diff options
author | Joaquim Rocha <me@joaquimrocha.com> | 2015-02-26 22:10:40 +0100 |
---|---|---|
committer | Rui Matos <tiagomatos@gmail.com> | 2015-03-19 20:01:55 +0100 |
commit | fe3e71b60ebabffa596920ad20a247870e857e65 (patch) | |
tree | ead26e1f1593d0169067921e29a1af79ad2fd5e9 | |
parent | 43b3bed8e038e2ce6ad418de0b70873336c1420e (diff) | |
download | gnome-control-center-fe3e71b60ebabffa596920ad20a247870e857e65.tar.gz |
region: Reuse the input chooser instance
The language input chooser is being created and destroyed every time
it is opened and closed. This is noticeably slow and is hardly
necessary as the values it contains should not change.
To fix this, these changes reuse the same instance of the input chooser
(by hiding and showing it) instead of renewing it.
The input chooser is also now shown using gtk_dialog_run to avoid having
it destroyed from the default delete event.
-rw-r--r-- | panels/region/cc-input-chooser.c | 7 | ||||
-rw-r--r-- | panels/region/cc-input-chooser.h | 2 | ||||
-rw-r--r-- | panels/region/cc-region-panel.c | 41 |
3 files changed, 33 insertions, 17 deletions
diff --git a/panels/region/cc-input-chooser.c b/panels/region/cc-input-chooser.c index 13500fb7a..297b79eb2 100644 --- a/panels/region/cc-input-chooser.c +++ b/panels/region/cc-input-chooser.c @@ -394,6 +394,7 @@ show_input_sources_for_locale (GtkWidget *chooser, gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->list)); gtk_list_box_set_selection_mode (GTK_LIST_BOX (priv->list), GTK_SELECTION_SINGLE); gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (priv->list), FALSE); + gtk_list_box_unselect_all (GTK_LIST_BOX (priv->list)); if (gtk_widget_is_visible (priv->filter_entry) && !gtk_widget_is_focus (priv->filter_entry)) @@ -1221,3 +1222,9 @@ cc_input_chooser_get_selected (GtkWidget *chooser, return TRUE; } + +void +cc_input_chooser_reset (GtkWidget *chooser) +{ + show_locale_rows (chooser); +} diff --git a/panels/region/cc-input-chooser.h b/panels/region/cc-input-chooser.h index fd6ac979c..d552abfde 100644 --- a/panels/region/cc-input-chooser.h +++ b/panels/region/cc-input-chooser.h @@ -36,6 +36,8 @@ gboolean cc_input_chooser_get_selected (GtkWidget *chooser, gchar **id, gchar **name); +void cc_input_chooser_reset (GtkWidget *chooser); + G_END_DECLS #endif /* __CC_INPUT_CHOOSER_H__ */ diff --git a/panels/region/cc-region-panel.c b/panels/region/cc-region-panel.c index b045c341c..e89268bc2 100644 --- a/panels/region/cc-region-panel.c +++ b/panels/region/cc-region-panel.c @@ -127,6 +127,7 @@ cc_region_panel_finalize (GObject *object) { CcRegionPanel *self = CC_REGION_PANEL (object); CcRegionPanelPrivate *priv = self->priv; + GtkWidget *chooser; g_cancellable_cancel (priv->cancellable); g_clear_object (&priv->cancellable); @@ -160,6 +161,9 @@ cc_region_panel_finalize (GObject *object) g_free (priv->system_language); g_free (priv->system_region); + chooser = g_object_get_data (G_OBJECT (self), "input-chooser"); + gtk_widget_destroy (chooser); + G_OBJECT_CLASS (cc_region_panel_parent_class)->finalize (object); } @@ -1121,16 +1125,14 @@ input_source_already_added (CcRegionPanel *self, } static void -input_response (GtkWidget *chooser, gint response_id, gpointer data) +run_input_chooser (CcRegionPanel *self, GtkWidget *chooser) { - CcRegionPanel *self = data; - CcRegionPanelPrivate *priv = self->priv; gchar *type; gchar *id; gchar *name; GDesktopAppInfo *app_info = NULL; - if (response_id == GTK_RESPONSE_OK) { + if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_OK) { if (cc_input_chooser_get_selected (chooser, &type, &id, &name) && !input_source_already_added (self, id)) { if (g_str_equal (type, INPUT_SOURCE_TYPE_IBUS)) { @@ -1144,7 +1146,7 @@ input_response (GtkWidget *chooser, gint response_id, gpointer data) type = INPUT_SOURCE_TYPE_XKB; } - if (priv->login && g_str_equal (type, INPUT_SOURCE_TYPE_IBUS)) { + if (self->priv->login && g_str_equal (type, INPUT_SOURCE_TYPE_IBUS)) { apologize_for_no_ibus_login (self); } else { add_input_row (self, type, id, name, app_info); @@ -1156,8 +1158,7 @@ input_response (GtkWidget *chooser, gint response_id, gpointer data) g_clear_object (&app_info); } } - gtk_widget_destroy (chooser); - g_object_set_data (G_OBJECT (self), "input-chooser", NULL); + gtk_widget_hide(chooser); } static void @@ -1167,20 +1168,26 @@ show_input_chooser (CcRegionPanel *self) GtkWidget *chooser; GtkWidget *toplevel; - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self)); - chooser = cc_input_chooser_new (GTK_WINDOW (toplevel), - priv->xkb_info, + chooser = g_object_get_data (G_OBJECT (self), "input-chooser"); + + if (!chooser) { + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self)); + chooser = cc_input_chooser_new (GTK_WINDOW (toplevel), + priv->xkb_info, #ifdef HAVE_IBUS - priv->ibus_engines + priv->ibus_engines #else - NULL + NULL #endif - ); - g_signal_connect (chooser, "response", - G_CALLBACK (input_response), self); - gtk_window_present (GTK_WINDOW (chooser)); + ); + g_object_ref (chooser); + g_object_set_data_full (G_OBJECT (self), "input-chooser", + chooser, g_object_unref); + } else { + cc_input_chooser_reset (chooser); + } - g_object_set_data (G_OBJECT (self), "input-chooser", chooser); + run_input_chooser (self, chooser); } static void |