[gedit] spell-language-dialog: use a template widget
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] spell-language-dialog: use a template widget
- Date: Tue, 21 Jul 2015 19:04:42 +0000 (UTC)
commit c10e51c9e0464bf38ea33d384168d111a9e9fc4f
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue Jul 21 20:33:56 2015 +0200
spell-language-dialog: use a template widget
plugins/spell/gedit-spell-language-dialog.c | 66 +++++-------------------
plugins/spell/resources/ui/languages-dialog.ui | 19 ++++---
2 files changed, 24 insertions(+), 61 deletions(-)
---
diff --git a/plugins/spell/gedit-spell-language-dialog.c b/plugins/spell/gedit-spell-language-dialog.c
index 0cc9423..22914bb 100644
--- a/plugins/spell/gedit-spell-language-dialog.c
+++ b/plugins/spell/gedit-spell-language-dialog.c
@@ -59,9 +59,15 @@ gedit_spell_language_dialog_response (GtkDialog *dialog,
static void
gedit_spell_language_dialog_class_init (GeditSpellLanguageDialogClass *klass)
{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
dialog_class->response = gedit_spell_language_dialog_response;
+
+ /* Bind class to template */
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/gedit/plugins/spell/ui/languages-dialog.ui");
+ gtk_widget_class_bind_template_child (widget_class, GeditSpellLanguageDialog, treeview);
}
static void
@@ -99,48 +105,12 @@ row_activated_cb (GtkTreeView *tree_view,
}
static void
-create_dialog (GeditSpellLanguageDialog *dialog)
+gedit_spell_language_dialog_init (GeditSpellLanguageDialog *dialog)
{
- GtkBuilder *builder;
- GtkWidget *content;
GtkCellRenderer *cell;
GtkTreeViewColumn *column;
- gchar *root_objects[] = {
- "content",
- NULL
- };
-
- gtk_dialog_add_buttons (GTK_DIALOG (dialog),
- _("_Cancel"), GTK_RESPONSE_CANCEL,
- _("_OK"), GTK_RESPONSE_OK,
- _("_Help"), GTK_RESPONSE_HELP,
- NULL);
-
- gtk_window_set_title (GTK_WINDOW (dialog), _("Set language"));
- gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
- gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
-
- /* HIG defaults */
- gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
- gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
- 2); /* 2 * 5 + 2 = 12 */
- gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog))),
- 5);
- gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))),
- 6);
-
- builder = gtk_builder_new ();
- gtk_builder_add_objects_from_resource (builder,
"/org/gnome/gedit/plugins/spell/ui/languages-dialog.ui",
- root_objects, NULL);
- content = GTK_WIDGET (gtk_builder_get_object (builder, "content"));
- g_object_ref (content);
- dialog->treeview = GTK_WIDGET (gtk_builder_get_object (builder, "languages_treeview"));
- g_object_unref (builder);
-
- gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
- content, TRUE, TRUE, 0);
- g_object_unref (content);
- gtk_container_set_border_width (GTK_CONTAINER (content), 5);
+
+ gtk_widget_init_template (GTK_WIDGET (dialog));
dialog->model = GTK_TREE_MODEL (gtk_list_store_new (N_COLUMNS,
G_TYPE_STRING,
@@ -153,10 +123,8 @@ create_dialog (GeditSpellLanguageDialog *dialog)
/* Add the language column */
cell = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes (_("Languages"),
- cell,
- "text",
- COLUMN_LANGUAGE_NAME,
+ column = gtk_tree_view_column_new_with_attributes (_("Languages"), cell,
+ "text", COLUMN_LANGUAGE_NAME,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->treeview),
@@ -177,11 +145,6 @@ create_dialog (GeditSpellLanguageDialog *dialog)
}
static void
-gedit_spell_language_dialog_init (GeditSpellLanguageDialog *dialog)
-{
-}
-
-static void
populate_language_list (GeditSpellLanguageDialog *dialog,
const GeditSpellCheckerLanguage *cur_lang)
{
@@ -226,13 +189,12 @@ gedit_spell_language_dialog_new (GtkWindow *parent,
g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
- dialog = g_object_new (GEDIT_TYPE_SPELL_LANGUAGE_DIALOG, NULL);
-
- create_dialog (dialog);
+ dialog = g_object_new (GEDIT_TYPE_SPELL_LANGUAGE_DIALOG,
+ "transient-for", parent,
+ NULL);
populate_language_list (dialog, cur_lang);
- gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
gtk_widget_grab_focus (dialog->treeview);
return GTK_WIDGET (dialog);
diff --git a/plugins/spell/resources/ui/languages-dialog.ui b/plugins/spell/resources/ui/languages-dialog.ui
index 5786d43..f996586 100644
--- a/plugins/spell/resources/ui/languages-dialog.ui
+++ b/plugins/spell/resources/ui/languages-dialog.ui
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.19.0 -->
<interface>
- <!-- interface-requires gtk+ 2.12 -->
- <object class="GtkDialog" id="dialog">
+ <requires lib="gtk+" version="3.16"/>
+ <template class="GeditSpellLanguageDialog" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Set Language</property>
@@ -22,11 +23,11 @@
<child>
<object class="GtkButton" id="helpbutton1">
<property name="label" translatable="yes">_Help</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -38,11 +39,11 @@
<child>
<object class="GtkButton" id="closebutton1">
<property name="label" translatable="yes">_Cancel</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -54,11 +55,11 @@
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">_OK</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -86,11 +87,11 @@
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="xalign">0</property>
<property name="label" translatable="yes">Select the _language of the current
document.</property>
<property name="use_underline">True</property>
<property name="wrap">True</property>
- <property name="mnemonic_widget">languages_treeview</property>
+ <property name="mnemonic_widget">treeview</property>
+ <property name="xalign">0</property>
</object>
<packing>
<property name="expand">False</property>
@@ -105,7 +106,7 @@
<property name="can_focus">True</property>
<property name="shadow_type">etched-in</property>
<child>
- <object class="GtkTreeView" id="languages_treeview">
+ <object class="GtkTreeView" id="treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">False</property>
@@ -135,5 +136,5 @@
<action-widget response="-6">closebutton1</action-widget>
<action-widget response="-5">button1</action-widget>
</action-widgets>
- </object>
+ </template>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]