[gtk+/wip/matthiasc/filechooser: 8/13] file chooser widget: Allow external save entry
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/filechooser: 8/13] file chooser widget: Allow external save entry
- Date: Sat, 27 Jun 2015 05:44:12 +0000 (UTC)
commit 7439d18e3430cd990c9c4180517cd3a016f5d8da
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jun 27 00:07:59 2015 -0400
file chooser widget: Allow external save entry
Prepare the file chooser to use an external entry in
save mode, instead of the builtin one.
gtk/Makefile.am | 1 +
gtk/gtkfilechooserwidget.c | 79 ++++++++++++++++++++++++++++++++-----
gtk/gtkfilechooserwidgetprivate.h | 35 ++++++++++++++++
3 files changed, 105 insertions(+), 10 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 50e8efb..861f186 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 18294c6..86befdb 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;
@@ -2974,6 +3008,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);
}
@@ -7656,6 +7696,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 0000000..00724c9
--- /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 <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__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]