[gnome-builder] libide/tweaks: start fleshing out tweaks engine



commit 5c100df568d00d8e188c9e80365d05ccdfeb27ef
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jul 29 17:14:58 2022 -0700

    libide/tweaks: start fleshing out tweaks engine
    
    Okay, so the goal here is to make a more descriptive way to do our
    preferences than the madness we have right now. It's just not sustainable
    and I'm sitting here loating the process of going through the rest of them
    and shoehorning them in. So we need something better.
    
    We need a way to describe various things, attach them to settings, and
    somewhat dynamically do so since sub-pages can alter the path to settings
    we might be interested in.
    
    Additionally, we need the ability to merge plugins definitions together
    dynamically like we do for menus.
    
    Also, like popover menus, we want the ability to create widgets on demand
    for where declarative things break down. The light/dark switcher, for
    example, would never work in a declarative manner.
    
    We also want to be able to search for settings nicely and elevate them
    to the global searech provider too for quick tweaking.
    
    Ultimtaely, these will all map to libadwaita preference pages, groups,
    rows, etc. But the "schematic" if you will, will live in auto-merged
    .ui files in plugins.
    
    I'm not going the GMenu route because my quick prototype there seemed to
    indicate I would spend a lot of time working around menu structures. And
    quite frankly, GMenuModel is madness, much like GActionGroup and I already
    have enough pain in that area.

 src/libide/meson.build              |   1 +
 src/libide/tweaks/ide-tweaks-item.c | 137 ++++++++++++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-item.h |  47 +++++++++++++
 src/libide/tweaks/ide-tweaks-page.c | 117 ++++++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-page.h |  41 +++++++++++
 src/libide/tweaks/libide-tweaks.h   |  26 +++++++
 src/libide/tweaks/meson.build       |  59 ++++++++++++++++
 7 files changed, 428 insertions(+)
---
diff --git a/src/libide/meson.build b/src/libide/meson.build
index 6f2eed369..ec5c2e69f 100644
--- a/src/libide/meson.build
+++ b/src/libide/meson.build
@@ -7,6 +7,7 @@ subdir('plugins')
 subdir('threading')
 subdir('io')
 subdir('gtk')
+subdir('tweaks')
 subdir('code')
 subdir('vcs')
 subdir('tree')
diff --git a/src/libide/tweaks/ide-tweaks-item.c b/src/libide/tweaks/ide-tweaks-item.c
new file mode 100644
index 000000000..49cf35417
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-item.c
@@ -0,0 +1,137 @@
+/* ide-tweaks-item.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-item"
+
+#include "config.h"
+
+#include "ide-tweaks-item.h"
+
+typedef struct
+{
+  char **keywords;
+} IdeTweaksItemPrivate;
+
+enum {
+  PROP_0,
+  PROP_KEYWORDS,
+  N_PROPS
+};
+
+G_DEFINE_ABSTRACT_TYPE (IdeTweaksItem, ide_tweaks_item, G_TYPE_OBJECT)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+ide_tweaks_item_finalize (GObject *object)
+{
+  IdeTweaksItem *self = (IdeTweaksItem *)object;
+  IdeTweaksItemPrivate *priv = ide_tweaks_item_get_instance_private (self);
+
+  g_clear_pointer (&priv->keywords, g_strfreev);
+
+  G_OBJECT_CLASS (ide_tweaks_item_parent_class)->finalize (object);
+}
+
+static void
+ide_tweaks_item_get_property (GObject    *object,
+                              guint       prop_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  IdeTweaksItem *self = IDE_TWEAKS_ITEM (object);
+
+  switch (prop_id)
+    {
+    case PROP_KEYWORDS:
+      g_value_set_boxed (value, ide_tweaks_item_get_keywords (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_item_set_property (GObject      *object,
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
+{
+  IdeTweaksItem *self = IDE_TWEAKS_ITEM (object);
+
+  switch (prop_id)
+    {
+    case PROP_KEYWORDS:
+      ide_tweaks_item_set_keywords (self, g_value_get_boxed (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_item_class_init (IdeTweaksItemClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = ide_tweaks_item_finalize;
+  object_class->get_property = ide_tweaks_item_get_property;
+  object_class->set_property = ide_tweaks_item_set_property;
+
+  properties [PROP_KEYWORDS] =
+    g_param_spec_boxed ("keywords", NULL, NULL,
+                        G_TYPE_STRV,
+                        (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ide_tweaks_item_init (IdeTweaksItem *self)
+{
+}
+
+const char * const *
+ide_tweaks_item_get_keywords (IdeTweaksItem *self)
+{
+  IdeTweaksItemPrivate *priv = ide_tweaks_item_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_TWEAKS_ITEM (self), NULL);
+
+  return (const char * const *)priv->keywords;
+}
+
+void
+ide_tweaks_item_set_keywords (IdeTweaksItem      *self,
+                              const char * const *keywords)
+{
+  IdeTweaksItemPrivate *priv = ide_tweaks_item_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_TWEAKS_ITEM (self));
+
+  if (keywords == priv->keywords)
+    return;
+
+  g_strfreev (priv->keywords);
+  priv->keywords = g_strdupv ((char **)keywords);
+  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_KEYWORDS]);
+}
diff --git a/src/libide/tweaks/ide-tweaks-item.h b/src/libide/tweaks/ide-tweaks-item.h
new file mode 100644
index 000000000..88ba5cb3e
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-item.h
@@ -0,0 +1,47 @@
+/* ide-tweaks-item.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 <libide-core.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TWEAKS_ITEM (ide_tweaks_item_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_DERIVABLE_TYPE (IdeTweaksItem, ide_tweaks_item, IDE, TWEAKS_ITEM, GObject)
+
+struct _IdeTweaksItemClass
+{
+  GObjectClass parent_class;
+};
+
+IDE_AVAILABLE_IN_ALL
+const char * const *ide_tweaks_item_get_keywords (IdeTweaksItem      *self);
+IDE_AVAILABLE_IN_ALL
+void                ide_tweaks_item_set_keywords (IdeTweaksItem      *self,
+                                                  const char * const *keywords);
+
+G_END_DECLS
diff --git a/src/libide/tweaks/ide-tweaks-page.c b/src/libide/tweaks/ide-tweaks-page.c
new file mode 100644
index 000000000..6144dfd35
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-page.c
@@ -0,0 +1,117 @@
+/*
+ * ide-tweaks-page.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-page"
+
+#include "config.h"
+
+#include "ide-tweaks-page.h"
+
+struct _IdeTweaksPage
+{
+  IdeTweaksItem parent_instance;
+  char *title;
+};
+
+G_DEFINE_FINAL_TYPE (IdeTweaksPage, ide_tweaks_page, IDE_TYPE_TWEAKS_ITEM)
+
+enum {
+  PROP_0,
+  PROP_TITLE,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+IdeTweaksPage *
+ide_tweaks_page_new (void)
+{
+  return g_object_new (IDE_TYPE_TWEAKS_PAGE, NULL);
+}
+
+static void
+ide_tweaks_page_finalize (GObject *object)
+{
+  IdeTweaksPage *self = (IdeTweaksPage *)object;
+
+  g_clear_pointer (&self->title, g_free);
+
+  G_OBJECT_CLASS (ide_tweaks_page_parent_class)->finalize (object);
+}
+
+static void
+ide_tweaks_page_get_property (GObject    *object,
+                              guint       prop_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  IdeTweaksPage *self = IDE_TWEAKS_PAGE (object);
+
+  switch (prop_id)
+    {
+    case PROP_TITLE:
+      g_value_set_string (value, ide_tweaks_page_get_title (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_page_set_property (GObject      *object,
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
+{
+  IdeTweaksPage *self = IDE_TWEAKS_PAGE (object);
+
+  switch (prop_id)
+    {
+    case PROP_TITLE:
+      ide_tweaks_page_set_title (self, g_value_get_string (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_page_class_init (IdeTweaksPageClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = ide_tweaks_page_finalize;
+  object_class->get_property = ide_tweaks_page_get_property;
+  object_class->set_property = ide_tweaks_page_set_property;
+
+  properties [PROP_TITLE] =
+    g_param_spec_string ("title", NULL, NULL, NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ide_tweaks_page_init (IdeTweaksPage *self)
+{
+}
diff --git a/src/libide/tweaks/ide-tweaks-page.h b/src/libide/tweaks/ide-tweaks-page.h
new file mode 100644
index 000000000..4d2acb32f
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-page.h
@@ -0,0 +1,41 @@
+/*
+ * ide-tweaks-page.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 "ide-tweaks-item.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TWEAKS_PAGE (ide_tweaks_page_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeTweaksPage, ide_tweaks_page, IDE, TWEAKS_PAGE, IdeTweaksItem)
+
+IDE_AVAILABLE_IN_ALL
+IdeTweaksPage *ide_tweaks_page_new       (void);
+IDE_AVAILABLE_IN_ALL
+const char    *ide_tweaks_page_get_title (IdeTweaksPage *self);
+IDE_AVAILABLE_IN_ALL
+void           ide_tweaks_page_set_title (IdeTweaksPage *self,
+                                          const char    *title);
+
+G_END_DECLS
diff --git a/src/libide/tweaks/libide-tweaks.h b/src/libide/tweaks/libide-tweaks.h
new file mode 100644
index 000000000..45d4ceef2
--- /dev/null
+++ b/src/libide/tweaks/libide-tweaks.h
@@ -0,0 +1,26 @@
+/* libide-tweaks.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
+
+#define IDE_TWEAKS_INSIDE
+# include "ide-tweaks-item.h"
+# include "ide-tweaks-page.h"
+#undef IDE_TWEAKS_INSIDE
diff --git a/src/libide/tweaks/meson.build b/src/libide/tweaks/meson.build
new file mode 100644
index 000000000..648161830
--- /dev/null
+++ b/src/libide/tweaks/meson.build
@@ -0,0 +1,59 @@
+libide_tweaks_header_dir = join_paths(libide_header_dir, 'tweaks')
+libide_tweaks_header_subdir = join_paths(libide_header_subdir, 'tweaks')
+libide_include_directories += include_directories('.')
+
+#
+# Public API Headers
+#
+
+libide_tweaks_public_headers = [
+  'libide-tweaks.h',
+  'ide-tweaks-item.h',
+  'ide-tweaks-page.h',
+]
+
+install_headers(libide_tweaks_public_headers, subdir: libide_tweaks_header_subdir)
+
+#
+# Sources
+#
+
+libide_tweaks_public_sources = [
+  'ide-tweaks-item.c',
+  'ide-tweaks-page.c',
+]
+
+libide_tweaks_private_sources = [
+]
+
+#
+# Dependencies
+#
+
+libide_tweaks_deps = [
+  libgio_dep,
+  libgtk_dep,
+
+  libide_core_dep,
+]
+
+#
+# Library Definitions
+#
+
+libide_tweaks = static_library('ide-tweaks-' + libide_api_version,
+   libide_tweaks_public_sources + libide_tweaks_private_sources,
+   dependencies: libide_tweaks_deps,
+         c_args: libide_args + release_args + ['-DIDE_TWEAKS_COMPILATION'],
+)
+
+libide_tweaks_dep = declare_dependency(
+         dependencies: libide_tweaks_deps,
+            link_with: libide_tweaks,
+  include_directories: include_directories('.'),
+)
+
+gnome_builder_public_sources += files(libide_tweaks_public_sources)
+gnome_builder_public_headers += files(libide_tweaks_public_headers)
+gnome_builder_include_subdirs += libide_tweaks_header_subdir
+gnome_builder_gir_extra_args += ['--c-include=libide-tweaks.h', '-DIDE_TWEAKS_COMPILATION']


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