12 |
MacroEditor::MacroEditor() : |
MacroEditor::MacroEditor() : |
13 |
m_macroOriginal(NULL), |
m_macroOriginal(NULL), |
14 |
m_statusLabel("", Gtk::ALIGN_START), |
m_statusLabel("", Gtk::ALIGN_START), |
15 |
m_deleteButton(_("Delete")), |
m_deleteButton(Glib::ustring(_("Delete")) + " " + UNICODE_PRIMARY_KEY_SYMBOL + UNICODE_ERASE_KEY_SYMBOL), |
16 |
m_inverseDeleteButton(_("Inverse Delete")), |
m_inverseDeleteButton(Glib::ustring(_("Inverse Delete")) + " " + UNICODE_ALT_KEY_SYMBOL + UNICODE_ERASE_KEY_SYMBOL), |
17 |
m_applyButton(_("_Apply"), true), |
m_applyButton(_("_Apply"), true), |
18 |
m_cancelButton(_("_Cancel"), true) |
m_cancelButton(_("_Cancel"), true), |
19 |
|
m_altKeyDown(false) |
20 |
{ |
{ |
21 |
add(m_vbox); |
add(m_vbox); |
22 |
|
|
121 |
sigc::mem_fun(*this, &MacroEditor::onWindowDelete) |
sigc::mem_fun(*this, &MacroEditor::onWindowDelete) |
122 |
); |
); |
123 |
|
|
124 |
|
signal_key_press_event().connect( |
125 |
|
sigc::mem_fun(*this, &MacroEditor::onKeyPressed) |
126 |
|
); |
127 |
|
signal_key_release_event().connect( |
128 |
|
sigc::mem_fun(*this, &MacroEditor::onKeyReleased) |
129 |
|
); |
130 |
|
|
131 |
show_all_children(); |
show_all_children(); |
132 |
updateStatus(); |
updateStatus(); |
133 |
} |
} |
200 |
m_inverseDeleteButton.set_sensitive(bValidSelection); |
m_inverseDeleteButton.set_sensitive(bValidSelection); |
201 |
} |
} |
202 |
|
|
203 |
|
bool MacroEditor::onKeyPressed(GdkEventKey* key) { |
204 |
|
//printf("key down 0x%x\n", key->keyval); |
205 |
|
if (key->keyval == GDK_KEY_Alt_L || key->keyval == GDK_KEY_Alt_R) |
206 |
|
m_altKeyDown = true; |
207 |
|
return false; |
208 |
|
} |
209 |
|
|
210 |
|
bool MacroEditor::onKeyReleased(GdkEventKey* key) { |
211 |
|
//printf("key up 0x%x\n", key->keyval); |
212 |
|
if (key->keyval == GDK_KEY_Alt_L || key->keyval == GDK_KEY_Alt_R) |
213 |
|
m_altKeyDown = false; |
214 |
|
return false; |
215 |
|
} |
216 |
|
|
217 |
void MacroEditor::onMacroTreeViewKeyRelease(GdkEventKey* key) { |
void MacroEditor::onMacroTreeViewKeyRelease(GdkEventKey* key) { |
218 |
if (key->keyval == GDK_KEY_BackSpace || key->keyval == GDK_KEY_Delete) |
if (key->keyval == GDK_KEY_BackSpace || key->keyval == GDK_KEY_Delete) { |
219 |
deleteSelectedRows(); |
if (m_altKeyDown) |
220 |
|
inverseDeleteSelectedRows(); |
221 |
|
else |
222 |
|
deleteSelectedRows(); |
223 |
|
} |
224 |
} |
} |
225 |
|
|
226 |
void MacroEditor::onMacroTreeViewRowValueChanged(const Gtk::TreeModel::Path& path, |
void MacroEditor::onMacroTreeViewRowValueChanged(const Gtk::TreeModel::Path& path, |
251 |
void MacroEditor::deleteSelectedRows() { |
void MacroEditor::deleteSelectedRows() { |
252 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_treeViewMacro.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_treeViewMacro.get_selection(); |
253 |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
254 |
|
deleteRows(rows); |
255 |
|
} |
256 |
|
|
257 |
|
void MacroEditor::deleteRows(const std::vector<Gtk::TreeModel::Path>& rows) { |
258 |
for (int r = rows.size() - 1; r >= 0; --r) { |
for (int r = rows.size() - 1; r >= 0; --r) { |
259 |
Gtk::TreeModel::iterator it = m_treeStoreMacro->get_iter(rows[r]); |
Gtk::TreeModel::iterator it = m_treeStoreMacro->get_iter(rows[r]); |
260 |
if (!it) continue; |
if (!it) continue; |
274 |
reloadTreeView(); |
reloadTreeView(); |
275 |
} |
} |
276 |
|
|
277 |
|
static bool _onEachTreeRow(const Gtk::TreeModel::Path& input, std::vector<Gtk::TreeModel::Path>* output) { |
278 |
|
output->push_back(input); |
279 |
|
return false; // continue walking the tree |
280 |
|
} |
281 |
|
|
282 |
void MacroEditor::inverseDeleteSelectedRows() { |
void MacroEditor::inverseDeleteSelectedRows() { |
283 |
|
// get all rows of tree view |
284 |
|
std::vector<Gtk::TreeModel::Path> rows; |
285 |
|
m_treeViewMacro.get_model()->foreach_path( |
286 |
|
sigc::bind( |
287 |
|
sigc::ptr_fun(&_onEachTreeRow), |
288 |
|
&rows |
289 |
|
) |
290 |
|
); |
291 |
|
|
292 |
|
// erase all entries from "rows" which are currently selected |
293 |
|
std::vector<Gtk::TreeModel::Path> vSelected = m_treeViewMacro.get_selection()->get_selected_rows(); |
294 |
|
for (int i = rows.size() - 1; i >= 0; --i) { |
295 |
|
bool bIsSelected = std::find(vSelected.begin(), vSelected.end(), |
296 |
|
rows[i]) != vSelected.end(); |
297 |
|
if (bIsSelected) |
298 |
|
rows.erase(rows.begin() + i); |
299 |
|
} |
300 |
|
|
301 |
|
// delete those 'inverse' selected rows |
302 |
|
deleteRows(rows); |
303 |
} |
} |
304 |
|
|
305 |
void MacroEditor::updateStatus() { |
void MacroEditor::updateStatus() { |
362 |
} |
} |
363 |
|
|
364 |
void MacroEditor::onButtonApply() { |
void MacroEditor::onButtonApply() { |
365 |
//m_macro.encode(); |
std::string errorText; |
366 |
*m_macroOriginal = m_macro; |
try { |
367 |
|
// enforce re-encoding the abstract object model and resetting the |
368 |
|
// 'modified' state |
369 |
|
m_macro.rawData(); |
370 |
|
// replace actual effective Archive object which is effectively used |
371 |
|
// for macro apply operations |
372 |
|
*m_macroOriginal = m_macro; |
373 |
|
} catch (Serialization::Exception e) { |
374 |
|
errorText = e.Message; |
375 |
|
} catch (...) { |
376 |
|
errorText = _("Unknown exception while applying macro changes"); |
377 |
|
} |
378 |
|
if (!errorText.empty()) { |
379 |
|
Glib::ustring txt = _("Couldn't apply macro changes:\n") + errorText; |
380 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
381 |
|
msg.run(); |
382 |
|
} |
383 |
|
updateStatus(); |
384 |
} |
} |
385 |
|
|
386 |
void MacroEditor::onWindowHide() { |
void MacroEditor::onWindowHide() { |