diff options
author | John Sullivan <sullivan@src.gnome.org> | 2000-04-17 18:25:56 +0000 |
---|---|---|
committer | John Sullivan <sullivan@src.gnome.org> | 2000-04-17 18:25:56 +0000 |
commit | c4002e6e1504ecdc09a8bd8a327f1489363aba4f (patch) | |
tree | f5f7e9bf8be2a996659cdf3c786cdf014f045b42 /libnautilus-private/nautilus-entry.c | |
parent | eab6fb37e1af5069b0e1c96bb70a7f84ffa42c7c (diff) | |
download | nautilus-c4002e6e1504ecdc09a8bd8a327f1489363aba4f.tar.gz |
Fixed bugs, mostly related to editable text fields.
* README: Made the contents of this file slightly helpful.
* data/mime/nautilus.keys: Added an obscure MIME type that
someone reported running into.
* libnautilus-extensions/nautilus-entry.h,
* libnautilus-extensions/nautilus-entry.c: New files. Define a
subclass of GtkEntry (one-line text editing field) that fixes
bugs and adds convenience functions.
(nautilus_entry_key_press): Override key_press handler to treat
the keypad Enter key the same as the other Enter key (in GtkEntry
it inserts a "/r" into the text).
(nautilus_entry_select_all): Select all text, and move the text
cursor position to the end.
(nautilus_entry_select_all_at_idle): Same, but do it at the next
idle opportunity. Useful since nautilus_entry_select_all won't
work right if called in a key_press signal handler.
* libnautilus-extensions/Makefile.am: Build these two new files.
* src/file-manager/fm-properties-window.c:
(name_field_activate): New function, updates file name and
selects all text.
(create_properties_window): Make name_field be a NautilusEntry.
This fixes half of bug 433 (Enter keys don't work properly in
properties window). Also attach to "activate" signal and update
name change then. This fixes other half of bug 433. Also start
with name field selected & focused. This fixes bug 432 (properties
window should appear with name text selected).
(name_field_update_to_match_file): Only update the displayed text
if the new name coming in is different. This was needed to make
select-all-on-activate work.
(name_field_done_editing): Don't accept empty string as name;
silently revert back to original name.
* src/nautilus-bookmarks-window.c:
(create_bookmarks_window): Change name & uri text fields to
NautilusEntry; this causes keypad Enter key to behave like other
Enter key. Also connect to focus_in and activate signals.
(update_bookmark_from_text): New function, extracted from
on_text_field_focus_out_event.
(on_text_field_focus_out_event): Deselect all text after updating
bookmark.
(on_text_field_focus_in_event): New function, select all text.
(name_or_uri_field_activate): New function, update bookmark and
select all text.
* src/nautilus-location-bar.c:
(nautilus_location_bar_initialize): Use NautilusEntry instead of
GtkEntry. This makes keypad Enter act like other Enter in uri-entry
field.
* src/ntl-window-msgs.c:
(nautilus_window_end_location_change_callback): Make "Nautilus can't
handle this type of file" message mention (human-readable version of)
file type.
Diffstat (limited to 'libnautilus-private/nautilus-entry.c')
-rw-r--r-- | libnautilus-private/nautilus-entry.c | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/libnautilus-private/nautilus-entry.c b/libnautilus-private/nautilus-entry.c new file mode 100644 index 000000000..7e56edd4c --- /dev/null +++ b/libnautilus-private/nautilus-entry.c @@ -0,0 +1,131 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* 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, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <config.h> +#include "nautilus-entry.h" + +#include "nautilus-gtk-macros.h" + +#include <gdk/gdkkeysyms.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkwidget.h> + +static void nautilus_entry_initialize (NautilusEntry *entry); +static void nautilus_entry_initialize_class (NautilusEntryClass *class); +static gint nautilus_entry_key_press (GtkWidget *widget, + GdkEventKey *event); + + +NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusEntry, nautilus_entry, GTK_TYPE_ENTRY) + +static void +nautilus_entry_initialize_class (NautilusEntryClass *class) +{ + GtkWidgetClass *widget_class; + + widget_class = GTK_WIDGET_CLASS (class); + + widget_class->key_press_event = nautilus_entry_key_press; +} + +static void +nautilus_entry_initialize (NautilusEntry *entry) +{ + /* Nothing to do here yet. */ +} + +GtkWidget* +nautilus_entry_new (void) +{ + return GTK_WIDGET (gtk_type_new (NAUTILUS_TYPE_ENTRY)); +} + +static gint +nautilus_entry_key_press (GtkWidget *widget, GdkEventKey *event) +{ + g_assert (NAUTILUS_IS_ENTRY (widget)); + + if (!GTK_EDITABLE (widget)->editable) { + return FALSE; + } + + /* Fix bug in GtkEntry where keypad Enter key inserts a + * character rather than activating like the other Enter key. + */ + switch (event->keyval) { + case GDK_KP_Enter: + gtk_widget_activate (widget); + return TRUE; + } + + return NAUTILUS_CALL_PARENT_CLASS (GTK_WIDGET_CLASS, key_press_event, (widget, event)); +} + +/** + * 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 (NautilusEntry *entry) +{ + nautilus_entry_select_all (entry); + 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). + */ + gtk_idle_add ((GtkFunction)select_all_at_idle, entry); +} + |