[gnome-builder] libide/core: add helper to get project settings
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/core: add helper to get project settings
- Date: Wed, 27 Jul 2022 01:56:55 +0000 (UTC)
commit 85a6e847cd4d8e7c47c4aebab86f8502d9e058dc
Author: Christian Hergert <chergert redhat com>
Date: Tue Jul 26 18:40:16 2022 -0700
libide/core: add helper to get project settings
This gets an IdeSettings that was previously registered for project
overrides and returns it. We reuse the setting from the actionmuxer
to reduce on the number of copies of IdeSettings we keep around.
src/libide/core/ide-context.c | 34 ++++++++++++++++++++++++++++++++++
src/libide/core/ide-context.h | 4 ++++
2 files changed, 38 insertions(+)
---
diff --git a/src/libide/core/ide-context.c b/src/libide/core/ide-context.c
index e443804ff..70a72dd20 100644
--- a/src/libide/core/ide-context.c
+++ b/src/libide/core/ide-context.c
@@ -658,6 +658,40 @@ ide_context_ref_project_settings (IdeContext *self)
return g_settings_new_with_path ("org.gnome.builder.project", path);
}
+/**
+ * ide_context_ref_settings:
+ * @self: a #IdeContext
+ *
+ * Gets an #IdeSettings for @schema_id.
+ *
+ * The #IdeSettings will read settings from project overrides before
+ * falling back to application settings.
+ *
+ * Changes to settings will always apply to the project overrides.
+ *
+ * Returns: (transfer full) (nullable): an #IdeSettings
+ */
+IdeSettings *
+ide_context_ref_settings (IdeContext *self,
+ const char *schema_id)
+{
+ g_autoptr(IdeActionMuxer) muxer = NULL;
+
+ g_return_val_if_fail (IDE_IS_CONTEXT (self), NULL);
+ g_return_val_if_fail (schema_id != NULL, NULL);
+
+ if ((muxer = ide_context_ref_action_muxer (self)))
+ {
+ g_autofree char *prefix = g_strconcat ("project.settings:", schema_id, NULL);
+ GActionGroup *group = ide_action_muxer_get_action_group (muxer, prefix);
+
+ if (IDE_IS_SETTINGS (group))
+ return g_object_ref (IDE_SETTINGS (group));
+ }
+
+ return NULL;
+}
+
/**
* ide_context_dup_title:
* @self: a #IdeContext
diff --git a/src/libide/core/ide-context.h b/src/libide/core/ide-context.h
index a167f4246..1748ff7ea 100644
--- a/src/libide/core/ide-context.h
+++ b/src/libide/core/ide-context.h
@@ -26,6 +26,7 @@
#include "ide-action-muxer.h"
#include "ide-object.h"
+#include "ide-settings.h"
G_BEGIN_DECLS
@@ -90,6 +91,9 @@ IdeActionMuxer *ide_context_ref_action_muxer (IdeContext *self);
IDE_AVAILABLE_IN_ALL
void ide_context_register_settings (IdeContext *self,
const char *schema_id);
+IDE_AVAILABLE_IN_ALL
+IdeSettings *ide_context_ref_settings (IdeContext *self,
+ const char *schema_id);
#ifdef __cplusplus
#define ide_context_warning(instance, format, ...) \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]