From 262a63153b19e69a52fb5d4ce62e67e825127902 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 8 Jan 2000 13:48:26 +0000 Subject: [PATCH] r160: Mounting and unmounting now updates the directories automatically. --- ROX-Filer/src/action.c | 84 +++++++++++++++++++++++++++++++++----------------- ROX-Filer/src/action.h | 2 +- ROX-Filer/src/filer.c | 67 ++++++++++++++++++++++++++++++++++------ ROX-Filer/src/filer.h | 3 ++ ROX-Filer/src/menu.c | 33 ++++++-------------- ROX-Filer/src/run.c | 1 + 6 files changed, 127 insertions(+), 63 deletions(-) diff --git a/ROX-Filer/src/action.c b/ROX-Filer/src/action.c index f583abc7..753da1a1 100644 --- a/ROX-Filer/src/action.c +++ b/ROX-Filer/src/action.c @@ -71,12 +71,14 @@ static GString *message = NULL; static char *action_dest = NULL; static gboolean (*action_do_func)(char *source, char *dest); static size_t size_tally; /* For Disk Usage */ +static DirItem *mount_item; /* Static prototypes */ static gboolean send(); static gboolean send_error(); static gboolean send_dir(char *dir); static gboolean read_exact(int source, char *buffer, ssize_t len); +static void do_mount(FilerWindow *filer_window, DirItem *item); static gboolean display_dir(gpointer data) { @@ -118,6 +120,12 @@ static void message_from_child(gpointer data, g_free(buffer); return; } + else if (*buffer == 'm') + { + filer_check_mounted(buffer + 1); + g_free(buffer); + return; + } else if (*buffer == '/') { if (gui_side->next_dir) @@ -714,6 +722,33 @@ static gboolean do_link(char *path, char *dest) return TRUE; } +/* Mount/umount this item */ +static void do_mount(FilerWindow *filer_window, DirItem *item) +{ + char *command; + char *path; + + path = make_path(filer_window->path, item->leafname)->str; + + command = g_strdup_printf("%smount %s", + item->flags & ITEM_FLAG_MOUNTED ? "u" : "", path); + g_string_sprintf(message, "'> %s\n", command); + send(); + if (system(command) == 0) + { + g_string_sprintf(message, "+%s", filer_window->path); + send(); + g_string_sprintf(message, "m%s", path); + send(); + } + else + { + g_string_sprintf(message, "!Operation failed.\n"); + send(); + } + g_free(command); +} + /* CHILD MAIN LOOPS */ /* After forking, the child calls one of these functions */ @@ -759,42 +794,32 @@ static void mount_cb(gpointer data) Collection *collection = filer_window->collection; DirItem *item; int i; - char *command; gboolean mount_points = FALSE; send_dir(filer_window->path); - for (i = 0; i < collection->number_of_items; i++) + if (mount_item) + do_mount(filer_window, mount_item); + else { - if (!collection->items[i].selected) - continue; - item = (DirItem *) collection->items[i].data; - if (!(item->flags & ITEM_FLAG_MOUNT_POINT)) - continue; - mount_points = TRUE; - - command = g_strdup_printf("%smount %s", - item->flags & ITEM_FLAG_MOUNTED ? "u" : "", - make_path(filer_window->path, item->leafname)->str); - g_string_sprintf(message, "'> %s\n", command); - send(); - if (system(command) == 0) + for (i = 0; i < collection->number_of_items; i++) { - g_string_sprintf(message, "+%s", filer_window->path); - send(); + if (!collection->items[i].selected) + continue; + item = (DirItem *) collection->items[i].data; + if (!(item->flags & ITEM_FLAG_MOUNT_POINT)) + continue; + mount_points = TRUE; + + do_mount(filer_window, item); } - else + + if (!mount_points) { - g_string_sprintf(message, "!Operation failed.\n"); + g_string_sprintf(message, + "!No mount points selected!\n"); send(); } - g_free(command); - } - - if (!mount_points) - { - g_string_sprintf(message, "!No mount points selected!\n"); - send(); } g_string_sprintf(message, "'\nDone\n"); @@ -881,8 +906,8 @@ void action_usage(FilerWindow *filer_window) gtk_widget_show_all(gui_side->window); } -/* Mount/unmount all selected mount points */ -void action_mount(FilerWindow *filer_window) +/* Mount/unmount 'item', or all selected mount points if NULL. */ +void action_mount(FilerWindow *filer_window, DirItem *item) { #ifdef DO_MOUNT_POINTS GUIside *gui_side; @@ -890,13 +915,14 @@ void action_mount(FilerWindow *filer_window) collection = filer_window->collection; - if (collection->number_selected < 1) + if (item == NULL && collection->number_selected < 1) { report_error("ROX-Filer", "You need to select some items " "to mount or unmount"); return; } + mount_item = item; gui_side = start_action(filer_window, mount_cb); if (!gui_side) return; diff --git a/ROX-Filer/src/action.h b/ROX-Filer/src/action.h index cbec7610..7ec22ed1 100644 --- a/ROX-Filer/src/action.h +++ b/ROX-Filer/src/action.h @@ -11,7 +11,7 @@ #include "filer.h" void action_usage(FilerWindow *filer_window); -void action_mount(FilerWindow *filer_window); +void action_mount(FilerWindow *filer_window, DirItem *item); void action_delete(FilerWindow *filer_window); void action_move(GSList *paths, char *dest); void action_copy(GSList *paths, char *dest); diff --git a/ROX-Filer/src/filer.c b/ROX-Filer/src/filer.c index 3bd03b2b..e630bd34 100644 --- a/ROX-Filer/src/filer.c +++ b/ROX-Filer/src/filer.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,7 @@ #include "mount.h" #include "type.h" #include "options.h" +#include "action.h" #define ROW_HEIGHT_LARGE 64 #define ROW_HEIGHT_SMALL 32 @@ -61,6 +63,7 @@ extern gboolean collection_single_click; FilerWindow *window_with_focus = NULL; GdkFont *fixed_font = NULL; +GList *all_filer_windows = NULL; static FilerWindow *window_with_selection = NULL; @@ -148,6 +151,7 @@ static void update_display(Directory *dir, FilerWindow *filer_window); void filer_change_to(FilerWindow *filer_window, char *path); static void shrink_width(FilerWindow *filer_window); +static gboolean may_rescan(FilerWindow *filer_window, gboolean warning); static GdkAtom xa_string; enum @@ -268,6 +272,8 @@ static void detach(FilerWindow *filer_window) static void filer_window_destroyed(GtkWidget *widget, FilerWindow *filer_window) { + all_filer_windows = g_list_remove(all_filer_windows, filer_window); + if (window_with_selection == filer_window) window_with_selection = NULL; if (window_with_focus == filer_window) @@ -681,7 +687,7 @@ void show_menu(Collection *collection, GdkEventButton *event, } /* Returns TRUE iff the directory still exits. */ -static gboolean may_rescan(FilerWindow *filer_window) +static gboolean may_rescan(FilerWindow *filer_window, gboolean warning) { Directory *dir; @@ -693,7 +699,8 @@ static gboolean may_rescan(FilerWindow *filer_window) dir = g_fscache_lookup(dir_cache, filer_window->path); if (!dir) { - delayed_error("ROX-Filer", "Directory missing/deleted"); + if (warning) + delayed_error("ROX-Filer", "Directory missing/deleted"); gtk_widget_destroy(filer_window->window); return FALSE; } @@ -892,17 +899,12 @@ void open_item(Collection *collection, FilerWindow *filer_window = (FilerWindow *) user_data; DirItem *item = (DirItem *) item_data; GdkEventButton *event; - char *full_path; - GtkWidget *widget; gboolean shift; gboolean adjust; /* do alternative action */ - event = (GdkEventButton *) gtk_get_current_event(); - full_path = make_path(filer_window->path, - item->leafname)->str; - collection_wink_item(filer_window->collection, item_number); + event = (GdkEventButton *) gtk_get_current_event(); if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) { @@ -917,7 +919,18 @@ void open_item(Collection *collection, adjust = FALSE; } + filer_openitem(filer_window, item, shift, adjust); +} + +void filer_openitem(FilerWindow *filer_window, DirItem *item, + gboolean shift, gboolean adjust) +{ + GtkWidget *widget; + char *full_path; + widget = filer_window->window; + full_path = make_path(filer_window->path, + item->leafname)->str; switch (item->base_type) { @@ -930,6 +943,14 @@ void open_item(Collection *collection, gtk_widget_destroy(widget); break; } + + if (item->flags & ITEM_FLAG_MOUNT_POINT && shift) + { + action_mount(filer_window, item); + if (item->flags & ITEM_FLAG_MOUNTED) + break; + } + if ((adjust ^ o_ro_bindings) || filer_window->panel) filer_opendir(full_path, FALSE, BOTTOM); else @@ -989,7 +1010,7 @@ static gint pointer_in(GtkWidget *widget, GdkEventCrossing *event, FilerWindow *filer_window) { - may_rescan(filer_window); + may_rescan(filer_window, TRUE); return FALSE; } @@ -1347,6 +1368,8 @@ void filer_opendir(char *path, gboolean panel, Side panel_side) number_of_windows++; gtk_widget_show_all(filer_window->window); attach(filer_window); + + all_filer_windows = g_list_prepend(all_filer_windows, filer_window); } static GtkWidget *create_toolbar(FilerWindow *filer_window) @@ -1470,7 +1493,7 @@ static char *filer_toolbar(char *data) /* Note that filer_window may not exist after this call. */ void update_dir(FilerWindow *filer_window) { - if (may_rescan(filer_window)) + if (may_rescan(filer_window, TRUE)) dir_update(filer_window->directory, filer_window->path); } @@ -1494,3 +1517,27 @@ void full_refresh(void) { mount_update(TRUE); } + +/* This path has been mounted/umounted - update all dirs */ +void filer_check_mounted(char *path) +{ + GList *next = all_filer_windows; + int len; + + len = strlen(path); + + while (next) + { + FilerWindow *filer_window = (FilerWindow *) next->data; + + next = next->next; + + if (strncmp(path, filer_window->path, len) == 0) + { + char s = filer_window->path[len]; + + if (s == '/' || s == '\0') + may_rescan(filer_window, FALSE); + } + } +} diff --git a/ROX-Filer/src/filer.h b/ROX-Filer/src/filer.h index dfdfb44e..e3fc9723 100644 --- a/ROX-Filer/src/filer.h +++ b/ROX-Filer/src/filer.h @@ -67,5 +67,8 @@ int sort_by_size(const void *item1, const void *item2); void filer_set_sort_fn(FilerWindow *filer_window, int (*fn)(const void *a, const void *b)); void full_refresh(void); +void filer_openitem(FilerWindow *filer_window, DirItem *item, + gboolean shift, gboolean adjust); +void filer_check_mounted(char *path); #endif /* _FILER_H */ diff --git a/ROX-Filer/src/menu.c b/ROX-Filer/src/menu.c index 394a0b9b..ddebce35 100644 --- a/ROX-Filer/src/menu.c +++ b/ROX-Filer/src/menu.c @@ -146,7 +146,7 @@ static GtkItemFactoryEntry filer_menu_def[] = { {"/File/Copy...", NULL, copy_item, 0, NULL}, {"/File/Rename...", NULL, rename_item, 0, NULL}, {"/File/Link...", NULL, link_item, 0, NULL}, -{"/File/Open", "O", open_file, 0, NULL}, +{"/File/Shift Open", NULL, open_file, 0, NULL}, {"/File/Help", "F1", help, 0, NULL}, {"/File/Info", "I", show_file_info, 0, NULL}, {"/File/Separator", NULL, NULL, 0, ""}, @@ -159,13 +159,13 @@ static GtkItemFactoryEntry filer_menu_def[] = { {"/Select All", C_"A", select_all, 0, NULL}, {"/Clear Selection", C_"Z", clear_selection, 0, NULL}, {"/Options...", NULL, show_options, 0, NULL}, -{"/New directory", NULL, new_directory, 0, NULL}, -{"/Xterm here", NULL, xterm_here, 0, NULL}, +{"/New Directory...", NULL, new_directory, 0, NULL}, +{"/Xterm Here", NULL, xterm_here, 0, NULL}, {"/Window", NULL, NULL, 0, ""}, -{"/Window/Parent, new window", NULL, open_parent, 0, NULL}, -{"/Window/Parent, same window", NULL, open_parent_same, 0, NULL}, -{"/Window/New window", NULL, new_window, 0, NULL}, -{"/Window/Close window", C_"Q", close_window, 0, NULL}, +{"/Window/Parent, New Window", NULL, open_parent, 0, NULL}, +{"/Window/Parent, Same Window", NULL, open_parent_same, 0, NULL}, +{"/Window/New Window", NULL, new_window, 0, NULL}, +{"/Window/Close Window", C_"Q", close_window, 0, NULL}, {"/Window/Separator", NULL, NULL, 0, ""}, {"/Window/Show ROX-Filer help", NULL, rox_help, 0, NULL}, }; @@ -540,7 +540,7 @@ static void mount(gpointer data, guint action, GtkWidget *widget) { g_return_if_fail(window_with_focus != NULL); - action_mount(window_with_focus); + action_mount(window_with_focus, NULL); } static void delete(gpointer data, guint action, GtkWidget *widget) @@ -693,21 +693,8 @@ static void open_file(gpointer data, guint action, GtkWidget *widget) report_error("ROX-Filer", "You must select a single " "file or application to open"); else - { - DirItem *item = selected_item(collection); - char *path; - - path = make_path(window_with_focus->path, item->leafname)->str; - - if (item->base_type == TYPE_APPDIR || - item->base_type == TYPE_DIRECTORY) - filer_opendir(path, FALSE, BOTTOM); - else - if (!type_open(path, &text_plain)) - delayed_error("ROX-Filer", - "You haven't specified any action " - "for text/plain files."); - } + filer_openitem(window_with_focus, selected_item(collection), + TRUE, FALSE); } static void show_file_info(gpointer data, guint action, GtkWidget *widget) diff --git a/ROX-Filer/src/run.c b/ROX-Filer/src/run.c index f0493ac8..25198af8 100644 --- a/ROX-Filer/src/run.c +++ b/ROX-Filer/src/run.c @@ -43,3 +43,4 @@ void run_app(char *path) g_string_free(apprun, TRUE); } + -- 2.11.4.GIT