[gnome-builder/wip/gtk4-port] libide/gui: start loading preferences



commit 391d82a2e05e58cfb67fafd5b749f1828cb4ec8c
Author: Christian Hergert <chergert redhat com>
Date:   Thu Mar 31 01:24:11 2022 -0700

    libide/gui: start loading preferences
    
    This adds a new mode so that we can add things to the window based on if
    we want to be in project, application, or empty (used for test app).

 src/libide/gui/ide-application-actions.c |   1 +
 src/libide/gui/ide-preferences-builtin.c |  18 +++++-
 src/libide/gui/ide-preferences-window.c  | 101 +++++++++++++++++++++++++++++++
 src/libide/gui/ide-preferences-window.h  |  54 +++++++++--------
 src/libide/gui/tests/meson.build         |   6 +-
 src/libide/gui/tests/test-preferences.c  |   4 +-
 6 files changed, 148 insertions(+), 36 deletions(-)
---
diff --git a/src/libide/gui/ide-application-actions.c b/src/libide/gui/ide-application-actions.c
index 36f9e560d..44703df23 100644
--- a/src/libide/gui/ide-application-actions.c
+++ b/src/libide/gui/ide-application-actions.c
@@ -72,6 +72,7 @@ ide_application_actions_preferences (GSimpleAction *action,
    * maximize the window if necessary.
    */
   window = g_object_new (IDE_TYPE_PREFERENCES_WINDOW,
+                         "mode", IDE_PREFERENCES_MODE_APPLICATION,
                          "transient-for", toplevel,
                          "default-width", 1300,
                          "default-height", 800,
diff --git a/src/libide/gui/ide-preferences-builtin.c b/src/libide/gui/ide-preferences-builtin.c
index e011495ba..79624b50c 100644
--- a/src/libide/gui/ide-preferences-builtin.c
+++ b/src/libide/gui/ide-preferences-builtin.c
@@ -676,8 +676,20 @@ ide_preferences_builtin_add_languages (IdePreferencesWindow *window)
 void
 _ide_preferences_builtin_register (IdePreferencesWindow *window)
 {
-  ide_preferences_window_add_pages (window, pages, G_N_ELEMENTS (pages), NULL);
-  ide_preferences_window_add_groups (window, groups, G_N_ELEMENTS (groups), NULL);
+  IdePreferencesMode mode;
 
-  ide_preferences_builtin_add_languages (window);
+  g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (window));
+
+  mode = ide_preferences_window_get_mode (window);
+
+  if (mode == IDE_PREFERENCES_MODE_APPLICATION)
+    {
+      ide_preferences_window_add_pages (window, pages, G_N_ELEMENTS (pages), NULL);
+      ide_preferences_window_add_groups (window, groups, G_N_ELEMENTS (groups), NULL);
+
+      ide_preferences_builtin_add_languages (window);
+    }
+  else if (mode == IDE_PREFERENCES_MODE_PROJECT)
+    {
+    }
 }
diff --git a/src/libide/gui/ide-preferences-window.c b/src/libide/gui/ide-preferences-window.c
index b45330ade..78254d737 100644
--- a/src/libide/gui/ide-preferences-window.c
+++ b/src/libide/gui/ide-preferences-window.c
@@ -23,8 +23,12 @@
 #include "config.h"
 
 #include <glib/gi18n.h>
+#include <libpeas/peas.h>
 
 #include "ide-gui-enums.h"
+#include "ide-config-view-addin.h"
+#include "ide-preferences-addin.h"
+#include "ide-preferences-builtin-private.h"
 #include "ide-preferences-window.h"
 
 struct _IdePreferencesWindow
@@ -33,6 +37,8 @@ struct _IdePreferencesWindow
 
   IdePreferencesMode mode;
 
+  PeasExtensionSet *addins;
+
   GtkToggleButton    *search_button;
   GtkButton          *back_button;
   GtkStack           *page_stack;
@@ -269,11 +275,94 @@ search_changed_cb (IdePreferencesWindow *self,
     gtk_list_box_set_filter_func (page->list_box, filter_rows_cb, g_strdup (text), g_free);
 }
 
+static void
+ide_preferences_window_extension_added (PeasExtensionSet *set,
+                                        PeasPluginInfo   *plugin_info,
+                                        PeasExtension    *exten,
+                                        gpointer          user_data)
+{
+  IdePreferencesWindow *self = user_data;
+
+  IDE_ENTRY;
+
+  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (plugin_info != NULL);
+  g_assert (IDE_IS_PREFERENCES_WINDOW (self));
+
+  if (IDE_IS_PREFERENCES_ADDIN (exten))
+    {
+      ide_preferences_addin_load (IDE_PREFERENCES_ADDIN (exten), self);
+      IDE_EXIT;
+    }
+
+  g_assert_not_reached ();
+}
+
+static void
+ide_preferences_window_extension_removed (PeasExtensionSet *set,
+                                          PeasPluginInfo   *plugin_info,
+                                          PeasExtension    *exten,
+                                          gpointer          user_data)
+{
+  IdePreferencesWindow *self = user_data;
+
+  IDE_ENTRY;
+
+  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (plugin_info != NULL);
+  g_assert (IDE_IS_PREFERENCES_WINDOW (self));
+
+  if (IDE_IS_PREFERENCES_ADDIN (exten))
+    {
+      ide_preferences_addin_unload (IDE_PREFERENCES_ADDIN (exten), self);
+      IDE_EXIT;
+    }
+
+  g_assert_not_reached ();
+}
+
+static void
+ide_preferences_window_load_addins (IdePreferencesWindow *self)
+{
+  g_assert (IDE_IS_PREFERENCES_WINDOW (self));
+  g_assert (self->addins == NULL);
+
+  _ide_preferences_builtin_register (self);
+
+  if (self->mode == IDE_PREFERENCES_MODE_APPLICATION)
+    self->addins = peas_extension_set_new (peas_engine_get_default (),
+                                           IDE_TYPE_PREFERENCES_ADDIN,
+                                           NULL);
+  else if (self->mode == IDE_PREFERENCES_MODE_PROJECT)
+    self->addins = peas_extension_set_new (peas_engine_get_default (),
+                                           IDE_TYPE_CONFIG_VIEW_ADDIN,
+                                           NULL);
+
+  if (self->addins == NULL)
+    return;
+
+  g_signal_connect (self->addins,
+                    "extension-added",
+                    G_CALLBACK (ide_preferences_window_extension_added),
+                    self);
+
+  g_signal_connect (self->addins,
+                    "extension-removed",
+                    G_CALLBACK (ide_preferences_window_extension_removed),
+                    self);
+
+  peas_extension_set_foreach (self->addins,
+                              ide_preferences_window_extension_added,
+                              self);
+}
+
 static void
 ide_preferences_window_dispose (GObject *object)
 {
   IdePreferencesWindow *self = (IdePreferencesWindow *)object;
 
+  g_clear_object (&self->addins);
+
   g_clear_pointer (&self->settings, g_hash_table_unref);
   g_clear_handle_id (&self->rebuild_source, g_source_remove);
 
@@ -298,7 +387,11 @@ ide_preferences_window_dispose (GObject *object)
 static void
 ide_preferences_window_constructed (GObject *object)
 {
+  IdePreferencesWindow *self = (IdePreferencesWindow *)object;
+
   G_OBJECT_CLASS (ide_preferences_window_parent_class)->constructed (object);
+
+  ide_preferences_window_load_addins (self);
 }
 
 static void
@@ -923,3 +1016,11 @@ ide_preferences_window_toggle (const char                   *page_name,
 
   g_settings_bind (settings, entry->key, child, "active", G_SETTINGS_BIND_DEFAULT);
 }
+
+IdePreferencesMode
+ide_preferences_window_get_mode (IdePreferencesWindow *self)
+{
+  g_return_val_if_fail (IDE_IS_PREFERENCES_WINDOW (self), 0);
+
+  return self->mode;
+}
diff --git a/src/libide/gui/ide-preferences-window.h b/src/libide/gui/ide-preferences-window.h
index 660fc4b6c..e3cd99ae4 100644
--- a/src/libide/gui/ide-preferences-window.h
+++ b/src/libide/gui/ide-preferences-window.h
@@ -89,37 +89,39 @@ 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        (IdePreferencesMode            mode);
+GtkWidget          *ide_preferences_window_new        (IdePreferencesMode             mode);
 IDE_AVAILABLE_IN_ALL
-void       ide_preferences_window_add_pages  (IdePreferencesWindow         *self,
-                                              const IdePreferencePageEntry *pages,
-                                              gsize                         n_pages,
-                                              const char                   *translation_domain);
+IdePreferencesMode  ide_preferences_window_get_mode   (IdePreferencesWindow          *self);
 IDE_AVAILABLE_IN_ALL
-void       ide_preferences_window_add_groups (IdePreferencesWindow          *self,
-                                              const IdePreferenceGroupEntry *groups,
-                                              gsize                          n_groups,
-                                              const char                   *translation_domain);
+void                ide_preferences_window_add_pages  (IdePreferencesWindow          *self,
+                                                       const IdePreferencePageEntry  *pages,
+                                                       gsize                          n_pages,
+                                                       const char                    *translation_domain);
 IDE_AVAILABLE_IN_ALL
-void       ide_preferences_window_add_items  (IdePreferencesWindow          *self,
-                                              const IdePreferenceItemEntry  *items,
-                                              gsize                          n_items,
-                                              gpointer                       user_data,
-                                              GDestroyNotify                 user_data_destroy);
+void                ide_preferences_window_add_groups (IdePreferencesWindow          *self,
+                                                       const IdePreferenceGroupEntry *groups,
+                                                       gsize                          n_groups,
+                                                       const char                    *translation_domain);
 IDE_AVAILABLE_IN_ALL
-void       ide_preferences_window_add_item   (IdePreferencesWindow          *self,
-                                              const char                    *page,
-                                              const char                    *group,
-                                              const char                    *name,
-                                              int                            priority,
-                                              IdePreferenceCallback          callback,
-                                              gpointer                       user_data,
-                                              GDestroyNotify                 user_data_destroy);
+void                ide_preferences_window_add_items  (IdePreferencesWindow          *self,
+                                                       const IdePreferenceItemEntry  *items,
+                                                       gsize                          n_items,
+                                                       gpointer                       user_data,
+                                                       GDestroyNotify                 user_data_destroy);
 IDE_AVAILABLE_IN_ALL
-void       ide_preferences_window_toggle     (const char                    *page_name,
-                                              const IdePreferenceItemEntry  *entry,
-                                              AdwPreferencesGroup           *group,
-                                              gpointer                       user_data);
+void                ide_preferences_window_add_item   (IdePreferencesWindow          *self,
+                                                       const char                    *page,
+                                                       const char                    *group,
+                                                       const char                    *name,
+                                                       int                            priority,
+                                                       IdePreferenceCallback          callback,
+                                                       gpointer                       user_data,
+                                                       GDestroyNotify                 user_data_destroy);
+IDE_AVAILABLE_IN_ALL
+void                ide_preferences_window_toggle     (const char                    *page_name,
+                                                       const IdePreferenceItemEntry  *entry,
+                                                       AdwPreferencesGroup           *group,
+                                                       gpointer                       user_data);
 
 
 
diff --git a/src/libide/gui/tests/meson.build b/src/libide/gui/tests/meson.build
index 3ff374620..65c9e23c3 100644
--- a/src/libide/gui/tests/meson.build
+++ b/src/libide/gui/tests/meson.build
@@ -1,5 +1,3 @@
-test_preferences = executable('test-preferences',
-  [ '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('..'),
+test_preferences = executable('test-preferences', 'test-preferences.c',
+  dependencies: [libide_gui_dep],
 )
diff --git a/src/libide/gui/tests/test-preferences.c b/src/libide/gui/tests/test-preferences.c
index 49c7e9b44..2922b8e4e 100644
--- a/src/libide/gui/tests/test-preferences.c
+++ b/src/libide/gui/tests/test-preferences.c
@@ -1,8 +1,6 @@
-#include "ide-preferences-window.h"
-#include "ide-gui-enums.h"
-
 #include <glib/gi18n.h>
 #include <gtksourceview/gtksource.h>
+#include <libide-gui.h>
 
 static void create_source_view_cb (const char                   *page,
                                    const IdePreferenceItemEntry *item,


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