[gtk+/portal] Move the choice apis to GtkFileChooser
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/portal] Move the choice apis to GtkFileChooser
- Date: Wed, 29 Jun 2016 02:45:28 +0000 (UTC)
commit 6442227f3378c5c1844590f7559d86fcd5425a16
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Jun 28 22:12:51 2016 -0400
Move the choice apis to GtkFileChooser
And implement them for GtkFileChooserWidget, which is useful
for both the fallback native file chooser and the portal one.
gtk/gtkfilechooser.c | 96 +++++++++++++++++++++
gtk/gtkfilechooser.h | 17 ++++
gtk/gtkfilechoosernative.c | 172 ++++++++------------------------------
gtk/gtkfilechoosernative.h | 31 -------
gtk/gtkfilechoosernativeportal.c | 2 +-
gtk/gtkfilechooserprivate.h | 16 ++++-
gtk/gtkfilechooserutils.c | 49 +++++++++++
gtk/gtkfilechooserwidget.c | 143 +++++++++++++++++++++++++++++++
8 files changed, 355 insertions(+), 171 deletions(-)
---
diff --git a/gtk/gtkfilechooser.c b/gtk/gtkfilechooser.c
index 101decb..18cc5af 100644
--- a/gtk/gtkfilechooser.c
+++ b/gtk/gtkfilechooser.c
@@ -2263,3 +2263,99 @@ gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
return do_overwrite_confirmation;
}
+
+/**
+ * gtk_file_chooser_add_choice:
+ * @chooser: a #GtkFileChooser
+ * @id: id for the added choice
+ * @label: user-visible label for the added choice
+ * @options: ids for the options of the choice, or %NULL for a boolean choice
+ * @option_labels: user-visible labels for the options, must be the same length as @options
+ *
+ * Adds a 'choice' to the file chooser. This is typically implemented
+ * as a combobox or, for boolean choices, as a checkbutton. You can select
+ * a value using gtk_file_chooser_set_choice() before the dialog is shown,
+ * and you can obtain the user-selected value in the ::response signal handler
+ * using gtk_file_chooser_get_choice().
+ *
+ * Compare gtk_file_chooser_set_extra_widget().
+ *
+ * Since: 3.22
+ */
+void
+gtk_file_chooser_add_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *label,
+ const char **options,
+ const char **option_labels)
+{
+ GtkFileChooserIface *iface = GTK_FILE_CHOOSER_GET_IFACE (chooser);
+
+ if (iface->add_choice)
+ iface->add_choice (chooser, id, label, options, option_labels);
+}
+
+/**
+ * gtk_file_chooser_remove_choice:
+ * @chooser: a #GtkFileChooser
+ * @id: the ID of the choice to remove
+ *
+ * Removes a 'choice' that has been added with gtk_file_chooser_add_choice().
+ *
+ * Since: 3.22
+ */
+void
+gtk_file_chooser_remove_choice (GtkFileChooser *chooser,
+ const char *id)
+{
+ GtkFileChooserIface *iface = GTK_FILE_CHOOSER_GET_IFACE (chooser);
+
+ if (iface->remove_choice)
+ iface->remove_choice (chooser, id);
+}
+
+/**
+ * gtk_file_chooser_set_choice:
+ * @chooser: a #GtkFileChooser
+ * @id: the ID of the choice to set
+ * @selected: the ID of the option to select
+ *
+ * Selects an option in a 'choice' that has been added with
+ * gtk_file_chooser_add_choice(). For a boolean choice, the
+ * possible options are "true" and "false".
+ *
+ * Since: 3.22
+ */
+void
+gtk_file_chooser_set_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *option)
+{
+ GtkFileChooserIface *iface = GTK_FILE_CHOOSER_GET_IFACE (chooser);
+
+ if (iface->set_choice)
+ iface->set_choice (chooser, id, option);
+}
+
+/**
+ * gtk_file_chooser_get_choice:
+ * @chooser: a #GtkFileChooser
+ * @id: the ID of the choice to get
+ *
+ * Gets the currently selected option in the 'choice' with the given ID.
+ *
+ * Returns: the ID of the currenly selected option
+ * Since: 3.22
+ */
+const char *
+gtk_file_chooser_get_choice (GtkFileChooser *chooser,
+ const char *id)
+{
+ GtkFileChooserIface *iface = GTK_FILE_CHOOSER_GET_IFACE (chooser);
+
+ if (iface->get_choice)
+ return iface->get_choice (chooser, id);
+
+ return NULL;
+}
+
diff --git a/gtk/gtkfilechooser.h b/gtk/gtkfilechooser.h
index d1f5543..92cdbb3 100644
--- a/gtk/gtkfilechooser.h
+++ b/gtk/gtkfilechooser.h
@@ -304,6 +304,23 @@ gboolean gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser *chooser,
GDK_AVAILABLE_IN_ALL
GSList *gtk_file_chooser_list_shortcut_folder_uris (GtkFileChooser *chooser);
+GDK_AVAILABLE_IN_3_22
+void gtk_file_chooser_add_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *label,
+ const char **options,
+ const char **option_labels);
+GDK_AVAILABLE_IN_3_22
+void gtk_file_chooser_remove_choice (GtkFileChooser *chooser,
+ const char *id);
+GDK_AVAILABLE_IN_3_22
+void gtk_file_chooser_set_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *option);
+GDK_AVAILABLE_IN_3_22
+const char *gtk_file_chooser_get_choice (GtkFileChooser *chooser,
+ const char *id);
+
G_END_DECLS
#endif /* __GTK_FILE_CHOOSER_H__ */
diff --git a/gtk/gtkfilechoosernative.c b/gtk/gtkfilechoosernative.c
index 0c100bc..e72c95f 100644
--- a/gtk/gtkfilechoosernative.c
+++ b/gtk/gtkfilechoosernative.c
@@ -331,30 +331,14 @@ gtk_file_chooser_native_choice_free (GtkFileChooserNativeChoice *choice)
g_free (choice);
}
-/**
- * gtk_file_chooser_native_add_choice:
- * @self: a #GtkFileChooserNative
- * @id: id for the added choice
- * @label: user-visible label for the added choice
- * @options: ids for the options of the choice
- * @option_labels: user-visible labels for the options, must be the same length as @options
- *
- * Adds a 'choice' to the native file chooser. This is typically implemented
- * as a combobox. You can select a value using gtk_file_chooser_native_set_choice()
- * before the dialog is shown, and you can obtain the user-selected value in the
- * #GtkFileChooserNative::response signal handler using gtk_file_chooser_native_get_choice().
- *
- * Compare gtk_file_chooser_set_extra_widget().
- *
- * Since: 3.22
- */
-void
-gtk_file_chooser_native_add_choice (GtkFileChooserNative *self,
- const char *id,
- const char *label,
- const char **options,
- const char **option_labels)
+static void
+gtk_file_chooser_native_add_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *label,
+ const char **options,
+ const char **option_labels)
{
+ GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (chooser);
GtkFileChooserNativeChoice *choice = find_choice (self, id);
if (choice != NULL)
@@ -374,21 +358,16 @@ gtk_file_chooser_native_add_choice (GtkFileChooserNative *self,
choice->selected = NULL;
self->choices = g_slist_append (self->choices, choice);
+
+ gtk_file_chooser_add_choice (GTK_FILE_CHOOSER (self->dialog),
+ id, label, options, option_labels);
}
-/**
- * gtk_file_chooser_native_remove_choice:
- * @self: a #GtkFileChooserNative
- * @id: the ID of the choice to remove
- *
- * Removes a 'choice' that has been added with gtk_file_chooser_native_add_choice().
- *
- * Since: 3.22
- */
-void
-gtk_file_chooser_native_remove_choice (GtkFileChooserNative *self,
- const char *id)
+static void
+gtk_file_chooser_native_remove_choice (GtkFileChooser *chooser,
+ const char *id)
{
+ GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (chooser);
GtkFileChooserNativeChoice *choice = find_choice (self, id);
if (choice == NULL)
@@ -400,24 +379,16 @@ gtk_file_chooser_native_remove_choice (GtkFileChooserNative *self,
self->choices = g_slist_remove (self->choices, choice);
gtk_file_chooser_native_choice_free (choice);
+
+ gtk_file_chooser_remove_choice (GTK_FILE_CHOOSER (self->dialog), id);
}
-/**
- * gtk_file_chooser_native_set_choice:
- * @self: a #GtkFileChooserNative
- * @id: the ID of the choice to set
- * @selected: the ID of the option to select
- *
- * Selects an option in a 'choice' that has been added
- * with gtk_file_chooser_native_add_choice().
- *
- * Since: 3.22
- */
-void
-gtk_file_chooser_native_set_choice (GtkFileChooserNative *self,
- const char *id,
- const char *selected)
+static void
+gtk_file_chooser_native_set_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *selected)
{
+ GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (chooser);
GtkFileChooserNativeChoice *choice = find_choice (self, id);
if (choice == NULL)
@@ -435,22 +406,15 @@ gtk_file_chooser_native_set_choice (GtkFileChooserNative *self,
g_free (choice->selected);
choice->selected = g_strdup (selected);
+
+ gtk_file_chooser_set_choice (GTK_FILE_CHOOSER (self->dialog), id, selected);
}
-/**
- * gtk_file_chooser_native_get_choice:
- * @self: a #GtkFileChooserNative
- * @id: the ID of the choice to get
- *
- * Gets the currently selected option in the 'choice' with the given ID.
- *
- * Returns: the ID of the currenly selected option
- * Since: 3.22
- */
-const char *
-gtk_file_chooser_native_get_choice (GtkFileChooserNative *self,
- const char *id)
+static const char *
+gtk_file_chooser_native_get_choice (GtkFileChooser *chooser,
+ const char *id)
{
+ GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (chooser);
GtkFileChooserNativeChoice *choice = find_choice (self, id);
if (choice == NULL)
@@ -459,82 +423,10 @@ gtk_file_chooser_native_get_choice (GtkFileChooserNative *self,
return NULL;
}
- return choice->selected;
-}
-
-/**
- * gtk_file_chooser_native_add_option:
- * @self: a #GtkFileChooserNative
- * @id: id for the added option
- * @label: user-visible label for the added option
- *
- * Adds a boolean 'option' to the native file chooser. This is typically implemented
- * as a check button. You can set the value using gtk_file_chooser_native_set_option()
- * before the dialog is shown, and you can obtain the user-selected value in the
- * #GtkFileChooserNative::response signal handler using gtk_file_chooser_native_get_option().
- *
- * Compare gtk_file_chooser_set_extra_widget().
- *
- * Since: 3.22
- */
-void
-gtk_file_chooser_native_add_option (GtkFileChooserNative *self,
- const char *id,
- const char *label)
-{
- gtk_file_chooser_native_add_choice (self, id, label, NULL, NULL);
-}
-
-/**
- * gtk_file_chooser_native_remove_option:
- * @self: a #GtkFileChooserNative
- * @id: the ID of the option to remove
- *
- * Removes an 'option' that has been added with gtk_file_chooser_native_add_option().
- *
- * Since: 3.22
- */
-void
-gtk_file_chooser_native_remove_option (GtkFileChooserNative *self,
- const char *id)
-{
- gtk_file_chooser_native_remove_option (self, id);
-}
-
-/**
- * gtk_file_chooser_native_set_option:
- * @self: a #GtkFileChooserNative
- * @id: the ID of the option to set
- * @value: the new value for the option
- *
- * Sets the value of an 'option' that has been added
- * with gtk_file_chooser_native_add_option().
- *
- * Since: 3.22
- */
-void
-gtk_file_chooser_native_set_option (GtkFileChooserNative *self,
- const char *id,
- gboolean value)
-{
- gtk_file_chooser_native_set_choice (self, id, value ? "true" : "false");
-}
+ if (self->mode == MODE_FALLBACK)
+ return gtk_file_chooser_get_choice (GTK_FILE_CHOOSER (self->dialog), id);
-/**
- * gtk_file_chooser_native_get_option:
- * @self: a #GtkFileChooserNative
- * @id: the ID of the option to get
- *
- * Gets the value of the 'option' with the given ID.
- *
- * Returns: the value of the 'option'
- * Since: 3.22
- */
-gboolean
-gtk_file_chooser_native_get_option (GtkFileChooserNative *self,
- const char *id)
-{
- return g_str_equal (gtk_file_chooser_native_get_choice (self, id), "true");
+ return choice->selected;
}
static void
@@ -920,4 +812,8 @@ _gtk_file_chooser_native_iface_init (GtkFileChooserIface *iface)
iface->set_current_name = gtk_file_chooser_native_set_current_name;
iface->set_current_folder = gtk_file_chooser_native_set_current_folder;
iface->get_files = gtk_file_chooser_native_get_files;
+ iface->add_choice = gtk_file_chooser_native_add_choice;
+ iface->remove_choice = gtk_file_chooser_native_remove_choice;
+ iface->set_choice = gtk_file_chooser_native_set_choice;
+ iface->get_choice = gtk_file_chooser_native_get_choice;
}
diff --git a/gtk/gtkfilechoosernative.h b/gtk/gtkfilechoosernative.h
index 384a814..c2c21d7 100644
--- a/gtk/gtkfilechoosernative.h
+++ b/gtk/gtkfilechoosernative.h
@@ -50,37 +50,6 @@ const char *gtk_file_chooser_native_get_cancel_label (GtkFileChooserNative *self
GDK_AVAILABLE_IN_3_20
void gtk_file_chooser_native_set_cancel_label (GtkFileChooserNative *self,
const char *cancel_label);
-GDK_AVAILABLE_IN_3_22
-void gtk_file_chooser_native_add_choice (GtkFileChooserNative *self,
- const char *id,
- const char *label,
- const char **options,
- const char **option_labels);
-GDK_AVAILABLE_IN_3_22
-void gtk_file_chooser_native_remove_choice (GtkFileChooserNative *self,
- const char *id);
-GDK_AVAILABLE_IN_3_22
-void gtk_file_chooser_native_set_choice (GtkFileChooserNative *self,
- const char *id,
- const char *option);
-GDK_AVAILABLE_IN_3_22
-const char *gtk_file_chooser_native_get_choice (GtkFileChooserNative *self,
- const char *id);
-GDK_AVAILABLE_IN_3_22
-void gtk_file_chooser_native_add_option (GtkFileChooserNative *self,
- const char *id,
- const char *label);
-GDK_AVAILABLE_IN_3_22
-void gtk_file_chooser_native_remove_option (GtkFileChooserNative *self,
- const char *id);
-GDK_AVAILABLE_IN_3_22
-void gtk_file_chooser_native_set_option (GtkFileChooserNative *self,
- const char *id,
- gboolean value);
-GDK_AVAILABLE_IN_3_22
-gboolean gtk_file_chooser_native_get_option (GtkFileChooserNative *self,
- const char *id);
-
G_END_DECLS
diff --git a/gtk/gtkfilechoosernativeportal.c b/gtk/gtkfilechoosernativeportal.c
index 462eedf..f418e2a 100644
--- a/gtk/gtkfilechoosernativeportal.c
+++ b/gtk/gtkfilechoosernativeportal.c
@@ -114,7 +114,7 @@ response_cb (GDBusConnection *connection,
const char *id;
const char *selected;
g_variant_get_child (choices, i, "(&s&s)", &id, &selected);
- gtk_file_chooser_native_set_choice (self, id, selected);
+ gtk_file_chooser_set_choice (self, id, selected);
}
g_slist_free_full (self->custom_files, g_object_unref);
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index 2280da9..0094beb 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -87,7 +87,7 @@ struct _GtkFileChooserIface
GFile *file,
GError **error);
GSList * (*list_shortcut_folders) (GtkFileChooser *chooser);
-
+
/* Signals
*/
void (*current_folder_changed) (GtkFileChooser *chooser);
@@ -95,6 +95,20 @@ struct _GtkFileChooserIface
void (*update_preview) (GtkFileChooser *chooser);
void (*file_activated) (GtkFileChooser *chooser);
GtkFileChooserConfirmation (*confirm_overwrite) (GtkFileChooser *chooser);
+
+ /* 3.22 additions */
+ void (*add_choice) (GtkFileChooser *chooser,
+ const char *id,
+ const char *label,
+ const char **options,
+ const char **option_labels);
+ void (*remove_choice) (GtkFileChooser *chooser,
+ const char *id);
+ void (*set_choice) (GtkFileChooser *chooser,
+ const char *id,
+ const char *option);
+ const char * (*get_choice) (GtkFileChooser *chooser,
+ const char *id);
};
GtkFileSystem *_gtk_file_chooser_get_file_system (GtkFileChooser *chooser);
diff --git a/gtk/gtkfilechooserutils.c b/gtk/gtkfilechooserutils.c
index 53246ca..7965ab0 100644
--- a/gtk/gtkfilechooserutils.c
+++ b/gtk/gtkfilechooserutils.c
@@ -68,6 +68,19 @@ static void delegate_file_activated (GtkFileChooser *choose
static GtkFileChooserConfirmation delegate_confirm_overwrite (GtkFileChooser *chooser,
gpointer data);
+static void delegate_add_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *label,
+ const char **options,
+ const char **option_labels);
+static void delegate_remove_choice (GtkFileChooser *chooser,
+ const char *id);
+static void delegate_set_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *option);
+static const char * delegate_get_choice (GtkFileChooser *chooser,
+ const char *id);
+
/**
* _gtk_file_chooser_install_properties:
@@ -149,6 +162,10 @@ _gtk_file_chooser_delegate_iface_init (GtkFileChooserIface *iface)
iface->add_shortcut_folder = delegate_add_shortcut_folder;
iface->remove_shortcut_folder = delegate_remove_shortcut_folder;
iface->list_shortcut_folders = delegate_list_shortcut_folders;
+ iface->add_choice = delegate_add_choice;
+ iface->remove_choice = delegate_remove_choice;
+ iface->set_choice = delegate_set_choice;
+ iface->get_choice = delegate_get_choice;
}
/**
@@ -499,3 +516,35 @@ _gtk_file_chooser_label_for_file (GFile *file)
return label;
}
+static void
+delegate_add_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *label,
+ const char **options,
+ const char **option_labels)
+{
+ gtk_file_chooser_add_choice (get_delegate (chooser),
+ id, label, options, option_labels);
+}
+static void
+delegate_remove_choice (GtkFileChooser *chooser,
+ const char *id)
+{
+ gtk_file_chooser_remove_choice (get_delegate (chooser), id);
+}
+
+static void
+delegate_set_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *option)
+{
+ gtk_file_chooser_set_choice (get_delegate (chooser), id, option);
+}
+
+
+static const char *
+delegate_get_choice (GtkFileChooser *chooser,
+ const char *id)
+{
+ return gtk_file_chooser_get_choice (get_delegate (chooser), id);
+}
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 79a099e..a9868f2 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -66,6 +66,7 @@
#include "gtktreeprivate.h"
#include "gtktreeselection.h"
#include "gtkbox.h"
+#include "gtkcheckbutton.h"
#include "gtkwindowgroup.h"
#include "gtkintl.h"
#include "gtkshow.h"
@@ -289,6 +290,9 @@ struct _GtkFileChooserWidgetPrivate {
GtkWidget *external_entry;
+ GtkWidget *choice_box;
+ GHashTable *choices;
+
/* Handles */
GCancellable *file_list_drag_data_received_cancellable;
GCancellable *update_current_folder_cancellable;
@@ -507,6 +511,20 @@ static void gtk_file_chooser_widget_get_default_size (GtkFileCho
static gboolean gtk_file_chooser_widget_should_respond (GtkFileChooserEmbed *chooser_embed);
static void gtk_file_chooser_widget_initial_focus (GtkFileChooserEmbed *chooser_embed);
+static void gtk_file_chooser_widget_add_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *label,
+ const char **options,
+ const char **option_labels);
+static void gtk_file_chooser_widget_remove_choice (GtkFileChooser *chooser,
+ const char *id);
+static void gtk_file_chooser_widget_set_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *option);
+static const char *gtk_file_chooser_widget_get_choice (GtkFileChooser *chooser,
+ const char *id);
+
+
static void add_selection_to_recent_list (GtkFileChooserWidget *impl);
static void location_popup_handler (GtkFileChooserWidget *impl,
@@ -625,6 +643,10 @@ gtk_file_chooser_widget_iface_init (GtkFileChooserIface *iface)
iface->add_shortcut_folder = gtk_file_chooser_widget_add_shortcut_folder;
iface->remove_shortcut_folder = gtk_file_chooser_widget_remove_shortcut_folder;
iface->list_shortcut_folders = gtk_file_chooser_widget_list_shortcut_folders;
+ iface->add_choice = gtk_file_chooser_widget_add_choice;
+ iface->remove_choice = gtk_file_chooser_widget_remove_choice;
+ iface->set_choice = gtk_file_chooser_widget_set_choice;
+ iface->get_choice = gtk_file_chooser_widget_get_choice;
}
static void
@@ -8676,3 +8698,124 @@ gtk_file_chooser_widget_new (GtkFileChooserAction action)
"action", action,
NULL);
}
+
+static void
+gtk_file_chooser_widget_add_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *label,
+ const char **options,
+ const char **option_labels)
+{
+ GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
+ GtkFileChooserWidgetPrivate *priv = impl->priv;
+ GtkWidget *widget;
+
+ if (priv->choices == NULL)
+ {
+ priv->choices = g_hash_table_new (g_str_hash, g_str_equal);
+ priv->choice_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ set_extra_widget (impl, priv->choice_box);
+ }
+ else if (g_hash_table_lookup (priv->choices, id))
+ {
+ g_warning ("Duplicate choice %s", id);
+ return;
+ }
+
+ if (options)
+ {
+ GtkWidget *box;
+ GtkWidget *combo;
+ int i;
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ gtk_container_add (GTK_CONTAINER (box), gtk_label_new (label));
+
+ combo = gtk_combo_box_text_new ();
+ g_hash_table_insert (priv->choices, g_strdup (id), combo);
+ gtk_container_add (GTK_CONTAINER (box), combo);
+
+ for (i = 0; options[i]; i++)
+ gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo),
+ options[i], option_labels[i]);
+
+ widget = box;
+ }
+ else
+ {
+ GtkWidget *check;
+
+ check = gtk_check_button_new_with_label (label);
+ g_hash_table_insert (priv->choices, g_strdup (id), check);
+
+ widget = check;
+ }
+
+ gtk_widget_show_all (widget);
+ gtk_container_add (GTK_CONTAINER (priv->choice_box), widget);
+}
+
+static void
+gtk_file_chooser_widget_remove_choice (GtkFileChooser *chooser,
+ const char *id)
+{
+ GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
+ GtkFileChooserWidgetPrivate *priv = impl->priv;
+ GtkWidget *widget;
+
+ if (priv->choices == NULL)
+ return;
+
+ widget = (GtkWidget *)g_hash_table_lookup (priv->choices, id);
+ g_hash_table_remove (priv->choices, id);
+ gtk_container_remove (GTK_CONTAINER (priv->choice_box), widget);
+
+ if (g_hash_table_size (priv->choices) == 0)
+ {
+ set_extra_widget (impl, NULL);
+ g_hash_table_unref (priv->choices);
+ priv->choices = NULL;
+ priv->choice_box = NULL;
+ }
+}
+
+static void
+gtk_file_chooser_widget_set_choice (GtkFileChooser *chooser,
+ const char *id,
+ const char *option)
+{
+ GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
+ GtkFileChooserWidgetPrivate *priv = impl->priv;
+ GtkWidget *widget;
+
+ if (priv->choices == NULL)
+ return;
+
+ widget = (GtkWidget *)g_hash_table_lookup (priv->choices, id);
+
+ if (GTK_IS_COMBO_BOX (widget))
+ gtk_combo_box_set_active_id (GTK_COMBO_BOX (widget), option);
+ else if (GTK_IS_TOGGLE_BUTTON (widget))
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), g_str_equal (option, "true"));
+}
+
+static const char *
+gtk_file_chooser_widget_get_choice (GtkFileChooser *chooser,
+ const char *id)
+{
+ GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
+ GtkFileChooserWidgetPrivate *priv = impl->priv;
+ GtkWidget *widget;
+
+ if (priv->choices == NULL)
+ return NULL;
+
+ widget = (GtkWidget *)g_hash_table_lookup (priv->choices, id);
+ if (GTK_IS_COMBO_BOX (widget))
+ return gtk_combo_box_get_active_id (GTK_COMBO_BOX (widget));
+ else if (GTK_IS_TOGGLE_BUTTON (widget))
+ return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)) ? "true" : "false";
+
+ return NULL;
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]