--- gigedit/trunk/src/gigedit/scripteditor.cpp 2016/05/02 14:36:40 2899 +++ gigedit/trunk/src/gigedit/scripteditor.cpp 2016/07/01 14:09:25 2928 @@ -41,6 +41,8 @@ int w = 0; int h = 0; // ignored Gtk::IconSize::lookup(Gtk::ICON_SIZE_SMALL_TOOLBAR, w, h); + if (!theme->has_icon(name)) + return Glib::RefPtr(); Glib::RefPtr 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); @@ -48,6 +50,14 @@ return pixbuf; } +static Glib::RefPtr createIcon(std::vector alternativeNames, const Glib::RefPtr& screen) { + for (int i = 0; i < alternativeNames.size(); ++i) { + Glib::RefPtr buf = createIcon(alternativeNames[i], screen); + if (buf) return buf; + } + return Glib::RefPtr(); +} + ScriptEditor::ScriptEditor() : m_statusLabel("", Gtk::ALIGN_START), m_applyButton(_("_Apply"), true), @@ -58,9 +68,30 @@ m_vm = NULL; #endif - m_errorIcon = createIcon("dialog-error", get_screen()); - m_warningIcon = createIcon("dialog-warning-symbolic", get_screen()); - m_successIcon = createIcon("emblem-default", get_screen()); + // depending on GTK version and installed themes, there may be different + // icons, and different names for them, so for each type of icon we use, + // we provide a list of possible icon names, the first one found to be + // installed on the local system from the list will be used and loaded for + // the respective purpose (so order matters in those lists) + // + // (see https://developer.gnome.org/gtkmm/stable/namespaceGtk_1_1Stock.html for + // available icon names) + std::vector errorIconNames; + errorIconNames.push_back("dialog-error"); + errorIconNames.push_back("media-record"); + errorIconNames.push_back("process-stop"); + + std::vector warningIconNames; + warningIconNames.push_back("dialog-warning-symbolic"); + warningIconNames.push_back("dialog-warning"); + + std::vector successIconNames; + successIconNames.push_back("emblem-default"); + successIconNames.push_back("tools-check-spelling"); + + m_errorIcon = createIcon(errorIconNames, get_screen()); + m_warningIcon = createIcon(warningIconNames, get_screen()); + m_successIcon = createIcon(successIconNames, get_screen()); add(m_vbox); @@ -108,6 +139,30 @@ m_warningTag->property_background() = "#fffd7c"; // yellow m_tagTable->add(m_warningTag); + // create menu + m_actionGroup = Gtk::ActionGroup::create(); + m_actionGroup->add(Gtk::Action::create("MenuScript", _("_Script"))); + m_actionGroup->add(Gtk::Action::create("Apply", _("_Apply")), + Gtk::AccelKey("s"), + sigc::mem_fun(*this, &ScriptEditor::onButtonApply)); + m_actionGroup->add(Gtk::Action::create("Close", _("_Close")), + Gtk::AccelKey("q"), + sigc::mem_fun(*this, &ScriptEditor::onButtonCancel)); + m_uiManager = Gtk::UIManager::create(); + m_uiManager->insert_action_group(m_actionGroup); + add_accel_group(m_uiManager->get_accel_group()); + m_uiManager->add_ui_from_string( + "" + " " + " " + " " + " " + " " + " " + " " + "" + ); + m_textBuffer = Gtk::TextBuffer::create(m_tagTable); m_textView.set_buffer(m_textBuffer); { @@ -126,6 +181,9 @@ } m_scrolledWindow.add(m_textView); m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); + + Gtk::Widget* menuBar = m_uiManager->get_widget("/MenuBar"); + m_vbox.pack_start(*menuBar, Gtk::PACK_SHRINK); m_vbox.pack_start(m_scrolledWindow); m_buttonBox.set_layout(Gtk::BUTTONBOX_END); @@ -134,9 +192,13 @@ m_applyButton.set_can_default(); m_applyButton.set_sensitive(false); m_applyButton.grab_focus(); - + +#if GTKMM_MAJOR_VERSION >= 3 m_statusImage.set_margin_left(6); m_statusImage.set_margin_right(6); +#else + m_statusHBox.set_spacing(6); +#endif m_statusHBox.pack_start(m_statusImage, Gtk::PACK_SHRINK); m_statusHBox.pack_start(m_statusLabel); @@ -176,8 +238,6 @@ ); show_all_children(); - - resize(460,300); } ScriptEditor::~ScriptEditor() { @@ -496,7 +556,9 @@ } void ScriptEditor::onButtonApply() { + signal_script_to_be_changed.emit(m_script); m_script->SetScriptAsText(m_textBuffer->get_text()); + signal_script_changed.emit(m_script); m_textBuffer->set_modified(false); }