[glom] List View: Make print layouts grayed-out if no record is selected.



commit d099b68ca4e39d064e314cb9aa79e35a5117460a
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Feb 22 12:34:39 2012 +0100

    List View: Make print layouts grayed-out if no record is selected.
    
    * glom/mode_data/db_adddel/db_adddel.[h|cc]:
    Add signal_record_selection_changed and emit it when the TreeView's selection
    changes:
    * glom/mode_data/db_adddel/db_adddel_withbuttons.cc: Make sure that we call
    the base class.
    * glom/mode_data/box_data_manyrecords.[h|cc]:
    Added signal_record_selection_changed.
    * glom/mode_data/box_data_list.[h|cc]: Handle the AddDel_DB's
    signal_record_selection_changed, emitting our own
    signal_record_selection_changed.
    * glom/mode_data/notebook_data.[h|cc]: Handle the Box_Data_List's
    signal_record_selection_changed, emitting our own
    signal_record_selection_changed.
    I still do not like the repetition that is required here, and elsewhere,
    when a child widget needs to signal all the way up an ownership hierarchy.
    
    * glom/appwindow.[h|cc]: Add enable_menu_print_layouts_details().
    * glom/frame_glom.[h|cc]: Handle the Notebook_Data's
    signal_record_selection_changed(), calling the AppWindow's
    enable_menu_print_layouts_details().

 ChangeLog                                         |   25 +++++++++++++++++++++
 glom/appwindow.cc                                 |    6 +++++
 glom/appwindow.h                                  |    1 +
 glom/frame_glom.cc                                |   14 +++++++++++
 glom/frame_glom.h                                 |    3 ++
 glom/mode_data/box_data_list.cc                   |    7 ++++++
 glom/mode_data/box_data_list.h                    |    1 +
 glom/mode_data/box_data_manyrecords.cc            |    5 ++++
 glom/mode_data/box_data_manyrecords.h             |    4 +++
 glom/mode_data/db_adddel/db_adddel.cc             |    7 ++++++
 glom/mode_data/db_adddel/db_adddel.h              |    7 +++++-
 glom/mode_data/db_adddel/db_adddel_withbuttons.cc |    2 +
 glom/mode_data/notebook_data.cc                   |   18 ++++++++++++++-
 glom/mode_data/notebook_data.h                    |    9 +++++++
 14 files changed, 107 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 97044de..4066109 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,30 @@
 2012-02-22  Murray Cumming  <murrayc murrayc com>
 
+	List View: Make print layouts grayed-out if no record is selected.
+
+	* glom/mode_data/db_adddel/db_adddel.[h|cc]:
+	Add signal_record_selection_changed and emit it when the TreeView's selection
+	changes:
+	* glom/mode_data/db_adddel/db_adddel_withbuttons.cc: Make sure that we call 
+	the base class.
+	* glom/mode_data/box_data_manyrecords.[h|cc]:
+	Added signal_record_selection_changed.
+	* glom/mode_data/box_data_list.[h|cc]: Handle the AddDel_DB's 
+	signal_record_selection_changed, emitting our own 
+	signal_record_selection_changed.
+	* glom/mode_data/notebook_data.[h|cc]: Handle the Box_Data_List's 
+	signal_record_selection_changed, emitting our own 
+	signal_record_selection_changed.
+	I still do not like the repetition that is required here, and elsewhere,
+	when a child widget needs to signal all the way up an ownership hierarchy.
+	
+	* glom/appwindow.[h|cc]: Add enable_menu_print_layouts_details().
+	* glom/frame_glom.[h|cc]: Handle the Notebook_Data's 
+	signal_record_selection_changed(), calling the AppWindow's
+	enable_menu_print_layouts_details().
+
+2012-02-22  Murray Cumming  <murrayc murrayc com>
+
 	Allow printing of print layouts from the list view.
 
 	* glom/appwindow.cc: fill_menu_print_layouts(): Show the print layouts
diff --git a/glom/appwindow.cc b/glom/appwindow.cc
index 58b82e8..ef02e70 100644
--- a/glom/appwindow.cc
+++ b/glom/appwindow.cc
@@ -2110,6 +2110,12 @@ void AppWindow::fill_menu_reports(const Glib::ustring& table_name)
   }
 }
 
+void AppWindow::enable_menu_print_layouts_details(bool enable)
+{
+ if(m_refNavPrintLayoutsActionGroup)
+    m_refNavPrintLayoutsActionGroup->set_sensitive(enable);
+}
+
 void AppWindow::fill_menu_print_layouts(const Glib::ustring& table_name)
 {
   //TODO: This is copy/pasted from fill_menu_print_reports. Can we generalize it?
diff --git a/glom/appwindow.h b/glom/appwindow.h
index 1ca8e88..5bc97ba 100644
--- a/glom/appwindow.h
+++ b/glom/appwindow.h
@@ -92,6 +92,7 @@ public:
   void fill_menu_tables();
   void fill_menu_reports(const Glib::ustring& table_name);
   void fill_menu_print_layouts(const Glib::ustring& table_name);
+  void enable_menu_print_layouts_details(bool enable = true);
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   void do_menu_developer_fields(Gtk::Window& parent, const Glib::ustring table_name);
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 5850171..0c7b719 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -154,6 +154,8 @@ Frame_Glom::Frame_Glom(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>
   m_Notebook_Find.signal_find_criteria.connect(sigc::mem_fun(*this, &Frame_Glom::on_notebook_find_criteria));
   m_Notebook_Find.show();
   m_Notebook_Data.signal_record_details_requested().connect(sigc::mem_fun(*this, &Frame_Glom::on_notebook_data_record_details_requested));
+  m_Notebook_Data.signal_record_selection_changed().connect(sigc::mem_fun(*this,
+    &Frame_Glom::on_notebook_data_record_selection_changed));
   m_Notebook_Data.signal_switch_page().connect(sigc::mem_fun(*this, &Frame_Glom::on_notebook_data_switch_page));
   m_Notebook_Data.show();
 
@@ -2428,6 +2430,18 @@ void Frame_Glom::on_notebook_data_record_details_requested(const Glib::ustring&
   show_table(table_name, primary_key_value);
 }
 
+void Frame_Glom::on_notebook_data_record_selection_changed()
+{
+  bool something_selected = false;
+  const FoundSet found_set = m_Notebook_Data.get_found_set_selected();
+  if(!found_set.m_where_clause.empty())
+    something_selected = true;
+  
+  AppWindow* pApp = dynamic_cast<AppWindow*>(get_app_window());
+  if(pApp)
+    pApp->enable_menu_print_layouts_details(something_selected);  
+}
+
 void Frame_Glom::update_records_count()
 {
   //Get the number of records available and the number found,
diff --git a/glom/frame_glom.h b/glom/frame_glom.h
index d54cd80..dff4352 100644
--- a/glom/frame_glom.h
+++ b/glom/frame_glom.h
@@ -215,6 +215,7 @@ protected:
 
   void alert_no_table();
 
+  //TODO: Make these private?
   //Signal handlers:
   void on_notebook_find_criteria(const Gnome::Gda::SqlExpr& where_clause);
   void on_button_quickfind();
@@ -235,6 +236,8 @@ protected:
 
 private:
 
+  void on_notebook_data_record_selection_changed();
+
   /**
    * @result Whether to try again.
    */
diff --git a/glom/mode_data/box_data_list.cc b/glom/mode_data/box_data_list.cc
index a1508b0..b6a045b 100644
--- a/glom/mode_data/box_data_list.cc
+++ b/glom/mode_data/box_data_list.cc
@@ -48,6 +48,8 @@ Box_Data_List::Box_Data_List()
   m_AddDel.signal_user_requested_edit().connect(sigc::mem_fun(*this, &Box_Data_List::on_adddel_user_requested_edit));
   m_AddDel.signal_script_button_clicked().connect(sigc::mem_fun(*this, &Box_Data_List::on_adddel_script_button_clicked));
   m_AddDel.signal_sort_clause_changed().connect(sigc::mem_fun(*this, &Box_Data_List::on_adddel_user_sort_clause_changed));
+  m_AddDel.signal_record_selection_changed().connect(
+    sigc::mem_fun(*this, &Box_Data_List::on_adddel_record_selection_changed));
 
   //TODO: Re-add this signal if this is really wanted, but make it part of a complete drag-and-drop feature for list views:
   //m_AddDel.signal_user_reordered_columns().connect(sigc::mem_fun(*this, &Box_Data_List::on_adddel_user_reordered_columns));
@@ -535,6 +537,11 @@ void Box_Data_List::on_adddel_user_sort_clause_changed()
     document->set_criteria_current(m_table_name, m_found_set);
 }
 
+void Box_Data_List::on_adddel_record_selection_changed()
+{
+  m_signal_record_selection_changed.emit();
+}
+
 Gtk::TreeModel::iterator Box_Data_List::get_row_selected()
 {
   return m_AddDel.get_item_selected();
diff --git a/glom/mode_data/box_data_list.h b/glom/mode_data/box_data_list.h
index b69aa99..d091406 100644
--- a/glom/mode_data/box_data_list.h
+++ b/glom/mode_data/box_data_list.h
@@ -94,6 +94,7 @@ protected:
   void on_adddel_user_requested_delete(const Gtk::TreeModel::iterator& rowStart, const Gtk::TreeModel::iterator& rowEnd);
   void on_adddel_user_reordered_columns();
   void on_adddel_user_sort_clause_changed();
+  void on_adddel_record_selection_changed();
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   void on_adddel_user_requested_layout();
diff --git a/glom/mode_data/box_data_manyrecords.cc b/glom/mode_data/box_data_manyrecords.cc
index 2fa7324..bee4042 100644
--- a/glom/mode_data/box_data_manyrecords.cc
+++ b/glom/mode_data/box_data_manyrecords.cc
@@ -68,6 +68,11 @@ Box_Data_ManyRecords::type_signal_user_requested_details Box_Data_ManyRecords::s
   return m_signal_user_requested_details;
 }
 
+Box_Data_ManyRecords::type_signal_record_selection_changed Box_Data_ManyRecords::signal_record_selection_changed()
+{
+  return m_signal_record_selection_changed;
+}
+
 void Box_Data_ManyRecords::print_layout()
 {
   const Privileges table_privs = Privs::get_current_privs(m_table_name);
diff --git a/glom/mode_data/box_data_manyrecords.h b/glom/mode_data/box_data_manyrecords.h
index 151cfe7..b67e236 100644
--- a/glom/mode_data/box_data_manyrecords.h
+++ b/glom/mode_data/box_data_manyrecords.h
@@ -50,6 +50,9 @@ public:
   //Primary Key value:
   typedef sigc::signal<void, const Gnome::Gda::Value&> type_signal_user_requested_details;
   type_signal_user_requested_details signal_user_requested_details();
+  
+  typedef sigc::signal<void> type_signal_record_selection_changed;
+  type_signal_record_selection_changed signal_record_selection_changed();
 
   void get_record_counts(gulong& total, gulong& found) const;
 
@@ -66,6 +69,7 @@ protected:
 
 
   type_signal_user_requested_details m_signal_user_requested_details;
+  type_signal_record_selection_changed m_signal_record_selection_changed;
 };
 
 } //namespace Glom
diff --git a/glom/mode_data/db_adddel/db_adddel.cc b/glom/mode_data/db_adddel/db_adddel.cc
index d0a38b9..0be2f00 100644
--- a/glom/mode_data/db_adddel/db_adddel.cc
+++ b/glom/mode_data/db_adddel/db_adddel.cc
@@ -1275,6 +1275,11 @@ DbAddDel::type_signal_sort_clause_changed DbAddDel::signal_sort_clause_changed()
   return m_signal_sort_clause_changed;
 }
 
+DbAddDel::type_signal_record_selection_changed DbAddDel::signal_record_selection_changed()
+{
+  return m_signal_record_selection_changed;
+}
+
 void DbAddDel::on_cell_layout_button_clicked(const Gtk::TreeModel::Path& path, int model_column_index)
 {
   if(!m_refListStore)
@@ -2461,6 +2466,8 @@ void DbAddDel::on_selection_changed(bool selection)
 {
   m_refContextDelete->set_sensitive(selection);
   m_refContextAdd->set_sensitive(selection);
+  
+  m_signal_record_selection_changed.emit();
 }
 
 } //namespace Glom
diff --git a/glom/mode_data/db_adddel/db_adddel.h b/glom/mode_data/db_adddel/db_adddel.h
index b8a041e..fb18a32 100644
--- a/glom/mode_data/db_adddel/db_adddel.h
+++ b/glom/mode_data/db_adddel/db_adddel.h
@@ -235,12 +235,16 @@ public:
   typedef sigc::signal<void, const Gtk::TreeModel::iterator&, const Gnome::Gda::Value&> type_signal_record_added;
   type_signal_record_added signal_record_added();
 
-
   /** Emitted when the user changed the sort order,
    * for instance by clicking on a column header.
    */
   typedef sigc::signal<void> type_signal_sort_clause_changed;
   type_signal_sort_clause_changed signal_sort_clause_changed();
+  
+  /** Emitted when the user selected (or deselected) a record.
+   */
+  typedef sigc::signal<void> type_signal_record_selection_changed;
+  type_signal_record_selection_changed signal_record_selection_changed();
 
   /** Get the last row.
    * This will never return the placeholder row. 
@@ -448,6 +452,7 @@ private:
   type_signal_script_button_clicked m_signal_script_button_clicked;
   type_signal_record_added m_signal_record_added;
   type_signal_sort_clause_changed m_signal_sort_clause_changed;
+  type_signal_record_selection_changed m_signal_record_selection_changed;
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   type_signal_user_requested_layout m_signal_user_requested_layout;
diff --git a/glom/mode_data/db_adddel/db_adddel_withbuttons.cc b/glom/mode_data/db_adddel/db_adddel_withbuttons.cc
index 273669d..8b552e2 100644
--- a/glom/mode_data/db_adddel/db_adddel_withbuttons.cc
+++ b/glom/mode_data/db_adddel/db_adddel_withbuttons.cc
@@ -136,6 +136,8 @@ void DbAddDel_WithButtons::on_selection_changed(bool selection)
 {
   m_Button_Edit.set_sensitive(selection);
   m_Button_Del.set_sensitive(selection);
+  
+  DbAddDel::on_selection_changed(selection);
 }
 
 } //namespace Glom
diff --git a/glom/mode_data/notebook_data.cc b/glom/mode_data/notebook_data.cc
index 7e17f06..ceb49e6 100644
--- a/glom/mode_data/notebook_data.cc
+++ b/glom/mode_data/notebook_data.cc
@@ -76,7 +76,12 @@ Notebook_Data::Notebook_Data()
   //Connect signals:
 
   //Allow List to ask Details to show a record.
-  m_Box_List.signal_user_requested_details().connect(sigc::mem_fun(*this, &Notebook_Data::on_list_user_requested_details));
+  m_Box_List.signal_user_requested_details().connect(sigc::mem_fun(*this,
+    &Notebook_Data::on_list_user_requested_details));
+  
+  //Allow the parent widget to detect list selection changes:
+  m_Box_List.signal_record_selection_changed().connect(sigc::mem_fun(*this,
+    &Notebook_Data::on_list_selection_changed));
 
   //Allow Details to ask List to ask Details to show a different record:
   m_Box_Details.signal_nav_first().connect(sigc::mem_fun(m_Box_List, &Box_Data_List::on_details_nav_first));
@@ -89,6 +94,7 @@ Notebook_Data::Notebook_Data()
 
   //Allow Details to ask to show a different record in a different table:
   m_Box_Details.signal_requested_related_details().connect(sigc::mem_fun(*this, &Notebook_Data::on_details_user_requested_related_details));
+  
 
   //Fill composite view:
   add_view(&m_Box_List);
@@ -245,6 +251,11 @@ void Notebook_Data::on_list_user_requested_details(const Gnome::Gda::Value& prim
       primary_key_value));
 }
 
+void Notebook_Data::on_list_selection_changed()
+{
+  m_signal_record_selection_changed.emit();
+}
+
 void Notebook_Data::on_details_user_requested_related_details(const Glib::ustring& table_name, Gnome::Gda::Value primary_key_value)
 {
   signal_record_details_requested().emit(table_name, primary_key_value);
@@ -373,6 +384,11 @@ Notebook_Data::type_signal_record_details_requested Notebook_Data::signal_record
   return m_signal_record_details_requested;
 }
 
+Notebook_Data::type_signal_record_selection_changed Notebook_Data::signal_record_selection_changed()
+{
+  return m_signal_record_selection_changed;
+}
+
 void Notebook_Data::on_switch_page_handler(Gtk::Widget* pPage, guint uiPageNumber)
 {
   //Call base class:
diff --git a/glom/mode_data/notebook_data.h b/glom/mode_data/notebook_data.h
index ee03bb8..3763778 100644
--- a/glom/mode_data/notebook_data.h
+++ b/glom/mode_data/notebook_data.h
@@ -78,6 +78,13 @@ public:
   typedef sigc::signal<void, const Glib::ustring&, Gnome::Gda::Value> type_signal_record_details_requested;
   type_signal_record_details_requested signal_record_details_requested();
 
+  typedef sigc::signal<void> type_signal_record_selection_changed;
+  
+  /** This signal is emitted when the a record is selected, or deselected,
+   * in the list view.
+   */
+  type_signal_record_selection_changed signal_record_selection_changed();
+
 protected:
 
   ///Show the counts of all records and found records.
@@ -92,6 +99,7 @@ protected:
 private:
 
   bool on_idle_show_details(const Gnome::Gda::Value& primary_key_value);
+  void on_list_selection_changed();
 
 protected:
   //Member widgets:
@@ -102,6 +110,7 @@ protected:
   Glib::ustring m_table_name;
 
   type_signal_record_details_requested m_signal_record_details_requested;
+  type_signal_record_selection_changed m_signal_record_selection_changed;
 };
 
 } //namespace Glom



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