/[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 2898 by schoenebeck, Sun May 1 21:17:42 2016 UTC revision 2899 by schoenebeck, Mon May 2 14:36:40 2016 UTC
# Line 35  static bool isEvent(const Glib::ustring& Line 35  static bool isEvent(const Glib::ustring&
35    
36  #endif // !USE_LS_SCRIPTVM  #endif // !USE_LS_SCRIPTVM
37    
38    static Glib::RefPtr<Gdk::Pixbuf> createIcon(std::string name, const Glib::RefPtr<Gdk::Screen>& screen) {
39        const int targetH = 16;
40        Glib::RefPtr<Gtk::IconTheme> theme = Gtk::IconTheme::get_for_screen(screen);
41        int w = 0;
42        int h = 0; // ignored
43        Gtk::IconSize::lookup(Gtk::ICON_SIZE_SMALL_TOOLBAR, w, h);
44        Glib::RefPtr<Gdk::Pixbuf> pixbuf = theme->load_icon(name, w, Gtk::ICON_LOOKUP_GENERIC_FALLBACK);
45        if (pixbuf->get_height() != targetH) {
46            pixbuf = pixbuf->scale_simple(targetH, targetH, Gdk::INTERP_BILINEAR);
47        }
48        return pixbuf;
49    }
50    
51  ScriptEditor::ScriptEditor() :  ScriptEditor::ScriptEditor() :
52        m_statusLabel("",  Gtk::ALIGN_START),
53      m_applyButton(_("_Apply"), true),      m_applyButton(_("_Apply"), true),
54      m_cancelButton(_("_Cancel"), true)      m_cancelButton(_("_Cancel"), true)
55  {  {
# Line 44  ScriptEditor::ScriptEditor() : Line 58  ScriptEditor::ScriptEditor() :
58      m_vm = NULL;      m_vm = NULL;
59  #endif  #endif
60    
61        m_errorIcon = createIcon("dialog-error", get_screen());
62        m_warningIcon = createIcon("dialog-warning-symbolic", get_screen());
63        m_successIcon = createIcon("emblem-default", get_screen());
64    
65      add(m_vbox);      add(m_vbox);
66    
67      m_tagTable = Gtk::TextBuffer::TagTable::create();      m_tagTable = Gtk::TextBuffer::TagTable::create();
# Line 116  ScriptEditor::ScriptEditor() : Line 134  ScriptEditor::ScriptEditor() :
134      m_applyButton.set_can_default();      m_applyButton.set_can_default();
135      m_applyButton.set_sensitive(false);      m_applyButton.set_sensitive(false);
136      m_applyButton.grab_focus();      m_applyButton.grab_focus();
137      m_vbox.pack_start(m_buttonBox, Gtk::PACK_SHRINK);      
138        m_statusImage.set_margin_left(6);
139        m_statusImage.set_margin_right(6);
140    
141        m_statusHBox.pack_start(m_statusImage, Gtk::PACK_SHRINK);
142        m_statusHBox.pack_start(m_statusLabel);
143        m_statusHBox.show_all_children();
144    
145        m_footerHBox.pack_start(m_statusHBox);
146        m_footerHBox.pack_start(m_buttonBox, Gtk::PACK_SHRINK);
147    
148        m_vbox.pack_start(m_footerHBox, Gtk::PACK_SHRINK);
149    
150      m_applyButton.signal_clicked().connect(      m_applyButton.signal_clicked().connect(
151          sigc::mem_fun(*this, &ScriptEditor::onButtonApply)          sigc::mem_fun(*this, &ScriptEditor::onButtonApply)
# Line 179  void ScriptEditor::onTextInserted(const Line 208  void ScriptEditor::onTextInserted(const
208      m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end());      m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end());
209      updateSyntaxHighlightingByVM();      updateSyntaxHighlightingByVM();
210      updateParserIssuesByVM();      updateParserIssuesByVM();
211        updateStatusBar();
212  #else  #else
213      //printf("inserted %d\n", length);      //printf("inserted %d\n", length);
214      Gtk::TextBuffer::iterator itStart = itEnd;      Gtk::TextBuffer::iterator itStart = itEnd;
# Line 293  void ScriptEditor::updateParserIssuesByV Line 323  void ScriptEditor::updateParserIssuesByV
323      const std::string s = m_textBuffer->get_text();      const std::string s = m_textBuffer->get_text();
324      LinuxSampler::VMParserContext* parserContext = m_vm->loadScript(s);      LinuxSampler::VMParserContext* parserContext = m_vm->loadScript(s);
325      m_issues = parserContext->issues();      m_issues = parserContext->issues();
326        m_errors = parserContext->errors();
327        m_warnings = parserContext->warnings();
328    
329      for (int i = 0; i < m_issues.size(); ++i) {      for (int i = 0; i < m_issues.size(); ++i) {
330          const LinuxSampler::ParserIssue& issue = m_issues[i];          const LinuxSampler::ParserIssue& issue = m_issues[i];
# Line 340  void ScriptEditor::updateIssueTooltip(Gd Line 372  void ScriptEditor::updateIssueTooltip(Gd
372      m_textView.set_tooltip_markup("");      m_textView.set_tooltip_markup("");
373  }  }
374    
375    static std::string warningsCountTxt(const std::vector<LinuxSampler::ParserIssue> warnings) {
376        std::string txt = "<span foreground=\"#c4950c\">" + ToString(warnings.size());
377        txt += (warnings.size() == 1) ? " Warning" : " Warnings";
378        txt += "</span>";
379        return txt;
380    }
381    
382    static std::string errorsCountTxt(const std::vector<LinuxSampler::ParserIssue> errors) {
383        std::string txt = "<span foreground=\"#c40c0c\">" + ToString(errors.size());
384        txt += (errors.size() == 1) ? " Error" : " Errors";
385        txt += "</span>";
386        return txt;
387    }
388    
389    void ScriptEditor::updateStatusBar() {
390        // update status text
391        std::string txt;
392        if (m_issues.empty()) {
393            txt = "No issues with this script.";
394        } else {
395            const char* txtWontLoad = ". Sampler won't load instruments using this script!";
396            txt = "There ";
397            txt += (m_errors.size() <= 1 && m_warnings.size() <= 1) ? "is " : "are ";
398            if (m_errors.empty()) {
399                txt += warningsCountTxt(m_warnings) + ". Script will load, but might not behave as expected!";
400            } else if (m_warnings.empty()) {
401                txt += errorsCountTxt(m_errors) + txtWontLoad;
402            } else {
403                txt += errorsCountTxt(m_errors) + " and " +
404                       warningsCountTxt(m_warnings) + txtWontLoad;
405            }
406        }
407        m_statusLabel.set_markup(txt);
408    
409        // update status icon
410        m_statusImage.set(
411            m_issues.empty() ? m_successIcon : !m_errors.empty() ? m_errorIcon : m_warningIcon
412        );
413    }
414    
415  #endif // USE_LS_SCRIPTVM  #endif // USE_LS_SCRIPTVM
416    
417  void ScriptEditor::onTextErased(const Gtk::TextBuffer::iterator& itStart, const Gtk::TextBuffer::iterator& itEnd) {  void ScriptEditor::onTextErased(const Gtk::TextBuffer::iterator& itStart, const Gtk::TextBuffer::iterator& itEnd) {
# Line 348  void ScriptEditor::onTextErased(const Gt Line 420  void ScriptEditor::onTextErased(const Gt
420      m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end());      m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end());
421      updateSyntaxHighlightingByVM();      updateSyntaxHighlightingByVM();
422      updateParserIssuesByVM();      updateParserIssuesByVM();
423        updateStatusBar();
424  #else  #else
425      Gtk::TextBuffer::iterator itStart2 = itStart;      Gtk::TextBuffer::iterator itStart2 = itStart;
426      if (itStart2.inside_word() || itStart2.ends_word())      if (itStart2.inside_word() || itStart2.ends_word())
# Line 411  bool ScriptEditor::isModified() const { Line 484  bool ScriptEditor::isModified() const {
484    
485  void ScriptEditor::onModifiedChanged() {  void ScriptEditor::onModifiedChanged() {
486      m_applyButton.set_sensitive(isModified());      m_applyButton.set_sensitive(isModified());
487    #if USE_LS_SCRIPTVM
488        updateStatusBar();
489    #endif
490  }  }
491    
492  void ScriptEditor::onButtonCancel() {  void ScriptEditor::onButtonCancel() {

Legend:
Removed from v.2898  
changed lines
  Added in v.2899

  ViewVC Help
Powered by ViewVC