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 |
{ |
{ |
170 |
} |
} |
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 |
printf("onTextInserted()\n"); |
//printf("onTextInserted()\n"); |
|
fflush(stdout); |
|
174 |
#if USE_LS_SCRIPTVM |
#if USE_LS_SCRIPTVM |
|
removeIssueAnchors(); |
|
175 |
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
176 |
updateSyntaxHighlightingByVM(); |
updateSyntaxHighlightingByVM(); |
177 |
updateParserIssuesByVM(); |
updateParserIssuesByVM(); |
227 |
return m_vm; |
return m_vm; |
228 |
} |
} |
229 |
|
|
230 |
|
static void getIteratorsForIssue(Glib::RefPtr<Gtk::TextBuffer>& txtbuf, const LinuxSampler::ParserIssue& issue, Gtk::TextBuffer::iterator& start, Gtk::TextBuffer::iterator& end) { |
231 |
|
start = txtbuf->get_iter_at_line_index(issue.firstLine - 1, issue.firstColumn - 1); |
232 |
|
end = start; |
233 |
|
end.forward_lines(issue.lastLine - issue.firstLine); |
234 |
|
end.forward_chars( |
235 |
|
(issue.lastLine != issue.firstLine) |
236 |
|
? issue.lastColumn - 1 |
237 |
|
: issue.lastColumn - issue.firstColumn + 1 |
238 |
|
); |
239 |
|
} |
240 |
|
|
241 |
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) { |
242 |
Gtk::TextBuffer::iterator itStart = |
Gtk::TextBuffer::iterator itStart = |
243 |
txtbuf->get_iter_at_line_index(token.firstLine(), token.firstColumn()); |
txtbuf->get_iter_at_line_index(token.firstLine(), token.firstColumn()); |
248 |
} |
} |
249 |
|
|
250 |
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) { |
251 |
Gtk::TextBuffer::iterator itStart = |
Gtk::TextBuffer::iterator itStart, itEnd; |
252 |
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 |
|
|
); |
|
253 |
txtbuf->apply_tag(tag, itStart, itEnd); |
txtbuf->apply_tag(tag, itStart, itEnd); |
254 |
} |
} |
255 |
|
|
|
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 |
|
|
} |
|
|
|
|
256 |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
257 |
GetScriptVM(); |
GetScriptVM(); |
258 |
const std::string s = m_textBuffer->get_text(); |
const std::string s = m_textBuffer->get_text(); |
284 |
} |
} |
285 |
} |
} |
286 |
|
|
|
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; |
|
|
} |
|
|
|
|
287 |
void ScriptEditor::updateParserIssuesByVM() { |
void ScriptEditor::updateParserIssuesByVM() { |
288 |
GetScriptVM(); |
GetScriptVM(); |
289 |
const std::string s = m_textBuffer->get_text(); |
const std::string s = m_textBuffer->get_text(); |
300 |
} |
} |
301 |
} |
} |
302 |
|
|
303 |
for (int i = m_issues.size() - 1; i >= 0; --i) { |
delete parserContext; |
304 |
const LinuxSampler::ParserIssue& issue = m_issues[i]; |
} |
305 |
|
|
306 |
|
void ScriptEditor::updateIssueTooltip(GdkEventMotion* e) { |
307 |
|
int x, y; |
308 |
|
m_textView.window_to_buffer_coords(Gtk::TEXT_WINDOW_TEXT, int(e->x), int(e->y), x, y); |
309 |
|
|
310 |
|
Gtk::TextBuffer::iterator it; |
311 |
|
m_textView.get_iter_at_location(it, x, y); |
312 |
|
|
313 |
|
const int line = it.get_line(); |
314 |
|
const int column = it.get_line_offset(); |
315 |
|
|
316 |
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(); |
|
317 |
|
|
318 |
// prevent that the user can erase the icon with backspace key |
for (int i = 0; i < m_issues.size(); ++i) { |
319 |
m_textBuffer->apply_tag(m_readOnlyTag, iter, itEnd); |
const LinuxSampler::ParserIssue& issue = m_issues[i]; |
320 |
|
const int firstLine = issue.firstLine - 1; |
321 |
|
const int firstColumn = issue.firstColumn - 1; |
322 |
|
const int lastLine = issue.lastLine - 1; |
323 |
|
const int lastColumn = issue.lastColumn - 1; |
324 |
|
if (firstLine <= line && line <= lastLine && |
325 |
|
(firstLine != line || firstColumn <= column) && |
326 |
|
(lastLine != line || lastColumn >= column)) |
327 |
|
{ |
328 |
|
m_textView.set_tooltip_markup( |
329 |
|
(issue.isErr() ? "<span foreground=\"#ff9393\">ERROR:</span> " : "<span foreground=\"#c4950c\">Warning:</span> ") + |
330 |
|
issue.txt |
331 |
|
); |
332 |
|
return; |
333 |
} |
} |
334 |
} |
} |
335 |
|
|
336 |
delete parserContext; |
m_textView.set_tooltip_markup(""); |
337 |
} |
} |
338 |
|
|
339 |
#endif // USE_LS_SCRIPTVM |
#endif // USE_LS_SCRIPTVM |
340 |
|
|
341 |
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) { |
342 |
//printf("erased\n"); |
//printf("erased\n"); |
|
if (m_ignoreEraseEvents) return; |
|
|
|
|
343 |
#if USE_LS_SCRIPTVM |
#if USE_LS_SCRIPTVM |
|
removeIssueAnchors(); |
|
344 |
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
m_textBuffer->remove_all_tags(m_textBuffer->begin(), m_textBuffer->end()); |
345 |
updateSyntaxHighlightingByVM(); |
updateSyntaxHighlightingByVM(); |
346 |
updateParserIssuesByVM(); |
updateParserIssuesByVM(); |
356 |
#endif // USE_LS_SCRIPTVM |
#endif // USE_LS_SCRIPTVM |
357 |
} |
} |
358 |
|
|
359 |
|
bool ScriptEditor::on_motion_notify_event(GdkEventMotion* e) { |
360 |
|
#if USE_LS_SCRIPTVM |
361 |
|
//TODO: event throttling would be a good idea here |
362 |
|
updateIssueTooltip(e); |
363 |
|
#endif |
364 |
|
return ManagedWindow::on_motion_notify_event(e); |
365 |
|
} |
366 |
|
|
367 |
void ScriptEditor::onModifiedChanged() { |
void ScriptEditor::onModifiedChanged() { |
368 |
m_applyButton.set_sensitive( m_textBuffer->get_modified() ); |
m_applyButton.set_sensitive( m_textBuffer->get_modified() ); |
369 |
} |
} |