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 |
339 |
} |
} |
340 |
|
|
341 |
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) { |
342 |
start = txtbuf->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1); |
Gtk::TextBuffer::iterator itLine = |
343 |
|
txtbuf->get_iter_at_line_index(issue.firstLine - 1, 0); |
344 |
|
const int charsInLine = itLine.get_bytes_in_line(); |
345 |
|
start = txtbuf->get_iter_at_line_index( |
346 |
|
issue.firstLine - 1, |
347 |
|
// check we are not getting past the end of the line here, otherwise Gtk crashes |
348 |
|
issue.firstColumn - 1 < charsInLine ? issue.firstColumn - 1 : charsInLine - 1 |
349 |
|
); |
350 |
end = start; |
end = start; |
351 |
end.forward_lines(issue.lastLine - issue.firstLine); |
end.forward_lines(issue.lastLine - issue.firstLine); |
352 |
end.forward_chars( |
end.forward_chars( |
357 |
} |
} |
358 |
|
|
359 |
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) { |
360 |
Gtk::TextBuffer::iterator itStart = |
Gtk::TextBuffer::iterator itLine = |
361 |
txtbuf->get_iter_at_line_index(token.firstLine(), token.firstColumn()); |
txtbuf->get_iter_at_line_index(token.firstLine(), 0); |
362 |
|
const int charsInLine = itLine.get_bytes_in_line(); |
363 |
|
Gtk::TextBuffer::iterator itStart = txtbuf->get_iter_at_line_index( |
364 |
|
token.firstLine(), |
365 |
|
// check we are not getting past the end of the line here, otherwise Gtk crashes |
366 |
|
token.firstColumn() < charsInLine ? token.firstColumn() : charsInLine - 1 |
367 |
|
); |
368 |
Gtk::TextBuffer::iterator itEnd = itStart; |
Gtk::TextBuffer::iterator itEnd = itStart; |
369 |
const int length = token.text().length(); |
const int length = token.text().length(); |
370 |
itEnd.forward_chars(length); |
itEnd.forward_chars(length); |
380 |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
381 |
GetScriptVM(); |
GetScriptVM(); |
382 |
const std::string s = m_textBuffer->get_text(); |
const std::string s = m_textBuffer->get_text(); |
383 |
|
if (s.empty()) return; |
384 |
std::vector<LinuxSampler::VMSourceToken> tokens = m_vm->syntaxHighlighting(s); |
std::vector<LinuxSampler::VMSourceToken> tokens = m_vm->syntaxHighlighting(s); |
385 |
|
|
386 |
for (int i = 0; i < tokens.size(); ++i) { |
for (int i = 0; i < tokens.size(); ++i) { |
417 |
m_errors = parserContext->errors(); |
m_errors = parserContext->errors(); |
418 |
m_warnings = parserContext->warnings(); |
m_warnings = parserContext->warnings(); |
419 |
|
|
420 |
for (int i = 0; i < m_issues.size(); ++i) { |
if (!s.empty()) { |
421 |
const LinuxSampler::ParserIssue& issue = m_issues[i]; |
for (int i = 0; i < m_issues.size(); ++i) { |
422 |
|
const LinuxSampler::ParserIssue& issue = m_issues[i]; |
423 |
if (issue.isErr()) { |
|
424 |
applyCodeTag(m_textBuffer, issue, m_errorTag); |
if (issue.isErr()) { |
425 |
} else if (issue.isWrn()) { |
applyCodeTag(m_textBuffer, issue, m_errorTag); |
426 |
applyCodeTag(m_textBuffer, issue, m_warningTag); |
} else if (issue.isWrn()) { |
427 |
|
applyCodeTag(m_textBuffer, issue, m_warningTag); |
428 |
|
} |
429 |
} |
} |
430 |
} |
} |
431 |
|
|