From 5d405a16449bfef786bc1451f9c0b75999322d3f Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 14 May 2000 20:00:05 +0000 Subject: [PATCH] r277: Started adding support for setting run actions. Dialog box displays the current action but you can't change it yet. --- ROX-Filer/Help/Changes | 9 +++ ROX-Filer/Help/README | 3 +- ROX-Filer/Help/TODO | 19 ++++++- ROX-Filer/pixmaps/drop.xpm | 60 ++++++++++++++++++++ ROX-Filer/src/menu.c | 28 ++++++++++ ROX-Filer/src/type.c | 134 ++++++++++++++++++++++++++++++++++++++++++++- ROX-Filer/src/type.h | 1 + 7 files changed, 251 insertions(+), 3 deletions(-) create mode 100644 ROX-Filer/pixmaps/drop.xpm diff --git a/ROX-Filer/Help/Changes b/ROX-Filer/Help/Changes index fd599806..9529773f 100644 --- a/ROX-Filer/Help/Changes +++ b/ROX-Filer/Help/Changes @@ -2,6 +2,15 @@ A RISC OS-like filer for X by Thomas Leonard + +12-May-2000 +~~~~~~~~~~~ +Applied Bernard's patch (a couple of cosmetic changes to the action windows). +Applied Vincent's patch (minor updates to the Frech translation). +Fixed a problem with the pixmap caching - the filer would detect that the +file had changed and try to reload it, but ImLib would simply return its +cached copy! + 28-Apr-2000 ~~~~~~~~~~~ Removed a debugging message that had somehow got into the release version :-( diff --git a/ROX-Filer/Help/README b/ROX-Filer/Help/README index ecaaf204..0f2b9505 100644 --- a/ROX-Filer/Help/README +++ b/ROX-Filer/Help/README @@ -52,10 +52,11 @@ First, a few people/projects whose work I've used: John Lindal co-author of the XDS protocol Midnight Commander the Virtual File System library -And now, people who've actually sent in code ;-) +And now, people who've actually written bits of it ;-) Jens Askengren GNOME-style toolbar Bernard Jungen lots of patches all over the place! + Vincent Lefevre French translation Christiansen Merel initial support for ImLib Chris Sawer leafname field in the Info box Simon Truss support for mount points on NetBSD diff --git a/ROX-Filer/Help/TODO b/ROX-Filer/Help/TODO index 229a332b..e43dd95a 100644 --- a/ROX-Filer/Help/TODO +++ b/ROX-Filer/Help/TODO @@ -10,7 +10,9 @@ BUGS Rename box - use action window (currently doesn't work across file systems) -GNOME toolbar doesn't work properly when detached. Is this a GTK+ problem? +GNOME toolbar + - doesn't work properly when detached. Is this a GTK+ problem? + - 'Other Action' doesn't work MISSING FEATURES @@ -31,6 +33,21 @@ Use an environment variable to override the platform-name guessing in AppRun. People sometimes forget to save the key bindings - remind them somehow? +Enable (temporarily) single-click navigation when a special key (e.g. Alt) is +pressed? + +'Other Action' should work on either 'other' button. + +Improve MIME-type guessing: + - Try to find longest extension match (eg .ps.gz, then .gz) + - Try again ignoring case (so .BMP matches .bmp) (.C must still work!) + - Use regexp rules on whole name (eg for 'Makefile' and 'core') + +Make the run-actions easier to set up (ie, from a dialog box). + +Provide a way to set the display style on a per-directory basis +(shell glob patterns?) + RISC OS COMPATIBILITY diff --git a/ROX-Filer/pixmaps/drop.xpm b/ROX-Filer/pixmaps/drop.xpm new file mode 100644 index 00000000..bad1d09d --- /dev/null +++ b/ROX-Filer/pixmaps/drop.xpm @@ -0,0 +1,60 @@ +/* XPM */ +static char * drop_xpm[] = { +"34 34 23 1", +" c None", +". c #000000", +"+ c #2A2A2A", +"@ c #404040", +"# c #484848", +"$ c #414141", +"% c #A6A6A6", +"& c #CCCCCC", +"* c #FFFFFF", +"= c #474747", +"- c #CFCFCF", +"; c #7B7B7B", +"> c #E4E4E4", +", c #3B3B3B", +"' c #989898", +") c #C9C9C9", +"! c #FBFBFB", +"~ c #979797", +"{ c #646464", +"] c #656565", +"^ c #B9B9B9", +"/ c #BABABA", +"( c #424242", +" ", +" ", +" .......... ", +" .+@####$+. ", +" .$%&&&&%$. ", +" .#&****&#. ", +" .#&****&#. ", +" .#&****&#. ", +" .#&****&#. ", +" .#&****&#. ", +" .#&****&#. ", +" .#&****&#. ", +" .#&****&#. ", +" .#&****&#. ", +" .#&****&#. ", +" .#&****&#. ", +" .#&****&#. ", +" .=&****&=. ", +" ..........#-****-#.......... ", +" .+$#####=#;>****>;#=#####$+. ", +" .,')&&&&&->!****!>-&&&&&)~,. ", +" .+{-!******************!-{+. ", +" ..+]-!****************!-]+.. ", +" ..+]-!**************!-]+.. ", +" ..+]-!************!-]+.. ", +" ..+]-!**********!-]+.. ", +" ..+]-!********!-]+.. ", +" ..+]-!******!-]+.. ", +" ..+]-!****!-]+.. ", +" ..+]-!**!-]+.. ", +" ..+{^&&/{+.. ", +" ..+(##$+.. ", +" ........ ", +" "}; diff --git a/ROX-Filer/src/menu.c b/ROX-Filer/src/menu.c index 0cc3b349..c59f6a3e 100644 --- a/ROX-Filer/src/menu.c +++ b/ROX-Filer/src/menu.c @@ -90,6 +90,7 @@ static void refresh(gpointer data, guint action, GtkWidget *widget); static void copy_item(gpointer data, guint action, GtkWidget *widget); static void rename_item(gpointer data, guint action, GtkWidget *widget); static void link_item(gpointer data, guint action, GtkWidget *widget); +static void run_action(gpointer data, guint action, GtkWidget *widget); static void open_file(gpointer data, guint action, GtkWidget *widget); static void help(gpointer data, guint action, GtkWidget *widget); static void show_file_info(gpointer data, guint action, GtkWidget *widget); @@ -172,6 +173,7 @@ static GtkItemFactoryEntry filer_menu_def[] = { {">" N_("Copy..."), NULL, copy_item, 0, NULL}, {">" N_("Rename..."), NULL, rename_item, 0, NULL}, {">" N_("Link..."), NULL, link_item, 0, NULL}, +{">" N_("Run Action..."), NULL, run_action, 0, NULL}, {">" N_("Shift Open"), NULL, open_file, 0, NULL}, {">" N_("Help"), NULL, help, 0, NULL}, {">" N_("Info"), NULL, show_file_info, 0, NULL}, @@ -865,6 +867,32 @@ static void link_item(gpointer data, guint action, GtkWidget *widget) SHOW_SAVEBOX(_("Symlink"), link_cb); } +static void run_action(gpointer data, guint action, GtkWidget *widget) +{ + Collection *collection; + + g_return_if_fail(window_with_focus != NULL); + + collection = window_with_focus->collection; + if (collection->number_selected > 1) + { + report_error(PROJECT, _("You cannot do this to more than " + "one item at a time")); + return; + } + else if (collection->number_selected != 1) + collection_target(collection, target_callback, run_action); + else + { + DirItem *item; + + item = selected_item(collection); + g_return_if_fail(item->mime_type != NULL); + + show_set_run_action(item->mime_type); + } +} + static void open_file(gpointer data, guint action, GtkWidget *widget) { Collection *collection; diff --git a/ROX-Filer/src/type.c b/ROX-Filer/src/type.c index 5a749531..a3ddfa08 100644 --- a/ROX-Filer/src/type.c +++ b/ROX-Filer/src/type.c @@ -23,13 +23,15 @@ #include "config.h" -#include #include #include #include #include #include #include +#include + +#include #include "string.h" #include "main.h" @@ -332,3 +334,133 @@ GdkAtom type_to_atom(MIME_type *type) return retval; } +/* Display a box allowing the user to set the run action for this type */ +void show_set_run_action(MIME_type *type) +{ + static GtkWidget *box = NULL; + static GtkWidget *pixmap = NULL, *link_path, *explain_label; + guchar *type_name, *path; + struct stat info; + static MaskedPixmap *drop = NULL; + MaskedPixmap *pic; + guchar *tmp; + + if (!box) + { + GtkWidget *vbox, *event, *hbox, *button, *frame; + GtkWidget *link_box; + GtkTargetEntry targets[] = { + {"text/uri-list", 0, 0}, + }; + + box = gtk_window_new(GTK_WINDOW_DIALOG); + gtk_container_set_border_width(GTK_CONTAINER(box), 4); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(box), vbox); + + explain_label = gtk_label_new(""); + gtk_box_pack_start(GTK_BOX(vbox), explain_label, + FALSE, TRUE, 4); + + frame = gtk_frame_new(NULL); + gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); + event = gtk_event_box_new(); + gtk_container_add(GTK_CONTAINER(frame), event); + gtk_drag_dest_set(event, GTK_DEST_DEFAULT_ALL, targets, + sizeof(targets) / sizeof(*targets), + GDK_ACTION_COPY | GDK_ACTION_PRIVATE); + + tmp = g_strconcat(getenv("APP_DIR"), "/pixmaps/drop.xpm", NULL); + drop = g_fscache_lookup(pixmap_cache, tmp); + g_free(tmp); + + link_box = gtk_vbox_new(FALSE, 4); + gtk_container_add(GTK_CONTAINER(event), link_box); + + pixmap = gtk_pixmap_new(drop->pixmap, drop->mask); + gtk_box_pack_start(GTK_BOX(link_box), pixmap, FALSE, TRUE, 4); + link_path = gtk_label_new(""); + gtk_misc_set_padding(GTK_MISC(link_path), 4, 0); + gtk_box_pack_start(GTK_BOX(link_box), + link_path, FALSE, TRUE, 4); + + hbox = gtk_hbox_new(TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 4); + + button = gtk_button_new_with_label(_("Save")); + gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 4); + button = gtk_button_new_with_label(_("Cancel")); + gtk_signal_connect_object(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(gtk_widget_hide), GTK_OBJECT(box)); + gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 4); + } + + if (GTK_WIDGET_VISIBLE(box)) + gtk_widget_hide(box); + + type_name = g_strconcat(type->media_type, "/", type->subtype, NULL); + gtk_window_set_title(GTK_WINDOW(box), type_name); + tmp = g_strdup_printf( + _("Default run action for files of type '%s':"), + type_name); + gtk_label_set_text(GTK_LABEL(explain_label), tmp); + g_free(tmp); + g_free(type_name); + + type_name = g_strconcat(type->media_type, "_", type->subtype, NULL); + path = choices_find_path_load(type_name, "MIME-types"); + if (!path) + path = choices_find_path_load(type->media_type, "MIME-types"); + + pic = NULL; + if (path && stat(path, &info) == 0) + { + if (S_ISDIR(info.st_mode)) + { + tmp = g_strconcat(path, "/AppIcon.xpm", NULL); + pic = g_fscache_lookup(pixmap_cache, tmp); + g_free(tmp); + if (!pic) + { + pic = default_pixmap[TYPE_APPDIR]; + pixmap_ref(pic); + } + } + else + { + pic = default_pixmap[TYPE_EXEC_FILE]; + pixmap_ref(pic); + } + } + + if (!pic) + { + pic = drop; + gtk_label_set_text(GTK_LABEL(link_path), + _("No run action set")); + } + else + { + char buffer[MAXPATHLEN + 1]; + int got; + + got = readlink(path, buffer, sizeof(buffer) - 1); + if (got > 0) + { + buffer[got] = '\0'; + gtk_label_set_text(GTK_LABEL(link_path), buffer); + } + else + gtk_label_set_text(GTK_LABEL(link_path), path); + } + + gtk_pixmap_set(GTK_PIXMAP(pixmap), pic->pixmap, pic->mask); + if (pic != drop) + g_fscache_data_unref(pixmap_cache, pic); + + g_free(path); + + gtk_widget_show_all(box); +} diff --git a/ROX-Filer/src/type.h b/ROX-Filer/src/type.h index e502e0e2..b90ed0a9 100644 --- a/ROX-Filer/src/type.h +++ b/ROX-Filer/src/type.h @@ -30,5 +30,6 @@ MIME_type *type_from_path(char *path); gboolean type_open(char *path, MIME_type *type); MaskedPixmap *type_to_icon(MIME_type *type); GdkAtom type_to_atom(MIME_type *type); +void show_set_run_action(MIME_type *type); #endif /* _TYPE_H */ -- 2.11.4.GIT