From 4ad7932a0874e5b0cd573838a9a6f06ba5e49738 Mon Sep 17 00:00:00 2001 From: Stephen Watson Date: Sat, 2 Aug 2003 13:01:55 +0000 Subject: [PATCH] r2932: Eject, Format and Free added to menu for mount points, only Eject implemented --- ROX-Filer/src/action.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ ROX-Filer/src/action.h | 1 + ROX-Filer/src/menu.c | 45 ++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) diff --git a/ROX-Filer/src/action.c b/ROX-Filer/src/action.c index 724ec6fd..0b62882f 100644 --- a/ROX-Filer/src/action.c +++ b/ROX-Filer/src/action.c @@ -904,6 +904,37 @@ static void do_delete(const char *src_path, const char *unused) g_free(safe_path); } +static void do_eject(const char *path) +{ + const char *argv[3] = {NULL, NULL, NULL}; + char *err; + + check_flags(); + + if (!quiet) + { + printf_send("<%s", path); + printf_send(">"); + if (!printf_reply(from_parent, !o_force, + _("?Eject '%s'?"), + path)) + return; + } + else if (!o_brief) + printf_send(_("'Eject '%s'\n"), path); + + argv[0]="eject"; + argv[1]=path; + argv[2]=NULL; + err=fork_exec_wait(argv); + if (err) + { + printf_send(_("!%s\neject failed\n"), err); + g_free(err); + } + +} + /* path is the item to check. If is is a directory then we may recurse * (unless prune is used). */ @@ -1566,6 +1597,22 @@ static void delete_cb(gpointer data) send_done(); } +static void eject_cb(gpointer data) +{ + GList *paths = (GList *) data; + + for (; paths; paths = paths->next) + { + guchar *path = (guchar *) paths->data; + + send_dir(path); + + do_eject(path); + } + + send_done(); +} + static void find_cb(gpointer data) { GList *all_paths = (GList *) data; @@ -1926,6 +1973,25 @@ void action_link(GList *paths, const char *dest, const char *leaf) gtk_widget_show(abox); } +/* Eject these paths */ +void action_eject(GList *paths) +{ + GUIside *gui_side; + GtkWidget *abox; + + abox = abox_new(_("Eject"), 0); + gui_side = start_action(abox, eject_cb, paths, + o_action_force.int_value, + o_action_brief.int_value, + o_action_recurse.int_value, + o_action_newer.int_value); + if (!gui_side) + return; + + number_of_windows++; + gtk_widget_show(abox); +} + void action_init(void) { option_add_int(&o_action_copy, "action_copy", 1); diff --git a/ROX-Filer/src/action.h b/ROX-Filer/src/action.h index 6c63f7ad..e87ca1c1 100644 --- a/ROX-Filer/src/action.h +++ b/ROX-Filer/src/action.h @@ -18,6 +18,7 @@ void action_find(GList *paths); void action_move(GList *paths, const char *dest, const char *leaf, int quiet); void action_copy(GList *paths, const char *dest, const char *leaf, int quiet); void action_link(GList *paths, const char *dest, const char *leaf); +void action_eject(GList *paths); void show_condition_help(gpointer data); void set_find_string_colour(GtkWidget *widget, const guchar *string); diff --git a/ROX-Filer/src/menu.c b/ROX-Filer/src/menu.c index d9a6181b..18537712 100644 --- a/ROX-Filer/src/menu.c +++ b/ROX-Filer/src/menu.c @@ -76,6 +76,9 @@ typedef enum { FILE_CHMOD_ITEMS, FILE_FIND, FILE_OPEN_VFS_AVFS, + FILE_EJECT, + FILE_FORMAT, + FILE_FREE, } FileOp; typedef enum menu_icon_style { @@ -173,6 +176,9 @@ static GtkWidget *filer_thumb_menu; /* The Show Thumbs item */ static GtkWidget *filer_new_window; /* The New Window item */ static GtkWidget *filer_new_menu; /* The New submenu */ static GtkWidget *filer_follow_sym; /* Follow symbolic links item */ +static GtkWidget *filer_file_eject; /* File => Eject item */ +static GtkWidget *filer_file_format; /* File => Format item */ +static GtkWidget *filer_file_free; /* File => Free item */ #undef N_ #define N_(x) x @@ -220,6 +226,10 @@ static GtkItemFactoryEntry filer_menu_def[] = { {">" N_("Permissions"), NULL, file_op, FILE_CHMOD_ITEMS, NULL}, {">", NULL, NULL, 0, ""}, {">" N_("Find"), NULL, file_op, FILE_FIND, "", GTK_STOCK_FIND}, +{">", NULL, NULL, 0, ""}, +{">" N_("Eject"), NULL, file_op, FILE_EJECT, NULL}, +{">" N_("Format"), NULL, file_op, FILE_FORMAT, NULL}, +{">" N_("Free"), NULL, file_op, FILE_FREE, NULL}, {N_("Select"), NULL, NULL, 0, ""}, {">" N_("Select All"), NULL, select_all, 0, NULL}, {">" N_("Clear Selection"), NULL, clear_selection, 0, NULL}, @@ -310,6 +320,10 @@ gboolean ensure_filer_menu(void) GET_SSMENU_ITEM(item, "filer", "Window", "New Window"); filer_new_window = GTK_BIN(item)->child; + GET_SSMENU_ITEM(filer_file_eject, "filer", "File", "Eject"); + GET_SSMENU_ITEM(filer_file_format, "filer", "File", "Format"); + GET_SSMENU_ITEM(filer_file_free, "filer", "File", "Free"); + g_signal_connect(filer_menu, "unmap_event", G_CALLBACK(menu_closed), NULL); g_signal_connect(filer_file_menu, "unmap_event", @@ -689,6 +703,25 @@ static MenuIconStyle get_menu_icon_style(void) return MIS_SMALL; } +/* Set availability of the mount point specific menu items + (only eject implemented at present) */ +static void set_mount_point_items(gboolean ismp, gboolean ismounted) +{ + gtk_widget_set_sensitive(filer_file_eject, ismp && !ismounted); + gtk_widget_set_sensitive(filer_file_format, ismp && !ismounted); + gtk_widget_set_sensitive(filer_file_free, ismp && ismounted); + + gtk_widget_set_sensitive(filer_file_format, FALSE); + gtk_widget_set_sensitive(filer_file_free, FALSE); +} + +/* Set mount point items based on state of selected item */ +static void set_mount_point(DirItem *item) +{ + set_mount_point_items(item->flags & ITEM_FLAG_MOUNT_POINT, + item->flags & ITEM_FLAG_MOUNTED); +} + /* iter->peek() is the clicked item, or NULL if none */ void show_filer_menu(FilerWindow *filer_window, GdkEvent *event, ViewIter *iter) { @@ -774,6 +807,7 @@ void show_filer_menu(FilerWindow *filer_window, GdkEvent *event, ViewIter *iter) case 0: g_string_assign(buffer, _("Next Click")); shade_file_menu_items(FALSE); + set_mount_point_items(FALSE, FALSE); break; case 1: item = filer_selected_item(filer_window); @@ -791,11 +825,13 @@ void show_filer_menu(FilerWindow *filer_window, GdkEvent *event, ViewIter *iter) if (!can_set_run_action(file_item)) menu_set_items_shaded(filer_file_menu, TRUE, 6, 1); + set_mount_point(file_item); break; default: shade_file_menu_items(TRUE); g_string_printf(buffer, _("%d items"), n_selected); + set_mount_point_items(FALSE, FALSE); break; } gtk_label_set_text(GTK_LABEL(file_label), buffer->str); @@ -1906,6 +1942,15 @@ static void file_op(gpointer data, FileOp action, GtkWidget *unused) case FILE_OPEN_VFS_AVFS: open_vfs_avfs(window_with_focus, item); break; + case FILE_EJECT: + { + GList *items; + + items=filer_selected_items(window_with_focus); + action_eject(items); + destroy_glist(&items); + } + break; default: g_warning("Unknown action!"); return; -- 2.11.4.GIT