[gnome-control-center/gbsneto/panel-headerbar-cleanup: 3/14] panel: Add 'folded' property




commit 6283815d5f0dede0cb2f46c7c6f8e2aed929ba64
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Jan 19 10:12:13 2022 -0300

    panel: Add 'folded' property
    
    This property keeps track of whether the panel is folded
    into the main leaflet. Will be used when moving headerbars
    into the panel themselves.

 shell/cc-panel-private.h | 28 ++++++++++++++++++++++++++++
 shell/cc-panel.c         | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 shell/cc-panel.h         |  2 ++
 shell/cc-window.c        | 12 +++++++-----
 4 files changed, 82 insertions(+), 6 deletions(-)
---
diff --git a/shell/cc-panel-private.h b/shell/cc-panel-private.h
new file mode 100644
index 000000000..5cc4ebc3a
--- /dev/null
+++ b/shell/cc-panel-private.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2022 Endless OS Foundation, LLC
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Georges Basile Stavracas Neto <georges stavracas gmail com>
+ */
+
+#pragma once
+
+#include "cc-panel.h"
+
+void cc_panel_set_folded (CcPanel  *panel,
+                          gboolean  folded);
+
+G_END_DECLS
+
diff --git a/shell/cc-panel.c b/shell/cc-panel.c
index 93983cfc0..655bd6fd4 100644
--- a/shell/cc-panel.c
+++ b/shell/cc-panel.c
@@ -32,7 +32,7 @@
 
 #include "config.h"
 
-#include "cc-panel.h"
+#include "cc-panel-private.h"
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -44,6 +44,7 @@ typedef struct
 {
   CcShell      *shell;
   GCancellable *cancellable;
+  gboolean      folded;
 } CcPanelPrivate;
 
 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (CcPanel, cc_panel, ADW_TYPE_BIN)
@@ -59,6 +60,7 @@ enum
   PROP_0,
   PROP_SHELL,
   PROP_PARAMETERS,
+  PROP_FOLDED,
   N_PROPS
 };
 
@@ -109,6 +111,8 @@ cc_panel_set_property (GObject      *object,
 
         break;
       }
+
+    case PROP_FOLDED:
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -129,6 +133,10 @@ cc_panel_get_property (GObject    *object,
       g_value_set_object (value, priv->shell);
       break;
 
+    case PROP_FOLDED:
+      g_value_set_boolean (value, priv->folded);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -168,6 +176,10 @@ cc_panel_class_init (CcPanelClass *klass)
                                                 CC_TYPE_SHELL,
                                                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | 
G_PARAM_STATIC_STRINGS);
 
+  properties[PROP_FOLDED] = g_param_spec_boolean ("folded", NULL, NULL,
+                                                  FALSE,
+                                                  G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
   properties[PROP_PARAMETERS] = g_param_spec_variant ("parameters",
                                                       "Structured parameters",
                                                       "Additional parameters passed externally (ie. command 
line, D-Bus activation)",
@@ -255,3 +267,35 @@ cc_panel_get_cancellable (CcPanel *panel)
 
   return priv->cancellable;
 }
+
+void
+cc_panel_set_folded (CcPanel  *panel,
+                     gboolean  folded)
+{
+  CcPanelPrivate *priv;
+
+  g_return_if_fail (CC_IS_PANEL (panel));
+
+  priv = cc_panel_get_instance_private (panel);
+
+  if (priv->folded != folded)
+    {
+      g_debug ("Panel %s folded: %s",
+               G_OBJECT_TYPE_NAME (panel),
+               folded ? "yes" : "no");
+
+      priv->folded = folded;
+      g_object_notify_by_pspec (G_OBJECT (panel), properties[PROP_FOLDED]);
+    }
+}
+
+gboolean
+cc_panel_get_folded (CcPanel *panel)
+{
+  CcPanelPrivate *priv;
+
+  g_return_val_if_fail (CC_IS_PANEL (panel), FALSE);
+
+  priv = cc_panel_get_instance_private (panel);
+  return priv->folded;
+}
diff --git a/shell/cc-panel.h b/shell/cc-panel.h
index 04b0d3533..da9e1e737 100644
--- a/shell/cc-panel.h
+++ b/shell/cc-panel.h
@@ -95,5 +95,7 @@ GtkWidget*    cc_panel_get_sidebar_widget (CcPanel     *panel);
 
 GCancellable *cc_panel_get_cancellable    (CcPanel     *panel);
 
+gboolean      cc_panel_get_folded         (CcPanel     *panel);
+
 G_END_DECLS
 
diff --git a/shell/cc-window.c b/shell/cc-window.c
index e8fedd44c..6185d2403 100644
--- a/shell/cc-window.c
+++ b/shell/cc-window.c
@@ -35,7 +35,7 @@
 #include <time.h>
 
 #include "cc-application.h"
-#include "cc-panel.h"
+#include "cc-panel-private.h"
 #include "cc-shell.h"
 #include "cc-shell-model.h"
 #include "cc-panel-list.h"
@@ -190,6 +190,7 @@ activate_panel (CcWindow          *self,
   if (self->current_panel)
     g_signal_handlers_disconnect_by_data (self->current_panel, self);
   self->current_panel = GTK_WIDGET (cc_panel_loader_load_by_name (CC_SHELL (self), id, parameters));
+  cc_panel_set_folded (CC_PANEL (self->current_panel), adw_leaflet_get_folded (self->main_leaflet));
   cc_shell_set_active_panel (CC_SHELL (self), CC_PANEL (self->current_panel));
   gtk_widget_show (self->current_panel);
 
@@ -528,15 +529,16 @@ static void
 on_main_leaflet_folded_changed_cb (CcWindow *self)
 {
   GtkSelectionMode selection_mode;
+  gboolean folded;
 
   g_assert (CC_IS_WINDOW (self));
 
-  selection_mode = GTK_SELECTION_SINGLE;
-
-  if (adw_leaflet_get_folded (self->main_leaflet))
-    selection_mode = GTK_SELECTION_NONE;
+  folded = adw_leaflet_get_folded (self->main_leaflet);
 
+  selection_mode = folded ? GTK_SELECTION_NONE : GTK_SELECTION_SINGLE;
   cc_panel_list_set_selection_mode (self->panel_list, selection_mode);
+
+  cc_panel_set_folded (CC_PANEL (self->current_panel), folded);
 }
 
 static void


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