summaryrefslogtreecommitdiff
path: root/gtk/gtkfilechooserdefault.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@ximian.com>2004-03-15 02:09:22 +0000
committerFederico Mena Quintero <federico@src.gnome.org>2004-03-15 02:09:22 +0000
commitdfa36bb4e4035370f283823372ea71e77baec3bc (patch)
treebec3906a4a93a54d9665a70e07b46216677a55c5 /gtk/gtkfilechooserdefault.c
parent3895bea4df873c114689f8de97b5527a75657aaf (diff)
downloadgdk-pixbuf-dfa36bb4e4035370f283823372ea71e77baec3bc.tar.gz
Fixes #136185, patch by Morten Welinder, with some changes.
2004-03-14 Federico Mena Quintero <federico@ximian.com> Fixes #136185, patch by Morten Welinder, with some changes. * gtk/gtkfilechooserdefault.c (check_is_folder): New helper function. (shortcuts_insert_path): Check the path first with check_is_folder(). (gtk_file_chooser_default_set_current_folder): Likewise. (gtk_file_chooser_default_add_shortcut_folder): Likewise. (browse_widgets_create): Unref the size group. * gtk/gtkfilesystemunix.c (gtk_file_system_unix_get_folder): Handle the case where the file exists but it is not a directory. (IconType): Add value for ICON_UNDECIDED. (struct stat_info_entry): New structure to hold a file's struct stat, its MIME type and its icon type. (struct _GtkFileFolderUnix): Added a hash of struct stat_info_entry, and flags to remember which info types we've read so far. (get_icon_type): Use a helper function for the icons-from-stat types. (gtk_file_system_unix_render_icon): Use the cached file info. (gtk_file_folder_unix_get_info): Put the info in the cache. (gtk_file_system_unix_get_folder): Create the cache of file info structures. * gtk/gtkfilesystem.c (gtk_file_info_set_display_name): Handle the case where display_name is the same as the existing info->display_name.
Diffstat (limited to 'gtk/gtkfilechooserdefault.c')
-rw-r--r--gtk/gtkfilechooserdefault.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index d8ccb35be..a2d301724 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -872,6 +872,22 @@ shortcuts_unselect_all (GtkFileChooserDefault *impl)
gtk_tree_selection_unselect_all (selection);
}
+/* Returns whether a path is a folder */
+static gboolean
+check_is_folder (GtkFileSystem *file_system, const GtkFilePath *path, GError **error)
+{
+ GtkFileFolder *folder;
+
+ folder = gtk_file_system_get_folder (file_system, path,
+ GTK_FILE_INFO_DISPLAY_NAME,
+ error);
+ if (!folder)
+ return FALSE;
+
+ g_object_unref (folder);
+ return TRUE;
+}
+
/* Convenience function to get the display name and icon info for a path */
static GtkFileInfo *
get_file_info (GtkFileSystem *file_system, const GtkFilePath *path, gboolean name_only, GError **error)
@@ -930,18 +946,21 @@ shortcuts_insert_path (GtkFileChooserDefault *impl,
}
else
{
- /* Always check to make sure that the directory exists. */
- GtkFileInfo *info = get_file_info (impl->file_system, path, FALSE, error);
-
- if (info == NULL)
+ if (!check_is_folder (impl->file_system, path, error))
return FALSE;
if (label)
label_copy = g_strdup (label);
else
- label_copy = g_strdup (gtk_file_info_get_display_name (info));
+ {
+ GtkFileInfo *info = get_file_info (impl->file_system, path, TRUE, error);
- gtk_file_info_free (info);
+ if (!info)
+ return FALSE;
+
+ label_copy = g_strdup (gtk_file_info_get_display_name (info));
+ gtk_file_info_free (info);
+ }
data = gtk_file_path_copy (path);
pixbuf = gtk_file_system_render_icon (impl->file_system, path, GTK_WIDGET (impl),
@@ -1991,7 +2010,7 @@ shortcuts_drag_outside_idle_cb (GtkFileChooserDefault *impl)
shortcuts_cancel_drag_outside_idle (impl);
return FALSE;
}
-
+
/* GtkWidget::drag-leave handler for the shortcuts list. We unhighlight the
* drop position.
*/
@@ -2810,6 +2829,8 @@ browse_widgets_create (GtkFileChooserDefault *impl)
widget = file_pane_create (impl, size_group);
gtk_paned_pack2 (GTK_PANED (hpaned), widget, TRUE, FALSE);
+ g_object_unref (size_group);
+
/* Alignment to hold custom widget */
impl->browse_extra_align = gtk_alignment_new (0.0, .5, 1.0, 1.0);
gtk_box_pack_start (GTK_BOX (vbox), impl->browse_extra_align, FALSE, FALSE, 0);
@@ -3561,13 +3582,10 @@ gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
GError **error)
{
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
- GtkFileInfo *info;
/* Test validity of path here. */
- info = get_file_info (impl->file_system, path, FALSE, error);
- if (!info)
+ if (!check_is_folder (impl->file_system, path, error))
return FALSE;
- gtk_file_info_free (info);
if (!_gtk_path_bar_set_path (GTK_PATH_BAR (impl->browse_path_bar), path, error))
return FALSE;
@@ -3947,6 +3965,10 @@ gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
gboolean result;
int pos;
+ /* Test validity of path here. */
+ if (!check_is_folder (impl->file_system, path, error))
+ return FALSE;
+
pos = shortcuts_get_pos_for_shortcut_folder (impl, impl->num_shortcuts);
result = shortcuts_insert_path (impl, pos, FALSE, NULL, path, NULL, FALSE, error);