[gnome-builder] libide/tweaks: pass tweaks object instead of project_id
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/tweaks: pass tweaks object instead of project_id
- Date: Wed, 17 Aug 2022 05:08:30 +0000 (UTC)
commit 267e87634798742925d8cfe98f8e067f41ec7d63
Author: Christian Hergert <chergert redhat com>
Date: Tue Aug 16 22:01:36 2022 -0700
libide/tweaks: pass tweaks object instead of project_id
Since we want to cache on the tweaks item, just pass that instead. This
helps ensure we still work if for some reason we loose our access to the
root item.
src/libide/tweaks/ide-tweaks-combo.c | 4 +---
src/libide/tweaks/ide-tweaks-font.c | 4 +---
src/libide/tweaks/ide-tweaks-item.c | 7 +------
src/libide/tweaks/ide-tweaks-panel.c | 5 ++---
src/libide/tweaks/ide-tweaks-settings.c | 22 ++++++++++------------
src/libide/tweaks/ide-tweaks-settings.h | 3 ++-
src/libide/tweaks/ide-tweaks-window.c | 5 +----
7 files changed, 18 insertions(+), 32 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-combo.c b/src/libide/tweaks/ide-tweaks-combo.c
index c8f7a379b..42ae66fd2 100644
--- a/src/libide/tweaks/ide-tweaks-combo.c
+++ b/src/libide/tweaks/ide-tweaks-combo.c
@@ -61,15 +61,13 @@ ide_tweaks_combo_create_for_item (IdeTweaksWidget *instance,
g_autoptr(GVariant) value = NULL;
IdeTweaksItem *root;
AdwComboRow *row;
- const char *project_id;
int selected = -1;
guint i = 0;
g_assert (IDE_IS_TWEAKS_COMBO (self));
root = ide_tweaks_item_get_root (IDE_TWEAKS_ITEM (widget));
- project_id = ide_tweaks_get_project_id (IDE_TWEAKS (root));
- settings = IDE_SETTINGS (ide_tweaks_settings_create_action_group (self->settings, project_id));
+ settings = IDE_SETTINGS (ide_tweaks_settings_create_action_group (self->settings, IDE_TWEAKS (root)));
store = g_list_store_new (IDE_TYPE_TWEAKS_CHOICE);
value = ide_settings_get_value (settings, self->key);
diff --git a/src/libide/tweaks/ide-tweaks-font.c b/src/libide/tweaks/ide-tweaks-font.c
index d5c806648..195045611 100644
--- a/src/libide/tweaks/ide-tweaks-font.c
+++ b/src/libide/tweaks/ide-tweaks-font.c
@@ -117,7 +117,6 @@ ide_tweaks_font_create_for_item (IdeTweaksWidget *instance,
{
IdeTweaksFont *self = (IdeTweaksFont *)widget;
g_autoptr(IdeSettings) settings = NULL;
- const char *project_id = NULL;
IdeTweaksItem *root;
AdwActionRow *row;
GtkButton *button;
@@ -131,8 +130,7 @@ ide_tweaks_font_create_for_item (IdeTweaksWidget *instance,
if (!root || !IDE_IS_TWEAKS (root))
return NULL;
- project_id = ide_tweaks_get_project_id (IDE_TWEAKS (root));
- settings = IDE_SETTINGS (ide_tweaks_settings_create_action_group (self->settings, project_id));
+ settings = IDE_SETTINGS (ide_tweaks_settings_create_action_group (self->settings, IDE_TWEAKS (root)));
button = g_object_new (GTK_TYPE_BUTTON,
"css-classes", IDE_STRV_INIT ("flat"),
diff --git a/src/libide/tweaks/ide-tweaks-item.c b/src/libide/tweaks/ide-tweaks-item.c
index fa629b32a..a4987e27b 100644
--- a/src/libide/tweaks/ide-tweaks-item.c
+++ b/src/libide/tweaks/ide-tweaks-item.c
@@ -131,15 +131,10 @@ ide_tweaks_item_real_copy (IdeTweaksItem *self)
child = ide_tweaks_item_get_next_sibling (child))
{
g_autoptr(IdeTweaksItem) new_child = ide_tweaks_item_copy (child);
- IdeTweaksItemPrivate *new_child_priv = ide_tweaks_item_get_instance_private (new_child);
ide_tweaks_item_insert_after (new_child, IDE_TWEAKS_ITEM (copy), NULL);
- /* Clear the "original" parent from the child because we want it to
- * resolve parents through this clone (and then to the alternate
- * ancestors.
- */
- g_clear_weak_pointer (&new_child_priv->parent_before_copy_wr);
+ g_assert (ide_tweaks_item_get_root (self) == ide_tweaks_item_get_root (IDE_TWEAKS_ITEM (copy)));
}
g_assert (ide_tweaks_item_get_parent (self) == ide_tweaks_item_get_parent (IDE_TWEAKS_ITEM (copy)));
diff --git a/src/libide/tweaks/ide-tweaks-panel.c b/src/libide/tweaks/ide-tweaks-panel.c
index c3d33b3be..61e282e2c 100644
--- a/src/libide/tweaks/ide-tweaks-panel.c
+++ b/src/libide/tweaks/ide-tweaks-panel.c
@@ -101,14 +101,13 @@ ide_tweaks_panel_visitor_cb (IdeTweaksItem *item,
}
else if (IDE_IS_TWEAKS_SETTINGS (item))
{
+ IdeTweaks *tweaks = ide_tweaks_item_get_ancestor (IDE_TWEAKS_ITEM (self->page), IDE_TYPE_TWEAKS);
IdeTweaksSettings *settings = IDE_TWEAKS_SETTINGS (item);
const char *schema_id = ide_tweaks_settings_get_schema_id (settings);
- IdeTweaks *tweaks = ide_tweaks_item_get_ancestor (item, IDE_TYPE_TWEAKS);
- const char *project_id = ide_tweaks_get_project_id (tweaks);
if (ide_action_muxer_get_action_group (self->muxer, schema_id) == NULL)
{
- GActionGroup *group = ide_tweaks_settings_create_action_group (settings, project_id);
+ GActionGroup *group = ide_tweaks_settings_create_action_group (settings, tweaks);
if (group != NULL)
ide_action_muxer_insert_action_group (self->muxer, schema_id, G_ACTION_GROUP (group));
diff --git a/src/libide/tweaks/ide-tweaks-settings.c b/src/libide/tweaks/ide-tweaks-settings.c
index 8135bec41..c73f30876 100644
--- a/src/libide/tweaks/ide-tweaks-settings.c
+++ b/src/libide/tweaks/ide-tweaks-settings.c
@@ -218,7 +218,7 @@ ide_tweaks_settings_set_application_only (IdeTweaksSettings *self,
/**
* ide_tweaks_settings_create_action_group:
* @self: a #IdeTweaksSettings
- * @project_id: the project identifier
+ * @tweaks: the #IdeTweaks
*
* Creates an action group containing the settings.
*
@@ -230,26 +230,27 @@ ide_tweaks_settings_set_application_only (IdeTweaksSettings *self,
*/
GActionGroup *
ide_tweaks_settings_create_action_group (IdeTweaksSettings *self,
- const char *project_id)
+ IdeTweaks *tweaks)
{
- IdeTweaksItem *root;
GActionGroup *cached;
IdeSettings *settings;
g_autofree char *hash_key = NULL;
+ const char *project_id;
g_return_val_if_fail (IDE_IS_TWEAKS_SETTINGS (self), NULL);
+ g_return_val_if_fail (IDE_IS_TWEAKS (tweaks), NULL);
if (self->schema_id == NULL)
return NULL;
+ project_id = ide_tweaks_get_project_id (tweaks);
+
hash_key = g_strdup_printf ("IdeSettings<%s|%s|%s>",
self->schema_id,
self->schema_path ? self->schema_path : (project_id ? project_id : "__app__"),
self->application_only ? "app" : "project");
- root = ide_tweaks_item_get_root (IDE_TWEAKS_ITEM (self));
-
- if ((cached = g_object_get_data (G_OBJECT (root), hash_key)))
+ if ((cached = g_object_get_data (G_OBJECT (tweaks), hash_key)))
{
g_assert (G_IS_ACTION_GROUP (cached));
return g_object_ref (cached);
@@ -262,7 +263,7 @@ ide_tweaks_settings_create_action_group (IdeTweaksSettings *self,
else
settings = ide_settings_new_with_path (project_id, self->schema_id, self->schema_path);
- g_object_set_data_full (G_OBJECT (root),
+ g_object_set_data_full (G_OBJECT (tweaks),
hash_key,
g_object_ref (settings),
g_object_unref);
@@ -278,7 +279,6 @@ ide_tweaks_settings_bind (IdeTweaksSettings *self,
GSettingsBindFlags bind_flags)
{
g_autoptr(IdeSettings) settings = NULL;
- const char *project_id = NULL;
IdeTweaksItem *root;
g_return_if_fail (IDE_IS_TWEAKS_SETTINGS (self));
@@ -286,9 +286,7 @@ ide_tweaks_settings_bind (IdeTweaksSettings *self,
g_return_if_fail (G_IS_OBJECT (instance));
g_return_if_fail (property != NULL);
- if ((root = ide_tweaks_item_get_root (IDE_TWEAKS_ITEM (self))) && IDE_IS_TWEAKS (root))
- project_id = ide_tweaks_get_project_id (IDE_TWEAKS (root));
-
- settings = IDE_SETTINGS (ide_tweaks_settings_create_action_group (self, project_id));
+ root = ide_tweaks_item_get_ancestor (IDE_TWEAKS_ITEM (self), IDE_TYPE_TWEAKS);
+ settings = IDE_SETTINGS (ide_tweaks_settings_create_action_group (self, IDE_TWEAKS (root)));
ide_settings_bind (settings, key, instance, property, bind_flags);
}
diff --git a/src/libide/tweaks/ide-tweaks-settings.h b/src/libide/tweaks/ide-tweaks-settings.h
index 12737ae2f..215b12ffb 100644
--- a/src/libide/tweaks/ide-tweaks-settings.h
+++ b/src/libide/tweaks/ide-tweaks-settings.h
@@ -20,6 +20,7 @@
#pragma once
+#include "ide-tweaks.h"
#include "ide-tweaks-item.h"
G_BEGIN_DECLS
@@ -48,7 +49,7 @@ void ide_tweaks_settings_set_application_only (IdeTweaksSettings
gboolean application_only);
IDE_AVAILABLE_IN_ALL
GActionGroup *ide_tweaks_settings_create_action_group (IdeTweaksSettings *self,
- const char *project_id);
+ IdeTweaks *tweaks);
IDE_AVAILABLE_IN_ALL
void ide_tweaks_settings_bind (IdeTweaksSettings *self,
const char *key,
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
index d0373e16d..0ee0b9059 100644
--- a/src/libide/tweaks/ide-tweaks-window.c
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -252,15 +252,12 @@ ide_tweaks_window_addin_removed_cb (PeasExtensionSet *set,
static void
ide_tweaks_window_rebuild (IdeTweaksWindow *self)
{
- const char *project_id;
GtkWidget *list;
g_assert (IDE_IS_TWEAKS_WINDOW (self));
g_assert (IDE_IS_TWEAKS (self->tweaks));
g_assert (self->addins == NULL);
- project_id = ide_tweaks_get_project_id (self->tweaks);
-
/* Allow addins to extend the tweaks instance */
self->addins = peas_extension_set_new (peas_engine_get_default (),
IDE_TYPE_TWEAKS_ADDIN,
@@ -306,7 +303,7 @@ ide_tweaks_window_rebuild (IdeTweaksWindow *self)
if (schema_id == NULL)
continue;
- group = ide_tweaks_settings_create_action_group (settings, project_id);
+ group = ide_tweaks_settings_create_action_group (settings, self->tweaks);
ide_action_muxer_insert_action_group (self->muxer, schema_id, group);
g_clear_object (&group);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]