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) { |
367 |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
void ScriptEditor::updateSyntaxHighlightingByVM() { |
368 |
GetScriptVM(); |
GetScriptVM(); |
369 |
const std::string s = m_textBuffer->get_text(); |
const std::string s = m_textBuffer->get_text(); |
370 |
|
if (s.empty()) return; |
371 |
std::vector<LinuxSampler::VMSourceToken> tokens = m_vm->syntaxHighlighting(s); |
std::vector<LinuxSampler::VMSourceToken> tokens = m_vm->syntaxHighlighting(s); |
372 |
|
|
373 |
for (int i = 0; i < tokens.size(); ++i) { |
for (int i = 0; i < tokens.size(); ++i) { |
404 |
m_errors = parserContext->errors(); |
m_errors = parserContext->errors(); |
405 |
m_warnings = parserContext->warnings(); |
m_warnings = parserContext->warnings(); |
406 |
|
|
407 |
for (int i = 0; i < m_issues.size(); ++i) { |
if (!s.empty()) { |
408 |
const LinuxSampler::ParserIssue& issue = m_issues[i]; |
for (int i = 0; i < m_issues.size(); ++i) { |
409 |
|
const LinuxSampler::ParserIssue& issue = m_issues[i]; |
410 |
if (issue.isErr()) { |
|
411 |
applyCodeTag(m_textBuffer, issue, m_errorTag); |
if (issue.isErr()) { |
412 |
} else if (issue.isWrn()) { |
applyCodeTag(m_textBuffer, issue, m_errorTag); |
413 |
applyCodeTag(m_textBuffer, issue, m_warningTag); |
} else if (issue.isWrn()) { |
414 |
|
applyCodeTag(m_textBuffer, issue, m_warningTag); |
415 |
|
} |
416 |
} |
} |
417 |
} |
} |
418 |
|
|
521 |
return ManagedWindow::on_motion_notify_event(e); |
return ManagedWindow::on_motion_notify_event(e); |
522 |
} |
} |
523 |
|
|
524 |
|
void ScriptEditor::onMenuChangeFontSize() { |
525 |
|
//TODO: for GTKMM >= 3.2 class Gtk::FontChooser could be used instead |
526 |
|
Gtk::Dialog dialog(_("Font Size"), true /*modal*/); |
527 |
|
Gtk::HBox hbox; |
528 |
|
hbox.set_spacing(6); |
529 |
|
|
530 |
|
Gtk::Label label(_("Editor's Font Size:"), Gtk::ALIGN_START); |
531 |
|
hbox.pack_start(label, Gtk::PACK_SHRINK); |
532 |
|
|
533 |
|
Gtk::SpinButton spinButton; |
534 |
|
spinButton.set_range(4, 80); |
535 |
|
spinButton.set_increments(1, 10); |
536 |
|
spinButton.set_value(currentFontSize()); |
537 |
|
hbox.pack_start(spinButton); |
538 |
|
|
539 |
|
dialog.get_vbox()->pack_start(hbox); |
540 |
|
dialog.add_button(_("_OK"), 0); |
541 |
|
dialog.add_button(_("_Cancel"), 1); |
542 |
|
|
543 |
|
dialog.show_all_children(); |
544 |
|
|
545 |
|
if (!dialog.run()) { // OK selected ... |
546 |
|
const int newFontSize = spinButton.get_value_as_int(); |
547 |
|
if (newFontSize >= 4) |
548 |
|
setFontSize(newFontSize, true); |
549 |
|
} |
550 |
|
} |
551 |
|
|
552 |
bool ScriptEditor::onWindowDelete(GdkEventAny* e) { |
bool ScriptEditor::onWindowDelete(GdkEventAny* e) { |
553 |
//printf("onWindowDelete\n"); |
//printf("onWindowDelete\n"); |
554 |
|
|