Fixed bugs 5837, 6463, 6478, and 6506 by making tilde support work alot better in nautilus.

This commit is contained in:
Arik Devens 2001-02-13 11:05:39 +00:00
parent f02bf5997c
commit 25dcf28b44
15 changed files with 183 additions and 54 deletions

View file

@ -1,3 +1,46 @@
2001-02-13 Arik Devens <arik@eazel.com>
reviewed by: Maciej Stachowiak <mjs@eazel.com>
Fixed bug 5837, 'Home Location' preference should accept ~.
Fixed bug 6463, GNOME-VFS spews critical errors as you type an
incomplete path in the location bar.
Fixed bug 6478, nautilus crashes on ~somedir/ if that dir
doesn't exist.
Fixed bug 6506, Entering "~" in Add New Background Dialogue box
causes Nautilus to crash.
* libnautilus-extensions/nautilus-entry.c:
(nautilus_entry_initialize), (nautilus_entry_key_press): Added
setting of expand_tilde to FALSE. Added a slash case so that ~/
gets expanded to $(HOMEDIR).
* libnautilus-extensions/nautilus-entry.h: Added gboolean
expand_tilde to the NautilusEntry struct.
* libnautilus-extensions/nautilus-file-utilities.c:
(nautilus_make_uri_from_input): Added falling into default case
on ~'s if the dir doesn't exist so they end up at http://'s.
* libnautilus-extensions/nautilus-preferences-item.c:
(preferences_item_create_editable_string): Added special case
setting of expand_tilde to TRUE on the home dir preference box.
As well as a FIXME saying this should be dealt with later on.
* libnautilus-extensions/nautilus-text-caption.c:
(nautilus_text_caption_initialize), (entry_changed_callback),
(nautilus_text_caption_set_editable),
(nautilus_text_caption_set_expand_tilde): Changed
NautilusTextCaption to use NautilusEntry instead of GtkEntry.
Added function to set expand tilde on NautilusText Caption.
Updated set_editable to work with NautilusEntry.
* libnautilus-extensions/nautilus-text-caption.h: Added
nautilus_text_caption_set_expand_tilde function prototype.
* src/nautilus-location-bar.c: (try_to_expand_path),
(nautilus_location_bar_initialize): Added expanding of ~'s at
the beginning of the location to full path. Added setting of
expand_tilde to TRUE.
* src/nautilus-property-browser.c: (add_pattern_to_browser):
Added if statement to not attempt to do anything if the dir
chosen uses ~ do to gtk brokenness. Also added error dialog
that explains what happened to the user.
2001-02-13 Andy Hertzfeld <andy@eazel.com>
* src/nautilus-theme-selector.c:

View file

@ -124,6 +124,7 @@ 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);
@ -159,7 +160,6 @@ nautilus_entry_destroy (GtkObject *object)
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}
static void
obscure_cursor (NautilusEntry *entry)
{
@ -210,6 +210,14 @@ nautilus_entry_key_press (GtkWidget *widget, GdkEventKey *event)
*/
gtk_widget_activate (widget);
return TRUE;
case GDK_slash:
if (entry->expand_tilde) {
if (g_strcasecmp (gtk_entry_get_text (GTK_ENTRY (entry)), "~") == 0) {
gtk_entry_set_text (GTK_ENTRY (entry), g_get_home_dir ());
}
}
break;
default:
break;

View file

@ -52,6 +52,7 @@ struct NautilusEntry {
gboolean user_edit;
gboolean special_tab_handling;
gboolean cursor_obscured;
gboolean expand_tilde;
};
struct NautilusEntryClass {

View file

@ -154,9 +154,14 @@ nautilus_make_uri_from_input (const char *location)
break;
case '~':
path = gnome_vfs_expand_initial_tilde (stripped);
uri = gnome_vfs_get_uri_from_local_path (path);
g_free (path);
break;
/* deliberately falling into default case on fail */
if (*path == '/') {
uri = gnome_vfs_get_uri_from_local_path (path);
g_free (path);
break;
}
g_free (path);
/* don't insert break here, read above comment */
default:
if (has_valid_scheme (stripped)) {
uri = g_strdup (stripped);

View file

@ -431,6 +431,13 @@ preferences_item_create_editable_string (NautilusPreferencesItem *item,
item->details->child = nautilus_text_caption_new ();
/* 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)
{
nautilus_text_caption_set_expand_tilde (NAUTILUS_TEXT_CAPTION (item->details->child), TRUE);
}
nautilus_caption_set_title_label (NAUTILUS_CAPTION (item->details->child), description);
g_free (description);

View file

@ -27,6 +27,7 @@
#include "nautilus-text-caption.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-entry.h"
#include <gtk/gtklabel.h>
#include <gtk/gtkentry.h>
@ -99,7 +100,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 = gtk_entry_new ();
text_caption->detail->text = nautilus_entry_new ();
gtk_entry_set_editable (GTK_ENTRY (text_caption->detail->text), TRUE);
@ -199,3 +200,12 @@ nautilus_text_caption_set_editable (NautilusTextCaption *text_caption,
gtk_entry_set_editable (GTK_ENTRY (text_caption->detail->text), editable);
}
void
nautilus_text_caption_set_expand_tilde (NautilusTextCaption *text_caption,
gboolean expand_tilde)
{
g_return_if_fail (NAUTILUS_IS_TEXT_CAPTION (text_caption));
NAUTILUS_ENTRY (text_caption->detail->text)->expand_tilde = TRUE;
}

View file

@ -71,6 +71,9 @@ void nautilus_text_caption_set_text (NautilusTextCaption *text_caption,
void nautilus_text_caption_set_editable (NautilusTextCaption *text_caption,
gboolean editable);
void nautilus_text_caption_set_expand_tilde (NautilusTextCaption *text_caption,
gboolean expand_tilde);
END_GNOME_DECLS
#endif /* NAUTILUS_TEXT_CAPTION_H */

View file

@ -124,6 +124,7 @@ 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);
@ -159,7 +160,6 @@ nautilus_entry_destroy (GtkObject *object)
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}
static void
obscure_cursor (NautilusEntry *entry)
{
@ -210,6 +210,14 @@ nautilus_entry_key_press (GtkWidget *widget, GdkEventKey *event)
*/
gtk_widget_activate (widget);
return TRUE;
case GDK_slash:
if (entry->expand_tilde) {
if (g_strcasecmp (gtk_entry_get_text (GTK_ENTRY (entry)), "~") == 0) {
gtk_entry_set_text (GTK_ENTRY (entry), g_get_home_dir ());
}
}
break;
default:
break;

View file

@ -52,6 +52,7 @@ struct NautilusEntry {
gboolean user_edit;
gboolean special_tab_handling;
gboolean cursor_obscured;
gboolean expand_tilde;
};
struct NautilusEntryClass {

View file

@ -154,9 +154,14 @@ nautilus_make_uri_from_input (const char *location)
break;
case '~':
path = gnome_vfs_expand_initial_tilde (stripped);
uri = gnome_vfs_get_uri_from_local_path (path);
g_free (path);
break;
/* deliberately falling into default case on fail */
if (*path == '/') {
uri = gnome_vfs_get_uri_from_local_path (path);
g_free (path);
break;
}
g_free (path);
/* don't insert break here, read above comment */
default:
if (has_valid_scheme (stripped)) {
uri = g_strdup (stripped);

View file

@ -431,6 +431,13 @@ preferences_item_create_editable_string (NautilusPreferencesItem *item,
item->details->child = nautilus_text_caption_new ();
/* 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)
{
nautilus_text_caption_set_expand_tilde (NAUTILUS_TEXT_CAPTION (item->details->child), TRUE);
}
nautilus_caption_set_title_label (NAUTILUS_CAPTION (item->details->child), description);
g_free (description);

View file

@ -27,6 +27,7 @@
#include "nautilus-text-caption.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-entry.h"
#include <gtk/gtklabel.h>
#include <gtk/gtkentry.h>
@ -99,7 +100,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 = gtk_entry_new ();
text_caption->detail->text = nautilus_entry_new ();
gtk_entry_set_editable (GTK_ENTRY (text_caption->detail->text), TRUE);
@ -199,3 +200,12 @@ nautilus_text_caption_set_editable (NautilusTextCaption *text_caption,
gtk_entry_set_editable (GTK_ENTRY (text_caption->detail->text), editable);
}
void
nautilus_text_caption_set_expand_tilde (NautilusTextCaption *text_caption,
gboolean expand_tilde)
{
g_return_if_fail (NAUTILUS_IS_TEXT_CAPTION (text_caption));
NAUTILUS_ENTRY (text_caption->detail->text)->expand_tilde = TRUE;
}

View file

@ -71,6 +71,9 @@ void nautilus_text_caption_set_text (NautilusTextCaption *text_caption,
void nautilus_text_caption_set_editable (NautilusTextCaption *text_caption,
gboolean editable);
void nautilus_text_caption_set_expand_tilde (NautilusTextCaption *text_caption,
gboolean expand_tilde);
END_GNOME_DECLS
#endif /* NAUTILUS_TEXT_CAPTION_H */

View file

@ -1,3 +1,4 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
@ -305,7 +306,8 @@ try_to_expand_path (NautilusLocationBar *bar)
char *dir_name;
char *expand_text;
char *expand_name;
char *tilde_expand_name;
editable = GTK_EDITABLE (bar->details->entry);
user_location = gtk_editable_get_chars (editable, 0, -1);
bar->details->idle_id = 0;
@ -339,7 +341,7 @@ try_to_expand_path (NautilusLocationBar *bar)
g_free (current_path);
return FALSE;
}
base_length = strlen (base_name);
dir_name = gnome_vfs_uri_extract_dirname (uri);
@ -372,11 +374,17 @@ try_to_expand_path (NautilusLocationBar *bar)
/* if we've got something, add it to the entry */
if (expand_text && !nautilus_str_has_suffix (current_path, expand_text)) {
gtk_entry_append_text (GTK_ENTRY (editable), expand_text + base_length);
gtk_entry_select_region (GTK_ENTRY (editable), current_path_length - offset,
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);
}
tilde_expand_name = gtk_entry_get_text (GTK_ENTRY (editable));
if (*tilde_expand_name == '~') {
gtk_entry_set_text (GTK_ENTRY (editable), gnome_vfs_expand_initial_tilde (tilde_expand_name));
}
g_free (tilde_expand_name);
g_free (dir_name);
g_free (base_name);
@ -540,6 +548,7 @@ 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));

View file

@ -1031,52 +1031,61 @@ add_pattern_to_browser (const char *path_name, gpointer *data)
NautilusPropertyBrowser *property_browser = NAUTILUS_PROPERTY_BROWSER(data);
/* fetch the mime type and make sure that the file is an image */
path_uri = gnome_vfs_get_uri_from_local_path (path_name);
/* FIXME this is not a problem in nautilus but rather in the
gtk widget that selects the tiles. that would have to be fixed to
support tilde's. at the moment this is the best we can do. */
if (*path_name != '~') {
/* fetch the mime type and make sure that the file is an image */
path_uri = gnome_vfs_get_uri_from_local_path (path_name);
/* don't allow the user to change the reset image */
basename = nautilus_uri_get_basename (path_uri);
if (basename && nautilus_strcmp (basename, RESET_IMAGE_NAME) == 0) {
nautilus_show_error_dialog (_("Sorry, but you can't replace the reset image."), _("Not an Image"), NULL);
g_free (path_uri);
g_free (basename);
return;
}
/* don't allow the user to change the reset image */
basename = nautilus_uri_get_basename (path_uri);
if (basename && nautilus_strcmp (basename, RESET_IMAGE_NAME) == 0) {
nautilus_show_error_dialog (_("Sorry, but you can't replace the reset image."), _("Not an Image"), NULL);
g_free (path_uri);
g_free (basename);
return;
}
g_free(path_uri);
g_free (basename);
user_directory = nautilus_get_user_directory ();
g_free (path_uri);
g_free (basename);
user_directory = nautilus_get_user_directory ();
/* copy the image file to the patterns directory */
directory_path = nautilus_make_path (user_directory, property_browser->details->category);
g_free (user_directory);
source_file_name = strrchr (path_name, '/');
destination_name = nautilus_make_path (directory_path, source_file_name + 1);
/* copy the image file to the patterns directory */
directory_path = nautilus_make_path (user_directory, property_browser->details->category);
g_free (user_directory);
source_file_name = strrchr (path_name, '/');
destination_name = nautilus_make_path (directory_path, source_file_name + 1);
/* make the directory if it doesn't exist */
if (!g_file_exists(directory_path)) {
directory_uri = gnome_vfs_get_uri_from_local_path (directory_path);
gnome_vfs_make_directory (directory_uri,
GNOME_VFS_PERM_USER_ALL
| GNOME_VFS_PERM_GROUP_ALL
| GNOME_VFS_PERM_OTHER_READ);
g_free (directory_uri);
}
g_free(directory_path);
result = nautilus_copy_uri_simple (path_name, destination_name);
if (result != GNOME_VFS_OK) {
char *message = g_strdup_printf (_("Sorry, but the pattern %s couldn't be installed."), path_name);
/* make the directory if it doesn't exist */
if (!g_file_exists(directory_path)) {
directory_uri = gnome_vfs_get_uri_from_local_path (directory_path);
gnome_vfs_make_directory (directory_uri,
GNOME_VFS_PERM_USER_ALL
| GNOME_VFS_PERM_GROUP_ALL
| GNOME_VFS_PERM_OTHER_READ);
g_free (directory_uri);
}
g_free (directory_path);
result = nautilus_copy_uri_simple (path_name, destination_name);
if (result != GNOME_VFS_OK) {
char *message = g_strdup_printf (_("Sorry, but the pattern %s couldn't be installed."), path_name);
nautilus_show_error_dialog (message, _("Couldn't install pattern"), GTK_WINDOW (property_browser));
g_free (message);
}
g_free (destination_name);
/* update the property browser's contents to show the new one */
nautilus_property_browser_update_contents (property_browser);
} else {
char *message = g_strdup_printf (_("Sorry, but ~ as a directory is not currently supported.\n Please Type the full path."));
nautilus_show_error_dialog (message, _("Couldn't install pattern"), GTK_WINDOW (property_browser));
g_free (message);
}
g_free(destination_name);
/* update the property browser's contents to show the new one */
nautilus_property_browser_update_contents(property_browser);
}
/* here's where we initiate adding a new pattern by putting up a file selector */