mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-17 06:10:15 +00:00
file chooser widget: Allow external save entry
Prepare the file chooser to use an external entry in save mode, instead of the builtin one.
This commit is contained in:
parent
140a157d47
commit
4f3f61bf5f
@ -431,6 +431,7 @@ gtk_private_h_sources = \
|
||||
gtkfilechooserembed.h \
|
||||
gtkfilechooserentry.h \
|
||||
gtkfilechooserprivate.h \
|
||||
gtkfilechooserwidgetprivate.h \
|
||||
gtkfilechooserutils.h \
|
||||
gtkfilesystem.h \
|
||||
gtkfilesystemmodel.h \
|
||||
|
@ -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;
|
||||
@ -2036,6 +2039,33 @@ location_entry_changed_cb (GtkEditable *editable,
|
||||
reset_location_timeout (impl);
|
||||
}
|
||||
|
||||
static void
|
||||
location_entry_setup (GtkFileChooserWidget *impl)
|
||||
{
|
||||
GtkFileChooserWidgetPrivate *priv = impl->priv;
|
||||
|
||||
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);
|
||||
|
||||
_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);
|
||||
gtk_entry_set_width_chars (GTK_ENTRY (priv->location_entry), 45);
|
||||
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)
|
||||
{
|
||||
@ -2044,18 +2074,8 @@ location_entry_create (GtkFileChooserWidget *impl)
|
||||
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"));
|
||||
|
||||
g_signal_connect (priv->location_entry, "changed",
|
||||
G_CALLBACK (location_entry_changed_cb), impl);
|
||||
location_entry_setup (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);
|
||||
gtk_entry_set_width_chars (GTK_ENTRY (priv->location_entry), 45);
|
||||
gtk_entry_set_activates_default (GTK_ENTRY (priv->location_entry), TRUE);
|
||||
}
|
||||
|
||||
/* Creates the widgets specific to Save mode */
|
||||
@ -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)
|
||||
{
|
||||
|
35
gtk/gtkfilechooserwidgetprivate.h
Normal file
35
gtk/gtkfilechooserwidgetprivate.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Matthias Clasen
|
||||
*/
|
||||
|
||||
#ifndef __GTK_FILE_CHOOSER_WIDGET_PRIVATE_H__
|
||||
#define __GTK_FILE_CHOOSER_WIDGET_PRIVATE_H__
|
||||
|
||||
#include <glib.h>
|
||||
#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__ */
|
Loading…
Reference in New Issue
Block a user