43 |
#if USE_LS_SCRIPTVM |
#if USE_LS_SCRIPTVM |
44 |
m_vm = NULL; |
m_vm = NULL; |
45 |
#endif |
#endif |
|
m_ignoreEraseEvents = false; |
|
46 |
|
|
47 |
add(m_vbox); |
add(m_vbox); |
48 |
|
|
90 |
m_warningTag->property_background() = "#fffd7c"; // yellow |
m_warningTag->property_background() = "#fffd7c"; // yellow |
91 |
m_tagTable->add(m_warningTag); |
m_tagTable->add(m_warningTag); |
92 |
|
|
|
m_readOnlyTag = Gtk::TextBuffer::Tag::create(); |
|
|
m_readOnlyTag->property_editable() = false; |
|
|
m_tagTable->add(m_readOnlyTag); |
|
|
|
|
93 |
m_textBuffer = Gtk::TextBuffer::create(m_tagTable); |
m_textBuffer = Gtk::TextBuffer::create(m_tagTable); |
94 |
m_textView.set_buffer(m_textBuffer); |
m_textView.set_buffer(m_textBuffer); |
95 |
{ |
{ |
142 |
sigc::mem_fun(*this, &ScriptEditor::onWindowHide) |
sigc::mem_fun(*this, &ScriptEditor::onWindowHide) |
143 |
); |
); |
144 |
|
|
145 |
|
signal_delete_event().connect( |
146 |
|
sigc::mem_fun(*this, &ScriptEditor::onWindowDelete) |
147 |
|
); |
148 |
|
|
149 |
show_all_children(); |
show_all_children(); |
150 |
|
|
151 |
resize(460,300); |
resize(460,300); |
174 |
} |
} |
175 |
|
|
176 |
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) { |
177 |
printf("onTextInserted()\n"); |
//printf("onTextInserted()\n"); |
|
fflush(stdout); |
|
178 |
#if USE_LS_SCRIPTVM |
#if USE_LS_SCRIPTVM |
|
removeIssueAnchors(); |
|
179 |
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
180 |
updateSyntaxHighlightingByVM(); |
updateSyntaxHighlightingByVM(); |
181 |
updateParserIssuesByVM(); |
updateParserIssuesByVM(); |
231 |
return m_vm; |
return m_vm; |
232 |
} |
} |
233 |
|
|
234 |
|
static void getIteratorsForIssue(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::ParserIssue& issue, Gtk::TextBuffer::iterator& start, Gtk::TextBuffer::iterator& end) { |
235 |
|
start = txtbuf->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1); |
236 |
|
end = start; |
237 |
|
end.forward_lines(issue.lastLine - issue.firstLine); |
238 |
|
end.forward_chars( |
239 |
|
(issue.lastLine != issue.firstLine) |
240 |
|
? issue.lastColumn - 1 |
241 |
|
: issue.lastColumn - issue.firstColumn + 1 |
242 |
|
); |
243 |
|
} |
244 |
|
|
245 |
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) { |
246 |
Gtk::TextBuffer::iterator itStart = |
Gtk::TextBuffer::iterator itStart = |
247 |
txtbuf->get_iter_at_line_index(token.firstLine(), token.firstColumn()); |
txtbuf->get_iter_at_line_index(token.firstLine(), token.firstColumn()); |
252 |
} |
} |
253 |
|
|
254 |
static void applyCodeTag(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::ParserIssue& issue, Glib::RefPtr<Gtk::TextBuffer::Tag>& tag) { |
static void applyCodeTag(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::ParserIssue& issue, Glib::RefPtr<Gtk::TextBuffer::Tag>& tag) { |
255 |
Gtk::TextBuffer::iterator itStart = |
Gtk::TextBuffer::iterator itStart, itEnd; |
256 |
txtbuf->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1); |
getIteratorsForIssue(txtbuf, issue, itStart, itEnd); |
|
Gtk::TextBuffer::iterator itEnd = itStart; |
|
|
itEnd.forward_lines(issue.lastLine - issue.firstLine); |
|
|
itEnd.forward_chars( |
|
|
(issue.lastLine != issue.firstLine) |
|
|
? issue.lastColumn - 1 |
|
|
: issue.lastColumn - issue.firstColumn + 1 |
|
|
); |
|
257 |
txtbuf->apply_tag(tag, itStart, itEnd); |
txtbuf->apply_tag(tag, itStart, itEnd); |
258 |
} |
} |
259 |
|
|
|
void ScriptEditor::removeIssueAnchors() { |
|
|
m_ignoreEraseEvents = true; // avoid endless recursion |
|
|
|
|
|
for (int i = 0; i < m_issues.size(); ++i) { |
|
|
const LinuxSampler::ParserIssue& issue = m_issues[i]; |
|
|
printf("erase anchor at l%d c%d\n", issue.firstLine - 1, issue.firstColumn - 1); |
|
|
fflush(stdout); |
|
|
Gtk::TextBuffer::iterator iter = m_textBuffer->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1); |
|
|
Gtk::TextBuffer::iterator iterEnd = iter; |
|
|
iterEnd.forward_chars(1); |
|
|
m_textBuffer->erase(iter, iterEnd); |
|
|
} |
|
|
|
|
|
m_ignoreEraseEvents = false; // back to normal |
|
|
} |
|
|
|
|
260 |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
261 |
GetScriptVM(); |
GetScriptVM(); |
262 |
const std::string s = m_textBuffer->get_text(); |
const std::string s = m_textBuffer->get_text(); |
288 |
} |
} |
289 |
} |
} |
290 |
|
|
|
static Glib::RefPtr<Gdk::Pixbuf> createIcon(std::string name, const Glib::RefPtr<Gdk::Screen>& screen) { |
|
|
const int targetH = 9; |
|
|
Glib::RefPtr<Gtk::IconTheme> theme = Gtk::IconTheme::get_for_screen(screen); |
|
|
int w = 0; |
|
|
int h = 0; // ignored |
|
|
Gtk::IconSize::lookup(Gtk::ICON_SIZE_SMALL_TOOLBAR, w, h); |
|
|
Glib::RefPtr<Gdk::Pixbuf> pixbuf = theme->load_icon(name, w, Gtk::ICON_LOOKUP_GENERIC_FALLBACK); |
|
|
if (pixbuf->get_height() != targetH) { |
|
|
pixbuf = pixbuf->scale_simple(targetH, targetH, Gdk::INTERP_BILINEAR); |
|
|
} |
|
|
return pixbuf; |
|
|
} |
|
|
|
|
291 |
void ScriptEditor::updateParserIssuesByVM() { |
void ScriptEditor::updateParserIssuesByVM() { |
292 |
GetScriptVM(); |
GetScriptVM(); |
293 |
const std::string s = m_textBuffer->get_text(); |
const std::string s = m_textBuffer->get_text(); |
304 |
} |
} |
305 |
} |
} |
306 |
|
|
307 |
for (int i = m_issues.size() - 1; i >= 0; --i) { |
delete parserContext; |
308 |
const LinuxSampler::ParserIssue& issue = m_issues[i]; |
} |
309 |
|
|
310 |
|
void ScriptEditor::updateIssueTooltip(GdkEventMotion* e) { |
311 |
|
int x, y; |
312 |
|
m_textView.window_to_buffer_coords(Gtk::TEXT_WINDOW_TEXT, int(e->x), int(e->y), x, y); |
313 |
|
|
314 |
|
Gtk::TextBuffer::iterator it; |
315 |
|
m_textView.get_iter_at_location(it, x, y); |
316 |
|
|
317 |
|
const int line = it.get_line(); |
318 |
|
const int column = it.get_line_offset(); |
319 |
|
|
320 |
if (issue.isErr() || issue.isWrn()) { |
//printf("mouse at l%d c%d\n", line, column); |
|
Glib::RefPtr<Gdk::Pixbuf> pixbuf = createIcon(issue.isErr() ? "dialog-error" : "dialog-warning-symbolic", get_screen()); |
|
|
Gtk::Image* image = Gtk::manage(new Gtk::Image(pixbuf)); |
|
|
image->show(); |
|
|
Gtk::TextBuffer::iterator iter = |
|
|
m_textBuffer->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1); |
|
|
Glib::RefPtr<Gtk::TextChildAnchor> anchor = m_textBuffer->create_child_anchor(iter); |
|
|
m_textView.add_child_at_anchor(*image, anchor); |
|
|
|
|
|
iter = |
|
|
m_textBuffer->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1); |
|
|
Gtk::TextBuffer::iterator itEnd = iter; |
|
|
itEnd.forward_char(); |
|
321 |
|
|
322 |
// prevent that the user can erase the icon with backspace key |
for (int i = 0; i < m_issues.size(); ++i) { |
323 |
m_textBuffer->apply_tag(m_readOnlyTag, iter, itEnd); |
const LinuxSampler::ParserIssue& issue = m_issues[i]; |
324 |
|
const int firstLine = issue.firstLine - 1; |
325 |
|
const int firstColumn = issue.firstColumn - 1; |
326 |
|
const int lastLine = issue.lastLine - 1; |
327 |
|
const int lastColumn = issue.lastColumn - 1; |
328 |
|
if (firstLine <= line && line <= lastLine && |
329 |
|
(firstLine != line || firstColumn <= column) && |
330 |
|
(lastLine != line || lastColumn >= column)) |
331 |
|
{ |
332 |
|
m_textView.set_tooltip_markup( |
333 |
|
(issue.isErr() ? "<span foreground=\"#ff9393\">ERROR:</span> " : "<span foreground=\"#c4950c\">Warning:</span> ") + |
334 |
|
issue.txt |
335 |
|
); |
336 |
|
return; |
337 |
} |
} |
338 |
} |
} |
339 |
|
|
340 |
delete parserContext; |
m_textView.set_tooltip_markup(""); |
341 |
} |
} |
342 |
|
|
343 |
#endif // USE_LS_SCRIPTVM |
#endif // USE_LS_SCRIPTVM |
344 |
|
|
345 |
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) { |
346 |
//printf("erased\n"); |
//printf("erased\n"); |
|
if (m_ignoreEraseEvents) return; |
|
|
|
|
347 |
#if USE_LS_SCRIPTVM |
#if USE_LS_SCRIPTVM |
|
removeIssueAnchors(); |
|
348 |
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
349 |
updateSyntaxHighlightingByVM(); |
updateSyntaxHighlightingByVM(); |
350 |
updateParserIssuesByVM(); |
updateParserIssuesByVM(); |
360 |
#endif // USE_LS_SCRIPTVM |
#endif // USE_LS_SCRIPTVM |
361 |
} |
} |
362 |
|
|
363 |
|
bool ScriptEditor::on_motion_notify_event(GdkEventMotion* e) { |
364 |
|
#if USE_LS_SCRIPTVM |
365 |
|
//TODO: event throttling would be a good idea here |
366 |
|
updateIssueTooltip(e); |
367 |
|
#endif |
368 |
|
return ManagedWindow::on_motion_notify_event(e); |
369 |
|
} |
370 |
|
|
371 |
|
bool ScriptEditor::onWindowDelete(GdkEventAny* e) { |
372 |
|
//printf("onWindowDelete\n"); |
373 |
|
|
374 |
|
if (!isModified()) return false; // propagate event further (which will close this window) |
375 |
|
|
376 |
|
gchar* msg = g_strdup_printf(_("Apply changes to instrument script \"%s\" before closing?"), |
377 |
|
m_script->Name.c_str()); |
378 |
|
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
379 |
|
g_free(msg); |
380 |
|
dialog.set_secondary_text(_("If you close without applying, your changes will be lost.")); |
381 |
|
dialog.add_button(_("Close _Without Applying"), Gtk::RESPONSE_NO); |
382 |
|
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
383 |
|
dialog.add_button(_("_Apply"), Gtk::RESPONSE_YES); |
384 |
|
dialog.set_default_response(Gtk::RESPONSE_YES); |
385 |
|
int response = dialog.run(); |
386 |
|
dialog.hide(); |
387 |
|
|
388 |
|
// user decided to close script editor without saving |
389 |
|
if (response == Gtk::RESPONSE_NO) |
390 |
|
return false; // propagate event further (which will close this window) |
391 |
|
|
392 |
|
// user cancelled dialog, thus don't close script editor |
393 |
|
if (response == Gtk::RESPONSE_CANCEL) { |
394 |
|
show(); |
395 |
|
return true; // drop event (prevents closing this window) |
396 |
|
} |
397 |
|
|
398 |
|
// user wants to apply the changes, afterwards close window |
399 |
|
if (response == Gtk::RESPONSE_YES) { |
400 |
|
onButtonApply(); |
401 |
|
return false; // propagate event further (which will close this window) |
402 |
|
} |
403 |
|
|
404 |
|
// should never ever make it to this point actually |
405 |
|
return false; |
406 |
|
} |
407 |
|
|
408 |
|
bool ScriptEditor::isModified() const { |
409 |
|
return m_textBuffer->get_modified(); |
410 |
|
} |
411 |
|
|
412 |
void ScriptEditor::onModifiedChanged() { |
void ScriptEditor::onModifiedChanged() { |
413 |
m_applyButton.set_sensitive( m_textBuffer->get_modified() ); |
m_applyButton.set_sensitive(isModified()); |
414 |
} |
} |
415 |
|
|
416 |
void ScriptEditor::onButtonCancel() { |
void ScriptEditor::onButtonCancel() { |
417 |
|
bool dropEvent = onWindowDelete(NULL); |
418 |
|
if (dropEvent) return; |
419 |
hide(); |
hide(); |
420 |
} |
} |
421 |
|
|