[glom] Make Find work again.



commit 1b172e287e8837267de4392d43a3f1a58b707a25
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Oct 18 11:18:29 2013 +0200

    Make Find work again.
    
    * glom/appwindow.[h|cc]:
      on_menu_edit_find(): Properly ! the active state.
      set_mode_data(), set_mode_find(): Call the same methods on
      the Frame widget, instead of expecting that to
      happen in a signal handler when we change the Action
      state.
    * glom/frame_glom.[h|cc]: Rename, and split,
      on_menu_Edit_Find() to set_mode_find()
      and set_mode_data(), documenting and simplifying
      them a bit.
    
    This needed reworking because Gio::Action does not act like
    Gtk::Action. For instance, we must set the state manually,
    and changing the state does not cause activate signals to be
    emitted.

 glom/appwindow.cc  |   26 ++++++++++++++++++--------
 glom/appwindow.h   |    6 ++++++
 glom/frame_glom.cc |   46 +++++++++++++++++++++++++++-------------------
 glom/frame_glom.h  |   15 ++++++++++-----
 4 files changed, 61 insertions(+), 32 deletions(-)
---
diff --git a/glom/appwindow.cc b/glom/appwindow.cc
index 0bd65de..c77648c 100644
--- a/glom/appwindow.cc
+++ b/glom/appwindow.cc
@@ -1427,20 +1427,26 @@ void AppWindow::existing_or_new_new()
 
 void AppWindow::set_mode_data()
 {
-  if (!m_pFrame)
+  if(!m_pFrame)
     return;
 
-  if (m_pFrame->m_Mode == Frame_Glom::MODE_Find)
-    m_action_mode_find->change_state(true);
+  //Update the visual feedback in the menu.
+  //This doesn't trigger the activate signal:
+  m_action_mode_find->change_state(false);
+
+  m_pFrame->set_mode_data();
 }
 
 void AppWindow::set_mode_find()
 {
-  if (!m_pFrame)
+  if(!m_pFrame)
     return;
 
-  if (m_pFrame->m_Mode == Frame_Glom::MODE_Data)
-    m_action_mode_find->change_state(true);
+  //Update the visual feedback in the menu.
+  //This doesn't trigger the activate signal:
+  m_action_mode_find->change_state(true);
+
+  m_pFrame->set_mode_find();
 }
 
 void AppWindow::on_menu_help_contents()
@@ -2997,9 +3003,13 @@ void AppWindow::on_menu_edit_find()
   //The state is not changed automatically:
   bool active = false;
   m_action_mode_find->get_state(active);
-  m_action_mode_find->change_state(!active);
+  active = !active;
+  m_action_mode_find->change_state(active);
 
-  m_pFrame->on_menu_Edit_Find();
+  if(active)
+    m_pFrame->set_mode_find();
+  else
+    m_pFrame->set_mode_data();
 }
 
 
diff --git a/glom/appwindow.h b/glom/appwindow.h
index 1478feb..9fb5302 100644
--- a/glom/appwindow.h
+++ b/glom/appwindow.h
@@ -78,8 +78,14 @@ public:
   /** Changes the mode to Data mode, as if the user had selected the Data Mode menu item.
    */
   void set_mode_data();
+
+private:
+  /** Changes the mode to Find mode, as if the user had selected the Data Mode menu item.
+   */
   void set_mode_find();
 
+public:
+
   /** Show in the UI whether the database is shared on the network.
    */
   void update_network_shared_ui();
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index f40d243..db80209 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -1025,18 +1025,9 @@ void Frame_Glom::set_enable_layout_drag_and_drop(bool enable)
 
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
-void Frame_Glom::on_menu_Edit_Find()
+void Frame_Glom::set_mode_find()
 {
-  //Switch back to data mode if we are in find mode.
-  if(m_Mode == MODE_Find)
-  {
-    //Switch to data mode
-    if(set_mode(MODE_Data))
-      show_table(m_table_name);
-    return;
-  }
-
-  //Otherwise switch to find mode.
+  //Switch to find mode.
   //This can take quite a long time, flicking between 1 or 2 intermediate screens.
   //It shouldn't, but until we fix that, let's show the busy cursor while it's working:
   BusyCursor busy_cursor(get_app_window());
@@ -1063,6 +1054,16 @@ void Frame_Glom::on_menu_Edit_Find()
   }
 }
 
+void Frame_Glom::set_mode_data()
+{
+  //Switch to data mode
+  if(!set_mode(MODE_Data))
+    return;
+
+  show_table(m_table_name);
+}
+
+
 void Frame_Glom::on_menu_add_record()
 {
   BusyCursor busy_cursor(get_app_window());
@@ -1312,7 +1313,8 @@ void Frame_Glom::on_notebook_find_criteria(const Gnome::Gda::SqlExpr& where_clau
     std::cerr << G_STRFUNC << ": get_app_window() failed." << std::endl;
     return;
   }
-  
+
+  //Identify the where_clause:
   Gnome::Gda::SqlExpr where_clause_to_use = where_clause;
 
   //Prefer the quick find text if any was entered:
@@ -1323,6 +1325,7 @@ void Frame_Glom::on_notebook_find_criteria(const Gnome::Gda::SqlExpr& where_clau
       Utils::get_find_where_clause_quick(get_document(), m_table_name, 
Gnome::Gda::Value(quickfind_criteria));
   }
 
+  //Warn if there was no find criteria:
   if(where_clause_to_use.empty())
   {
     const Glib::ustring message = _("You have not entered any find criteria. Try entering information in the 
fields.");
@@ -1336,35 +1339,40 @@ void Frame_Glom::on_notebook_find_criteria(const Gnome::Gda::SqlExpr& where_clau
 
   //std::cout << "debug: " << G_STRFUNC << ": " << where_clause << std::endl;
   
+
+  //Try to find some records with the where_clause:
   bool records_found = false;
 
   { //Extra scope, to control the lifetime of the busy cursor.
     BusyCursor busy_cursor(app);
 
-    app->set_mode_data();
-
     //std::cout << "Frame_Glom::on_notebook_find_criteria: where_clause=" << where_clause << std::endl;
     FoundSet found_set;
     found_set.m_table_name = m_table_name;
     found_set.m_where_clause = where_clause_to_use;
     records_found = m_Notebook_Data.init_db_details(found_set);
 
-    //std::cout << "debug: " << G_STRFUNC << ": BEFORE  m_Notebook_Data.select_page_for_find_results()" << 
std::endl;
     m_Notebook_Data.select_page_for_find_results();
-    //std::cout << "debug: " << G_STRFUNC << ": AFTER  m_Notebook_Data.select_page_for_find_results()" << 
std::endl;
   }
 
+  std::cout << G_STRFUNC << ": records_found=" << records_found << std::endl;
+
   if(!records_found)
   {
     const bool find_again = Utils::show_warning_no_records_found(*app);
 
-    if(find_again)
-      app->set_mode_find();
-    else
+    if(!find_again)
+    {
+      //Go back to data mode, showing all records:
       on_button_find_all();
+    }
   }
   else
   {
+    //Actually show the found data,
+    //and show that we are in data mode:
+    app->set_mode_data();
+
     //Show how many records were found:
     update_records_count();
   }
diff --git a/glom/frame_glom.h b/glom/frame_glom.h
index e491dab..b36b0fd 100644
--- a/glom/frame_glom.h
+++ b/glom/frame_glom.h
@@ -86,7 +86,15 @@ public:
   bool attempt_toggle_shared(bool shared);
   void on_menu_file_print();
 
-  void on_menu_Edit_Find();
+  /** Show the widgets for find mode.
+   * It is up to the caller to indicate in the menu that find mode is active.
+   */
+  void set_mode_find();
+
+  /** Show the widgets for data mode.
+   * It is up to the caller to indicate in the menu that find mode is not active.
+   */
+  void set_mode_data();
   
   void on_menu_add_record();
 
@@ -178,9 +186,7 @@ public:
    */
   void show_table(const Glib::ustring& table_name, const Gnome::Gda::Value& primary_key_value_for_details = 
Gnome::Gda::Value());
 
-protected:
-
-
+private:
 
   //virtual void set_document(Document* pDocument); //override
 
@@ -214,7 +220,6 @@ protected:
 
   void alert_no_table();
 
-private:
   //Signal handlers:
   void on_notebook_find_criteria(const Gnome::Gda::SqlExpr& where_clause);
   void on_button_quickfind();


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