/[svn]/gigedit/trunk/src/gigedit/MacroEditor.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/MacroEditor.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3151 by schoenebeck, Fri May 5 18:44:59 2017 UTC revision 3154 by schoenebeck, Sat May 6 13:46:14 2017 UTC
# Line 12  Line 12 
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")),
16        m_inverseDeleteButton(_("Inverse Delete")),
17      m_applyButton(_("_Apply"), true),      m_applyButton(_("_Apply"), true),
18      m_cancelButton(_("_Cancel"), true)      m_cancelButton(_("_Cancel"), true)
19  {  {
# Line 27  MacroEditor::MacroEditor() : Line 29  MacroEditor::MacroEditor() :
29      m_treeViewMacro.append_column(_("Key"), m_treeModelMacro.m_col_name);      m_treeViewMacro.append_column(_("Key"), m_treeModelMacro.m_col_name);
30      m_treeViewMacro.append_column(_("Type"), m_treeModelMacro.m_col_type);      m_treeViewMacro.append_column(_("Type"), m_treeModelMacro.m_col_type);
31      m_treeViewMacro.append_column_editable(_("Value"), m_treeModelMacro.m_col_value);      m_treeViewMacro.append_column_editable(_("Value"), m_treeModelMacro.m_col_value);
32        {
33            Gtk::TreeViewColumn* column = m_treeViewMacro.get_column(1);
34            Gtk::CellRendererText* cellrenderer =
35                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
36            cellrenderer->property_foreground().set_value("#bababa");
37        }
38      /*{      /*{
39          Gtk::TreeViewColumn* column = m_treeViewMacro.get_column(0);          Gtk::TreeViewColumn* column = m_treeViewMacro.get_column(0);
40          Gtk::CellRendererText* cellrenderer =          Gtk::CellRendererText* cellrenderer =
# Line 44  MacroEditor::MacroEditor() : Line 52  MacroEditor::MacroEditor() :
52          );          );
53      }*/      }*/
54      m_treeViewMacro.set_headers_visible(true);      m_treeViewMacro.set_headers_visible(true);
55      /*m_treeViewMacro.signal_button_press_event().connect_notify(      m_treeViewMacro.get_selection()->signal_changed().connect(
56          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MacroEditor::onTreeViewSelectionChanged)
57      );*/      );
58      /*m_refSamplesTreeModel->signal_row_changed().connect(      m_treeViewMacro.signal_key_release_event().connect_notify(
59          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MacroEditor::onMacroTreeViewKeyRelease)
60      );*/      );
61        m_treeStoreMacro->signal_row_changed().connect(
62            sigc::mem_fun(*this, &MacroEditor::onMacroTreeViewRowValueChanged)
63        );
64        m_ignoreTreeViewValueChange = false;
65    
66      m_scrolledWindow.add(m_treeViewMacro);      m_scrolledWindow.add(m_treeViewMacro);
67      m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
68      m_vbox.pack_start(m_scrolledWindow);      m_vbox.pack_start(m_scrolledWindow);
69    
70        m_buttonBoxL.set_layout(Gtk::BUTTONBOX_START);
71        m_buttonBoxL.pack_start(m_deleteButton);
72        m_buttonBoxL.pack_start(m_inverseDeleteButton);
73        m_deleteButton.set_sensitive(false);
74        m_inverseDeleteButton.set_sensitive(false);
75    
76      m_buttonBox.set_layout(Gtk::BUTTONBOX_END);      m_buttonBox.set_layout(Gtk::BUTTONBOX_END);
77      m_buttonBox.pack_start(m_applyButton);      m_buttonBox.pack_start(m_applyButton);
78      m_buttonBox.pack_start(m_cancelButton);      m_buttonBox.pack_start(m_cancelButton);
# Line 72  MacroEditor::MacroEditor() : Line 90  MacroEditor::MacroEditor() :
90      m_statusHBox.pack_start(m_statusLabel);      m_statusHBox.pack_start(m_statusLabel);
91      m_statusHBox.show_all_children();      m_statusHBox.show_all_children();
92    
93        m_footerHBox.pack_start(m_buttonBoxL, Gtk::PACK_SHRINK);
94      m_footerHBox.pack_start(m_statusHBox);      m_footerHBox.pack_start(m_statusHBox);
95      m_footerHBox.pack_start(m_buttonBox, Gtk::PACK_SHRINK);      m_footerHBox.pack_start(m_buttonBox, Gtk::PACK_SHRINK);
96    
# Line 85  MacroEditor::MacroEditor() : Line 104  MacroEditor::MacroEditor() :
104          sigc::mem_fun(*this, &MacroEditor::onButtonCancel)          sigc::mem_fun(*this, &MacroEditor::onButtonCancel)
105      );      );
106    
107        m_deleteButton.signal_clicked().connect(
108            sigc::mem_fun(*this, &MacroEditor::deleteSelectedRows)
109        );
110    
111        m_inverseDeleteButton.signal_clicked().connect(
112            sigc::mem_fun(*this, &MacroEditor::inverseDeleteSelectedRows)
113        );
114    
115      signal_hide().connect(      signal_hide().connect(
116          sigc::mem_fun(*this, &MacroEditor::onWindowHide)          sigc::mem_fun(*this, &MacroEditor::onWindowHide)
117      );      );
# Line 136  void MacroEditor::buildTreeView(const Gt Line 163  void MacroEditor::buildTreeView(const Gt
163  }  }
164    
165  void MacroEditor::reloadTreeView() {  void MacroEditor::reloadTreeView() {
166        m_ignoreTreeViewValueChange = true;
167    
168      m_treeStoreMacro->clear();      m_treeStoreMacro->clear();
169    
170      const Serialization::Object& rootObject = m_macro.rootObject();      const Serialization::Object& rootObject = m_macro.rootObject();
# Line 152  void MacroEditor::reloadTreeView() { Line 181  void MacroEditor::reloadTreeView() {
181      m_treeViewMacro.expand_all();      m_treeViewMacro.expand_all();
182    
183      updateStatus();      updateStatus();
184    
185        m_ignoreTreeViewValueChange = false;
186    }
187    
188    void MacroEditor::onTreeViewSelectionChanged() {
189        std::vector<Gtk::TreeModel::Path> v = m_treeViewMacro.get_selection()->get_selected_rows();
190        const bool bValidSelection = !v.empty();
191        m_deleteButton.set_sensitive(bValidSelection);
192        m_inverseDeleteButton.set_sensitive(bValidSelection);
193    }
194    
195    void MacroEditor::onMacroTreeViewKeyRelease(GdkEventKey* key) {
196        if (key->keyval == GDK_KEY_BackSpace || key->keyval == GDK_KEY_Delete)
197            deleteSelectedRows();
198    }
199    
200    void MacroEditor::onMacroTreeViewRowValueChanged(const Gtk::TreeModel::Path& path,
201                                                     const Gtk::TreeModel::iterator& iter)
202    {
203        if (m_ignoreTreeViewValueChange) return;
204        if (!iter) return;
205        Gtk::TreeModel::Row row = *iter;
206        Glib::ustring value    = row[m_treeModelMacro.m_col_value];
207        Serialization::UID uid = row[m_treeModelMacro.m_col_uid];
208        Serialization::String gigvalue(gig_from_utf8(value));
209        Serialization::Object& object = m_macro.objectByUID(uid);
210        std::string errorText;
211        try {
212            m_macro.setAutoValue(object, gigvalue);
213        } catch (Serialization::Exception e) {
214            errorText = e.Message;
215        } catch (...) {
216            errorText = _("Unknown exception during object value change");
217        }
218        if (!errorText.empty()) {
219            Glib::ustring txt = _("Couldn't change value:\n") + errorText;
220            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
221            msg.run();
222        }
223    }
224    
225    void MacroEditor::deleteSelectedRows() {
226        Glib::RefPtr<Gtk::TreeSelection> sel = m_treeViewMacro.get_selection();
227        std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
228        for (int r = rows.size() - 1; r >= 0; --r) {
229            Gtk::TreeModel::iterator it = m_treeStoreMacro->get_iter(rows[r]);
230            if (!it) continue;
231            Gtk::TreeModel::Row row = *it;
232            Serialization::UID uid = row[m_treeModelMacro.m_col_uid];
233            if (uid == m_macro.rootObject().uid()) continue; // prohibit deleting root object
234            Gtk::TreeModel::iterator itParent = row.parent();
235            if (!itParent) continue;
236            Gtk::TreeModel::Row rowParent = *itParent;
237            Serialization::UID uidParent = rowParent[m_treeModelMacro.m_col_uid];
238            //Serialization::Object& object = m_macro.objectByUID(uid);
239            Serialization::Object& parentObject = m_macro.objectByUID(uidParent);
240            const Serialization::Member& member = parentObject.memberByUID(uid);
241            m_macro.removeMember(parentObject, member);
242            //m_macro.remove(object);
243        }
244        reloadTreeView();
245    }
246    
247    void MacroEditor::inverseDeleteSelectedRows() {
248  }  }
249    
250  void MacroEditor::updateStatus() {  void MacroEditor::updateStatus() {

Legend:
Removed from v.3151  
changed lines
  Added in v.3154

  ViewVC Help
Powered by ViewVC