summaryrefslogtreecommitdiff
path: root/libnautilus-private/nautilus-entry.c
diff options
context:
space:
mode:
authorDarin Adler <darin@src.gnome.org>2001-03-16 22:26:53 +0000
committerDarin Adler <darin@src.gnome.org>2001-03-16 22:26:53 +0000
commitdcb478cf7e1500504a8273ad6ef0422f7fbc3e29 (patch)
treec1400dd09095b724e50805eec0f6c71122f20ca1 /libnautilus-private/nautilus-entry.c
parenta85afd0f2524ca254099a41cf8585c435c19f0b8 (diff)
downloadnautilus-dcb478cf7e1500504a8273ad6ef0422f7fbc3e29.tar.gz
reviewed by: John Sullivan <sullivan@eazel.com>
Fix bug 6495 (Emacs-style keybindings not working in location bar and other NautilusEntry fields) by adding an expert preference to control whether the Emacs shortcuts or the ones in the menu bar take precedence. I started with Maciej's patch and did many refinements. Fix bug 1788 ("Select All" needs to be implemented for text): I had to add Select All so it won't do the icon view's Select All when you do a select all with the location bar focused. Fix bug 5612 (clicking to deselect causes incorrect menu sensitivity) by adding another signal handler for button clicks. Fix bug 7581 (When trying to restart Nautilus after crash from bug 7579 I get a Segmentation Fault). I was just lucky enough to run into the problem on my machine. * libnautilus-extensions/nautilus-global-preferences.h: * libnautilus-extensions/nautilus-global-preferences.c: (global_preferences_install_descriptions), (global_preferences_install_defaults), (global_preferences_install_visibility), (global_preferences_create_dialog): Added the new Emacs-shortcut preference with the wording requested in the bug report. * libnautilus-extensions/nautilus-entry.h: * libnautilus-extensions/nautilus-entry.c: (emacs_shortcuts_preference_changed_callback): Track the preference. (nautilus_entry_initialize): Set up the callback to track the preference. (nautilus_entry_destroy): Tear down the callback to track the preference. (nautilus_entry_key_press): Allow the emacs shortcuts built into GtkEntry to work if the preference is set that way. Also, only emit the selection_changed signal if the key is actually handled. (nautilus_entry_motion_notify): Simplify the logic, since it's OK to send the selection_changed signal a little too often. (select_all_at_idle): Handle the case where the object is destroyed. (nautilus_entry_select_all_at_idle): Ref the object to handle the case where the object is destroyed before the idle happens. (nautilus_entry_button_press): Send a selection_changed message, since pressing the button can cause a selection change. (nautilus_entry_button_release): Send a selection_changed message, since pressing the button can cause a selection change. (nautilus_entry_initialize_class): Add new default handlers. Also, move to bottom of file so we don't need so many forward declarations. * libnautilus/nautilus-clipboard-ui.xml: Add a Select All Text command. * libnautilus/nautilus-clipboard.c: (select_all): New function to select all the text in a GtkEditable. Sadly it needs a special case for GtkText. (select_all_idle_callback): Callback used to select the text from idle. (select_all_callback): Callback that sets up the idle. Called from the bonobo verb. (initialize_clipboard_component_with_callback_data): Add the callback for Select All. * librsvg/rsvg.c: (rsvg_state_init): Initialize more fields, including font_size. (rsvg_text_handler_characters): Don't try to draw if the font size is 0 or negative. * librsvg/art_render_mask.c: (art_render_mask_render): Handle cases where x1 < x0. The old code would seg. fault. This was the reason we got a crash in bug 7581. * configure.in: Upped the required version of gnome-vfs.
Diffstat (limited to 'libnautilus-private/nautilus-entry.c')
-rw-r--r--libnautilus-private/nautilus-entry.c253
1 files changed, 147 insertions, 106 deletions
diff --git a/libnautilus-private/nautilus-entry.c b/libnautilus-private/nautilus-entry.c
index 10af50e5d..4d4a684ff 100644
--- a/libnautilus-private/nautilus-entry.c
+++ b/libnautilus-private/nautilus-entry.c
@@ -28,20 +28,18 @@
#include "nautilus-entry.h"
#include "nautilus-gtk-macros.h"
-
#include <gdk/gdkkeysyms.h>
-#include <gtk/gtksignal.h>
#include <gtk/gtkmain.h>
-#include <gtk/gtkwidget.h>
-
-#include <libgnome/gnome-defs.h>
+#include <gtk/gtksignal.h>
#include <libgnome/gnome-i18n.h>
-
#include <libnautilus-extensions/nautilus-gdk-extensions.h>
+#include <libnautilus-extensions/nautilus-global-preferences.h>
#include <libnautilus-extensions/nautilus-undo-signal-handlers.h>
-
#include <orb/orbit.h>
+struct NautilusEntryDetails {
+ gboolean use_emacs_shortcuts;
+};
enum {
USER_CHANGED,
@@ -50,68 +48,22 @@ enum {
};
static guint signals[LAST_SIGNAL];
-static void nautilus_entry_initialize (NautilusEntry *entry);
+static void nautilus_entry_initialize (NautilusEntry *entry);
static void nautilus_entry_initialize_class (NautilusEntryClass *class);
-static void nautilus_entry_destroy (GtkObject *object);
-static gint nautilus_entry_key_press (GtkWidget *widget,
- GdkEventKey *event);
-static gint nautilus_entry_motion_notify (GtkWidget *widget,
- GdkEventMotion *event);
-static void nautilus_entry_insert_text (GtkEditable *editable,
- const gchar *text,
- gint length,
- gint *position);
-static gboolean nautilus_entry_selection_clear (GtkWidget *widget,
- GdkEventSelection *event);
-static void nautilus_entry_delete_text (GtkEditable *editable,
- gint start_pos,
- gint end_pos);
-static void nautilus_entry_set_selection (GtkEditable *editable,
- gint start_pos,
- gint end_pos);
-
-NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusEntry, nautilus_entry, GTK_TYPE_ENTRY)
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusEntry,
+ nautilus_entry,
+ GTK_TYPE_ENTRY)
static void
-nautilus_entry_initialize_class (NautilusEntryClass *class)
+emacs_shortcuts_preference_changed_callback (gpointer callback_data)
{
- GtkWidgetClass *widget_class;
- GtkObjectClass *object_class;
- GtkEditableClass *editable_class;
-
- widget_class = GTK_WIDGET_CLASS (class);
- object_class = GTK_OBJECT_CLASS (class);
- editable_class = GTK_EDITABLE_CLASS (class);
-
- 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;
-
- object_class->destroy = nautilus_entry_destroy;
-
- editable_class->insert_text = nautilus_entry_insert_text;
- editable_class->delete_text = nautilus_entry_delete_text;
- editable_class->set_selection = nautilus_entry_set_selection;
+ NautilusEntry *entry;
+ entry = NAUTILUS_ENTRY (callback_data);
- /* Set up signals */
- signals[USER_CHANGED] = gtk_signal_new
- ("user_changed",
- GTK_RUN_LAST,
- object_class->type,
- GTK_SIGNAL_OFFSET (NautilusEntryClass,
- user_changed),
- gtk_marshal_NONE__NONE,
- GTK_TYPE_NONE, 0);
- signals[SELECTION_CHANGED] = gtk_signal_new
- ("selection_changed",
- GTK_RUN_LAST,
- object_class->type,
- GTK_SIGNAL_OFFSET (NautilusEntryClass,
- selection_changed),
- gtk_marshal_NONE__NONE,
- GTK_TYPE_NONE, 0);
- gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
+ entry->details->use_emacs_shortcuts =
+ nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_USE_EMACS_SHORTCUTS);
}
static void
@@ -120,15 +72,19 @@ nautilus_entry_initialize (NautilusEntry *entry)
GtkWidget *widget;
widget = GTK_WIDGET (entry);
+ entry->details = g_new0 (NautilusEntryDetails, 1);
entry->user_edit = TRUE;
- entry->special_tab_handling = FALSE;
- entry->cursor_obscured = FALSE;
/* Allow pointer motion events so we can expose an obscured cursor if necessary */
gtk_widget_set_events (widget, gtk_widget_get_events (widget) | GDK_POINTER_MOTION_MASK);
nautilus_undo_set_up_nautilus_entry_for_undo (entry);
+
+ nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_USE_EMACS_SHORTCUTS,
+ emacs_shortcuts_preference_changed_callback,
+ entry);
+ emacs_shortcuts_preference_changed_callback (entry);
}
GtkWidget *
@@ -148,7 +104,6 @@ nautilus_entry_new_with_max_length (guint16 max)
return widget;
}
-
static void
nautilus_entry_destroy (GtkObject *object)
{
@@ -156,6 +111,12 @@ nautilus_entry_destroy (GtkObject *object)
entry = NAUTILUS_ENTRY (object);
+ nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_USE_EMACS_SHORTCUTS,
+ emacs_shortcuts_preference_changed_callback,
+ entry);
+
+ g_free (entry->details);
+
NAUTILUS_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}
@@ -170,14 +131,13 @@ obscure_cursor (NautilusEntry *entry)
nautilus_gdk_window_set_invisible_cursor (GTK_ENTRY (entry)->text_area);
}
-
-static gint
+static gboolean
nautilus_entry_key_press (GtkWidget *widget, GdkEventKey *event)
{
NautilusEntry *entry;
GtkEditable *editable;
int position;
- gint return_code;
+ gboolean result;
entry = NAUTILUS_ENTRY (widget);
editable = GTK_EDITABLE (widget);
@@ -194,8 +154,7 @@ nautilus_entry_key_press (GtkWidget *widget, GdkEventKey *event)
* should position the insertion point at the end of
* the selection.
*/
- if (entry->special_tab_handling
- && editable->has_selection) {
+ if (entry->special_tab_handling && editable->has_selection) {
position = strlen (gtk_entry_get_text (GTK_ENTRY (editable)));
gtk_entry_select_region (GTK_ENTRY (editable), position, position);
return TRUE;
@@ -203,9 +162,9 @@ nautilus_entry_key_press (GtkWidget *widget, GdkEventKey *event)
break;
case GDK_KP_Enter:
- /* Fix bug in GtkEntry where keypad Enter key inserts
- * a character rather than activating like the other
- * Enter key.
+ /* Work around bug in GtkEntry where keypad Enter key
+ * inserts a character rather than activating like the
+ * other Enter key.
*/
gtk_widget_activate (widget);
return TRUE;
@@ -214,27 +173,33 @@ nautilus_entry_key_press (GtkWidget *widget, GdkEventKey *event)
break;
}
- /* Filter out default GTKEntry alt and control key bindings. They have numerous conflicts
- * with Nautilus menu keyboard accelerators.
- */
- if (event->state & GDK_CONTROL_MASK || event->state & GDK_MOD1_MASK) {
- return FALSE;
+ if (!entry->details->use_emacs_shortcuts) {
+ /* Filter out the emacs-style keyboard shortcuts in
+ * GtkEntry for alt and control keys. They have
+ * numerous conflicts with menu keyboard shortcuts.
+ */
+ if (event->state & GDK_CONTROL_MASK || event->state & GDK_MOD1_MASK) {
+ return FALSE;
+ }
}
obscure_cursor (entry);
- return_code = NAUTILUS_CALL_PARENT_WITH_RETURN_VALUE
+ result = NAUTILUS_CALL_PARENT_WITH_RETURN_VALUE
(GTK_WIDGET_CLASS, key_press_event, (widget, event));
- gtk_signal_emit (GTK_OBJECT (widget), signals[SELECTION_CHANGED]);
- return return_code;
+ if (result) {
+ gtk_signal_emit (GTK_OBJECT (widget), signals[SELECTION_CHANGED]);
+ }
+
+ return result;
}
-static gint
+static gboolean
nautilus_entry_motion_notify (GtkWidget *widget, GdkEventMotion *event)
{
- gint return_code;
+ int result;
guint old_start_pos, old_end_pos;
GdkCursor *cursor;
NautilusEntry *entry;
@@ -248,21 +213,17 @@ nautilus_entry_motion_notify (GtkWidget *widget, GdkEventMotion *event)
entry->cursor_obscured = FALSE;
}
- if (GTK_ENTRY (widget)->button == 0) {
- return FALSE;
- }
-
old_start_pos = GTK_EDITABLE (widget)->selection_start_pos;
old_end_pos = GTK_EDITABLE (widget)->selection_end_pos;
- return_code = NAUTILUS_CALL_PARENT_WITH_RETURN_VALUE
+ result = NAUTILUS_CALL_PARENT_WITH_RETURN_VALUE
(GTK_WIDGET_CLASS, motion_notify_event, (widget, event));
- if (GTK_EDITABLE (widget)->selection_start_pos != old_start_pos ||
- GTK_EDITABLE (widget)->selection_end_pos != old_end_pos) {
+
+ if (result) {
gtk_signal_emit (GTK_OBJECT (widget), signals[SELECTION_CHANGED]);
}
-
- return return_code;
+
+ return result;
}
/**
@@ -282,9 +243,15 @@ nautilus_entry_select_all (NautilusEntry *entry)
}
static gboolean
-select_all_at_idle (NautilusEntry *entry)
+select_all_at_idle (gpointer callback_data)
{
- nautilus_entry_select_all (entry);
+ NautilusEntry *entry;
+
+ entry = NAUTILUS_ENTRY (callback_data);
+ if (!GTK_OBJECT_DESTROYED (entry)) {
+ nautilus_entry_select_all (entry);
+ }
+ gtk_object_unref (GTK_OBJECT (entry));
return FALSE;
}
@@ -307,7 +274,8 @@ nautilus_entry_select_all_at_idle (NautilusEntry *entry)
* 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);
+ gtk_object_ref (GTK_OBJECT (entry));
+ gtk_idle_add (select_all_at_idle, entry);
}
/**
@@ -334,20 +302,52 @@ nautilus_entry_set_text (NautilusEntry *entry, const gchar *text)
gtk_signal_emit (GTK_OBJECT (entry), signals[SELECTION_CHANGED]);
}
-void
+static void
nautilus_entry_set_selection (GtkEditable *editable,
- gint start_pos,
- gint end_pos)
+ int start_pos,
+ int end_pos)
{
-
NAUTILUS_CALL_PARENT (GTK_EDITABLE_CLASS, set_selection,
(editable, start_pos, end_pos));
+
gtk_signal_emit (GTK_OBJECT (editable), signals[SELECTION_CHANGED]);
}
+static gboolean
+nautilus_entry_button_press (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ gboolean result;
+
+ result = NAUTILUS_CALL_PARENT_WITH_RETURN_VALUE
+ (GTK_WIDGET_CLASS, button_press_event, (widget, event));
+
+ if (result) {
+ gtk_signal_emit (GTK_OBJECT (widget), signals[SELECTION_CHANGED]);
+ }
+
+ return result;
+}
+
+static gboolean
+nautilus_entry_button_release (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ gboolean result;
+
+ result = NAUTILUS_CALL_PARENT_WITH_RETURN_VALUE
+ (GTK_WIDGET_CLASS, button_release_event, (widget, event));
+
+ if (result) {
+ gtk_signal_emit (GTK_OBJECT (widget), signals[SELECTION_CHANGED]);
+ }
+
+ return result;
+}
+
static void
nautilus_entry_insert_text (GtkEditable *editable, const gchar *text,
- gint length, gint *position)
+ int length, int *position)
{
NautilusEntry *entry;
@@ -360,18 +360,16 @@ nautilus_entry_insert_text (GtkEditable *editable, const gchar *text,
NAUTILUS_CALL_PARENT (GTK_EDITABLE_CLASS, insert_text,
(editable, text, length, position));
- gtk_signal_emit (GTK_OBJECT (editable), signals[SELECTION_CHANGED]);
+ gtk_signal_emit (GTK_OBJECT (editable), signals[SELECTION_CHANGED]);
}
-
static void
-nautilus_entry_delete_text (GtkEditable *editable, gint start_pos, gint end_pos)
+nautilus_entry_delete_text (GtkEditable *editable, int start_pos, int end_pos)
{
NautilusEntry *entry;
-
- entry = NAUTILUS_ENTRY(editable);
+ entry = NAUTILUS_ENTRY (editable);
/* Fire off user changed signals */
if (entry->user_edit) {
@@ -405,3 +403,46 @@ nautilus_entry_selection_clear (GtkWidget *widget,
return NAUTILUS_CALL_PARENT_WITH_RETURN_VALUE
(GTK_WIDGET_CLASS, selection_clear_event, (widget, event));
}
+
+static void
+nautilus_entry_initialize_class (NautilusEntryClass *class)
+{
+ GtkWidgetClass *widget_class;
+ GtkObjectClass *object_class;
+ GtkEditableClass *editable_class;
+
+ widget_class = GTK_WIDGET_CLASS (class);
+ object_class = GTK_OBJECT_CLASS (class);
+ editable_class = GTK_EDITABLE_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;
+
+ object_class->destroy = nautilus_entry_destroy;
+
+ editable_class->insert_text = nautilus_entry_insert_text;
+ editable_class->delete_text = nautilus_entry_delete_text;
+ editable_class->set_selection = nautilus_entry_set_selection;
+
+ /* Set up signals */
+ signals[USER_CHANGED] = gtk_signal_new
+ ("user_changed",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (NautilusEntryClass,
+ user_changed),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE, 0);
+ signals[SELECTION_CHANGED] = gtk_signal_new
+ ("selection_changed",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (NautilusEntryClass,
+ selection_changed),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE, 0);
+ gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
+}