[gnome-builder/wip/chergert/layout] symbol-tree: add search to symbol popover
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/layout] symbol-tree: add search to symbol popover
- Date: Sun, 2 Jul 2017 01:36:07 +0000 (UTC)
commit 3e2dcc8c60132d5e148da93d04f443766598b8ac
Author: Christian Hergert <chergert redhat com>
Date: Sat Jul 1 18:35:04 2017 -0700
symbol-tree: add search to symbol popover
This is useful for quickly filtering the symbols based on a
search query. We should probably make this easily focusable
by keybinding with a layout-view action.
plugins/symbol-tree/gbp-symbol-menu-button.c | 49 ++++++++++++++++++++++++-
plugins/symbol-tree/gbp-symbol-menu-button.ui | 32 +++++++++++-----
2 files changed, 70 insertions(+), 11 deletions(-)
---
diff --git a/plugins/symbol-tree/gbp-symbol-menu-button.c b/plugins/symbol-tree/gbp-symbol-menu-button.c
index 6879a21..73062ba 100644
--- a/plugins/symbol-tree/gbp-symbol-menu-button.c
+++ b/plugins/symbol-tree/gbp-symbol-menu-button.c
@@ -31,7 +31,8 @@ struct _GbpSymbolMenuButton
/* Template references */
DzlTree *tree;
DzlTreeBuilder *tree_builder;
- GtkWidget *popover;
+ GtkPopover *popover;
+ GtkSearchEntry *search_entry;
};
enum {
@@ -44,6 +45,46 @@ G_DEFINE_TYPE (GbpSymbolMenuButton, gbp_symbol_menu_button, GTK_TYPE_MENU_BUTTON
static GParamSpec *properties [N_PROPS];
+static gboolean
+filter_symbols_cb (DzlTree *tree,
+ DzlTreeNode *node,
+ gpointer user_data)
+{
+ DzlPatternSpec *spec = user_data;
+ const gchar *text;
+
+ if G_LIKELY (NULL != (text = dzl_tree_node_get_text (node)))
+ return dzl_pattern_spec_match (spec, text);
+
+ return FALSE;
+}
+
+static void
+gbp_symbol_menu_button_search_changed (GbpSymbolMenuButton *self,
+ GtkSearchEntry *search_entry)
+{
+ DzlPatternSpec *spec;
+ const gchar *text;
+
+ g_assert (GBP_IS_SYMBOL_MENU_BUTTON (self));
+ g_assert (GTK_IS_SEARCH_ENTRY (search_entry));
+
+ text = gtk_entry_get_text (GTK_ENTRY (search_entry));
+
+ if (ide_str_empty0 (text))
+ {
+ dzl_tree_set_filter (self->tree, NULL, NULL, NULL);
+ return;
+ }
+
+ spec = dzl_pattern_spec_new (text);
+ dzl_tree_set_filter (self->tree,
+ filter_symbols_cb,
+ spec,
+ (GDestroyNotify)dzl_pattern_spec_unref);
+ gtk_tree_view_expand_all (GTK_TREE_VIEW (self->tree));
+}
+
static void
gbp_symbol_menu_button_destroy (GtkWidget *widget)
{
@@ -108,6 +149,7 @@ gbp_symbol_menu_button_class_init (GbpSymbolMenuButtonClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/builder/plugins/symbol-tree-plugin/gbp-symbol-menu-button.ui");
gtk_widget_class_bind_template_child (widget_class, GbpSymbolMenuButton, popover);
+ gtk_widget_class_bind_template_child (widget_class, GbpSymbolMenuButton, search_entry);
gtk_widget_class_bind_template_child (widget_class, GbpSymbolMenuButton, tree);
gtk_widget_class_bind_template_child (widget_class, GbpSymbolMenuButton, tree_builder);
@@ -127,6 +169,11 @@ static void
gbp_symbol_menu_button_init (GbpSymbolMenuButton *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
+
+ g_signal_connect_swapped (self->search_entry,
+ "changed",
+ G_CALLBACK (gbp_symbol_menu_button_search_changed),
+ self);
}
/**
diff --git a/plugins/symbol-tree/gbp-symbol-menu-button.ui b/plugins/symbol-tree/gbp-symbol-menu-button.ui
index 39c35f9..00667c4 100644
--- a/plugins/symbol-tree/gbp-symbol-menu-button.ui
+++ b/plugins/symbol-tree/gbp-symbol-menu-button.ui
@@ -5,19 +5,31 @@
<class name="symbols-button"/>
</style>
<child>
- <object class="GtkScrolledWindow">
- <property name="propagate-natural-width">true</property>
- <property name="propagate-natural-height">true</property>
- <property name="max-content-height">600</property>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
<property name="visible">true</property>
<child>
- <object class="DzlTree" id="tree">
- <property name="headers-visible">false</property>
- <property name="show-icons">true</property>
- <property name="activate-on-single-click">true</property>
+ <object class="GtkSearchEntry" id="search_entry">
+ <property name="margin">6</property>
<property name="visible">true</property>
- <child type="builder">
- <object class="GbpSymbolTreeBuilder" id="tree_builder"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="propagate-natural-width">true</property>
+ <property name="propagate-natural-height">true</property>
+ <property name="max-content-height">600</property>
+ <property name="visible">true</property>
+ <child>
+ <object class="DzlTree" id="tree">
+ <property name="headers-visible">false</property>
+ <property name="show-icons">true</property>
+ <property name="activate-on-single-click">true</property>
+ <property name="visible">true</property>
+ <child type="builder">
+ <object class="GbpSymbolTreeBuilder" id="tree_builder"/>
+ </child>
+ </object>
</child>
</object>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]