9 |
#include "global.h" |
#include "global.h" |
10 |
#if USE_LS_SCRIPTVM |
#if USE_LS_SCRIPTVM |
11 |
# include <linuxsampler/scriptvm/ScriptVM.h> |
# include <linuxsampler/scriptvm/ScriptVM.h> |
12 |
|
# include <linuxsampler/scriptvm/ScriptVMFactory.h> |
13 |
#endif |
#endif |
14 |
|
|
15 |
#if !USE_LS_SCRIPTVM |
#if !USE_LS_SCRIPTVM |
84 |
m_preprocTag->property_foreground() = "#2f8a33"; // green |
m_preprocTag->property_foreground() = "#2f8a33"; // green |
85 |
m_tagTable->add(m_preprocTag); |
m_tagTable->add(m_preprocTag); |
86 |
|
|
87 |
|
m_errorTag = Gtk::TextBuffer::Tag::create(); |
88 |
|
m_errorTag->property_background() = "#ff9393"; // red |
89 |
|
m_tagTable->add(m_errorTag); |
90 |
|
|
91 |
|
m_warningTag = Gtk::TextBuffer::Tag::create(); |
92 |
|
m_warningTag->property_background() = "#fffd7c"; // yellow |
93 |
|
m_tagTable->add(m_warningTag); |
94 |
|
|
95 |
m_textBuffer = Gtk::TextBuffer::create(m_tagTable); |
m_textBuffer = Gtk::TextBuffer::create(m_tagTable); |
96 |
m_textView.set_buffer(m_textBuffer); |
m_textView.set_buffer(m_textBuffer); |
97 |
{ |
{ |
171 |
|
|
172 |
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) { |
173 |
#if USE_LS_SCRIPTVM |
#if USE_LS_SCRIPTVM |
174 |
|
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
175 |
updateSyntaxHighlightingByVM(); |
updateSyntaxHighlightingByVM(); |
176 |
|
updateParserIssuesByVM(); |
177 |
#else |
#else |
178 |
//printf("inserted %d\n", length); |
//printf("inserted %d\n", length); |
179 |
Gtk::TextBuffer::iterator itStart = itEnd; |
Gtk::TextBuffer::iterator itStart = itEnd; |
221 |
|
|
222 |
#if USE_LS_SCRIPTVM |
#if USE_LS_SCRIPTVM |
223 |
|
|
224 |
|
LinuxSampler::ScriptVM* ScriptEditor::GetScriptVM() { |
225 |
|
if (!m_vm) m_vm = LinuxSampler::ScriptVMFactory::Create("gig"); |
226 |
|
return m_vm; |
227 |
|
} |
228 |
|
|
229 |
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) { |
230 |
Gtk::TextBuffer::iterator itStart = |
Gtk::TextBuffer::iterator itStart = |
231 |
txtbuf->get_iter_at_line_index(token.firstLine(), token.firstColumn()); |
txtbuf->get_iter_at_line_index(token.firstLine(), token.firstColumn()); |
235 |
txtbuf->apply_tag(tag, itStart, itEnd); |
txtbuf->apply_tag(tag, itStart, itEnd); |
236 |
} |
} |
237 |
|
|
238 |
|
static void applyCodeTag(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::ParserIssue& issue, Glib::RefPtr<Gtk::TextBuffer::Tag>& tag) { |
239 |
|
Gtk::TextBuffer::iterator itStart = |
240 |
|
txtbuf->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1); |
241 |
|
Gtk::TextBuffer::iterator itEnd = itStart; |
242 |
|
itEnd.forward_lines(issue.lastLine - issue.firstLine); |
243 |
|
itEnd.forward_chars( |
244 |
|
(issue.lastLine != issue.firstLine) |
245 |
|
? issue.lastColumn - 1 |
246 |
|
: issue.lastColumn - issue.firstColumn + 1 |
247 |
|
); |
248 |
|
txtbuf->apply_tag(tag, itStart, itEnd); |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
253 |
if (!m_vm) m_vm = new LinuxSampler::ScriptVM(); |
GetScriptVM(); |
254 |
const std::string s = m_textBuffer->get_text(); |
const std::string s = m_textBuffer->get_text(); |
255 |
std::vector<LinuxSampler::VMSourceToken> tokens = m_vm->syntaxHighlighting(s); |
std::vector<LinuxSampler::VMSourceToken> tokens = m_vm->syntaxHighlighting(s); |
256 |
|
|
|
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
|
|
|
|
257 |
for (int i = 0; i < tokens.size(); ++i) { |
for (int i = 0; i < tokens.size(); ++i) { |
258 |
const LinuxSampler::VMSourceToken& token = tokens[i]; |
const LinuxSampler::VMSourceToken& token = tokens[i]; |
259 |
|
|
280 |
} |
} |
281 |
} |
} |
282 |
|
|
283 |
|
void ScriptEditor::updateParserIssuesByVM() { |
284 |
|
GetScriptVM(); |
285 |
|
const std::string s = m_textBuffer->get_text(); |
286 |
|
LinuxSampler::VMParserContext* parserContext = m_vm->loadScript(s); |
287 |
|
std::vector<LinuxSampler::ParserIssue> issues = parserContext->issues(); |
288 |
|
|
289 |
|
for (int i = 0; i < issues.size(); ++i) { |
290 |
|
const LinuxSampler::ParserIssue& issue = issues[i]; |
291 |
|
|
292 |
|
if (issue.isErr()) { |
293 |
|
applyCodeTag(m_textBuffer, issue, m_errorTag); |
294 |
|
} else if (issue.isWrn()) { |
295 |
|
applyCodeTag(m_textBuffer, issue, m_warningTag); |
296 |
|
} |
297 |
|
} |
298 |
|
|
299 |
|
delete parserContext; |
300 |
|
} |
301 |
|
|
302 |
#endif // USE_LS_SCRIPTVM |
#endif // USE_LS_SCRIPTVM |
303 |
|
|
304 |
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) { |
305 |
//printf("erased\n"); |
//printf("erased\n"); |
306 |
#if USE_LS_SCRIPTVM |
#if USE_LS_SCRIPTVM |
307 |
|
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
308 |
updateSyntaxHighlightingByVM(); |
updateSyntaxHighlightingByVM(); |
309 |
|
updateParserIssuesByVM(); |
310 |
#else |
#else |
311 |
Gtk::TextBuffer::iterator itStart2 = itStart; |
Gtk::TextBuffer::iterator itStart2 = itStart; |
312 |
if (itStart2.inside_word() || itStart2.ends_word()) |
if (itStart2.inside_word() || itStart2.ends_word()) |