diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index b5274ef4f7..a7cc587122 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -1483,6 +1483,8 @@ gtk_file_chooser_set_show_hidden gtk_file_chooser_get_show_hidden gtk_file_chooser_set_do_overwrite_confirmation gtk_file_chooser_get_do_overwrite_confirmation +gtk_file_chooser_set_create_folders +gtk_file_chooser_get_create_folders gtk_file_chooser_set_current_name gtk_file_chooser_get_filename gtk_file_chooser_set_filename diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index d120fec69f..bf8a06ee98 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -1531,6 +1531,8 @@ gtk_file_chooser_get_select_multiple gtk_file_chooser_get_show_hidden gtk_file_chooser_set_do_overwrite_confirmation gtk_file_chooser_get_do_overwrite_confirmation +gtk_file_chooser_set_create_folders +gtk_file_chooser_get_create_folders gtk_file_chooser_get_type G_GNUC_CONST gtk_file_chooser_get_uri gtk_file_chooser_get_uris diff --git a/gtk/gtkfilechooser.c b/gtk/gtkfilechooser.c index f113bea1f0..c8078b12a5 100644 --- a/gtk/gtkfilechooser.c +++ b/gtk/gtkfilechooser.c @@ -269,6 +269,22 @@ gtk_file_chooser_class_init (gpointer g_iface) "if necessary."), FALSE, GTK_PARAM_READWRITE)); + + /** + * GtkFileChooser:create-folders: + * + * Whether a file chooser not in %GTK_FILE_CHOOSER_ACTION_OPEN mode + * will offer the user to create new folders. + * + * Since: 2.18 + */ + g_object_interface_install_property (g_iface, + g_param_spec_boolean ("create-folders", + P_("Allow folders creation"), + P_("Whether a file chooser not in open mode " + "will offer the user to create new folders."), + TRUE, + GTK_PARAM_READWRITE)); } /** @@ -423,6 +439,49 @@ gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser) return select_multiple; } +/** + * gtk_file_chooser_set_create_folders: + * @chooser: a #GtkFileChooser + * @create_folders: %TRUE if the New Folder button should be displayed + * + * Sets whether file choser will offer to create new folders. + * This is only relevant if the action is not set to be + * GTK_FILE_CHOOSER_ACTION_OPEN. + * + * Since: 2.18 + **/ +void +gtk_file_chooser_set_create_folders (GtkFileChooser *chooser, + gboolean create_folders) +{ + g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser)); + + g_object_set (chooser, "create-folders", create_folders, NULL); +} + +/** + * gtk_file_chooser_get_create_folders: + * @chooser: a #GtkFileChooser + * + * Gets whether file choser will offer to create new folders. + * See gtk_file_chooser_set_create_folders(). + * + * Return value: %TRUE if the New Folder button should be displayed. + * + * Since: 2.18 + **/ +gboolean +gtk_file_chooser_get_create_folders (GtkFileChooser *chooser) +{ + gboolean create_folders; + + g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE); + + g_object_get (chooser, "create-folders", &create_folders, NULL); + + return create_folders; +} + /** * gtk_file_chooser_get_filename: * @chooser: a #GtkFileChooser diff --git a/gtk/gtkfilechooser.h b/gtk/gtkfilechooser.h index b7983a9660..0772690bd2 100644 --- a/gtk/gtkfilechooser.h +++ b/gtk/gtkfilechooser.h @@ -85,6 +85,10 @@ void gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChoo gboolean do_overwrite_confirmation); gboolean gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser); +void gtk_file_chooser_set_create_folders (GtkFileChooser *chooser, + gboolean create_folders); +gboolean gtk_file_chooser_get_create_folders (GtkFileChooser *chooser); + /* Suggested name for the Save-type actions */ void gtk_file_chooser_set_current_name (GtkFileChooser *chooser, diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c index 3b95adeeda..4319bb0298 100644 --- a/gtk/gtkfilechooserbutton.c +++ b/gtk/gtkfilechooserbutton.c @@ -810,6 +810,7 @@ gtk_file_chooser_button_set_property (GObject *object, case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET: case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN: case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION: + case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS: g_object_set_property (G_OBJECT (priv->dialog), pspec->name, value); break; diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 365f4e07fe..abcc0105d4 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -801,6 +801,7 @@ _gtk_file_chooser_default_init (GtkFileChooserDefault *impl) impl->sort_column = FILE_LIST_COL_NAME; impl->sort_order = GTK_SORT_ASCENDING; impl->recent_manager = gtk_recent_manager_get_default (); + impl->create_folders = TRUE; gtk_box_set_spacing (GTK_BOX (impl), 12); @@ -5621,7 +5622,7 @@ update_appearance (GtkFileChooserDefault *impl) if (impl->location_entry) _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action); - if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN) + if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN || !impl->create_folders) gtk_widget_hide (impl->browse_new_folder_button); else gtk_widget_show (impl->browse_new_folder_button); @@ -5736,6 +5737,14 @@ gtk_file_chooser_default_set_property (GObject *object, } break; + case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS: + { + gboolean create_folders = g_value_get_boolean (value); + impl->create_folders = create_folders; + update_appearance (impl); + } + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -5792,6 +5801,10 @@ gtk_file_chooser_default_get_property (GObject *object, g_value_set_boolean (value, impl->do_overwrite_confirmation); break; + case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS: + g_value_set_boolean (value, impl->create_folders); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -9211,7 +9224,7 @@ search_switch_to_browse_mode (GtkFileChooserDefault *impl) impl->search_entry = NULL; gtk_widget_show (impl->browse_path_bar); - if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN) + if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN || !impl->create_folders) gtk_widget_hide (impl->browse_new_folder_button); else gtk_widget_show (impl->browse_new_folder_button); @@ -9783,7 +9796,7 @@ recent_switch_to_browse_mode (GtkFileChooserDefault *impl) impl->recent_hbox = NULL; gtk_widget_show (impl->browse_path_bar); - if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN) + if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN || !impl->create_folders) gtk_widget_hide (impl->browse_new_folder_button); else gtk_widget_show (impl->browse_new_folder_button); diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h index be10757c29..ae7f183a57 100644 --- a/gtk/gtkfilechooserprivate.h +++ b/gtk/gtkfilechooserprivate.h @@ -308,6 +308,7 @@ struct _GtkFileChooserDefault guint has_search : 1; guint has_recent : 1; guint show_size_column : 1; + guint create_folders : 1; #if 0 guint shortcuts_drag_outside : 1; diff --git a/gtk/gtkfilechooserutils.c b/gtk/gtkfilechooserutils.c index 0eab525b3f..69c71d1116 100644 --- a/gtk/gtkfilechooserutils.c +++ b/gtk/gtkfilechooserutils.c @@ -117,6 +117,9 @@ _gtk_file_chooser_install_properties (GObjectClass *klass) g_object_class_override_property (klass, GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION, "do-overwrite-confirmation"); + g_object_class_override_property (klass, + GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS, + "create-folders"); } /** diff --git a/gtk/gtkfilechooserutils.h b/gtk/gtkfilechooserutils.h index c5c1aa75aa..a590cccd16 100644 --- a/gtk/gtkfilechooserutils.h +++ b/gtk/gtkfilechooserutils.h @@ -41,7 +41,8 @@ typedef enum { GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE, GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN, GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION, - GTK_FILE_CHOOSER_PROP_LAST = GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION + GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS, + GTK_FILE_CHOOSER_PROP_LAST = GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS } GtkFileChooserProp; void _gtk_file_chooser_install_properties (GObjectClass *klass);