[glom] Allow printing of print layouts from the list view.



commit e1a54b03f3c17057423fe584738d508a9f750895
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Feb 22 09:53:45 2012 +0100

    Allow printing of print layouts from the list view.
    
    * glom/appwindow.cc: fill_menu_print_layouts(): Show the print layouts
    even if the list view is visible.
    * glom/mode_data/notebook_data.[h|cc]:
    get_found_set_details(): Replace with get_found_set_selected()
    which checks the selected record in the list view, if the list
    view is visible, instead of just the details view.
    * glom/frame_glom.[h|cc]: Remove get_viewing_details().
    do_print_layout(): Use get_found_set_selected() so we can print the
    print layout for the selected record.
    
    This avoids some confusion caused by the print layouts not being available
    when viewing the list instead of the details.
    Bug #670462 (alien)

 ChangeLog                       |   18 ++++++++++++++++++
 glom/appwindow.cc               |    5 -----
 glom/frame_glom.cc              |    7 +------
 glom/frame_glom.h               |    3 ---
 glom/mode_data/notebook_data.cc |   36 ++++++++++++++++++++++++++++++++++--
 glom/mode_data/notebook_data.h  |    6 ++++--
 6 files changed, 57 insertions(+), 18 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0de6bd1..97044de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+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
+	even if the list view is visible.
+	* glom/mode_data/notebook_data.[h|cc]:
+	get_found_set_details(): Replace with get_found_set_selected()
+	which checks the selected record in the list view, if the list 
+	view is visible, instead of just the details view.
+	* glom/frame_glom.[h|cc]: Remove get_viewing_details().
+	do_print_layout(): Use get_found_set_selected() so we can print the 
+	print layout for the selected record.
+	
+	This avoids some confusion caused by the print layouts not being available
+	when viewing the list instead of the details.
+	Bug #670462 (alien)
+
 2012-02-13  Murray Cumming  <murrayc murrayc com>
 
 	Users: Warn if we cannot get the list of users.
diff --git a/glom/appwindow.cc b/glom/appwindow.cc
index 868b4b5..58b82e8 100644
--- a/glom/appwindow.cc
+++ b/glom/appwindow.cc
@@ -2120,11 +2120,6 @@ void AppWindow::fill_menu_print_layouts(const Glib::ustring& table_name)
   if(m_menu_print_layouts_ui_merge_id)
     m_refUIManager->remove_ui(m_menu_print_layouts_ui_merge_id);
 
-  //Only fill menu if we are in details mode,
-  //because this feature is not (yet) available for lists:
-  if(!m_pFrame || !m_pFrame->get_viewing_details())
-    return;
-
   if(m_refNavPrintLayoutsActionGroup)
   {
     m_refUIManager->remove_action_group(m_refNavPrintLayoutsActionGroup);
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index e632e04..da52fee 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -2332,7 +2332,7 @@ void Frame_Glom::do_print_layout(const Glib::ustring& print_layout_name, bool pr
   
   //TODO: When expanding items, avoid the page gaps that the print layout's design
   //has added.  
-  const FoundSet found_set = m_Notebook_Data.get_found_set_details();
+  const FoundSet found_set = m_Notebook_Data.get_found_set_selected();
   //Note that found_set.m_where_clause could be empty if there are no records yet,
   //and that is acceptable if this is for a print preview while designing the print layout. 
   
@@ -2473,11 +2473,6 @@ void Frame_Glom::on_button_find_all()
   show_table(m_table_name);
 }
 
-bool Frame_Glom::get_viewing_details() const
-{
-  return (m_Notebook_Data.get_current_view() == Notebook_Data::DATA_VIEW_Details);
-}
-
 Glib::ustring Frame_Glom::get_shown_table_name() const
 {
   return m_table_name;
diff --git a/glom/frame_glom.h b/glom/frame_glom.h
index 29efa56..d54cd80 100644
--- a/glom/frame_glom.h
+++ b/glom/frame_glom.h
@@ -170,9 +170,6 @@ public:
    */
   void show_table_refresh();
 
-  ///Whether we are viewing the details or list.
-  bool get_viewing_details() const;
-
   Glib::ustring get_shown_table_name() const;
 
   /** Show the table, possibly selecting a particular record, possibly showing that in the details tab.
diff --git a/glom/mode_data/notebook_data.cc b/glom/mode_data/notebook_data.cc
index 2c71cda..7e17f06 100644
--- a/glom/mode_data/notebook_data.cc
+++ b/glom/mode_data/notebook_data.cc
@@ -258,9 +258,41 @@ void Notebook_Data::on_details_user_requested_related_details(const Glib::ustrin
   */
 }
 
-FoundSet Notebook_Data::get_found_set_details() const
+FoundSet Notebook_Data::get_found_set_selected() const
 {
-  return m_Box_Details.get_found_set();
+  if(get_current_view() == DATA_VIEW_Details)
+  {
+    return m_Box_Details.get_found_set();
+  }
+  else
+  {
+    //Start with something sensible:
+    FoundSet found_set = m_Box_List.get_found_set();
+    
+    const Gnome::Gda::Value primary_key_value_selected = 
+      m_Box_List.get_primary_key_value_selected();
+    if(Conversions::value_is_empty(primary_key_value_selected))
+    {
+      //Indicate to the caller that no record is selected:
+      found_set.m_where_clause = Gnome::Gda::SqlExpr();
+      return found_set;
+    }
+
+    const Document* document = get_document();
+    if(!document)
+    {
+      std::cerr << G_STRFUNC << ": document is null" << std::endl;
+      found_set.m_where_clause = Gnome::Gda::SqlExpr();
+      return found_set;
+    }
+    
+    sharedptr<Field> primary_key_field =
+      document->get_field_primary_key(m_table_name);
+    found_set.m_where_clause = Utils::build_simple_where_expression(
+      m_table_name, primary_key_field,
+      primary_key_value_selected);
+    return found_set;
+  }
 }
 
 
diff --git a/glom/mode_data/notebook_data.h b/glom/mode_data/notebook_data.h
index 23dfe6d..ee03bb8 100644
--- a/glom/mode_data/notebook_data.h
+++ b/glom/mode_data/notebook_data.h
@@ -44,8 +44,10 @@ public:
   ///Get the existing where clause, previously supplied to init_db_details().
   FoundSet get_found_set() const;
 
-  ///Get the found set for the currently-visible record in the details tab:
-  FoundSet get_found_set_details() const;
+  /** Get the found set for the currently-selected record in the list view,
+   * if the list view is visible, or the currently-visible details tab.
+   */
+  FoundSet get_found_set_selected() const;
 
   ///Show the details for a particular record, without affecting the list view.
   void show_details(const Gnome::Gda::Value& primary_key_value);



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