[gnome-builder/wip/gtk4-port] gui: port IdeApplication core object to GTK 4



commit 4d8871475c9ba571788993e5ac8585ecff01467a
Author: Christian Hergert <chergert redhat com>
Date:   Fri Sep 24 14:11:03 2021 -0700

    gui: port IdeApplication core object to GTK 4
    
    This doesn't get the accessories (-shortcuts, -actions, etc) but just the
    ide-application.c to compile.

 src/libide/gui/ide-application-private.h |  11 +++-
 src/libide/gui/ide-application.c         | 100 +++++++++++++++++++------------
 src/libide/gui/ide-application.h         |  31 +++++-----
 3 files changed, 87 insertions(+), 55 deletions(-)
---
diff --git a/src/libide/gui/ide-application-private.h b/src/libide/gui/ide-application-private.h
index 52a5d642f..0b0f51282 100644
--- a/src/libide/gui/ide-application-private.h
+++ b/src/libide/gui/ide-application-private.h
@@ -20,7 +20,8 @@
 
 #pragma once
 
-#include <dazzle.h>
+#include <libide-core.h>
+
 #include <libpeas/peas.h>
 
 #include "ide-application.h"
@@ -31,7 +32,11 @@ G_BEGIN_DECLS
 
 struct _IdeApplication
 {
-  DzlApplication parent_instance;
+  AdwApplication parent_instance;
+
+  /* Our helper to merge menus together */
+  IdeMenuManager *menu_manager;
+  GHashTable *menu_merge_ids;
 
   /* Array of all of our IdeWorkebench instances (loaded projects and
    * their application windows).
@@ -103,5 +108,7 @@ void            _ide_application_load_plugins_for_startup (IdeApplication
 void            _ide_application_load_plugins             (IdeApplication          *self);
 void            _ide_application_command_line             (IdeApplication          *self,
                                                            GApplicationCommandLine *cmdline);
+void            _ide_application_add_resources            (IdeApplication          *self,
+                                                           const char              *path);
 
 G_END_DECLS
diff --git a/src/libide/gui/ide-application.c b/src/libide/gui/ide-application.c
index 5debac6ca..c9c5a0631 100644
--- a/src/libide/gui/ide-application.c
+++ b/src/libide/gui/ide-application.c
@@ -37,11 +37,8 @@
 #include "ide-application-private.h"
 #include "ide-gui-global.h"
 #include "ide-primary-workspace.h"
-#include "ide-worker.h"
 
-G_DEFINE_FINAL_TYPE (IdeApplication, ide_application, DZL_TYPE_APPLICATION)
-
-#define IS_UI_PROCESS(app) ((app)->type == NULL)
+G_DEFINE_FINAL_TYPE (IdeApplication, ide_application, ADW_TYPE_APPLICATION)
 
 typedef struct
 {
@@ -123,6 +120,9 @@ static void
 ide_application_startup (GApplication *app)
 {
   IdeApplication *self = (IdeApplication *)app;
+  g_autofree gchar *style_path = NULL;
+  GtkSourceStyleSchemeManager *styles;
+  GtkIconTheme *icon_theme;
 
   g_assert (IDE_IS_MAIN_THREAD ());
   g_assert (IDE_IS_APPLICATION (self));
@@ -137,38 +137,30 @@ ide_application_startup (GApplication *app)
 
   G_APPLICATION_CLASS (ide_application_parent_class)->startup (app);
 
-  if (IS_UI_PROCESS (self))
-    {
-      g_autofree gchar *style_path = NULL;
-      GtkSourceStyleSchemeManager *styles;
-
-      /* Setup access to private icons dir */
-      gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (), PACKAGE_ICONDIR);
+  /* Setup access to private icons dir */
+  icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
+  gtk_icon_theme_add_search_path (icon_theme, PACKAGE_ICONDIR);
 
-      /* Add custom style locations for gtksourceview schemes */
-      styles = gtk_source_style_scheme_manager_get_default ();
-      style_path = g_build_filename (g_get_home_dir (), ".local", "share", "gtksourceview-4", "styles", 
NULL);
-      gtk_source_style_scheme_manager_append_search_path (styles, style_path);
-      gtk_source_style_scheme_manager_append_search_path (styles, PACKAGE_DATADIR"/gtksourceview-4/styles/");
+  /* Add custom style locations for gtksourceview schemes */
+  styles = gtk_source_style_scheme_manager_get_default ();
+  style_path = g_build_filename (g_get_home_dir (), ".local", "share", "gtksourceview-4", "styles", NULL);
+  gtk_source_style_scheme_manager_append_search_path (styles, style_path);
+  gtk_source_style_scheme_manager_append_search_path (styles, PACKAGE_DATADIR"/gtksourceview-4/styles/");
 
-      /* Load color settings (Night Light, Dark Mode, etc) */
-      _ide_application_init_color (self);
-    }
+  /* Load color settings (Night Light, Dark Mode, etc) */
+  _ide_application_init_color (self);
 
   /* And now we can load the rest of our plugins for startup. */
   _ide_application_load_plugins (self);
 
-  if (IS_UI_PROCESS (self))
-    {
-      /* Make sure our shorcuts are registered */
-      _ide_application_init_shortcuts (self);
+  /* Make sure our shorcuts are registered */
+  _ide_application_init_shortcuts (self);
 
-      /* Load keybindings from plugins and what not */
-      ide_application_register_keybindings (self);
+  /* Load keybindings from plugins and what not */
+  ide_application_register_keybindings (self);
 
-      /* Load language defaults into gsettings */
-      ide_language_defaults_init_async (NULL, NULL, NULL);
-    }
+  /* Load language defaults into gsettings */
+  ide_language_defaults_init_async (NULL, NULL, NULL);
 }
 
 static void
@@ -215,14 +207,8 @@ ide_application_activate (GApplication *app)
   g_assert (IDE_IS_MAIN_THREAD ());
   g_assert (IDE_IS_APPLICATION (self));
 
-  if (ide_str_equal0 (self->type, "worker"))
-    {
-      ide_application_activate_worker (self);
-      IDE_EXIT;
-    }
-
   if ((window = gtk_application_get_active_window (GTK_APPLICATION (self))))
-    ide_gtk_window_present (window);
+    gtk_window_present (GTK_WINDOW (window));
 
   if (self->addins != NULL)
     peas_extension_set_foreach (self->addins,
@@ -279,6 +265,40 @@ ide_application_open (GApplication  *app,
   IDE_EXIT;
 }
 
+void
+_ide_application_add_resources (IdeApplication *self,
+                                const char     *resource_path)
+{
+  g_autoptr(GError) error = NULL;
+  g_autofree gchar *menu_path = NULL;
+  guint merge_id;
+
+  g_assert (IDE_IS_APPLICATION (self));
+  g_assert (resource_path != NULL);
+
+  /* We use interned strings for hash table keys */
+  resource_path = g_intern_string (resource_path);
+
+  /*
+   * If the resource path has a gtk/menus.ui file, we want to auto-load and
+   * merge the menus.
+   */
+  menu_path = g_build_filename (resource_path, "gtk", "menus.ui", NULL);
+
+  if (g_str_has_prefix (menu_path, "resource://"))
+    merge_id = ide_menu_manager_add_resource (self->menu_manager, menu_path, &error);
+  else
+    merge_id = ide_menu_manager_add_filename (self->menu_manager, menu_path, &error);
+
+  if (merge_id != 0)
+    g_hash_table_insert (self->menu_merge_ids, (gchar *)resource_path, GUINT_TO_POINTER (merge_id));
+
+  if (error != NULL &&
+      !(g_error_matches (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND) ||
+        g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)))
+    g_warning ("%s", error->message);
+}
+
 static void
 ide_application_dispose (GObject *object)
 {
@@ -293,10 +313,12 @@ ide_application_dispose (GObject *object)
   g_clear_pointer (&self->plugin_settings, g_hash_table_unref);
   g_clear_pointer (&self->plugin_gresources, g_hash_table_unref);
   g_clear_pointer (&self->argv, g_strfreev);
+  g_clear_pointer (&self->menu_merge_ids, g_hash_table_unref);
   g_clear_object (&self->addins);
   g_clear_object (&self->color_proxy);
   g_clear_object (&self->settings);
   g_clear_object (&self->network_monitor);
+  g_clear_object (&self->menu_manager);
 
   G_OBJECT_CLASS (ide_application_parent_class)->dispose (object);
 }
@@ -321,6 +343,8 @@ ide_application_class_init (IdeApplicationClass *klass)
 static void
 ide_application_init (IdeApplication *self)
 {
+  self->menu_merge_ids = g_hash_table_new (g_str_hash, g_str_equal);
+  self->menu_manager = ide_menu_manager_new ();
   self->started_at = g_date_time_new_now_local ();
   self->workspace_type = IDE_TYPE_PRIMARY_WORKSPACE;
   self->workbenches = g_ptr_array_new_with_free_func (g_object_unref);
@@ -333,9 +357,9 @@ ide_application_init (IdeApplication *self)
   ide_themes_init ();
 
   /* Ensure our core data is loaded early. */
-  dzl_application_add_resources (DZL_APPLICATION (self), "resource:///org/gnome/libide-sourceview/");
-  dzl_application_add_resources (DZL_APPLICATION (self), "resource:///org/gnome/libide-gui/");
-  dzl_application_add_resources (DZL_APPLICATION (self), "resource:///org/gnome/libide-terminal/");
+  _ide_application_add_resources (self, "resource:///org/gnome/libide-sourceview/");
+  _ide_application_add_resources (self, "resource:///org/gnome/libide-gui/");
+  _ide_application_add_resources (self, "resource:///org/gnome/libide-terminal/");
 
   /* Make sure our GAction are available */
   _ide_application_init_actions (self);
diff --git a/src/libide/gui/ide-application.h b/src/libide/gui/ide-application.h
index 7b09bb088..448ed877a 100644
--- a/src/libide/gui/ide-application.h
+++ b/src/libide/gui/ide-application.h
@@ -24,7 +24,8 @@
 # error "Only <libide-gui.h> can be included directly."
 #endif
 
-#include <dazzle.h>
+#include <adwaita.h>
+
 #include <libide-core.h>
 #include <libide-projects.h>
 
@@ -35,48 +36,48 @@ G_BEGIN_DECLS
 #define IDE_TYPE_APPLICATION    (ide_application_get_type())
 #define IDE_APPLICATION_DEFAULT IDE_APPLICATION(g_application_get_default())
 
-IDE_AVAILABLE_IN_3_32
-G_DECLARE_FINAL_TYPE (IdeApplication, ide_application, IDE, APPLICATION, DzlApplication)
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeApplication, ide_application, IDE, APPLICATION, AdwApplication)
 
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gboolean       ide_application_has_network              (IdeApplication           *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gchar        **ide_application_get_argv                 (IdeApplication           *self,
                                                          GApplicationCommandLine  *cmdline);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 GDateTime     *ide_application_get_started_at           (IdeApplication           *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gboolean       ide_application_get_command_line_handled (IdeApplication           *self,
                                                          GApplicationCommandLine  *cmdline);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_application_set_command_line_handled (IdeApplication           *self,
                                                          GApplicationCommandLine  *cmdline,
                                                          gboolean                  handled);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_application_open_project_async       (IdeApplication           *self,
                                                          IdeProjectInfo           *project_info,
                                                          GType                     workspace_type,
                                                          GCancellable             *cancellable,
                                                          GAsyncReadyCallback       callback,
                                                          gpointer                  user_data);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 IdeWorkbench  *ide_application_open_project_finish      (IdeApplication           *self,
                                                          GAsyncResult             *result,
                                                          GError                  **error);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_application_set_workspace_type       (IdeApplication           *self,
                                                          GType                     workspace_type);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_application_add_workbench            (IdeApplication           *self,
                                                          IdeWorkbench             *workbench);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_application_remove_workbench         (IdeApplication           *self,
                                                          IdeWorkbench             *workbench);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_application_foreach_workbench        (IdeApplication           *self,
                                                          GFunc                     callback,
                                                          gpointer                  user_data);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 IdeWorkbench  *ide_application_find_workbench_for_file  (IdeApplication           *self,
                                                          GFile                    *file);
 IDE_AVAILABLE_IN_3_34


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