Commit 9b5e00b3 authored by Matthias Clasen's avatar Matthias Clasen

file chooser entry: Capture Escape and emit :hide-entry

Make the file chooser entry optionally capture Escape
and emit a signal. Make the file chooser widget hide the
entry on that signal and go back to the path bar.
This gives us a two-level undo:
location entry -> path bar -> dialog close.
When the location entry is permanently displayed in the
header for save mode, we still let the first Escape close
the dialog.
parent e0b81faa
...@@ -558,7 +558,7 @@ setup_save_entry (GtkFileChooserDialog *dialog) ...@@ -558,7 +558,7 @@ setup_save_entry (GtkFileChooserDialog *dialog)
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
label = gtk_label_new_with_mnemonic (_("_Name")); label = gtk_label_new_with_mnemonic (_("_Name"));
entry = _gtk_file_chooser_entry_new (FALSE); entry = _gtk_file_chooser_entry_new (FALSE, FALSE);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry); gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
gtk_container_add (GTK_CONTAINER (box), label); gtk_container_add (GTK_CONTAINER (box), label);
gtk_container_add (GTK_CONTAINER (box), entry); gtk_container_add (GTK_CONTAINER (box), entry);
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "gtksizerequest.h" #include "gtksizerequest.h"
#include "gtkwindow.h" #include "gtkwindow.h"
#include "gtkintl.h" #include "gtkintl.h"
#include "gtkmarshalers.h"
typedef struct _GtkFileChooserEntryClass GtkFileChooserEntryClass; typedef struct _GtkFileChooserEntryClass GtkFileChooserEntryClass;
...@@ -59,6 +60,7 @@ struct _GtkFileChooserEntry ...@@ -59,6 +60,7 @@ struct _GtkFileChooserEntry
guint current_folder_loaded : 1; guint current_folder_loaded : 1;
guint complete_on_load : 1; guint complete_on_load : 1;
guint eat_tabs : 1; guint eat_tabs : 1;
guint eat_escape : 1;
guint local_only : 1; guint local_only : 1;
}; };
...@@ -69,6 +71,14 @@ enum ...@@ -69,6 +71,14 @@ enum
N_COLUMNS N_COLUMNS
}; };
enum
{
HIDE_ENTRY,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static void gtk_file_chooser_entry_finalize (GObject *object); static void gtk_file_chooser_entry_finalize (GObject *object);
static void gtk_file_chooser_entry_dispose (GObject *object); static void gtk_file_chooser_entry_dispose (GObject *object);
static void gtk_file_chooser_entry_grab_focus (GtkWidget *widget); static void gtk_file_chooser_entry_grab_focus (GtkWidget *widget);
...@@ -157,6 +167,15 @@ _gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class) ...@@ -157,6 +167,15 @@ _gtk_file_chooser_entry_class_init (GtkFileChooserEntryClass *class)
widget_class->grab_focus = gtk_file_chooser_entry_grab_focus; widget_class->grab_focus = gtk_file_chooser_entry_grab_focus;
widget_class->focus_out_event = gtk_file_chooser_entry_focus_out_event; widget_class->focus_out_event = gtk_file_chooser_entry_focus_out_event;
signals[HIDE_ENTRY] =
g_signal_new (I_("hide-entry"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
0,
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
} }
static void static void
...@@ -397,6 +416,13 @@ gtk_file_chooser_entry_tab_handler (GtkWidget *widget, ...@@ -397,6 +416,13 @@ gtk_file_chooser_entry_tab_handler (GtkWidget *widget,
chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget); chooser_entry = GTK_FILE_CHOOSER_ENTRY (widget);
editable = GTK_EDITABLE (widget); editable = GTK_EDITABLE (widget);
if (event->keyval == GDK_KEY_Escape &&
chooser_entry->eat_escape)
{
g_signal_emit (widget, signals[HIDE_ENTRY], 0);
return TRUE;
}
if (!chooser_entry->eat_tabs) if (!chooser_entry->eat_tabs)
return FALSE; return FALSE;
...@@ -709,6 +735,7 @@ delete_text_callback (GtkFileChooserEntry *chooser_entry, ...@@ -709,6 +735,7 @@ delete_text_callback (GtkFileChooserEntry *chooser_entry,
/** /**
* _gtk_file_chooser_entry_new: * _gtk_file_chooser_entry_new:
* @eat_tabs: If %FALSE, allow focus navigation with the tab key. * @eat_tabs: If %FALSE, allow focus navigation with the tab key.
* @eat_escape: If %TRUE, capture Escape key presses and emit ::hide-entry
* *
* Creates a new #GtkFileChooserEntry object. #GtkFileChooserEntry * Creates a new #GtkFileChooserEntry object. #GtkFileChooserEntry
* is an internal implementation widget for the GTK+ file chooser * is an internal implementation widget for the GTK+ file chooser
...@@ -718,12 +745,14 @@ delete_text_callback (GtkFileChooserEntry *chooser_entry, ...@@ -718,12 +745,14 @@ delete_text_callback (GtkFileChooserEntry *chooser_entry,
* Returns: the newly created #GtkFileChooserEntry * Returns: the newly created #GtkFileChooserEntry
**/ **/
GtkWidget * GtkWidget *
_gtk_file_chooser_entry_new (gboolean eat_tabs) _gtk_file_chooser_entry_new (gboolean eat_tabs,
gboolean eat_escape)
{ {
GtkFileChooserEntry *chooser_entry; GtkFileChooserEntry *chooser_entry;
chooser_entry = g_object_new (GTK_TYPE_FILE_CHOOSER_ENTRY, NULL); chooser_entry = g_object_new (GTK_TYPE_FILE_CHOOSER_ENTRY, NULL);
chooser_entry->eat_tabs = (eat_tabs != FALSE); chooser_entry->eat_tabs = (eat_tabs != FALSE);
chooser_entry->eat_escape = (eat_escape != FALSE);
return GTK_WIDGET (chooser_entry); return GTK_WIDGET (chooser_entry);
} }
......
...@@ -31,7 +31,8 @@ G_BEGIN_DECLS ...@@ -31,7 +31,8 @@ G_BEGIN_DECLS
typedef struct _GtkFileChooserEntry GtkFileChooserEntry; typedef struct _GtkFileChooserEntry GtkFileChooserEntry;
GType _gtk_file_chooser_entry_get_type (void) G_GNUC_CONST; GType _gtk_file_chooser_entry_get_type (void) G_GNUC_CONST;
GtkWidget * _gtk_file_chooser_entry_new (gboolean eat_tab); GtkWidget * _gtk_file_chooser_entry_new (gboolean eat_tab,
gboolean eat_escape);
void _gtk_file_chooser_entry_set_action (GtkFileChooserEntry *chooser_entry, void _gtk_file_chooser_entry_set_action (GtkFileChooserEntry *chooser_entry,
GtkFileChooserAction action); GtkFileChooserAction action);
GtkFileChooserAction _gtk_file_chooser_entry_get_action (GtkFileChooserEntry *chooser_entry); GtkFileChooserAction _gtk_file_chooser_entry_get_action (GtkFileChooserEntry *chooser_entry);
......
...@@ -2039,6 +2039,12 @@ location_entry_changed_cb (GtkEditable *editable, ...@@ -2039,6 +2039,12 @@ location_entry_changed_cb (GtkEditable *editable,
reset_location_timeout (impl); reset_location_timeout (impl);
} }
static void
location_entry_close_clicked (GtkFileChooserWidget *impl)
{
location_mode_set (impl, LOCATION_MODE_PATH_BAR);
}
static void static void
location_entry_setup (GtkFileChooserWidget *impl) location_entry_setup (GtkFileChooserWidget *impl)
{ {
...@@ -2050,6 +2056,8 @@ location_entry_setup (GtkFileChooserWidget *impl) ...@@ -2050,6 +2056,8 @@ location_entry_setup (GtkFileChooserWidget *impl)
g_signal_connect (priv->location_entry, "changed", g_signal_connect (priv->location_entry, "changed",
G_CALLBACK (location_entry_changed_cb), impl); G_CALLBACK (location_entry_changed_cb), impl);
g_signal_connect_swapped (priv->location_entry, "hide-entry",
G_CALLBACK (location_entry_close_clicked), impl);
_gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (priv->location_entry), priv->local_only); _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_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (priv->location_entry), priv->action);
...@@ -2073,7 +2081,7 @@ location_entry_create (GtkFileChooserWidget *impl) ...@@ -2073,7 +2081,7 @@ location_entry_create (GtkFileChooserWidget *impl)
if (!priv->location_entry) if (!priv->location_entry)
{ {
priv->location_entry = _gtk_file_chooser_entry_new (TRUE); priv->location_entry = _gtk_file_chooser_entry_new (TRUE, TRUE);
location_entry_setup (impl); location_entry_setup (impl);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment