From: Matthias Clasen Date: Sat, 27 Jun 2015 04:07:59 +0000 (-0400) Subject: file chooser widget: Allow external save entry X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~24^2~9199 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=4f3f61bf5ffe3c57dcbb21e87902816687067827;p=gtk4.git file chooser widget: Allow external save entry Prepare the file chooser to use an external entry in save mode, instead of the builtin one. --- diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 50e8efb21f..861f186370 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -431,6 +431,7 @@ gtk_private_h_sources = \ gtkfilechooserembed.h \ gtkfilechooserentry.h \ gtkfilechooserprivate.h \ + gtkfilechooserwidgetprivate.h \ gtkfilechooserutils.h \ gtkfilesystem.h \ gtkfilesystemmodel.h \ diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 5b13265a03..7c18f2600d 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -25,6 +25,7 @@ #include "config.h" #include "gtkfilechooserwidget.h" +#include "gtkfilechooserwidgetprivate.h" #include "gtkbindings.h" #include "gtkbutton.h" @@ -266,6 +267,8 @@ struct _GtkFileChooserWidgetPrivate { GtkWidget *location_entry; LocationMode location_mode; + GtkWidget *external_entry; + /* Handles */ GCancellable *file_list_drag_data_received_cancellable; GCancellable *update_current_folder_cancellable; @@ -2037,20 +2040,16 @@ location_entry_changed_cb (GtkEditable *editable, } static void -location_entry_create (GtkFileChooserWidget *impl) +location_entry_setup (GtkFileChooserWidget *impl) { GtkFileChooserWidgetPrivate *priv = impl->priv; - if (!priv->location_entry) - { - priv->location_entry = _gtk_file_chooser_entry_new (TRUE); - if (priv->action == GTK_FILE_CHOOSER_ACTION_OPEN || - priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) - gtk_entry_set_placeholder_text (GTK_ENTRY (priv->location_entry), _("Location")); + if (priv->action == GTK_FILE_CHOOSER_ACTION_OPEN || + priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) + gtk_entry_set_placeholder_text (GTK_ENTRY (priv->location_entry), _("Location")); - g_signal_connect (priv->location_entry, "changed", - G_CALLBACK (location_entry_changed_cb), impl); - } + g_signal_connect (priv->location_entry, "changed", + G_CALLBACK (location_entry_changed_cb), impl); _gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (priv->location_entry), priv->local_only); _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (priv->location_entry), priv->action); @@ -2058,6 +2057,27 @@ location_entry_create (GtkFileChooserWidget *impl) gtk_entry_set_activates_default (GTK_ENTRY (priv->location_entry), TRUE); } +static void +location_entry_disconnect (GtkFileChooserWidget *impl) +{ + GtkFileChooserWidgetPrivate *priv = impl->priv; + + if (priv->location_entry) + g_signal_handlers_disconnect_by_func (priv->location_entry, location_entry_changed_cb, impl); +} + +static void +location_entry_create (GtkFileChooserWidget *impl) +{ + GtkFileChooserWidgetPrivate *priv = impl->priv; + + if (!priv->location_entry) + { + priv->location_entry = _gtk_file_chooser_entry_new (TRUE); + location_entry_setup (impl); + } +} + /* Creates the widgets specific to Save mode */ static void save_widgets_create (GtkFileChooserWidget *impl) @@ -2071,6 +2091,14 @@ save_widgets_create (GtkFileChooserWidget *impl) location_switch_to_path_bar (impl); + if (priv->external_entry) + { + location_entry_disconnect (impl); + priv->location_entry = priv->external_entry; + location_entry_setup (impl); + return; + } + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_style_context_add_class (gtk_widget_get_style_context (vbox), "search-bar"); @@ -2111,6 +2139,12 @@ save_widgets_destroy (GtkFileChooserWidget *impl) { GtkFileChooserWidgetPrivate *priv = impl->priv; + if (priv->external_entry && priv->external_entry == priv->location_entry) + { + location_entry_disconnect (impl); + priv->location_entry = NULL; + } + if (priv->save_widgets == NULL) return; @@ -2968,6 +3002,12 @@ gtk_file_chooser_widget_dispose (GObject *object) priv->bookmarks_manager = NULL; } + if (priv->external_entry && priv->location_entry == priv->external_entry) + { + location_entry_disconnect (impl); + priv->external_entry = NULL; + } + G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->dispose (object); } @@ -7649,6 +7689,25 @@ post_process_ui (GtkFileChooserWidget *impl) gtk_popover_set_default_widget (GTK_POPOVER (impl->priv->new_folder_popover), impl->priv->new_folder_create_button); } +void +gtk_file_chooser_widget_set_save_entry (GtkFileChooserWidget *impl, + GtkWidget *entry) +{ + GtkFileChooserWidgetPrivate *priv = impl->priv; + + g_return_if_fail (GTK_IS_FILE_CHOOSER_WIDGET (impl)); + g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (entry)); + + priv->external_entry = entry; + + if (priv->action == GTK_FILE_CHOOSER_ACTION_SAVE || + priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) + { + save_widgets_destroy (impl); + save_widgets_create (impl); + } +} + static void gtk_file_chooser_widget_init (GtkFileChooserWidget *impl) { diff --git a/gtk/gtkfilechooserwidgetprivate.h b/gtk/gtkfilechooserwidgetprivate.h new file mode 100644 index 0000000000..00724c9a38 --- /dev/null +++ b/gtk/gtkfilechooserwidgetprivate.h @@ -0,0 +1,35 @@ +/* gtkfilechooserwidgetprivate.h + * + * Copyright (C) 2015 Red Hat + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: Matthias Clasen + */ + +#ifndef __GTK_FILE_CHOOSER_WIDGET_PRIVATE_H__ +#define __GTK_FILE_CHOOSER_WIDGET_PRIVATE_H__ + +#include +#include "gtkfilechooserwidget.h" + +G_BEGIN_DECLS + +void +gtk_file_chooser_widget_set_save_entry (GtkFileChooserWidget *chooser, + GtkWidget *entry); + +G_END_DECLS + +#endif /* __GTK_FILE_CHOOSER_WIDGET_PRIVATE_H__ */