[gnome-system-monitor/wip/searchbar] Added process list filter searchbar (bgo #509787)
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor/wip/searchbar] Added process list filter searchbar (bgo #509787)
- Date: Wed, 31 Jul 2013 21:17:32 +0000 (UTC)
commit f3045232d1503c8b481b5c51fdea6d77f4b6a235
Author: Robert Roth <robert roth off gmail com>
Date: Thu Aug 1 00:17:01 2013 +0300
Added process list filter searchbar (bgo #509787)
data/interface.ui | 47 ++++++++++++++++++++++++++++++++++++++++-------
src/interface.cpp | 26 ++++++++++++++++++++++++++
src/procman-app.h | 1 +
src/proctable.cpp | 27 ++++++++++++++++++++++++---
4 files changed, 91 insertions(+), 10 deletions(-)
---
diff --git a/data/interface.ui b/data/interface.ui
index 5bcb19d..765f34d 100644
--- a/data/interface.ui
+++ b/data/interface.ui
@@ -141,18 +141,51 @@
</packing>
</child>
<child>
- <object class="GtkScrolledWindow" id="processes_scrolled">
+ <object class="GtkBox" id="proclist_box">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hexpand">True</property>
- <property name="vexpand">True</property>
- <property name="shadow_type">in</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
<child>
- <placeholder/>
+ <object class="GtkSearchBar" id="proc_searchbar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="show-close-button">True</property>
+ <child>
+ <object class="GtkSearchEntry" id="proc_searchentry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="halign">fill</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="processes_scrolled">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
</child>
</object>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
diff --git a/src/interface.cpp b/src/interface.cpp
index f96efb0..ada8645 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -44,6 +44,23 @@
#include "gsm_color_button.h"
+static gboolean
+window_key_press_event_cb (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ return gtk_search_bar_handle_event (GTK_SEARCH_BAR (user_data), event);
+}
+
+static void
+search_text_changed (GtkEditable *entry, gpointer data)
+{
+ ProcmanApp * const app = static_cast<ProcmanApp *>(data);
+ gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (gtk_tree_model_sort_get_model (
+ GTK_TREE_MODEL_SORT (gtk_tree_view_get_model(
+ GTK_TREE_VIEW (app->tree))))));
+}
+
static void
create_proc_view(ProcmanApp *app, GtkBuilder * builder)
{
@@ -66,6 +83,15 @@ create_proc_view(ProcmanApp *app, GtkBuilder * builder)
GMenuModel *menu_model = G_MENU_MODEL (gtk_builder_get_object (builder, "process-popup-menu"));
app->popup_menu = gtk_menu_new_from_model (menu_model);
gtk_menu_attach_to_widget (GTK_MENU (app->popup_menu), app->main_window, NULL);
+
+ GtkSearchBar *search_bar = GTK_SEARCH_BAR (gtk_builder_get_object (builder, "proc_searchbar"));
+ app->search_entry = GTK_WIDGET (gtk_builder_get_object (builder, "proc_searchentry"));
+
+ gtk_search_bar_connect_entry (search_bar, GTK_ENTRY (app->search_entry));
+ g_signal_connect (app->main_window, "key-press-event",
+ G_CALLBACK (window_key_press_event_cb), search_bar);
+
+ g_signal_connect (app->search_entry, "changed", G_CALLBACK (search_text_changed), app);
}
void
diff --git a/src/procman-app.h b/src/procman-app.h
index 8888a82..5abc585 100644
--- a/src/procman-app.h
+++ b/src/procman-app.h
@@ -172,6 +172,7 @@ public:
GtkWidget *refresh_button;
GtkWidget *view_menu_button;
GtkWidget *end_process_button;
+ GtkWidget *search_entry;
ProcConfig config;
LoadGraph *cpu_graph;
LoadGraph *mem_graph;
diff --git a/src/proctable.cpp b/src/proctable.cpp
index a2d3ad0..05f7368 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -292,10 +292,31 @@ cb_refresh_icons (GtkIconTheme *theme, gpointer data)
}
gboolean process_visibility_func (GtkTreeModel *model,
- GtkTreeIter *iter,
+ GtkTreeIter *iter,
gpointer data)
{
- return !search_equal_func(model, 0, "", iter, data);
+ ProcmanApp * const app = static_cast<ProcmanApp *>(data);
+ const gchar * search_text = app->search_entry == NULL ? "" : gtk_entry_get_text (GTK_ENTRY
(app->search_entry));
+ GtkTreePath *tree_path = gtk_tree_model_get_path (model, iter);
+ // in case we are in dependencies view, we show (and expand) rows not matching the text, but having a
matching child
+ gboolean match = false;
+ if (g_settings_get_boolean (app->settings, "show-dependencies")) {
+
+ if (!search_equal_func (model, 0, search_text, iter, data)) {
+ match = true;
+ if (strlen (search_text) > 0)
+ gtk_tree_view_expand_to_path (GTK_TREE_VIEW (app->tree), tree_path);
+ } else {
+ GtkTreeIter child;
+ if (gtk_tree_model_iter_children (model, &child, iter)) {
+ while ((match = !process_visibility_func (model, &child, data)) && gtk_tree_model_iter_next
(model, &child)) ;
+ match = !match;
+ }
+ }
+ } else match = !search_equal_func (model, 0, search_text, iter, data);
+
+ gtk_tree_path_free (tree_path);
+ return match;
}
GtkWidget *
@@ -373,7 +394,7 @@ proctable_new (ProcmanApp * const app)
model_filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (GTK_TREE_MODEL (model), NULL));
- gtk_tree_model_filter_set_visible_func(model_filter, process_visibility_func, NULL, NULL);
+ gtk_tree_model_filter_set_visible_func(model_filter, process_visibility_func, app, NULL);
model_sort = GTK_TREE_MODEL_SORT (gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (model_filter)));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]