[gnome-builder] prefs: move preferences to an external window
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] prefs: move preferences to an external window
- Date: Mon, 25 Sep 2017 07:04:00 +0000 (UTC)
commit 77aa1b7677afb686857a96e8be80d5fe4492fe0d
Author: Christian Hergert <chergert redhat com>
Date: Mon Sep 25 00:00:20 2017 -0700
prefs: move preferences to an external window
This moves the preferences to an external window instead of
using a perspective within the parent window. This useful for
couple of reasons:
* It allows us to use the preferences outside of the workbench
such as during the greeter phase.
* It allows us to destroy widgets when they aren't visible.
There are lots created in preferences, so this is a sort of
nice thing from a memory usage standpoint.
* Reduce the time it takes to open a project since it would
add the preferences as part of that phase.
src/libide/application/ide-application-actions.c | 79 ++++++++++----------
src/libide/application/ide-application-shortcuts.c | 8 ++
src/libide/gtk/menus.ui | 9 --
src/libide/workbench/ide-workbench.c | 8 --
4 files changed, 46 insertions(+), 58 deletions(-)
---
diff --git a/src/libide/application/ide-application-actions.c
b/src/libide/application/ide-application-actions.c
index f78933b..bac81ef 100644
--- a/src/libide/application/ide-application-actions.c
+++ b/src/libide/application/ide-application-actions.c
@@ -31,9 +31,10 @@
#include "application/ide-application-actions.h"
#include "application/ide-application-credits.h"
#include "application/ide-application-private.h"
+#include "greeter/ide-greeter-perspective.h"
#include "keybindings/ide-shortcuts-window.h"
+#include "preferences/ide-preferences-perspective.h"
#include "workbench/ide-workbench.h"
-#include "greeter/ide-greeter-perspective.h"
#include "util/ide-flatpak.h"
static void
@@ -42,35 +43,55 @@ ide_application_actions_preferences (GSimpleAction *action,
gpointer user_data)
{
IdeApplication *self = user_data;
+ IdePreferencesPerspective *perspective;
GList *windows;
+ GtkWindow *toplevel = NULL;
+ GtkWindow *window;
IDE_ENTRY;
+ g_assert (G_IS_SIMPLE_ACTION (action));
g_assert (IDE_IS_APPLICATION (self));
- /*
- * TODO: Make this work at the greeter screen too.
+ /* Locate a toplevel for a transient-for property, or a previous
+ * preferences window to display.
*/
-
windows = gtk_application_get_windows (GTK_APPLICATION (self));
-
- for (; windows; windows = windows->next)
+ for (; windows != NULL; windows = windows->next)
{
- GtkWindow *window = windows->data;
- const gchar *name;
+ GtkWindow *ele = windows->data;
- if (!IDE_IS_WORKBENCH (window))
- continue;
-
- name = ide_workbench_get_visible_perspective_name (IDE_WORKBENCH (window));
-
- if (!ide_str_equal0 (name, "greeter") && !ide_str_equal0 (name, "genesis"))
+ if (g_object_get_data (G_OBJECT (ele), "PREFERENCES"))
{
- ide_workbench_set_visible_perspective_name (IDE_WORKBENCH (window), "preferences");
- IDE_EXIT;
+ gtk_window_present (ele);
+ return;
}
+
+ if (toplevel == NULL && IDE_IS_WORKBENCH (ele))
+ toplevel = ele;
}
+ /* Create a new window for preferences, with enough space for
+ * 2 columns of preferences. The window manager will automatically
+ * maximize the window if necessary.
+ */
+ window = g_object_new (GTK_TYPE_WINDOW,
+ "transient-for", toplevel,
+ "title", _("Preferences"),
+ "default-width", 1300,
+ "default-height", 800,
+ "window-position", GTK_WIN_POS_CENTER_ON_PARENT,
+ NULL);
+ g_object_set_data (G_OBJECT (window), "PREFERENCES", "1");
+ gtk_application_add_window (GTK_APPLICATION (self), window);
+
+ perspective = g_object_new (IDE_TYPE_PREFERENCES_PERSPECTIVE,
+ "visible", TRUE,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (perspective));
+
+ gtk_window_present (GTK_WINDOW (window));
+
IDE_EXIT;
}
@@ -425,31 +446,7 @@ ide_application_actions_init (IdeApplication *self)
void
ide_application_actions_update (IdeApplication *self)
{
- GList *windows;
- GAction *action;
- gboolean enabled;
-
g_assert (IDE_IS_APPLICATION (self));
- /*
- * We only enable the preferences action if we have a workbench open
- * that is past the greeter.
- */
- action = g_action_map_lookup_action (G_ACTION_MAP (self), "preferences");
- enabled = FALSE;
- for (windows = gtk_application_get_windows (GTK_APPLICATION (self));
- windows != NULL;
- windows = windows->next)
- {
- GtkWindow *window = windows->data;
-
- if (IDE_IS_WORKBENCH (window) &&
- !ide_str_equal0 ("greeter",
- ide_workbench_get_visible_perspective_name (IDE_WORKBENCH (window))))
- {
- enabled = TRUE;
- break;
- }
- }
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
+ /* Nothing to do currently */
}
diff --git a/src/libide/application/ide-application-shortcuts.c
b/src/libide/application/ide-application-shortcuts.c
index bd4e7df..e368694 100644
--- a/src/libide/application/ide-application-shortcuts.c
+++ b/src/libide/application/ide-application-shortcuts.c
@@ -47,6 +47,14 @@ _ide_application_init_shortcuts (IdeApplication *self)
dzl_shortcut_theme_set_accel_for_action (theme, "app.help", "F1", DZL_SHORTCUT_PHASE_DISPATCH);
dzl_shortcut_manager_add_action (manager,
+ I_("app.preferences"),
+ NC_("shortcut window", "Workbench shortcuts"),
+ NC_("shortcut window", "Preferences"),
+ NC_("shortcut window", "Show the preferences window"),
+ NULL);
+ dzl_shortcut_theme_set_accel_for_action (theme, "app.preferences", "<Primary>comma",
DZL_SHORTCUT_PHASE_DISPATCH);
+
+ dzl_shortcut_manager_add_action (manager,
I_("app.shortcuts"),
NC_("shortcut window", "Workbench shortcuts"),
NC_("shortcut window", "Help"),
diff --git a/src/libide/gtk/menus.ui b/src/libide/gtk/menus.ui
index acc05a1..6c01f71 100644
--- a/src/libide/gtk/menus.ui
+++ b/src/libide/gtk/menus.ui
@@ -53,15 +53,6 @@
<attribute name="target">buildperspective</attribute>
<attribute name="verb-icon-name">builder-build-configure-symbolic</attribute>
</item>
- <item>
- <attribute name="accel"><primary>comma</attribute>
- <attribute name="action">win.perspective</attribute>
- <attribute name="id">perspective-menu-prefs</attribute>
- <attribute name="label" translatable="yes">Preferences</attribute>
- <attribute name="role">normal</attribute>
- <attribute name="target">preferences</attribute>
- <attribute name="verb-icon-name">preferences-system-symbolic</attribute>
- </item>
</section>
</menu>
<menu id="gear-menu">
diff --git a/src/libide/workbench/ide-workbench.c b/src/libide/workbench/ide-workbench.c
index 2ecd675..fb3fe17 100644
--- a/src/libide/workbench/ide-workbench.c
+++ b/src/libide/workbench/ide-workbench.c
@@ -675,14 +675,6 @@ ide_workbench_set_context (IdeWorkbench *self,
peas_extension_set_foreach (self->addins, ide_workbench_addin_added, self);
- /* We wait to add the preferences perspective until we have a valid
- * IdeContext for them to potentially use.
- */
- ide_workbench_add_perspective (self,
- g_object_new (IDE_TYPE_PREFERENCES_PERSPECTIVE,
- "visible", TRUE,
- NULL));
-
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CONTEXT]);
/*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]