diff options
author | Ernestas Kulik <ernestask@src.gnome.org> | 2016-08-29 23:22:13 +0300 |
---|---|---|
committer | Ernestas Kulik <ernestask@src.gnome.org> | 2016-08-30 21:09:46 +0300 |
commit | e92e417152081500a0188eeee346c1bc9636e276 (patch) | |
tree | 8e78b1274c0895879156ec944048a7332e786d36 | |
parent | 18915442e63a99022fd2a0d39f1f0c4edbbdd8c7 (diff) | |
download | nautilus-e92e417152081500a0188eeee346c1bc9636e276.tar.gz |
Remove NautilusEntry
NautilusEntry was written to work around some issues with GtkEntry,
which are largely irrelevant, since its use has lessened over the years.
This commit removes the class.
https://bugzilla.gnome.org/show_bug.cgi?id=770578
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/nautilus-entry.c | 386 | ||||
-rw-r--r-- | src/nautilus-entry.h | 67 | ||||
-rw-r--r-- | src/nautilus-location-entry.c | 208 | ||||
-rw-r--r-- | src/nautilus-location-entry.h | 29 | ||||
-rw-r--r-- | src/nautilus-properties-window.c | 80 | ||||
-rw-r--r-- | src/nautilus-window.c | 2 |
7 files changed, 202 insertions, 572 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 99edf8fa0..e0b7b663b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -269,8 +269,6 @@ nautilus_no_main_sources = \ nautilus-directory.h \ nautilus-dnd.c \ nautilus-dnd.h \ - nautilus-entry.c \ - nautilus-entry.h \ nautilus-file-attributes.h \ nautilus-file-changes-queue.c \ nautilus-file-changes-queue.h \ diff --git a/src/nautilus-entry.c b/src/nautilus-entry.c deleted file mode 100644 index e8110ab87..000000000 --- a/src/nautilus-entry.c +++ /dev/null @@ -1,386 +0,0 @@ -/* NautilusEntry: one-line text editing widget. This consists of bug fixes - * and other improvements to GtkEntry, and all the changes could be rolled - * into GtkEntry some day. - * - * Copyright (C) 2000 Eazel, Inc. - * - * Author: John Sullivan <sullivan@eazel.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include "nautilus-entry.h" - -#include <string.h> -#include "nautilus-global-preferences.h" -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> -#include <glib/gi18n.h> - -struct NautilusEntryDetails -{ - gboolean special_tab_handling; - - guint select_idle_id; -}; - -enum -{ - SELECTION_CHANGED, - LAST_SIGNAL -}; -static guint signals[LAST_SIGNAL]; - -static void nautilus_entry_editable_init (GtkEditableInterface *iface); - -G_DEFINE_TYPE_WITH_CODE (NautilusEntry, nautilus_entry, GTK_TYPE_ENTRY, - G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, - nautilus_entry_editable_init)); - -static GtkEditableInterface *parent_editable_interface = NULL; - -static void -nautilus_entry_init (NautilusEntry *entry) -{ - entry->details = g_new0 (NautilusEntryDetails, 1); -} - -GtkWidget * -nautilus_entry_new (void) -{ - return gtk_widget_new (NAUTILUS_TYPE_ENTRY, NULL); -} - -static void -nautilus_entry_finalize (GObject *object) -{ - NautilusEntry *entry; - - entry = NAUTILUS_ENTRY (object); - - if (entry->details->select_idle_id != 0) - { - g_source_remove (entry->details->select_idle_id); - } - - g_free (entry->details); - - G_OBJECT_CLASS (nautilus_entry_parent_class)->finalize (object); -} - -static gboolean -nautilus_entry_key_press (GtkWidget *widget, - GdkEventKey *event) -{ - NautilusEntry *entry; - GtkEditable *editable; - int position; - gboolean old_has, new_has; - gboolean result; - - entry = NAUTILUS_ENTRY (widget); - editable = GTK_EDITABLE (widget); - - if (!gtk_editable_get_editable (editable)) - { - return FALSE; - } - - switch (event->keyval) - { - case GDK_KEY_Tab: - { - /* The location bar entry wants TAB to work kind of - * like it does in the shell for command completion, - * so if we get a tab and there's a selection, we - * should position the insertion point at the end of - * the selection. - */ - if (entry->details->special_tab_handling && gtk_editable_get_selection_bounds (editable, NULL, NULL)) - { - position = strlen (gtk_entry_get_text (GTK_ENTRY (editable))); - gtk_editable_select_region (editable, position, position); - return TRUE; - } - } - break; - - default: - { - } - break; - } - - old_has = gtk_editable_get_selection_bounds (editable, NULL, NULL); - - result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->key_press_event (widget, event); - - /* Pressing a key usually changes the selection if there is a selection. - * If there is not selection, we can save work by not emitting a signal. - */ - if (result) - { - new_has = gtk_editable_get_selection_bounds (editable, NULL, NULL); - if (old_has || new_has) - { - g_signal_emit (widget, signals[SELECTION_CHANGED], 0); - } - } - - return result; -} - -static gboolean -nautilus_entry_motion_notify (GtkWidget *widget, - GdkEventMotion *event) -{ - int result; - gboolean old_had, new_had; - int old_start, old_end, new_start, new_end; - GtkEditable *editable; - - editable = GTK_EDITABLE (widget); - - old_had = gtk_editable_get_selection_bounds (editable, &old_start, &old_end); - - result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->motion_notify_event (widget, event); - - /* Send a signal if dragging the mouse caused the selection to change. */ - if (result) - { - new_had = gtk_editable_get_selection_bounds (editable, &new_start, &new_end); - if (old_had != new_had || (old_had && (old_start != new_start || old_end != new_end))) - { - g_signal_emit (widget, signals[SELECTION_CHANGED], 0); - } - } - - return result; -} - -/** - * nautilus_entry_select_all - * - * Select all text, leaving the text cursor position at the end. - * - * @entry: A NautilusEntry - **/ -void -nautilus_entry_select_all (NautilusEntry *entry) -{ - g_return_if_fail (NAUTILUS_IS_ENTRY (entry)); - - gtk_editable_set_position (GTK_EDITABLE (entry), -1); - gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1); -} - -static gboolean -select_all_at_idle (gpointer callback_data) -{ - NautilusEntry *entry; - - entry = NAUTILUS_ENTRY (callback_data); - - nautilus_entry_select_all (entry); - - entry->details->select_idle_id = 0; - - return FALSE; -} - -/** - * nautilus_entry_select_all_at_idle - * - * Select all text at the next idle, not immediately. - * This is useful when reacting to a key press, because - * changing the selection and the text cursor position doesn't - * work in a key_press signal handler. - * - * @entry: A NautilusEntry - **/ -void -nautilus_entry_select_all_at_idle (NautilusEntry *entry) -{ - g_return_if_fail (NAUTILUS_IS_ENTRY (entry)); - - /* If the text cursor position changes in this routine - * then gtk_entry_key_press will unselect (and we want - * to move the text cursor position to the end). - */ - - if (entry->details->select_idle_id == 0) - { - entry->details->select_idle_id = g_idle_add (select_all_at_idle, entry); - } -} - -/** - * nautilus_entry_set_text - * - * This function wraps gtk_entry_set_text. It sets undo_registered - * to TRUE and preserves the old value for a later restore. This is - * done so the programmatic changes to the entry do not register - * with the undo manager. - * - * @entry: A NautilusEntry - * @test: The text to set - **/ - -void -nautilus_entry_set_text (NautilusEntry *entry, - const gchar *text) -{ - g_return_if_fail (NAUTILUS_IS_ENTRY (entry)); - - gtk_entry_set_text (GTK_ENTRY (entry), text); - g_signal_emit (entry, signals[SELECTION_CHANGED], 0); -} - -static void -nautilus_entry_set_selection_bounds (GtkEditable *editable, - int start_pos, - int end_pos) -{ - parent_editable_interface->set_selection_bounds (editable, start_pos, end_pos); - - g_signal_emit (editable, signals[SELECTION_CHANGED], 0); -} - -static gboolean -nautilus_entry_button_press (GtkWidget *widget, - GdkEventButton *event) -{ - gboolean result; - - result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->button_press_event (widget, event); - - if (result) - { - g_signal_emit (widget, signals[SELECTION_CHANGED], 0); - } - - return result; -} - -static gboolean -nautilus_entry_button_release (GtkWidget *widget, - GdkEventButton *event) -{ - gboolean result; - - result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->button_release_event (widget, event); - - if (result) - { - g_signal_emit (widget, signals[SELECTION_CHANGED], 0); - } - - return result; -} - -static void -nautilus_entry_insert_text (GtkEditable *editable, - const gchar *text, - int length, - int *position) -{ - parent_editable_interface->insert_text (editable, text, length, position); - - g_signal_emit (editable, signals[SELECTION_CHANGED], 0); -} - -static void -nautilus_entry_delete_text (GtkEditable *editable, - int start_pos, - int end_pos) -{ - parent_editable_interface->delete_text (editable, start_pos, end_pos); - - g_signal_emit (editable, signals[SELECTION_CHANGED], 0); -} - -/* Overridden to work around GTK bug. The selection_clear_event is queued - * when the selection changes. Changing the selection to NULL and then - * back to the original selection owner still sends the event, so the - * selection owner then gets the selection ripped away from it. We ran into - * this with type-completion behavior in NautilusLocationBar (see bug 5313). - * There's a FIXME comment that seems to be about this same issue in - * gtk+/gtkselection.c, gtk_selection_clear. - */ -static gboolean -nautilus_entry_selection_clear (GtkWidget *widget, - GdkEventSelection *event) -{ - g_assert (NAUTILUS_IS_ENTRY (widget)); - - if (gdk_selection_owner_get (event->selection) == gtk_widget_get_window (widget)) - { - return FALSE; - } - - return GTK_WIDGET_CLASS (nautilus_entry_parent_class)->selection_clear_event (widget, event); -} - -static void -nautilus_entry_editable_init (GtkEditableInterface *iface) -{ - parent_editable_interface = g_type_interface_peek_parent (iface); - - iface->insert_text = nautilus_entry_insert_text; - iface->delete_text = nautilus_entry_delete_text; - iface->set_selection_bounds = nautilus_entry_set_selection_bounds; - - /* Otherwise we might need some memcpy loving */ - g_assert (iface->do_insert_text != NULL); - g_assert (iface->get_position != NULL); - g_assert (iface->get_chars != NULL); -} - -static void -nautilus_entry_class_init (NautilusEntryClass *class) -{ - GtkWidgetClass *widget_class; - GObjectClass *gobject_class; - - widget_class = GTK_WIDGET_CLASS (class); - gobject_class = G_OBJECT_CLASS (class); - - widget_class->button_press_event = nautilus_entry_button_press; - widget_class->button_release_event = nautilus_entry_button_release; - widget_class->key_press_event = nautilus_entry_key_press; - widget_class->motion_notify_event = nautilus_entry_motion_notify; - widget_class->selection_clear_event = nautilus_entry_selection_clear; - - gobject_class->finalize = nautilus_entry_finalize; - - /* Set up signals */ - signals[SELECTION_CHANGED] = g_signal_new - ("selection-changed", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (NautilusEntryClass, selection_changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - -void -nautilus_entry_set_special_tab_handling (NautilusEntry *entry, - gboolean special_tab_handling) -{ - g_return_if_fail (NAUTILUS_IS_ENTRY (entry)); - - entry->details->special_tab_handling = special_tab_handling; -} diff --git a/src/nautilus-entry.h b/src/nautilus-entry.h deleted file mode 100644 index eb6d9779d..000000000 --- a/src/nautilus-entry.h +++ /dev/null @@ -1,67 +0,0 @@ - -/* NautilusEntry: one-line text editing widget. This consists of bug fixes - * and other improvements to GtkEntry, and all the changes could be rolled - * into GtkEntry some day. - * - * Copyright (C) 2000 Eazel, Inc. - * - * Author: John Sullivan <sullivan@eazel.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef NAUTILUS_ENTRY_H -#define NAUTILUS_ENTRY_H - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define NAUTILUS_TYPE_ENTRY nautilus_entry_get_type() -#define NAUTILUS_ENTRY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_ENTRY, NautilusEntry)) -#define NAUTILUS_ENTRY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_ENTRY, NautilusEntryClass)) -#define NAUTILUS_IS_ENTRY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_ENTRY)) -#define NAUTILUS_IS_ENTRY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_ENTRY)) -#define NAUTILUS_ENTRY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_ENTRY, NautilusEntryClass)) - -typedef struct NautilusEntryDetails NautilusEntryDetails; - -typedef struct { - GtkEntry parent; - NautilusEntryDetails *details; -} NautilusEntry; - -typedef struct { - GtkEntryClass parent_class; - - void (*selection_changed) (NautilusEntry *entry); -} NautilusEntryClass; - -GType nautilus_entry_get_type (void); -GtkWidget *nautilus_entry_new (void); -void nautilus_entry_set_text (NautilusEntry *entry, - const char *text); -void nautilus_entry_select_all (NautilusEntry *entry); -void nautilus_entry_select_all_at_idle (NautilusEntry *entry); -void nautilus_entry_set_special_tab_handling (NautilusEntry *entry, - gboolean special_tab_handling); - -G_END_DECLS - -#endif /* NAUTILUS_ENTRY_H */ diff --git a/src/nautilus-location-entry.c b/src/nautilus-location-entry.c index 73af0efa5..17f4a8846 100644 --- a/src/nautilus-location-entry.c +++ b/src/nautilus-location-entry.c @@ -37,7 +37,6 @@ #include <glib/gi18n.h> #include <gio/gio.h> #include "nautilus-file-utilities.h" -#include "nautilus-entry.h" #include "nautilus-clipboard.h" #include <eel/eel-stock-dialogs.h> #include <eel/eel-string.h> @@ -67,7 +66,7 @@ static const GtkTargetEntry drop_types [] = { NAUTILUS_DND_TEXT_PLAIN_TYPE, 0, NAUTILUS_DND_TEXT_PLAIN }, }; -struct NautilusLocationEntryDetails +typedef struct _NautilusLocationEntryPrivate { char *current_directory; GFilenameCompleter *completer; @@ -80,7 +79,7 @@ struct NautilusLocationEntryDetails gboolean setting_special_text; gchar *special_text; NautilusLocationEntryAction secondary_action; -}; +} NautilusLocationEntryPrivate; enum { @@ -91,17 +90,7 @@ enum static guint signals[LAST_SIGNAL]; -G_DEFINE_TYPE (NautilusLocationEntry, nautilus_location_entry, NAUTILUS_TYPE_ENTRY); - -void -nautilus_location_entry_focus (NautilusLocationEntry *entry) -{ - /* Put the keyboard focus in the text field when switching to this mode, - * and select all text for easy overtyping - */ - gtk_widget_grab_focus (GTK_WIDGET (entry)); - nautilus_entry_select_all (NAUTILUS_ENTRY (entry)); -} +G_DEFINE_TYPE_WITH_PRIVATE (NautilusLocationEntry, nautilus_location_entry, GTK_TYPE_ENTRY); static GFile * nautilus_location_entry_get_location (NautilusLocationEntry *entry) @@ -129,10 +118,13 @@ emit_location_changed (NautilusLocationEntry *entry) static void nautilus_location_entry_update_action (NautilusLocationEntry *entry) { + NautilusLocationEntryPrivate *priv; const char *current_text; GFile *location; - if (entry->details->last_location == NULL) + priv = nautilus_location_entry_get_instance_private (entry); + + if (priv->last_location == NULL) { nautilus_location_entry_set_secondary_action (entry, NAUTILUS_LOCATION_ENTRY_ACTION_GOTO); @@ -142,7 +134,7 @@ nautilus_location_entry_update_action (NautilusLocationEntry *entry) current_text = gtk_entry_get_text (GTK_ENTRY (entry)); location = g_file_parse_name (current_text); - if (g_file_equal (entry->details->last_location, location)) + if (g_file_equal (priv->last_location, location)) { nautilus_location_entry_set_secondary_action (entry, NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR); @@ -182,10 +174,14 @@ static void nautilus_location_entry_update_current_uri (NautilusLocationEntry *entry, const char *uri) { - g_free (entry->details->current_directory); - entry->details->current_directory = g_strdup (uri); + NautilusLocationEntryPrivate *priv; + + priv = nautilus_location_entry_get_instance_private (entry); + + g_free (priv->current_directory); + priv->current_directory = g_strdup (uri); - nautilus_entry_set_text (NAUTILUS_ENTRY (entry), uri); + gtk_entry_set_text (GTK_ENTRY (entry), uri); set_position_and_selection_to_end (GTK_EDITABLE (entry)); } @@ -193,10 +189,13 @@ void nautilus_location_entry_set_location (NautilusLocationEntry *entry, GFile *location) { + NautilusLocationEntryPrivate *priv; gchar *uri, *formatted_uri; g_assert (location != NULL); + priv = nautilus_location_entry_get_instance_private (entry); + /* Note: This is called in reaction to external changes, and * thus should not emit the LOCATION_CHANGED signal. */ uri = g_file_get_uri (location); @@ -212,11 +211,11 @@ nautilus_location_entry_set_location (NautilusLocationEntry *entry, } /* remember the original location for later comparison */ - if (!entry->details->last_location || - !g_file_equal (entry->details->last_location, location)) + if (!priv->last_location || + !g_file_equal (priv->last_location, location)) { - g_clear_object (&entry->details->last_location); - entry->details->last_location = g_object_ref (location); + g_clear_object (&priv->last_location); + priv->last_location = g_object_ref (location); } nautilus_location_entry_update_action (entry); @@ -361,28 +360,30 @@ static gboolean try_to_expand_path (gpointer callback_data) { NautilusLocationEntry *entry; + NautilusLocationEntryPrivate *priv; GtkEditable *editable; char *suffix, *user_location, *absolute_location, *uri_scheme; int user_location_length, pos; entry = NAUTILUS_LOCATION_ENTRY (callback_data); + priv = nautilus_location_entry_get_instance_private (entry); editable = GTK_EDITABLE (entry); user_location = gtk_editable_get_chars (editable, 0, -1); user_location_length = g_utf8_strlen (user_location, -1); - entry->details->idle_id = 0; + priv->idle_id = 0; uri_scheme = g_uri_parse_scheme (user_location); if (!g_path_is_absolute (user_location) && uri_scheme == NULL && user_location[0] != '~') { - absolute_location = g_build_filename (entry->details->current_directory, user_location, NULL); - suffix = g_filename_completer_get_completion_suffix (entry->details->completer, + absolute_location = g_build_filename (priv->current_directory, user_location, NULL); + suffix = g_filename_completer_get_completion_suffix (priv->completer, absolute_location); g_free (absolute_location); } else { - suffix = g_filename_completer_get_completion_suffix (entry->details->completer, + suffix = g_filename_completer_get_completion_suffix (priv->completer, user_location); } @@ -468,10 +469,14 @@ static void got_completion_data_callback (GFilenameCompleter *completer, NautilusLocationEntry *entry) { - if (entry->details->idle_id) + NautilusLocationEntryPrivate *priv; + + priv = nautilus_location_entry_get_instance_private (entry); + + if (priv->idle_id) { - g_source_remove (entry->details->idle_id); - entry->details->idle_id = 0; + g_source_remove (priv->idle_id); + priv->idle_id = 0; } try_to_expand_path (entry); } @@ -481,6 +486,7 @@ editable_event_after_callback (GtkEntry *entry, GdkEvent *event, NautilusLocationEntry *location_entry) { + NautilusLocationEntryPrivate *priv; GtkEditable *editable; GdkEventKey *keyevent; @@ -489,6 +495,7 @@ editable_event_after_callback (GtkEntry *entry, return; } + priv = nautilus_location_entry_get_instance_private (location_entry); editable = GTK_EDITABLE (entry); keyevent = (GdkEventKey *) event; @@ -513,9 +520,9 @@ editable_event_after_callback (GtkEntry *entry, { if (entry_would_have_inserted_characters (keyevent)) { - if (location_entry->details->idle_id == 0) + if (priv->idle_id == 0) { - location_entry->details->idle_id = g_idle_add (try_to_expand_path, location_entry); + priv->idle_id = g_idle_add (try_to_expand_path, location_entry); } } } @@ -524,10 +531,10 @@ editable_event_after_callback (GtkEntry *entry, /* FIXME: Also might be good to do this when you click * to change the position or selection. */ - if (location_entry->details->idle_id != 0) + if (priv->idle_id != 0) { - g_source_remove (location_entry->details->idle_id); - location_entry->details->idle_id = 0; + g_source_remove (priv->idle_id); + priv->idle_id = 0; } } } @@ -536,13 +543,15 @@ static void finalize (GObject *object) { NautilusLocationEntry *entry; + NautilusLocationEntryPrivate *priv; entry = NAUTILUS_LOCATION_ENTRY (object); + priv = nautilus_location_entry_get_instance_private (entry); - g_object_unref (entry->details->completer); - g_free (entry->details->special_text); + g_object_unref (priv->completer); + g_free (priv->special_text); - g_clear_object (&entry->details->last_location); + g_clear_object (&priv->last_location); G_OBJECT_CLASS (nautilus_location_entry_parent_class)->finalize (object); } @@ -551,18 +560,20 @@ static void destroy (GtkWidget *object) { NautilusLocationEntry *entry; + NautilusLocationEntryPrivate *priv; entry = NAUTILUS_LOCATION_ENTRY (object); + priv = nautilus_location_entry_get_instance_private (entry); /* cancel the pending idle call, if any */ - if (entry->details->idle_id != 0) + if (priv->idle_id != 0) { - g_source_remove (entry->details->idle_id); - entry->details->idle_id = 0; + g_source_remove (priv->idle_id); + priv->idle_id = 0; } - g_free (entry->details->current_directory); - entry->details->current_directory = NULL; + g_free (priv->current_directory); + priv->current_directory = NULL; GTK_WIDGET_CLASS (nautilus_location_entry_parent_class)->destroy (object); } @@ -571,12 +582,16 @@ static void nautilus_location_entry_text_changed (NautilusLocationEntry *entry, GParamSpec *pspec) { - if (entry->details->setting_special_text) + NautilusLocationEntryPrivate *priv; + + priv = nautilus_location_entry_get_instance_private (entry); + + if (priv->setting_special_text) { return; } - entry->details->has_special_text = FALSE; + priv->has_special_text = FALSE; } static void @@ -585,7 +600,13 @@ nautilus_location_entry_icon_release (GtkEntry *gentry, GdkEvent *event, gpointer unused) { - switch (NAUTILUS_LOCATION_ENTRY (gentry)->details->secondary_action) + NautilusLocationEntry *entry; + NautilusLocationEntryPrivate *priv; + + entry = NAUTILUS_LOCATION_ENTRY (gentry); + priv = nautilus_location_entry_get_instance_private (entry); + + switch (priv->secondary_action) { case NAUTILUS_LOCATION_ENTRY_ACTION_GOTO: { @@ -609,25 +630,69 @@ nautilus_location_entry_focus_in (GtkWidget *widget, GdkEventFocus *event) { NautilusLocationEntry *entry = NAUTILUS_LOCATION_ENTRY (widget); + NautilusLocationEntryPrivate *priv; - if (entry->details->has_special_text) + priv = nautilus_location_entry_get_instance_private (entry); + + if (priv->has_special_text) { - entry->details->setting_special_text = TRUE; + priv->setting_special_text = TRUE; gtk_entry_set_text (GTK_ENTRY (entry), ""); - entry->details->setting_special_text = FALSE; + priv->setting_special_text = FALSE; } return GTK_WIDGET_CLASS (nautilus_location_entry_parent_class)->focus_in_event (widget, event); } +static gboolean +nautilus_location_entry_on_key_press (GtkWidget *widget, + GdkEventKey *event) +{ + NautilusLocationEntry *entry; + GtkEditable *editable; + GtkWidgetClass *parent_widget_class; + int position; + gboolean result; + + entry = NAUTILUS_LOCATION_ENTRY (widget); + editable = GTK_EDITABLE (widget); + + if (!gtk_editable_get_editable (editable)) + { + return FALSE; + } + + /* The location bar entry wants TAB to work kind of + * like it does in the shell for command completion, + * so if we get a tab and there's a selection, we + * should position the insertion point at the end of + * the selection. + */ + if (event->keyval == GDK_KEY_Tab && + gtk_editable_get_selection_bounds (editable, NULL, NULL)) + { + position = strlen (gtk_entry_get_text (GTK_ENTRY (editable))); + gtk_editable_select_region (editable, position, position); + + return TRUE; + } + + parent_widget_class = GTK_WIDGET_CLASS (nautilus_location_entry_parent_class); + result = parent_widget_class->key_press_event (widget, event); + + return result; +} + static void nautilus_location_entry_activate (GtkEntry *entry) { NautilusLocationEntry *loc_entry; + NautilusLocationEntryPrivate *priv; const gchar *entry_text; gchar *full_path, *uri_scheme = NULL; loc_entry = NAUTILUS_LOCATION_ENTRY (entry); + priv = nautilus_location_entry_get_instance_private (loc_entry); entry_text = gtk_entry_get_text (entry); if (entry_text != NULL && *entry_text != '\0') @@ -637,7 +702,7 @@ nautilus_location_entry_activate (GtkEntry *entry) if (!g_path_is_absolute (entry_text) && uri_scheme == NULL && entry_text[0] != '~') { /* Fix non absolute paths */ - full_path = g_build_filename (loc_entry->details->current_directory, entry_text, NULL); + full_path = g_build_filename (priv->current_directory, entry_text, NULL); gtk_entry_set_text (entry, full_path); g_free (full_path); } @@ -651,7 +716,11 @@ nautilus_location_entry_activate (GtkEntry *entry) static void nautilus_location_entry_cancel (NautilusLocationEntry *entry) { - nautilus_location_entry_set_location (entry, entry->details->last_location); + NautilusLocationEntryPrivate *priv; + + priv = nautilus_location_entry_get_instance_private (entry); + + nautilus_location_entry_set_location (entry, priv->last_location); } static void @@ -665,6 +734,7 @@ nautilus_location_entry_class_init (NautilusLocationEntryClass *class) widget_class = GTK_WIDGET_CLASS (class); widget_class->focus_in_event = nautilus_location_entry_focus_in; widget_class->destroy = destroy; + widget_class->key_press_event = nautilus_location_entry_on_key_press; gobject_class = G_OBJECT_CLASS (class); gobject_class->finalize = finalize; @@ -694,15 +764,17 @@ nautilus_location_entry_class_init (NautilusLocationEntryClass *class) binding_set = gtk_binding_set_by_class (class); gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "cancel", 0); - - g_type_class_add_private (class, sizeof (NautilusLocationEntryDetails)); } void nautilus_location_entry_set_secondary_action (NautilusLocationEntry *entry, NautilusLocationEntryAction secondary_action) { - if (entry->details->secondary_action == secondary_action) + NautilusLocationEntryPrivate *priv; + + priv = nautilus_location_entry_get_instance_private (entry); + + if (priv->secondary_action == secondary_action) { return; } @@ -728,7 +800,7 @@ nautilus_location_entry_set_secondary_action (NautilusLocationEntry *entry default: g_assert_not_reached (); } - entry->details->secondary_action = secondary_action; + priv->secondary_action = secondary_action; } static void @@ -755,13 +827,13 @@ editable_changed_callback (GtkEntry *entry, static void nautilus_location_entry_init (NautilusLocationEntry *entry) { + NautilusLocationEntryPrivate *priv; GtkTargetList *targetlist; - entry->details = G_TYPE_INSTANCE_GET_PRIVATE (entry, NAUTILUS_TYPE_LOCATION_ENTRY, - NautilusLocationEntryDetails); + priv = nautilus_location_entry_get_instance_private (entry); - entry->details->completer = g_filename_completer_new (); - g_filename_completer_set_dirs_only (entry->details->completer, TRUE); + priv->completer = g_filename_completer_new (); + g_filename_completer_set_dirs_only (priv->completer, TRUE); gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, "folder-symbolic"); gtk_entry_set_icon_activatable (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, FALSE); @@ -772,8 +844,6 @@ nautilus_location_entry_init (NautilusLocationEntry *entry) nautilus_location_entry_set_secondary_action (entry, NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR); - nautilus_entry_set_special_tab_handling (NAUTILUS_ENTRY (entry), TRUE); - g_signal_connect (entry, "event-after", G_CALLBACK (editable_event_after_callback), entry); @@ -783,7 +853,7 @@ nautilus_location_entry_init (NautilusLocationEntry *entry) g_signal_connect (entry, "icon-release", G_CALLBACK (nautilus_location_entry_icon_release), NULL); - g_signal_connect (entry->details->completer, "got-completion-data", + g_signal_connect (priv->completer, "got-completion-data", G_CALLBACK (got_completion_data_callback), entry); /* Drag source */ @@ -818,12 +888,16 @@ void nautilus_location_entry_set_special_text (NautilusLocationEntry *entry, const char *special_text) { - entry->details->has_special_text = TRUE; + NautilusLocationEntryPrivate *priv; + + priv = nautilus_location_entry_get_instance_private (entry); + + priv->has_special_text = TRUE; - g_free (entry->details->special_text); - entry->details->special_text = g_strdup (special_text); + g_free (priv->special_text); + priv->special_text = g_strdup (special_text); - entry->details->setting_special_text = TRUE; + priv->setting_special_text = TRUE; gtk_entry_set_text (GTK_ENTRY (entry), special_text); - entry->details->setting_special_text = FALSE; + priv->setting_special_text = FALSE; } diff --git a/src/nautilus-location-entry.h b/src/nautilus-location-entry.h index 980a56103..5c1948154 100644 --- a/src/nautilus-location-entry.h +++ b/src/nautilus-location-entry.h @@ -25,29 +25,15 @@ #ifndef NAUTILUS_LOCATION_ENTRY_H #define NAUTILUS_LOCATION_ENTRY_H -#include "nautilus-entry.h" +#include <gtk/gtk.h> #define NAUTILUS_TYPE_LOCATION_ENTRY nautilus_location_entry_get_type() -#define NAUTILUS_LOCATION_ENTRY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_LOCATION_ENTRY, NautilusLocationEntry)) -#define NAUTILUS_LOCATION_ENTRY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_LOCATION_ENTRY, NautilusLocationEntryClass)) -#define NAUTILUS_IS_LOCATION_ENTRY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_LOCATION_ENTRY)) -#define NAUTILUS_IS_LOCATION_ENTRY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_LOCATION_ENTRY)) -#define NAUTILUS_LOCATION_ENTRY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_LOCATION_ENTRY, NautilusLocationEntryClass)) +G_DECLARE_DERIVABLE_TYPE (NautilusLocationEntry, nautilus_location_entry, + NAUTILUS, LOCATION_ENTRY, + GtkEntry) -typedef struct NautilusLocationEntryDetails NautilusLocationEntryDetails; - -typedef struct NautilusLocationEntry { - NautilusEntry parent; - NautilusLocationEntryDetails *details; -} NautilusLocationEntry; - -typedef struct { - NautilusEntryClass parent_class; +typedef struct _NautilusLocationEntryClass { + GtkEntryClass parent_class; /* for GtkBindingSet */ void (* cancel) (NautilusLocationEntry *entry); } NautilusLocationEntryClass; @@ -57,8 +43,6 @@ typedef enum { NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR } NautilusLocationEntryAction; -GType nautilus_location_entry_get_type (void); - GtkWidget* nautilus_location_entry_new (void); void nautilus_location_entry_set_special_text (NautilusLocationEntry *entry, const char *special_text); @@ -66,6 +50,5 @@ void nautilus_location_entry_set_secondary_action (NautilusLocationEntry * NautilusLocationEntryAction secondary_action); void nautilus_location_entry_set_location (NautilusLocationEntry *entry, GFile *location); -void nautilus_location_entry_focus (NautilusLocationEntry *entry); #endif /* NAUTILUS_LOCATION_ENTRY_H */ diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c index 46789abac..62b4596ff 100644 --- a/src/nautilus-properties-window.c +++ b/src/nautilus-properties-window.c @@ -46,7 +46,6 @@ #include <eel/eel-vfs-extensions.h> #include <libnautilus-extension/nautilus-property-page-provider.h> -#include "nautilus-entry.h" #include "nautilus-file-attributes.h" #include "nautilus-file-operations.h" #include "nautilus-file-utilities.h" @@ -108,6 +107,8 @@ struct NautilusPropertiesWindowDetails unsigned int name_row; char *pending_name; + guint select_idle_id; + GtkLabel *directory_contents_title_field; GtkLabel *directory_contents_value_field; GtkWidget *directory_contents_spinner; @@ -218,11 +219,11 @@ static void remove_pending (StartupData *data, gboolean cancel_destroy_handler); static void append_extension_pages (NautilusPropertiesWindow *window); -static gboolean name_field_focus_out (NautilusEntry *name_field, +static gboolean name_field_focus_out (GtkWidget *name_field, GdkEventFocus *event, - gpointer callback_data); -static void name_field_activate (NautilusEntry *name_field, - gpointer callback_data); + gpointer user_data); +static void name_field_activate (GtkWidget *name_field, + gpointer user_data); static GtkLabel *attach_ellipsizing_value_label (GtkGrid *grid, GtkWidget *sibling, const char *initial_text); @@ -584,7 +585,7 @@ set_name_field (NautilusPropertiesWindow *window, * 4) Creating entry (potentially replacing label) */ use_label = is_multi_file_window (window) || !nautilus_file_can_rename (get_original_file (window)); - new_widget = !window->details->name_field || (use_label ? NAUTILUS_IS_ENTRY (window->details->name_field) : GTK_IS_LABEL (window->details->name_field)); + new_widget = !window->details->name_field || (use_label ? GTK_IS_ENTRY (window->details->name_field) : GTK_IS_LABEL (window->details->name_field)); if (new_widget) { @@ -602,7 +603,7 @@ set_name_field (NautilusPropertiesWindow *window, } else { - window->details->name_field = nautilus_entry_new (); + window->details->name_field = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (window->details->name_field), name); gtk_widget_show (window->details->name_field); @@ -727,7 +728,7 @@ update_name_field (NautilusPropertiesWindow *window) } static void -name_field_restore_original_name (NautilusEntry *name_field) +name_field_restore_original_name (GtkWidget *name_field) { const char *original_name; char *displayed_name; @@ -746,7 +747,7 @@ name_field_restore_original_name (NautilusEntry *name_field) { gtk_entry_set_text (GTK_ENTRY (name_field), original_name); } - nautilus_entry_select_all (name_field); + gtk_editable_select_region (GTK_EDITABLE (name_field), 0, -1); g_free (displayed_name); } @@ -770,7 +771,7 @@ rename_callback (NautilusFile *file, GTK_WINDOW (window)); if (window->details->name_field != NULL) { - name_field_restore_original_name (NAUTILUS_ENTRY (window->details->name_field)); + name_field_restore_original_name (window->details->name_field); } } @@ -786,14 +787,14 @@ set_pending_name (NautilusPropertiesWindow *window, } static void -name_field_done_editing (NautilusEntry *name_field, +name_field_done_editing (GtkWidget *name_field, NautilusPropertiesWindow *window) { NautilusFile *file; char *new_name; const char *original_name; - g_return_if_fail (NAUTILUS_IS_ENTRY (name_field)); + g_return_if_fail (GTK_IS_ENTRY (name_field)); /* Don't apply if the dialog has more than one file */ if (is_multi_file_window (window)) @@ -816,7 +817,7 @@ name_field_done_editing (NautilusEntry *name_field, /* Special case: silently revert text if new text is empty. */ if (strlen (new_name) == 0) { - name_field_restore_original_name (NAUTILUS_ENTRY (name_field)); + name_field_restore_original_name (name_field); } else { @@ -838,31 +839,54 @@ name_field_done_editing (NautilusEntry *name_field, } static gboolean -name_field_focus_out (NautilusEntry *name_field, +name_field_focus_out (GtkWidget *name_field, GdkEventFocus *event, - gpointer callback_data) + gpointer user_data) { - g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (callback_data)); + g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (user_data)); - if (gtk_widget_get_sensitive (GTK_WIDGET (name_field))) + if (gtk_widget_get_sensitive (name_field)) { - name_field_done_editing (name_field, NAUTILUS_PROPERTIES_WINDOW (callback_data)); + name_field_done_editing (name_field, NAUTILUS_PROPERTIES_WINDOW (user_data)); } return FALSE; } +static gboolean +select_all_at_idle (gpointer user_data) +{ + NautilusPropertiesWindow *window; + + window = NAUTILUS_PROPERTIES_WINDOW (user_data); + + gtk_editable_select_region (GTK_EDITABLE (window->details->name_field), + 0, -1); + + window->details->select_idle_id = 0; + + return FALSE; +} + static void -name_field_activate (NautilusEntry *name_field, - gpointer callback_data) +name_field_activate (GtkWidget *name_field, + gpointer user_data) { - g_assert (NAUTILUS_IS_ENTRY (name_field)); - g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (callback_data)); + NautilusPropertiesWindow *window; + + g_assert (GTK_IS_ENTRY (name_field)); + g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (user_data)); + + window = NAUTILUS_PROPERTIES_WINDOW (user_data); /* Accept changes. */ - name_field_done_editing (name_field, NAUTILUS_PROPERTIES_WINDOW (callback_data)); + name_field_done_editing (name_field, window); - nautilus_entry_select_all_at_idle (name_field); + if (window->details->select_idle_id == 0) + { + window->details->select_idle_id = g_idle_add (select_all_at_idle, + window); + } } static void @@ -3169,9 +3193,8 @@ create_basic_page (NautilusPropertiesWindow *window) update_name_field (window); /* Start with name field selected, if it's an entry. */ - if (NAUTILUS_IS_ENTRY (window->details->name_field)) + if (GTK_IS_ENTRY (window->details->name_field)) { - nautilus_entry_select_all (NAUTILUS_ENTRY (window->details->name_field)); gtk_widget_grab_focus (GTK_WIDGET (window->details->name_field)); } @@ -5481,6 +5504,11 @@ real_finalize (GObject *object) g_free (window->details->pending_name); + if (window->details->select_idle_id != 0) + { + g_source_remove (window->details->select_idle_id); + } + G_OBJECT_CLASS (nautilus_properties_window_parent_class)->finalize (object); } diff --git a/src/nautilus-window.c b/src/nautilus-window.c index b6bfc30e5..be126f476 100644 --- a/src/nautilus-window.c +++ b/src/nautilus-window.c @@ -1597,7 +1597,7 @@ nautilus_window_ensure_location_entry (NautilusWindow *window) nautilus_toolbar_set_show_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar), TRUE); location_entry = nautilus_toolbar_get_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar)); - nautilus_location_entry_focus (NAUTILUS_LOCATION_ENTRY (location_entry)); + gtk_widget_grab_focus (location_entry); return location_entry; } |