diff --git a/gnome/ChangeLog b/gnome/ChangeLog index b41dbe92f..a1799c906 100644 --- a/gnome/ChangeLog +++ b/gnome/ChangeLog @@ -1,3 +1,29 @@ +1999-02-17 Federico Mena Quintero + + * gdesktop.c (do_mount_umount): Removed unused variable. + (do_eject): Return FALSE if there is no eject command. + (setup_devices): Removed unused variable. + + * gdnd.c (drop_on_file): Pass the directory to if_link_is_exe(). + (gdnd_validate_action): Likewise. + (gdnd_perform_drop): Made consistent with the rest of the code by + taking the directory name along with the file entry. + (gdnd_validate_action): Likewise. + + * gdesktop.c (icon_drag_motion): Pass the directory to the gdnd + functions. + (icon_drag_data_received): Likewise. + (desktop_drag_motion): Likewise. + (desktop_drag_data_received): Likewise. + (desktop_icon_info_open): Pass the directory to if_link_is_exe(). + + * gscreen.c (panel_icon_list_drag_data_received): Pass the + directory to gdnd functions. + (panel_clist_drag_data_received): Likewise. + (panel_tree_drag_data_received): Likewise. + (panel_clist_drag_motion): Likewise. + (panel_icon_list_drag_motion): Likewise. + 1999-02-17 Miguel de Icaza * gdesktop.c (reload_desktop_icons): Load the information provided diff --git a/gnome/gdesktop.c b/gnome/gdesktop.c index 2994130be..30e0e4852 100644 --- a/gnome/gdesktop.c +++ b/gnome/gdesktop.c @@ -482,7 +482,9 @@ reload_desktop_icons (int user_pos, int xpos, int ypos) orig_xpos = orig_ypos = 0; for (sl = need_position_list; sl; sl = sl->next) { - file_and_url_t *fau = sl->data; + file_and_url_t *fau; + + fau = sl->data; if (user_pos && sl == need_position_list) { /* If we are on the first icon, place it "by hand". @@ -503,40 +505,46 @@ reload_desktop_icons (int user_pos, int xpos, int ypos) get_icon_auto_pos (&xpos, &ypos); } - /* - * If the file dropped was a .desktop file, pull the suggested + /* If the file dropped was a .desktop file, pull the suggested * title and icon from there */ mime = gnome_mime_type_or_default (fau->filename, NULL); - if (mime && strcmp (mime, "application/x-gnome-app-info") == 0){ + if (mime && strcmp (mime, "application/x-gnome-app-info") == 0) { GnomeDesktopEntry *entry; - char *fullname = g_concat_dir_and_file (desktop_directory, fau->filename); - + char *fullname; + + fullname = g_concat_dir_and_file (desktop_directory, fau->filename); entry = gnome_desktop_entry_load (fullname); - if (entry){ - if (entry->name){ + if (entry) { + if (entry->name) { if (fau->caption) g_free (fau->caption); + fau->caption = g_strdup (entry->name); gnome_metadata_set (fullname, "icon-caption", - strlen (fau->caption)+1, fau->caption); + strlen (fau->caption) + 1, + fau->caption); } - if (entry->icon){ + + if (entry->icon) gnome_metadata_set (fullname, "icon-filename", - strlen (entry->icon)+1, entry->icon); - } + strlen (entry->icon) + 1, + entry->icon); + gnome_desktop_entry_free (entry); } g_free (fullname); } - + dii = desktop_icon_info_new (fau->filename, fau->url, fau->caption, xpos, ypos); gtk_widget_show (dii->dicon); if (fau->url) g_free (fau->url); + if (fau->caption) g_free (fau->caption); + g_free (fau->filename); g_free (fau); } @@ -914,7 +922,7 @@ do_mount_umount (char *filename, gboolean is_mount) { static char *mount_command; static char *umount_command; - char *command, *op; + char *op; char buffer [128]; if (is_mount){ @@ -979,9 +987,10 @@ do_eject (char *filename) char *eject_command = find_command (eject_known_locations); char *command; FILE *f; - + if (!eject_command) - return; + return FALSE; + command = g_strconcat (eject_command, " ", filename, NULL); open_error_pipe (); f = popen (command, "r"); @@ -989,6 +998,7 @@ do_eject (char *filename) close_error_pipe (1, _("While running the eject command")); else close_error_pipe (0, 0); + pclose (f); return TRUE; @@ -1029,8 +1039,8 @@ desktop_icon_info_open (DesktopIconInfo *dii) if (S_ISDIR (fe->buf.st_mode) || link_isdir (fe)) new_panel_at (filename); else { - if (!try_to_mount (filename, fe)){ - if (is_exe (fe->buf.st_mode) && if_link_is_exe (fe)) + if (!try_to_mount (filename, fe)) { + if (is_exe (fe->buf.st_mode) && if_link_is_exe (desktop_directory, fe)) my_system (EXECUTE_AS_SHELL, shell, filename); else gmc_open_filename (filename, NULL); @@ -1450,6 +1460,7 @@ icon_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y, gu TRUE, source_widget != NULL, source_widget && is_desktop_icon, + desktop_directory, fe, dii->selected); @@ -1559,10 +1570,11 @@ icon_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gin full_name = g_concat_dir_and_file (desktop_directory, dii->filename); fe = file_entry_from_file (full_name); + g_free (full_name); if (!fe) return; /* eeeek */ - if (gdnd_perform_drop (context, data, fe, full_name)) + if (gdnd_perform_drop (context, data, desktop_directory, fe)) reload_desktop_icons (FALSE, 0, 0); file_entry_free (fe); @@ -1783,8 +1795,6 @@ setup_devices (void) int count; if (strncmp (short_dev_name, "fd", 2) == 0){ - char *full; - format = _("floppy %d"); count = floppy++; } else if (strncmp (short_dev_name, "hd", 2) == 0 || strncmp (short_dev_name, "sd", 2) == 0){ @@ -2028,6 +2038,7 @@ desktop_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y, TRUE, source_widget != NULL, source_widget && is_desktop_icon, + desktop_directory, NULL, FALSE); @@ -2052,14 +2063,20 @@ desktop_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, drop_desktop_icons (context, data, x, y); else { file_entry *desktop_fe; + char *directory, *p; desktop_fe = file_entry_from_file (desktop_directory); if (!desktop_fe) return; /* eeek */ - if (gdnd_perform_drop (context, data, desktop_fe, desktop_directory)) + p = strrchr (desktop_directory, PATH_SEP); + g_assert (p); + directory = g_strndup (desktop_directory, p - desktop_directory); + + if (gdnd_perform_drop (context, data, directory, desktop_fe)) reload_desktop_icons (TRUE, x, y); + g_free (directory); file_entry_free (desktop_fe); } } diff --git a/gnome/gdnd.c b/gnome/gdnd.c index 392640cb0..b41d0577f 100644 --- a/gnome/gdnd.c +++ b/gnome/gdnd.c @@ -290,38 +290,52 @@ drop_url_on_directory (GdkDragContext *context, GtkSelectionData *selection_data /* Drop stuff on a directory */ static int drop_on_directory (GdkDragContext *context, GtkSelectionData *selection_data, - GdkDragAction action, char *destdir) + GdkDragAction action, char *directory, file_entry *dest_fe) { - if (gdnd_drag_context_has_target (context, TARGET_URI_LIST)) - drop_uri_list_on_directory (context, selection_data, action, destdir); - else if (gdnd_drag_context_has_target (context, TARGET_URL)) - drop_url_on_directory (context, selection_data, destdir); - else - return FALSE; + char *full_name; + int retval; - return TRUE; + retval = FALSE; + full_name = g_concat_dir_and_file (directory, dest_fe->fname); + + if (gdnd_drag_context_has_target (context, TARGET_URI_LIST)) { + drop_uri_list_on_directory (context, selection_data, action, full_name); + retval = TRUE; + } else if (gdnd_drag_context_has_target (context, TARGET_URL)) { + drop_url_on_directory (context, selection_data, full_name); + retval = TRUE; + } + + g_free (full_name); + return retval; } /* Drop stuff on a non-directory file. This uses metadata and MIME as well. */ static int drop_on_file (GdkDragContext *context, GtkSelectionData *selection_data, - file_entry *dest_fe, char *dest_name) + char *directory, file_entry *dest_fe) { int size; char *buf; const char *mime_type; + char *full_name; + int retval; + + retval = FALSE; /* assume we cannot drop */ + full_name = g_concat_dir_and_file (directory, dest_fe->fname); /* 1. Try to use a metadata-based drop action */ - if (gnome_metadata_get (dest_name, "drop-action", &size, &buf) == 0) { + if (gnome_metadata_get (full_name, "drop-action", &size, &buf) == 0) { /*action_drop (dest_name, buf, context, selection_data);*/ /* Fixme: i'm undefined */ g_free (buf); - return TRUE; + retval = TRUE; + goto out; } /* 2. Try a drop action from the MIME-type */ - mime_type = gnome_mime_type_or_default (dest_name, NULL); + mime_type = gnome_mime_type_or_default (full_name, NULL); if (mime_type) { char *action; @@ -329,13 +343,14 @@ drop_on_file (GdkDragContext *context, GtkSelectionData *selection_data, if (action) { /* Fixme: i'm undefined */ /*action_drop (dest_name, action, context, selection_data);*/ - return TRUE; + retval = TRUE; + goto out; } } /* 3. If executable, try metadata keys for "open" */ - if (is_exe (dest_fe->buf.st_mode) && if_link_is_exe (dest_fe)) { + if (is_exe (dest_fe->buf.st_mode) && if_link_is_exe (directory, dest_fe)) { GList *names, *l; int len, i; char **drops; @@ -358,29 +373,34 @@ drop_on_file (GdkDragContext *context, GtkSelectionData *selection_data, } drops[i] = NULL; - if (gnome_metadata_get (dest_name, "open", &size, &buf) == 0) - exec_extension (dest_name, buf, drops, NULL, 0); + if (gnome_metadata_get (full_name, "open", &size, &buf) == 0) + exec_extension (full_name, buf, drops, NULL, 0); else - exec_extension (dest_name, "%f %q", drops, NULL, 0); + exec_extension (full_name, "%f %q", drops, NULL, 0); g_free (drops); gnome_uri_list_free_strings (names); g_free (buf); - return TRUE; + retval = TRUE; + goto out; } - return FALSE; /* could not drop */ + out: + + g_free (full_name); + return retval; } int gdnd_perform_drop (GdkDragContext *context, GtkSelectionData *selection_data, - file_entry *dest_fe, char *dest_name) + char *directory, file_entry *dest_fe) { GdkDragAction action; g_return_val_if_fail (context != NULL, FALSE); g_return_val_if_fail (selection_data != NULL, FALSE); + g_return_val_if_fail (directory != NULL, FALSE); g_return_val_if_fail (dest_fe != NULL, FALSE); /* Get action */ @@ -393,9 +413,9 @@ gdnd_perform_drop (GdkDragContext *context, GtkSelectionData *selection_data, action = context->action; if (S_ISDIR (dest_fe->buf.st_mode) || dest_fe->f.link_to_dir) - return drop_on_directory (context, selection_data, action, dest_name); + return drop_on_directory (context, selection_data, action, directory, dest_fe); else - return drop_on_file (context, selection_data, dest_fe, dest_name); + return drop_on_file (context, selection_data, directory, dest_fe); } /** @@ -480,12 +500,13 @@ gdnd_find_panel_by_drag_context (GdkDragContext *context, GtkWidget **source_wid GdkDragAction gdnd_validate_action (GdkDragContext *context, int on_desktop, int same_process, int same_source, - file_entry *dest_fe, int dest_selected) + char *directory, file_entry *dest_fe, int dest_selected) { int on_directory; int on_exe; g_return_val_if_fail (context != NULL, 0); + g_return_val_if_fail (directory != NULL, 0); /* If we are dragging a desktop icon onto the desktop or onto a selected * desktop icon, unconditionally specify MOVE. @@ -499,7 +520,7 @@ gdnd_validate_action (GdkDragContext *context, if (dest_fe) { on_directory = S_ISDIR (dest_fe->buf.st_mode) || dest_fe->f.link_to_dir; - on_exe = is_exe (dest_fe->buf.st_mode) && if_link_is_exe (dest_fe); + on_exe = is_exe (dest_fe->buf.st_mode) && if_link_is_exe (directory, dest_fe); } if (gdnd_drag_context_has_target (context, TARGET_URI_LIST)) { diff --git a/gnome/gdnd.h b/gnome/gdnd.h index 2d843749f..23729999c 100644 --- a/gnome/gdnd.h +++ b/gnome/gdnd.h @@ -40,7 +40,7 @@ void gdnd_init (void); * Returns TRUE if an action was performed, FALSE otherwise (i.e. invalid drop). */ int gdnd_perform_drop (GdkDragContext *context, GtkSelectionData *selection_data, - file_entry *dest_fe, char *dest_name); + char *directory, file_entry *dest_fe); /* Test whether the specified context has a certain target type */ int gdnd_drag_context_has_target (GdkDragContext *context, TargetType type); @@ -53,7 +53,7 @@ WPanel *gdnd_find_panel_by_drag_context (GdkDragContext *context, GtkWidget **so */ GdkDragAction gdnd_validate_action (GdkDragContext *context, int on_desktop, int same_process, int same_source, - file_entry *dest_fe, int dest_selected); + char *directory, file_entry *dest_fe, int dest_selected); #endif diff --git a/gnome/gmount.c b/gnome/gmount.c index 31cab30bb..8680a1ae1 100644 --- a/gnome/gmount.c +++ b/gnome/gmount.c @@ -1,3 +1,10 @@ +/* Mount/umount support for the Midnight Commander + * + * Copyright (C) 1998-1999 The Free Software Foundation + * + * Author: Miguel de Icaza + */ + #include #ifdef STDC_HEADERS diff --git a/gnome/gmount.h b/gnome/gmount.h index bbd818070..a17e5a9ea 100644 --- a/gnome/gmount.h +++ b/gnome/gmount.h @@ -1,6 +1,15 @@ +/* Mount/umount support for the Midnight Commander + * + * Copyright (C) 1998-1999 The Free Software Foundation + * + * Author: Miguel de Icaza + */ + #ifndef GMOUNT_H #define GMOUNT_H +#include + gboolean is_block_device_mountable (char *devname); gboolean is_block_device_mounted (char *devname); GList *get_list_of_mountable_devices (void); diff --git a/gnome/gscreen.c b/gnome/gscreen.c index 354145ad5..dc9289036 100644 --- a/gnome/gscreen.c +++ b/gnome/gscreen.c @@ -805,7 +805,7 @@ panel_icon_list_drag_data_received (GtkWidget *widget, free_fe = FALSE; } - reload = gdnd_perform_drop (context, selection_data, fe, file); + reload = gdnd_perform_drop (context, selection_data, panel->cwd, fe); if (free_file) g_free (file); @@ -860,7 +860,7 @@ panel_clist_drag_data_received (GtkWidget *widget, free_fe = FALSE; } - reload = gdnd_perform_drop (context, selection_data, fe, file); + reload = gdnd_perform_drop (context, selection_data, panel->cwd, fe); if (free_file) g_free (file); @@ -908,7 +908,7 @@ panel_tree_drag_data_received (GtkWidget *widget, if (!fe) return; /* eeeek */ - gdnd_perform_drop (context, selection_data, fe, path); + gdnd_perform_drop (context, selection_data, panel->cwd, fe); file_entry_free (fe); g_free (path); @@ -1117,6 +1117,7 @@ panel_clist_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gin FALSE, source_widget != NULL, source_widget == widget, + panel->cwd, fe, fe ? fe->f.marked : FALSE); @@ -1232,6 +1233,7 @@ panel_icon_list_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, FALSE, source_widget != NULL, source_widget == widget, + panel->cwd, fe, fe ? fe->f.marked : FALSE); diff --git a/src/ChangeLog b/src/ChangeLog index eb20e9345..152497b65 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +1999-02-17 Federico Mena Quintero + + * dir.c (if_link_is_exe): Made this function take in a directory + argument as well -- the sought file may not be in the cwd, and + file entries do not carry the directory the file refers to. + + * screen.c (do_enter_on_file_entry): Pass in the cpanel->cwd to + if_link_is_exe(). + 1999-02-16 Miguel de Icaza * treestore.c (tree_store_rescan): Add code to skip scanning diff --git a/src/dir.c b/src/dir.c index 5dd7aacff..938b8e932 100644 --- a/src/dir.c +++ b/src/dir.c @@ -293,7 +293,8 @@ do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitiv qsort (&(list->list) [1], top, sizeof (file_entry), sort); } -void clean_dir (dir_list *list, int count) +void +clean_dir (dir_list *list, int count) { int i; @@ -357,16 +358,18 @@ add_dotdot_to_list (dir_list *list, int index) } /* Used to set up a directory list when there is no access to a directory */ -int set_zero_dir (dir_list *list) +int +set_zero_dir (dir_list *list) { return (add_dotdot_to_list (list, 0)); } /* If you change handle_dirent then check also handle_path. */ /* Return values: -1 = failure, 0 = don't add, 1 = add to the list */ -int handle_dirent (dir_list *list, char *filter, struct dirent *dp, - struct stat *buf1, int next_free, int *link_to_dir, - int *stalled_link) +int +handle_dirent (dir_list *list, char *filter, struct dirent *dp, + struct stat *buf1, int next_free, int *link_to_dir, + int *stalled_link) { if (dp->d_name [0] == '.' && dp->d_name [1] == 0) return 0; @@ -417,9 +420,10 @@ int handle_dirent (dir_list *list, char *filter, struct dirent *dp, Moreover handle_path can't be used with a filemask. If you change handle_path then check also handle_dirent. */ /* Return values: -1 = failure, 0 = don't add, 1 = add to the list */ -int handle_path (dir_list *list, char *path, - struct stat *buf1, int next_free, int *link_to_dir, - int *stalled_link) +int +handle_path (dir_list *list, char *path, + struct stat *buf1, int next_free, int *link_to_dir, + int *stalled_link) { if (path [0] == '.' && path [1] == 0) return 0; @@ -451,7 +455,8 @@ int handle_path (dir_list *list, char *path, return 1; } -int do_load_dir(dir_list *list, sortfn *sort, int reverse, int case_sensitive, char *filter) +int +do_load_dir (dir_list *list, sortfn *sort, int reverse, int case_sensitive, char *filter) { DIR *dirp; struct dirent *dp; @@ -504,7 +509,8 @@ int do_load_dir(dir_list *list, sortfn *sort, int reverse, int case_sensitive, c return next_free; } -int link_isdir (file_entry *file) +int +link_isdir (file_entry *file) { if (file->f.link_to_dir) return 1; @@ -512,20 +518,25 @@ int link_isdir (file_entry *file) return 0; } -int if_link_is_exe (file_entry *file) +int +if_link_is_exe (char *directory, file_entry *file) { struct stat b; + char *full_name; - if (S_ISLNK (file->buf.st_mode)){ - mc_stat (file->fname, &b); + if (S_ISLNK (file->buf.st_mode)) { + full_name = concat_dir_and_file (directory, file->fname); + mc_stat (full_name, &b); + g_free (full_name); return is_exe (b.st_mode); - } - return 1; + } else + return 1; } static dir_list dir_copy = { 0, 0 }; -static void alloc_dir_copy (int size) +static void +alloc_dir_copy (int size) { int i; @@ -549,8 +560,9 @@ static void alloc_dir_copy (int size) } /* If filter is null, then it is a match */ -int do_reload_dir (dir_list *list, sortfn *sort, int count, int rev, - int case_sensitive, char *filter) +int +do_reload_dir (dir_list *list, sortfn *sort, int count, int rev, + int case_sensitive, char *filter) { DIR *dirp; struct dirent *dp; @@ -636,7 +648,8 @@ int do_reload_dir (dir_list *list, sortfn *sort, int count, int rev, return next_free; } -char *sort_type_to_name (sortfn *sort_fn) +char * +sort_type_to_name (sortfn *sort_fn) { int i; @@ -647,7 +660,8 @@ char *sort_type_to_name (sortfn *sort_fn) return _("Unknown"); } -sortfn *sort_name_to_type (char *sname) +sortfn * +sort_name_to_type (char *sname) { int i; diff --git a/src/dir.h b/src/dir.h index 2ac2e2836..418a83e69 100644 --- a/src/dir.h +++ b/src/dir.h @@ -79,7 +79,7 @@ typedef struct { extern sort_orders_t sort_orders [SORT_TYPES_TOTAL]; int link_isdir (file_entry *); -int if_link_is_exe (file_entry *file); +int if_link_is_exe (char *directory, file_entry *file); extern int show_backups; extern int show_dot_files; diff --git a/src/screen.c b/src/screen.c index 857a7c087..16242dc3e 100644 --- a/src/screen.c +++ b/src/screen.c @@ -2036,9 +2036,8 @@ do_enter_on_file_entry (file_entry *fe) if (S_ISDIR (fe->buf.st_mode) || link_isdir (fe)) { do_cd (fe->fname, cd_exact); return 1; - } else { - if (is_exe (fe->buf.st_mode) && - if_link_is_exe (fe)) { + } else { + if (is_exe (fe->buf.st_mode) && if_link_is_exe (cpanel->cwd, fe)) { #ifdef USE_VFS if (vfs_current_is_local ()) #endif