[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 54/473: Add sorting search results by relevance.
noreply at xfce.org
noreply at xfce.org
Mon Feb 16 23:53:44 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 f8f3080a2d09c519542078d9c4756a58cf17571c
Author: Graeme Gott <graeme at gottcode.org>
Date: Mon Jul 1 18:41:08 2013 -0400
Add sorting search results by relevance.
---
src/search_page.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++-
src/search_page.hpp | 4 ++++
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/src/search_page.cpp b/src/search_page.cpp
index f03ffd5..4ddce03 100644
--- a/src/search_page.cpp
+++ b/src/search_page.cpp
@@ -31,7 +31,8 @@ using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
SearchPage::SearchPage(Menu* menu) :
- FilterPage(menu)
+ FilterPage(menu),
+ m_sort_model(NULL)
{
get_view()->set_selection_mode(GTK_SELECTION_BROWSE);
@@ -66,8 +67,14 @@ void SearchPage::set_filter(const gchar* filter)
}
// Apply filter
+ GtkTreeModel* filter_model = gtk_tree_model_sort_get_model(m_sort_model);
+ get_view()->unset_model();
+ unset_search_model();
+
refilter();
+ set_search_model(filter_model);
+
// Find first result
GtkTreeIter iter;
GtkTreePath* path = gtk_tree_path_new_first();
@@ -86,13 +93,16 @@ void SearchPage::set_filter(const gchar* filter)
void SearchPage::set_menu_items(GtkTreeModel* model)
{
+ unset_search_model();
set_model(model);
+ set_search_model(get_view()->get_model());
}
//-----------------------------------------------------------------------------
void SearchPage::unset_menu_items()
{
+ unset_search_model();
unset_model();
}
@@ -115,6 +125,39 @@ bool SearchPage::on_filter(GtkTreeModel* model, GtkTreeIter* iter)
//-----------------------------------------------------------------------------
+gint SearchPage::on_sort(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, SearchPage* page)
+{
+ Launcher* launcher_a = NULL;
+ gtk_tree_model_get(model, a, LauncherModel::COLUMN_LAUNCHER, &launcher_a, -1);
+
+ Launcher* launcher_b = NULL;
+ gtk_tree_model_get(model, b, LauncherModel::COLUMN_LAUNCHER, &launcher_b, -1);
+
+ return launcher_a->search(page->m_filter_string) - launcher_b->search(page->m_filter_string);
+}
+
+//-----------------------------------------------------------------------------
+
+void SearchPage::set_search_model(GtkTreeModel* child_model)
+{
+ m_sort_model = GTK_TREE_MODEL_SORT(gtk_tree_model_sort_new_with_model(child_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));
+}
+
+//-----------------------------------------------------------------------------
+
+void SearchPage::unset_search_model()
+{
+ if (m_sort_model)
+ {
+ g_object_unref(m_sort_model);
+ m_sort_model = NULL;
+ }
+}
+
+//-----------------------------------------------------------------------------
+
void SearchPage::clear_search(GtkEntry* entry, GtkEntryIconPosition icon_pos, GdkEvent*)
{
if (icon_pos == GTK_ENTRY_ICON_SECONDARY)
diff --git a/src/search_page.hpp b/src/search_page.hpp
index 1beec63..1c3306f 100644
--- a/src/search_page.hpp
+++ b/src/search_page.hpp
@@ -43,9 +43,13 @@ private:
private:
bool on_filter(GtkTreeModel* model, GtkTreeIter* iter);
+ static gint on_sort(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, SearchPage* page);
+ void set_search_model(GtkTreeModel* child_model);
+ void unset_search_model();
private:
std::string m_filter_string;
+ GtkTreeModelSort* m_sort_model;
};
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list