7 |
|
|
8 |
#include "scripteditor.h" |
#include "scripteditor.h" |
9 |
#include "global.h" |
#include "global.h" |
|
#if USE_LS_SCRIPTVM |
|
|
# include <linuxsampler/scriptvm/ScriptVM.h> |
|
|
# include <linuxsampler/scriptvm/ScriptVMFactory.h> |
|
|
#endif |
|
10 |
|
|
11 |
#if !USE_LS_SCRIPTVM |
#if !USE_LS_SCRIPTVM |
12 |
|
|
40 |
m_cancelButton(_("_Cancel"), true) |
m_cancelButton(_("_Cancel"), true) |
41 |
{ |
{ |
42 |
m_script = NULL; |
m_script = NULL; |
43 |
|
#if USE_LS_SCRIPTVM |
44 |
m_vm = NULL; |
m_vm = NULL; |
45 |
|
#endif |
46 |
|
m_ignoreEraseEvents = false; |
47 |
|
|
48 |
add(m_vbox); |
add(m_vbox); |
49 |
|
|
91 |
m_warningTag->property_background() = "#fffd7c"; // yellow |
m_warningTag->property_background() = "#fffd7c"; // yellow |
92 |
m_tagTable->add(m_warningTag); |
m_tagTable->add(m_warningTag); |
93 |
|
|
94 |
|
m_readOnlyTag = Gtk::TextBuffer::Tag::create(); |
95 |
|
m_readOnlyTag->property_editable() = false; |
96 |
|
m_tagTable->add(m_readOnlyTag); |
97 |
|
|
98 |
m_textBuffer = Gtk::TextBuffer::create(m_tagTable); |
m_textBuffer = Gtk::TextBuffer::create(m_tagTable); |
99 |
m_textView.set_buffer(m_textBuffer); |
m_textView.set_buffer(m_textBuffer); |
100 |
{ |
{ |
154 |
|
|
155 |
ScriptEditor::~ScriptEditor() { |
ScriptEditor::~ScriptEditor() { |
156 |
printf("ScriptEditor destruct\n"); |
printf("ScriptEditor destruct\n"); |
157 |
|
#if USE_LS_SCRIPTVM |
158 |
if (m_vm) delete m_vm; |
if (m_vm) delete m_vm; |
159 |
|
#endif |
160 |
} |
} |
161 |
|
|
162 |
void ScriptEditor::setScript(gig::Script* script) { |
void ScriptEditor::setScript(gig::Script* script) { |
175 |
} |
} |
176 |
|
|
177 |
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) { |
178 |
|
printf("onTextInserted()\n"); |
179 |
|
fflush(stdout); |
180 |
#if USE_LS_SCRIPTVM |
#if USE_LS_SCRIPTVM |
181 |
|
removeIssueAnchors(); |
182 |
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
183 |
updateSyntaxHighlightingByVM(); |
updateSyntaxHighlightingByVM(); |
184 |
updateParserIssuesByVM(); |
updateParserIssuesByVM(); |
256 |
txtbuf->apply_tag(tag, itStart, itEnd); |
txtbuf->apply_tag(tag, itStart, itEnd); |
257 |
} |
} |
258 |
|
|
259 |
|
void ScriptEditor::removeIssueAnchors() { |
260 |
|
m_ignoreEraseEvents = true; // avoid endless recursion |
261 |
|
|
262 |
|
for (int i = 0; i < m_issues.size(); ++i) { |
263 |
|
const LinuxSampler::ParserIssue& issue = m_issues[i]; |
264 |
|
printf("erase anchor at l%d c%d\n", issue.firstLine - 1, issue.firstColumn - 1); |
265 |
|
fflush(stdout); |
266 |
|
Gtk::TextBuffer::iterator iter = m_textBuffer->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1); |
267 |
|
Gtk::TextBuffer::iterator iterEnd = iter; |
268 |
|
iterEnd.forward_chars(1); |
269 |
|
m_textBuffer->erase(iter, iterEnd); |
270 |
|
} |
271 |
|
|
272 |
|
m_ignoreEraseEvents = false; // back to normal |
273 |
|
} |
274 |
|
|
275 |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
276 |
GetScriptVM(); |
GetScriptVM(); |
303 |
} |
} |
304 |
} |
} |
305 |
|
|
306 |
|
static Glib::RefPtr<Gdk::Pixbuf> createIcon(std::string name, const Glib::RefPtr<Gdk::Screen>& screen) { |
307 |
|
const int targetH = 9; |
308 |
|
Glib::RefPtr<Gtk::IconTheme> theme = Gtk::IconTheme::get_for_screen(screen); |
309 |
|
int w = 0; |
310 |
|
int h = 0; // ignored |
311 |
|
Gtk::IconSize::lookup(Gtk::ICON_SIZE_SMALL_TOOLBAR, w, h); |
312 |
|
Glib::RefPtr<Gdk::Pixbuf> pixbuf = theme->load_icon(name, w, Gtk::ICON_LOOKUP_GENERIC_FALLBACK); |
313 |
|
if (pixbuf->get_height() != targetH) { |
314 |
|
pixbuf = pixbuf->scale_simple(targetH, targetH, Gdk::INTERP_BILINEAR); |
315 |
|
} |
316 |
|
return pixbuf; |
317 |
|
} |
318 |
|
|
319 |
void ScriptEditor::updateParserIssuesByVM() { |
void ScriptEditor::updateParserIssuesByVM() { |
320 |
GetScriptVM(); |
GetScriptVM(); |
321 |
const std::string s = m_textBuffer->get_text(); |
const std::string s = m_textBuffer->get_text(); |
322 |
LinuxSampler::VMParserContext* parserContext = m_vm->loadScript(s); |
LinuxSampler::VMParserContext* parserContext = m_vm->loadScript(s); |
323 |
std::vector<LinuxSampler::ParserIssue> issues = parserContext->issues(); |
m_issues = parserContext->issues(); |
324 |
|
|
325 |
for (int i = 0; i < issues.size(); ++i) { |
for (int i = 0; i < m_issues.size(); ++i) { |
326 |
const LinuxSampler::ParserIssue& issue = issues[i]; |
const LinuxSampler::ParserIssue& issue = m_issues[i]; |
327 |
|
|
328 |
if (issue.isErr()) { |
if (issue.isErr()) { |
329 |
applyCodeTag(m_textBuffer, issue, m_errorTag); |
applyCodeTag(m_textBuffer, issue, m_errorTag); |
332 |
} |
} |
333 |
} |
} |
334 |
|
|
335 |
|
for (int i = m_issues.size() - 1; i >= 0; --i) { |
336 |
|
const LinuxSampler::ParserIssue& issue = m_issues[i]; |
337 |
|
|
338 |
|
if (issue.isErr() || issue.isWrn()) { |
339 |
|
Glib::RefPtr<Gdk::Pixbuf> pixbuf = createIcon(issue.isErr() ? "dialog-error" : "dialog-warning-symbolic", get_screen()); |
340 |
|
Gtk::Image* image = Gtk::manage(new Gtk::Image(pixbuf)); |
341 |
|
image->show(); |
342 |
|
Gtk::TextBuffer::iterator iter = |
343 |
|
m_textBuffer->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1); |
344 |
|
Glib::RefPtr<Gtk::TextChildAnchor> anchor = m_textBuffer->create_child_anchor(iter); |
345 |
|
m_textView.add_child_at_anchor(*image, anchor); |
346 |
|
|
347 |
|
iter = |
348 |
|
m_textBuffer->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1); |
349 |
|
Gtk::TextBuffer::iterator itEnd = iter; |
350 |
|
itEnd.forward_char(); |
351 |
|
|
352 |
|
// prevent that the user can erase the icon with backspace key |
353 |
|
m_textBuffer->apply_tag(m_readOnlyTag, iter, itEnd); |
354 |
|
} |
355 |
|
} |
356 |
|
|
357 |
delete parserContext; |
delete parserContext; |
358 |
} |
} |
359 |
|
|
361 |
|
|
362 |
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) { |
363 |
//printf("erased\n"); |
//printf("erased\n"); |
364 |
|
if (m_ignoreEraseEvents) return; |
365 |
|
|
366 |
#if USE_LS_SCRIPTVM |
#if USE_LS_SCRIPTVM |
367 |
|
removeIssueAnchors(); |
368 |
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
369 |
updateSyntaxHighlightingByVM(); |
updateSyntaxHighlightingByVM(); |
370 |
updateParserIssuesByVM(); |
updateParserIssuesByVM(); |