[gnome-builder/wip/gtk4-port: 660/736] libide/gui: setup preferences window for project options




commit ba29ea3b797bb499347733fec83aecafbf5b3427
Author: Christian Hergert <chergert redhat com>
Date:   Tue Apr 19 17:41:45 2022 -0700

    libide/gui: setup preferences window for project options
    
    The goal here is to allow plugins to have overrides for projects as well
    as having the projects configurations. All of that still needs to be
    done of course.

 src/libide/gui/gtk/menus.ui              |   2 +-
 src/libide/gui/ide-preferences-builtin.c |   5 ++
 src/libide/gui/ide-preferences-window.c  | 111 ++++++++++++++++++++-----------
 src/libide/gui/ide-workbench.c           |  45 +++++++++++++
 4 files changed, 123 insertions(+), 40 deletions(-)
---
diff --git a/src/libide/gui/gtk/menus.ui b/src/libide/gui/gtk/menus.ui
index 4a579fd25..a4c7f5466 100644
--- a/src/libide/gui/gtk/menus.ui
+++ b/src/libide/gui/gtk/menus.ui
@@ -57,7 +57,7 @@
       </submenu>
       <item>
         <attribute name="label" translatable="yes">Configure Project…</attribute>
-        <attribute name="action">buildui.configure</attribute>
+        <attribute name="action">workbench.configure</attribute>
       </item>
     </section>
     <section id="build-menu-target">
diff --git a/src/libide/gui/ide-preferences-builtin.c b/src/libide/gui/ide-preferences-builtin.c
index ab40d0680..10a0a548f 100644
--- a/src/libide/gui/ide-preferences-builtin.c
+++ b/src/libide/gui/ide-preferences-builtin.c
@@ -664,6 +664,10 @@ static const IdePreferencePageEntry pages[] = {
   { NULL, "plugins",  "plugins",    "org.gnome.Builder-plugins-symbolic",     700, N_("Plugins") },
 };
 
+static const IdePreferencePageEntry project_pages[] = {
+  { NULL, "code",     "languages",  "org.gnome.Builder-languages-symbolic",   100, N_("Languages") },
+};
+
 static const IdePreferenceGroupEntry groups[] = {
   { "appearance", "style",                  0, N_("Appearance") },
   { "appearance", "interface",           1000, N_("Interface") },
@@ -781,5 +785,6 @@ _ide_preferences_builtin_register (IdePreferencesWindow *window)
     }
   else if (mode == IDE_PREFERENCES_MODE_PROJECT)
     {
+      ide_preferences_window_add_pages (window, project_pages, G_N_ELEMENTS (project_pages), NULL);
     }
 }
diff --git a/src/libide/gui/ide-preferences-window.c b/src/libide/gui/ide-preferences-window.c
index 0b0babe63..c5e17d6df 100644
--- a/src/libide/gui/ide-preferences-window.c
+++ b/src/libide/gui/ide-preferences-window.c
@@ -23,13 +23,15 @@
 #include "config.h"
 
 #include <glib/gi18n.h>
-#include <libpeas/peas.h>
+
+#include <libide-plugins.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"
+#include "ide-workbench.h"
 
 struct _IdePreferencesWindow
 {
@@ -37,7 +39,7 @@ struct _IdePreferencesWindow
 
   IdePreferencesMode mode;
 
-  PeasExtensionSet *addins;
+  IdeExtensionSetAdapter *addins;
 
   GtkToggleButton    *search_button;
   GtkButton          *back_button;
@@ -281,49 +283,43 @@ search_changed_cb (IdePreferencesWindow *self,
 }
 
 static void
-ide_preferences_window_extension_added (PeasExtensionSet *set,
-                                        PeasPluginInfo   *plugin_info,
-                                        PeasExtension    *exten,
-                                        gpointer          user_data)
+ide_preferences_window_extension_added (IdeExtensionSetAdapter *set,
+                                        PeasPluginInfo         *plugin_info,
+                                        PeasExtension          *exten,
+                                        gpointer                user_data)
 {
   IdePreferencesWindow *self = user_data;
 
   IDE_ENTRY;
 
-  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (IDE_IS_EXTENSION_SET_ADAPTER (set));
   g_assert (plugin_info != NULL);
   g_assert (IDE_IS_PREFERENCES_WINDOW (self));
+  g_assert (IDE_IS_PREFERENCES_ADDIN (exten));
 
-  if (IDE_IS_PREFERENCES_ADDIN (exten))
-    {
-      ide_preferences_addin_load (IDE_PREFERENCES_ADDIN (exten), self);
-      IDE_EXIT;
-    }
+  ide_preferences_addin_load (IDE_PREFERENCES_ADDIN (exten), self);
 
-  g_assert_not_reached ();
+  IDE_EXIT;
 }
 
 static void
-ide_preferences_window_extension_removed (PeasExtensionSet *set,
-                                          PeasPluginInfo   *plugin_info,
-                                          PeasExtension    *exten,
-                                          gpointer          user_data)
+ide_preferences_window_extension_removed (IdeExtensionSetAdapter *set,
+                                          PeasPluginInfo         *plugin_info,
+                                          PeasExtension          *exten,
+                                          gpointer                user_data)
 {
   IdePreferencesWindow *self = user_data;
 
   IDE_ENTRY;
 
-  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (IDE_IS_EXTENSION_SET_ADAPTER (set));
   g_assert (plugin_info != NULL);
   g_assert (IDE_IS_PREFERENCES_WINDOW (self));
+  g_assert (IDE_IS_PREFERENCES_ADDIN (exten));
 
-  if (IDE_IS_PREFERENCES_ADDIN (exten))
-    {
-      ide_preferences_addin_unload (IDE_PREFERENCES_ADDIN (exten), self);
-      IDE_EXIT;
-    }
+  ide_preferences_addin_unload (IDE_PREFERENCES_ADDIN (exten), self);
 
-  g_assert_not_reached ();
+  IDE_EXIT;
 }
 
 static void
@@ -335,13 +331,26 @@ ide_preferences_window_load_addins (IdePreferencesWindow *self)
   _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);
+    {
+      self->addins = ide_extension_set_adapter_new (NULL,
+                                                    peas_engine_get_default (),
+                                                    IDE_TYPE_PREFERENCES_ADDIN,
+                                                    "Preferences-Kind", "application");
+    }
   else if (self->mode == IDE_PREFERENCES_MODE_PROJECT)
-    self->addins = peas_extension_set_new (peas_engine_get_default (),
-                                           IDE_TYPE_CONFIG_VIEW_ADDIN,
-                                           NULL);
+    {
+      IdeWorkbench *workbench = IDE_WORKBENCH (gtk_window_get_group (GTK_WINDOW (self)));
+      IdeContext *context = ide_workbench_get_context (workbench);
+
+      self->addins = ide_extension_set_adapter_new (IDE_OBJECT (context),
+                                                    peas_engine_get_default (),
+                                                    IDE_TYPE_PREFERENCES_ADDIN,
+                                                    "Preferences-Kind", "project");
+
+      /* TODO: This also needs configurations, but that could be under a page
+       *       if we wanted to.
+       */
+    }
 
   if (self->addins == NULL)
     return;
@@ -356,9 +365,9 @@ ide_preferences_window_load_addins (IdePreferencesWindow *self)
                     G_CALLBACK (ide_preferences_window_extension_removed),
                     self);
 
-  peas_extension_set_foreach (self->addins,
-                              ide_preferences_window_extension_added,
-                              self);
+  ide_extension_set_adapter_foreach (self->addins,
+                                     ide_preferences_window_extension_added,
+                                     self);
 }
 
 static void
@@ -366,7 +375,7 @@ ide_preferences_window_dispose (GObject *object)
 {
   IdePreferencesWindow *self = (IdePreferencesWindow *)object;
 
-  g_clear_object (&self->addins);
+  ide_clear_and_destroy_object (&self->addins);
 
   g_clear_pointer (&self->settings, g_hash_table_unref);
   g_clear_handle_id (&self->rebuild_source, g_source_remove);
@@ -390,13 +399,16 @@ ide_preferences_window_dispose (GObject *object)
 }
 
 static void
-ide_preferences_window_constructed (GObject *object)
+ide_preferences_window_show (GtkWidget *widget)
 {
-  IdePreferencesWindow *self = (IdePreferencesWindow *)object;
+  IdePreferencesWindow *self = (IdePreferencesWindow *)widget;
 
-  G_OBJECT_CLASS (ide_preferences_window_parent_class)->constructed (object);
+  g_assert (IDE_IS_PREFERENCES_WINDOW (self));
+
+  if (self->addins == NULL)
+    ide_preferences_window_load_addins (self);
 
-  ide_preferences_window_load_addins (self);
+  GTK_WIDGET_CLASS (ide_preferences_window_parent_class)->show (widget);
 }
 
 static void
@@ -443,11 +455,12 @@ 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;
 
+  widget_class->show = ide_preferences_window_show;
+
   properties [PROP_MODE] =
     g_param_spec_enum ("mode",
                        "Mode",
@@ -642,11 +655,29 @@ group_is_empty (AdwPreferencesGroup *group)
          gtk_widget_get_last_child (listbox_box) == listbox;
 }
 
+static char *
+get_project_title (IdePreferencesWindow *self)
+{
+  IdeWorkbench *workbench;
+  IdeContext *context;
+
+  g_assert (IDE_IS_PREFERENCES_WINDOW (self));
+
+  if (self->mode != IDE_PREFERENCES_MODE_PROJECT)
+    return NULL;
+
+  workbench = IDE_WORKBENCH (gtk_window_get_group (GTK_WINDOW (self)));
+  context = ide_workbench_get_context (workbench);
+
+  return ide_context_dup_title (context);
+}
+
 static void
 ide_preferences_window_page_activated_cb (IdePreferencesWindow *self,
                                           GtkListBoxRow        *row,
                                           GtkListBox           *list_box)
 {
+  g_autofree char *project_title = NULL;
   const IdePreferencePageEntry *entry;
   const IdePreferencePageEntry *parent;
   AdwPreferencesPage *page;
@@ -669,6 +700,8 @@ ide_preferences_window_page_activated_cb (IdePreferencesWindow *self,
 
   if (parent != NULL)
     adw_window_title_set_title (self->pages_title, parent->title);
+  else if ((project_title = get_project_title (self)))
+    adw_window_title_set_title (self->pages_title, project_title);
   else
     adw_window_title_set_title (self->pages_title, _("Preferences"));
 
diff --git a/src/libide/gui/ide-workbench.c b/src/libide/gui/ide-workbench.c
index 1ff3d3687..e10eb6ae3 100644
--- a/src/libide/gui/ide-workbench.c
+++ b/src/libide/gui/ide-workbench.c
@@ -38,6 +38,7 @@
 
 #include "ide-application.h"
 #include "ide-gui-global.h"
+#include "ide-preferences-window.h"
 #include "ide-primary-workspace.h"
 #include "ide-workbench-addin.h"
 #include "ide-workbench-private.h"
@@ -126,12 +127,15 @@ static void ide_workbench_action_reload_all    (IdeWorkbench *self,
                                                 GVariant     *param);
 static void ide_workbench_action_global_search (IdeWorkbench *self,
                                                 GVariant     *param);
+static void ide_workbench_action_configure     (IdeWorkbench *self,
+                                                GVariant     *param);
 
 IDE_DEFINE_ACTION_GROUP (IdeWorkbench, ide_workbench, {
   { "close", ide_workbench_action_close },
   { "open", ide_workbench_action_open },
   { "reload-files", ide_workbench_action_reload_all },
   { "global-search", ide_workbench_action_global_search },
+  { "configure", ide_workbench_action_configure },
   { "-inspector", ide_workbench_action_inspector },
   { "-object-tree", ide_workbench_action_object_tree },
   { "-dump-tasks", ide_workbench_action_dump_tasks },
@@ -495,6 +499,7 @@ ide_workbench_class_init (IdeWorkbenchClass *klass)
 static void
 ide_workbench_init (IdeWorkbench *self)
 {
+  ide_workbench_set_action_enabled (self, "configure", FALSE);
 }
 
 static void
@@ -1000,6 +1005,9 @@ ide_workbench_load_project_completed (IdeWorkbench *self,
   build_manager = ide_build_manager_from_context (self->context);
   _ide_build_manager_start (build_manager);
 
+  /* Enable actions that are available to projects */
+  ide_workbench_set_action_enabled (self, "configure", TRUE);
+
   ide_task_return_boolean (task, TRUE);
 }
 
@@ -2602,3 +2610,40 @@ ide_workbench_resolve_file_finish (IdeWorkbench  *self,
 
   IDE_RETURN (g_steal_pointer (&ret));
 }
+
+static void
+ide_workbench_action_configure (IdeWorkbench *self,
+                                GVariant     *param)
+{
+  GtkWindow *window;
+  GList *windows;
+  gboolean found = FALSE;
+
+  g_assert (IDE_IS_WORKBENCH (self));
+
+  windows = gtk_window_group_list_windows (GTK_WINDOW_GROUP (self));
+
+  for (const GList *iter = windows; iter; iter = iter->next)
+    {
+      window = iter->data;
+
+      if (IDE_IS_PREFERENCES_WINDOW (window) &&
+          ide_preferences_window_get_mode (IDE_PREFERENCES_WINDOW (window)) == IDE_PREFERENCES_MODE_PROJECT)
+        {
+          gtk_window_present (window);
+          found = TRUE;
+          break;
+        }
+    }
+
+  g_list_free (windows);
+
+  if (!found)
+    {
+      window = g_object_new (IDE_TYPE_PREFERENCES_WINDOW,
+                             "mode", IDE_PREFERENCES_MODE_PROJECT,
+                             NULL);
+      gtk_window_group_add_window (GTK_WINDOW_GROUP (self), window);
+      gtk_window_present (window);
+    }
+}


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