Drop GtkFileChooser:extra-widget

We have "choices" as a more rational (and portable) API; additionally,
the ownership semantics of the extra widget property getter are a hack.
This commit is contained in:
Emmanuele Bassi 2020-02-21 15:34:37 +00:00
parent 5f070ff233
commit d505573ee6
11 changed files with 8 additions and 151 deletions

View File

@ -1158,8 +1158,6 @@ gtk_file_chooser_get_preview_widget_active
gtk_file_chooser_set_use_preview_label gtk_file_chooser_set_use_preview_label
gtk_file_chooser_get_use_preview_label gtk_file_chooser_get_use_preview_label
gtk_file_chooser_get_preview_file gtk_file_chooser_get_preview_file
gtk_file_chooser_set_extra_widget
gtk_file_chooser_get_extra_widget
<SUBSECTION> <SUBSECTION>
gtk_file_chooser_add_filter gtk_file_chooser_add_filter
gtk_file_chooser_remove_filter gtk_file_chooser_remove_filter

View File

@ -117,32 +117,15 @@
* } * }
* ]| * ]|
* *
* # Adding Extra Widgets * # Adding options
* *
* You can add extra widgets to a file chooser to provide options * You can add extra widgets to a file chooser to provide options
* that are not present in the default design. For example, you * that are not present in the default design, by using
* can add a toggle button to give the user the option to open a * gtk_file_chooser_add_choice(). Each choice has an identifier and
* file in read-only mode. You can use * a user visible label; additionally, each choice can have multiple
* gtk_file_chooser_set_extra_widget() to insert additional * options. If a choice has no option, it will be rendered as a
* widgets in a file chooser. * check button with the given label; if a choice has options, it will
* * be rendered as a combo box.
* An example for adding extra widgets:
* |[<!-- language="C" -->
*
* GtkWidget *toggle;
*
* ...
*
* toggle = gtk_check_button_new_with_label ("Open file read-only");
* gtk_widget_show (toggle);
* gtk_file_chooser_set_extra_widget (my_file_chooser, toggle);
* }
* ]|
*
* If you want to set more than one extra widget in the file
* chooser, you can a container such as a #GtkBox or a #GtkGrid
* and include your widgets in it. Then, set the container as
* the whole extra widget.
*/ */
@ -385,12 +368,6 @@ gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
P_("Whether to display a label with the name of the previewed file."), P_("Whether to display a label with the name of the previewed file."),
TRUE, TRUE,
GTK_PARAM_READWRITE)); GTK_PARAM_READWRITE));
g_object_interface_install_property (iface,
g_param_spec_object ("extra-widget",
P_("Extra widget"),
P_("Application supplied widget for extra options."),
GTK_TYPE_WIDGET,
GTK_PARAM_READWRITE));
g_object_interface_install_property (iface, g_object_interface_install_property (iface,
g_param_spec_boolean ("select-multiple", g_param_spec_boolean ("select-multiple",
P_("Select Multiple"), P_("Select Multiple"),
@ -650,10 +627,7 @@ gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
* text entry for Name. * text entry for Name.
* *
* This is meant to be used in save dialogs, to get the currently typed filename * This is meant to be used in save dialogs, to get the currently typed filename
* when the file itself does not exist yet. For example, an application that * when the file itself does not exist yet.
* adds a custom extra widget to the file chooser for file format may want to
* change the extension of the typed filename based on the chosen format, say,
* from .jpg to .png.
* *
* Returns: The raw text from the file choosers Name entry. Free this with * Returns: The raw text from the file choosers Name entry. Free this with
* g_free(). Note that this string is not a full pathname or URI; it is * g_free(). Note that this string is not a full pathname or URI; it is
@ -1107,50 +1081,6 @@ gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, folder, error); return GTK_FILE_CHOOSER_GET_IFACE (chooser)->remove_shortcut_folder (chooser, folder, error);
} }
/**
* gtk_file_chooser_set_extra_widget:
* @chooser: a #GtkFileChooser
* @extra_widget: widget for extra options
*
* Sets an application-supplied widget to provide extra options to the user.
**/
void
gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
GtkWidget *extra_widget)
{
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
g_object_set (chooser, "extra-widget", extra_widget, NULL);
}
/**
* gtk_file_chooser_get_extra_widget:
* @chooser: a #GtkFileChooser
*
* Gets the current extra widget; see
* gtk_file_chooser_set_extra_widget().
*
* Returns: (nullable) (transfer none): the current extra widget, or %NULL
**/
GtkWidget *
gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser)
{
GtkWidget *extra_widget;
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
g_object_get (chooser, "extra-widget", &extra_widget, NULL);
/* Horrid hack; g_object_get() refs returned objects but
* that contradicts the memory management conventions
* for accessors.
*/
if (extra_widget)
g_object_unref (extra_widget);
return extra_widget;
}
/** /**
* gtk_file_chooser_add_filter: * gtk_file_chooser_add_filter:
* @chooser: a #GtkFileChooser * @chooser: a #GtkFileChooser
@ -1372,8 +1302,6 @@ gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
* a value using gtk_file_chooser_set_choice() before the dialog is shown, * 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 * and you can obtain the user-selected value in the ::response signal handler
* using gtk_file_chooser_get_choice(). * using gtk_file_chooser_get_choice().
*
* Compare gtk_file_chooser_set_extra_widget().
*/ */
void void
gtk_file_chooser_add_choice (GtkFileChooser *chooser, gtk_file_chooser_add_choice (GtkFileChooser *chooser,

View File

@ -205,14 +205,6 @@ gboolean gtk_file_chooser_get_use_preview_label (GtkFileChooser *chooser);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GFile *gtk_file_chooser_get_preview_file (GtkFileChooser *chooser); GFile *gtk_file_chooser_get_preview_file (GtkFileChooser *chooser);
/* Extra widget
*/
GDK_AVAILABLE_IN_ALL
void gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser,
GtkWidget *extra_widget);
GDK_AVAILABLE_IN_ALL
GtkWidget *gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser);
/* List of user selectable filters /* List of user selectable filters
*/ */
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL

View File

@ -925,7 +925,6 @@ gtk_file_chooser_button_set_property (GObject *object,
case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET: case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE: case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL: case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN: case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION: case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS: case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS:
@ -971,7 +970,6 @@ gtk_file_chooser_button_get_property (GObject *object,
case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET: case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE: case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL: case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE: case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN: case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION: case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:

View File

@ -165,8 +165,6 @@
* used. It supports many of the features that #GtkFileChooserDialog * used. It supports many of the features that #GtkFileChooserDialog
* does, but there are some things it does not handle: * does, but there are some things it does not handle:
* *
* * Extra widgets added with gtk_file_chooser_set_extra_widget().
*
* * Use of custom previews by connecting to #GtkFileChooser::update-preview. * * Use of custom previews by connecting to #GtkFileChooser::update-preview.
* *
* * Any #GtkFileFilter added using a mimetype or custom filter. * * Any #GtkFileFilter added using a mimetype or custom filter.
@ -182,8 +180,6 @@
* be a GTK+ file chooser. In this situation, the following things are not * be a GTK+ file chooser. In this situation, the following things are not
* supported and will be silently ignored: * supported and will be silently ignored:
* *
* * Extra widgets added with gtk_file_chooser_set_extra_widget().
*
* * Use of custom previews by connecting to #GtkFileChooser::update-preview. * * Use of custom previews by connecting to #GtkFileChooser::update-preview.
* *
* * Any #GtkFileFilter added with a custom filter. * * Any #GtkFileFilter added with a custom filter.
@ -194,10 +190,6 @@
* file chooser dialogs. Some features provided by #GtkFileChooserDialog are * file chooser dialogs. Some features provided by #GtkFileChooserDialog are
* not supported: * not supported:
* *
* * Extra widgets added with gtk_file_chooser_set_extra_widget(), unless the
* widget is an instance of GtkLabel, in which case the label text will be used
* to set the NSSavePanel message instance property.
*
* * Use of custom previews by connecting to #GtkFileChooser::update-preview. * * Use of custom previews by connecting to #GtkFileChooser::update-preview.
* *
* * Any #GtkFileFilter added with a custom filter. * * Any #GtkFileFilter added with a custom filter.

View File

@ -448,19 +448,8 @@ gtk_file_chooser_native_quartz_show (GtkFileChooserNative *self)
guint update_preview_signal; guint update_preview_signal;
GSList *filters, *l; GSList *filters, *l;
int n_filters, i; int n_filters, i;
GtkWidget *extra_widget = NULL;
char *message = NULL; char *message = NULL;
extra_widget = gtk_file_chooser_get_extra_widget (GTK_FILE_CHOOSER (self));
// if the extra_widget is a GtkLabel, then use its text to set the dialog message
if (extra_widget != NULL)
{
if (!GTK_IS_LABEL (extra_widget))
return FALSE;
else
message = g_strdup (gtk_label_get_text (GTK_LABEL (extra_widget)));
}
update_preview_signal = g_signal_lookup ("update-preview", GTK_TYPE_FILE_CHOOSER); update_preview_signal = g_signal_lookup ("update-preview", GTK_TYPE_FILE_CHOOSER);
if (g_signal_has_handler_pending (self, update_preview_signal, 0, TRUE)) if (g_signal_has_handler_pending (self, update_preview_signal, 0, TRUE))
return FALSE; return FALSE;

View File

@ -877,10 +877,6 @@ gtk_file_chooser_native_win32_show (GtkFileChooserNative *self)
GSList *filters, *l; GSList *filters, *l;
int n_filters, i; int n_filters, i;
if (gtk_file_chooser_get_extra_widget (GTK_FILE_CHOOSER (self)) != NULL &&
self->choices == NULL)
return FALSE;
update_preview_signal = g_signal_lookup ("update-preview", GTK_TYPE_FILE_CHOOSER); update_preview_signal = g_signal_lookup ("update-preview", GTK_TYPE_FILE_CHOOSER);
if (g_signal_has_handler_pending (self, update_preview_signal, 0, TRUE)) if (g_signal_has_handler_pending (self, update_preview_signal, 0, TRUE))
return FALSE; return FALSE;

View File

@ -99,9 +99,6 @@ _gtk_file_chooser_install_properties (GObjectClass *klass)
g_object_class_override_property (klass, g_object_class_override_property (klass,
GTK_FILE_CHOOSER_PROP_ACTION, GTK_FILE_CHOOSER_PROP_ACTION,
"action"); "action");
g_object_class_override_property (klass,
GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET,
"extra-widget");
g_object_class_override_property (klass, g_object_class_override_property (klass,
GTK_FILE_CHOOSER_PROP_FILTER, GTK_FILE_CHOOSER_PROP_FILTER,
"filter"); "filter");

View File

@ -34,7 +34,6 @@ typedef enum {
GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET, GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET,
GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE, GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE,
GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL, GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL,
GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET,
GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE, GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE,
GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN, GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN,
GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION, GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION,

View File

@ -3315,10 +3315,6 @@ gtk_file_chooser_widget_set_property (GObject *object,
update_preview_widget_visibility (impl); update_preview_widget_visibility (impl);
break; break;
case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
set_extra_widget (impl, g_value_get_object (value));
break;
case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE: case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
{ {
gboolean select_multiple = g_value_get_boolean (value); gboolean select_multiple = g_value_get_boolean (value);
@ -3405,10 +3401,6 @@ gtk_file_chooser_widget_get_property (GObject *object,
g_value_set_boolean (value, priv->use_preview_label); g_value_set_boolean (value, priv->use_preview_label);
break; break;
case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
g_value_set_object (value, priv->extra_widget);
break;
case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE: case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
g_value_set_boolean (value, priv->select_multiple); g_value_set_boolean (value, priv->select_multiple);
break; break;

View File

@ -5786,25 +5786,6 @@ native_overwrite_confirmation_toggle (GtkWidget *checkbutton,
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(checkbutton))); gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(checkbutton)));
} }
static void
native_extra_widget_toggle (GtkWidget *checkbutton,
GtkFileChooserNative *native)
{
gboolean extra_widget = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(checkbutton));
if (extra_widget)
{
GtkWidget *extra = gtk_check_button_new_with_label ("Extra toggle");
gtk_widget_show (extra);
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (native), extra);
}
else
{
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (native), NULL);
}
}
static void static void
native_visible_notify_show (GObject *object, native_visible_notify_show (GObject *object,
GParamSpec *pspec, GParamSpec *pspec,
@ -6028,11 +6009,6 @@ create_native_dialogs (GtkWidget *widget)
G_CALLBACK (native_overwrite_confirmation_toggle), native); G_CALLBACK (native_overwrite_confirmation_toggle), native);
gtk_container_add (GTK_CONTAINER (box), check_button); gtk_container_add (GTK_CONTAINER (box), check_button);
check_button = gtk_check_button_new_with_label ("Extra widget");
g_signal_connect (check_button, "toggled",
G_CALLBACK (native_extra_widget_toggle), native);
gtk_container_add (GTK_CONTAINER (box), check_button);
show_button = gtk_button_new_with_label ("Show"); show_button = gtk_button_new_with_label ("Show");
hide_button = gtk_button_new_with_label ("Hide"); hide_button = gtk_button_new_with_label ("Hide");
gtk_widget_set_sensitive (hide_button, FALSE); gtk_widget_set_sensitive (hide_button, FALSE);