/[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 3309 by schoenebeck, Thu Jun 22 10:54:10 2017 UTC revision 3310 by schoenebeck, Sat Jul 15 12:02:21 2017 UTC
# Line 7  Line 7 
7    
8  #include "scripteditor.h"  #include "scripteditor.h"
9  #include "global.h"  #include "global.h"
10    #include <gtk/gtkwidget.h> // for gtk_widget_modify_*()
11    
12  #if !USE_LS_SCRIPTVM  #if !USE_LS_SCRIPTVM
13    
# Line 151  ScriptEditor::ScriptEditor() : Line 152  ScriptEditor::ScriptEditor() :
152      m_warningTag->property_background() = "#fffd7c"; // yellow      m_warningTag->property_background() = "#fffd7c"; // yellow
153      m_tagTable->add(m_warningTag);      m_tagTable->add(m_warningTag);
154    
155        m_lineNrTag = Gtk::TextBuffer::Tag::create();
156        m_lineNrTag->property_foreground() = "#CCCCCC";
157        m_tagTable->add(m_lineNrTag);
158    
159      // create menu      // create menu
160      m_actionGroup = Gtk::ActionGroup::create();      m_actionGroup = Gtk::ActionGroup::create();
161      m_actionGroup->add(Gtk::Action::create("MenuScript", _("_Script")));      m_actionGroup->add(Gtk::Action::create("MenuScript", _("_Script")));
# Line 181  ScriptEditor::ScriptEditor() : Line 186  ScriptEditor::ScriptEditor() :
186          "</ui>"          "</ui>"
187      );      );
188    
189        m_lineNrBuffer = Gtk::TextBuffer::create(m_tagTable);
190        m_lineNrView.set_buffer(m_lineNrBuffer);
191        m_lineNrView.set_left_margin(3);
192        m_lineNrView.set_right_margin(3);
193        m_lineNrTextViewSpacer.set_size_request(5);
194        {
195            Gdk::Color color;
196            color.set("#F5F5F5");
197            GtkWidget* widget = (GtkWidget*) m_lineNrView.gobj();
198            gtk_widget_modify_base(widget, GTK_STATE_NORMAL, color.gobj());
199            gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color.gobj());
200        }
201        {
202            Gdk::Color color;
203            color.set("#EEEEEE");
204            GtkWidget* widget = (GtkWidget*) m_lineNrTextViewSpacer.gobj();
205            gtk_widget_modify_base(widget, GTK_STATE_NORMAL, color.gobj());
206            gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color.gobj());
207        }
208      m_textBuffer = Gtk::TextBuffer::create(m_tagTable);      m_textBuffer = Gtk::TextBuffer::create(m_tagTable);
209      m_textView.set_buffer(m_textBuffer);      m_textView.set_buffer(m_textBuffer);
210        m_textView.set_left_margin(5);
211      setFontSize(currentFontSize(), false);      setFontSize(currentFontSize(), false);
212      m_scrolledWindow.add(m_textView);      m_textViewHBox.pack_start(m_lineNrView, Gtk::PACK_SHRINK);
213        m_textViewHBox.pack_start(m_lineNrTextViewSpacer, Gtk::PACK_SHRINK);
214        m_textViewHBox.add(m_textView);
215        m_scrolledWindow.add(m_textViewHBox);
216      m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
217    
218      Gtk::Widget* menuBar = m_uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = m_uiManager->get_widget("/MenuBar");
# Line 269  void ScriptEditor::setFontSize(int size, Line 297  void ScriptEditor::setFontSize(int size,
297      fdesc.set_family("monospace");      fdesc.set_family("monospace");
298      fdesc.set_size(size * PANGO_SCALE);      fdesc.set_size(size * PANGO_SCALE);
299  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
300        m_lineNrView.modify_font(fdesc);
301      m_textView.modify_font(fdesc);      m_textView.modify_font(fdesc);
302  #else  #else
303        m_lineNrView.override_font(fdesc);
304      m_textView.override_font(fdesc);      m_textView.override_font(fdesc);
305  #endif  #endif
306      if (save) Settings::singleton()->scriptEditorFontSize = size;      if (save) Settings::singleton()->scriptEditorFontSize = size;
# Line 291  void ScriptEditor::setScript(gig::Script Line 321  void ScriptEditor::setScript(gig::Script
321      m_textBuffer->set_modified(false);      m_textBuffer->set_modified(false);
322  }  }
323    
324    void ScriptEditor::updateLineNumbers() {
325        const int n = m_textBuffer->get_line_count();
326        const int old = m_lineNrBuffer->get_line_count();
327        if (n == old) return;
328        Glib::ustring s;
329        for (int i = 0; i < n; ++i) {
330            if (i) s += "\n";
331            s += ToString(i+1);
332        }
333        m_lineNrBuffer->remove_all_tags(m_lineNrBuffer->begin(), m_lineNrBuffer->end());
334        m_lineNrBuffer->set_text(s);
335        m_lineNrBuffer->apply_tag(m_lineNrTag, m_lineNrBuffer->begin(), m_lineNrBuffer->end());
336    }
337    
338  void ScriptEditor::onTextInserted(const Gtk::TextBuffer::iterator& itEnd, const Glib::ustring& txt, int length) {  void ScriptEditor::onTextInserted(const Gtk::TextBuffer::iterator& itEnd, const Glib::ustring& txt, int length) {
339      //printf("onTextInserted()\n");      //printf("onTextInserted()\n");
340  #if USE_LS_SCRIPTVM  #if USE_LS_SCRIPTVM
# Line 341  void ScriptEditor::onTextInserted(const Line 385  void ScriptEditor::onTextInserted(const
385      ;      ;
386            
387  #endif // USE_LS_SCRIPTVM  #endif // USE_LS_SCRIPTVM
388        updateLineNumbers();
389  }  }
390    
391  #if USE_LS_SCRIPTVM  #if USE_LS_SCRIPTVM
# Line 566  void ScriptEditor::onTextErased(const Gt Line 611  void ScriptEditor::onTextErased(const Gt
611    
612      m_textBuffer->remove_all_tags(itStart2, itEnd2);      m_textBuffer->remove_all_tags(itStart2, itEnd2);
613  #endif // USE_LS_SCRIPTVM  #endif // USE_LS_SCRIPTVM
614        updateLineNumbers();
615  }  }
616    
617  bool ScriptEditor::on_motion_notify_event(GdkEventMotion* e) {  bool ScriptEditor::on_motion_notify_event(GdkEventMotion* e) {

Legend:
Removed from v.3309  
changed lines
  Added in v.3310

  ViewVC Help
Powered by ViewVC