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 |
148 |
m_actionGroup->add(Gtk::Action::create("Close", _("_Close")), |
m_actionGroup->add(Gtk::Action::create("Close", _("_Close")), |
149 |
Gtk::AccelKey("<control>q"), |
Gtk::AccelKey("<control>q"), |
150 |
sigc::mem_fun(*this, &ScriptEditor::onButtonCancel)); |
sigc::mem_fun(*this, &ScriptEditor::onButtonCancel)); |
151 |
|
m_actionGroup->add(Gtk::Action::create("MenuEditor", _("_Editor"))); |
152 |
|
m_actionGroup->add(Gtk::Action::create("ChangeFont", _("_Font Size ...")), |
153 |
|
sigc::mem_fun(*this, &ScriptEditor::onMenuChangeFontSize)); |
154 |
m_uiManager = Gtk::UIManager::create(); |
m_uiManager = Gtk::UIManager::create(); |
155 |
m_uiManager->insert_action_group(m_actionGroup); |
m_uiManager->insert_action_group(m_actionGroup); |
156 |
add_accel_group(m_uiManager->get_accel_group()); |
add_accel_group(m_uiManager->get_accel_group()); |
162 |
" <separator/>" |
" <separator/>" |
163 |
" <menuitem action='Close'/>" |
" <menuitem action='Close'/>" |
164 |
" </menu>" |
" </menu>" |
165 |
|
" <menu action='MenuEditor'>" |
166 |
|
" <menuitem action='ChangeFont'/>" |
167 |
|
" </menu>" |
168 |
" </menubar>" |
" </menubar>" |
169 |
"</ui>" |
"</ui>" |
170 |
); |
); |
171 |
|
|
172 |
m_textBuffer = Gtk::TextBuffer::create(m_tagTable); |
m_textBuffer = Gtk::TextBuffer::create(m_tagTable); |
173 |
m_textView.set_buffer(m_textBuffer); |
m_textView.set_buffer(m_textBuffer); |
174 |
{ |
setFontSize(currentFontSize(), false); |
|
Pango::FontDescription fdesc; |
|
|
fdesc.set_family("monospace"); |
|
|
#if defined(__APPLE__) |
|
|
fdesc.set_size(14 * PANGO_SCALE); |
|
|
#else |
|
|
fdesc.set_size(10 * PANGO_SCALE); |
|
|
#endif |
|
|
#if GTKMM_MAJOR_VERSION < 3 |
|
|
m_textView.modify_font(fdesc); |
|
|
#else |
|
|
m_textView.override_font(fdesc); |
|
|
#endif |
|
|
} |
|
175 |
m_scrolledWindow.add(m_textView); |
m_scrolledWindow.add(m_textView); |
176 |
m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
177 |
|
|
240 |
#endif |
#endif |
241 |
} |
} |
242 |
|
|
243 |
|
int ScriptEditor::currentFontSize() const { |
244 |
|
#if defined(__APPLE__) |
245 |
|
const int defaultFontSize = 13; |
246 |
|
#else |
247 |
|
const int defaultFontSize = 10; |
248 |
|
#endif |
249 |
|
const int settingFontSize = Settings::singleton()->scriptEditorFontSize; |
250 |
|
const int fontSize = (settingFontSize > 0) ? settingFontSize : defaultFontSize; |
251 |
|
return fontSize; |
252 |
|
} |
253 |
|
|
254 |
|
void ScriptEditor::setFontSize(int size, bool save) { |
255 |
|
//printf("setFontSize(%d,%d)\n", size, save); |
256 |
|
Pango::FontDescription fdesc; |
257 |
|
fdesc.set_family("monospace"); |
258 |
|
fdesc.set_size(size * PANGO_SCALE); |
259 |
|
#if GTKMM_MAJOR_VERSION < 3 |
260 |
|
m_textView.modify_font(fdesc); |
261 |
|
#else |
262 |
|
m_textView.override_font(fdesc); |
263 |
|
#endif |
264 |
|
if (save) Settings::singleton()->scriptEditorFontSize = size; |
265 |
|
} |
266 |
|
|
267 |
void ScriptEditor::setScript(gig::Script* script) { |
void ScriptEditor::setScript(gig::Script* script) { |
268 |
m_script = script; |
m_script = script; |
269 |
if (!script) { |
if (!script) { |
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 |
|
|
534 |
return ManagedWindow::on_motion_notify_event(e); |
return ManagedWindow::on_motion_notify_event(e); |
535 |
} |
} |
536 |
|
|
537 |
|
void ScriptEditor::onMenuChangeFontSize() { |
538 |
|
//TODO: for GTKMM >= 3.2 class Gtk::FontChooser could be used instead |
539 |
|
Gtk::Dialog dialog(_("Font Size"), true /*modal*/); |
540 |
|
Gtk::HBox hbox; |
541 |
|
hbox.set_spacing(6); |
542 |
|
|
543 |
|
Gtk::Label label(_("Editor's Font Size:"), Gtk::ALIGN_START); |
544 |
|
hbox.pack_start(label, Gtk::PACK_SHRINK); |
545 |
|
|
546 |
|
Gtk::SpinButton spinButton; |
547 |
|
spinButton.set_range(4, 80); |
548 |
|
spinButton.set_increments(1, 10); |
549 |
|
spinButton.set_value(currentFontSize()); |
550 |
|
hbox.pack_start(spinButton); |
551 |
|
|
552 |
|
dialog.get_vbox()->pack_start(hbox); |
553 |
|
dialog.add_button(_("_OK"), 0); |
554 |
|
dialog.add_button(_("_Cancel"), 1); |
555 |
|
|
556 |
|
dialog.show_all_children(); |
557 |
|
|
558 |
|
if (!dialog.run()) { // OK selected ... |
559 |
|
const int newFontSize = spinButton.get_value_as_int(); |
560 |
|
if (newFontSize >= 4) |
561 |
|
setFontSize(newFontSize, true); |
562 |
|
} |
563 |
|
} |
564 |
|
|
565 |
bool ScriptEditor::onWindowDelete(GdkEventAny* e) { |
bool ScriptEditor::onWindowDelete(GdkEventAny* e) { |
566 |
//printf("onWindowDelete\n"); |
//printf("onWindowDelete\n"); |
567 |
|
|