[gnote] Refactor SearchNotesWidget



commit ddd778dc244984cea8b016b53c9fdf44bb5abea4
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat May 25 19:02:20 2013 +0300

    Refactor SearchNotesWidget
    
    * Derive from HPaned, remove redundant HBox around it
    * Use Alignment for aligning no-matches link
    * Replace use of deprecated Box by Grid

 src/searchnoteswidget.cpp |   46 ++++++++++++++++++--------------------------
 src/searchnoteswidget.hpp |    7 ++---
 2 files changed, 22 insertions(+), 31 deletions(-)
---
diff --git a/src/searchnoteswidget.cpp b/src/searchnoteswidget.cpp
index fc1b7f5..4541a93 100644
--- a/src/searchnoteswidget.cpp
+++ b/src/searchnoteswidget.cpp
@@ -27,7 +27,6 @@
 #include <gtkmm/liststore.h>
 #include <gtkmm/separatormenuitem.h>
 #include <gtkmm/stock.h>
-#include <gtkmm/table.h>
 
 #include "debug.hpp"
 #include "iconmanager.hpp"
@@ -51,8 +50,7 @@ Glib::RefPtr<Gdk::Pixbuf> SearchNotesWidget::get_note_icon()
 
 
 SearchNotesWidget::SearchNotesWidget(NoteManager & m)
-  : Gtk::VBox(false, 0)
-  , m_accel_group(Gtk::AccelGroup::create())
+  : m_accel_group(Gtk::AccelGroup::create())
   , m_no_matches_box(NULL)
   , m_manager(m)
   , m_clickX(0), m_clickY(0)
@@ -69,10 +67,9 @@ SearchNotesWidget::SearchNotesWidget(NoteManager & m)
   Gtk::Widget *notebooksPane = Gtk::manage(make_notebooks_pane());
   notebooksPane->show();
 
-  m_hpaned.set_position(150);
-  m_hpaned.add1(*notebooksPane);
-  m_hpaned.add2(m_matches_window);
-  m_hpaned.show();
+  set_position(150);
+  add1(*notebooksPane);
+  add2(m_matches_window);
 
   make_recent_tree();
   m_tree = manage(m_tree);
@@ -87,8 +84,6 @@ SearchNotesWidget::SearchNotesWidget(NoteManager & m)
   m_matches_window.add(*m_tree);
   m_matches_window.show();
 
-  pack_start(m_hpaned, true, true, 0);
-
   // Update on changes to notes
   m.signal_note_deleted.connect(sigc::mem_fun(*this, &SearchNotesWidget::on_note_deleted));
   m.signal_note_added.connect(sigc::mem_fun(*this, &SearchNotesWidget::on_note_added));
@@ -197,9 +192,9 @@ void SearchNotesWidget::perform_search()
 
 void SearchNotesWidget::restore_matches_window()
 {
-  if(m_no_matches_box && m_hpaned.get_child2() == m_no_matches_box) {
-    m_hpaned.remove(*m_no_matches_box);
-    m_hpaned.add2(m_matches_window);
+  if(m_no_matches_box && get_child2() == m_no_matches_box) {
+    remove(*m_no_matches_box);
+    add2(m_matches_window);
   }
 }
 
@@ -269,7 +264,7 @@ void SearchNotesWidget::save_position()
 
   Glib::RefPtr<Gio::Settings> settings = Preferences::obj()
     .get_schema_settings(Preferences::SCHEMA_GNOTE);
-  settings->set_int(Preferences::SEARCH_WINDOW_SPLITTER_POS, m_hpaned.get_position());
+  settings->set_int(Preferences::SEARCH_WINDOW_SPLITTER_POS, get_position());
 
   Gtk::Window *window = dynamic_cast<Gtk::Window*>(current_host);
   if(!window || (window->get_window()->get_state() & Gdk::WINDOW_STATE_MAXIMIZED) != 0) {
@@ -998,7 +993,7 @@ void SearchNotesWidget::remove_matches_column()
 // called when no search results are found in the selected notebook
 void SearchNotesWidget::no_matches_found_action()
 {
-  m_hpaned.remove(m_matches_window);
+  remove(m_matches_window);
   if(!m_no_matches_box) {
     Glib::ustring message = _("No results found in the selected notebook.\nClick here to search across all 
notes.");
     Gtk::LinkButton *link_button = manage(new Gtk::LinkButton("", message));
@@ -1006,20 +1001,17 @@ void SearchNotesWidget::no_matches_found_action()
       .connect(sigc::mem_fun(*this, &SearchNotesWidget::show_all_search_results));
     link_button->set_tooltip_text(_("Click here to search across all notebooks"));
     link_button->show();
-    Gtk::Table *no_matches_found_table = manage(new Gtk::Table(1, 3, false));
-    no_matches_found_table->attach(*link_button, 1, 2, 0, 1,
-      Gtk::FILL | Gtk::SHRINK,
-      Gtk::SHRINK,
-      0, 0
-    );
-
-    no_matches_found_table->set_col_spacings(4);
-    no_matches_found_table->show_all();
-    m_no_matches_box = manage(new Gtk::HBox(false, 0));
-    m_no_matches_box->pack_start(*no_matches_found_table, true, true, 0);
+    Gtk::Alignment *no_matches_found = manage(new Gtk::Alignment(Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER, 0.0, 
0.0));
+    no_matches_found->add(*link_button);
+
+    no_matches_found->set_hexpand(true);
+    no_matches_found->set_vexpand(true);
+    no_matches_found->show_all();
+    m_no_matches_box = manage(new Gtk::Grid);
+    m_no_matches_box->attach(*no_matches_found, 0, 0, 1, 1);
     m_no_matches_box->show();
   }
-  m_hpaned.add2(*m_no_matches_box);
+  add2(*m_no_matches_box);
 }
 
 void SearchNotesWidget::add_matches_column()
@@ -1404,7 +1396,7 @@ void SearchNotesWidget::size_internals()
     .get_schema_settings(Preferences::SCHEMA_GNOTE);
   int pos = settings->get_int(Preferences::SEARCH_WINDOW_SPLITTER_POS);
   if(pos) {
-    m_hpaned.set_position(pos);
+    set_position(pos);
   }
 }
 
diff --git a/src/searchnoteswidget.hpp b/src/searchnoteswidget.hpp
index 33ca564..b4bbbe9 100644
--- a/src/searchnoteswidget.hpp
+++ b/src/searchnoteswidget.hpp
@@ -25,7 +25,7 @@
 
 #include <set>
 
-#include <gtkmm/box.h>
+#include <gtkmm/grid.h>
 #include <gtkmm/liststore.h>
 #include <gtkmm/paned.h>
 #include <gtkmm/scrolledwindow.h>
@@ -39,7 +39,7 @@
 namespace gnote {
 
 class SearchNotesWidget
-  : public Gtk::VBox
+  : public Gtk::HPaned
   , public EmbeddableWidget
   , public SearchableItem
 {
@@ -150,9 +150,8 @@ private:
   Glib::RefPtr<Gtk::Action> m_delete_note_action;
   Glib::RefPtr<Gtk::Action> m_delete_notebook_action;
   RecentSearchColumnTypes m_find_combo_columns;
-  Gtk::HPaned m_hpaned;
   Gtk::ScrolledWindow m_matches_window;
-  Gtk::HBox *m_no_matches_box;
+  Gtk::Grid *m_no_matches_box;
   notebooks::NotebooksTreeView *m_notebooksTree;
   sigc::connection m_on_notebook_selection_changed_cid;
   std::set<Tag::Ptr>  m_selected_tags;


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