shell: Remember the last used panel

And restore it if the application is launched without any panels
requested.

https://bugzilla.gnome.org/show_bug.cgi?id=786607
This commit is contained in:
Bastien Nocera 2017-08-22 18:10:25 +02:00
parent f092ca00eb
commit 10738d68c6
4 changed files with 31 additions and 2 deletions

View file

@ -16,6 +16,7 @@ control_center_sysconfdir = join_paths(control_center_prefix, get_option('syscon
control_center_pkgdatadir = join_paths(control_center_datadir, meson.project_name())
control_center_desktopdir = join_paths(control_center_datadir, 'applications')
control_center_icondir = join_paths(control_center_datadir, 'icons')
control_center_schemadir = join_paths (control_center_datadir, 'glib-2.0', 'schemas')
control_center_gettext = meson.project_name() + '-2.0'

View file

@ -74,6 +74,7 @@ struct _CcWindow
GtkListStore *store;
CcPanel *active_panel;
GSettings *settings;
};
static void cc_shell_iface_init (CcShellInterface *iface);
@ -123,6 +124,8 @@ activate_panel (CcWindow *self,
if (!id)
return FALSE;
g_settings_set_string (self->settings, "last-panel", id);
self->current_panel = GTK_WIDGET (cc_panel_loader_load_by_name (CC_SHELL (self), id, parameters));
cc_shell_set_active_panel (CC_SHELL (self), CC_PANEL (self->current_panel));
gtk_widget_show (self->current_panel);
@ -664,6 +667,8 @@ cc_window_finalize (GObject *object)
self->previous_panels = NULL;
}
g_clear_object (&self->settings);
G_OBJECT_CLASS (cc_window_parent_class)->finalize (object);
}
@ -713,11 +718,14 @@ static void
cc_window_init (CcWindow *self)
{
GtkSettings *settings;
g_autofree char *id = NULL;
gtk_widget_init_template (GTK_WIDGET (self));
gtk_widget_add_events (GTK_WIDGET (self), GDK_BUTTON_RELEASE_MASK);
self->settings = g_settings_new ("org.gnome.ControlCenter");
/* Handle decorations for the split headers. */
settings = gtk_settings_get_default ();
g_signal_connect (settings,
@ -733,7 +741,12 @@ cc_window_init (CcWindow *self)
setup_model (self);
/* After everything is loaded, select the first visible panel */
/* After everything is loaded, select the last used panel, if any,
* or the first visible panel */
id = g_settings_get_string (self->settings, "last-panel");
if (id != NULL && *id != '\0')
cc_panel_list_set_active_panel (CC_PANEL_LIST (self->panel_list), id);
else
cc_panel_list_activate (CC_PANEL_LIST (self->panel_list));
}

View file

@ -133,3 +133,6 @@ exe = executable(
)
test(test_unit, exe)
install_data ('org.gnome.ControlCenter.gschema.xml',
install_dir: control_center_schemadir)

View file

@ -0,0 +1,12 @@
<schemalist>
<schema id="org.gnome.ControlCenter" path="/org/gnome/control-center/">
<key name="last-panel" type="s">
<default>''</default>
<summary>The identifier for the last Settings panel to be opened</summary>
<description>
The identifier for the last Settings panel to be opened. Unrecognised values
will be ignored and the first panel in the list selected.
</description>
</key>
</schema>
</schemalist>