[gnome-builder/wip/gtk4-port: 803/1774] libide/gui: add context to project preferences window
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 803/1774] libide/gui: add context to project preferences window
- Date: Mon, 11 Jul 2022 22:31:24 +0000 (UTC)
commit 3b7d5041e815eb3fb5e9587351170ce825a39421
Author: Christian Hergert <chergert redhat com>
Date: Thu Apr 28 22:11:19 2022 -0700
libide/gui: add context to project preferences window
We need access to the context when loading preferences for projects as
opposed to application-wide.
src/libide/gui/ide-preferences-addin.c | 14 +++++++----
src/libide/gui/ide-preferences-addin.h | 12 ++++++----
src/libide/gui/ide-preferences-window.c | 27 ++++++++++++++++++---
src/libide/gui/ide-preferences-window.h | 3 ++-
src/libide/gui/ide-workbench.c | 1 +
src/libide/gui/tests/test-preferences.c | 2 +-
src/plugins/clang/ide-clang-preferences-addin.c | 8 +++++--
.../editorui/gbp-editorui-preferences-addin.c | 28 +++++++++++++++++-----
.../gbp-quick-highlight-preferences.c | 3 ++-
.../rust-analyzer-preferences-addin.c | 6 +++--
.../spellcheck/gbp-spell-preferences-addin.c | 6 +++--
src/plugins/vim/gbp-vim-preferences-addin.c | 6 +++--
12 files changed, 88 insertions(+), 28 deletions(-)
---
diff --git a/src/libide/gui/ide-preferences-addin.c b/src/libide/gui/ide-preferences-addin.c
index 45d5cd3ac..96cc97fb7 100644
--- a/src/libide/gui/ide-preferences-addin.c
+++ b/src/libide/gui/ide-preferences-addin.c
@@ -35,6 +35,7 @@ ide_preferences_addin_default_init (IdePreferencesAddinInterface *iface)
* ide_preferences_addin_load:
* @self: An #IdePreferencesAddin.
* @preferences: The preferences container implementation.
+ * @context: (nullable): an #IdeContext or %NULL
*
* This interface method is called when a preferences addin is initialized. It
* could be initialized from multiple preferences implementations, so consumers
@@ -42,19 +43,22 @@ ide_preferences_addin_default_init (IdePreferencesAddinInterface *iface)
*/
void
ide_preferences_addin_load (IdePreferencesAddin *self,
- IdePreferencesWindow *preferences)
+ IdePreferencesWindow *preferences,
+ IdeContext *context)
{
g_return_if_fail (IDE_IS_PREFERENCES_ADDIN (self));
g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (preferences));
+ g_return_if_fail (!context || IDE_IS_CONTEXT (context));
if (IDE_PREFERENCES_ADDIN_GET_IFACE (self)->load)
- IDE_PREFERENCES_ADDIN_GET_IFACE (self)->load (self, preferences);
+ IDE_PREFERENCES_ADDIN_GET_IFACE (self)->load (self, preferences, context);
}
/**
* ide_preferences_addin_unload:
* @self: An #IdePreferencesAddin.
* @preferences: The preferences container implementation.
+ * @context: (nullable): an #IdeContext or %NULL
*
* This interface method is called when the preferences addin should remove all
* controls added to @preferences. This could happen during desctruction of
@@ -62,11 +66,13 @@ ide_preferences_addin_load (IdePreferencesAddin *self,
*/
void
ide_preferences_addin_unload (IdePreferencesAddin *self,
- IdePreferencesWindow *preferences)
+ IdePreferencesWindow *preferences,
+ IdeContext *context)
{
g_return_if_fail (IDE_IS_PREFERENCES_ADDIN (self));
g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (preferences));
+ g_return_if_fail (!context || IDE_IS_CONTEXT (context));
if (IDE_PREFERENCES_ADDIN_GET_IFACE (self)->unload)
- IDE_PREFERENCES_ADDIN_GET_IFACE (self)->unload (self, preferences);
+ IDE_PREFERENCES_ADDIN_GET_IFACE (self)->unload (self, preferences, context);
}
diff --git a/src/libide/gui/ide-preferences-addin.h b/src/libide/gui/ide-preferences-addin.h
index 60912864f..b88409045 100644
--- a/src/libide/gui/ide-preferences-addin.h
+++ b/src/libide/gui/ide-preferences-addin.h
@@ -40,16 +40,20 @@ struct _IdePreferencesAddinInterface
GTypeInterface parent_interface;
void (*load) (IdePreferencesAddin *self,
- IdePreferencesWindow *preferences);
+ IdePreferencesWindow *preferences,
+ IdeContext *context);
void (*unload) (IdePreferencesAddin *self,
- IdePreferencesWindow *preferences);
+ IdePreferencesWindow *preferences,
+ IdeContext *context);
};
IDE_AVAILABLE_IN_ALL
void ide_preferences_addin_load (IdePreferencesAddin *self,
- IdePreferencesWindow *preferences);
+ IdePreferencesWindow *preferences,
+ IdeContext *context);
IDE_AVAILABLE_IN_ALL
void ide_preferences_addin_unload (IdePreferencesAddin *self,
- IdePreferencesWindow *preferences);
+ IdePreferencesWindow *preferences,
+ IdeContext *context);
G_END_DECLS
diff --git a/src/libide/gui/ide-preferences-window.c b/src/libide/gui/ide-preferences-window.c
index f6d98b041..0626fda74 100644
--- a/src/libide/gui/ide-preferences-window.c
+++ b/src/libide/gui/ide-preferences-window.c
@@ -40,6 +40,7 @@ struct _IdePreferencesWindow
IdePreferencesMode mode;
IdeExtensionSetAdapter *addins;
+ IdeContext *context;
GtkToggleButton *search_button;
GtkButton *back_button;
@@ -87,6 +88,7 @@ G_DEFINE_FINAL_TYPE (IdePreferencesWindow, ide_preferences_window, ADW_TYPE_APPL
enum {
PROP_0,
+ PROP_CONTEXT,
PROP_MODE,
N_PROPS
};
@@ -297,7 +299,7 @@ ide_preferences_window_extension_added (IdeExtensionSetAdapter *set,
g_assert (IDE_IS_PREFERENCES_WINDOW (self));
g_assert (IDE_IS_PREFERENCES_ADDIN (exten));
- ide_preferences_addin_load (IDE_PREFERENCES_ADDIN (exten), self);
+ ide_preferences_addin_load (IDE_PREFERENCES_ADDIN (exten), self, self->context);
IDE_EXIT;
}
@@ -317,7 +319,7 @@ ide_preferences_window_extension_removed (IdeExtensionSetAdapter *set,
g_assert (IDE_IS_PREFERENCES_WINDOW (self));
g_assert (IDE_IS_PREFERENCES_ADDIN (exten));
- ide_preferences_addin_unload (IDE_PREFERENCES_ADDIN (exten), self);
+ ide_preferences_addin_unload (IDE_PREFERENCES_ADDIN (exten), self, self->context);
IDE_EXIT;
}
@@ -377,6 +379,8 @@ ide_preferences_window_dispose (GObject *object)
ide_clear_and_destroy_object (&self->addins);
+ g_clear_object (&self->context);
+
g_clear_pointer (&self->settings, g_hash_table_unref);
g_clear_handle_id (&self->rebuild_source, g_source_remove);
@@ -421,6 +425,10 @@ ide_preferences_window_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_CONTEXT:
+ g_value_set_object (value, self->context);
+ break;
+
case PROP_MODE:
g_value_set_enum (value, self->mode);
break;
@@ -440,6 +448,10 @@ ide_preferences_window_set_property (GObject *object,
switch (prop_id)
{
+ case PROP_CONTEXT:
+ self->context = g_value_dup_object (value);
+ break;
+
case PROP_MODE:
self->mode = g_value_get_enum (value);
break;
@@ -469,6 +481,13 @@ ide_preferences_window_class_init (IdePreferencesWindowClass *klass)
IDE_PREFERENCES_MODE_EMPTY,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+ properties [PROP_CONTEXT] =
+ g_param_spec_object ("context",
+ "Context",
+ "The project context, if any",
+ IDE_TYPE_CONTEXT,
+ (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/libide-gui/ui/ide-preferences-window.ui");
@@ -500,9 +519,11 @@ ide_preferences_window_init (IdePreferencesWindow *self)
}
GtkWidget *
-ide_preferences_window_new (IdePreferencesMode mode)
+ide_preferences_window_new (IdePreferencesMode mode,
+ IdeContext *context)
{
return g_object_new (IDE_TYPE_PREFERENCES_WINDOW,
+ "context", context,
"mode", mode,
NULL);
}
diff --git a/src/libide/gui/ide-preferences-window.h b/src/libide/gui/ide-preferences-window.h
index dbbf4b38d..2aefa8821 100644
--- a/src/libide/gui/ide-preferences-window.h
+++ b/src/libide/gui/ide-preferences-window.h
@@ -90,7 +90,8 @@ IDE_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (IdePreferencesWindow, ide_preferences_window, IDE, PREFERENCES_WINDOW,
AdwApplicationWindow)
IDE_AVAILABLE_IN_ALL
-GtkWidget *ide_preferences_window_new (IdePreferencesMode mode);
+GtkWidget *ide_preferences_window_new (IdePreferencesMode mode,
+ IdeContext *context);
IDE_AVAILABLE_IN_ALL
IdePreferencesMode ide_preferences_window_get_mode (IdePreferencesWindow *self);
IDE_AVAILABLE_IN_ALL
diff --git a/src/libide/gui/ide-workbench.c b/src/libide/gui/ide-workbench.c
index 7f29b7570..d6fa8d4e2 100644
--- a/src/libide/gui/ide-workbench.c
+++ b/src/libide/gui/ide-workbench.c
@@ -2669,6 +2669,7 @@ ide_workbench_action_configure (IdeWorkbench *self,
window = g_object_new (IDE_TYPE_PREFERENCES_WINDOW,
"mode", IDE_PREFERENCES_MODE_PROJECT,
+ "context", self->context,
"default-width", 1050,
"default-height", 700,
"title", window_title,
diff --git a/src/libide/gui/tests/test-preferences.c b/src/libide/gui/tests/test-preferences.c
index 19725eb2d..0b362f038 100644
--- a/src/libide/gui/tests/test-preferences.c
+++ b/src/libide/gui/tests/test-preferences.c
@@ -111,7 +111,7 @@ main (int argc,
g_resources_register (ide_gui_get_resource ());
main_loop = g_main_loop_new (NULL, FALSE);
- window = IDE_PREFERENCES_WINDOW (ide_preferences_window_new (IDE_PREFERENCES_MODE_EMPTY));
+ window = IDE_PREFERENCES_WINDOW (ide_preferences_window_new (IDE_PREFERENCES_MODE_EMPTY, NULL));
gtk_window_set_default_size (GTK_WINDOW (window), 1200, 900);
diff --git a/src/plugins/clang/ide-clang-preferences-addin.c b/src/plugins/clang/ide-clang-preferences-addin.c
index fedc86c47..e8520626d 100644
--- a/src/plugins/clang/ide-clang-preferences-addin.c
+++ b/src/plugins/clang/ide-clang-preferences-addin.c
@@ -70,12 +70,14 @@ static const IdePreferenceItemEntry items[] = {
static void
ide_clang_preferences_addin_load (IdePreferencesAddin *addin,
- IdePreferencesWindow *window)
+ IdePreferencesWindow *window,
+ IdeContext *context)
{
IDE_ENTRY;
g_assert (IDE_IS_CLANG_PREFERENCES_ADDIN (addin));
g_assert (IDE_IS_PREFERENCES_WINDOW (window));
+ g_assert (!context || IDE_IS_CONTEXT (context));
ide_preferences_window_add_groups (window, groups, G_N_ELEMENTS (groups), NULL);
ide_preferences_window_add_items (window, items, G_N_ELEMENTS (items), window, NULL);
@@ -85,12 +87,14 @@ ide_clang_preferences_addin_load (IdePreferencesAddin *addin,
static void
ide_clang_preferences_addin_unload (IdePreferencesAddin *addin,
- IdePreferencesWindow *window)
+ IdePreferencesWindow *window,
+ IdeContext *context)
{
IDE_ENTRY;
g_assert (IDE_IS_CLANG_PREFERENCES_ADDIN (addin));
g_assert (IDE_IS_PREFERENCES_WINDOW (window));
+ g_assert (!context || IDE_IS_CONTEXT (context));
/* TODO: Remove gsettings switches */
diff --git a/src/plugins/editorui/gbp-editorui-preferences-addin.c
b/src/plugins/editorui/gbp-editorui-preferences-addin.c
index 8b077198b..06b9dfac5 100644
--- a/src/plugins/editorui/gbp-editorui-preferences-addin.c
+++ b/src/plugins/editorui/gbp-editorui-preferences-addin.c
@@ -250,11 +250,13 @@ ide_preferences_builtin_add_schemes (const char *page_name,
}
static void
-gbp_editorui_preferences_addin_add_languages (IdePreferencesWindow *window)
+gbp_editorui_preferences_addin_add_languages (IdePreferencesWindow *window,
+ const char *lang_path)
{
GtkSourceLanguageManager *langs;
const char * const *lang_ids;
IdePreferencePageEntry *lpages;
+ IdePreferenceItemEntry _items[G_N_ELEMENTS (lang_items)];
guint j = 0;
g_assert (IDE_IS_PREFERENCES_WINDOW (window));
@@ -287,8 +289,12 @@ gbp_editorui_preferences_addin_add_languages (IdePreferencesWindow *window)
for (guint i = 0; i < j; i++)
lpages[i].priority = i;
+ memcpy (_items, lang_items, sizeof _items);
+ for (guint i = 0; i < G_N_ELEMENTS (_items); i++)
+ _items[i].path = lang_path;
+
ide_preferences_window_add_pages (window, lpages, j, NULL);
- ide_preferences_window_add_items (window, lang_items, G_N_ELEMENTS (lang_items), window, NULL);
+ ide_preferences_window_add_items (window, _items, G_N_ELEMENTS (_items), window, NULL);
g_free (lpages);
}
@@ -296,26 +302,36 @@ gbp_editorui_preferences_addin_add_languages (IdePreferencesWindow *window)
static void
gbp_editorui_preferences_addin_load (IdePreferencesAddin *addin,
- IdePreferencesWindow *window)
+ IdePreferencesWindow *window,
+ IdeContext *context)
{
GbpEditoruiPreferencesAddin *self = (GbpEditoruiPreferencesAddin *)addin;
+ IdePreferencesMode mode;
IDE_ENTRY;
g_assert (IDE_IS_MAIN_THREAD ());
g_assert (GBP_IS_EDITORUI_PREFERENCES_ADDIN (self));
g_assert (IDE_IS_PREFERENCES_WINDOW (window));
+ g_assert (!context || IDE_IS_CONTEXT (context));
+
+ mode = ide_preferences_window_get_mode (window);
- if (ide_preferences_window_get_mode (window) == IDE_PREFERENCES_MODE_APPLICATION)
+ if (mode == IDE_PREFERENCES_MODE_APPLICATION)
{
ide_preferences_window_add_groups (window, groups, G_N_ELEMENTS (groups), NULL);
ide_preferences_window_add_items (window, items, G_N_ELEMENTS (items), window, NULL);
ide_preferences_window_add_item (window, "appearance", "preview", "scheme", 0,
ide_preferences_builtin_add_schemes, window, NULL);
+ gbp_editorui_preferences_addin_add_languages (window, LANG_PATH);
}
+ else if (mode == IDE_PREFERENCES_MODE_PROJECT && IDE_IS_CONTEXT (context))
+ {
+ g_autofree char *project_id = ide_context_dup_project_id (context);
+ g_autofree char *project_lang_path = g_strdup_printf ("/org/gnome/builder/projects/%s/languages/*",
project_id);
- /* TODO: Apply prefix for project overrides! */
- gbp_editorui_preferences_addin_add_languages (window);
+ gbp_editorui_preferences_addin_add_languages (window, project_lang_path);
+ }
IDE_EXIT;
}
diff --git a/src/plugins/quick-highlight/gbp-quick-highlight-preferences.c
b/src/plugins/quick-highlight/gbp-quick-highlight-preferences.c
index 744a33c17..155e990b3 100644
--- a/src/plugins/quick-highlight/gbp-quick-highlight-preferences.c
+++ b/src/plugins/quick-highlight/gbp-quick-highlight-preferences.c
@@ -53,7 +53,8 @@ static const IdePreferenceItemEntry items[] = {
static void
gbp_quick_highlight_preferences_load (IdePreferencesAddin *addin,
- IdePreferencesWindow *window)
+ IdePreferencesWindow *window,
+ IdeContext *context)
{
GbpQuickHighlightPreferences *self = (GbpQuickHighlightPreferences *)addin;
diff --git a/src/plugins/rust-analyzer/rust-analyzer-preferences-addin.c
b/src/plugins/rust-analyzer/rust-analyzer-preferences-addin.c
index dfb336e6c..13cb83c91 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-preferences-addin.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-preferences-addin.c
@@ -51,7 +51,8 @@ static const IdePreferenceItemEntry items[] = {
static void
rust_analyzer_preferences_addin_load (IdePreferencesAddin *addin,
- IdePreferencesWindow *window)
+ IdePreferencesWindow *window,
+ IdeContext *context)
{
RustAnalyzerPreferencesAddin *self = (RustAnalyzerPreferencesAddin *)addin;
@@ -68,7 +69,8 @@ rust_analyzer_preferences_addin_load (IdePreferencesAddin *addin,
static void
rust_analyzer_preferences_addin_unload (IdePreferencesAddin *addin,
- IdePreferencesWindow *window)
+ IdePreferencesWindow *window,
+ IdeContext *context)
{
IDE_ENTRY;
diff --git a/src/plugins/spellcheck/gbp-spell-preferences-addin.c
b/src/plugins/spellcheck/gbp-spell-preferences-addin.c
index f99feb1fa..f53ad3104 100644
--- a/src/plugins/spellcheck/gbp-spell-preferences-addin.c
+++ b/src/plugins/spellcheck/gbp-spell-preferences-addin.c
@@ -46,7 +46,8 @@ static const IdePreferenceItemEntry items[] = {
static void
gbp_spell_preferences_addin_load (IdePreferencesAddin *addin,
- IdePreferencesWindow *window)
+ IdePreferencesWindow *window,
+ IdeContext *context)
{
GbpSpellPreferencesAddin *self = (GbpSpellPreferencesAddin *)addin;
@@ -63,7 +64,8 @@ gbp_spell_preferences_addin_load (IdePreferencesAddin *addin,
static void
gbp_spell_preferences_addin_unload (IdePreferencesAddin *addin,
- IdePreferencesWindow *window)
+ IdePreferencesWindow *window,
+ IdeContext *context)
{
GbpSpellPreferencesAddin *self = (GbpSpellPreferencesAddin *)addin;
diff --git a/src/plugins/vim/gbp-vim-preferences-addin.c b/src/plugins/vim/gbp-vim-preferences-addin.c
index 232dea357..ce99b63ed 100644
--- a/src/plugins/vim/gbp-vim-preferences-addin.c
+++ b/src/plugins/vim/gbp-vim-preferences-addin.c
@@ -42,7 +42,8 @@ static const IdePreferenceItemEntry items[] = {
static void
gbp_vim_preferences_addin_load (IdePreferencesAddin *addin,
- IdePreferencesWindow *window)
+ IdePreferencesWindow *window,
+ IdeContext *context)
{
GbpVimPreferencesAddin *self = (GbpVimPreferencesAddin *)addin;
@@ -58,7 +59,8 @@ gbp_vim_preferences_addin_load (IdePreferencesAddin *addin,
static void
gbp_vim_preferences_addin_unload (IdePreferencesAddin *addin,
- IdePreferencesWindow *window)
+ IdePreferencesWindow *window,
+ IdeContext *context)
{
GbpVimPreferencesAddin *self = (GbpVimPreferencesAddin *)addin;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]