[gnome-builder/wip/chergert/layout] symbol-tree: update symbols when popover is toggled
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/layout] symbol-tree: update symbols when popover is toggled
- Date: Mon, 3 Jul 2017 02:16:11 +0000 (UTC)
commit d56a0af348df3848645a40ad567c910f57a76af8
Author: Christian Hergert <chergert redhat com>
Date: Sun Jul 2 19:12:41 2017 -0700
symbol-tree: update symbols when popover is toggled
Try to avoid updating the symbol popover when the popover is
not displayed. We will populate it quickly when the menu button
is toggled.
.../symbol-tree/gbp-symbol-layout-stack-addin.c | 71 +++++++++++++++-----
plugins/symbol-tree/gbp-symbol-menu-button.c | 2 +-
plugins/symbol-tree/gbp-symbol-menu-button.ui | 8 ++-
3 files changed, 62 insertions(+), 19 deletions(-)
---
diff --git a/plugins/symbol-tree/gbp-symbol-layout-stack-addin.c
b/plugins/symbol-tree/gbp-symbol-layout-stack-addin.c
index 3474c1d..3aef7b6 100644
--- a/plugins/symbol-tree/gbp-symbol-layout-stack-addin.c
+++ b/plugins/symbol-tree/gbp-symbol-layout-stack-addin.c
@@ -40,6 +40,7 @@ gbp_symbol_layout_stack_addin_cursor_moved (GbpSymbolLayoutStackAddin *self,
g_assert (location != NULL);
g_assert (IDE_IS_BUFFER (buffer));
+ /* TODO: Delay a bit so we aren't super active */
}
static void
@@ -52,9 +53,9 @@ gbp_symbol_layout_stack_addin_get_symbol_tree_cb (GObject *object,
g_autoptr(IdeSymbolTree) tree = NULL;
g_autoptr(GError) error = NULL;
- g_assert (GBP_IS_SYMBOL_LAYOUT_STACK_ADDIN (self));
- g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (IDE_IS_SYMBOL_RESOLVER (symbol_resolver));
g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (GBP_IS_SYMBOL_LAYOUT_STACK_ADDIN (self));
tree = ide_symbol_resolver_get_symbol_tree_finish (symbol_resolver, result, &error);
@@ -67,19 +68,12 @@ gbp_symbol_layout_stack_addin_get_symbol_tree_cb (GObject *object,
if (self->button == NULL)
return;
- if (tree == NULL)
- {
- gtk_widget_hide (GTK_WIDGET (self->button));
- return;
- }
-
gbp_symbol_menu_button_set_symbol_tree (self->button, tree);
- gtk_widget_show (GTK_WIDGET (self->button));
}
static void
-gbp_symbol_layout_stack_addin_change_settled (GbpSymbolLayoutStackAddin *self,
- IdeBuffer *buffer)
+gbp_symbol_layout_stack_addin_update_tree (GbpSymbolLayoutStackAddin *self,
+ IdeBuffer *buffer)
{
IdeSymbolResolver *symbol_resolver;
IdeFile *file;
@@ -87,18 +81,22 @@ gbp_symbol_layout_stack_addin_change_settled (GbpSymbolLayoutStackAddin *self,
g_assert (GBP_IS_SYMBOL_LAYOUT_STACK_ADDIN (self));
g_assert (IDE_IS_BUFFER (buffer));
+ /* Cancel any in-flight work */
+ g_cancellable_cancel (self->cancellable);
+ g_clear_object (&self->cancellable);
+
symbol_resolver = ide_buffer_get_symbol_resolver (buffer);
g_assert (!symbol_resolver || IDE_IS_SYMBOL_RESOLVER (symbol_resolver));
+ gtk_widget_set_visible (GTK_WIDGET (self->button), symbol_resolver != NULL);
if (symbol_resolver == NULL)
- {
- gtk_widget_hide (GTK_WIDGET (self->button));
- return;
- }
+ return;
file = ide_buffer_get_file (buffer);
g_assert (IDE_IS_FILE (file));
+ self->cancellable = g_cancellable_new ();
+
ide_symbol_resolver_get_symbol_tree_async (symbol_resolver,
ide_file_get_file (file),
buffer,
@@ -108,17 +106,54 @@ gbp_symbol_layout_stack_addin_change_settled (GbpSymbolLayoutStackAddin *self,
}
static void
+gbp_symbol_layout_stack_addin_change_settled (GbpSymbolLayoutStackAddin *self,
+ IdeBuffer *buffer)
+{
+ g_assert (GBP_IS_SYMBOL_LAYOUT_STACK_ADDIN (self));
+ g_assert (IDE_IS_BUFFER (buffer));
+
+ /* Ignore this request unless the button is active */
+ if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->button)))
+ return;
+
+ gbp_symbol_layout_stack_addin_update_tree (self, buffer);
+}
+
+static void
+gbp_symbol_layout_stack_addin_button_toggled (GbpSymbolLayoutStackAddin *self,
+ GtkMenuButton *button)
+{
+ IdeBuffer *buffer;
+
+ g_assert (GBP_IS_SYMBOL_LAYOUT_STACK_ADDIN (self));
+ g_assert (GTK_IS_MENU_BUTTON (button));
+
+ buffer = dzl_signal_group_get_target (self->buffer_signals);
+ g_assert (!buffer || IDE_IS_BUFFER (buffer));
+
+ if (buffer != NULL && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
+ gbp_symbol_layout_stack_addin_update_tree (self, buffer);
+}
+
+static void
gbp_symbol_layout_stack_addin_bind (GbpSymbolLayoutStackAddin *self,
IdeBuffer *buffer,
DzlSignalGroup *buffer_signals)
{
+ IdeSymbolResolver *symbol_resolver;
+
g_assert (GBP_IS_SYMBOL_LAYOUT_STACK_ADDIN (self));
g_assert (IDE_IS_BUFFER (buffer));
g_assert (DZL_IS_SIGNAL_GROUP (buffer_signals));
self->cancellable = g_cancellable_new ();
- gbp_symbol_layout_stack_addin_change_settled (self, buffer);
+ gtk_button_set_label (GTK_BUTTON (self->button), _("Symbols"));
+
+ symbol_resolver = ide_buffer_get_symbol_resolver (buffer);
+ gtk_widget_set_visible (GTK_WIDGET (self->button), symbol_resolver != NULL);
+
+ gbp_symbol_layout_stack_addin_update_tree (self, buffer);
}
static void
@@ -150,6 +185,10 @@ gbp_symbol_layout_stack_addin_load (IdeLayoutStackAddin *addin,
"destroy",
G_CALLBACK (gtk_widget_destroyed),
&self->button);
+ g_signal_connect_swapped (self->button,
+ "toggled",
+ G_CALLBACK (gbp_symbol_layout_stack_addin_button_toggled),
+ self);
ide_layout_stack_header_add_custom_title (IDE_LAYOUT_STACK_HEADER (header),
GTK_WIDGET (self->button),
100);
diff --git a/plugins/symbol-tree/gbp-symbol-menu-button.c b/plugins/symbol-tree/gbp-symbol-menu-button.c
index 73062ba..2efe4cb 100644
--- a/plugins/symbol-tree/gbp-symbol-menu-button.c
+++ b/plugins/symbol-tree/gbp-symbol-menu-button.c
@@ -216,7 +216,7 @@ gbp_symbol_menu_button_set_symbol_tree (GbpSymbolMenuButton *self,
if (symbol_tree != NULL)
dzl_tree_node_set_item (root, G_OBJECT (symbol_tree));
dzl_tree_set_root (self->tree, root);
-
+ gtk_tree_view_expand_all (GTK_TREE_VIEW (self->tree));
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SYMBOL_TREE]);
}
}
diff --git a/plugins/symbol-tree/gbp-symbol-menu-button.ui b/plugins/symbol-tree/gbp-symbol-menu-button.ui
index 00667c4..a0fe230 100644
--- a/plugins/symbol-tree/gbp-symbol-menu-button.ui
+++ b/plugins/symbol-tree/gbp-symbol-menu-button.ui
@@ -10,14 +10,18 @@
<property name="visible">true</property>
<child>
<object class="GtkSearchEntry" id="search_entry">
- <property name="margin">6</property>
+ <property name="margin-start">14</property>
+ <property name="margin-end">14</property>
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
<property name="visible">true</property>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
- <property name="propagate-natural-width">true</property>
<property name="propagate-natural-height">true</property>
+ <property name="propagate-natural-width">true</property>
+ <property name="min-content-height">300</property>
<property name="max-content-height">600</property>
<property name="visible">true</property>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]