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. |
12 |
|
|
13 |
static const std::string _keywords[] = { |
static const std::string _keywords[] = { |
14 |
"on", "end", "declare", "while", "if", "or", "and", "not", "else", "case", |
"on", "end", "declare", "while", "if", "or", "and", "not", "else", "case", |
15 |
"select", "to", "const", "polyphonic", "mod" |
"select", "to", "const", "polyphonic", "mod", "synchronized" |
16 |
}; |
}; |
17 |
static int _keywordsSz = sizeof(_keywords) / sizeof(std::string); |
static int _keywordsSz = sizeof(_keywords) / sizeof(std::string); |
18 |
|
|
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 |
132 |
m_commentTag->property_foreground() = "#9c9c9c"; // gray |
m_commentTag->property_foreground() = "#9c9c9c"; // gray |
133 |
m_tagTable->add(m_commentTag); |
m_tagTable->add(m_commentTag); |
134 |
|
|
135 |
|
#define PREPROC_TOKEN_COLOR "#2f8a33" // green |
136 |
|
|
137 |
m_preprocTag = Gtk::TextBuffer::Tag::create(); |
m_preprocTag = Gtk::TextBuffer::Tag::create(); |
138 |
m_preprocTag->property_foreground() = "#2f8a33"; // green |
m_preprocTag->property_foreground() = PREPROC_TOKEN_COLOR; |
139 |
m_tagTable->add(m_preprocTag); |
m_tagTable->add(m_preprocTag); |
140 |
|
|
141 |
|
m_preprocCommentTag = Gtk::TextBuffer::Tag::create(); |
142 |
|
m_preprocCommentTag->property_strikethrough() = true; |
143 |
|
m_preprocCommentTag->property_background() = "#e5e5e5"; |
144 |
|
m_tagTable->add(m_preprocCommentTag); |
145 |
|
|
146 |
m_errorTag = Gtk::TextBuffer::Tag::create(); |
m_errorTag = Gtk::TextBuffer::Tag::create(); |
147 |
m_errorTag->property_background() = "#ff9393"; // red |
m_errorTag->property_background() = "#ff9393"; // red |
148 |
m_tagTable->add(m_errorTag); |
m_tagTable->add(m_errorTag); |
350 |
return m_vm; |
return m_vm; |
351 |
} |
} |
352 |
|
|
353 |
static void getIteratorsForIssue(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::ParserIssue& issue, Gtk::TextBuffer::iterator& start, Gtk::TextBuffer::iterator& end) { |
template<class T> |
354 |
|
static void getIteratorsForIssue(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const T& issue, Gtk::TextBuffer::iterator& start, Gtk::TextBuffer::iterator& end) { |
355 |
Gtk::TextBuffer::iterator itLine = |
Gtk::TextBuffer::iterator itLine = |
356 |
txtbuf->get_iter_at_line_index(issue.firstLine - 1, 0); |
txtbuf->get_iter_at_line_index(issue.firstLine - 1, 0); |
357 |
const int charsInLine = itLine.get_bytes_in_line(); |
const int charsInLine = itLine.get_bytes_in_line(); |
390 |
txtbuf->apply_tag(tag, itStart, itEnd); |
txtbuf->apply_tag(tag, itStart, itEnd); |
391 |
} |
} |
392 |
|
|
393 |
|
static void applyPreprocessorComment(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::CodeBlock& block, Glib::RefPtr<Gtk::TextBuffer::Tag>& tag) { |
394 |
|
Gtk::TextBuffer::iterator itStart, itEnd; |
395 |
|
getIteratorsForIssue(txtbuf, block, itStart, itEnd); |
396 |
|
txtbuf->apply_tag(tag, itStart, itEnd); |
397 |
|
} |
398 |
|
|
399 |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
400 |
GetScriptVM(); |
GetScriptVM(); |
401 |
const std::string s = m_textBuffer->get_text(); |
const std::string s = m_textBuffer->get_text(); |
435 |
m_issues = parserContext->issues(); |
m_issues = parserContext->issues(); |
436 |
m_errors = parserContext->errors(); |
m_errors = parserContext->errors(); |
437 |
m_warnings = parserContext->warnings(); |
m_warnings = parserContext->warnings(); |
438 |
|
m_preprocComments = parserContext->preprocessorComments(); |
439 |
|
|
440 |
if (!s.empty()) { |
if (!s.empty()) { |
441 |
for (int i = 0; i < m_issues.size(); ++i) { |
for (int i = 0; i < m_issues.size(); ++i) { |
449 |
} |
} |
450 |
} |
} |
451 |
|
|
452 |
|
for (int i = 0; i < m_preprocComments.size(); ++i) { |
453 |
|
applyPreprocessorComment(m_textBuffer, m_preprocComments[i], |
454 |
|
m_preprocCommentTag); |
455 |
|
} |
456 |
|
|
457 |
delete parserContext; |
delete parserContext; |
458 |
} |
} |
459 |
|
|
485 |
); |
); |
486 |
return; |
return; |
487 |
} |
} |
488 |
|
} |
489 |
|
|
490 |
|
for (int i = 0; i < m_preprocComments.size(); ++i) { |
491 |
|
const LinuxSampler::CodeBlock& block = m_preprocComments[i]; |
492 |
|
const int firstLine = block.firstLine - 1; |
493 |
|
const int firstColumn = block.firstColumn - 1; |
494 |
|
const int lastLine = block.lastLine - 1; |
495 |
|
const int lastColumn = block.lastColumn - 1; |
496 |
|
if (firstLine <= line && line <= lastLine && |
497 |
|
(firstLine != line || firstColumn <= column) && |
498 |
|
(lastLine != line || lastColumn >= column)) |
499 |
|
{ |
500 |
|
m_textView.set_tooltip_markup( |
501 |
|
"Code block filtered out by preceding <span foreground=\"" PREPROC_TOKEN_COLOR "\">preprocessor</span> statement." |
502 |
|
); |
503 |
|
return; |
504 |
|
} |
505 |
} |
} |
506 |
|
|
507 |
m_textView.set_tooltip_markup(""); |
m_textView.set_tooltip_markup(""); |