Commit 04ab2a53 authored by Arik Devens's avatar Arik Devens
Browse files

Updated tilde expand code to not suck, and to work right for the location bar...

Updated tilde expand code to not suck, and to work right for the location bar and the pref dialog. part of a fix for bug 6391.
parent c4e21249
2001-02-22 Arik Devens <arik@eazel.com>
reviewed by: Darin Adler <darin@eazel.com>
Fixed bug 6391, nautilus crashes on certain strings set as home
dir preference. This is actually only half the fix, for the "\"
char i am waiting on pavel's input.
* libnautilus-extensions/nautilus-entry.c:
(nautilus_entry_initialize), (nautilus_entry_key_press): Removed
tilde expand code.
* libnautilus-extensions/nautilus-entry.h: Removed tilde_expand
gboolean.
* libnautilus-extensions/nautilus-preferences-item.c:
(preferences_item_create_editable_string): Cleanup to use
NAUTILUS_PREFERENCES_HOME_URI instead of "preferences/home_uri" as
per ramiro's advice.
* libnautilus-extensions/nautilus-text-caption.c:
(nautilus_text_caption_initialize), (entry_key_press_callback),
(nautilus_text_caption_set_expand_tilde): Added tilde_expand code
to the text-caption for use in the preferences dialog. Much
smarter tilde code, should handle any corner case (at least any i
could think of).
* src/nautilus-location-bar.c: (try_to_expand_path),
(editable_key_press_callback), (nautilus_location_bar_initialize):
Added handling of the ~/ case directly to the location bar instead
of going through the NautilusEntry.
2001-02-22 John Harper <jsh@eazel.com>
reviewed by: Darin Adler <darin@eazel.com>
......
......@@ -124,7 +124,6 @@ nautilus_entry_initialize (NautilusEntry *entry)
entry->user_edit = TRUE;
entry->special_tab_handling = FALSE;
entry->cursor_obscured = FALSE;
entry->expand_tilde = 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);
......@@ -210,15 +209,6 @@ nautilus_entry_key_press (GtkWidget *widget, GdkEventKey *event)
*/
gtk_widget_activate (widget);
return TRUE;
case GDK_slash:
if (entry->expand_tilde) {
/* FIXME: This handles only ~/, not the fancier variants. */
if (strcmp (gtk_entry_get_text (GTK_ENTRY (entry)), "~") == 0) {
gtk_entry_set_text (GTK_ENTRY (entry), g_get_home_dir ());
}
}
break;
default:
break;
......
......@@ -52,7 +52,6 @@ struct NautilusEntry {
gboolean user_edit;
gboolean special_tab_handling;
gboolean cursor_obscured;
gboolean expand_tilde;
};
struct NautilusEntryClass {
......
......@@ -39,6 +39,8 @@
#include "nautilus-string-picker.h"
#include "nautilus-text-caption.h"
#include "nautilus-global-preferences.h"
/* Arguments */
enum
{
......@@ -433,7 +435,7 @@ preferences_item_create_editable_string (NautilusPreferencesItem *item,
/* FIXME This is a special case for the home uri preference,
in the future this should be generalized. */
if (g_strcasecmp (preference_name, "preferences/home_uri") == 0)
if (g_strcasecmp (preference_name, NAUTILUS_PREFERENCES_HOME_URI) == 0)
{
nautilus_text_caption_set_expand_tilde (NAUTILUS_TEXT_CAPTION (item->details->child), TRUE);
}
......
......@@ -32,8 +32,13 @@
#include <gtk/gtklabel.h>
#include <gtk/gtkentry.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtksignal.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <string.h>
static const gint TEXT_CAPTION_INVALID = -1;
static const gint TEXT_CAPTION_SPACING = 10;
......@@ -47,6 +52,8 @@ typedef enum
struct _NautilusTextCaptionDetail
{
GtkWidget *text;
gboolean expand_tilde;
};
/* NautilusTextCaptionClass methods */
......@@ -59,6 +66,9 @@ static void nautilus_text_caption_destroy (GtkObject
/* Editable (entry) callbacks */
static void entry_changed_callback (GtkWidget *entry,
gpointer user_data);
static void entry_key_press_callback (GtkWidget *widget,
GdkEventKey *event,
gpointer user_data);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusTextCaption, nautilus_text_caption, NAUTILUS_TYPE_CAPTION)
......@@ -100,7 +110,7 @@ nautilus_text_caption_initialize (NautilusTextCaption *text_caption)
gtk_box_set_homogeneous (GTK_BOX (text_caption), FALSE);
gtk_box_set_spacing (GTK_BOX (text_caption), TEXT_CAPTION_SPACING);
text_caption->detail->text = nautilus_entry_new ();
text_caption->detail->text = gtk_entry_new ();
gtk_entry_set_editable (GTK_ENTRY (text_caption->detail->text), TRUE);
......@@ -111,7 +121,11 @@ nautilus_text_caption_initialize (NautilusTextCaption *text_caption)
"changed",
GTK_SIGNAL_FUNC (entry_changed_callback),
(gpointer) text_caption);
gtk_signal_connect_after (GTK_OBJECT (text_caption->detail->text),
"key_press_event",
GTK_SIGNAL_FUNC (entry_key_press_callback),
(gpointer) text_caption);
gtk_widget_show (text_caption->detail->text);
}
......@@ -150,6 +164,24 @@ entry_changed_callback (GtkWidget *entry, gpointer user_data)
gtk_signal_emit (GTK_OBJECT (text_caption), text_caption_signals[CHANGED]);
}
static void
entry_key_press_callback (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
{
NautilusTextCaption *text_caption;
char *expanded_text;
text_caption = NAUTILUS_TEXT_CAPTION (user_data);
if (event->keyval == GDK_asciitilde) {
if (text_caption->detail->expand_tilde) {
expanded_text = gnome_vfs_expand_initial_tilde (gtk_entry_get_text (GTK_ENTRY (widget)));
gtk_entry_set_text (GTK_ENTRY (widget), expanded_text);
g_free (expanded_text);
}
}
}
/*
* NautilusTextCaption public methods
*/
......@@ -207,5 +239,5 @@ nautilus_text_caption_set_expand_tilde (NautilusTextCaption *text_caption,
{
g_return_if_fail (NAUTILUS_IS_TEXT_CAPTION (text_caption));
NAUTILUS_ENTRY (text_caption->detail->text)->expand_tilde = TRUE;
text_caption->detail->expand_tilde = expand_tilde;
}
......@@ -124,7 +124,6 @@ nautilus_entry_initialize (NautilusEntry *entry)
entry->user_edit = TRUE;
entry->special_tab_handling = FALSE;
entry->cursor_obscured = FALSE;
entry->expand_tilde = 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);
......@@ -210,15 +209,6 @@ nautilus_entry_key_press (GtkWidget *widget, GdkEventKey *event)
*/
gtk_widget_activate (widget);
return TRUE;
case GDK_slash:
if (entry->expand_tilde) {
/* FIXME: This handles only ~/, not the fancier variants. */
if (strcmp (gtk_entry_get_text (GTK_ENTRY (entry)), "~") == 0) {
gtk_entry_set_text (GTK_ENTRY (entry), g_get_home_dir ());
}
}
break;
default:
break;
......
......@@ -52,7 +52,6 @@ struct NautilusEntry {
gboolean user_edit;
gboolean special_tab_handling;
gboolean cursor_obscured;
gboolean expand_tilde;
};
struct NautilusEntryClass {
......
......@@ -39,6 +39,8 @@
#include "nautilus-string-picker.h"
#include "nautilus-text-caption.h"
#include "nautilus-global-preferences.h"
/* Arguments */
enum
{
......@@ -433,7 +435,7 @@ preferences_item_create_editable_string (NautilusPreferencesItem *item,
/* FIXME This is a special case for the home uri preference,
in the future this should be generalized. */
if (g_strcasecmp (preference_name, "preferences/home_uri") == 0)
if (g_strcasecmp (preference_name, NAUTILUS_PREFERENCES_HOME_URI) == 0)
{
nautilus_text_caption_set_expand_tilde (NAUTILUS_TEXT_CAPTION (item->details->child), TRUE);
}
......
......@@ -32,8 +32,13 @@
#include <gtk/gtklabel.h>
#include <gtk/gtkentry.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtksignal.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <string.h>
static const gint TEXT_CAPTION_INVALID = -1;
static const gint TEXT_CAPTION_SPACING = 10;
......@@ -47,6 +52,8 @@ typedef enum
struct _NautilusTextCaptionDetail
{
GtkWidget *text;
gboolean expand_tilde;
};
/* NautilusTextCaptionClass methods */
......@@ -59,6 +66,9 @@ static void nautilus_text_caption_destroy (GtkObject
/* Editable (entry) callbacks */
static void entry_changed_callback (GtkWidget *entry,
gpointer user_data);
static void entry_key_press_callback (GtkWidget *widget,
GdkEventKey *event,
gpointer user_data);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusTextCaption, nautilus_text_caption, NAUTILUS_TYPE_CAPTION)
......@@ -100,7 +110,7 @@ nautilus_text_caption_initialize (NautilusTextCaption *text_caption)
gtk_box_set_homogeneous (GTK_BOX (text_caption), FALSE);
gtk_box_set_spacing (GTK_BOX (text_caption), TEXT_CAPTION_SPACING);
text_caption->detail->text = nautilus_entry_new ();
text_caption->detail->text = gtk_entry_new ();
gtk_entry_set_editable (GTK_ENTRY (text_caption->detail->text), TRUE);
......@@ -111,7 +121,11 @@ nautilus_text_caption_initialize (NautilusTextCaption *text_caption)
"changed",
GTK_SIGNAL_FUNC (entry_changed_callback),
(gpointer) text_caption);
gtk_signal_connect_after (GTK_OBJECT (text_caption->detail->text),
"key_press_event",
GTK_SIGNAL_FUNC (entry_key_press_callback),
(gpointer) text_caption);
gtk_widget_show (text_caption->detail->text);
}
......@@ -150,6 +164,24 @@ entry_changed_callback (GtkWidget *entry, gpointer user_data)
gtk_signal_emit (GTK_OBJECT (text_caption), text_caption_signals[CHANGED]);
}
static void
entry_key_press_callback (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
{
NautilusTextCaption *text_caption;
char *expanded_text;
text_caption = NAUTILUS_TEXT_CAPTION (user_data);
if (event->keyval == GDK_asciitilde) {
if (text_caption->detail->expand_tilde) {
expanded_text = gnome_vfs_expand_initial_tilde (gtk_entry_get_text (GTK_ENTRY (widget)));
gtk_entry_set_text (GTK_ENTRY (widget), expanded_text);
g_free (expanded_text);
}
}
}
/*
* NautilusTextCaption public methods
*/
......@@ -207,5 +239,5 @@ nautilus_text_caption_set_expand_tilde (NautilusTextCaption *text_caption,
{
g_return_if_fail (NAUTILUS_IS_TEXT_CAPTION (text_caption));
NAUTILUS_ENTRY (text_caption->detail->text)->expand_tilde = TRUE;
text_caption->detail->expand_tilde = expand_tilde;
}
......@@ -318,6 +318,7 @@ try_to_expand_path (NautilusLocationBar *bar)
|| nautilus_strcmp (user_location, "~/") == 0) {
return FALSE;
}
gnome_vfs_expand_initial_tilde (user_location);
current_path = nautilus_make_uri_from_input (user_location);
if (!nautilus_istr_has_prefix (current_path, "file://")) {
......@@ -328,6 +329,7 @@ try_to_expand_path (NautilusLocationBar *bar)
current_path_length = strlen(current_path);
offset = current_path_length - strlen(user_location);
gnome_vfs_expand_initial_tilde (current_path);
uri = gnome_vfs_uri_new (current_path);
base_name_ptr = gnome_vfs_uri_get_basename (uri);
......@@ -379,8 +381,8 @@ try_to_expand_path (NautilusLocationBar *bar)
gtk_entry_append_text (GTK_ENTRY (editable), expand_text + base_length);
gtk_entry_select_region (GTK_ENTRY (editable), current_path_length - offset,
current_path_length + strlen (expand_text) - base_length - offset);
g_free (expand_text);
}
g_free (expand_text);
tilde_expand_name = gtk_entry_get_text (GTK_ENTRY (editable));
if (*tilde_expand_name == '~') {
......@@ -443,6 +445,7 @@ editable_key_press_callback (GtkObject *object,
int position;
gboolean *return_value_location;
NautilusLocationBar *bar;
char *expanded_text;
g_assert (n_args == 1);
g_assert (args != NULL);
......@@ -468,6 +471,13 @@ editable_key_press_callback (GtkObject *object,
&& entry_would_have_inserted_characters (event)) {
bar->details->idle_id = gtk_idle_add ( (GtkFunction) try_to_expand_path, bar);
}
if (event->keyval == GDK_slash) {
expanded_text = gnome_vfs_expand_initial_tilde (gtk_entry_get_text (GTK_ENTRY (editable)));
gtk_entry_set_text (GTK_ENTRY (editable), expanded_text);
g_free (expanded_text);
}
nautilus_location_bar_update_label (bar);
}
......@@ -551,7 +561,6 @@ nautilus_location_bar_initialize (NautilusLocationBar *bar)
entry = nautilus_entry_new ();
NAUTILUS_ENTRY (entry)->special_tab_handling = TRUE;
NAUTILUS_ENTRY (entry)->expand_tilde = TRUE;
gtk_signal_connect_object (GTK_OBJECT (entry), "activate",
nautilus_navigation_bar_location_changed, GTK_OBJECT (bar));
......
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