[gnome-builder] libide/tweaks: add IdeTweaksPanel



commit 4b4841683b8a0d6288225e95271f6a1153426324
Author: Christian Hergert <chergert redhat com>
Date:   Mon Aug 1 16:54:57 2022 -0700

    libide/tweaks: add IdeTweaksPanel
    
    This is meant to represent the right side of the window contents, like
    CcPanel in g-c-c. I haven't decided if we'll subclass for some internal
    things or not, but I want to leave that an option for splash pages or
    similar should we need them.

 src/libide/tweaks/ide-tweaks-panel-private.h  |  42 ++++++
 src/libide/tweaks/ide-tweaks-panel.c          | 179 ++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-panel.ui         |  43 +++++++
 src/libide/tweaks/ide-tweaks-window.c         |   3 +
 src/libide/tweaks/ide-tweaks-window.ui        |   7 +
 src/libide/tweaks/libide-tweaks.gresource.xml |   1 +
 src/libide/tweaks/meson.build                 |   1 +
 7 files changed, 276 insertions(+)
---
diff --git a/src/libide/tweaks/ide-tweaks-panel-private.h b/src/libide/tweaks/ide-tweaks-panel-private.h
new file mode 100644
index 000000000..c5b262947
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-panel-private.h
@@ -0,0 +1,42 @@
+/* ide-tweaks-panel-private.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * 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 3 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <adwaita.h>
+
+#include "ide-tweaks-item.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TWEAKS_PANEL (ide_tweaks_panel_get_type())
+
+G_DECLARE_DERIVABLE_TYPE (IdeTweaksPanel, ide_tweaks_panel, IDE, TWEAKS_PANEL, AdwBin)
+
+struct _IdeTweaksPanelClass
+{
+  AdwBinClass parent_class;
+};
+
+IdeTweaksItem *ide_tweaks_panel_get_item   (IdeTweaksPanel *self);
+gboolean       ide_tweaks_panel_get_folded (IdeTweaksPanel *self);
+const char    *ide_tweaks_panel_get_title  (IdeTweaksPanel *self);
+
+G_END_DECLS
diff --git a/src/libide/tweaks/ide-tweaks-panel.c b/src/libide/tweaks/ide-tweaks-panel.c
new file mode 100644
index 000000000..0127bbe42
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-panel.c
@@ -0,0 +1,179 @@
+/* ide-tweaks-panel.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * 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 3 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-tweaks-panel"
+
+#include "config.h"
+
+#include "ide-tweaks-panel-private.h"
+
+typedef struct
+{
+  IdeTweaksItem *item;
+  char *title;
+  guint folded : 1;
+} IdeTweaksPanelPrivate;
+
+enum {
+  PROP_0,
+  PROP_FOLDED,
+  PROP_ITEM,
+  PROP_TITLE,
+  N_PROPS
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (IdeTweaksPanel, ide_tweaks_panel, ADW_TYPE_BIN)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+ide_tweaks_panel_set_item (IdeTweaksPanel *self,
+                           IdeTweaksItem  *item)
+{
+  IdeTweaksPanelPrivate *priv = ide_tweaks_panel_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_TWEAKS_PANEL (self));
+  g_return_if_fail (!item || IDE_IS_TWEAKS_ITEM (item));
+
+  g_set_object (&priv->item, item);
+}
+
+static void
+ide_tweaks_panel_dispose (GObject *object)
+{
+  IdeTweaksPanel *self = (IdeTweaksPanel *)object;
+  IdeTweaksPanelPrivate *priv = ide_tweaks_panel_get_instance_private (self);
+
+  g_clear_object (&priv->item);
+
+  G_OBJECT_CLASS (ide_tweaks_panel_parent_class)->dispose (object);
+}
+
+static void
+ide_tweaks_panel_get_property (GObject    *object,
+                               guint       prop_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  IdeTweaksPanel *self = IDE_TWEAKS_PANEL (object);
+
+  switch (prop_id)
+    {
+    case PROP_FOLDED:
+      g_value_set_boolean (value, ide_tweaks_panel_get_folded (self));
+      break;
+
+    case PROP_ITEM:
+      g_value_set_object (value, ide_tweaks_panel_get_item (self));
+      break;
+
+    case PROP_TITLE:
+      g_value_set_string (value, ide_tweaks_panel_get_title (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_panel_set_property (GObject      *object,
+                               guint         prop_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
+{
+  IdeTweaksPanel *self = IDE_TWEAKS_PANEL (object);
+
+  switch (prop_id)
+    {
+    case PROP_ITEM:
+      ide_tweaks_panel_set_item (self, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_panel_class_init (IdeTweaksPanelClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->dispose = ide_tweaks_panel_dispose;
+  object_class->get_property = ide_tweaks_panel_get_property;
+  object_class->set_property = ide_tweaks_panel_set_property;
+
+  properties[PROP_FOLDED] =
+    g_param_spec_boolean ("folded", NULL, NULL,
+                         FALSE,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  properties[PROP_ITEM] =
+    g_param_spec_object ("item", NULL, NULL,
+                         IDE_TYPE_TWEAKS_ITEM,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  properties[PROP_TITLE] =
+    g_param_spec_string ("title", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READABLE | 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.ui");
+}
+
+static void
+ide_tweaks_panel_init (IdeTweaksPanel *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+IdeTweaksItem *
+ide_tweaks_panel_get_item (IdeTweaksPanel *self)
+{
+  IdeTweaksPanelPrivate *priv = ide_tweaks_panel_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_TWEAKS_PANEL (self), NULL);
+
+  return priv->item;
+}
+
+const char *
+ide_tweaks_panel_get_title (IdeTweaksPanel *self)
+{
+  IdeTweaksPanelPrivate *priv = ide_tweaks_panel_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_TWEAKS_PANEL (self), NULL);
+
+  return priv->title;
+}
+
+gboolean
+ide_tweaks_panel_get_folded (IdeTweaksPanel *self)
+{
+  IdeTweaksPanelPrivate *priv = ide_tweaks_panel_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_TWEAKS_PANEL (self), FALSE);
+
+  return priv->folded;
+}
diff --git a/src/libide/tweaks/ide-tweaks-panel.ui b/src/libide/tweaks/ide-tweaks-panel.ui
new file mode 100644
index 000000000..f45fd6ddb
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-panel.ui
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="IdeTweaksPanel" parent="AdwBin">
+    <child>
+      <object class="GtkBox">
+        <property name="hexpand">true</property>
+        <property name="vexpand">true</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="AdwBin">
+            <property name="hexpand">true</property>
+            <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"/>
+                <child type="start">
+                  <object class="GtkButton">
+                    <property name="visible" bind-source="IdeTweaksPanel" bind-property="folded" 
bind-flags="default|sync-create"/>
+                    <property name="icon-name">go-previous-symbolic</property>
+                    <property name="action-name">window.navigate</property>
+                    <property name="action-target">0</property>
+                  </object>
+                </child>
+                <property name="title-widget">
+                  <object class="AdwWindowTitle">
+                    <property name="title" bind-source="IdeTweaksPanel" bind-property="title" 
bind-flags="default|sync-create"/>
+                  </object>
+                </property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="AdwBin" id="content">
+            <property name="hexpand">true</property>
+            <property name="vexpand">true</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
+
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
index c880089c5..873eb12b4 100644
--- a/src/libide/tweaks/ide-tweaks-window.c
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -22,6 +22,7 @@
 
 #include "config.h"
 
+#include "ide-tweaks-panel-private.h"
 #include "ide-tweaks-window.h"
 
 struct _IdeTweaksWindow
@@ -106,6 +107,8 @@ ide_tweaks_window_class_init (IdeTweaksWindowClass *klass)
   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-window.ui");
+
+  g_type_ensure (IDE_TYPE_TWEAKS_PANEL);
 }
 
 static void
diff --git a/src/libide/tweaks/ide-tweaks-window.ui b/src/libide/tweaks/ide-tweaks-window.ui
index 22e44ee30..535738505 100644
--- a/src/libide/tweaks/ide-tweaks-window.ui
+++ b/src/libide/tweaks/ide-tweaks-window.ui
@@ -114,6 +114,13 @@
                 <style>
                   <class name="background"/>
                 </style>
+                <child>
+                  <object class="GtkStackPage">
+                    <property name="child">
+                      <object class="IdeTweaksPanel"/>
+                    </property>
+                  </object>
+                </child>
               </object>
             </child>
           </object>
diff --git a/src/libide/tweaks/libide-tweaks.gresource.xml b/src/libide/tweaks/libide-tweaks.gresource.xml
index 05f497189..3703ace42 100644
--- a/src/libide/tweaks/libide-tweaks.gresource.xml
+++ b/src/libide/tweaks/libide-tweaks.gresource.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/org/gnome/libide-tweaks">
+    <file preprocess="xml-stripblanks">ide-tweaks-panel.ui</file>
     <file preprocess="xml-stripblanks">ide-tweaks-window.ui</file>
   </gresource>
 </gresources>
diff --git a/src/libide/tweaks/meson.build b/src/libide/tweaks/meson.build
index 1cd9f30e7..880d48fa3 100644
--- a/src/libide/tweaks/meson.build
+++ b/src/libide/tweaks/meson.build
@@ -41,6 +41,7 @@ libide_tweaks_public_sources = [
 
 libide_tweaks_private_sources = [
   'ide-tweaks-init.c',
+  'ide-tweaks-panel.c',
 ]
 
 #


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