41 |
int w = 0; |
int w = 0; |
42 |
int h = 0; // ignored |
int h = 0; // ignored |
43 |
Gtk::IconSize::lookup(Gtk::ICON_SIZE_SMALL_TOOLBAR, w, h); |
Gtk::IconSize::lookup(Gtk::ICON_SIZE_SMALL_TOOLBAR, w, h); |
44 |
|
if (!theme->has_icon(name)) |
45 |
|
return Glib::RefPtr<Gdk::Pixbuf>(); |
46 |
Glib::RefPtr<Gdk::Pixbuf> pixbuf = theme->load_icon(name, w, Gtk::ICON_LOOKUP_GENERIC_FALLBACK); |
Glib::RefPtr<Gdk::Pixbuf> pixbuf = theme->load_icon(name, w, Gtk::ICON_LOOKUP_GENERIC_FALLBACK); |
47 |
if (pixbuf->get_height() != targetH) { |
if (pixbuf->get_height() != targetH) { |
48 |
pixbuf = pixbuf->scale_simple(targetH, targetH, Gdk::INTERP_BILINEAR); |
pixbuf = pixbuf->scale_simple(targetH, targetH, Gdk::INTERP_BILINEAR); |
50 |
return pixbuf; |
return pixbuf; |
51 |
} |
} |
52 |
|
|
53 |
|
static Glib::RefPtr<Gdk::Pixbuf> createIcon(std::vector<std::string> alternativeNames, const Glib::RefPtr<Gdk::Screen>& screen) { |
54 |
|
for (int i = 0; i < alternativeNames.size(); ++i) { |
55 |
|
Glib::RefPtr<Gdk::Pixbuf> buf = createIcon(alternativeNames[i], screen); |
56 |
|
if (buf) return buf; |
57 |
|
} |
58 |
|
return Glib::RefPtr<Gdk::Pixbuf>(); |
59 |
|
} |
60 |
|
|
61 |
ScriptEditor::ScriptEditor() : |
ScriptEditor::ScriptEditor() : |
62 |
m_statusLabel("", Gtk::ALIGN_START), |
m_statusLabel("", Gtk::ALIGN_START), |
63 |
m_applyButton(_("_Apply"), true), |
m_applyButton(_("_Apply"), true), |
68 |
m_vm = NULL; |
m_vm = NULL; |
69 |
#endif |
#endif |
70 |
|
|
71 |
m_errorIcon = createIcon("dialog-error", get_screen()); |
// depending on GTK version and installed themes, there may be different |
72 |
m_warningIcon = createIcon("dialog-warning-symbolic", get_screen()); |
// icons, and different names for them, so for each type of icon we use, |
73 |
m_successIcon = createIcon("emblem-default", get_screen()); |
// we provide a list of possible icon names, the first one found to be |
74 |
|
// installed on the local system from the list will be used and loaded for |
75 |
|
// the respective purpose (so order matters in those lists) |
76 |
|
// |
77 |
|
// (see https://developer.gnome.org/gtkmm/stable/namespaceGtk_1_1Stock.html for |
78 |
|
// available icon names) |
79 |
|
std::vector<std::string> errorIconNames; |
80 |
|
errorIconNames.push_back("dialog-error"); |
81 |
|
errorIconNames.push_back("media-record"); |
82 |
|
errorIconNames.push_back("process-stop"); |
83 |
|
|
84 |
|
std::vector<std::string> warningIconNames; |
85 |
|
warningIconNames.push_back("dialog-warning-symbolic"); |
86 |
|
warningIconNames.push_back("dialog-warning"); |
87 |
|
|
88 |
|
std::vector<std::string> successIconNames; |
89 |
|
successIconNames.push_back("emblem-default"); |
90 |
|
successIconNames.push_back("tools-check-spelling"); |
91 |
|
|
92 |
|
m_errorIcon = createIcon(errorIconNames, get_screen()); |
93 |
|
m_warningIcon = createIcon(warningIconNames, get_screen()); |
94 |
|
m_successIcon = createIcon(successIconNames, get_screen()); |
95 |
|
|
96 |
add(m_vbox); |
add(m_vbox); |
97 |
|
|
139 |
m_warningTag->property_background() = "#fffd7c"; // yellow |
m_warningTag->property_background() = "#fffd7c"; // yellow |
140 |
m_tagTable->add(m_warningTag); |
m_tagTable->add(m_warningTag); |
141 |
|
|
142 |
|
// create menu |
143 |
|
m_actionGroup = Gtk::ActionGroup::create(); |
144 |
|
m_actionGroup->add(Gtk::Action::create("MenuScript", _("_Script"))); |
145 |
|
m_actionGroup->add(Gtk::Action::create("Apply", _("_Apply")), |
146 |
|
Gtk::AccelKey("<control>s"), |
147 |
|
sigc::mem_fun(*this, &ScriptEditor::onButtonApply)); |
148 |
|
m_actionGroup->add(Gtk::Action::create("Close", _("_Close")), |
149 |
|
Gtk::AccelKey("<control>q"), |
150 |
|
sigc::mem_fun(*this, &ScriptEditor::onButtonCancel)); |
151 |
|
m_uiManager = Gtk::UIManager::create(); |
152 |
|
m_uiManager->insert_action_group(m_actionGroup); |
153 |
|
add_accel_group(m_uiManager->get_accel_group()); |
154 |
|
m_uiManager->add_ui_from_string( |
155 |
|
"<ui>" |
156 |
|
" <menubar name='MenuBar'>" |
157 |
|
" <menu action='MenuScript'>" |
158 |
|
" <menuitem action='Apply'/>" |
159 |
|
" <separator/>" |
160 |
|
" <menuitem action='Close'/>" |
161 |
|
" </menu>" |
162 |
|
" </menubar>" |
163 |
|
"</ui>" |
164 |
|
); |
165 |
|
|
166 |
m_textBuffer = Gtk::TextBuffer::create(m_tagTable); |
m_textBuffer = Gtk::TextBuffer::create(m_tagTable); |
167 |
m_textView.set_buffer(m_textBuffer); |
m_textView.set_buffer(m_textBuffer); |
168 |
{ |
{ |
169 |
Pango::FontDescription fdesc; |
Pango::FontDescription fdesc; |
170 |
fdesc.set_family("monospace"); |
fdesc.set_family("monospace"); |
171 |
#if defined(__APPLE__) |
#if defined(__APPLE__) |
172 |
fdesc.set_size(12 * PANGO_SCALE); |
fdesc.set_size(14 * PANGO_SCALE); |
173 |
#else |
#else |
174 |
fdesc.set_size(10 * PANGO_SCALE); |
fdesc.set_size(10 * PANGO_SCALE); |
175 |
#endif |
#endif |
181 |
} |
} |
182 |
m_scrolledWindow.add(m_textView); |
m_scrolledWindow.add(m_textView); |
183 |
m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
184 |
|
|
185 |
|
Gtk::Widget* menuBar = m_uiManager->get_widget("/MenuBar"); |
186 |
|
m_vbox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
187 |
m_vbox.pack_start(m_scrolledWindow); |
m_vbox.pack_start(m_scrolledWindow); |
188 |
|
|
189 |
m_buttonBox.set_layout(Gtk::BUTTONBOX_END); |
m_buttonBox.set_layout(Gtk::BUTTONBOX_END); |
192 |
m_applyButton.set_can_default(); |
m_applyButton.set_can_default(); |
193 |
m_applyButton.set_sensitive(false); |
m_applyButton.set_sensitive(false); |
194 |
m_applyButton.grab_focus(); |
m_applyButton.grab_focus(); |
195 |
|
|
196 |
#if GTKMM_MAJOR_VERSION >= 3 |
#if GTKMM_MAJOR_VERSION >= 3 |
197 |
m_statusImage.set_margin_left(6); |
m_statusImage.set_margin_left(6); |
198 |
m_statusImage.set_margin_right(6); |
m_statusImage.set_margin_right(6); |
238 |
); |
); |
239 |
|
|
240 |
show_all_children(); |
show_all_children(); |
|
|
|
|
resize(460,300); |
|
241 |
} |
} |
242 |
|
|
243 |
ScriptEditor::~ScriptEditor() { |
ScriptEditor::~ScriptEditor() { |
556 |
} |
} |
557 |
|
|
558 |
void ScriptEditor::onButtonApply() { |
void ScriptEditor::onButtonApply() { |
559 |
|
signal_script_to_be_changed.emit(m_script); |
560 |
m_script->SetScriptAsText(m_textBuffer->get_text()); |
m_script->SetScriptAsText(m_textBuffer->get_text()); |
561 |
|
signal_script_changed.emit(m_script); |
562 |
m_textBuffer->set_modified(false); |
m_textBuffer->set_modified(false); |
563 |
} |
} |
564 |
|
|