[gnome-builder] libide/tweaks: wire up selection-mode and folded to window



commit 33aaf8c4c97ae93405d77bc0f593e5942d55990f
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 4 09:15:20 2022 -0700

    libide/tweaks: wire up selection-mode and folded to window

 src/libide/tweaks/ide-tweaks-panel-list-private.h | 15 +++++----
 src/libide/tweaks/ide-tweaks-panel-list.c         | 28 ++++++++++++++++
 src/libide/tweaks/ide-tweaks-panel-private.h      |  2 ++
 src/libide/tweaks/ide-tweaks-panel.c              | 21 +++++++++++-
 src/libide/tweaks/ide-tweaks-panel.ui             |  4 +--
 src/libide/tweaks/ide-tweaks-window.c             | 41 +++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-window.ui            |  1 +
 7 files changed, 103 insertions(+), 9 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-panel-list-private.h 
b/src/libide/tweaks/ide-tweaks-panel-list-private.h
index 798e5a512..74cd43783 100644
--- a/src/libide/tweaks/ide-tweaks-panel-list-private.h
+++ b/src/libide/tweaks/ide-tweaks-panel-list-private.h
@@ -30,11 +30,14 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (IdeTweaksPanelList, ide_tweaks_panel_list, IDE, TWEAKS_PANEL_LIST, AdwBin)
 
-GtkWidget     *ide_tweaks_panel_list_new             (IdeTweaksItem      *item);
-IdeTweaksItem *ide_tweaks_panel_list_get_item        (IdeTweaksPanelList *self);
-void           ide_tweaks_panel_list_select_first    (IdeTweaksPanelList *self);
-gboolean       ide_tweaks_panel_list_get_search_mode (IdeTweaksPanelList *self);
-void           ide_tweaks_panel_list_set_search_mode (IdeTweaksPanelList *self,
-                                                      gboolean            search_mode);
+GtkWidget        *ide_tweaks_panel_list_new                (IdeTweaksItem      *item);
+IdeTweaksItem    *ide_tweaks_panel_list_get_item           (IdeTweaksPanelList *self);
+void              ide_tweaks_panel_list_select_first       (IdeTweaksPanelList *self);
+gboolean          ide_tweaks_panel_list_get_search_mode    (IdeTweaksPanelList *self);
+void              ide_tweaks_panel_list_set_search_mode    (IdeTweaksPanelList *self,
+                                                            gboolean            search_mode);
+GtkSelectionMode  ide_tweaks_panel_list_get_selection_mode (IdeTweaksPanelList *self);
+void              ide_tweaks_panel_list_set_selection_mode (IdeTweaksPanelList *self,
+                                                            GtkSelectionMode    selection_mode);
 
 G_END_DECLS
diff --git a/src/libide/tweaks/ide-tweaks-panel-list.c b/src/libide/tweaks/ide-tweaks-panel-list.c
index 4d1788ee7..a20a6ca1c 100644
--- a/src/libide/tweaks/ide-tweaks-panel-list.c
+++ b/src/libide/tweaks/ide-tweaks-panel-list.c
@@ -43,6 +43,7 @@ enum {
   PROP_0,
   PROP_ITEM,
   PROP_SEARCH_MODE,
+  PROP_SELECTION_MODE,
   N_PROPS
 };
 
@@ -234,6 +235,12 @@ ide_tweaks_panel_list_class_init (IdeTweaksPanelListClass *klass)
                           FALSE,
                           (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
 
+  properties[PROP_SELECTION_MODE] =
+    g_param_spec_enum ("selection-mode", NULL, NULL,
+                       GTK_TYPE_SELECTION_MODE,
+                       GTK_SELECTION_SINGLE,
+                       (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, N_PROPS, properties);
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/libide-tweaks/ide-tweaks-panel-list.ui");
@@ -326,3 +333,24 @@ ide_tweaks_panel_list_set_search_mode (IdeTweaksPanelList *self,
       g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SEARCH_MODE]);
     }
 }
+
+GtkSelectionMode
+ide_tweaks_panel_list_get_selection_mode (IdeTweaksPanelList *self)
+{
+  g_return_val_if_fail (IDE_IS_TWEAKS_PANEL_LIST (self), 0);
+
+  return gtk_list_box_get_selection_mode (self->list_box);
+}
+
+void
+ide_tweaks_panel_list_set_selection_mode (IdeTweaksPanelList *self,
+                                          GtkSelectionMode    selection_mode)
+{
+  g_return_if_fail (IDE_IS_TWEAKS_PANEL_LIST (self));
+
+  if (selection_mode != ide_tweaks_panel_list_get_selection_mode (self))
+    {
+      gtk_list_box_set_selection_mode (self->list_box, selection_mode);
+      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTION_MODE]);
+    }
+}
diff --git a/src/libide/tweaks/ide-tweaks-panel-private.h b/src/libide/tweaks/ide-tweaks-panel-private.h
index d931e7662..3b3cde0c6 100644
--- a/src/libide/tweaks/ide-tweaks-panel-private.h
+++ b/src/libide/tweaks/ide-tweaks-panel-private.h
@@ -33,5 +33,7 @@ G_DECLARE_FINAL_TYPE (IdeTweaksPanel, ide_tweaks_panel, IDE, TWEAKS_PANEL, AdwBi
 GtkWidget     *ide_tweaks_panel_new        (IdeTweaksPage  *page);
 IdeTweaksPage *ide_tweaks_panel_get_page   (IdeTweaksPanel *self);
 gboolean       ide_tweaks_panel_get_folded (IdeTweaksPanel *self);
+void           ide_tweaks_panel_set_folded (IdeTweaksPanel *self,
+                                            gboolean        folded);
 
 G_END_DECLS
diff --git a/src/libide/tweaks/ide-tweaks-panel.c b/src/libide/tweaks/ide-tweaks-panel.c
index 5a3233a7e..438f45392 100644
--- a/src/libide/tweaks/ide-tweaks-panel.c
+++ b/src/libide/tweaks/ide-tweaks-panel.c
@@ -154,6 +154,10 @@ ide_tweaks_panel_set_property (GObject      *object,
 
   switch (prop_id)
     {
+    case PROP_FOLDED:
+      ide_tweaks_panel_set_folded (self, g_value_get_boolean (value));
+      break;
+
     case PROP_PAGE:
       self->page = g_value_dup_object (value);
       break;
@@ -177,7 +181,7 @@ ide_tweaks_panel_class_init (IdeTweaksPanelClass *klass)
   properties[PROP_FOLDED] =
     g_param_spec_boolean ("folded", NULL, NULL,
                          FALSE,
-                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
 
   properties[PROP_PAGE] =
     g_param_spec_object ("page", NULL, NULL,
@@ -221,3 +225,18 @@ ide_tweaks_panel_get_folded (IdeTweaksPanel *self)
 
   return self->folded;
 }
+
+void
+ide_tweaks_panel_set_folded (IdeTweaksPanel *self,
+                             gboolean        folded)
+{
+  g_return_if_fail (IDE_IS_TWEAKS_PANEL (self));
+
+  folded = !!folded;
+
+  if (self->folded != folded)
+    {
+      self->folded = folded;
+      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FOLDED]);
+    }
+}
diff --git a/src/libide/tweaks/ide-tweaks-panel.ui b/src/libide/tweaks/ide-tweaks-panel.ui
index c754c01cf..993c2aba2 100644
--- a/src/libide/tweaks/ide-tweaks-panel.ui
+++ b/src/libide/tweaks/ide-tweaks-panel.ui
@@ -12,10 +12,10 @@
             <child>
               <object class="AdwHeaderBar" id="titlebar">
                 <property name="show-end-title-buttons">true</property>
-                <property name="show-start-title-buttons" bind-source="IdeTweaksPanel" 
bind-property="folded" bind-flags="default|sync-create"/>
+                <property name="show-start-title-buttons" bind-source="IdeTweaksPanel" 
bind-property="folded" bind-flags="sync-create"/>
                 <child type="start">
                   <object class="GtkButton">
-                    <property name="visible" bind-source="IdeTweaksPanel" bind-property="folded" 
bind-flags="default|sync-create"/>
+                    <property name="visible" bind-source="IdeTweaksPanel" bind-property="folded" 
bind-flags="sync-create"/>
                     <property name="icon-name">go-previous-symbolic</property>
                     <property name="action-name">window.navigate</property>
                     <property name="action-target">0</property>
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
index ae5bb7fff..749753c63 100644
--- a/src/libide/tweaks/ide-tweaks-window.c
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -41,11 +41,13 @@ struct _IdeTweaksWindow
   GtkSearchEntry *sidebar_search_entry;
 
   guint           can_navigate_back : 1;
+  guint           folded : 1;
 };
 
 enum {
   PROP_0,
   PROP_CAN_NAVIGATE_BACK,
+  PROP_FOLDED,
   PROP_TWEAKS,
   N_PROPS
 };
@@ -303,6 +305,33 @@ ide_tweaks_window_navigate_back_action (GtkWidget  *widget,
   ide_tweaks_window_navigate_back (IDE_TWEAKS_WINDOW (widget));
 }
 
+static void
+ide_tweaks_window_set_folded (IdeTweaksWindow *self,
+                              gboolean         folded)
+{
+  g_assert (IDE_IS_TWEAKS_WINDOW (self));
+
+  folded = !!folded;
+
+  if (self->folded != folded)
+    {
+      GtkSelectionMode selection_mode;
+      GtkWidget *child;
+
+      self->folded = folded;
+
+      selection_mode = folded ? GTK_SELECTION_NONE : GTK_SELECTION_SINGLE;
+
+      if ((child = gtk_stack_get_visible_child (self->panel_stack)))
+        ide_tweaks_panel_set_folded (IDE_TWEAKS_PANEL (child), folded);
+
+      if ((child = gtk_stack_get_visible_child (self->panel_list_stack)))
+        ide_tweaks_panel_list_set_selection_mode (IDE_TWEAKS_PANEL_LIST (child), selection_mode);
+
+      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FOLDED]);
+    }
+}
+
 static void
 ide_tweaks_window_dispose (GObject *object)
 {
@@ -331,6 +360,10 @@ ide_tweaks_window_get_property (GObject    *object,
       g_value_set_boolean (value, ide_tweaks_window_get_can_navigate_back (self));
       break;
 
+    case PROP_FOLDED:
+      g_value_set_boolean (value, self->folded);
+      break;
+
     case PROP_TWEAKS:
       g_value_set_object (value, ide_tweaks_window_get_tweaks (self));
       break;
@@ -350,6 +383,10 @@ ide_tweaks_window_set_property (GObject      *object,
 
   switch (prop_id)
     {
+    case PROP_FOLDED:
+      ide_tweaks_window_set_folded (self, g_value_get_boolean (value));
+      break;
+
     case PROP_TWEAKS:
       ide_tweaks_window_set_tweaks (self, g_value_get_object (value));
       break;
@@ -374,6 +411,10 @@ ide_tweaks_window_class_init (IdeTweaksWindowClass *klass)
                           FALSE,
                           (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
+  properties[PROP_FOLDED] =
+    g_param_spec_boolean ("folded", NULL, NULL,
+                         FALSE,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
 
   properties [PROP_TWEAKS] =
     g_param_spec_object ("tweaks", NULL, NULL,
diff --git a/src/libide/tweaks/ide-tweaks-window.ui b/src/libide/tweaks/ide-tweaks-window.ui
index 0fb7e4cda..4bea7235e 100644
--- a/src/libide/tweaks/ide-tweaks-window.ui
+++ b/src/libide/tweaks/ide-tweaks-window.ui
@@ -4,6 +4,7 @@
     <property name="title" translatable="yes">Preferences</property>
     <property name="default-width">1080</property>
     <property name="default-height">720</property>
+    <property name="folded" bind-source="leaflet" bind-property="folded" bind-flags="sync-create"/>
     <child>
       <object class="AdwLeaflet" id="leaflet">
         <property name="can-navigate-back">true</property>


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