[gnome-builder/wip/gtk4-port: 262/736] libide/gui: add mode to preferences window




commit aa0416c1770d6832bd8ee030e379b09dffadb68b
Author: Christian Hergert <chergert redhat com>
Date:   Thu Mar 31 00:56:21 2022 -0700

    libide/gui: add mode to preferences window
    
    So that we can load addins based on that mode.

 src/libide/gui/ide-preferences-window.c | 74 ++++++++++++++++++++++++++++++++-
 src/libide/gui/ide-preferences-window.h |  9 +++-
 src/libide/gui/libide-gui.h             |  1 +
 src/libide/gui/meson.build              | 20 +++++++++
 src/libide/gui/tests/meson.build        |  3 +-
 src/libide/gui/tests/test-preferences.c |  5 ++-
 6 files changed, 106 insertions(+), 6 deletions(-)
---
diff --git a/src/libide/gui/ide-preferences-window.c b/src/libide/gui/ide-preferences-window.c
index ca8adc1fe..b45330ade 100644
--- a/src/libide/gui/ide-preferences-window.c
+++ b/src/libide/gui/ide-preferences-window.c
@@ -24,12 +24,15 @@
 
 #include <glib/gi18n.h>
 
+#include "ide-gui-enums.h"
 #include "ide-preferences-window.h"
 
 struct _IdePreferencesWindow
 {
   AdwApplicationWindow parent_window;
 
+  IdePreferencesMode mode;
+
   GtkToggleButton    *search_button;
   GtkButton          *back_button;
   GtkStack           *page_stack;
@@ -74,6 +77,14 @@ typedef struct
 
 G_DEFINE_FINAL_TYPE (IdePreferencesWindow, ide_preferences_window, ADW_TYPE_APPLICATION_WINDOW)
 
+enum {
+  PROP_0,
+  PROP_MODE,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
 static gboolean
 drop_page_cb (gpointer data)
 {
@@ -284,13 +295,70 @@ ide_preferences_window_dispose (GObject *object)
   G_OBJECT_CLASS (ide_preferences_window_parent_class)->dispose (object);
 }
 
+static void
+ide_preferences_window_constructed (GObject *object)
+{
+  G_OBJECT_CLASS (ide_preferences_window_parent_class)->constructed (object);
+}
+
+static void
+ide_preferences_window_get_property (GObject    *object,
+                                     guint       prop_id,
+                                     GValue     *value,
+                                     GParamSpec *pspec)
+{
+  IdePreferencesWindow *self = IDE_PREFERENCES_WINDOW (object);
+
+  switch (prop_id)
+    {
+    case PROP_MODE:
+      g_value_set_enum (value, self->mode);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_preferences_window_set_property (GObject      *object,
+                                     guint         prop_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec)
+{
+  IdePreferencesWindow *self = IDE_PREFERENCES_WINDOW (object);
+
+  switch (prop_id)
+    {
+    case PROP_MODE:
+      self->mode = g_value_get_enum (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
 static void
 ide_preferences_window_class_init (IdePreferencesWindowClass *klass)
 {
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->constructed = ide_preferences_window_constructed;
   object_class->dispose = ide_preferences_window_dispose;
+  object_class->get_property = ide_preferences_window_get_property;
+  object_class->set_property = ide_preferences_window_set_property;
+
+  properties [PROP_MODE] =
+    g_param_spec_enum ("mode",
+                       "Mode",
+                       "The mode for the preferences window",
+                       IDE_TYPE_PREFERENCES_MODE,
+                       IDE_PREFERENCES_MODE_EMPTY,
+                       (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | 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-gui/ui/ide-preferences-window.ui");
   gtk_widget_class_bind_template_child (widget_class, IdePreferencesWindow, page_stack);
@@ -316,9 +384,11 @@ ide_preferences_window_init (IdePreferencesWindow *self)
 }
 
 GtkWidget *
-ide_preferences_window_new (void)
+ide_preferences_window_new (IdePreferencesMode mode)
 {
-  return g_object_new (IDE_TYPE_PREFERENCES_WINDOW, NULL);
+  return g_object_new (IDE_TYPE_PREFERENCES_WINDOW,
+                       "mode", mode,
+                       NULL);
 }
 
 static int
diff --git a/src/libide/gui/ide-preferences-window.h b/src/libide/gui/ide-preferences-window.h
index b72eec59a..660fc4b6c 100644
--- a/src/libide/gui/ide-preferences-window.h
+++ b/src/libide/gui/ide-preferences-window.h
@@ -76,13 +76,20 @@ struct _IdePreferenceItemEntry
   gconstpointer user_data;
 };
 
+typedef enum
+{
+  IDE_PREFERENCES_MODE_EMPTY,
+  IDE_PREFERENCES_MODE_APPLICATION,
+  IDE_PREFERENCES_MODE_PROJECT,
+} IdePreferencesMode;
+
 #define IDE_TYPE_PREFERENCES_WINDOW (ide_preferences_window_get_type())
 
 IDE_AVAILABLE_IN_ALL
 G_DECLARE_FINAL_TYPE (IdePreferencesWindow, ide_preferences_window, IDE, PREFERENCES_WINDOW, 
AdwApplicationWindow)
 
 IDE_AVAILABLE_IN_ALL
-GtkWidget *ide_preferences_window_new        (void);
+GtkWidget *ide_preferences_window_new        (IdePreferencesMode            mode);
 IDE_AVAILABLE_IN_ALL
 void       ide_preferences_window_add_pages  (IdePreferencesWindow         *self,
                                               const IdePreferencePageEntry *pages,
diff --git a/src/libide/gui/libide-gui.h b/src/libide/gui/libide-gui.h
index 4bf7d818c..abcea657e 100644
--- a/src/libide/gui/libide-gui.h
+++ b/src/libide/gui/libide-gui.h
@@ -37,6 +37,7 @@
 # include "ide-frame-addin.h"
 # include "ide-header-bar.h"
 # include "ide-grid.h"
+# include "ide-gui-enums.h"
 # include "ide-gui-global.h"
 # include "ide-header-bar.h"
 # include "ide-marked-view.h"
diff --git a/src/libide/gui/meson.build b/src/libide/gui/meson.build
index 7a4756b85..fb800f21f 100644
--- a/src/libide/gui/meson.build
+++ b/src/libide/gui/meson.build
@@ -1,3 +1,4 @@
+libide_gui_header_dir = join_paths(libide_header_dir, 'gui')
 libide_gui_header_subdir = join_paths(libide_header_subdir, 'gui')
 libide_include_directories += include_directories('.')
 
@@ -111,6 +112,25 @@ libide_gui_resources = gnome.compile_resources(
 libide_gui_generated_headers += [libide_gui_resources[1]]
 libide_gui_sources += libide_gui_resources
 
+#
+# Enum generation
+#
+
+libide_gui_enum_headers = [
+  'ide-preferences-window.h',
+]
+
+libide_gui_enums = gnome.mkenums_simple('ide-gui-enums',
+     body_prefix: '#include "config.h"',
+   header_prefix: '#include <libide-core.h>',
+       decorator: '_IDE_EXTERN',
+         sources: libide_gui_enum_headers,
+  install_header: true,
+     install_dir: libide_gui_header_dir,
+)
+libide_gui_generated_headers += [libide_gui_enums[1]]
+libide_gui_sources += [libide_gui_enums[0]]
+
 
 #
 # Dependencies
diff --git a/src/libide/gui/tests/meson.build b/src/libide/gui/tests/meson.build
index 0e82e37e7..3ff374620 100644
--- a/src/libide/gui/tests/meson.build
+++ b/src/libide/gui/tests/meson.build
@@ -1,4 +1,5 @@
 test_preferences = executable('test-preferences',
-  [ 'test-preferences.c', '../ide-preferences-window.c', libide_gui_resources ],
+  [ 'test-preferences.c', '../ide-preferences-window.c', libide_gui_enums, libide_gui_resources ],
   dependencies: [libadwaita_dep, libide_core_dep, libgtksource_dep],
+  include_directories: include_directories('..'),
 )
diff --git a/src/libide/gui/tests/test-preferences.c b/src/libide/gui/tests/test-preferences.c
index 18182787b..49c7e9b44 100644
--- a/src/libide/gui/tests/test-preferences.c
+++ b/src/libide/gui/tests/test-preferences.c
@@ -1,4 +1,5 @@
-#include "../ide-preferences-window.h"
+#include "ide-preferences-window.h"
+#include "ide-gui-enums.h"
 
 #include <glib/gi18n.h>
 #include <gtksourceview/gtksource.h>
@@ -108,7 +109,7 @@ main (int argc,
   gtk_source_init ();
 
   main_loop = g_main_loop_new (NULL, FALSE);
-  window = IDE_PREFERENCES_WINDOW (ide_preferences_window_new ());
+  window = IDE_PREFERENCES_WINDOW (ide_preferences_window_new (IDE_PREFERENCES_MODE_EMPTY));
 
   gtk_window_set_default_size (GTK_WINDOW (window), 1200, 900);
 


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