From 23bb34582bb5937e3436841b1ae43416ac08d1c9 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 16 May 2000 10:21:05 +0000 Subject: [PATCH] r280: All objects now have MIME types. This allows you to specify the action for special/directory for example. The cursor is a bit nicer and usually appears where you want it to now. You can also get rid of it by pressing Escape. --- ROX-Filer/Help/Changes | 9 +++++++++ ROX-Filer/src/collection.c | 20 +++++++++++++++++--- ROX-Filer/src/collection.h | 5 +++-- ROX-Filer/src/dir.c | 3 +++ ROX-Filer/src/dnd.c | 2 +- ROX-Filer/src/filer.c | 4 +++- ROX-Filer/src/menu.c | 17 ++++++++++------- ROX-Filer/src/minibuffer.c | 3 ++- ROX-Filer/src/type.c | 44 ++++++++++++++++++++++++++++++++++++++++---- ROX-Filer/src/type.h | 1 + 10 files changed, 89 insertions(+), 19 deletions(-) diff --git a/ROX-Filer/Help/Changes b/ROX-Filer/Help/Changes index 9529773f..220ab9bf 100644 --- a/ROX-Filer/Help/Changes +++ b/ROX-Filer/Help/Changes @@ -3,6 +3,15 @@ by Thomas Leonard +16-May-2000 +~~~~~~~~~~~ +Added the `Window->Set Run Action' menu item. This allows you to specify the +default run action for a file by simply dragging the file into a program. +You can also enter a shell command in the minibuffer to make that command +the default. +The cursor is a bit nicer and usually appears where you want it to now. You +can also get rid of it by pressing Escape. + 12-May-2000 ~~~~~~~~~~~ Applied Bernard's patch (a couple of cosmetic changes to the action windows). diff --git a/ROX-Filer/src/collection.c b/ROX-Filer/src/collection.c index c0fb660c..607bd99b 100644 --- a/ROX-Filer/src/collection.c +++ b/ROX-Filer/src/collection.c @@ -333,6 +333,7 @@ static void collection_init(Collection *object) object->items = g_malloc(sizeof(CollectionItem) * MINIMUM_ITEMS); object->cursor_item = -1; + object->cursor_item_old = -1; object->wink_item = -1; object->array_size = MINIMUM_ITEMS; object->draw_item = default_draw_item; @@ -986,7 +987,10 @@ static gint collection_key_press(GtkWidget *widget, GdkEventKey *event) break; case GDK_Escape: if (!collection->target_cb) + { + collection_set_cursor_item(collection, -1); return FALSE; /* Pass it on */ + } collection_target(collection, NULL, NULL); break; case ' ': @@ -1653,6 +1657,7 @@ void collection_clear(Collection *collection) collection_set_cursor_item(collection, collection->cursor_item == -1 ? -1: 0); + collection->cursor_item_old = -1; prev_selected = collection->number_selected; collection->number_of_items = collection->number_selected = 0; @@ -2053,6 +2058,8 @@ void collection_set_cursor_item(Collection *collection, gint item) collection_draw_item(collection, item, TRUE); scroll_to_show(collection, item); } + else if (old_item != -1) + collection->cursor_item_old = old_item; } /* Briefly highlight an item to draw the user's attention to it. @@ -2071,7 +2078,7 @@ void collection_wink_item(Collection *collection, gint item) if (item == -1) return; - collection->wink_item = item; + collection->cursor_item_old = collection->wink_item = item; collection->wink_timeout = gtk_timeout_add(300, (GtkFunction) cancel_wink_timeout, collection); @@ -2167,7 +2174,9 @@ void collection_target(Collection *collection, FALSE); } -/* Move the cursor by the given row and column offsets. */ +/* Move the cursor by the given row and column offsets. + * Moving by (0,0) can be used to simply make the cursor appear. + */ void collection_move_cursor(Collection *collection, int drow, int dcol) { int row, col, item; @@ -2181,6 +2190,12 @@ void collection_move_cursor(Collection *collection, int drow, int dcol) item = collection->cursor_item; if (item == -1) { + item = MIN(collection->cursor_item_old, + collection->number_of_items - 1); + } + + if (item == -1) + { col = 0; row = first; } @@ -2218,4 +2233,3 @@ void collection_move_cursor(Collection *collection, int drow, int dcol) if (item >= 0 && item < collection->number_of_items) collection_set_cursor_item(collection, item); } - diff --git a/ROX-Filer/src/collection.h b/ROX-Filer/src/collection.h index ff5d903c..c2b7bf1f 100644 --- a/ROX-Filer/src/collection.h +++ b/ROX-Filer/src/collection.h @@ -76,8 +76,9 @@ struct _Collection gboolean may_drag; /* Tried to drag since first press? */ CollectionItem *items; - gint cursor_item; /* -1 if not shown */ - gint wink_item; /* -1 if not active */ + gint cursor_item; /* -1 if not shown */ + gint cursor_item_old; /* May be -1 */ + gint wink_item; /* -1 if not active */ gint wink_timeout; guint columns; gint number_of_items; /* (often compared with -1) */ diff --git a/ROX-Filer/src/dir.c b/ROX-Filer/src/dir.c index 2ed585db..dfddb021 100644 --- a/ROX-Filer/src/dir.c +++ b/ROX-Filer/src/dir.c @@ -457,6 +457,9 @@ static void insert_item(Directory *dir, struct dirent *ent) else new.image = default_pixmap[new.base_type]; + if (!new.mime_type) + new.mime_type = mime_type_from_base_type(new.base_type); + for (i = 0; i < array->len; i++) { item = (DirItem *) array->pdata[i]; diff --git a/ROX-Filer/src/dnd.c b/ROX-Filer/src/dnd.c index 5ef189dc..6fc32050 100644 --- a/ROX-Filer/src/dnd.c +++ b/ROX-Filer/src/dnd.c @@ -380,7 +380,7 @@ void drag_selection(Collection *collection, target_list = gtk_target_list_new(target_table, 1); } - else if (item && item->mime_type) + else if (item && item->base_type == TYPE_FILE) { MIME_type *t = item->mime_type; diff --git a/ROX-Filer/src/filer.c b/ROX-Filer/src/filer.c index 12e2ae57..47a02cf3 100644 --- a/ROX-Filer/src/filer.c +++ b/ROX-Filer/src/filer.c @@ -1165,7 +1165,9 @@ void filer_openitem(FilerWindow *filer_window, int item_number, OpenFlags flags) { message = g_string_new(NULL); g_string_sprintf(message, - _("No open action specified for files of this type (%s/%s)"), + _("No run action specified for files of this type (%s/%s) - " + "you can set a run action using by choosing `Set Run Action' " + "from the Window menu"), type->media_type, type->subtype); report_error(PROJECT, message->str); diff --git a/ROX-Filer/src/menu.c b/ROX-Filer/src/menu.c index 2a3fca11..24333f1b 100644 --- a/ROX-Filer/src/menu.c +++ b/ROX-Filer/src/menu.c @@ -937,13 +937,6 @@ static void file_info_destroyed(GtkWidget *widget, FileStatus *fs) /* g_free() the result */ guchar *pretty_type(DirItem *file, guchar *path) { - if (file->mime_type) - return g_strconcat(file->mime_type->media_type, "/", - file->mime_type->subtype, NULL); - - if (file->flags & ITEM_FLAG_APPDIR) - return g_strdup(_("ROX application")); - if (file->flags & ITEM_FLAG_SYMLINK) { char p[MAXPATHLEN + 1]; @@ -958,6 +951,12 @@ guchar *pretty_type(DirItem *file, guchar *path) return g_strdup(_("Symbolic link")); } + if (file->flags & ITEM_FLAG_EXEC_FILE) + return g_strdup(_("Executable file")); + + if (file->flags & ITEM_FLAG_APPDIR) + return g_strdup(_("ROX application")); + if (file->flags & ITEM_FLAG_MOUNT_POINT) { MountPoint *mp; @@ -969,6 +968,10 @@ guchar *pretty_type(DirItem *file, guchar *path) return g_strdup(_("Mount point")); } + if (file->mime_type) + return g_strconcat(file->mime_type->media_type, "/", + file->mime_type->subtype, NULL); + return g_strdup("-"); } diff --git a/ROX-Filer/src/minibuffer.c b/ROX-Filer/src/minibuffer.c index f4dd95a2..7ff5ec07 100644 --- a/ROX-Filer/src/minibuffer.c +++ b/ROX-Filer/src/minibuffer.c @@ -98,10 +98,11 @@ void minibuffer_show(FilerWindow *filer_window, MiniType mini_type) mini_type == MINI_RUN_ACTION ? "Run Action:" : "?"); + collection = filer_window->collection; + collection_move_cursor(collection, 0, 0); /* Turn the cursor on */ switch (mini_type) { case MINI_PATH: - collection = filer_window->collection; filer_window->mini_cursor_base = MAX(collection->cursor_item, 0); gtk_entry_set_text(mini, diff --git a/ROX-Filer/src/type.c b/ROX-Filer/src/type.c index 014c6ad1..00c13349 100644 --- a/ROX-Filer/src/type.c +++ b/ROX-Filer/src/type.c @@ -53,7 +53,14 @@ static GHashTable *extension_hash = NULL; static char *current_type = NULL; /* (used while reading file) */ /* Most things on Unix are text files, so this is the default type */ -MIME_type text_plain = {"text", "plain", NULL}; +MIME_type text_plain = {"text", "plain", NULL}; + +MIME_type special_directory = {"special", "directory", NULL}; +MIME_type special_pipe = {"special", "pipe", NULL}; +MIME_type special_socket = {"special", "socket", NULL}; +MIME_type special_block_dev = {"special", "block-device", NULL}; +MIME_type special_char_dev = {"special", "char-device", NULL}; +MIME_type special_unknown = {"special", "unknown", NULL}; void type_init() { @@ -341,8 +348,9 @@ GdkAtom type_to_atom(MIME_type *type) */ char *type_ask_which_action(guchar *media_type, guchar *subtype) { - int r; - guchar *tmp, *type_name, *path; + int r; + guchar *tmp, *type_name, *path; + struct stat info; g_return_val_if_fail(media_type != NULL, NULL); g_return_val_if_fail(subtype != NULL, NULL); @@ -374,8 +382,18 @@ char *type_ask_which_action(guchar *media_type, guchar *subtype) else return NULL; - if (access(path, F_OK) == 0) + if (lstat(path, &info) == 0) { + /* A binding already exists... */ + if (S_ISREG(info.st_mode) && info.st_size > 256) + { + if (get_choice(PROJECT, + _("A run action already exists and is quite " + "a big program - are you sure you want to " + "delete it?"), 2, "Delete", "Cancel") != 0) + return NULL; + } + if (unlink(path)) { tmp = g_strdup_printf( _("Can't remove %s: %s"), @@ -388,3 +406,21 @@ char *type_ask_which_action(guchar *media_type, guchar *subtype) return path; } + +MIME_type *mime_type_from_base_type(int base_type) +{ + switch (base_type) + { + case TYPE_DIRECTORY: + return &special_directory; + case TYPE_PIPE: + return &special_pipe; + case TYPE_SOCKET: + return &special_socket; + case TYPE_BLOCK_DEVICE: + return &special_block_dev; + case TYPE_CHAR_DEVICE: + return &special_char_dev; + } + return &special_unknown; +} diff --git a/ROX-Filer/src/type.h b/ROX-Filer/src/type.h index 64570d4f..af880f8d 100644 --- a/ROX-Filer/src/type.h +++ b/ROX-Filer/src/type.h @@ -31,5 +31,6 @@ gboolean type_open(char *path, MIME_type *type); MaskedPixmap *type_to_icon(MIME_type *type); GdkAtom type_to_atom(MIME_type *type); char *type_ask_which_action(guchar *media_type, guchar *subtype); +MIME_type *mime_type_from_base_type(int base_type); #endif /* _TYPE_H */ -- 2.11.4.GIT