summaryrefslogtreecommitdiff
path: root/src/nautilus-entry.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nautilus-entry.c')
-rw-r--r--src/nautilus-entry.c395
1 files changed, 208 insertions, 187 deletions
diff --git a/src/nautilus-entry.c b/src/nautilus-entry.c
index 1b790a2ab..e8110ab87 100644
--- a/src/nautilus-entry.c
+++ b/src/nautilus-entry.c
@@ -1,4 +1,3 @@
-
/* 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.
@@ -30,160 +29,175 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
-struct NautilusEntryDetails {
- gboolean special_tab_handling;
+struct NautilusEntryDetails
+{
+ gboolean special_tab_handling;
- guint select_idle_id;
+ guint select_idle_id;
};
-enum {
- SELECTION_CHANGED,
- LAST_SIGNAL
+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));
+ 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);
+ entry->details = g_new0 (NautilusEntryDetails, 1);
}
GtkWidget *
nautilus_entry_new (void)
{
- return gtk_widget_new (NAUTILUS_TYPE_ENTRY, NULL);
+ return gtk_widget_new (NAUTILUS_TYPE_ENTRY, NULL);
}
static void
nautilus_entry_finalize (GObject *object)
{
- NautilusEntry *entry;
+ NautilusEntry *entry;
- entry = NAUTILUS_ENTRY (object);
+ entry = NAUTILUS_ENTRY (object);
- if (entry->details->select_idle_id != 0) {
- g_source_remove (entry->details->select_idle_id);
- }
-
- g_free (entry->details);
+ if (entry->details->select_idle_id != 0)
+ {
+ g_source_remove (entry->details->select_idle_id);
+ }
- G_OBJECT_CLASS (nautilus_entry_parent_class)->finalize (object);
+ g_free (entry->details);
+
+ G_OBJECT_CLASS (nautilus_entry_parent_class)->finalize (object);
}
static gboolean
-nautilus_entry_key_press (GtkWidget *widget, GdkEventKey *event)
+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;
-
+ 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)
+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;
+ 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));
+ 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);
+ 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;
+ NautilusEntry *entry;
- entry = NAUTILUS_ENTRY (callback_data);
+ entry = NAUTILUS_ENTRY (callback_data);
- nautilus_entry_select_all (entry);
+ nautilus_entry_select_all (entry);
- entry->details->select_idle_id = 0;
-
- return FALSE;
+ entry->details->select_idle_id = 0;
+
+ return FALSE;
}
/**
@@ -193,22 +207,23 @@ select_all_at_idle (gpointer callback_data)
* 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));
+ 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 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);
- }
+ if (entry->details->select_idle_id == 0)
+ {
+ entry->details->select_idle_id = g_idle_add (select_all_at_idle, entry);
+ }
}
/**
@@ -218,75 +233,82 @@ nautilus_entry_select_all_at_idle (NautilusEntry *entry)
* 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)
+nautilus_entry_set_text (NautilusEntry *entry,
+ const gchar *text)
{
- g_return_if_fail (NAUTILUS_IS_ENTRY (entry));
+ g_return_if_fail (NAUTILUS_IS_ENTRY (entry));
- gtk_entry_set_text (GTK_ENTRY (entry), text);
- g_signal_emit (entry, signals[SELECTION_CHANGED], 0);
+ 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)
+ int start_pos,
+ int end_pos)
{
- parent_editable_interface->set_selection_bounds (editable, start_pos, end_pos);
+ parent_editable_interface->set_selection_bounds (editable, start_pos, end_pos);
- g_signal_emit (editable, signals[SELECTION_CHANGED], 0);
+ g_signal_emit (editable, signals[SELECTION_CHANGED], 0);
}
static gboolean
-nautilus_entry_button_press (GtkWidget *widget,
- GdkEventButton *event)
+nautilus_entry_button_press (GtkWidget *widget,
+ GdkEventButton *event)
{
- gboolean result;
+ gboolean result;
- result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->button_press_event (widget, event);
+ result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->button_press_event (widget, event);
- if (result) {
- g_signal_emit (widget, signals[SELECTION_CHANGED], 0);
- }
+ if (result)
+ {
+ g_signal_emit (widget, signals[SELECTION_CHANGED], 0);
+ }
- return result;
+ return result;
}
static gboolean
-nautilus_entry_button_release (GtkWidget *widget,
- GdkEventButton *event)
+nautilus_entry_button_release (GtkWidget *widget,
+ GdkEventButton *event)
{
- gboolean result;
+ gboolean result;
- result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->button_release_event (widget, event);
+ result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->button_release_event (widget, event);
- if (result) {
- g_signal_emit (widget, signals[SELECTION_CHANGED], 0);
- }
+ if (result)
+ {
+ g_signal_emit (widget, signals[SELECTION_CHANGED], 0);
+ }
- return result;
+ return result;
}
static void
-nautilus_entry_insert_text (GtkEditable *editable, const gchar *text,
- int length, int *position)
+nautilus_entry_insert_text (GtkEditable *editable,
+ const gchar *text,
+ int length,
+ int *position)
{
- parent_editable_interface->insert_text (editable, text, length, position);
+ parent_editable_interface->insert_text (editable, text, length, position);
- g_signal_emit (editable, signals[SELECTION_CHANGED], 0);
+ g_signal_emit (editable, signals[SELECTION_CHANGED], 0);
}
-
-static void
-nautilus_entry_delete_text (GtkEditable *editable, int start_pos, int end_pos)
+
+static void
+nautilus_entry_delete_text (GtkEditable *editable,
+ int start_pos,
+ int end_pos)
{
- parent_editable_interface->delete_text (editable, start_pos, end_pos);
+ parent_editable_interface->delete_text (editable, start_pos, end_pos);
- g_signal_emit (editable, signals[SELECTION_CHANGED], 0);
+ g_signal_emit (editable, signals[SELECTION_CHANGED], 0);
}
/* Overridden to work around GTK bug. The selection_clear_event is queued
@@ -298,68 +320,67 @@ nautilus_entry_delete_text (GtkEditable *editable, int start_pos, int end_pos)
* gtk+/gtkselection.c, gtk_selection_clear.
*/
static gboolean
-nautilus_entry_selection_clear (GtkWidget *widget,
- GdkEventSelection *event)
+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);
+ 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);
+ 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;
+ 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);
+ /* 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);
+ 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)
+ gboolean special_tab_handling)
{
- g_return_if_fail (NAUTILUS_IS_ENTRY (entry));
+ g_return_if_fail (NAUTILUS_IS_ENTRY (entry));
- entry->details->special_tab_handling = special_tab_handling;
+ entry->details->special_tab_handling = special_tab_handling;
}
-
-