/[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 2964 by schoenebeck, Sun Jul 17 22:02:36 2016 UTC revision 3225 by schoenebeck, Fri May 26 22:10:16 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 60  static Glib::RefPtr<Gdk::Pixbuf> createI Line 60  static Glib::RefPtr<Gdk::Pixbuf> createI
60    
61  ScriptEditor::ScriptEditor() :  ScriptEditor::ScriptEditor() :
62      m_statusLabel("",  Gtk::ALIGN_START),      m_statusLabel("",  Gtk::ALIGN_START),
63      m_applyButton(_("_Apply"), true),      m_applyButton(Gtk::Stock::APPLY),
64      m_cancelButton(_("_Cancel"), true)      m_cancelButton(Gtk::Stock::CANCEL)
65  {  {
66      m_script = NULL;      m_script = NULL;
67  #if USE_LS_SCRIPTVM  #if USE_LS_SCRIPTVM
68      m_vm = NULL;      m_vm = NULL;
69  #endif  #endif
70    
71        if (!Settings::singleton()->autoRestoreWindowDimension) {
72            set_default_size(800, 700);
73            set_position(Gtk::WIN_POS_MOUSE);
74        }
75    
76      // depending on GTK version and installed themes, there may be different      // depending on GTK version and installed themes, there may be different
77      // 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,
78      // 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 339  LinuxSampler::ScriptVM* ScriptEditor::Ge Line 344  LinuxSampler::ScriptVM* ScriptEditor::Ge
344  }  }
345    
346  static void getIteratorsForIssue(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::ParserIssue& issue, Gtk::TextBuffer::iterator& start, Gtk::TextBuffer::iterator& end) {  static void getIteratorsForIssue(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::ParserIssue& issue, Gtk::TextBuffer::iterator& start, Gtk::TextBuffer::iterator& end) {
347      start = txtbuf->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1);      Gtk::TextBuffer::iterator itLine =
348            txtbuf->get_iter_at_line_index(issue.firstLine - 1, 0);
349        const int charsInLine = itLine.get_bytes_in_line();
350        start = txtbuf->get_iter_at_line_index(
351            issue.firstLine - 1,
352            // check we are not getting past the end of the line here, otherwise Gtk crashes
353            issue.firstColumn - 1 < charsInLine ? issue.firstColumn - 1 : charsInLine - 1
354        );
355      end = start;      end = start;
356      end.forward_lines(issue.lastLine - issue.firstLine);      end.forward_lines(issue.lastLine - issue.firstLine);
357      end.forward_chars(      end.forward_chars(
# Line 350  static void getIteratorsForIssue(Glib::R Line 362  static void getIteratorsForIssue(Glib::R
362  }  }
363    
364  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) {
365      Gtk::TextBuffer::iterator itStart =      Gtk::TextBuffer::iterator itLine =
366          txtbuf->get_iter_at_line_index(token.firstLine(), token.firstColumn());          txtbuf->get_iter_at_line_index(token.firstLine(), 0);
367        const int charsInLine = itLine.get_bytes_in_line();
368        Gtk::TextBuffer::iterator itStart = txtbuf->get_iter_at_line_index(
369            token.firstLine(),
370            // check we are not getting past the end of the line here, otherwise Gtk crashes
371            token.firstColumn() < charsInLine ? token.firstColumn() : charsInLine - 1
372        );
373      Gtk::TextBuffer::iterator itEnd = itStart;      Gtk::TextBuffer::iterator itEnd = itStart;
374      const int length = token.text().length();      const int length = token.text().length();
375      itEnd.forward_chars(length);      itEnd.forward_chars(length);
# Line 367  static void applyCodeTag(Glib::RefPtr<Gt Line 385  static void applyCodeTag(Glib::RefPtr<Gt
385  void ScriptEditor::updateSyntaxHighlightingByVM() {  void ScriptEditor::updateSyntaxHighlightingByVM() {
386      GetScriptVM();      GetScriptVM();
387      const std::string s = m_textBuffer->get_text();      const std::string s = m_textBuffer->get_text();
388        if (s.empty()) return;
389      std::vector<LinuxSampler::VMSourceToken> tokens = m_vm->syntaxHighlighting(s);      std::vector<LinuxSampler::VMSourceToken> tokens = m_vm->syntaxHighlighting(s);
390    
391      for (int i = 0; i < tokens.size(); ++i) {      for (int i = 0; i < tokens.size(); ++i) {
# Line 403  void ScriptEditor::updateParserIssuesByV Line 422  void ScriptEditor::updateParserIssuesByV
422      m_errors = parserContext->errors();      m_errors = parserContext->errors();
423      m_warnings = parserContext->warnings();      m_warnings = parserContext->warnings();
424    
425      for (int i = 0; i < m_issues.size(); ++i) {      if (!s.empty()) {
426          const LinuxSampler::ParserIssue& issue = m_issues[i];          for (int i = 0; i < m_issues.size(); ++i) {
427                const LinuxSampler::ParserIssue& issue = m_issues[i];
428          if (issue.isErr()) {  
429              applyCodeTag(m_textBuffer, issue, m_errorTag);              if (issue.isErr()) {
430          } else if (issue.isWrn()) {                  applyCodeTag(m_textBuffer, issue, m_errorTag);
431              applyCodeTag(m_textBuffer, issue, m_warningTag);              } else if (issue.isWrn()) {
432                    applyCodeTag(m_textBuffer, issue, m_warningTag);
433                }
434          }          }
435      }      }
436    

Legend:
Removed from v.2964  
changed lines
  Added in v.3225

  ViewVC Help
Powered by ViewVC