[gnome-builder] libide/tweaks: remove unnecessary panel lists after transitions



commit c97e99c5155937cfb74eb7d7a14f1dde6841beff
Author: Christian Hergert <chergert redhat com>
Date:   Wed Aug 3 10:32:11 2022 -0700

    libide/tweaks: remove unnecessary panel lists after transitions

 src/libide/tweaks/ide-tweaks-window.c  | 48 ++++++++++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-window.ui |  1 +
 2 files changed, 49 insertions(+)
---
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
index 6ed2505db..26a30c406 100644
--- a/src/libide/tweaks/ide-tweaks-window.c
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -65,6 +65,19 @@ ide_tweaks_window_get_current_page (IdeTweaksWindow *self)
   return NULL;
 }
 
+static IdeTweaksItem *
+ide_tweaks_window_get_current_list_item (IdeTweaksWindow *self)
+{
+  GtkWidget *visible_child;
+
+  g_assert (IDE_IS_TWEAKS_WINDOW (self));
+
+  if ((visible_child = gtk_stack_get_visible_child (self->panel_list_stack)))
+    return ide_tweaks_panel_list_get_item (IDE_TWEAKS_PANEL_LIST (visible_child));
+
+  return NULL;
+}
+
 static void
 ide_tweaks_window_update_actions (IdeTweaksWindow *self)
 {
@@ -212,6 +225,40 @@ panel_stack_notify_transition_running_cb (IdeTweaksWindow *self,
     }
 }
 
+static void
+panel_list_stack_notify_transition_running_cb (IdeTweaksWindow *self,
+                                               GParamSpec      *pspec,
+                                               GtkStack        *stack)
+{
+  IdeTweaksItem *current_list_item;
+  GListModel *model;
+  guint n_items;
+
+  g_assert (IDE_IS_TWEAKS_WINDOW (self));
+  g_assert (GTK_IS_STACK (stack));
+
+  if (gtk_stack_get_transition_running (stack))
+    return;
+
+  if (!(current_list_item = ide_tweaks_window_get_current_list_item (self)))
+    return;
+
+  model = G_LIST_MODEL (gtk_stack_get_pages (stack));
+  n_items = g_list_model_get_n_items (model);
+
+  for (guint i = n_items; i > 0; i--)
+    {
+      g_autoptr(GtkStackPage) page = g_list_model_get_item (G_LIST_MODEL (model), i - 1);
+      IdeTweaksPanelList *list = IDE_TWEAKS_PANEL_LIST (gtk_stack_page_get_child (page));
+      IdeTweaksItem *item = ide_tweaks_panel_list_get_item (list);
+
+      if (item != NULL &&
+          item != current_list_item &&
+          !ide_tweaks_item_is_ancestor (current_list_item, item))
+        gtk_stack_remove (stack, GTK_WIDGET (list));
+    }
+}
+
 static void
 ide_tweaks_window_navigate_back_action (GtkWidget  *widget,
                                         const char *action_name,
@@ -302,6 +349,7 @@ ide_tweaks_window_class_init (IdeTweaksWindowClass *klass)
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/libide-tweaks/ide-tweaks-window.ui");
   gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, panel_stack);
   gtk_widget_class_bind_template_child (widget_class, IdeTweaksWindow, panel_list_stack);
+  gtk_widget_class_bind_template_callback (widget_class, panel_list_stack_notify_transition_running_cb);
   gtk_widget_class_bind_template_callback (widget_class, panel_stack_notify_transition_running_cb);
 
   gtk_widget_class_install_action (widget_class, "navigation.back", NULL, 
ide_tweaks_window_navigate_back_action);
diff --git a/src/libide/tweaks/ide-tweaks-window.ui b/src/libide/tweaks/ide-tweaks-window.ui
index c42d39b33..12500ba74 100644
--- a/src/libide/tweaks/ide-tweaks-window.ui
+++ b/src/libide/tweaks/ide-tweaks-window.ui
@@ -82,6 +82,7 @@
                 <property name="vexpand">true</property>
                 <property name="vhomogeneous">false</property>
                 <property name="width-request">200</property>
+                <signal name="notify::transition-running" 
handler="panel_list_stack_notify_transition_running_cb" swapped="true" object="IdeTweaksWindow"/>
               </object>
             </child>
           </object>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]