GtkFileChooser: Add abstract api for comboboxes and checkbuttons

This commit adds API for adding combo boxes and check buttons to
GtkFileChooser, and getting the selected value back in ::response.

In contrast to gtk_file_chooser_set_extra_widget, these APIs are
abstract and suitable for implementation in GtkFileChooserNative.

https://bugzilla.gnome.org/show_bug.cgi?id=768499
This commit is contained in:
Matthias Clasen 2016-07-05 22:09:56 -04:00
parent 2b77eaa1ae
commit 6fc7485077
3 changed files with 128 additions and 1 deletions

View File

@ -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;
}

View File

@ -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__ */

View File

@ -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);