[gnome-builder] symbol-tree: add search capabilities to symbol tree panel
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] symbol-tree: add search capabilities to symbol tree panel
- Date: Sat, 20 Jun 2015 09:48:55 +0000 (UTC)
commit 22902e2a238cdd966c3c7742883ab22135cd688a
Author: Christian Hergert <christian hergert me>
Date: Fri Jun 19 02:00:40 2015 -0700
symbol-tree: add search capabilities to symbol tree panel
Use IdePatternSpec to provide basic search filtering capabilities to the
symbols panel.
data/theme/Adwaita-shared.css | 11 +++++++
plugins/symbol-tree/symbol-tree.c | 56 ++++++++++++++++++++++++++++++++---
plugins/symbol-tree/symbol-tree.ui | 6 ++++
3 files changed, 68 insertions(+), 5 deletions(-)
---
diff --git a/data/theme/Adwaita-shared.css b/data/theme/Adwaita-shared.css
index 8adda4d..4f03d50 100644
--- a/data/theme/Adwaita-shared.css
+++ b/data/theme/Adwaita-shared.css
@@ -72,3 +72,14 @@ DhSidebar GtkSearchEntry {
border-top: none;
border-radius: 0px;
}
+
+
+/*
+ * Adjust symbol panel styling.
+ */
+SymbolTree GtkSearchEntry {
+ border-left: none;
+ border-right: none;
+ border-top: none;
+ border-radius: 0px;
+}
diff --git a/plugins/symbol-tree/symbol-tree.c b/plugins/symbol-tree/symbol-tree.c
index fd6517c..69e5e49 100644
--- a/plugins/symbol-tree/symbol-tree.c
+++ b/plugins/symbol-tree/symbol-tree.c
@@ -17,6 +17,7 @@
*/
#include <glib/gi18n.h>
+#include <ide.h>
#include <libpeas/peas.h>
#include "egg-task-cache.h"
@@ -32,12 +33,13 @@
struct _SymbolTree
{
- GtkBox parent_instance;
+ GtkBox parent_instance;
- GCancellable *cancellable;
- EggTaskCache *symbols_cache;
- GbWorkbench *workbench;
- GbTree *tree;
+ GCancellable *cancellable;
+ EggTaskCache *symbols_cache;
+ GbWorkbench *workbench;
+ GbTree *tree;
+ GtkSearchEntry *search_entry;
};
enum {
@@ -234,6 +236,43 @@ symbol_tree_set_workbench (SymbolTree *self,
ide_set_weak_pointer (&self->workbench, workbench);
}
+static gboolean
+filter_symbols_cb (GbTree *tree,
+ GbTreeNode *node,
+ gpointer user_data)
+{
+ IdePatternSpec *spec = user_data;
+
+ return ide_pattern_spec_match (spec, gb_tree_node_get_text (node));
+}
+
+static void
+symbol_tree__search_entry_changed (SymbolTree *self,
+ GtkSearchEntry *search_entry)
+{
+ const gchar *text;
+
+ g_return_if_fail (SYMBOL_IS_TREE (self));
+ g_return_if_fail (GTK_IS_SEARCH_ENTRY (search_entry));
+
+ text = gtk_entry_get_text (GTK_ENTRY (search_entry));
+
+ if (ide_str_empty0 (text))
+ {
+ gb_tree_set_filter (self->tree, NULL, NULL, NULL);
+ }
+ else
+ {
+ IdePatternSpec *spec;
+
+ spec = ide_pattern_spec_new (text);
+ gb_tree_set_filter (self->tree,
+ filter_symbols_cb,
+ spec,
+ (GDestroyNotify)ide_pattern_spec_unref);
+ }
+}
+
static void
symbol_tree_set_property (GObject *object,
guint prop_id,
@@ -291,6 +330,7 @@ symbol_tree_class_init (SymbolTreeClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/builder/plugins/symbol-tree/symbol-tree.ui");
gtk_widget_class_bind_template_child (widget_class, SymbolTree, tree);
+ gtk_widget_class_bind_template_child (widget_class, SymbolTree, search_entry);
g_type_ensure (GB_TYPE_TREE);
}
@@ -319,6 +359,12 @@ symbol_tree_init (SymbolTree *self)
builder = g_object_new (SYMBOL_TYPE_TREE_BUILDER, NULL);
gb_tree_add_builder (self->tree, builder);
+
+ g_signal_connect_object (self->search_entry,
+ "changed",
+ G_CALLBACK (symbol_tree__search_entry_changed),
+ self,
+ G_CONNECT_SWAPPED);
}
GB_DEFINE_EMBEDDED_PLUGIN (symbol_tree,
diff --git a/plugins/symbol-tree/symbol-tree.ui b/plugins/symbol-tree/symbol-tree.ui
index 6097591..5cd0a80 100644
--- a/plugins/symbol-tree/symbol-tree.ui
+++ b/plugins/symbol-tree/symbol-tree.ui
@@ -4,6 +4,12 @@
<template class="SymbolTree" parent="GtkBox">
<property name="vexpand">true</property>
<property name="visible">true</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkSearchEntry" id="search_entry">
+ <property name="visible">true</property>
+ </object>
+ </child>
<child>
<object class="GtkScrolledWindow">
<property name="expand">true</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]