[gnome-builder] libide/foundry: use IdeSettings when appropriate



commit f55fb5212570e79e5ab52110cd47720424e195cf
Author: Christian Hergert <chergert redhat com>
Date:   Sat Aug 27 01:01:44 2022 -0700

    libide/foundry: use IdeSettings when appropriate
    
    We want these to be stored in gsettings first and foremost, instead of all
    the cached copies in manager objects. Additionally, we want them to be
    layered so we can have app vs project settings.

 .../org.gnome.builder.project.gschema.xml          |   6 ++
 src/libide/foundry/ide-config-manager.c            |  12 +--
 src/libide/foundry/ide-run-manager-private.h       |   8 +-
 src/libide/foundry/ide-run-manager.c               | 101 ++++-----------------
 src/libide/foundry/ide-test.c                      |   6 +-
 .../buildui/gbp-buildui-preferences-addin.c        |   2 +-
 src/plugins/buildui/gtk/menus.ui                   |   2 +-
 src/plugins/buildui/tweaks.ui                      |  16 ++++
 8 files changed, 55 insertions(+), 98 deletions(-)
---
diff --git a/data/gsettings/org.gnome.builder.project.gschema.xml 
b/data/gsettings/org.gnome.builder.project.gschema.xml
index b20e727a4..740910047 100644
--- a/data/gsettings/org.gnome.builder.project.gschema.xml
+++ b/data/gsettings/org.gnome.builder.project.gschema.xml
@@ -45,5 +45,11 @@
       <description>What environment to use when running unit tests</description>
     </key>
 
+    <key name="verbose-logging" type="b">
+      <default>false</default>
+      <summary>Verbose Logging</summary>
+      <description>If G_MESSAGES_DEBUG=all should be used when running the target application</description>
+    </key>
+
   </schema>
 </schemalist>
diff --git a/src/libide/foundry/ide-config-manager.c b/src/libide/foundry/ide-config-manager.c
index 36437eec8..afd176fa7 100644
--- a/src/libide/foundry/ide-config-manager.c
+++ b/src/libide/foundry/ide-config-manager.c
@@ -42,7 +42,7 @@ struct _IdeConfigManager
   GArray           *configs;
   IdeConfig        *current;
   PeasExtensionSet *providers;
-  GSettings        *project_settings;
+  IdeSettings      *project_settings;
 
   GMenu            *menu;
   GMenu            *config_menu;
@@ -806,7 +806,7 @@ notify_providers_loaded (IdeConfigManager *self,
     return;
 
   /*
-   * At this point, all of our configuratin providers have returned from
+   * At this point, all of our configuration providers have returned from
    * their asynchronous loading. So we should have all of the configs we
    * can know about at this point.
    *
@@ -814,7 +814,7 @@ notify_providers_loaded (IdeConfigManager *self,
    * a match, make that our active configuration.
    *
    * We want to avoid applying the value if the value is unchanged
-   * according to g_settings_get_user_value() so that we don't override
+   * according to ide_settings_get_user_value() so that we don't override
    * any provider that set_current() during it's load, unless the user
    * has manually set this config in the past.
    *
@@ -822,7 +822,7 @@ notify_providers_loaded (IdeConfigManager *self,
    * new values to the settings when set_current() is called.
    */
 
-  user_value = g_settings_get_user_value (self->project_settings, "config-id");
+  user_value = ide_settings_get_user_value (self->project_settings, "config-id");
 
   if (user_value != NULL)
     {
@@ -903,7 +903,7 @@ ide_config_manager_init_async (GAsyncInitable      *initable,
   context = ide_object_get_context (IDE_OBJECT (self));
   g_assert (IDE_IS_CONTEXT (context));
 
-  self->project_settings = ide_context_ref_project_settings (context);
+  self->project_settings = ide_context_ref_settings (context, "org.gnome.builder.project");
 
   self->providers = peas_extension_set_new (peas_engine_get_default (),
                                             IDE_TYPE_CONFIG_PROVIDER,
@@ -1010,7 +1010,7 @@ ide_config_manager_set_current (IdeConfigManager *self,
           if (self->propagate_to_settings && self->project_settings != NULL)
             {
               g_autofree gchar *new_id = g_strdup (ide_config_get_id (current));
-              g_settings_set_string (self->project_settings, "config-id", new_id);
+              ide_settings_set_string (self->project_settings, "config-id", new_id);
             }
 
           id = ide_config_get_id (self->current);
diff --git a/src/libide/foundry/ide-run-manager-private.h b/src/libide/foundry/ide-run-manager-private.h
index cfc93e2fe..2f16a7fac 100644
--- a/src/libide/foundry/ide-run-manager-private.h
+++ b/src/libide/foundry/ide-run-manager-private.h
@@ -24,9 +24,9 @@
 
 G_BEGIN_DECLS
 
-void        _ide_run_manager_drop_caches    (IdeRunManager *self);
-const char *_ide_run_manager_get_default_id (IdeRunManager *self);
-void        _ide_run_manager_set_default_id (IdeRunManager *self,
-                                             const char    *run_command_id);
+void  _ide_run_manager_drop_caches    (IdeRunManager *self);
+char *_ide_run_manager_get_default_id (IdeRunManager *self);
+void  _ide_run_manager_set_default_id (IdeRunManager *self,
+                                       const char    *run_command_id);
 
 G_END_DECLS
diff --git a/src/libide/foundry/ide-run-manager.c b/src/libide/foundry/ide-run-manager.c
index 10031422c..ab6b4bfb2 100644
--- a/src/libide/foundry/ide-run-manager.c
+++ b/src/libide/foundry/ide-run-manager.c
@@ -54,6 +54,8 @@ struct _IdeRunManager
 {
   IdeObject                parent_instance;
 
+  IdeSettings             *project_settings;
+
   GCancellable            *cancellable;
   IdeNotification         *notif;
   IdeExtensionSetAdapter  *run_command_providers;
@@ -70,11 +72,8 @@ struct _IdeRunManager
   guint64                  last_change_seq;
   guint64                  pending_last_change_seq;
 
-  char                    *default_run_command;
-
   guint                    busy;
 
-  guint                    messages_debug_all : 1;
   guint                    has_installed_once : 1;
   guint                    sent_signal : 1;
 };
@@ -86,10 +85,6 @@ static void ide_run_manager_actions_run_with_handler    (IdeRunManager  *self,
                                                          GVariant       *param);
 static void ide_run_manager_actions_stop                (IdeRunManager  *self,
                                                          GVariant       *param);
-static void ide_run_manager_actions_messages_debug_all  (IdeRunManager  *self,
-                                                         GVariant       *param);
-static void ide_run_manager_actions_default_run_command (IdeRunManager  *self,
-                                                         GVariant       *param);
 static void ide_run_manager_actions_color_scheme        (IdeRunManager  *self,
                                                          GVariant       *param);
 static void ide_run_manager_actions_high_contrast       (IdeRunManager  *self,
@@ -101,8 +96,6 @@ IDE_DEFINE_ACTION_GROUP (IdeRunManager, ide_run_manager, {
   { "run", ide_run_manager_actions_run },
   { "run-with-handler", ide_run_manager_actions_run_with_handler, "s" },
   { "stop", ide_run_manager_actions_stop },
-  { "messages-debug-all", ide_run_manager_actions_messages_debug_all, NULL, "false" },
-  { "default-run-command", ide_run_manager_actions_default_run_command, "s", "''" },
   { "color-scheme", ide_run_manager_actions_color_scheme, "s", "'follow'" },
   { "high-contrast", ide_run_manager_actions_high_contrast, NULL, "false" },
   { "text-direction", ide_run_manager_actions_text_direction, "s", "''" },
@@ -234,23 +227,6 @@ ide_run_manager_actions_color_scheme (IdeRunManager *self,
                                     g_variant_new_string (str));
 }
 
-static void
-ide_run_manager_actions_default_run_command (IdeRunManager *self,
-                                             GVariant      *param)
-{
-  const char *str;
-
-  g_assert (IDE_IS_RUN_MANAGER (self));
-  g_assert (param != NULL);
-  g_assert (g_variant_is_of_type (param, G_VARIANT_TYPE_STRING));
-
-  str = g_variant_get_string (param, NULL);
-  if (ide_str_empty0 (str))
-    str = NULL;
-
-  _ide_run_manager_set_default_id (self, str);
-}
-
 static void
 ide_run_manager_update_action_enabled (IdeRunManager *self)
 {
@@ -313,8 +289,7 @@ ide_run_manager_dispose (GObject *object)
 {
   IdeRunManager *self = (IdeRunManager *)object;
 
-  g_clear_pointer (&self->default_run_command, g_free);
-
+  g_clear_object (&self->project_settings);
   g_clear_object (&self->cancellable);
   g_clear_object (&self->current_run_command);
   g_clear_object (&self->current_subprocess);
@@ -359,7 +334,6 @@ initable_init (GInitable     *initable,
                GError       **error)
 {
   IdeRunManager *self = (IdeRunManager *)initable;
-  g_autoptr(GSettings) settings = NULL;
   IdeBuildManager *build_manager;
   IdeContext *context;
 
@@ -370,13 +344,9 @@ initable_init (GInitable     *initable,
 
   context = ide_object_get_context (IDE_OBJECT (self));
   build_manager = ide_build_manager_from_context (context);
-  settings = ide_context_ref_project_settings (context);
 
-  g_clear_pointer (&self->default_run_command, g_free);
-  self->default_run_command = g_settings_get_string (settings, "default-run-command");
-  ide_run_manager_set_action_state (self,
-                                    "default-run-command",
-                                    g_variant_new_string (self->default_run_command));
+  self->project_settings = ide_context_ref_settings (context,
+                                                     "org.gnome.builder.project");
 
   g_signal_connect_object (build_manager,
                            "notify::can-build",
@@ -680,7 +650,6 @@ ide_run_manager_install_async (IdeRunManager       *self,
                                gpointer             user_data)
 {
   g_autoptr(IdeContext) context = NULL;
-  g_autoptr(GSettings) project_settings = NULL;
   g_autoptr(IdeTask) task = NULL;
   IdeBuildManager *build_manager;
   IdeVcsMonitor *monitor;
@@ -696,8 +665,7 @@ ide_run_manager_install_async (IdeRunManager       *self,
   task = ide_task_new (self, cancellable, callback, user_data);
   ide_task_set_source_tag (task, ide_run_manager_install_async);
 
-  project_settings = ide_context_ref_project_settings (context);
-  if (!g_settings_get_boolean (project_settings, "install-before-run"))
+  if (!ide_settings_get_boolean (self->project_settings, "install-before-run"))
     {
       ide_task_return_boolean (task, TRUE);
       IDE_EXIT;
@@ -855,7 +823,7 @@ ide_run_manager_prepare_run_context (IdeRunManager *self,
   apply_color_scheme (run_context, get_action_state_string (self, "color-scheme"));
   apply_high_contrast (run_context, get_action_state_bool (self, "high-contrast"));
   apply_text_direction (run_context, get_action_state_string (self, "text-direction"));
-  apply_messages_debug (run_context, self->messages_debug_all);
+  apply_messages_debug (run_context, ide_settings_get_boolean (self->project_settings, "verbose-logging"));
 
 #if 0
 /* TODO: Probably want to inherit these when running, but we should have
@@ -1178,16 +1146,12 @@ do_cancel_in_timeout (gpointer user_data)
 static int
 ide_run_manager_get_exit_signal (IdeRunManager *self)
 {
-  g_autoptr(GSettings) settings = NULL;
   g_autofree char *stop_signal = NULL;
-  IdeContext *context;
   int signum;
 
   g_assert (IDE_IS_RUN_MANAGER (self));
 
-  context = ide_object_get_context (IDE_OBJECT (self));
-  settings = ide_context_ref_project_settings (context);
-  stop_signal = g_settings_get_string (settings, "stop-signal");
+  stop_signal = ide_settings_get_string (self->project_settings, "stop-signal");
 
   if (0) {}
   else if (ide_str_equal0 (stop_signal, "SIGKILL")) signum = SIGKILL;
@@ -1305,7 +1269,6 @@ ide_run_manager_init (IdeRunManager *self)
 
   self->cancellable = g_cancellable_new ();
   self->run_tool = ide_no_tool_new ();
-  self->default_run_command = g_strdup ("");
 
   /* Setup initial text direction state */
   text_dir = gtk_widget_get_default_direction ();
@@ -1325,22 +1288,6 @@ _ide_run_manager_drop_caches (IdeRunManager *self)
   self->last_change_seq = 0;
 }
 
-static void
-ide_run_manager_actions_messages_debug_all (IdeRunManager *self,
-                                            GVariant      *param)
-{
-  IDE_ENTRY;
-
-  g_assert (IDE_IS_RUN_MANAGER (self));
-
-  self->messages_debug_all = !self->messages_debug_all;
-  ide_run_manager_set_action_state (self,
-                                    "messages-debug-all",
-                                    g_variant_new_boolean (self->messages_debug_all));
-
-  IDE_EXIT;
-}
-
 typedef struct
 {
   GString *errors;
@@ -1581,7 +1528,10 @@ ide_run_manager_discover_run_command_async (IdeRunManager       *self,
 
   task = ide_task_new (self, cancellable, callback, user_data);
   ide_task_set_source_tag (task, ide_run_manager_discover_run_command_async);
-  ide_task_set_task_data (task, g_strdup (self->default_run_command), g_free);
+  ide_task_set_task_data (task,
+                          ide_settings_get_string (self->project_settings,
+                                                   "default-run-command"),
+                          g_free);
 
   ide_run_manager_list_commands_async (self,
                                        cancellable,
@@ -1619,12 +1569,12 @@ ide_run_manager_discover_run_command_finish (IdeRunManager  *self,
   IDE_RETURN (run_command);
 }
 
-const char *
+char *
 _ide_run_manager_get_default_id (IdeRunManager *self)
 {
   g_return_val_if_fail (IDE_IS_RUN_MANAGER (self), NULL);
 
-  return self->default_run_command;
+  return ide_settings_get_string (self->project_settings, "default-run-command");
 }
 
 void
@@ -1636,23 +1586,8 @@ _ide_run_manager_set_default_id (IdeRunManager *self,
   if (run_command_id == NULL)
     run_command_id = "";
 
-  if (g_strcmp0 (run_command_id, self->default_run_command) != 0)
-    {
-      IdeContext *context = ide_object_get_context (IDE_OBJECT (self));
-      g_autoptr(GSettings) settings = ide_context_ref_project_settings (context);
-
-      g_debug ("Setting default run command to \"%s\"",
-               run_command_id);
-
-      g_free (self->default_run_command);
-      self->default_run_command = g_strdup (run_command_id);
-
-      g_settings_set_string (settings,
-                             "default-run-command",
-                             run_command_id);
-
-      ide_run_manager_set_action_state (self,
-                                        "default-run-command",
-                                        g_variant_new_string (run_command_id));
-    }
+  g_debug ("Settinging default run command to \"%s\"", run_command_id);
+  ide_settings_set_string (self->project_settings,
+                           "default-run-command",
+                           run_command_id);
 }
diff --git a/src/libide/foundry/ide-test.c b/src/libide/foundry/ide-test.c
index 3af5ad7a3..a11c30d62 100644
--- a/src/libide/foundry/ide-test.c
+++ b/src/libide/foundry/ide-test.c
@@ -293,7 +293,7 @@ ide_test_run_async (IdeTest             *self,
 {
   g_autoptr(IdeRunContext) run_context = NULL;
   g_autoptr(IdeSubprocess) subprocess = NULL;
-  g_autoptr(GSettings) settings = NULL;
+  g_autoptr(IdeSettings) settings = NULL;
   g_autoptr(IdeTask) task = NULL;
   g_autoptr(GError) error = NULL;
   g_autofree char *locality = NULL;
@@ -314,8 +314,8 @@ ide_test_run_async (IdeTest             *self,
 
   context = ide_object_get_context (IDE_OBJECT (pipeline));
   runtime = ide_pipeline_get_runtime (pipeline);
-  settings = ide_context_ref_project_settings (context);
-  locality = g_settings_get_string (settings, "unit-test-locality");
+  settings = ide_context_ref_settings (context, "org.gnome.builder.project");
+  locality = ide_settings_get_string (settings, "unit-test-locality");
 
   if (ide_str_equal0 (locality, "runtime"))
     {
diff --git a/src/plugins/buildui/gbp-buildui-preferences-addin.c 
b/src/plugins/buildui/gbp-buildui-preferences-addin.c
index f5a2d3681..222fbd81d 100644
--- a/src/plugins/buildui/gbp-buildui-preferences-addin.c
+++ b/src/plugins/buildui/gbp-buildui-preferences-addin.c
@@ -153,7 +153,7 @@ list_run_commands_cb (GObject      *object,
     }
   else
     {
-      const char *id = _ide_run_manager_get_default_id (run_manager);
+      g_autofree char *id = _ide_run_manager_get_default_id (run_manager);
       guint n_items = g_list_model_get_n_items (model);
 
       for (guint i = 0; i < n_items; i++)
diff --git a/src/plugins/buildui/gtk/menus.ui b/src/plugins/buildui/gtk/menus.ui
index c0265cf56..a312d04f2 100644
--- a/src/plugins/buildui/gtk/menus.ui
+++ b/src/plugins/buildui/gtk/menus.ui
@@ -177,7 +177,7 @@
       <item>
         <attribute name="id">run-menu-verbose-logging</attribute>
         <attribute name="label" translatable="yes">Verbose Logging</attribute>
-        <attribute name="action">context.run-manager.messages-debug-all</attribute>
+        <attribute 
name="action">context.settings.project:org.gnome.builder.project.verbose-logging</attribute>
         <attribute name="role">check</attribute>
       </item>
     </section>
diff --git a/src/plugins/buildui/tweaks.ui b/src/plugins/buildui/tweaks.ui
index cbf9cd552..26a6ce33f 100644
--- a/src/plugins/buildui/tweaks.ui
+++ b/src/plugins/buildui/tweaks.ui
@@ -67,6 +67,22 @@
                 </child>
               </object>
             </child>
+            <child>
+              <object class="IdeTweaksGroup">
+                <child>
+                  <object class="IdeTweaksSwitch">
+                    <property name="title" translatable="yes">Verbose Logging</property>
+                    <property name="subtitle" translatable="yes">Runs with 
&lt;tt&gt;G_MESSAGES_DEBUG=all&lt;/tt&gt; environment variable for troubleshooting</property>
+                    <property name="binding">
+                      <object class="IdeTweaksSetting">
+                        <property name="schema-id">org.gnome.builder.project</property>
+                        <property name="schema-key">verbose-logging</property>
+                      </object>
+                    </property>
+                  </object>
+                </child>
+              </object>
+            </child>
             <child>
               <object class="IdeTweaksGroup">
                 <child>


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