[glom] List view and Related Records: Disable buttons when appropriate.



commit edc483a24f29da0ca871c48526a889bed2d7d839
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Nov 11 10:16:19 2011 +0100

    List view and Related Records: Disable buttons when appropriate.
    
    * glom/mode_data/db_adddel/db_adddel.[h|cc]: Handle the
    Gtk::TreeView::Selection::signal_changed() signal and call a
    new virtual on_selection_changed() method.
    * glom/mode_data/db_adddel/db_adddel_withbuttons.[h|cc]:
    Disable the Edit/Open and Delete buttons when there is no selection.
    Bug #663812 (Andrà Klapper)

 ChangeLog                                         |   11 ++++++++++
 glom/mode_data/db_adddel/db_adddel.cc             |   23 +++++++++++++++++++++
 glom/mode_data/db_adddel/db_adddel.h              |    4 +++
 glom/mode_data/db_adddel/db_adddel_withbuttons.cc |    5 ++++
 glom/mode_data/db_adddel/db_adddel_withbuttons.h  |    1 +
 5 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 77677be..b1dd73c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-11-11  Murray Cumming  <murrayc murrayc com>
+
+	List view and Related Records: Disable buttons when appropriate.
+
+	* glom/mode_data/db_adddel/db_adddel.[h|cc]: Handle the 
+	Gtk::TreeView::Selection::signal_changed() signal and call a 
+	new virtual on_selection_changed() method.
+	* glom/mode_data/db_adddel/db_adddel_withbuttons.[h|cc]:
+	Disable the Edit/Open and Delete buttons when there is no selection.
+	Bug #663812 (Andrà Klapper)
+
 2011-11-10  Murray Cumming  <murrayc murrayc com>
 
 	Correct an error in the previous commit.
diff --git a/glom/mode_data/db_adddel/db_adddel.cc b/glom/mode_data/db_adddel/db_adddel.cc
index bd7c621..2a0419d 100644
--- a/glom/mode_data/db_adddel/db_adddel.cc
+++ b/glom/mode_data/db_adddel/db_adddel.cc
@@ -114,6 +114,13 @@ DbAddDel::DbAddDel()
 
   signal_style_changed().connect(sigc::mem_fun(*this, &DbAddDel::on_self_style_changed));
 #endif // !GLOM_ENABLE_CLIENT_ONLY
+
+  Glib::RefPtr<Gtk::TreeView::Selection> refSelection = m_TreeView.get_selection();
+  if(refSelection)
+  {
+    refSelection->signal_changed().connect(
+      sigc::mem_fun(*this, &DbAddDel::on_treeview_selection_changed));
+  }
 }
 
 DbAddDel::~DbAddDel()
@@ -2398,4 +2405,20 @@ Gtk::TreeModel::iterator DbAddDel::get_row_selected()
   return get_item_selected();
 }
 
+void DbAddDel::on_treeview_selection_changed()
+{
+  Glib::RefPtr<Gtk::TreeView::Selection> refSelection = m_TreeView.get_selection();
+  if(!refSelection)
+    return;
+
+  const bool one_selected = (refSelection->count_selected_rows() > 0);
+  on_selection_changed(one_selected);
+}
+
+void DbAddDel::on_selection_changed(bool selection)
+{
+  m_refContextDel->set_sensitive(selection);
+  m_refContextAdd->set_sensitive(selection);
+}
+
 } //namespace Glom
diff --git a/glom/mode_data/db_adddel/db_adddel.h b/glom/mode_data/db_adddel/db_adddel.h
index 8526181..f8b2cfc 100644
--- a/glom/mode_data/db_adddel/db_adddel.h
+++ b/glom/mode_data/db_adddel/db_adddel.h
@@ -305,6 +305,8 @@ protected:
   /// A common handler for the edit button, the context menu, etc.
   void do_user_requested_edit();
 
+  virtual void on_selection_changed(bool selection);
+
 private:
   Gnome::Gda::Value treeview_get_key(const Gtk::TreeModel::iterator& row) const;
 
@@ -326,6 +328,7 @@ private:
 
   bool on_button_press_event_Popup(GdkEventButton* event);
   void on_treeview_button_press_event(GdkEventButton* event);
+  void on_treeview_selection_changed();
 
 protected:
   void on_MenuPopup_activate_Edit();
@@ -386,6 +389,7 @@ private:
   Gtk::ScrolledWindow m_ScrolledWindow;
   Gtk::TreeView m_TreeView;
 
+private:
   Glib::RefPtr<DbTreeModel> m_refListStore;
 
   //Columns, not including the hidden internal columns:
diff --git a/glom/mode_data/db_adddel/db_adddel_withbuttons.cc b/glom/mode_data/db_adddel/db_adddel_withbuttons.cc
index 164d2fd..273669d 100644
--- a/glom/mode_data/db_adddel/db_adddel_withbuttons.cc
+++ b/glom/mode_data/db_adddel/db_adddel_withbuttons.cc
@@ -132,5 +132,10 @@ void DbAddDel_WithButtons::set_allow_view_details(bool val)
   setup_buttons();
 }
 
+void DbAddDel_WithButtons::on_selection_changed(bool selection)
+{
+  m_Button_Edit.set_sensitive(selection);
+  m_Button_Del.set_sensitive(selection);
+}
 
 } //namespace Glom
diff --git a/glom/mode_data/db_adddel/db_adddel_withbuttons.h b/glom/mode_data/db_adddel/db_adddel_withbuttons.h
index 0858668..bffaf18 100644
--- a/glom/mode_data/db_adddel/db_adddel_withbuttons.h
+++ b/glom/mode_data/db_adddel/db_adddel_withbuttons.h
@@ -46,6 +46,7 @@ private:
   void on_button_add();
   void on_button_del();
   void on_button_edit();
+  virtual void on_selection_changed(bool selection);
 
   virtual void show_all_vfunc();
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]