[gedit] Use a template for the encodings dialog
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Use a template for the encodings dialog
- Date: Thu, 25 Apr 2013 12:27:49 +0000 (UTC)
commit 582737521a9428f0b3bcb843efdfab2fed9715c5
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Thu Apr 25 14:27:02 2013 +0200
Use a template for the encodings dialog
gedit/gedit-encodings-combo-box.c | 5 +-
gedit/gedit-encodings-dialog.c | 140 ++++++++++++++-----------------------
gedit/gedit-encodings-dialog.ui | 28 ++++---
gedit/gedit-preferences-dialog.c | 2 +-
4 files changed, 74 insertions(+), 101 deletions(-)
---
diff --git a/gedit/gedit-encodings-combo-box.c b/gedit/gedit-encodings-combo-box.c
index 1d1514b..68db99e 100644
--- a/gedit/gedit-encodings-combo-box.c
+++ b/gedit/gedit-encodings-combo-box.c
@@ -187,7 +187,10 @@ dialog_response_cb (GtkDialog *dialog,
update_menu (menu);
}
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ if (response_id != GTK_RESPONSE_HELP)
+ {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ }
}
static void
diff --git a/gedit/gedit-encodings-dialog.c b/gedit/gedit-encodings-dialog.c
index 442e77c..a6b297d 100644
--- a/gedit/gedit-encodings-dialog.c
+++ b/gedit/gedit-encodings-dialog.c
@@ -54,7 +54,9 @@ struct _GeditEncodingsDialogPrivate
GSettings *enc_settings;
GtkListStore *available_liststore;
+ GtkTreeModel *sort_available;
GtkListStore *displayed_liststore;
+ GtkTreeModel *sort_displayed;
GtkWidget *available_treeview;
GtkWidget *displayed_treeview;
GtkWidget *add_button;
@@ -81,18 +83,66 @@ gedit_encodings_dialog_dispose (GObject *object)
GeditEncodingsDialogPrivate *priv = GEDIT_ENCODINGS_DIALOG (object)->priv;
g_clear_object (&priv->enc_settings);
+ g_message ("disposed");
G_OBJECT_CLASS (gedit_encodings_dialog_parent_class)->dispose (object);
}
static void
+gedit_encodings_dialog_response (GtkDialog *dialog,
+ gint response_id)
+{
+ GeditEncodingsDialogPrivate *priv = GEDIT_ENCODINGS_DIALOG (dialog)->priv;
+
+ switch (response_id)
+ {
+ case GTK_RESPONSE_HELP:
+ gedit_app_show_help (GEDIT_APP (g_application_get_default ()),
+ GTK_WINDOW (dialog),
+ "gedit",
+ NULL);
+ break;
+
+ case GTK_RESPONSE_OK:
+ {
+ gchar **encs;
+
+ encs = _gedit_encoding_list_to_strv (priv->show_in_menu_list);
+ g_settings_set_strv (priv->enc_settings,
+ GEDIT_SETTINGS_ENCODING_SHOWN_IN_MENU,
+ (const gchar * const *)encs);
+
+ g_strfreev (encs);
+ }
+ default:
+ break;
+ }
+}
+
+static void
gedit_encodings_dialog_class_init (GeditEncodingsDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
object_class->finalize = gedit_encodings_dialog_finalize;
object_class->dispose = gedit_encodings_dialog_dispose;
+ dialog_class->response = gedit_encodings_dialog_response;
+
+ /* Bind class to template */
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/gedit/ui/gedit-encodings-dialog.ui");
+ gtk_widget_class_bind_child (widget_class, GeditEncodingsDialogPrivate, add_button);
+ gtk_widget_class_bind_child (widget_class, GeditEncodingsDialogPrivate, remove_button);
+ gtk_widget_class_bind_child (widget_class, GeditEncodingsDialogPrivate, available_treeview);
+ gtk_widget_class_bind_child (widget_class, GeditEncodingsDialogPrivate, available_liststore);
+ gtk_widget_class_bind_child (widget_class, GeditEncodingsDialogPrivate, sort_available);
+ gtk_widget_class_bind_child (widget_class, GeditEncodingsDialogPrivate, displayed_treeview);
+ gtk_widget_class_bind_child (widget_class, GeditEncodingsDialogPrivate, displayed_liststore);
+ gtk_widget_class_bind_child (widget_class, GeditEncodingsDialogPrivate, sort_displayed);
+
g_type_class_add_private (object_class, sizeof (GeditEncodingsDialogPrivate));
}
@@ -284,106 +334,22 @@ init_shown_in_menu_tree_model (GeditEncodingsDialog *dialog)
}
static void
-response_handler (GtkDialog *dialog,
- gint response_id,
- GeditEncodingsDialog *dlg)
-{
- if (response_id == GTK_RESPONSE_HELP)
- {
- gedit_app_show_help (GEDIT_APP (g_application_get_default ()),
- GTK_WINDOW (dialog),
- "gedit",
- NULL);
-
- g_signal_stop_emission_by_name (dialog, "response");
- return;
- }
-
- if (response_id == GTK_RESPONSE_OK)
- {
- gchar **encs;
-
- encs = _gedit_encoding_list_to_strv (dlg->priv->show_in_menu_list);
- g_settings_set_strv (dlg->priv->enc_settings,
- GEDIT_SETTINGS_ENCODING_SHOWN_IN_MENU,
- (const gchar * const *)encs);
-
- g_strfreev (encs);
- }
-}
-
-static void
gedit_encodings_dialog_init (GeditEncodingsDialog *dlg)
{
- GtkBuilder *builder;
- GtkWidget *content;
GtkTreeIter parent_iter;
GtkTreeSelection *selection;
- GtkTreeModel *sort_available;
- GtkTreeModel *sort_displayed;
const GeditEncoding *enc;
int i;
- gchar *root_objects[] = {
- "available_liststore",
- "sort_available",
- "displayed_liststore",
- "sort_displayed",
- "encodings-dialog-contents",
- NULL
- };
dlg->priv = GEDIT_ENCODINGS_DIALOG_GET_PRIVATE (dlg);
dlg->priv->enc_settings = g_settings_new ("org.gnome.gedit.preferences.encodings");
- gtk_dialog_add_buttons (GTK_DIALOG (dlg),
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL,
- GTK_STOCK_OK,
- GTK_RESPONSE_OK,
- GTK_STOCK_HELP,
- GTK_RESPONSE_HELP,
- NULL);
-
- gtk_window_set_title (GTK_WINDOW (dlg), _("Character Encodings"));
- gtk_window_set_default_size (GTK_WINDOW (dlg), 650, 400);
-
- /* HIG defaults */
- gtk_container_set_border_width (GTK_CONTAINER (dlg), 5);
- gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
- 2); /* 2 * 5 + 2 = 12 */
- gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))),
- 5);
- gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6);
+ gtk_widget_init_template (GTK_WIDGET (dlg));
gtk_dialog_set_default_response (GTK_DIALOG (dlg),
GTK_RESPONSE_OK);
- g_signal_connect (dlg,
- "response",
- G_CALLBACK (response_handler),
- dlg);
-
- builder = gtk_builder_new ();
- gtk_builder_add_objects_from_resource (builder, "/org/gnome/gedit/ui/gedit-encodings-dialog.ui",
- root_objects, NULL);
- content = GTK_WIDGET (gtk_builder_get_object (builder, "encodings-dialog-contents"));
- g_object_ref (content);
- dlg->priv->add_button = GTK_WIDGET (gtk_builder_get_object (builder, "add-button"));
- dlg->priv->remove_button = GTK_WIDGET (gtk_builder_get_object (builder, "remove-button"));
- dlg->priv->available_treeview = GTK_WIDGET (gtk_builder_get_object (builder, "available-treeview"));
- dlg->priv->available_liststore = GTK_LIST_STORE (gtk_builder_get_object (builder,
"available_liststore"));
- sort_available = GTK_TREE_MODEL (gtk_builder_get_object (builder, "sort_available"));
- dlg->priv->displayed_treeview = GTK_WIDGET (gtk_builder_get_object (builder, "displayed-treeview"));
- dlg->priv->displayed_liststore = GTK_LIST_STORE (gtk_builder_get_object (builder,
"displayed_liststore"));
- sort_displayed = GTK_TREE_MODEL (gtk_builder_get_object (builder, "sort_displayed"));
- g_object_unref (builder);
-
- gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
- content, TRUE, TRUE, 0);
- g_object_unref (content);
- gtk_container_set_border_width (GTK_CONTAINER (content), 5);
-
g_signal_connect (dlg->priv->add_button,
"clicked",
G_CALLBACK (add_button_clicked_callback),
@@ -412,7 +378,7 @@ gedit_encodings_dialog_init (GeditEncodingsDialog *dlg)
}
/* Sort model */
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_available),
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dlg->priv->sort_available),
COLUMN_NAME,
GTK_SORT_ASCENDING);
@@ -430,7 +396,7 @@ gedit_encodings_dialog_init (GeditEncodingsDialog *dlg)
init_shown_in_menu_tree_model (dlg);
/* Sort model */
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_displayed),
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dlg->priv->sort_displayed),
COLUMN_NAME,
GTK_SORT_ASCENDING);
diff --git a/gedit/gedit-encodings-dialog.ui b/gedit/gedit-encodings-dialog.ui
index 6b2652f..17f154e 100644
--- a/gedit/gedit-encodings-dialog.ui
+++ b/gedit/gedit-encodings-dialog.ui
@@ -23,12 +23,13 @@
<object class="GtkTreeModelSort" id="sort_displayed">
<property name="model">displayed_liststore</property>
</object>
- <object class="GtkDialog" id="encodings-dialog">
+ <template class="GeditEncodingsDialog" parent="GtkDialog">
<property name="width_request">650</property>
<property name="height_request">400</property>
<property name="can_focus">False</property>
<property name="has_focus">False</property>
<property name="is_focus">False</property>
+ <property name="border_width">5</property>
<property name="title" translatable="yes">Character encodings</property>
<property name="modal">True</property>
<property name="destroy_with_parent">True</property>
@@ -40,6 +41,7 @@
<property name="has_focus">False</property>
<property name="is_focus">False</property>
<property name="orientation">vertical</property>
+ <property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area3">
<property name="visible">True</property>
@@ -47,6 +49,8 @@
<property name="has_focus">False</property>
<property name="is_focus">False</property>
<property name="layout_style">end</property>
+ <property name="border_width">5</property>
+ <property name="spacing">6</property>
<child>
<object class="GtkButton" id="helpbutton1">
<property name="label">gtk-help</property>
@@ -110,7 +114,7 @@
</packing>
</child>
<child>
- <object class="GtkGrid" id="encodings-dialog-contents">
+ <object class="GtkGrid" id="encodings_dialog_contents">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_focus">False</property>
@@ -119,7 +123,7 @@
<property name="column_spacing">6</property>
<property name="column_homogeneous">True</property>
<child>
- <object class="GtkLabel" id="available-label">
+ <object class="GtkLabel" id="available_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_focus">False</property>
@@ -128,7 +132,7 @@
<property name="xalign">0</property>
<property name="label" translatable="yes">A_vailable encodings:</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">available-treeview</property>
+ <property name="mnemonic_widget">available_treeview</property>
</object>
<packing>
<property name="left_attach">0</property>
@@ -147,7 +151,7 @@
<property name="vexpand">True</property>
<property name="shadow_type">etched-in</property>
<child>
- <object class="GtkTreeView" id="available-treeview">
+ <object class="GtkTreeView" id="available_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">False</property>
@@ -155,7 +159,7 @@
<property name="model">sort_available</property>
<property name="rules_hint">True</property>
<child internal-child="selection">
- <object class="GtkTreeSelection" id="treeview-selection">
+ <object class="GtkTreeSelection" id="treeview_selection">
<property name="mode">multiple</property>
</object>
</child>
@@ -194,7 +198,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="add-button">
+ <object class="GtkButton" id="add_button">
<property name="label">gtk-add</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
@@ -214,7 +218,7 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="remove-button">
+ <object class="GtkButton" id="remove_button">
<property name="label">gtk-remove</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
@@ -241,7 +245,7 @@
<property name="is_focus">False</property>
<property name="shadow_type">etched-in</property>
<child>
- <object class="GtkTreeView" id="displayed-treeview">
+ <object class="GtkTreeView" id="displayed_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">False</property>
@@ -290,7 +294,7 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="displayed-label">
+ <object class="GtkLabel" id="displayed_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_focus">False</property>
@@ -299,7 +303,7 @@
<property name="xalign">0</property>
<property name="label" translatable="yes">E_ncodings shown in menu:</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">displayed-treeview</property>
+ <property name="mnemonic_widget">displayed_treeview</property>
</object>
<packing>
<property name="left_attach">1</property>
@@ -322,5 +326,5 @@
<action-widget response="-6">closebutton1</action-widget>
<action-widget response="-5">button1</action-widget>
</action-widgets>
- </object>
+ </template>
</interface>
diff --git a/gedit/gedit-preferences-dialog.c b/gedit/gedit-preferences-dialog.c
index 7f6f98d..b2a6da0 100644
--- a/gedit/gedit-preferences-dialog.c
+++ b/gedit/gedit-preferences-dialog.c
@@ -158,7 +158,7 @@ gedit_preferences_dialog_response (GtkDialog *dlg,
break;
default:
- gtk_widget_destroy (GTK_WIDGET(dlg));
+ gtk_widget_destroy (GTK_WIDGET (dlg));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]