--- gigedit/trunk/src/gigedit/scripteditor.cpp 2017/05/31 21:11:56 3261 +++ gigedit/trunk/src/gigedit/scripteditor.cpp 2017/06/22 10:54:10 3286 @@ -132,10 +132,17 @@ m_commentTag->property_foreground() = "#9c9c9c"; // gray m_tagTable->add(m_commentTag); + #define PREPROC_TOKEN_COLOR "#2f8a33" // green + m_preprocTag = Gtk::TextBuffer::Tag::create(); - m_preprocTag->property_foreground() = "#2f8a33"; // green + m_preprocTag->property_foreground() = PREPROC_TOKEN_COLOR; m_tagTable->add(m_preprocTag); + m_preprocCommentTag = Gtk::TextBuffer::Tag::create(); + m_preprocCommentTag->property_strikethrough() = true; + m_preprocCommentTag->property_background() = "#e5e5e5"; + m_tagTable->add(m_preprocCommentTag); + m_errorTag = Gtk::TextBuffer::Tag::create(); m_errorTag->property_background() = "#ff9393"; // red m_tagTable->add(m_errorTag); @@ -343,7 +350,8 @@ return m_vm; } -static void getIteratorsForIssue(Glib::RefPtr& txtbuf, const LinuxSampler::ParserIssue& issue, Gtk::TextBuffer::iterator& start, Gtk::TextBuffer::iterator& end) { +template +static void getIteratorsForIssue(Glib::RefPtr& txtbuf, const T& issue, Gtk::TextBuffer::iterator& start, Gtk::TextBuffer::iterator& end) { Gtk::TextBuffer::iterator itLine = txtbuf->get_iter_at_line_index(issue.firstLine - 1, 0); const int charsInLine = itLine.get_bytes_in_line(); @@ -382,6 +390,12 @@ txtbuf->apply_tag(tag, itStart, itEnd); } +static void applyPreprocessorComment(Glib::RefPtr& txtbuf, const LinuxSampler::CodeBlock& block, Glib::RefPtr& tag) { + Gtk::TextBuffer::iterator itStart, itEnd; + getIteratorsForIssue(txtbuf, block, itStart, itEnd); + txtbuf->apply_tag(tag, itStart, itEnd); +} + void ScriptEditor::updateSyntaxHighlightingByVM() { GetScriptVM(); const std::string s = m_textBuffer->get_text(); @@ -421,6 +435,7 @@ m_issues = parserContext->issues(); m_errors = parserContext->errors(); m_warnings = parserContext->warnings(); + m_preprocComments = parserContext->preprocessorComments(); if (!s.empty()) { for (int i = 0; i < m_issues.size(); ++i) { @@ -434,6 +449,11 @@ } } + for (int i = 0; i < m_preprocComments.size(); ++i) { + applyPreprocessorComment(m_textBuffer, m_preprocComments[i], + m_preprocCommentTag); + } + delete parserContext; } @@ -465,6 +485,23 @@ ); return; } + } + + for (int i = 0; i < m_preprocComments.size(); ++i) { + const LinuxSampler::CodeBlock& block = m_preprocComments[i]; + const int firstLine = block.firstLine - 1; + const int firstColumn = block.firstColumn - 1; + const int lastLine = block.lastLine - 1; + const int lastColumn = block.lastColumn - 1; + if (firstLine <= line && line <= lastLine && + (firstLine != line || firstColumn <= column) && + (lastLine != line || lastColumn >= column)) + { + m_textView.set_tooltip_markup( + "Code block filtered out by preceding preprocessor statement." + ); + return; + } } m_textView.set_tooltip_markup("");