11 |
#include <set> |
#include <set> |
12 |
#include <math.h> |
#include <math.h> |
13 |
#include <gtkmm/stock.h> |
#include <gtkmm/stock.h> |
14 |
|
#include "MacroEditor.h" |
15 |
|
|
16 |
MacrosSetup::MacrosSetup() : |
MacrosSetup::MacrosSetup() : |
17 |
m_modified(false), |
m_modified(false), |
18 |
m_clipboardContent(NULL), |
m_clipboardContent(NULL), |
19 |
m_addFromClipboardButton(" " + Glib::ustring(_("From Clipboard")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + "B"), |
m_addFromClipboardButton(" " + Glib::ustring(_("From Clipboard")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + "B"), |
20 |
m_addFromSelectionButton(" " + Glib::ustring(_("From Selection")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + "S"), |
m_addFromSelectionButton(" " + Glib::ustring(_("From Selection")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + "S"), |
21 |
|
m_buttonUp(Gtk::Stock::GO_UP), |
22 |
|
m_buttonDown(Gtk::Stock::GO_DOWN), |
23 |
|
m_buttonEdit(Gtk::Stock::EDIT), |
24 |
m_statusLabel("", Gtk::ALIGN_START), |
m_statusLabel("", Gtk::ALIGN_START), |
25 |
m_deleteButton(Glib::ustring(_("Delete")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + UNICODE_ERASE_KEY_SYMBOL), |
m_labelComment(_("Comment"), Gtk::ALIGN_START), |
26 |
m_inverseDeleteButton(Glib::ustring(_("Inverse Delete")) + " " + UNICODE_ALT_KEY_SYMBOL + UNICODE_ERASE_KEY_SYMBOL), |
m_deleteButton(" " + Glib::ustring(_("Delete")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + UNICODE_ERASE_KEY_SYMBOL), |
27 |
m_applyButton(_("_Apply"), true), |
m_inverseDeleteButton(" " + Glib::ustring(_("Inverse Delete")) + " " + UNICODE_ALT_KEY_SYMBOL + UNICODE_ERASE_KEY_SYMBOL), |
28 |
m_cancelButton(_("_Cancel"), true), |
m_applyButton(Gtk::Stock::APPLY), |
29 |
|
m_cancelButton(Gtk::Stock::CANCEL), |
30 |
m_altKeyDown(false), |
m_altKeyDown(false), |
31 |
m_primaryKeyDown(false) |
m_primaryKeyDown(false) |
32 |
{ |
{ |
34 |
|
|
35 |
set_title(_("Setup Macros")); |
set_title(_("Setup Macros")); |
36 |
|
|
37 |
set_default_size(800, 600); |
set_default_size(680, 500); |
38 |
|
|
39 |
m_addFromClipboardButton.set_image( |
m_addFromClipboardButton.set_image( |
40 |
*new Gtk::Image(Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON) |
*new Gtk::Image(Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON) |
42 |
m_addFromSelectionButton.set_image( |
m_addFromSelectionButton.set_image( |
43 |
*new Gtk::Image(Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON) |
*new Gtk::Image(Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON) |
44 |
); |
); |
45 |
|
m_deleteButton.set_image( |
46 |
|
*new Gtk::Image(Gtk::Stock::DELETE, Gtk::ICON_SIZE_BUTTON) |
47 |
|
); |
48 |
|
m_inverseDeleteButton.set_image( |
49 |
|
*new Gtk::Image(Gtk::Stock::DELETE, Gtk::ICON_SIZE_BUTTON) |
50 |
|
); |
51 |
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.")); |
52 |
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.")); |
53 |
m_addHBox.pack_start(m_addFromClipboardButton); |
m_addHBox.pack_start(m_addFromClipboardButton, Gtk::PACK_EXPAND_WIDGET/*, 15*/); |
54 |
m_addHBox.pack_start(m_addFromSelectionButton); |
m_addHBox.pack_start(m_addFromSelectionButton, Gtk::PACK_EXPAND_WIDGET/*, 15*/); |
55 |
m_vbox.pack_start(m_addHBox, Gtk::PACK_SHRINK); |
m_vbox.pack_start(m_addHBox, Gtk::PACK_SHRINK); |
56 |
|
|
57 |
|
m_vbox.pack_start(m_mainHBox); |
58 |
|
m_vbox.set_spacing(5); |
59 |
|
|
60 |
// create Macro list treeview (including its data model) |
// create Macro list treeview (including its data model) |
61 |
m_treeStoreMacros = MacroListTreeStore::create(m_treeModelMacros); |
m_treeStoreMacros = MacroListTreeStore::create(m_treeModelMacros); |
62 |
m_treeViewMacros.set_model(m_treeStoreMacros); |
m_treeViewMacros.set_model(m_treeStoreMacros); |
63 |
m_treeViewMacros.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); |
m_treeViewMacros.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); |
64 |
//m_treeViewMacro.set_tooltip_text(_("")); |
//m_treeViewMacro.set_tooltip_text(_("")); |
65 |
m_treeViewMacros.append_column(_("Key"), m_treeModelMacros.m_col_key); |
m_treeViewMacros.append_column(_("Key"), m_treeModelMacros.m_col_key); |
66 |
m_treeViewMacros.append_column_editable(_("Name"), m_treeModelMacros.m_col_name); |
m_treeViewMacros.append_column_editable(_("Macro Name"), m_treeModelMacros.m_col_name); |
67 |
m_treeViewMacros.append_column(_("Created"), m_treeModelMacros.m_col_created); |
m_treeViewMacros.append_column(_("Created"), m_treeModelMacros.m_col_created); |
68 |
m_treeViewMacros.append_column(_("Modified"), m_treeModelMacros.m_col_modified); |
m_treeViewMacros.append_column(_("Modified"), m_treeModelMacros.m_col_modified); |
69 |
m_treeViewMacros.set_tooltip_column(m_treeModelMacros.m_col_comment.index()); |
m_treeViewMacros.set_tooltip_column(m_treeModelMacros.m_col_comment.index()); |
103 |
sigc::mem_fun(*this, &MacrosSetup::onMacroTreeViewRowValueChanged) |
sigc::mem_fun(*this, &MacrosSetup::onMacroTreeViewRowValueChanged) |
104 |
); |
); |
105 |
m_ignoreTreeViewValueChange = false; |
m_ignoreTreeViewValueChange = false; |
106 |
|
m_ignoreCommentTextViewChange = false; |
107 |
|
|
108 |
m_scrolledWindow.add(m_treeViewMacros); |
m_scrolledWindow.add(m_treeViewMacros); |
109 |
m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
110 |
m_vbox.pack_start(m_scrolledWindow); |
m_mainHBox.pack_start(m_scrolledWindow); |
111 |
|
|
112 |
|
m_rvbox.set_spacing(5); |
113 |
|
|
114 |
|
m_mainHBox.pack_start(m_rvbox, Gtk::PACK_SHRINK); |
115 |
|
m_mainHBox.set_spacing(5), |
116 |
|
m_rvbox.set_spacing(5); |
117 |
|
m_rvbox.pack_start(m_detailsButtonBox, Gtk::PACK_SHRINK); |
118 |
|
|
119 |
|
//m_textViewComment.set_left_margin(3); |
120 |
|
//m_textViewComment.set_right_margin(3); |
121 |
|
m_textViewComment.set_indent(2); |
122 |
|
m_scrolledWindowComment.add(m_textViewComment); |
123 |
|
m_scrolledWindowComment.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
124 |
|
m_labelComment.set_markup( |
125 |
|
"<b>" + m_labelComment.get_text() + "</b>" |
126 |
|
); |
127 |
|
m_rvbox.pack_start(m_labelComment, Gtk::PACK_SHRINK); |
128 |
|
m_rvbox.pack_start(m_scrolledWindowComment); |
129 |
|
|
130 |
|
m_detailsButtonBox.pack_start(m_buttonUp); |
131 |
|
m_detailsButtonBox.pack_start(m_buttonDown); |
132 |
|
m_detailsButtonBox.pack_start(m_buttonEdit); |
133 |
|
|
134 |
m_buttonBoxL.set_layout(Gtk::BUTTONBOX_START); |
m_buttonBoxL.set_layout(Gtk::BUTTONBOX_START); |
135 |
m_buttonBoxL.pack_start(m_deleteButton); |
m_buttonBoxL.pack_start(m_deleteButton); |
168 |
sigc::mem_fun(*this, &MacrosSetup::onButtonAddFromSelection) |
sigc::mem_fun(*this, &MacrosSetup::onButtonAddFromSelection) |
169 |
); |
); |
170 |
|
|
171 |
|
m_buttonUp.signal_clicked().connect( |
172 |
|
sigc::mem_fun(*this, &MacrosSetup::onButtonUp) |
173 |
|
); |
174 |
|
|
175 |
|
m_buttonDown.signal_clicked().connect( |
176 |
|
sigc::mem_fun(*this, &MacrosSetup::onButtonDown) |
177 |
|
); |
178 |
|
|
179 |
|
m_buttonEdit.signal_clicked().connect( |
180 |
|
sigc::mem_fun(*this, &MacrosSetup::onButtonEdit) |
181 |
|
); |
182 |
|
|
183 |
|
m_textViewComment.get_buffer()->signal_changed().connect( |
184 |
|
sigc::mem_fun(*this, &MacrosSetup::onCommentTextViewChanged) |
185 |
|
); |
186 |
|
|
187 |
m_applyButton.signal_clicked().connect( |
m_applyButton.signal_clicked().connect( |
188 |
sigc::mem_fun(*this, &MacrosSetup::onButtonApply) |
sigc::mem_fun(*this, &MacrosSetup::onButtonApply) |
189 |
); |
); |
268 |
} |
} |
269 |
} |
} |
270 |
|
|
271 |
|
void MacrosSetup::moveByDir(int d) { |
272 |
|
if (d < -1 || d > 1) return; |
273 |
|
int index = getSelectedMacroIndex(); |
274 |
|
if (index < 0) return; |
275 |
|
if (d == -1 && index == 0) return; |
276 |
|
if (d == +1 && index >= m_macros.size() - 1) return; |
277 |
|
|
278 |
|
// swap macros |
279 |
|
std::swap(m_macros[index + d], m_macros[index]); |
280 |
|
|
281 |
|
// swap tree view rows |
282 |
|
Gtk::TreePath p1(ToString(index + d)); |
283 |
|
Gtk::TreePath p2(ToString(index)); |
284 |
|
Gtk::TreeModel::iterator it1 = m_treeStoreMacros->get_iter(p1); |
285 |
|
Gtk::TreeModel::iterator it2 = m_treeStoreMacros->get_iter(p2); |
286 |
|
m_treeStoreMacros->iter_swap(it1, it2); |
287 |
|
int idx1 = (*it1)[m_treeModelMacros.m_col_index]; |
288 |
|
int idx2 = (*it2)[m_treeModelMacros.m_col_index]; |
289 |
|
(*it1)[m_treeModelMacros.m_col_index] = idx2; |
290 |
|
(*it2)[m_treeModelMacros.m_col_index] = idx1; |
291 |
|
Glib::ustring s1 = (*it1)[m_treeModelMacros.m_col_key]; |
292 |
|
Glib::ustring s2 = (*it2)[m_treeModelMacros.m_col_key]; |
293 |
|
(*it1)[m_treeModelMacros.m_col_key] = s2; |
294 |
|
(*it2)[m_treeModelMacros.m_col_key] = s1; |
295 |
|
|
296 |
|
m_modified = true; |
297 |
|
} |
298 |
|
|
299 |
|
void MacrosSetup::onButtonUp() { |
300 |
|
moveByDir(-1); |
301 |
|
} |
302 |
|
|
303 |
|
void MacrosSetup::onButtonDown() { |
304 |
|
moveByDir(+1); |
305 |
|
} |
306 |
|
|
307 |
|
void MacrosSetup::onButtonEdit() { |
308 |
|
Serialization::Archive* macro = getSelectedMacro(); |
309 |
|
if (!macro) return; |
310 |
|
|
311 |
|
m_modifiedBeforeMacroEditor = isModified(); |
312 |
|
|
313 |
|
MacroEditor* editor = new MacroEditor(); |
314 |
|
editor->setMacro(macro, false); |
315 |
|
editor->signal_changes_applied().connect( |
316 |
|
sigc::mem_fun(*this, &MacrosSetup::onMacroEditorAppliedChanges) |
317 |
|
); |
318 |
|
editor->show(); |
319 |
|
} |
320 |
|
|
321 |
|
void MacrosSetup::onMacroEditorAppliedChanges() { |
322 |
|
// so that the user does not need to click on a Apply buttons twice |
323 |
|
if (!m_modifiedBeforeMacroEditor) |
324 |
|
onButtonApply(); |
325 |
|
updateStatus(); |
326 |
|
} |
327 |
|
|
328 |
|
void MacrosSetup::onCommentTextViewChanged() { |
329 |
|
if (m_ignoreCommentTextViewChange) return; |
330 |
|
//printf("textChanged\n"); |
331 |
|
Serialization::Archive* macro = getSelectedMacro(); |
332 |
|
if (!macro) return; |
333 |
|
macro->setComment( |
334 |
|
m_textViewComment.get_buffer()->get_text() |
335 |
|
); |
336 |
|
updateStatus(); |
337 |
|
} |
338 |
|
|
339 |
|
int MacrosSetup::getSelectedMacroIndex() const { |
340 |
|
std::vector<Gtk::TreeModel::Path> v = m_treeViewMacros.get_selection()->get_selected_rows(); |
341 |
|
if (v.empty()) return -1; |
342 |
|
Gtk::TreeModel::iterator it = m_treeStoreMacros->get_iter(v[0]); |
343 |
|
if (!it) return -1; |
344 |
|
const Gtk::TreeModel::Row& row = *it; |
345 |
|
int index = row[m_treeModelMacros.m_col_index]; |
346 |
|
if (index < 0 || index >= m_macros.size()) return -1; |
347 |
|
return index; |
348 |
|
} |
349 |
|
|
350 |
|
Serialization::Archive* MacrosSetup::getSelectedMacro() { |
351 |
|
int index = getSelectedMacroIndex(); |
352 |
|
if (index < 0) return NULL; |
353 |
|
return &m_macros[index]; |
354 |
|
} |
355 |
|
|
356 |
static Glib::ustring indexToAccKey(uint index) { |
static Glib::ustring indexToAccKey(uint index) { |
357 |
if (index >= 12) return ""; |
if (index >= 12) return ""; |
358 |
return "F" + ToString(index+1); |
return "F" + ToString(index+1); |
423 |
const bool bValidSelection = !v.empty(); |
const bool bValidSelection = !v.empty(); |
424 |
m_deleteButton.set_sensitive(bValidSelection); |
m_deleteButton.set_sensitive(bValidSelection); |
425 |
m_inverseDeleteButton.set_sensitive(bValidSelection); |
m_inverseDeleteButton.set_sensitive(bValidSelection); |
426 |
|
m_buttonEdit.set_sensitive(bValidSelection); |
427 |
|
|
428 |
|
// update comment text view |
429 |
|
std::string sComment; |
430 |
|
Serialization::Archive* macro = getSelectedMacro(); |
431 |
|
if (macro) |
432 |
|
sComment = macro->comment(); |
433 |
|
m_ignoreCommentTextViewChange = true; |
434 |
|
m_textViewComment.get_buffer()->set_text(sComment); |
435 |
|
m_ignoreCommentTextViewChange = false; |
436 |
|
m_textViewComment.set_sensitive(bValidSelection); |
437 |
} |
} |
438 |
|
|
439 |
// Cmd key on Mac, Ctrl key on all other OSs |
// Cmd key on Mac, Ctrl key on all other OSs |
550 |
} |
} |
551 |
|
|
552 |
void MacrosSetup::updateStatus() { |
void MacrosSetup::updateStatus() { |
553 |
|
bool bValidSelection = !m_treeViewMacros.get_selection()->get_selected_rows().empty(); |
554 |
m_addFromClipboardButton.set_sensitive( |
m_addFromClipboardButton.set_sensitive( |
555 |
m_clipboardContent && m_clipboardContent->rootObject() |
m_clipboardContent && m_clipboardContent->rootObject() |
556 |
); |
); |
557 |
m_addFromSelectionButton.set_sensitive(m_selectedDimRgn); |
m_addFromSelectionButton.set_sensitive(m_selectedDimRgn); |
558 |
|
m_buttonEdit.set_sensitive(bValidSelection); |
559 |
m_applyButton.set_sensitive(isModified()); |
m_applyButton.set_sensitive(isModified()); |
560 |
|
m_textViewComment.set_sensitive(bValidSelection); |
561 |
updateStatusBar(); |
updateStatusBar(); |
562 |
} |
} |
563 |
|
|