6 |
*/ |
*/ |
7 |
|
|
8 |
#include "MacrosSetup.h" |
#include "MacrosSetup.h" |
9 |
|
#include "compat.h" |
10 |
#include "global.h" |
#include "global.h" |
11 |
#include <assert.h> |
#include <assert.h> |
12 |
#include <set> |
#include <set> |
13 |
#include <math.h> |
#include <math.h> |
14 |
#include <gtkmm/stock.h> |
#if HAS_GTKMM_STOCK |
15 |
|
# include <gtkmm/stock.h> |
16 |
|
#endif |
17 |
#include "MacroEditor.h" |
#include "MacroEditor.h" |
18 |
|
|
19 |
MacrosSetup::MacrosSetup() : |
MacrosSetup::MacrosSetup() : |
21 |
m_clipboardContent(NULL), |
m_clipboardContent(NULL), |
22 |
m_addFromClipboardButton(" " + Glib::ustring(_("From Clipboard")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + "B"), |
m_addFromClipboardButton(" " + Glib::ustring(_("From Clipboard")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + "B"), |
23 |
m_addFromSelectionButton(" " + Glib::ustring(_("From Selection")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + "S"), |
m_addFromSelectionButton(" " + Glib::ustring(_("From Selection")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + "S"), |
24 |
|
#if HAS_GTKMM_STOCK |
25 |
m_buttonUp(Gtk::Stock::GO_UP), |
m_buttonUp(Gtk::Stock::GO_UP), |
26 |
m_buttonDown(Gtk::Stock::GO_DOWN), |
m_buttonDown(Gtk::Stock::GO_DOWN), |
27 |
m_buttonEdit(Gtk::Stock::EDIT), |
m_buttonEdit(Gtk::Stock::EDIT), |
28 |
|
#else |
29 |
|
m_buttonUp(_("Up"), true), |
30 |
|
m_buttonDown(_("Down"), true), |
31 |
|
m_buttonEdit(_("Edit"), true), |
32 |
|
#endif |
33 |
m_buttonDuplicate(_("Duplicate")), |
m_buttonDuplicate(_("Duplicate")), |
34 |
m_statusLabel("", Gtk::ALIGN_START), |
m_statusLabel("", Gtk::ALIGN_START), |
35 |
m_labelComment(_("Comment"), Gtk::ALIGN_START), |
m_labelComment(_("Comment"), Gtk::ALIGN_START), |
36 |
m_deleteButton(" " + Glib::ustring(_("Delete")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + UNICODE_ERASE_KEY_SYMBOL), |
m_deleteButton(" " + Glib::ustring(_("Delete")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + UNICODE_ERASE_KEY_SYMBOL), |
37 |
m_inverseDeleteButton(" " + Glib::ustring(_("Inverse Delete")) + " " + UNICODE_ALT_KEY_SYMBOL + UNICODE_ERASE_KEY_SYMBOL), |
m_inverseDeleteButton(" " + Glib::ustring(_("Inverse Delete")) + " " + UNICODE_ALT_KEY_SYMBOL + UNICODE_ERASE_KEY_SYMBOL), |
38 |
|
#if HAS_GTKMM_STOCK |
39 |
m_applyButton(Gtk::Stock::APPLY), |
m_applyButton(Gtk::Stock::APPLY), |
40 |
m_cancelButton(Gtk::Stock::CANCEL), |
m_cancelButton(Gtk::Stock::CANCEL), |
41 |
|
#else |
42 |
|
m_applyButton(_("Apply"), true), |
43 |
|
m_cancelButton(_("_Cancel"), true), |
44 |
|
#endif |
45 |
m_altKeyDown(false), |
m_altKeyDown(false), |
46 |
m_primaryKeyDown(false) |
m_primaryKeyDown(false) |
47 |
{ |
{ |
49 |
|
|
50 |
set_title(_("Setup Macros")); |
set_title(_("Setup Macros")); |
51 |
|
|
52 |
|
#if !HAS_GTKMM_STOCK |
53 |
|
// see : https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html |
54 |
|
m_buttonUp.set_icon_name("go-up"); |
55 |
|
m_buttonDown.set_icon_name("go-down"); |
56 |
|
m_buttonEdit.set_icon_name("insert-text"); |
57 |
|
#endif |
58 |
|
|
59 |
if (!Settings::singleton()->autoRestoreWindowDimension) { |
if (!Settings::singleton()->autoRestoreWindowDimension) { |
60 |
set_default_size(680, 500); |
set_default_size(680, 500); |
61 |
set_position(Gtk::WIN_POS_CENTER); |
set_position(Gtk::WIN_POS_CENTER); |
62 |
} |
} |
63 |
|
|
64 |
|
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 12) |
65 |
|
m_labelIntro.set_margin_start(10); |
66 |
|
m_labelIntro.set_margin_end(10); |
67 |
|
#else |
68 |
m_labelIntro.set_padding(10, 10); |
m_labelIntro.set_padding(10, 10); |
69 |
|
#endif |
70 |
|
|
71 |
#if GTKMM_MAJOR_VERSION >= 3 |
#if GTKMM_MAJOR_VERSION >= 3 |
72 |
m_labelIntro.set_line_wrap(); |
m_labelIntro.set_line_wrap(); |
73 |
#endif |
#endif |
81 |
); |
); |
82 |
m_vbox.pack_start(m_labelIntro, Gtk::PACK_SHRINK); |
m_vbox.pack_start(m_labelIntro, Gtk::PACK_SHRINK); |
83 |
|
|
84 |
|
#if HAS_GTKMM_STOCK |
85 |
m_addFromClipboardButton.set_image( |
m_addFromClipboardButton.set_image( |
86 |
*new Gtk::Image(Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON) |
*new Gtk::Image(Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON) |
87 |
); |
); |
97 |
m_inverseDeleteButton.set_image( |
m_inverseDeleteButton.set_image( |
98 |
*new Gtk::Image(Gtk::Stock::DELETE, Gtk::ICON_SIZE_BUTTON) |
*new Gtk::Image(Gtk::Stock::DELETE, Gtk::ICON_SIZE_BUTTON) |
99 |
); |
); |
100 |
|
#else // since GTKMM 3.90 ... |
101 |
|
// see : https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html |
102 |
|
m_addFromClipboardButton.set_icon_name("list-add"); |
103 |
|
m_addFromSelectionButton.set_icon_name("list-add"); |
104 |
|
m_buttonDuplicate.set_icon_name("edit-copy"); |
105 |
|
m_deleteButton.set_icon_name("edit-delete"); |
106 |
|
m_inverseDeleteButton.set_icon_name("edit-delete"); |
107 |
|
#endif |
108 |
m_addFromClipboardButton.set_tooltip_text(_("Create a new macro from the content currently available on the clipboard.")); |
m_addFromClipboardButton.set_tooltip_text(_("Create a new macro from the content currently available on the clipboard.")); |
109 |
m_addFromSelectionButton.set_tooltip_text(_("Create a new macro from the currently selected dimension region's parameters currently shown on the main window.")); |
m_addFromSelectionButton.set_tooltip_text(_("Create a new macro from the currently selected dimension region's parameters currently shown on the main window.")); |
110 |
m_buttonDuplicate.set_tooltip_text(_("Duplicate the selected macro(s). The new macro(s) will be appended to the end of the list.")); |
m_buttonDuplicate.set_tooltip_text(_("Duplicate the selected macro(s). The new macro(s) will be appended to the end of the list.")); |
165 |
m_treeViewMacros.get_selection()->signal_changed().connect( |
m_treeViewMacros.get_selection()->signal_changed().connect( |
166 |
sigc::mem_fun(*this, &MacrosSetup::onTreeViewSelectionChanged) |
sigc::mem_fun(*this, &MacrosSetup::onTreeViewSelectionChanged) |
167 |
); |
); |
168 |
|
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 |
169 |
|
m_treeViewMacros.signal_key_release_event().connect( |
170 |
|
#else |
171 |
m_treeViewMacros.signal_key_release_event().connect_notify( |
m_treeViewMacros.signal_key_release_event().connect_notify( |
172 |
|
#endif |
173 |
sigc::mem_fun(*this, &MacrosSetup::onMacroTreeViewKeyRelease) |
sigc::mem_fun(*this, &MacrosSetup::onMacroTreeViewKeyRelease) |
174 |
); |
); |
175 |
m_treeStoreMacros->signal_row_changed().connect( |
m_treeStoreMacros->signal_row_changed().connect( |
226 |
m_applyButton.set_sensitive(false); |
m_applyButton.set_sensitive(false); |
227 |
m_applyButton.grab_focus(); |
m_applyButton.grab_focus(); |
228 |
|
|
229 |
#if GTKMM_MAJOR_VERSION >= 3 |
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 12) |
230 |
|
m_statusLabel.set_margin_start(6); |
231 |
|
m_statusLabel.set_margin_end(6); |
232 |
|
#elif GTKMM_MAJOR_VERSION >= 3 |
233 |
m_statusLabel.set_margin_left(6); |
m_statusLabel.set_margin_left(6); |
234 |
m_statusLabel.set_margin_right(6); |
m_statusLabel.set_margin_right(6); |
235 |
#else |
#else |
236 |
m_statusHBox.set_spacing(6); |
m_statusLabel.set_spacing(6); |
237 |
#endif |
#endif |
238 |
|
|
239 |
m_statusHBox.pack_start(m_statusLabel); |
m_statusHBox.pack_start(m_statusLabel); |
240 |
|
#if HAS_GTKMM_SHOW_ALL_CHILDREN |
241 |
m_statusHBox.show_all_children(); |
m_statusHBox.show_all_children(); |
242 |
|
#endif |
243 |
|
|
244 |
m_footerHBox.pack_start(m_buttonBoxL, Gtk::PACK_SHRINK); |
m_footerHBox.pack_start(m_buttonBoxL, Gtk::PACK_SHRINK); |
245 |
m_footerHBox.pack_start(m_statusHBox); |
m_footerHBox.pack_start(m_statusHBox); |
296 |
); |
); |
297 |
|
|
298 |
signal_delete_event().connect( |
signal_delete_event().connect( |
299 |
|
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 |
300 |
sigc::mem_fun(*this, &MacrosSetup::onWindowDelete) |
sigc::mem_fun(*this, &MacrosSetup::onWindowDelete) |
301 |
|
#else |
302 |
|
sigc::mem_fun(*this, &MacrosSetup::onWindowDeleteP) |
303 |
|
#endif |
304 |
); |
); |
305 |
|
|
306 |
signal_key_press_event().connect( |
signal_key_press_event().connect( |
310 |
sigc::mem_fun(*this, &MacrosSetup::onKeyReleased) |
sigc::mem_fun(*this, &MacrosSetup::onKeyReleased) |
311 |
); |
); |
312 |
|
|
313 |
|
#if HAS_GTKMM_SHOW_ALL_CHILDREN |
314 |
show_all_children(); |
show_all_children(); |
315 |
|
#endif |
316 |
updateStatus(); |
updateStatus(); |
317 |
} |
} |
318 |
|
|
557 |
GDK_KEY_Control_R; |
GDK_KEY_Control_R; |
558 |
#endif |
#endif |
559 |
|
|
560 |
|
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 |
561 |
|
bool MacrosSetup::onKeyPressed(Gdk::EventKey& _key) { |
562 |
|
GdkEventKey* key = _key.gobj(); |
563 |
|
#else |
564 |
bool MacrosSetup::onKeyPressed(GdkEventKey* key) { |
bool MacrosSetup::onKeyPressed(GdkEventKey* key) { |
565 |
|
#endif |
566 |
//printf("key down 0x%x\n", key->keyval); |
//printf("key down 0x%x\n", key->keyval); |
567 |
if (key->keyval == GDK_KEY_Alt_L || key->keyval == GDK_KEY_Alt_R) |
if (key->keyval == GDK_KEY_Alt_L || key->keyval == GDK_KEY_Alt_R) |
568 |
m_altKeyDown = true; |
m_altKeyDown = true; |
571 |
return false; |
return false; |
572 |
} |
} |
573 |
|
|
574 |
|
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 |
575 |
|
bool MacrosSetup::onKeyReleased(Gdk::EventKey& _key) { |
576 |
|
GdkEventKey* key = _key.gobj(); |
577 |
|
#else |
578 |
bool MacrosSetup::onKeyReleased(GdkEventKey* key) { |
bool MacrosSetup::onKeyReleased(GdkEventKey* key) { |
579 |
|
#endif |
580 |
//printf("key up 0x%x\n", key->keyval); |
//printf("key up 0x%x\n", key->keyval); |
581 |
if (key->keyval == GDK_KEY_Alt_L || key->keyval == GDK_KEY_Alt_R) |
if (key->keyval == GDK_KEY_Alt_L || key->keyval == GDK_KEY_Alt_R) |
582 |
m_altKeyDown = false; |
m_altKeyDown = false; |
589 |
return false; |
return false; |
590 |
} |
} |
591 |
|
|
592 |
|
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 |
593 |
|
bool MacrosSetup::onMacroTreeViewKeyRelease(Gdk::EventKey& _key) { |
594 |
|
GdkEventKey* key = _key.gobj(); |
595 |
|
#else |
596 |
void MacrosSetup::onMacroTreeViewKeyRelease(GdkEventKey* key) { |
void MacrosSetup::onMacroTreeViewKeyRelease(GdkEventKey* key) { |
597 |
|
#endif |
598 |
if (key->keyval == GDK_KEY_BackSpace || key->keyval == GDK_KEY_Delete) { |
if (key->keyval == GDK_KEY_BackSpace || key->keyval == GDK_KEY_Delete) { |
599 |
if (m_altKeyDown) |
if (m_altKeyDown) |
600 |
inverseDeleteSelectedRows(); |
inverseDeleteSelectedRows(); |
601 |
else if (m_primaryKeyDown) |
else if (m_primaryKeyDown) |
602 |
deleteSelectedRows(); |
deleteSelectedRows(); |
603 |
} |
} |
604 |
|
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 |
605 |
|
return false; |
606 |
|
#endif |
607 |
} |
} |
608 |
|
|
609 |
void MacrosSetup::onMacroTreeViewRowValueChanged(const Gtk::TreeModel::Path& path, |
void MacrosSetup::onMacroTreeViewRowValueChanged(const Gtk::TreeModel::Path& path, |
738 |
{ |
{ |
739 |
return m_macros_changed; |
return m_macros_changed; |
740 |
} |
} |
741 |
|
|
742 |
|
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 |
743 |
|
bool MacrosSetup::onWindowDelete(Gdk::Event& e) { |
744 |
|
return onWindowDeleteP(NULL); |
745 |
|
} |
746 |
|
#endif |
747 |
|
|
748 |
bool MacrosSetup::onWindowDelete(GdkEventAny* e) { |
bool MacrosSetup::onWindowDeleteP(GdkEventAny* /*e*/) { |
749 |
//printf("onWindowDelete\n"); |
//printf("onWindowDelete\n"); |
750 |
|
|
751 |
if (!isModified()) return false; // propagate event further (which will close this window) |
if (!isModified()) return false; // propagate event further (which will close this window) |
796 |
} |
} |
797 |
|
|
798 |
void MacrosSetup::onButtonCancel() { |
void MacrosSetup::onButtonCancel() { |
799 |
bool dropEvent = onWindowDelete(NULL); |
bool dropEvent = onWindowDeleteP(NULL); |
800 |
if (dropEvent) return; |
if (dropEvent) return; |
801 |
hide(); |
hide(); |
802 |
} |
} |