[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 147/473: Derive search page from page.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:55:17 CET 2015


This is an automated email from the git hooks/post-receive script.

gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.

commit 00d5b608fd2c3a0926d57fc6e330b0a554b9e538
Author: Graeme Gott <graeme at gottcode.org>
Date:   Mon Jul 29 10:00:04 2013 -0400

    Derive search page from page.
---
 src/CMakeLists.txt  |    1 -
 src/filter_page.cpp |   79 ---------------------------------------------------
 src/filter_page.hpp |   50 --------------------------------
 src/search_page.cpp |   33 +++++++++++++--------
 src/search_page.hpp |    9 +++---
 5 files changed, 26 insertions(+), 146 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dade67d..08dbdf8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -66,7 +66,6 @@ add_library(whiskermenu SHARED
     category.cpp
     configuration_dialog.cpp
     favorites_page.cpp
-    filter_page.cpp
     icon_size.cpp
     launcher.cpp
     launcher_model.cpp
diff --git a/src/filter_page.cpp b/src/filter_page.cpp
deleted file mode 100644
index 6738541..0000000
--- a/src/filter_page.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
-//
-// This library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 2 of the License, or
-// at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library.  If not, see <http://www.gnu.org/licenses/>.
-
-
-#include "filter_page.hpp"
-
-#include "launcher_view.hpp"
-
-using namespace WhiskerMenu;
-
-//-----------------------------------------------------------------------------
-
-FilterPage::FilterPage(Menu* menu) :
-	Page(menu),
-	m_filter_model(NULL)
-{
-}
-
-//-----------------------------------------------------------------------------
-
-FilterPage::~FilterPage()
-{
-	unset_model();
-}
-
-//-----------------------------------------------------------------------------
-
-void FilterPage::refilter()
-{
-	if (m_filter_model)
-	{
-		gtk_tree_model_filter_refilter(m_filter_model);
-	}
-}
-
-//-----------------------------------------------------------------------------
-
-GtkTreePath* FilterPage::convert_child_path_to_path(GtkTreePath* path) const
-{
-	return gtk_tree_model_filter_convert_child_path_to_path((m_filter_model), path);
-}
-
-//-----------------------------------------------------------------------------
-
-void FilterPage::set_model(GtkTreeModel* model)
-{
-	unset_model();
-
-	m_filter_model = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(model, NULL));
-	gtk_tree_model_filter_set_visible_func(m_filter_model, (GtkTreeModelFilterVisibleFunc)&FilterPage::filter_visible, this, NULL);
-	get_view()->set_model(GTK_TREE_MODEL(m_filter_model));
-}
-
-//-----------------------------------------------------------------------------
-
-void FilterPage::unset_model()
-{
-	get_view()->unset_model();
-
-	if (m_filter_model)
-	{
-		g_object_unref(m_filter_model);
-		m_filter_model = NULL;
-	}
-}
-
-//-----------------------------------------------------------------------------
diff --git a/src/filter_page.hpp b/src/filter_page.hpp
deleted file mode 100644
index 1bbe71b..0000000
--- a/src/filter_page.hpp
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
-//
-// This library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 2 of the License, or
-// at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library.  If not, see <http://www.gnu.org/licenses/>.
-
-
-#ifndef WHISKERMENU_FILTER_PAGE_HPP
-#define WHISKERMENU_FILTER_PAGE_HPP
-
-#include "page.hpp"
-
-namespace WhiskerMenu
-{
-
-class FilterPage : public Page
-{
-public:
-	explicit FilterPage(Menu* menu);
-	~FilterPage();
-
-protected:
-	GtkTreePath* convert_child_path_to_path(GtkTreePath* path) const;
-	virtual bool on_filter(GtkTreeModel* model, GtkTreeIter* iter)=0;
-	void refilter();
-	void set_model(GtkTreeModel* model);
-	void unset_model();
-
-private:
-	static gboolean filter_visible(GtkTreeModel* model, GtkTreeIter* iter, FilterPage* page)
-	{
-		return page->on_filter(model, iter);
-	}
-
-private:
-	GtkTreeModelFilter* m_filter_model;
-};
-
-}
-
-#endif // WHISKERMENU_FILTER_PAGE_HPP
diff --git a/src/search_page.cpp b/src/search_page.cpp
index 1f03a06..79b1025 100644
--- a/src/search_page.cpp
+++ b/src/search_page.cpp
@@ -31,7 +31,8 @@ using namespace WhiskerMenu;
 //-----------------------------------------------------------------------------
 
 SearchPage::SearchPage(Menu* menu) :
-	FilterPage(menu),
+	Page(menu),
+	m_filter_model(NULL),
 	m_sort_model(NULL),
 	m_current_results(NULL)
 {
@@ -114,7 +115,7 @@ void SearchPage::set_filter(const gchar* filter)
 	get_view()->unset_model();
 	gtk_tree_model_sort_reset_default_sort_func(m_sort_model);
 
-	refilter();
+	gtk_tree_model_filter_refilter(m_filter_model);
 
 	gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(m_sort_model), (GtkTreeIterCompareFunc)&SearchPage::on_sort, this, NULL);
 	get_view()->set_model(GTK_TREE_MODEL(m_sort_model));
@@ -152,11 +153,13 @@ void SearchPage::set_menu_items(GtkTreeModel* model)
 		valid = gtk_tree_model_iter_next(model, &iter);
 	}
 
-	unset_search_model();
-	set_model(model);
-	m_sort_model = GTK_TREE_MODEL_SORT(gtk_tree_model_sort_new_with_model(get_view()->get_model()));
+	unset_model();
+
+	m_filter_model = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(model, NULL));
+	gtk_tree_model_filter_set_visible_func(m_filter_model, (GtkTreeModelFilterVisibleFunc)&SearchPage::on_filter, this, NULL);
+
+	m_sort_model = GTK_TREE_MODEL_SORT(gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(m_filter_model)));
 	gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(m_sort_model), (GtkTreeIterCompareFunc)&SearchPage::on_sort, this, NULL);
-	get_view()->unset_model();
 }
 
 //-----------------------------------------------------------------------------
@@ -166,15 +169,14 @@ void SearchPage::unset_menu_items()
 	m_launchers.clear();
 	m_results.clear();
 	m_current_results = NULL;
-	unset_search_model();
 	unset_model();
 }
 
 //-----------------------------------------------------------------------------
 
-bool SearchPage::on_filter(GtkTreeModel* model, GtkTreeIter* iter)
+gboolean SearchPage::on_filter(GtkTreeModel* model, GtkTreeIter* iter, SearchPage* page)
 {
-	if (!m_current_results)
+	if (!page->m_current_results)
 	{
 		return false;
 	}
@@ -182,7 +184,7 @@ bool SearchPage::on_filter(GtkTreeModel* model, GtkTreeIter* iter)
 	// Check if launcher search string contains text
 	Launcher* launcher = NULL;
 	gtk_tree_model_get(model, iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
-	return launcher && (m_current_results->find(launcher) != m_current_results->end());
+	return launcher && (page->m_current_results->find(launcher) != page->m_current_results->end());
 }
 
 //-----------------------------------------------------------------------------
@@ -204,14 +206,21 @@ gint SearchPage::on_sort(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, Se
 
 //-----------------------------------------------------------------------------
 
-void SearchPage::unset_search_model()
+void SearchPage::unset_model()
 {
+	get_view()->unset_model();
+
+	if (m_filter_model)
+	{
+		g_object_unref(m_filter_model);
+		m_filter_model = NULL;
+	}
+
 	if (m_sort_model)
 	{
 		g_object_unref(m_sort_model);
 		m_sort_model = NULL;
 	}
-	get_view()->unset_model();
 }
 
 //-----------------------------------------------------------------------------
diff --git a/src/search_page.hpp b/src/search_page.hpp
index 7fbb9f7..8439de4 100644
--- a/src/search_page.hpp
+++ b/src/search_page.hpp
@@ -17,7 +17,7 @@
 #ifndef WHISKERMENU_SEARCH_PAGE_HPP
 #define WHISKERMENU_SEARCH_PAGE_HPP
 
-#include "filter_page.hpp"
+#include "page.hpp"
 #include "query.hpp"
 
 #include <map>
@@ -29,7 +29,7 @@ namespace WhiskerMenu
 
 class LauncherView;
 
-class SearchPage : public FilterPage
+class SearchPage : public Page
 {
 public:
 	explicit SearchPage(Menu* menu);
@@ -42,12 +42,13 @@ public:
 private:
 	void clear_search(GtkEntry* entry, GtkEntryIconPosition icon_pos);
 	bool search_entry_key_press(GtkWidget* widget, GdkEventKey* event);
-	bool on_filter(GtkTreeModel* model, GtkTreeIter* iter);
 	static gint on_sort(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, SearchPage* page);
-	void unset_search_model();
+	static gboolean on_filter(GtkTreeModel* model, GtkTreeIter* iter, SearchPage* page);
+	void unset_model();
 
 private:
 	Query m_query;
+	GtkTreeModelFilter* m_filter_model;
 	GtkTreeModelSort* m_sort_model;
 	std::vector<Launcher*> m_launchers;
 	std::map<std::string, std::map<Launcher*, int> > m_results;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list