[gnome-builder] libide/tweaks: add scaffolding for IdeTweaksWindow



commit 2171183c5e51a5a43653fbf67929a331c7743a8d
Author: Christian Hergert <chergert redhat com>
Date:   Sun Jul 31 13:35:54 2022 -0700

    libide/tweaks: add scaffolding for IdeTweaksWindow
    
    This is just a landing spot for what will be the tweaks window which can
    process and transform IdeTweaks object graphs into widgetry.

 src/libide/tweaks/ide-tweaks-init.c           |   4 +
 src/libide/tweaks/ide-tweaks-window.c         | 149 ++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-window.h         |  49 +++++++++
 src/libide/tweaks/ide-tweaks-window.ui        |   5 +
 src/libide/tweaks/ide-tweaks.h                |   4 +
 src/libide/tweaks/libide-tweaks.gresource.xml |   6 ++
 src/libide/tweaks/libide-tweaks.h             |   1 +
 src/libide/tweaks/meson.build                 |  15 ++-
 8 files changed, 232 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-init.c b/src/libide/tweaks/ide-tweaks-init.c
index f4d2bfe0a..cd4839afa 100644
--- a/src/libide/tweaks/ide-tweaks-init.c
+++ b/src/libide/tweaks/ide-tweaks-init.c
@@ -25,10 +25,13 @@
 #include "libide-tweaks.h"
 
 #include "ide-tweaks-init.h"
+#include "ide-tweaks-resources.h"
 
 void
 _ide_tweaks_init (void)
 {
+  g_resources_register (ide_tweaks_get_resource ());
+
   g_type_ensure (IDE_TYPE_TWEAKS);
   g_type_ensure (IDE_TYPE_TWEAKS_CUSTOM);
   g_type_ensure (IDE_TYPE_TWEAKS_GROUP);
@@ -38,4 +41,5 @@ _ide_tweaks_init (void)
   g_type_ensure (IDE_TYPE_TWEAKS_SUBPAGE);
   g_type_ensure (IDE_TYPE_TWEAKS_SUBPAGE_FACTORY);
   g_type_ensure (IDE_TYPE_TWEAKS_VARIABLE);
+  g_type_ensure (IDE_TYPE_TWEAKS_WINDOW);
 }
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
new file mode 100644
index 000000000..57791c55f
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -0,0 +1,149 @@
+/* ide-tweaks-window.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-window"
+
+#include "config.h"
+
+#include "ide-tweaks-window.h"
+
+struct _IdeTweaksWindow
+{
+  AdwWindow  parent_instance;
+  IdeTweaks *tweaks;
+};
+
+enum {
+  PROP_0,
+  PROP_TWEAKS,
+  N_PROPS
+};
+
+G_DEFINE_FINAL_TYPE (IdeTweaksWindow, ide_tweaks_window, ADW_TYPE_WINDOW)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+ide_tweaks_window_dispose (GObject *object)
+{
+  IdeTweaksWindow *self = (IdeTweaksWindow *)object;
+
+  g_clear_object (&self->tweaks);
+
+  G_OBJECT_CLASS (ide_tweaks_window_parent_class)->dispose (object);
+}
+
+static void
+ide_tweaks_window_get_property (GObject    *object,
+                                guint       prop_id,
+                                GValue     *value,
+                                GParamSpec *pspec)
+{
+  IdeTweaksWindow *self = IDE_TWEAKS_WINDOW (object);
+
+  switch (prop_id)
+    {
+    case PROP_TWEAKS:
+      g_value_set_object (value, ide_tweaks_window_get_tweaks (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_window_set_property (GObject      *object,
+                                guint         prop_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+  IdeTweaksWindow *self = IDE_TWEAKS_WINDOW (object);
+
+  switch (prop_id)
+    {
+    case PROP_TWEAKS:
+      ide_tweaks_window_set_tweaks (self, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_window_class_init (IdeTweaksWindowClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->dispose = ide_tweaks_window_dispose;
+  object_class->get_property = ide_tweaks_window_get_property;
+  object_class->set_property = ide_tweaks_window_set_property;
+
+  properties [PROP_TWEAKS] =
+    g_param_spec_object ("tweaks", NULL, NULL,
+                         IDE_TYPE_TWEAKS,
+                         (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-window.ui");
+}
+
+static void
+ide_tweaks_window_init (IdeTweaksWindow *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+/**
+ * ide_tweaks_window_get_tweaks:
+ * @self: a #IdeTweaksWindow
+ *
+ * Gets the tweaks property of the window.
+ *
+ * Returns: (transfer none) (nullable): an #IdeTweaks or %NULL
+ */
+IdeTweaks *
+ide_tweaks_window_get_tweaks (IdeTweaksWindow *self)
+{
+  g_return_val_if_fail (IDE_IS_TWEAKS_WINDOW (self), NULL);
+
+  return self->tweaks;
+}
+
+/**
+ * ide_tweaks_window_set_tweaks:
+ * @self: a #IdeTweaksWindow
+ * @tweaks: (nullable): an #IdeTweaks
+ *
+ * Sets the tweaks to be displayed in the window.
+ */
+void
+ide_tweaks_window_set_tweaks (IdeTweaksWindow *self,
+                              IdeTweaks       *tweaks)
+{
+  g_return_if_fail (IDE_IS_TWEAKS_WINDOW (self));
+  g_return_if_fail (!tweaks || IDE_IS_TWEAKS (tweaks));
+
+  if (g_set_object (&self->tweaks, tweaks))
+    g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TWEAKS]);
+}
diff --git a/src/libide/tweaks/ide-tweaks-window.h b/src/libide/tweaks/ide-tweaks-window.h
new file mode 100644
index 000000000..4bb96360b
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-window.h
@@ -0,0 +1,49 @@
+/* ide-tweaks-window.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
+
+#if !defined (IDE_TWEAKS_INSIDE) && !defined (IDE_TWEAKS_COMPILATION)
+# error "Only <libide-tweaks.h> can be included directly."
+#endif
+
+#include <adwaita.h>
+
+#include "ide-tweaks.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TWEAKS_WINDOW (ide_tweaks_window_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeTweaksWindow, ide_tweaks_window, IDE, TWEAKS_WINDOW, AdwWindow)
+
+IDE_AVAILABLE_IN_ALL
+GtkWidget *ide_tweaks_window_new         (void);
+IDE_AVAILABLE_IN_ALL
+IdeTweaks *ide_tweaks_window_get_tweaks  (IdeTweaksWindow *self);
+IDE_AVAILABLE_IN_ALL
+void       ide_tweaks_window_set_tweaks  (IdeTweaksWindow *self,
+                                          IdeTweaks       *tweaks);
+IDE_AVAILABLE_IN_ALL
+void       ide_tweaks_window_navigate_to (IdeTweaksWindow *self,
+                                          IdeTweaksItem   *item);
+
+G_END_DECLS
diff --git a/src/libide/tweaks/ide-tweaks-window.ui b/src/libide/tweaks/ide-tweaks-window.ui
new file mode 100644
index 000000000..749066f43
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-window.ui
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="IdeTweaksWindow" parent="AdwWindow">
+  </template>
+</interface>
diff --git a/src/libide/tweaks/ide-tweaks.h b/src/libide/tweaks/ide-tweaks.h
index 37bb5aa44..7f1a1b372 100644
--- a/src/libide/tweaks/ide-tweaks.h
+++ b/src/libide/tweaks/ide-tweaks.h
@@ -20,6 +20,10 @@
 
 #pragma once
 
+#if !defined (IDE_TWEAKS_INSIDE) && !defined (IDE_TWEAKS_COMPILATION)
+# error "Only <libide-tweaks.h> can be included directly."
+#endif
+
 #include "ide-tweaks-item.h"
 
 G_BEGIN_DECLS
diff --git a/src/libide/tweaks/libide-tweaks.gresource.xml b/src/libide/tweaks/libide-tweaks.gresource.xml
new file mode 100644
index 000000000..05f497189
--- /dev/null
+++ b/src/libide/tweaks/libide-tweaks.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/libide-tweaks">
+    <file preprocess="xml-stripblanks">ide-tweaks-window.ui</file>
+  </gresource>
+</gresources>
diff --git a/src/libide/tweaks/libide-tweaks.h b/src/libide/tweaks/libide-tweaks.h
index 7040a5e73..7958831f9 100644
--- a/src/libide/tweaks/libide-tweaks.h
+++ b/src/libide/tweaks/libide-tweaks.h
@@ -30,4 +30,5 @@
 # include "ide-tweaks-subpage.h"
 # include "ide-tweaks-subpage-factory.h"
 # include "ide-tweaks-variable.h"
+# include "ide-tweaks-window.h"
 #undef IDE_TWEAKS_INSIDE
diff --git a/src/libide/tweaks/meson.build b/src/libide/tweaks/meson.build
index b23c68e1b..1cd9f30e7 100644
--- a/src/libide/tweaks/meson.build
+++ b/src/libide/tweaks/meson.build
@@ -17,6 +17,7 @@ libide_tweaks_public_headers = [
   'ide-tweaks-subpage.h',
   'ide-tweaks-subpage-factory.h',
   'ide-tweaks-variable.h',
+  'ide-tweaks-window.h',
 ]
 
 install_headers(libide_tweaks_public_headers, subdir: libide_tweaks_header_subdir)
@@ -35,12 +36,23 @@ libide_tweaks_public_sources = [
   'ide-tweaks-subpage.c',
   'ide-tweaks-subpage-factory.c',
   'ide-tweaks-variable.c',
+  'ide-tweaks-window.c',
 ]
 
 libide_tweaks_private_sources = [
   'ide-tweaks-init.c',
 ]
 
+#
+# Generated Resource Files
+#
+
+libide_tweaks_resources = gnome.compile_resources(
+  'ide-tweaks-resources',
+  'libide-tweaks.gresource.xml',
+  c_name: 'ide_tweaks',
+)
+
 #
 # Dependencies
 #
@@ -48,6 +60,7 @@ libide_tweaks_private_sources = [
 libide_tweaks_deps = [
   libgio_dep,
   libgtk_dep,
+  libadwaita_dep,
 
   libide_core_dep,
 ]
@@ -57,7 +70,7 @@ libide_tweaks_deps = [
 #
 
 libide_tweaks = static_library('ide-tweaks-' + libide_api_version,
-   libide_tweaks_public_sources + libide_tweaks_private_sources,
+   libide_tweaks_public_sources + libide_tweaks_private_sources + libide_tweaks_resources,
    dependencies: libide_tweaks_deps,
          c_args: libide_args + release_args + ['-DIDE_TWEAKS_COMPILATION'],
 )


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