1 |
/* |
2 |
Copyright (c) MMXVII Christian Schoenebeck |
3 |
|
4 |
This file is part of "gigedit" and released under the terms of the |
5 |
GNU General Public License version 2. |
6 |
*/ |
7 |
|
8 |
#ifndef GIGEDIT_MACROEDITOR_H |
9 |
#define GIGEDIT_MACROEDITOR_H |
10 |
|
11 |
#ifdef LIBGIG_HEADER_FILE |
12 |
# include LIBGIG_HEADER_FILE(gig.h) |
13 |
# include LIBGIG_HEADER_FILE(Serialization.h) |
14 |
#else |
15 |
# include <gig.h> |
16 |
# include <Serialization.h> |
17 |
#endif |
18 |
|
19 |
#include <gtkmm.h> |
20 |
#if HAVE_CONFIG_H |
21 |
# include <config.h> |
22 |
#endif |
23 |
#include "compat.h" |
24 |
#include <gtkmm/uimanager.h> |
25 |
#include <gtkmm/actiongroup.h> |
26 |
#include "wrapLabel.hh" |
27 |
#include "ManagedWindow.h" |
28 |
|
29 |
/** @brief Editor for gigedit macros. |
30 |
* |
31 |
* Implements a window which allows to edit the abstract tree of one macro |
32 |
* that may be applied with gigedit. |
33 |
*/ |
34 |
class MacroEditor : public ManagedWindow { |
35 |
public: |
36 |
MacroEditor(); |
37 |
~MacroEditor(); |
38 |
void setMacro(Serialization::Archive* macro, bool isClipboard); |
39 |
|
40 |
sigc::signal<void>& signal_changes_applied(); |
41 |
|
42 |
// implementation for abstract methods of interface class "ManagedWindow" |
43 |
virtual Settings::Property<int>* windowSettingX() { return &Settings::singleton()->macroEditorWindowX; } |
44 |
virtual Settings::Property<int>* windowSettingY() { return &Settings::singleton()->macroEditorWindowY; } |
45 |
virtual Settings::Property<int>* windowSettingWidth() { return &Settings::singleton()->macroEditorWindowW; } |
46 |
virtual Settings::Property<int>* windowSettingHeight() { return &Settings::singleton()->macroEditorWindowH; } |
47 |
|
48 |
protected: |
49 |
Serialization::Archive* m_macroOriginal; |
50 |
Serialization::Archive m_macro; |
51 |
|
52 |
sigc::signal<void> m_changes_applied; |
53 |
|
54 |
Gtk::VBox m_vbox; |
55 |
Gtk::HBox m_footerHBox; |
56 |
Gtk::HBox m_statusHBox; |
57 |
Gtk::HButtonBox m_buttonBoxL; |
58 |
Gtk::HButtonBox m_buttonBox; |
59 |
Gtk::ScrolledWindow m_scrolledWindow; |
60 |
#if GTKMM_MAJOR_VERSION < 3 |
61 |
view::WrapLabel m_labelIntro; |
62 |
#else |
63 |
Gtk::Label m_labelIntro; |
64 |
#endif |
65 |
|
66 |
class ComboOptionsModel : public Gtk::TreeModel::ColumnRecord { |
67 |
public: |
68 |
ComboOptionsModel() { |
69 |
add(m_col_choice); |
70 |
} |
71 |
|
72 |
Gtk::TreeModelColumn<Glib::ustring> m_col_choice; |
73 |
} m_comboOptionsModel; |
74 |
|
75 |
class MacroModel : public Gtk::TreeModel::ColumnRecord { |
76 |
public: |
77 |
MacroModel() { |
78 |
add(m_col_name); |
79 |
add(m_col_type); |
80 |
add(m_col_value); |
81 |
add(m_col_uid); |
82 |
add(m_col_allowTextEntry); |
83 |
add(m_col_editable); |
84 |
add(m_col_options); |
85 |
} |
86 |
|
87 |
Gtk::TreeModelColumn<Glib::ustring> m_col_name; |
88 |
Gtk::TreeModelColumn<Glib::ustring> m_col_type; |
89 |
Gtk::TreeModelColumn<Glib::ustring> m_col_value; |
90 |
Gtk::TreeModelColumn<Serialization::UID> m_col_uid; |
91 |
Gtk::TreeModelColumn<bool> m_col_allowTextEntry; |
92 |
Gtk::TreeModelColumn<bool> m_col_editable; |
93 |
Gtk::TreeModelColumn<Glib::RefPtr<Gtk::ListStore> > m_col_options; |
94 |
} m_treeModelMacro; |
95 |
|
96 |
class MacroTreeStore : public Gtk::TreeStore { |
97 |
public: |
98 |
static Glib::RefPtr<MacroTreeStore> create(const MacroModel& columns) { |
99 |
return Glib::RefPtr<MacroTreeStore>( new MacroTreeStore(columns) ); |
100 |
} |
101 |
protected: |
102 |
MacroTreeStore(const MacroModel& columns) : Gtk::TreeStore(columns) {} |
103 |
}; |
104 |
|
105 |
Gtk::TreeView m_treeViewMacro; |
106 |
Glib::RefPtr<MacroTreeStore> m_treeStoreMacro; |
107 |
Gtk::CellRendererCombo m_valueCellRenderer; |
108 |
Glib::RefPtr<Gtk::ListStore> m_comboBoxModel; |
109 |
bool m_ignoreTreeViewValueChange; |
110 |
|
111 |
Gtk::Label m_statusLabel; |
112 |
Gtk::Button m_deleteButton; |
113 |
Gtk::Button m_inverseDeleteButton; |
114 |
Gtk::Button m_applyButton; |
115 |
Gtk::Button m_cancelButton; |
116 |
|
117 |
bool m_altKeyDown; |
118 |
bool m_primaryKeyDown; // on Mac: Cmd key, on all other OSs: Ctrl key |
119 |
|
120 |
bool isModified() const; |
121 |
void onButtonCancel(); |
122 |
void onButtonApply(); |
123 |
void onWindowHide(); |
124 |
bool onWindowDelete(GdkEventAny* e); |
125 |
void updateStatus(); |
126 |
void updateStatusBar(); |
127 |
void reloadTreeView(); |
128 |
void buildTreeView(const Gtk::TreeModel::Row& parentRow, const Serialization::Object& parentObject); |
129 |
void onTreeViewSelectionChanged(); |
130 |
void onMacroTreeViewKeyRelease(GdkEventKey* button); |
131 |
void onMacroTreeViewRowValueChanged(const Gtk::TreeModel::Path& path, |
132 |
const Gtk::TreeModel::iterator& iter); |
133 |
void onMacroTreeViewRowValueChangedImpl(const Gtk::TreeModel::Path& path, |
134 |
const Gtk::TreeModel::iterator& iter, |
135 |
const Glib::ustring& value); |
136 |
void onValueCellEdited(const Glib::ustring& sPath, const Glib::ustring& text); |
137 |
void deleteSelectedRows(); |
138 |
void inverseDeleteSelectedRows(); |
139 |
void deleteRows(const std::vector<Gtk::TreeModel::Path>& rows); |
140 |
bool onKeyPressed(GdkEventKey* key); |
141 |
bool onKeyReleased(GdkEventKey* key); |
142 |
Glib::RefPtr<Gtk::ListStore> createComboOptions(const char** options); |
143 |
}; |
144 |
|
145 |
#endif // GIGEDIT_MACROEDITOR_H |