/[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 3184 by schoenebeck, Wed May 17 12:28:39 2017 UTC revision 3456 by persson, Sun Jan 27 10:07:56 2019 UTC
# Line 1  Line 1 
1  /*  /*
2      Copyright (c) MMXVII Christian Schoenebeck      Copyright (c) MMXVII - MMXIX Christian Schoenebeck
3    
4      This file is part of "gigedit" and released under the terms of the      This file is part of "gigedit" and released under the terms of the
5      GNU General Public License version 2.      GNU General Public License version 2.
# Line 21  MacroEditor::MacroEditor() : Line 21  MacroEditor::MacroEditor() :
21  {  {
22      add(m_vbox);      add(m_vbox);
23    
24      set_default_size(800, 600);      if (!Settings::singleton()->autoRestoreWindowDimension) {
25            set_default_size(800, 600);
26            set_position(Gtk::WIN_POS_MOUSE);
27        }
28    
29    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 12)
30        m_labelIntro.set_margin_start(10);
31        m_labelIntro.set_margin_end(10);
32    #else
33      m_labelIntro.set_padding(10, 10);      m_labelIntro.set_padding(10, 10);
34    #endif
35  #if GTKMM_MAJOR_VERSION >= 3  #if GTKMM_MAJOR_VERSION >= 3
36      m_labelIntro.set_line_wrap();      m_labelIntro.set_line_wrap();
37  #endif  #endif
# Line 58  MacroEditor::MacroEditor() : Line 66  MacroEditor::MacroEditor() :
66          //column->set_renderer(m_valueCellRenderer, m_treeModelMacro.m_col_value);          //column->set_renderer(m_valueCellRenderer, m_treeModelMacro.m_col_value);
67          column->add_attribute(m_valueCellRenderer.property_text(),          column->add_attribute(m_valueCellRenderer.property_text(),
68                                m_treeModelMacro.m_col_value);                                m_treeModelMacro.m_col_value);
69          //column->add_attribute(m_valueCellRenderer.property_has_entry(),          column->add_attribute(m_valueCellRenderer.property_has_entry(),
70          //                      m_treeModelMacro.m_col_allowTextEntry);                                m_treeModelMacro.m_col_allowTextEntry);
71          column->add_attribute(m_valueCellRenderer.property_editable(),          column->add_attribute(m_valueCellRenderer.property_editable(),
72                                m_treeModelMacro.m_col_editable);                                m_treeModelMacro.m_col_editable);
73          column->add_attribute(m_valueCellRenderer.property_model(),          column->add_attribute(m_valueCellRenderer.property_model(),
# Line 80  MacroEditor::MacroEditor() : Line 88  MacroEditor::MacroEditor() :
88      m_treeViewMacro.get_selection()->signal_changed().connect(      m_treeViewMacro.get_selection()->signal_changed().connect(
89          sigc::mem_fun(*this, &MacroEditor::onTreeViewSelectionChanged)          sigc::mem_fun(*this, &MacroEditor::onTreeViewSelectionChanged)
90      );      );
91    #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
92        m_treeViewMacro.signal_key_release_event().connect(
93    #else
94      m_treeViewMacro.signal_key_release_event().connect_notify(      m_treeViewMacro.signal_key_release_event().connect_notify(
95    #endif
96          sigc::mem_fun(*this, &MacroEditor::onMacroTreeViewKeyRelease)          sigc::mem_fun(*this, &MacroEditor::onMacroTreeViewKeyRelease)
97      );      );
98      m_treeStoreMacro->signal_row_changed().connect(      m_treeStoreMacro->signal_row_changed().connect(
# Line 105  MacroEditor::MacroEditor() : Line 117  MacroEditor::MacroEditor() :
117      m_applyButton.set_sensitive(false);      m_applyButton.set_sensitive(false);
118      m_applyButton.grab_focus();      m_applyButton.grab_focus();
119    
120  #if GTKMM_MAJOR_VERSION >= 3  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 12)
121        m_labelIntro.set_margin_start(6);
122        m_labelIntro.set_margin_end(6);
123    #elif GTKMM_MAJOR_VERSION >= 3
124      m_statusLabel.set_margin_left(6);      m_statusLabel.set_margin_left(6);
125      m_statusLabel.set_margin_right(6);      m_statusLabel.set_margin_right(6);
126  #else  #else
# Line 113  MacroEditor::MacroEditor() : Line 128  MacroEditor::MacroEditor() :
128  #endif  #endif
129    
130      m_statusHBox.pack_start(m_statusLabel);      m_statusHBox.pack_start(m_statusLabel);
131    #if HAS_GTKMM_SHOW_ALL_CHILDREN
132      m_statusHBox.show_all_children();      m_statusHBox.show_all_children();
133    #endif
134    
135      m_footerHBox.pack_start(m_buttonBoxL, Gtk::PACK_SHRINK);      m_footerHBox.pack_start(m_buttonBoxL, Gtk::PACK_SHRINK);
136      m_footerHBox.pack_start(m_statusHBox);      m_footerHBox.pack_start(m_statusHBox);
# Line 142  MacroEditor::MacroEditor() : Line 159  MacroEditor::MacroEditor() :
159      );      );
160    
161      signal_delete_event().connect(      signal_delete_event().connect(
162    #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
163          sigc::mem_fun(*this, &MacroEditor::onWindowDelete)          sigc::mem_fun(*this, &MacroEditor::onWindowDelete)
164    #else
165            sigc::mem_fun(*this, &MacroEditor::onWindowDeleteP)
166    #endif
167      );      );
168    
169      signal_key_press_event().connect(      signal_key_press_event().connect(
# Line 155  MacroEditor::MacroEditor() : Line 176  MacroEditor::MacroEditor() :
176      m_deleteButton.set_tooltip_text(_("Delete the selected parameters from this macro."));      m_deleteButton.set_tooltip_text(_("Delete the selected parameters from this macro."));
177      m_inverseDeleteButton.set_tooltip_text(_("Delete all parameters from this macro except the selected ones."));      m_inverseDeleteButton.set_tooltip_text(_("Delete all parameters from this macro except the selected ones."));
178    
179    #if HAS_GTKMM_SHOW_ALL_CHILDREN
180      show_all_children();      show_all_children();
181    #endif
182      updateStatus();      updateStatus();
183  }  }
184    
# Line 196  Glib::RefPtr<Gtk::ListStore> MacroEditor Line 219  Glib::RefPtr<Gtk::ListStore> MacroEditor
219      return refOptions;      return refOptions;
220  }  }
221    
222    inline static Serialization::String _boolToStr(bool b) {
223        // 'NO' intentional all uper case in contrast to 'Yes', simply because I
224        // find them easier distinguishable that way on quick readings
225        return b ? "Yes" : "NO";
226    }
227    
228    static const char* _boolOptions[] = { "Yes", "NO", NULL };
229    
230  void MacroEditor::buildTreeView(const Gtk::TreeModel::Row& parentRow, const Serialization::Object& parentObject) {  void MacroEditor::buildTreeView(const Gtk::TreeModel::Row& parentRow, const Serialization::Object& parentObject) {
231      for (int iMember = 0; iMember < parentObject.members().size(); ++iMember) {      for (int iMember = 0; iMember < parentObject.members().size(); ++iMember) {
232          const Serialization::Member& member = parentObject.members()[iMember];          const Serialization::Member& member = parentObject.members()[iMember];
233          const Serialization::Object& object = m_macro.objectByUID(member.uid());          const Serialization::Object& object = m_macro.objectByUID(member.uid());
234            
235    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
236            //HACK: on GTKMM 3.9x append() below requires TreeNodeChildren, parentRow.children() returns TreeNodeConstChildren though, probably going to be fixed before final GTKMM4 release though.
237            const Gtk::TreeNodeConstChildren& children = parentRow.children();
238            Gtk::TreeNodeChildren* const pChildren = (Gtk::TreeNodeChildren* const) &children;
239            Gtk::TreeModel::iterator iterRow = m_treeStoreMacro->append(*pChildren);
240    #else
241          Gtk::TreeModel::iterator iterRow = m_treeStoreMacro->append(parentRow.children());          Gtk::TreeModel::iterator iterRow = m_treeStoreMacro->append(parentRow.children());
242    #endif
243          Gtk::TreeModel::Row row = *iterRow;          Gtk::TreeModel::Row row = *iterRow;
244          row[m_treeModelMacro.m_col_name] = gig_to_utf8(member.name());          row[m_treeModelMacro.m_col_name] = gig_to_utf8(member.name());
245          row[m_treeModelMacro.m_col_type] = gig_to_utf8(member.type().asLongDescr());          row[m_treeModelMacro.m_col_type] = gig_to_utf8(member.type().asLongDescr());
246          row[m_treeModelMacro.m_col_uid]  = object.uid();          row[m_treeModelMacro.m_col_uid]  = object.uid();
247          row[m_treeModelMacro.m_col_allowTextEntry] = false;          row[m_treeModelMacro.m_col_allowTextEntry] = true;
248    
249          if (object.type().isClass()) {          if (object.type().isClass()) {
250              row[m_treeModelMacro.m_col_value] = "(class)";              row[m_treeModelMacro.m_col_value] = "(class)";
# Line 222  void MacroEditor::buildTreeView(const Gt Line 261  void MacroEditor::buildTreeView(const Gt
261                  Glib::RefPtr<Gtk::ListStore> refOptions = createComboOptions(allKeys);                  Glib::RefPtr<Gtk::ListStore> refOptions = createComboOptions(allKeys);
262                  row[m_treeModelMacro.m_col_options] = refOptions;                  row[m_treeModelMacro.m_col_options] = refOptions;
263              }              }
264            } else if (object.type().isBool()) {
265                row[m_treeModelMacro.m_col_value] =  _boolToStr( m_macro.valueAsBool(object) );
266                row[m_treeModelMacro.m_col_editable] = true;
267                Glib::RefPtr<Gtk::ListStore> refOptions = createComboOptions(_boolOptions);
268                row[m_treeModelMacro.m_col_options] = refOptions;
269                row[m_treeModelMacro.m_col_allowTextEntry] = false;
270          } else {          } else {
271              row[m_treeModelMacro.m_col_value] = m_macro.valueAsString(object);              row[m_treeModelMacro.m_col_value] = m_macro.valueAsString(object);
272              row[m_treeModelMacro.m_col_editable] = true;              row[m_treeModelMacro.m_col_editable] = true;
# Line 276  static const guint primaryKeyR = Line 321  static const guint primaryKeyR =
321      GDK_KEY_Control_R;      GDK_KEY_Control_R;
322      #endif      #endif
323    
324    #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
325    bool MacroEditor::onKeyPressed(Gdk::EventKey& _key) {
326        GdkEventKey* key = _key.gobj();
327    #else
328  bool MacroEditor::onKeyPressed(GdkEventKey* key) {  bool MacroEditor::onKeyPressed(GdkEventKey* key) {
329    #endif
330      //printf("key down 0x%x\n", key->keyval);      //printf("key down 0x%x\n", key->keyval);
331      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)
332          m_altKeyDown = true;          m_altKeyDown = true;
# Line 285  bool MacroEditor::onKeyPressed(GdkEventK Line 335  bool MacroEditor::onKeyPressed(GdkEventK
335      return false;      return false;
336  }  }
337    
338    #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
339    bool MacroEditor::onKeyReleased(Gdk::EventKey& _key) {
340        GdkEventKey* key = _key.gobj();
341    #else
342  bool MacroEditor::onKeyReleased(GdkEventKey* key) {  bool MacroEditor::onKeyReleased(GdkEventKey* key) {
343    #endif
344      //printf("key up 0x%x\n", key->keyval);      //printf("key up 0x%x\n", key->keyval);
345      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)
346          m_altKeyDown = false;          m_altKeyDown = false;
# Line 294  bool MacroEditor::onKeyReleased(GdkEvent Line 349  bool MacroEditor::onKeyReleased(GdkEvent
349      return false;      return false;
350  }  }
351    
352    #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
353    bool MacroEditor::onMacroTreeViewKeyRelease(Gdk::EventKey& _key) {
354        GdkEventKey* key = _key.gobj();
355    #else
356  void MacroEditor::onMacroTreeViewKeyRelease(GdkEventKey* key) {  void MacroEditor::onMacroTreeViewKeyRelease(GdkEventKey* key) {
357    #endif
358      if (key->keyval == GDK_KEY_BackSpace || key->keyval == GDK_KEY_Delete) {      if (key->keyval == GDK_KEY_BackSpace || key->keyval == GDK_KEY_Delete) {
359          if (m_altKeyDown)          if (m_altKeyDown)
360              inverseDeleteSelectedRows();              inverseDeleteSelectedRows();
361          else if (m_primaryKeyDown)          else if (m_primaryKeyDown)
362              deleteSelectedRows();              deleteSelectedRows();
363      }      }
364    #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
365        return true;
366    #endif
367  }  }
368    
369  void MacroEditor::onValueCellEdited(const Glib::ustring& sPath, const Glib::ustring& text) {  void MacroEditor::onValueCellEdited(const Glib::ustring& sPath, const Glib::ustring& text) {
# Line 338  void MacroEditor::onMacroTreeViewRowValu Line 401  void MacroEditor::onMacroTreeViewRowValu
401              // no auto correct here yet (due to numeric vs. textual values)              // no auto correct here yet (due to numeric vs. textual values)
402              if (row[m_treeModelMacro.m_col_value] != value)              if (row[m_treeModelMacro.m_col_value] != value)
403                  row[m_treeModelMacro.m_col_value] = value;                  row[m_treeModelMacro.m_col_value] = value;
404            } else if (object.type().isBool()) {
405                m_macro.setAutoValue(object, gigvalue);
406                Serialization::String sBoolean = _boolToStr( m_macro.valueAsBool(object) );
407                // potentially auto correct (i.e. when type is bool, user entered '5' -> yields 'Yes')
408                if (row[m_treeModelMacro.m_col_value] != sBoolean)
409                    row[m_treeModelMacro.m_col_value] = sBoolean;
410          } else {          } else {
411              m_macro.setAutoValue(object, gigvalue);              m_macro.setAutoValue(object, gigvalue);
412              // potentially auto correct (i.e. when type is bool, user entered 5 -> yields 1)              // potentially auto correct (i.e. when type is bool, user entered 5 -> yields 1)
# Line 422  void MacroEditor::updateStatusBar() { Line 491  void MacroEditor::updateStatusBar() {
491      m_statusLabel.set_markup(txt);      m_statusLabel.set_markup(txt);
492  }  }
493    
494  bool MacroEditor::onWindowDelete(GdkEventAny* e) {  #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
495    bool MacroEditor::onWindowDelete(Gdk::Event& e) {
496        return onWindowDeleteP(NULL);
497    }
498    #endif
499    
500    bool MacroEditor::onWindowDeleteP(GdkEventAny* /*e*/) {
501      //printf("onWindowDelete\n");      //printf("onWindowDelete\n");
502    
503      if (!isModified()) return false; // propagate event further (which will close this window)      if (!isModified()) return false; // propagate event further (which will close this window)
504    
505      //gchar* msg = g_strdup_printf(_("Apply changes to macro \"%s\" before closing?"),      //gchar* msg = g_strdup_printf(_("Apply changes to macro \"%s\" before closing?"),
506      //                             m_macroOriginal->Name.c_str());      //                             m_macroOriginal->Name.c_str());
507      gchar* msg = g_strdup_printf(_("Apply changes to macro before closing?"));      gchar* msg = g_strdup(_("Apply changes to macro before closing?"));
508      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
509      g_free(msg);      g_free(msg);
510      dialog.set_secondary_text(_("If you close without applying, your changes will be lost."));      dialog.set_secondary_text(_("If you close without applying, your changes will be lost."));
# Line 465  bool MacroEditor::isModified() const { Line 540  bool MacroEditor::isModified() const {
540  }  }
541    
542  void MacroEditor::onButtonCancel() {  void MacroEditor::onButtonCancel() {
543      bool dropEvent = onWindowDelete(NULL);      bool dropEvent = onWindowDeleteP(NULL);
544      if (dropEvent) return;      if (dropEvent) return;
545      hide();      hide();
546  }  }

Legend:
Removed from v.3184  
changed lines
  Added in v.3456

  ViewVC Help
Powered by ViewVC