/[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 2939 by schoenebeck, Mon Jul 11 17:58:33 2016 UTC revision 3364 by schoenebeck, Tue Nov 14 18:07:25 2017 UTC
# Line 1  Line 1 
1  /*  /*
2      Copyright (c) 2014-2016 Christian Schoenebeck      Copyright (c) 2014-2017 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 7  Line 7 
7    
8  #include "scripteditor.h"  #include "scripteditor.h"
9  #include "global.h"  #include "global.h"
10    #include "compat.h"
11    #include <gtk/gtkwidget.h> // for gtk_widget_modify_*()
12    #if defined(__APPLE__)
13    # include "MacHelper.h"
14    #endif
15    #include <math.h> // for log10()
16    
17  #if !USE_LS_SCRIPTVM  #if !USE_LS_SCRIPTVM
18    
19  static const std::string _keywords[] = {  static const std::string _keywords[] = {
20      "on", "end", "declare", "while", "if", "or", "and", "not", "else", "case",      "on", "end", "declare", "while", "if", "or", "and", "not", "else", "case",
21      "select", "to", "const", "polyphonic", "mod"      "select", "to", "const", "polyphonic", "mod", "synchronized"
22  };  };
23  static int _keywordsSz = sizeof(_keywords) / sizeof(std::string);  static int _keywordsSz = sizeof(_keywords) / sizeof(std::string);
24    
# Line 60  static Glib::RefPtr<Gdk::Pixbuf> createI Line 66  static Glib::RefPtr<Gdk::Pixbuf> createI
66    
67  ScriptEditor::ScriptEditor() :  ScriptEditor::ScriptEditor() :
68      m_statusLabel("",  Gtk::ALIGN_START),      m_statusLabel("",  Gtk::ALIGN_START),
69    #if HAS_GTKMM_STOCK
70        m_applyButton(Gtk::Stock::APPLY),
71        m_cancelButton(Gtk::Stock::CANCEL)
72    #else
73      m_applyButton(_("_Apply"), true),      m_applyButton(_("_Apply"), true),
74      m_cancelButton(_("_Cancel"), true)      m_cancelButton(_("_Cancel"), true)
75    #endif
76  {  {
77      m_script = NULL;      m_script = NULL;
78  #if USE_LS_SCRIPTVM  #if USE_LS_SCRIPTVM
79      m_vm = NULL;      m_vm = NULL;
80  #endif  #endif
81    
82        if (!Settings::singleton()->autoRestoreWindowDimension) {
83            set_default_size(800, 700);
84            set_position(Gtk::WIN_POS_MOUSE);
85        }
86    
87      // depending on GTK version and installed themes, there may be different      // depending on GTK version and installed themes, there may be different
88      // icons, and different names for them, so for each type of icon we use,      // icons, and different names for them, so for each type of icon we use,
89      // we provide a list of possible icon names, the first one found to be      // we provide a list of possible icon names, the first one found to be
# Line 127  ScriptEditor::ScriptEditor() : Line 143  ScriptEditor::ScriptEditor() :
143      m_commentTag->property_foreground() = "#9c9c9c"; // gray      m_commentTag->property_foreground() = "#9c9c9c"; // gray
144      m_tagTable->add(m_commentTag);      m_tagTable->add(m_commentTag);
145    
146        #define PREPROC_TOKEN_COLOR  "#2f8a33" // green
147    
148      m_preprocTag = Gtk::TextBuffer::Tag::create();      m_preprocTag = Gtk::TextBuffer::Tag::create();
149      m_preprocTag->property_foreground() = "#2f8a33"; // green      m_preprocTag->property_foreground() = PREPROC_TOKEN_COLOR;
150      m_tagTable->add(m_preprocTag);      m_tagTable->add(m_preprocTag);
151    
152        m_preprocCommentTag = Gtk::TextBuffer::Tag::create();
153        m_preprocCommentTag->property_strikethrough() = true;
154        m_preprocCommentTag->property_background() = "#e5e5e5";
155        m_tagTable->add(m_preprocCommentTag);
156    
157      m_errorTag = Gtk::TextBuffer::Tag::create();      m_errorTag = Gtk::TextBuffer::Tag::create();
158      m_errorTag->property_background() = "#ff9393"; // red      m_errorTag->property_background() = "#ff9393"; // red
159      m_tagTable->add(m_errorTag);      m_tagTable->add(m_errorTag);
# Line 139  ScriptEditor::ScriptEditor() : Line 162  ScriptEditor::ScriptEditor() :
162      m_warningTag->property_background() = "#fffd7c"; // yellow      m_warningTag->property_background() = "#fffd7c"; // yellow
163      m_tagTable->add(m_warningTag);      m_tagTable->add(m_warningTag);
164    
165        m_lineNrTag = Gtk::TextBuffer::Tag::create();
166        m_lineNrTag->property_foreground() = "#CCCCCC";
167        m_tagTable->add(m_lineNrTag);
168    
169      // create menu      // create menu
170    #if USE_GTKMM_BUILDER
171        m_actionGroup = Gio::SimpleActionGroup::create();
172        m_actionGroup->add_action(
173            "Apply", sigc::mem_fun(*this, &ScriptEditor::onButtonApply)
174        );
175        m_actionGroup->add_action(
176            "Close", sigc::mem_fun(*this, &ScriptEditor::onButtonCancel)
177        );
178        m_actionGroup->add_action(
179            "ChangeFont", sigc::mem_fun(*this, &ScriptEditor::onMenuChangeFontSize)
180        );
181        insert_action_group("ScriptEditor", m_actionGroup);
182    
183        m_uiManager = Gtk::Builder::create();
184        Glib::ustring ui_info =
185            "<interface>"
186            "  <menubar id='MenuBar'>"
187            "    <menu id='MenuScript'>"
188            "      <section>"
189            "        <item id='Apply'>"
190            "          <attribute name='label' translatable='yes'>_Apply</attribute>"
191            "          <attribute name='action'>ScriptEditor.Apply</attribute>"
192            "          <attribute name='accel'>&lt;Primary&gt;s</attribute>"
193            "        </item>"
194            "      </section>"
195            "      <section>"
196            "        <item id='Close'>"
197            "          <attribute name='label' translatable='yes'>_Close</attribute>"
198            "          <attribute name='action'>ScriptEditor.Close</attribute>"
199            "          <attribute name='accel'>&lt;Primary&gt;q</attribute>"
200            "        </item>"
201            "      </section>"
202            "    </menu>"
203            "    <menu id='MenuEditor'>"
204            "      <section>"
205            "        <item id='ChangeFont'>"
206            "          <attribute name='label' translatable='yes'>_Font Size ...</attribute>"
207            "          <attribute name='action'>ScriptEditor.ChangeFont</attribute>"
208            "        </item>"
209            "      </section>"
210            "    </menu>"
211            "  </menubar>"
212            "</interface>";
213        m_uiManager->add_from_string(ui_info);
214        /*{
215            auto object = uiManager->get_object("MenuBar");
216            auto gmenu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
217            set_menubar(gmenu);
218        }*/
219    #else
220      m_actionGroup = Gtk::ActionGroup::create();      m_actionGroup = Gtk::ActionGroup::create();
221      m_actionGroup->add(Gtk::Action::create("MenuScript", _("_Script")));      m_actionGroup->add(Gtk::Action::create("MenuScript", _("_Script")));
222      m_actionGroup->add(Gtk::Action::create("Apply", _("_Apply")),      m_actionGroup->add(Gtk::Action::create("Apply", _("_Apply")),
# Line 148  ScriptEditor::ScriptEditor() : Line 225  ScriptEditor::ScriptEditor() :
225      m_actionGroup->add(Gtk::Action::create("Close", _("_Close")),      m_actionGroup->add(Gtk::Action::create("Close", _("_Close")),
226                         Gtk::AccelKey("<control>q"),                         Gtk::AccelKey("<control>q"),
227                         sigc::mem_fun(*this, &ScriptEditor::onButtonCancel));                         sigc::mem_fun(*this, &ScriptEditor::onButtonCancel));
228        m_actionGroup->add(Gtk::Action::create("MenuEditor", _("_Editor")));
229        m_actionGroup->add(Gtk::Action::create("ChangeFont", _("_Font Size ...")),
230                           sigc::mem_fun(*this, &ScriptEditor::onMenuChangeFontSize));
231      m_uiManager = Gtk::UIManager::create();      m_uiManager = Gtk::UIManager::create();
232      m_uiManager->insert_action_group(m_actionGroup);      m_uiManager->insert_action_group(m_actionGroup);
233      add_accel_group(m_uiManager->get_accel_group());      add_accel_group(m_uiManager->get_accel_group());
# Line 159  ScriptEditor::ScriptEditor() : Line 239  ScriptEditor::ScriptEditor() :
239          "      <separator/>"          "      <separator/>"
240          "      <menuitem action='Close'/>"          "      <menuitem action='Close'/>"
241          "    </menu>"          "    </menu>"
242            "    <menu action='MenuEditor'>"
243            "      <menuitem action='ChangeFont'/>"
244            "    </menu>"
245          "  </menubar>"          "  </menubar>"
246          "</ui>"          "</ui>"
247      );      );
248    #endif
249    
250      m_textBuffer = Gtk::TextBuffer::create(m_tagTable);      m_lineNrBuffer = Gtk::TextBuffer::create(m_tagTable);
251      m_textView.set_buffer(m_textBuffer);      m_lineNrView.set_buffer(m_lineNrBuffer);
252        m_lineNrView.set_left_margin(3);
253        m_lineNrView.set_right_margin(3);
254        m_lineNrTextViewSpacer.set_size_request(5);
255      {      {
256          Pango::FontDescription fdesc;  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
257          fdesc.set_family("monospace");          Gdk::Color color;
 #if defined(__APPLE__)  
         fdesc.set_size(14 * PANGO_SCALE);  
258  #else  #else
259          fdesc.set_size(10 * PANGO_SCALE);          Gdk::RGBA color;
260  #endif  #endif
261  #if GTKMM_MAJOR_VERSION < 3          color.set("#F5F5F5");
262          m_textView.modify_font(fdesc);          GtkWidget* widget = (GtkWidget*) m_lineNrView.gobj();
263    #if GTK_MAJOR_VERSION < 3
264            gtk_widget_modify_base(widget, GTK_STATE_NORMAL, color.gobj());
265            gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color.gobj());
266    #endif
267        }
268        {
269    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
270            Gdk::Color color;
271  #else  #else
272          m_textView.override_font(fdesc);          Gdk::RGBA color;
273    #endif
274            color.set("#EEEEEE");
275            GtkWidget* widget = (GtkWidget*) m_lineNrTextViewSpacer.gobj();
276    #if GTK_MAJOR_VERSION < 3
277            gtk_widget_modify_base(widget, GTK_STATE_NORMAL, color.gobj());
278            gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color.gobj());
279  #endif  #endif
280      }      }
281      m_scrolledWindow.add(m_textView);      m_textBuffer = Gtk::TextBuffer::create(m_tagTable);
282        m_textView.set_buffer(m_textBuffer);
283        m_textView.set_left_margin(5);
284        setFontSize(currentFontSize(), false);
285        m_textViewHBox.pack_start(m_lineNrView, Gtk::PACK_SHRINK);
286        m_textViewHBox.pack_start(m_lineNrTextViewSpacer, Gtk::PACK_SHRINK);
287        m_textViewHBox.add(m_textView);
288        m_scrolledWindow.add(m_textViewHBox);
289      m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
290    
291    #if USE_GTKMM_BUILDER
292        Gtk::Widget* menuBar = new Gtk::MenuBar(
293            Glib::RefPtr<Gio::Menu>::cast_dynamic(
294                m_uiManager->get_object("MenuBar")
295            )
296        );
297    #else
298      Gtk::Widget* menuBar = m_uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = m_uiManager->get_widget("/MenuBar");
299    #endif
300    
301      m_vbox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_vbox.pack_start(*menuBar, Gtk::PACK_SHRINK);
302      m_vbox.pack_start(m_scrolledWindow);      m_vbox.pack_start(m_scrolledWindow);
303    
# Line 193  ScriptEditor::ScriptEditor() : Line 308  ScriptEditor::ScriptEditor() :
308      m_applyButton.set_sensitive(false);      m_applyButton.set_sensitive(false);
309      m_applyButton.grab_focus();      m_applyButton.grab_focus();
310    
311  #if GTKMM_MAJOR_VERSION >= 3  #if GTKMM_MAJOR_VERSION < 3
312        m_statusHBox.set_spacing(6);
313    #elif GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 12
314      m_statusImage.set_margin_left(6);      m_statusImage.set_margin_left(6);
315      m_statusImage.set_margin_right(6);      m_statusImage.set_margin_right(6);
316  #else  #else
317      m_statusHBox.set_spacing(6);      m_statusImage.set_margin_start(6);
318        m_statusImage.set_margin_end(6);
319  #endif  #endif
320    
321      m_statusHBox.pack_start(m_statusImage, Gtk::PACK_SHRINK);      m_statusHBox.pack_start(m_statusImage, Gtk::PACK_SHRINK);
322      m_statusHBox.pack_start(m_statusLabel);      m_statusHBox.pack_start(m_statusLabel);
323    #if HAS_GTKMM_SHOW_ALL_CHILDREN
324      m_statusHBox.show_all_children();      m_statusHBox.show_all_children();
325    #endif
326    
327      m_footerHBox.pack_start(m_statusHBox);      m_footerHBox.pack_start(m_statusHBox);
328      m_footerHBox.pack_start(m_buttonBox, Gtk::PACK_SHRINK);      m_footerHBox.pack_start(m_buttonBox, Gtk::PACK_SHRINK);
# Line 234  ScriptEditor::ScriptEditor() : Line 354  ScriptEditor::ScriptEditor() :
354      );      );
355    
356      signal_delete_event().connect(      signal_delete_event().connect(
357    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
358          sigc::mem_fun(*this, &ScriptEditor::onWindowDelete)          sigc::mem_fun(*this, &ScriptEditor::onWindowDelete)
359    #else
360            sigc::mem_fun(*this, &ScriptEditor::onWindowDeleteP)
361    #endif
362      );      );
363    
364    #if HAS_GTKMM_SHOW_ALL_CHILDREN
365      show_all_children();      show_all_children();
366    #endif
367  }  }
368    
369  ScriptEditor::~ScriptEditor() {  ScriptEditor::~ScriptEditor() {
# Line 247  ScriptEditor::~ScriptEditor() { Line 373  ScriptEditor::~ScriptEditor() {
373  #endif  #endif
374  }  }
375    
376    int ScriptEditor::currentFontSize() const {
377    #if defined(__APPLE__)
378        const int defaultFontSize = 11;
379    #else
380        const int defaultFontSize = 10;
381    #endif
382        const int settingFontSize = Settings::singleton()->scriptEditorFontSize;
383        const int fontSize = (settingFontSize > 0) ? settingFontSize : defaultFontSize;
384        return fontSize;
385    }
386    
387    void ScriptEditor::setFontSize(int size, bool save) {
388        //printf("setFontSize(%d,%d)\n", size, save);
389    #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 20)
390        Pango::FontDescription fdesc;
391        fdesc.set_family("monospace");
392    # if defined(__APPLE__)
393        // fixes poor readability of default monospace font on Macs
394        if (macIsMinMac10_6())
395            fdesc.set_family("Menlo");
396    # endif
397        fdesc.set_size(size * PANGO_SCALE);
398    # if GTKMM_MAJOR_VERSION < 3
399        m_lineNrView.modify_font(fdesc);
400        m_textView.modify_font(fdesc);
401    # else
402        m_lineNrView.override_font(fdesc);
403        m_textView.override_font(fdesc);
404    # endif
405    #else
406        Glib::ustring family = "monospace";
407    # if defined(__APPLE__)
408        // fixes poor readability of default monospace font on Macs
409        if (macIsMinMac10_6())
410            family = "Menlo";
411    # endif
412        if (!m_css) {
413            m_css = Gtk::CssProvider::create();
414            m_lineNrView.get_style_context()->add_provider(m_css, GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
415            m_textView.get_style_context()->add_provider(m_css, GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
416        }
417        m_css->load_from_data(
418            "* {"
419            "  font: " + ToString(size) + " " + family + ";"
420            "}"
421        );
422    #endif
423        if (save) Settings::singleton()->scriptEditorFontSize = size;
424    }
425    
426  void ScriptEditor::setScript(gig::Script* script) {  void ScriptEditor::setScript(gig::Script* script) {
427      m_script = script;      m_script = script;
428      if (!script) {      if (!script) {
# Line 262  void ScriptEditor::setScript(gig::Script Line 438  void ScriptEditor::setScript(gig::Script
438      m_textBuffer->set_modified(false);      m_textBuffer->set_modified(false);
439  }  }
440    
441    void ScriptEditor::updateLineNumbers() {
442        const int n = m_textBuffer->get_line_count();
443        const int old = m_lineNrBuffer->get_line_count();
444        if (n == old) return;
445        const int digits = log10(n) + 1;
446        const int bufSz = digits + 2;
447        char* buf = new char[bufSz];
448        std::string sFmt1 =   "%" + ToString(digits) + "d";
449        std::string sFmt2 = "\n%" + ToString(digits) + "d";
450        Glib::ustring s;
451        for (int i = 0; i < n; ++i) {
452            snprintf(buf, bufSz, i ? sFmt2.c_str() : sFmt1.c_str(), i+1);
453            s += buf;
454        }
455        m_lineNrBuffer->remove_all_tags(m_lineNrBuffer->begin(), m_lineNrBuffer->end());
456        m_lineNrBuffer->set_text(s);
457        m_lineNrBuffer->apply_tag(m_lineNrTag, m_lineNrBuffer->begin(), m_lineNrBuffer->end());
458        if (buf) delete[] buf;
459    }
460    
461  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) {
462      //printf("onTextInserted()\n");      //printf("onTextInserted()\n");
463  #if USE_LS_SCRIPTVM  #if USE_LS_SCRIPTVM
# Line 312  void ScriptEditor::onTextInserted(const Line 508  void ScriptEditor::onTextInserted(const
508      ;      ;
509            
510  #endif // USE_LS_SCRIPTVM  #endif // USE_LS_SCRIPTVM
511        updateLineNumbers();
512  }  }
513    
514  #if USE_LS_SCRIPTVM  #if USE_LS_SCRIPTVM
# Line 321  LinuxSampler::ScriptVM* ScriptEditor::Ge Line 518  LinuxSampler::ScriptVM* ScriptEditor::Ge
518      return m_vm;      return m_vm;
519  }  }
520    
521  static void getIteratorsForIssue(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::ParserIssue& issue, Gtk::TextBuffer::iterator& start, Gtk::TextBuffer::iterator& end) {  template<class T>
522      start = txtbuf->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1);  static void getIteratorsForIssue(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const T& issue, Gtk::TextBuffer::iterator& start, Gtk::TextBuffer::iterator& end) {
523        Gtk::TextBuffer::iterator itLine =
524            txtbuf->get_iter_at_line_index(issue.firstLine - 1, 0);
525        const int charsInLine = itLine.get_bytes_in_line();
526        start = txtbuf->get_iter_at_line_index(
527            issue.firstLine - 1,
528            // check we are not getting past the end of the line here, otherwise Gtk crashes
529            issue.firstColumn - 1 < charsInLine ? issue.firstColumn - 1 : charsInLine - 1
530        );
531      end = start;      end = start;
532      end.forward_lines(issue.lastLine - issue.firstLine);      end.forward_lines(issue.lastLine - issue.firstLine);
533      end.forward_chars(      end.forward_chars(
# Line 333  static void getIteratorsForIssue(Glib::R Line 538  static void getIteratorsForIssue(Glib::R
538  }  }
539    
540  static void applyCodeTag(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::VMSourceToken& token, Glib::RefPtr<Gtk::TextBuffer::Tag>& tag) {  static void applyCodeTag(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::VMSourceToken& token, Glib::RefPtr<Gtk::TextBuffer::Tag>& tag) {
541      Gtk::TextBuffer::iterator itStart =      Gtk::TextBuffer::iterator itLine =
542          txtbuf->get_iter_at_line_index(token.firstLine(), token.firstColumn());          txtbuf->get_iter_at_line_index(token.firstLine(), 0);
543        const int charsInLine = itLine.get_bytes_in_line();
544        Gtk::TextBuffer::iterator itStart = txtbuf->get_iter_at_line_index(
545            token.firstLine(),
546            // check we are not getting past the end of the line here, otherwise Gtk crashes
547            token.firstColumn() < charsInLine ? token.firstColumn() : charsInLine - 1
548        );
549      Gtk::TextBuffer::iterator itEnd = itStart;      Gtk::TextBuffer::iterator itEnd = itStart;
550      const int length = token.text().length();      const int length = token.text().length();
551      itEnd.forward_chars(length);      itEnd.forward_chars(length);
# Line 347  static void applyCodeTag(Glib::RefPtr<Gt Line 558  static void applyCodeTag(Glib::RefPtr<Gt
558      txtbuf->apply_tag(tag, itStart, itEnd);      txtbuf->apply_tag(tag, itStart, itEnd);
559  }  }
560    
561    static void applyPreprocessorComment(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::CodeBlock& block, Glib::RefPtr<Gtk::TextBuffer::Tag>& tag) {
562        Gtk::TextBuffer::iterator itStart, itEnd;
563        getIteratorsForIssue(txtbuf, block, itStart, itEnd);
564        txtbuf->apply_tag(tag, itStart, itEnd);
565    }
566    
567  void ScriptEditor::updateSyntaxHighlightingByVM() {  void ScriptEditor::updateSyntaxHighlightingByVM() {
568      GetScriptVM();      GetScriptVM();
569      const std::string s = m_textBuffer->get_text();      const std::string s = m_textBuffer->get_text();
570        if (s.empty()) return;
571      std::vector<LinuxSampler::VMSourceToken> tokens = m_vm->syntaxHighlighting(s);      std::vector<LinuxSampler::VMSourceToken> tokens = m_vm->syntaxHighlighting(s);
572    
573      for (int i = 0; i < tokens.size(); ++i) {      for (int i = 0; i < tokens.size(); ++i) {
# Line 385  void ScriptEditor::updateParserIssuesByV Line 603  void ScriptEditor::updateParserIssuesByV
603      m_issues = parserContext->issues();      m_issues = parserContext->issues();
604      m_errors = parserContext->errors();      m_errors = parserContext->errors();
605      m_warnings = parserContext->warnings();      m_warnings = parserContext->warnings();
606        m_preprocComments = parserContext->preprocessorComments();
607    
608      for (int i = 0; i < m_issues.size(); ++i) {      if (!s.empty()) {
609          const LinuxSampler::ParserIssue& issue = m_issues[i];          for (int i = 0; i < m_issues.size(); ++i) {
610                const LinuxSampler::ParserIssue& issue = m_issues[i];
611          if (issue.isErr()) {  
612              applyCodeTag(m_textBuffer, issue, m_errorTag);              if (issue.isErr()) {
613          } else if (issue.isWrn()) {                  applyCodeTag(m_textBuffer, issue, m_errorTag);
614              applyCodeTag(m_textBuffer, issue, m_warningTag);              } else if (issue.isWrn()) {
615                    applyCodeTag(m_textBuffer, issue, m_warningTag);
616                }
617          }          }
618      }      }
619    
620        for (int i = 0; i < m_preprocComments.size(); ++i) {
621            applyPreprocessorComment(m_textBuffer, m_preprocComments[i],
622                                     m_preprocCommentTag);
623        }
624    
625      delete parserContext;      delete parserContext;
626  }  }
627    
# Line 429  void ScriptEditor::updateIssueTooltip(Gd Line 655  void ScriptEditor::updateIssueTooltip(Gd
655          }          }
656      }      }
657    
658        for (int i = 0; i < m_preprocComments.size(); ++i) {
659            const LinuxSampler::CodeBlock& block = m_preprocComments[i];
660            const int firstLine   = block.firstLine - 1;
661            const int firstColumn = block.firstColumn - 1;
662            const int lastLine    = block.lastLine - 1;
663            const int lastColumn  = block.lastColumn - 1;
664            if (firstLine  <= line && line <= lastLine &&
665                (firstLine != line || firstColumn <= column) &&
666                (lastLine  != line || lastColumn  >= column))
667            {
668                m_textView.set_tooltip_markup(
669                    "Code block filtered out by preceding <span foreground=\"" PREPROC_TOKEN_COLOR "\">preprocessor</span> statement."
670                );
671                return;
672            }
673        }
674    
675      m_textView.set_tooltip_markup("");      m_textView.set_tooltip_markup("");
676  }  }
677    
# Line 491  void ScriptEditor::onTextErased(const Gt Line 734  void ScriptEditor::onTextErased(const Gt
734    
735      m_textBuffer->remove_all_tags(itStart2, itEnd2);      m_textBuffer->remove_all_tags(itStart2, itEnd2);
736  #endif // USE_LS_SCRIPTVM  #endif // USE_LS_SCRIPTVM
737        updateLineNumbers();
738  }  }
739    
740  bool ScriptEditor::on_motion_notify_event(GdkEventMotion* e) {  bool ScriptEditor::on_motion_notify_event(GdkEventMotion* e) {
# Line 498  bool ScriptEditor::on_motion_notify_even Line 742  bool ScriptEditor::on_motion_notify_even
742      //TODO: event throttling would be a good idea here      //TODO: event throttling would be a good idea here
743      updateIssueTooltip(e);      updateIssueTooltip(e);
744  #endif  #endif
745    #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION <= 22)
746      return ManagedWindow::on_motion_notify_event(e);      return ManagedWindow::on_motion_notify_event(e);
747    #else
748        Gdk::EventMotion em = Glib::wrap(e, true);
749        return ManagedWindow::on_motion_notify_event(em);
750    #endif
751  }  }
752    
753  bool ScriptEditor::onWindowDelete(GdkEventAny* e) {  void ScriptEditor::onMenuChangeFontSize() {
754        //TODO: for GTKMM >= 3.2 class Gtk::FontChooser could be used instead
755        Gtk::Dialog dialog(_("Font Size"), true /*modal*/);
756        HBox hbox;
757        hbox.set_spacing(6);
758    
759        Gtk::Label label(_("Editor's Font Size:"), Gtk::ALIGN_START);
760        hbox.pack_start(label, Gtk::PACK_SHRINK);
761    
762        Gtk::SpinButton spinButton;
763        spinButton.set_range(4, 80);
764        spinButton.set_increments(1, 10);
765        spinButton.set_value(currentFontSize());
766        hbox.pack_start(spinButton);
767    
768    #if USE_GTKMM_BOX
769        dialog.get_content_area()->pack_start(hbox);
770    #else
771        dialog.get_vbox()->pack_start(hbox);
772    #endif
773        dialog.add_button(_("_OK"), 0);
774        dialog.add_button(_("_Cancel"), 1);
775    
776    #if HAS_GTKMM_SHOW_ALL_CHILDREN
777        dialog.show_all_children();
778    #endif
779    
780        if (!dialog.run()) { // OK selected ...
781            const int newFontSize = spinButton.get_value_as_int();
782            if (newFontSize >= 4)
783                setFontSize(newFontSize, true);
784        }
785    }
786    
787    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
788    bool ScriptEditor::onWindowDelete(Gdk::Event& e) {
789        return onWindowDeleteP(NULL);
790    }
791    #endif
792    
793    bool ScriptEditor::onWindowDeleteP(GdkEventAny* /*e*/) {
794      //printf("onWindowDelete\n");      //printf("onWindowDelete\n");
795    
796      if (!isModified()) return false; // propagate event further (which will close this window)      if (!isModified()) return false; // propagate event further (which will close this window)
# Line 550  void ScriptEditor::onModifiedChanged() { Line 839  void ScriptEditor::onModifiedChanged() {
839  }  }
840    
841  void ScriptEditor::onButtonCancel() {  void ScriptEditor::onButtonCancel() {
842      bool dropEvent = onWindowDelete(NULL);      bool dropEvent = onWindowDeleteP(NULL);
843      if (dropEvent) return;      if (dropEvent) return;
844      hide();      hide();
845  }  }

Legend:
Removed from v.2939  
changed lines
  Added in v.3364

  ViewVC Help
Powered by ViewVC