Commit abb05928 authored by Joaquim Rocha's avatar Joaquim Rocha
Browse files

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.
parent bd6347d0
......@@ -395,6 +395,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))
......@@ -1227,3 +1228,9 @@ cc_input_chooser_get_selected (GtkWidget *chooser,
return TRUE;
}
void
cc_input_chooser_reset (GtkWidget *chooser)
{
show_locale_rows (chooser);
}
......@@ -37,6 +37,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__ */
......@@ -131,6 +131,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);
......@@ -164,6 +165,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);
}
......@@ -1110,15 +1114,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;
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)) {
......@@ -1141,8 +1144,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
......@@ -1152,21 +1154,27 @@ 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->login,
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->login,
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment