/[svn]/gigedit/trunk/src/gigedit/scripteditor.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/scripteditor.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3368 by schoenebeck, Thu Nov 16 19:18:42 2017 UTC revision 3566 by schoenebeck, Sat Aug 24 13:42:17 2019 UTC
# Line 1  Line 1 
1  /*  /*
2      Copyright (c) 2014-2017 Christian Schoenebeck      Copyright (c) 2014-2019 Christian Schoenebeck
3            
4      This file is part of "gigedit" and released under the terms of the      This file is part of "gigedit" and released under the terms of the
5      GNU General Public License version 2.      GNU General Public License version 2.
# Line 166  ScriptEditor::ScriptEditor() : Line 166  ScriptEditor::ScriptEditor() :
166      m_lineNrTag->property_foreground() = "#CCCCCC";      m_lineNrTag->property_foreground() = "#CCCCCC";
167      m_tagTable->add(m_lineNrTag);      m_tagTable->add(m_lineNrTag);
168    
169        m_metricTag = Gtk::TextBuffer::Tag::create();
170        m_metricTag->property_foreground() = "#000000"; // black
171        m_tagTable->add(m_metricTag);
172    
173        m_stdUnitTag = Gtk::TextBuffer::Tag::create();
174        m_stdUnitTag->property_foreground() = "#50BC00"; // greenish
175        m_tagTable->add(m_stdUnitTag);
176    
177      // create menu      // create menu
178  #if USE_GTKMM_BUILDER  #if USE_GTKMM_BUILDER
179      m_actionGroup = Gio::SimpleActionGroup::create();      m_actionGroup = Gio::SimpleActionGroup::create();
# Line 248  ScriptEditor::ScriptEditor() : Line 256  ScriptEditor::ScriptEditor() :
256  #endif  #endif
257    
258      m_lineNrBuffer = Gtk::TextBuffer::create(m_tagTable);      m_lineNrBuffer = Gtk::TextBuffer::create(m_tagTable);
259        m_lineNrView.set_size_request(22,14);
260      m_lineNrView.set_buffer(m_lineNrBuffer);      m_lineNrView.set_buffer(m_lineNrBuffer);
261      m_lineNrView.set_left_margin(3);      m_lineNrView.set_left_margin(3);
262      m_lineNrView.set_right_margin(3);      m_lineNrView.set_right_margin(3);
263      m_lineNrTextViewSpacer.set_size_request(5);      m_lineNrView.property_editable() = false;
264        m_lineNrView.property_sensitive() = false;
265        m_lineNrTextViewSpacer.set_size_request(5,14);
266        m_lineNrTextViewSpacer.property_editable() = false;
267        m_lineNrTextViewSpacer.property_sensitive() = false;
268      {      {
269  #if 1 //(GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if 1 //(GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
270          Gdk::Color color;          Gdk::Color color;
# Line 260  ScriptEditor::ScriptEditor() : Line 273  ScriptEditor::ScriptEditor() :
273  #endif  #endif
274          color.set("#F5F5F5");          color.set("#F5F5F5");
275          GtkWidget* widget = (GtkWidget*) m_lineNrView.gobj();          GtkWidget* widget = (GtkWidget*) m_lineNrView.gobj();
276  #if GTK_MAJOR_VERSION < 3 || (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION <= 22)  #if GTK_MAJOR_VERSION < 3 || (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION <= 24)
277          gtk_widget_modify_base(widget, GTK_STATE_NORMAL, color.gobj());          gtk_widget_modify_base(widget, GTK_STATE_NORMAL, color.gobj());
278          gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color.gobj());          gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color.gobj());
279  #endif  #endif
# Line 273  ScriptEditor::ScriptEditor() : Line 286  ScriptEditor::ScriptEditor() :
286  #endif  #endif
287          color.set("#EEEEEE");          color.set("#EEEEEE");
288          GtkWidget* widget = (GtkWidget*) m_lineNrTextViewSpacer.gobj();          GtkWidget* widget = (GtkWidget*) m_lineNrTextViewSpacer.gobj();
289  #if GTK_MAJOR_VERSION < 3 || (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION <= 22)  #if GTK_MAJOR_VERSION < 3 || (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION <= 24)
290          gtk_widget_modify_base(widget, GTK_STATE_NORMAL, color.gobj());          gtk_widget_modify_base(widget, GTK_STATE_NORMAL, color.gobj());
291          gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color.gobj());          gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color.gobj());
292  #endif  #endif
# Line 443  void ScriptEditor::setScript(gig::Script Line 456  void ScriptEditor::setScript(gig::Script
456      //printf("text : '%s'\n", txt.c_str());      //printf("text : '%s'\n", txt.c_str());
457      m_textBuffer->set_text(txt);      m_textBuffer->set_text(txt);
458      m_textBuffer->set_modified(false);      m_textBuffer->set_modified(false);
459    
460        // on Gtk 3 the respective text change callback would not be called, so force this update here
461        if (txt.empty())
462            updateLineNumbers();
463  }  }
464    
465  void ScriptEditor::updateLineNumbers() {  void ScriptEditor::updateLineNumbers() {
466      const int n = m_textBuffer->get_line_count();      int n = m_textBuffer->get_line_count();
467      const int old = m_lineNrBuffer->get_line_count();      int old = m_lineNrBuffer->get_line_count();
468      if (n == old) return;      if (n == old && old > 1) return;
469        if (n < 1) n = 1;
470      const int digits = log10(n) + 1;      const int digits = log10(n) + 1;
471      const int bufSz = digits + 2;      const int bufSz = digits + 2;
472      char* buf = new char[bufSz];      char* buf = new char[bufSz];
# Line 598  void ScriptEditor::updateSyntaxHighlight Line 616  void ScriptEditor::updateSyntaxHighlight
616              applyCodeTag(m_textBuffer, token, m_commentTag);              applyCodeTag(m_textBuffer, token, m_commentTag);
617          } else if (token.isPreprocessor()) {          } else if (token.isPreprocessor()) {
618              applyCodeTag(m_textBuffer, token, m_preprocTag);              applyCodeTag(m_textBuffer, token, m_preprocTag);
619            } else if (token.isMetricPrefix()) {
620                applyCodeTag(m_textBuffer, token, m_metricTag);
621            } else if (token.isStdUnit()) {
622                applyCodeTag(m_textBuffer, token, m_stdUnitTag);
623          } else if (token.isNewLine()) {          } else if (token.isNewLine()) {
624          }          }
625      }      }
# Line 749  bool ScriptEditor::on_motion_notify_even Line 771  bool ScriptEditor::on_motion_notify_even
771      //TODO: event throttling would be a good idea here      //TODO: event throttling would be a good idea here
772      updateIssueTooltip(e);      updateIssueTooltip(e);
773  #endif  #endif
774  #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION <= 22)  #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION <= 24)
775      return ManagedWindow::on_motion_notify_event(e);      return ManagedWindow::on_motion_notify_event(e);
776  #else  #else
777      Gdk::EventMotion em = Glib::wrap(e, true);      Gdk::EventMotion em = Glib::wrap(e, true);

Legend:
Removed from v.3368  
changed lines
  Added in v.3566

  ViewVC Help
Powered by ViewVC