[gnome-builder/wip/gtk4-port: 1461/1774] libide/gui: add helper to go to preferences page
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 1461/1774] libide/gui: add helper to go to preferences page
- Date: Mon, 11 Jul 2022 22:31:46 +0000 (UTC)
commit ae0fef534a9bf7656c3be6c682b1bbb25218eb96
Author: Christian Hergert <chergert redhat com>
Date: Fri Jun 10 15:23:05 2022 -0700
libide/gui: add helper to go to preferences page
src/libide/gui/ide-application-actions.c | 19 +++++++++----
src/libide/gui/ide-preferences-window.c | 46 +++++++++++++++++++++++++++-----
src/libide/gui/ide-preferences-window.h | 3 +++
3 files changed, 56 insertions(+), 12 deletions(-)
---
diff --git a/src/libide/gui/ide-application-actions.c b/src/libide/gui/ide-application-actions.c
index 5c76de0b2..19e5a7e76 100644
--- a/src/libide/gui/ide-application-actions.c
+++ b/src/libide/gui/ide-application-actions.c
@@ -41,6 +41,7 @@ ide_application_actions_preferences (GSimpleAction *action,
gpointer user_data)
{
IdeApplication *self = user_data;
+ const char *page = NULL;
IdeContext *context = NULL;
GtkWindow *toplevel = NULL;
GtkWindow *window;
@@ -51,6 +52,10 @@ ide_application_actions_preferences (GSimpleAction *action,
g_assert (G_IS_SIMPLE_ACTION (action));
g_assert (IDE_IS_APPLICATION (self));
+ if (parameter != NULL &&
+ g_variant_is_of_type (parameter, G_VARIANT_TYPE_STRING))
+ page = g_variant_get_string (parameter, NULL);
+
/* Locate a toplevel for a transient-for property, or a previous
* preferences window to display.
*/
@@ -88,6 +93,9 @@ ide_application_actions_preferences (GSimpleAction *action,
gtk_application_add_window (GTK_APPLICATION (self), window);
ide_gtk_window_present (window);
+ if (page != NULL)
+ ide_preferences_window_set_page (IDE_PREFERENCES_WINDOW (window), page);
+
IDE_EXIT;
}
@@ -356,12 +364,13 @@ ide_application_actions_stats (GSimpleAction *action,
}
static const GActionEntry IdeApplicationActions[] = {
- { "about:types", ide_application_actions_stats },
- { "about", ide_application_actions_about },
+ { "about:types", ide_application_actions_stats },
+ { "about", ide_application_actions_about },
{ "load-project", ide_application_actions_load_project, "s"},
- { "preferences", ide_application_actions_preferences },
- { "quit", ide_application_actions_quit },
- { "help", ide_application_actions_help },
+ { "preferences", ide_application_actions_preferences },
+ { "preferences-page", ide_application_actions_preferences, "s" },
+ { "quit", ide_application_actions_quit },
+ { "help", ide_application_actions_help },
};
void
diff --git a/src/libide/gui/ide-preferences-window.c b/src/libide/gui/ide-preferences-window.c
index ff7186ac4..c9bfd5aad 100644
--- a/src/libide/gui/ide-preferences-window.c
+++ b/src/libide/gui/ide-preferences-window.c
@@ -688,21 +688,17 @@ get_project_title (IdePreferencesWindow *self)
}
static void
-ide_preferences_window_page_activated_cb (IdePreferencesWindow *self,
- GtkListBoxRow *row,
- GtkListBox *list_box)
+ide_preferences_window_set_page_entry (IdePreferencesWindow *self,
+ const IdePreferencePageEntry *entry)
{
g_autofree char *project_title = NULL;
- const IdePreferencePageEntry *entry;
const IdePreferencePageEntry *parent;
AdwPreferencesPage *page;
GtkWidget *visible_child;
g_assert (IDE_IS_PREFERENCES_WINDOW (self));
- g_assert (GTK_IS_LIST_BOX_ROW (row));
- g_assert (GTK_IS_LIST_BOX (list_box));
+ g_assert (entry != NULL);
- entry = g_object_get_data (G_OBJECT (row), "ENTRY");
if (entry == self->current_page)
return;
@@ -792,6 +788,25 @@ ide_preferences_window_page_activated_cb (IdePreferencesWindow *self,
drop_page_free);
}
+static void
+ide_preferences_window_page_activated_cb (IdePreferencesWindow *self,
+ GtkListBoxRow *row,
+ GtkListBox *list_box)
+{
+ const IdePreferencePageEntry *entry;
+
+ g_assert (IDE_IS_PREFERENCES_WINDOW (self));
+ g_assert (GTK_IS_LIST_BOX_ROW (row));
+ g_assert (GTK_IS_LIST_BOX (list_box));
+
+ entry = g_object_get_data (G_OBJECT (row), "ENTRY");
+
+ if (entry == self->current_page)
+ return;
+
+ ide_preferences_window_set_page_entry (self, entry);
+}
+
static void
create_navigation_page (IdePreferencesWindow *self,
Page **out_page)
@@ -849,6 +864,8 @@ ide_preferences_window_rebuild (IdePreferencesWindow *self)
g_assert (IDE_IS_PREFERENCES_WINDOW (self));
+ g_clear_handle_id (&self->rebuild_source, g_source_remove);
+
/* Remove old widgets */
for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self->pages_stack));
child != NULL;
@@ -1604,3 +1621,18 @@ ide_preferences_window_get_context (IdePreferencesWindow *self)
return self->context;
}
+
+void
+ide_preferences_window_set_page (IdePreferencesWindow *self,
+ const char *page)
+{
+ const IdePreferencePageEntry *p;
+
+ g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (self));
+ g_return_if_fail (page != NULL);
+
+ ide_preferences_window_rebuild (self);
+
+ if ((p = get_page (self, page)))
+ ide_preferences_window_set_page_entry (self, p);
+}
diff --git a/src/libide/gui/ide-preferences-window.h b/src/libide/gui/ide-preferences-window.h
index 150651035..b5878f377 100644
--- a/src/libide/gui/ide-preferences-window.h
+++ b/src/libide/gui/ide-preferences-window.h
@@ -97,6 +97,9 @@ IdePreferencesMode ide_preferences_window_get_mode (IdePreferencesWindow
IDE_AVAILABLE_IN_ALL
IdeContext *ide_preferences_window_get_context (IdePreferencesWindow *self);
IDE_AVAILABLE_IN_ALL
+void ide_preferences_window_set_page (IdePreferencesWindow *self,
+ const char *page);
+IDE_AVAILABLE_IN_ALL
void ide_preferences_window_add_pages (IdePreferencesWindow *self,
const IdePreferencePageEntry *pages,
gsize n_pages,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]