From 8bfd9cdac2e6f09eeb140a00d6ceeb2881159f34 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Fri, 9 Nov 2001 17:22:37 +0000 Subject: [PATCH] r913: Allow current directory and selection to be stored with Ctrl+[0-9] and retrieved by pressing [0-9] (suggested by Jakub Turski). The groups are not saved yet. --- ROX-Filer/Help/Changes | 6 +++ ROX-Filer/Help/TODO | 2 + ROX-Filer/src/filer.c | 104 +++++++++++++++++++++++++++++++++++++++++++++- ROX-Filer/src/support.c | 23 ++++++++++ ROX-Filer/src/support.h | 1 + ROX-Filer/src/usericons.c | 35 ++++------------ 6 files changed, 144 insertions(+), 27 deletions(-) diff --git a/ROX-Filer/Help/Changes b/ROX-Filer/Help/Changes index d08d4ca8..275cf423 100644 --- a/ROX-Filer/Help/Changes +++ b/ROX-Filer/Help/Changes @@ -2,6 +2,12 @@ A RISC OS-like filer for X by Thomas Leonard +09-Nov-2001 +~~~~~~~~~~~ +Allow current directory and selection to be stored with Ctrl+[0-9] and +retrieved by pressing [0-9] (suggested by Jakub Turski). The groups are not +saved yet. + 08-Nov-2001 ~~~~~~~~~~~ Don't use re_set_syntax() on systems that don't have it (reported by diff --git a/ROX-Filer/Help/TODO b/ROX-Filer/Help/TODO index d29edf8f..58226e32 100644 --- a/ROX-Filer/Help/TODO +++ b/ROX-Filer/Help/TODO @@ -7,6 +7,8 @@ when someone sends patches!). BUGS +Remove icon should work with MIME stuff. + Show Hidden flashes the last winked item. Think about XXXs in dnd menu. diff --git a/ROX-Filer/src/filer.c b/ROX-Filer/src/filer.c index 88cad568..b3f441a9 100644 --- a/ROX-Filer/src/filer.c +++ b/ROX-Filer/src/filer.c @@ -60,9 +60,19 @@ #define PANEL_BORDER 2 +struct _Group { + char *dir; + GList *files; /* List of leafnames */ +}; + +typedef struct _Group Group; + FilerWindow *window_with_focus = NULL; GList *all_filer_windows = NULL; +#define N_GROUPS 10 +static Group groups[N_GROUPS]; + static FilerWindow *window_with_selection = NULL; /* Item we are about to display a tooltip for */ @@ -105,6 +115,7 @@ static void filer_tooltip_prime(FilerWindow *filer_window, DirItem *item); static void show_tooltip(guchar *text); static void filer_size_for(FilerWindow *filer_window, int w, int h, int n, gboolean allow_shrink); +static void group_free(int i); static void set_unique(guchar *unique); @@ -123,6 +134,7 @@ void filer_init(void) gchar *ohost; gchar *dpyhost, *dpy; gchar *tmp; + int i; option_add_int("filer_size_limit", 75, NULL); option_add_int("filer_auto_resize", RESIZE_ALWAYS, NULL); @@ -155,6 +167,10 @@ void filer_init(void) } g_free(dpyhost); + + /* Just in case... */ + for (i = 0; i < N_GROUPS; i++) + group_free(i); } static void set_unique(guchar *unique) @@ -845,6 +861,85 @@ static void return_pressed(FilerWindow *filer_window, GdkEventKey *event) filer_openitem(filer_window, item, flags); } +static void group_free(int i) +{ + g_free(groups[i].dir); + + g_list_foreach(groups[i].files, (GFunc) g_free, NULL); + + g_list_free(groups[i].files); + + groups[i].dir = NULL; + groups[i].files = NULL; +} + +static void group_save(FilerWindow *filer_window, int i) +{ + Collection *collection = filer_window->collection; + int j; + + group_free(i); + + groups[i].dir = g_strdup(filer_window->path); + + for (j = 0; j < collection->number_of_items; j++) + { + DirItem *item = (DirItem *) collection->items[j].data; + + if (collection->items[j].selected) + groups[i].files = g_list_prepend(groups[i].files, + g_strdup(item->leafname)); + } +} + +static void group_restore(FilerWindow *filer_window, int i) +{ + GHashTable *in_group; + GList *next; + Collection *collection = filer_window->collection; + int j, n; + + if (!groups[i].dir) + { + report_rox_error(_("Group %d is not set. Select some files " + "and press Ctrl+%d to set the group. Press %d " + "on its own to reselect the files later."), + i, i, i); + return; + } + + if (strcmp(groups[i].dir, filer_window->path) != 0) + { + filer_change_to(filer_window, groups[i].dir, NULL); + /* XXX: Need to wait until scanning is done! */ + } + + /* If an item at the start is selected then we could lose the + * primary selection after checking that item and then need to + * gain it again at the end. Therefore, if anything is selected + * then select the last item until the end of the search. + */ + n = collection->number_of_items; + if (collection->number_selected) + collection_select_item(collection, n - 1); + + in_group = g_hash_table_new(g_str_hash, g_str_equal); + for (next = groups[i].files; next; next = next->next) + g_hash_table_insert(in_group, next->data, filer_window); + + for (j = 0; j < n; j++) + { + DirItem *item = (DirItem *) collection->items[j].data; + + if (g_hash_table_lookup(in_group, item->leafname)) + collection_select_item(collection, j); + else + collection_unselect_item(collection, j); + } + + g_hash_table_destroy(in_group); +} + /* Handle keys that can't be bound with the menu */ static gint key_press_event(GtkWidget *widget, GdkEventKey *event, @@ -873,7 +968,14 @@ static gint key_press_event(GtkWidget *widget, filer_window->collection->cursor_item); break; default: - return FALSE; + if (event->keyval < GDK_0 || event->keyval > GDK_9) + return FALSE; + + if (event->state & GDK_CONTROL_MASK) + group_save(filer_window, event->keyval - GDK_0); + else + group_restore(filer_window, + event->keyval - GDK_0); } #ifndef GTK2 diff --git a/ROX-Filer/src/support.c b/ROX-Filer/src/support.c index 3d77d737..f21c2fcd 100644 --- a/ROX-Filer/src/support.c +++ b/ROX-Filer/src/support.c @@ -837,3 +837,26 @@ void set_to_null(gpointer *data) { *data = NULL; } + +/* Save doc as XML as filename, 0 on success or -1 on failure */ +int save_xml_file(xmlDocPtr doc, gchar *filename) +{ +#if LIBXML_VERSION > 20400 + if (xmlSaveFormatFileEnc(filename, doc, NULL, 1) < 0) + return 1; +#else + FILE *out; + + out = fopen(filename, "w"); + if (!out) + return 1; + + xmlDocDump(out, doc); /* Some versions return void */ + + if (fclose(out)) + return 1; +#endif + + return 0; +} + diff --git a/ROX-Filer/src/support.h b/ROX-Filer/src/support.h index f1bfb7c2..702cd2d2 100644 --- a/ROX-Filer/src/support.h +++ b/ROX-Filer/src/support.h @@ -39,5 +39,6 @@ guchar *get_relative_path(guchar *from, guchar *to); void add_default_styles(void); xmlNode *get_subnode(xmlNode *node, char *namespaceURI, char *name); void set_to_null(gpointer *data); +int save_xml_file(xmlDocPtr doc, gchar *filename); #endif /* _SUPPORT_H */ diff --git a/ROX-Filer/src/usericons.c b/ROX-Filer/src/usericons.c index 0fcf1a64..3433cd7a 100644 --- a/ROX-Filer/src/usericons.c +++ b/ROX-Filer/src/usericons.c @@ -244,6 +244,7 @@ void icon_set_handler_dialog(DirItem *item, guchar *path) gtk_object_set_data(GTK_OBJECT(dialog), "mime_type", item->mime_type); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio[0]), TRUE); frame = gtk_frame_new(NULL); gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 4); @@ -366,8 +367,7 @@ static void write_globicon(gpointer key, gpointer value, gpointer data) /* Write globicons file */ static void write_globicons(void) { - gchar *save = NULL; - gchar *save_new = NULL; + gchar *save = NULL, *save_new = NULL; xmlDocPtr doc = NULL; save = choices_find_path_save("globicons", PROJECT, TRUE); @@ -384,32 +384,15 @@ static void write_globicons(void) g_hash_table_foreach(glob_icons, write_globicon, xmlDocGetRootElement(doc)); -#if LIBXML_VERSION > 20400 - if (xmlSaveFormatFileEnc(save_new, doc, NULL, 1) < 0) - goto err; -#else - { - FILE *out; - - out = fopen(save_new, "w"); - if (!out) - goto err; - xmlDocDump(out, doc); /* Some versions return void */ - if (fclose(out)) - goto err; - } -#endif - - if (rename(save_new, save)) - goto err; - goto out; - err: - delayed_rox_error(_("Error saving globicons: %s"), g_strerror(errno)); - out: - if (doc) - xmlFreeDoc(doc); + if (save_xml_file(doc, save_new) || rename(save_new, save)) + delayed_rox_error(_("Error saving %s: %s"), + save, g_strerror(errno)); + g_free(save_new); g_free(save); + + if (doc) + xmlFreeDoc(doc); } /* Process a globicon line. Format: -- 2.11.4.GIT