[gtk+/composite-templates-new: 30/32] GtkFileChooserButton: Define children with a GtkBuilder template
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/composite-templates-new: 30/32] GtkFileChooserButton: Define children with a GtkBuilder template
- Date: Sun, 31 Mar 2013 07:59:26 +0000 (UTC)
commit c55e1e01899b0b584ba5e32cbfd20c0bddffb012
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Sat Mar 30 17:12:35 2013 +0900
GtkFileChooserButton: Define children with a GtkBuilder template
gtk/Makefile.am | 1 +
gtk/gtk.gresource.xml | 1 +
gtk/gtkfilechooserbutton.c | 53 +++++++++++++------
gtk/gtkfilechooserbutton.ui | 120 +++++++++++++++++++++++++++++++++++++++++++
gtk/tests/templates.c | 16 ++++++
po/POTFILES.in | 1 +
6 files changed, 176 insertions(+), 16 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 0133c14..d7e3dd6 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1102,6 +1102,7 @@ COMPOSITE_TEMPLATES = \
gtkcolorchooserdialog.ui \
gtkcoloreditor.ui \
gtkdialog.ui \
+ gtkfilechooserbutton.ui \
gtkfilechooserdefault.ui \
gtkfilechooserdialog.ui \
gtkfontchooserdialog.ui \
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index 0e40d07..bdc844a 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -18,6 +18,7 @@
<file compressed="true">gtkcolorchooserdialog.ui</file>
<file compressed="true">gtkcoloreditor.ui</file>
<file compressed="true">gtkdialog.ui</file>
+ <file compressed="true">gtkfilechooserbutton.ui</file>
<file compressed="true">gtkfilechooserdefault.ui</file>
<file compressed="true">gtkfilechooserdialog.ui</file>
<file compressed="true">gtkfontchooserdialog.ui</file>
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index a2c37c8..5e7ea61 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -130,7 +130,10 @@ enum
LAST_SIGNAL
};
-/* TreeModel Columns */
+/* TreeModel Columns
+ *
+ * keep in line with the store defined in gtkfilechooserbutton.ui
+ */
enum
{
ICON_COLUMN,
@@ -182,7 +185,6 @@ struct _GtkFileChooserButtonPrivate
GFile *selection_while_inactive;
GFile *current_folder_while_inactive;
- gulong combo_box_changed_id;
gulong fs_volumes_changed_id;
gulong fs_bookmarks_changed_id;
@@ -465,6 +467,23 @@ gtk_file_chooser_button_class_init (GtkFileChooserButtonClass * class)
_gtk_file_chooser_install_properties (gobject_class);
+ /* Bind class to template
+ */
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gtk/libgtk/gtkfilechooserbutton.ui");
+
+ gtk_widget_class_bind_child (widget_class, GtkFileChooserButtonPrivate, model);
+ gtk_widget_class_bind_child (widget_class, GtkFileChooserButtonPrivate, button);
+ gtk_widget_class_bind_child (widget_class, GtkFileChooserButtonPrivate, image);
+ gtk_widget_class_bind_child (widget_class, GtkFileChooserButtonPrivate, label);
+ gtk_widget_class_bind_child (widget_class, GtkFileChooserButtonPrivate, combo_box);
+ gtk_widget_class_bind_child (widget_class, GtkFileChooserButtonPrivate, icon_cell);
+ gtk_widget_class_bind_child (widget_class, GtkFileChooserButtonPrivate, name_cell);
+
+ gtk_widget_class_bind_callback (widget_class, button_clicked_cb);
+ gtk_widget_class_bind_callback (widget_class, combo_box_changed_cb);
+ gtk_widget_class_bind_callback (widget_class, combo_box_notify_popup_shown_cb);
+
g_type_class_add_private (class, sizeof (GtkFileChooserButtonPrivate));
}
@@ -472,7 +491,6 @@ static void
gtk_file_chooser_button_init (GtkFileChooserButton *button)
{
GtkFileChooserButtonPrivate *priv;
- GtkWidget *box, *image, *sep;
GtkTargetList *target_list;
priv = button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
@@ -482,6 +500,11 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
priv->icon_size = FALLBACK_ICON_SIZE;
priv->focus_on_click = TRUE;
+ gtk_widget_init_template (GTK_WIDGET (button));
+
+#if 0
+ GtkWidget *box, *image, *sep;
+
/* Button */
priv->button = gtk_button_new ();
g_signal_connect (priv->button, "clicked",
@@ -526,8 +549,9 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
G_TYPE_POINTER /* CANCELLABLE_COLUMN */));
priv->combo_box = gtk_combo_box_new ();
- priv->combo_box_changed_id = g_signal_connect (priv->combo_box, "changed",
- G_CALLBACK (combo_box_changed_cb), button);
+
+ g_signal_connect (priv->combo_box, "changed",
+ G_CALLBACK (combo_box_changed_cb), button);
g_signal_connect (priv->combo_box, "notify::popup-shown",
G_CALLBACK (combo_box_notify_popup_shown_cb), button);
@@ -546,6 +570,10 @@ gtk_file_chooser_button_init (GtkFileChooserButton *button)
priv->name_cell, TRUE);
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->combo_box),
priv->name_cell, "text", DISPLAY_NAME_COLUMN);
+
+#endif
+
+ /* XXX Setup in CODE ! */
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->combo_box),
priv->name_cell, name_cell_data_func,
NULL, NULL);
@@ -1124,12 +1152,6 @@ gtk_file_chooser_button_destroy (GtkWidget *widget)
priv->change_icon_theme_cancellables = NULL;
}
- if (priv->model)
- {
- g_object_unref (priv->model);
- priv->model = NULL;
- }
-
if (priv->filter_model)
{
g_object_unref (priv->filter_model);
@@ -2398,9 +2420,9 @@ select_combo_box_row_no_notify (GtkFileChooserButton *button, int pos)
gtk_tree_model_filter_convert_child_iter_to_iter (GTK_TREE_MODEL_FILTER (priv->filter_model),
&filter_iter, &iter);
- g_signal_handler_block (priv->combo_box, priv->combo_box_changed_id);
+ g_signal_handlers_block_by_func (priv->combo_box, combo_box_changed_cb, button);
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->combo_box), &filter_iter);
- g_signal_handler_unblock (priv->combo_box, priv->combo_box_changed_id);
+ g_signal_handlers_unblock_by_func (priv->combo_box, combo_box_changed_cb, button);
}
static void
@@ -2457,11 +2479,10 @@ update_combo_box (GtkFileChooserButton *button)
if (row_found)
{
- g_signal_handler_block (priv->combo_box, priv->combo_box_changed_id);
+ g_signal_handlers_block_by_func (priv->combo_box, combo_box_changed_cb, button);
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->combo_box),
&iter);
- g_signal_handler_unblock (priv->combo_box,
- priv->combo_box_changed_id);
+ g_signal_handlers_unblock_by_func (priv->combo_box, combo_box_changed_cb, button);
}
}
while (!row_found && gtk_tree_model_iter_next (priv->filter_model, &iter));
diff --git a/gtk/gtkfilechooserbutton.ui b/gtk/gtkfilechooserbutton.ui
new file mode 100644
index 0000000..2153eed
--- /dev/null
+++ b/gtk/gtkfilechooserbutton.ui
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+ <!-- interface-requires gtk+ 3.10 -->
+ <template class="GtkFileChooserButton" parent="GtkBox">
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkButton" id="button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="button_clicked_cb" swapped="no"/>
+ <child>
+ <object class="GtkBox" id="box2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">4</property>
+ <child>
+ <object class="GtkImage" id="image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-missing-image</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="valign">center</property>
+ <property name="label" translatable="yes">(None)</property>
+ <property name="ellipsize">end</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSeparator" id="separator1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkImage" id="open_file_icon">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-open</property>
+ <property name="icon-size">1</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="combo_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <signal name="changed" handler="combo_box_changed_cb" swapped="no"/>
+ <signal name="notify::popup-shown" handler="combo_box_notify_popup_shown_cb" swapped="no"/>
+ <child>
+ <object class="GtkCellRendererPixbuf" id="icon_cell"/>
+ <attributes>
+ <attribute name="pixbuf">0</attribute>
+ </attributes>
+ </child>
+ <child>
+ <object class="GtkCellRendererText" id="name_cell"/>
+ <attributes>
+ <attribute name="text">1</attribute>
+ </attributes>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </template>
+ <object class="GtkListStore" id="model">
+ <columns>
+ <!-- column-name icon -->
+ <column type="GdkPixbuf"/>
+ <!-- column-name display-name -->
+ <column type="gchararray"/>
+ <!-- column-name type -->
+ <column type="gchar"/>
+ <!-- column-name data -->
+ <column type="gpointer"/>
+ <!-- column-name is-folder -->
+ <column type="gboolean"/>
+ <!-- column-name cancelable -->
+ <column type="gpointer"/>
+ </columns>
+ </object>
+</interface>
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index 834d183..8816f80 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -231,6 +231,21 @@ test_file_chooser_dialog_basic (void)
}
static void
+test_file_chooser_button_basic (void)
+{
+ GtkWidget *widget;
+
+ g_test_log_set_fatal_handler (ignore_gvfs_warning, NULL);
+
+ widget = gtk_file_chooser_button_new ("Choose a file !", GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+ g_assert (GTK_IS_FILE_CHOOSER_BUTTON (widget));
+ g_timeout_add (100, main_loop_quit_cb, NULL);
+ gtk_main();
+
+ gtk_widget_destroy (widget);
+}
+
+static void
test_font_chooser_widget_basic (void)
{
GtkWidget *widget;
@@ -308,6 +323,7 @@ main (int argc, char **argv)
g_test_add_func ("/Template/GtkColorChooserDialog/Basic", test_color_chooser_dialog_basic);
g_test_add_func ("/Template/GtkFileChooserWidget/Basic", test_file_chooser_widget_basic);
g_test_add_func ("/Template/GtkFileChooserDialog/Basic", test_file_chooser_dialog_basic);
+ g_test_add_func ("/Template/GtkFileChooserButton/Basic", test_file_chooser_button_basic);
g_test_add_func ("/Template/GtkFontChooserWidget/Basic", test_font_chooser_widget_basic);
g_test_add_func ("/Template/GtkFontChooserDialog/Basic", test_font_chooser_dialog_basic);
g_test_add_func ("/Template/GtkRecentChooserWidget/Basic", test_recent_chooser_widget_basic);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 66d875b..0672280 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -281,6 +281,7 @@ modules/printbackends/test/gtkprintbackendtest.c
[type: gettext/glade]gtk/gtkcolorchooserdialog.ui
[type: gettext/glade]gtk/gtkcoloreditor.ui
[type: gettext/glade]gtk/gtkdialog.ui
+[type: gettext/glade]gtk/gtkfilechooserbutton.ui
[type: gettext/glade]gtk/gtkfilechooserdedault.ui
[type: gettext/glade]gtk/gtkfilechooserdialog.ui
[type: gettext/glade]gtk/gtkfontchooserdialog.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]