r286: Added some truncation code (not finished yet).
[rox-filer/ma.git] / ROX-Filer / src / filer.c
blob43d539f62b295a9ac3ad59a937eae50066419c30
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2000, Thomas Leonard, <tal197@ecs.soton.ac.uk>.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* filer.c - code for handling filer windows */
24 #include "config.h"
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <errno.h>
30 #include <sys/param.h>
31 #include <unistd.h>
32 #include <time.h>
33 #include <ctype.h>
35 #include <gtk/gtk.h>
36 #include <gdk/gdkx.h>
37 #include <gdk/gdkkeysyms.h>
38 #include "collection.h"
40 #include "main.h"
41 #include "support.h"
42 #include "gui_support.h"
43 #include "filer.h"
44 #include "pixmaps.h"
45 #include "menu.h"
46 #include "dnd.h"
47 #include "run.h"
48 #include "mount.h"
49 #include "type.h"
50 #include "options.h"
51 #include "action.h"
52 #include "minibuffer.h"
54 #define ROW_HEIGHT_LARGE 64
55 #define ROW_HEIGHT_SMALL 20
56 #define ROW_HEIGHT_FULL_INFO 44
57 #define SMALL_ICON_HEIGHT 20
58 #ifdef HAVE_IMLIB
59 # define SMALL_ICON_WIDTH 24
60 #else
61 # define SMALL_ICON_WIDTH 48
62 #endif
63 #define MAX_ICON_HEIGHT 42
64 #define MAX_ICON_WIDTH 48
65 #define PANEL_BORDER 2
66 #define MIN_ITEM_WIDTH 64
68 #define MIN_TRUNCATE 0
69 #define MAX_TRUNCATE 250
71 extern int collection_menu_button;
72 extern gboolean collection_single_click;
74 FilerWindow *window_with_focus = NULL;
75 GList *all_filer_windows = NULL;
77 static DisplayStyle last_display_style = LARGE_ICONS;
78 static gboolean last_show_hidden = FALSE;
79 static int (*last_sort_fn)(const void *a, const void *b) = sort_by_type;
81 static FilerWindow *window_with_selection = NULL;
83 /* Options bits */
84 static guchar *style_to_name(void);
85 static guchar *sort_fn_to_name(void);
86 static void update_options_label(void);
88 static GtkWidget *create_options();
89 static void update_options();
90 static void set_options();
91 static void save_options();
92 static char *filer_sort_nocase(char *data);
93 static char *filer_single_click(char *data);
94 static char *filer_unique_windows(char *data);
95 static char *filer_menu_on_2(char *data);
96 static char *filer_new_window_on_1(char *data);
97 static char *filer_toolbar(char *data);
98 static char *filer_display_style(char *data);
99 static char *filer_sort_by(char *data);
100 static char *filer_truncate(char *data);
102 static OptionsSection options =
104 N_("Filer window options"),
105 create_options,
106 update_options,
107 set_options,
108 save_options
111 /* The values correspond to the menu indexes in the option widget */
112 typedef enum {
113 TOOLBAR_NONE = 0,
114 TOOLBAR_NORMAL = 1,
115 TOOLBAR_GNOME = 2,
116 } ToolbarType;
117 static ToolbarType o_toolbar = TOOLBAR_NORMAL;
118 static GtkWidget *menu_toolbar;
120 static GtkWidget *display_label;
122 static gboolean o_sort_nocase = FALSE;
123 static gboolean o_single_click = FALSE;
124 static gboolean o_new_window_on_1 = FALSE; /* Button 1 => New window */
125 gboolean o_unique_filer_windows = FALSE;
126 static gint o_small_truncate = 144;
127 static gint o_large_truncate = 89;
128 static GtkAdjustment *adj_small_truncate;
129 static GtkAdjustment *adj_large_truncate;
130 static GtkWidget *toggle_sort_nocase;
131 static GtkWidget *toggle_single_click;
132 static GtkWidget *toggle_new_window_on_1;
133 static GtkWidget *toggle_menu_on_2;
134 static GtkWidget *toggle_unique_filer_windows;
136 /* Static prototypes */
137 static void attach(FilerWindow *filer_window);
138 static void detach(FilerWindow *filer_window);
139 static void filer_window_destroyed(GtkWidget *widget,
140 FilerWindow *filer_window);
141 static void show_menu(Collection *collection, GdkEventButton *event,
142 int number_selected, gpointer user_data);
143 static gint focus_in(GtkWidget *widget,
144 GdkEventFocus *event,
145 FilerWindow *filer_window);
146 static gint focus_out(GtkWidget *widget,
147 GdkEventFocus *event,
148 FilerWindow *filer_window);
149 static void add_item(FilerWindow *filer_window, DirItem *item);
150 static void toolbar_up_clicked(GtkWidget *widget, FilerWindow *filer_window);
151 static void toolbar_home_clicked(GtkWidget *widget, FilerWindow *filer_window);
152 static void add_button(GtkWidget *box, int pixmap,
153 GtkSignalFunc cb, FilerWindow *filer_window,
154 char *label, char *tip);
155 static GtkWidget *create_toolbar(FilerWindow *filer_window);
156 static int filer_confirm_close(GtkWidget *widget, GdkEvent *event,
157 FilerWindow *window);
158 static int calc_width(FilerWindow *filer_window, DirItem *item);
159 static void draw_large_icon(GtkWidget *widget,
160 GdkRectangle *area,
161 DirItem *item,
162 gboolean selected);
163 static void draw_string(GtkWidget *widget,
164 GdkFont *font,
165 char *string,
166 int x,
167 int y,
168 int width,
169 int area_width,
170 gboolean selected);
171 static void draw_item_large(GtkWidget *widget,
172 CollectionItem *item,
173 GdkRectangle *area);
174 static void draw_item_small(GtkWidget *widget,
175 CollectionItem *item,
176 GdkRectangle *area);
177 static void draw_item_full_info(GtkWidget *widget,
178 CollectionItem *colitem,
179 GdkRectangle *area);
180 static gboolean test_point_large(Collection *collection,
181 int point_x, int point_y,
182 CollectionItem *item,
183 int width, int height);
184 static gboolean test_point_small(Collection *collection,
185 int point_x, int point_y,
186 CollectionItem *item,
187 int width, int height);
188 static gboolean test_point_full_info(Collection *collection,
189 int point_x, int point_y,
190 CollectionItem *item,
191 int width, int height);
192 static void update_display(Directory *dir,
193 DirAction action,
194 GPtrArray *items,
195 FilerWindow *filer_window);
196 static void set_scanning_display(FilerWindow *filer_window, gboolean scanning);
197 static void shrink_width(FilerWindow *filer_window);
198 static gboolean may_rescan(FilerWindow *filer_window, gboolean warning);
199 static void open_item(Collection *collection,
200 gpointer item_data, int item_number,
201 gpointer user_data);
202 static gboolean minibuffer_show_cb(FilerWindow *filer_window);
203 static FilerWindow *find_filer_window(char *path, FilerWindow *diff);
204 static void filer_set_title(FilerWindow *filer_window);
206 static GdkAtom xa_string;
207 enum
209 TARGET_STRING,
210 TARGET_URI_LIST,
213 static GdkCursor *busy_cursor = NULL;
214 static GtkTooltips *tooltips = NULL;
216 void filer_init()
218 xa_string = gdk_atom_intern("STRING", FALSE);
220 options_sections = g_slist_prepend(options_sections, &options);
221 option_register("filer_sort_nocase", filer_sort_nocase);
222 option_register("filer_new_window_on_1", filer_new_window_on_1);
223 option_register("filer_menu_on_2", filer_menu_on_2);
224 option_register("filer_single_click", filer_single_click);
225 option_register("filer_unique_windows", filer_unique_windows);
226 option_register("filer_toolbar", filer_toolbar);
227 option_register("filer_display_style", filer_display_style);
228 option_register("filer_sort_by", filer_sort_by);
229 option_register("filer_truncate", filer_truncate);
231 busy_cursor = gdk_cursor_new(GDK_WATCH);
233 tooltips = gtk_tooltips_new();
236 static gboolean if_deleted(gpointer item, gpointer removed)
238 int i = ((GPtrArray *) removed)->len;
239 DirItem **r = (DirItem **) ((GPtrArray *) removed)->pdata;
240 char *leafname = ((DirItem *) item)->leafname;
242 while (i--)
244 if (strcmp(leafname, r[i]->leafname) == 0)
245 return TRUE;
248 return FALSE;
251 static void update_item(FilerWindow *filer_window, DirItem *item)
253 int i;
254 char *leafname = item->leafname;
256 if (leafname[0] == '.')
258 if (filer_window->show_hidden == FALSE || leafname[1] == '\0'
259 || (leafname[1] == '.' && leafname[2] == '\0'))
260 return;
263 i = collection_find_item(filer_window->collection, item, dir_item_cmp);
265 if (i >= 0)
266 collection_draw_item(filer_window->collection, i, TRUE);
267 else
268 g_warning("Failed to find '%s'\n", item->leafname);
271 static void update_display(Directory *dir,
272 DirAction action,
273 GPtrArray *items,
274 FilerWindow *filer_window)
276 int old_num;
277 int i;
278 int cursor = filer_window->collection->cursor_item;
279 char *as;
280 Collection *collection = filer_window->collection;
282 switch (action)
284 case DIR_ADD:
285 as = filer_window->auto_select;
287 old_num = collection->number_of_items;
288 for (i = 0; i < items->len; i++)
290 DirItem *item = (DirItem *) items->pdata[i];
292 add_item(filer_window, item);
294 if (cursor != -1 || !as)
295 continue;
297 if (strcmp(as, item->leafname) != 0)
298 continue;
300 cursor = collection->number_of_items - 1;
301 if (filer_window->had_cursor)
303 collection_set_cursor_item(collection,
304 cursor);
305 filer_window->mini_cursor_base = cursor;
307 else
308 collection_wink_item(collection,
309 cursor);
312 if (old_num != collection->number_of_items)
313 collection_qsort(filer_window->collection,
314 filer_window->sort_fn);
315 break;
316 case DIR_REMOVE:
317 collection_delete_if(filer_window->collection,
318 if_deleted,
319 items);
320 break;
321 case DIR_START_SCAN:
322 set_scanning_display(filer_window, TRUE);
323 break;
324 case DIR_END_SCAN:
325 if (filer_window->window->window)
326 gdk_window_set_cursor(
327 filer_window->window->window,
328 NULL);
329 shrink_width(filer_window);
330 if (filer_window->had_cursor &&
331 collection->cursor_item == -1)
333 collection_set_cursor_item(collection, 0);
334 filer_window->had_cursor = FALSE;
336 set_scanning_display(filer_window, FALSE);
337 break;
338 case DIR_UPDATE:
339 for (i = 0; i < items->len; i++)
341 DirItem *item = (DirItem *) items->pdata[i];
343 update_item(filer_window, item);
345 collection_qsort(filer_window->collection,
346 filer_window->sort_fn);
347 break;
351 static void attach(FilerWindow *filer_window)
353 gdk_window_set_cursor(filer_window->window->window, busy_cursor);
354 collection_clear(filer_window->collection);
355 filer_window->scanning = TRUE;
356 dir_attach(filer_window->directory, (DirCallback) update_display,
357 filer_window);
358 filer_set_title(filer_window);
361 static void detach(FilerWindow *filer_window)
363 g_return_if_fail(filer_window->directory != NULL);
365 dir_detach(filer_window->directory,
366 (DirCallback) update_display, filer_window);
367 g_fscache_data_unref(dir_cache, filer_window->directory);
368 filer_window->directory = NULL;
371 static void filer_window_destroyed(GtkWidget *widget,
372 FilerWindow *filer_window)
374 all_filer_windows = g_list_remove(all_filer_windows, filer_window);
376 if (window_with_selection == filer_window)
377 window_with_selection = NULL;
378 if (window_with_focus == filer_window)
379 window_with_focus = NULL;
381 if (filer_window->directory)
382 detach(filer_window);
384 g_free(filer_window->auto_select);
385 g_free(filer_window->path);
386 g_free(filer_window);
388 if (--number_of_windows < 1)
389 gtk_main_quit();
392 static int calc_width(FilerWindow *filer_window, DirItem *item)
394 int pix_width = item->image->width;
395 int w;
397 switch (filer_window->display_style)
399 case FULL_INFO:
400 return MAX_ICON_WIDTH + 12 +
401 MAX(item->details_width, item->name_width);
402 case SMALL_ICONS:
403 return SMALL_ICON_WIDTH + 12 + item->name_width;
404 default:
405 w = MIN(item->name_width, o_large_truncate);
406 return MAX(pix_width, w) + 4;
410 /* Add a single object to a directory display */
411 static void add_item(FilerWindow *filer_window, DirItem *item)
413 char *leafname = item->leafname;
414 int item_width;
416 if (leafname[0] == '.')
418 if (filer_window->show_hidden == FALSE || leafname[1] == '\0'
419 || (leafname[1] == '.' && leafname[2] == '\0'))
420 return;
423 item_width = calc_width(filer_window, item);
424 if (item_width > filer_window->collection->item_width)
425 collection_set_item_size(filer_window->collection,
426 item_width,
427 filer_window->collection->item_height);
428 collection_insert(filer_window->collection, item);
431 /* Is a point inside an item? */
432 static gboolean test_point_large(Collection *collection,
433 int point_x, int point_y,
434 CollectionItem *colitem,
435 int width, int height)
437 DirItem *item = (DirItem *) colitem->data;
438 int text_height = item_font->ascent + item_font->descent;
439 MaskedPixmap *image = item->image;
440 int image_y = MAX(0, MAX_ICON_HEIGHT - image->height);
441 int image_width = (image->width >> 1) + 2;
442 int text_width = (item->name_width >> 1) + 2;
443 int x_limit;
445 if (point_y < image_y)
446 return FALSE; /* Too high up (don't worry about too low) */
448 if (point_y <= image_y + image->height + 2)
449 x_limit = image_width;
450 else if (point_y > height - text_height - 2)
451 x_limit = text_width;
452 else
453 x_limit = MIN(image_width, text_width);
455 return ABS(point_x - (width >> 1)) < x_limit;
458 static gboolean test_point_full_info(Collection *collection,
459 int point_x, int point_y,
460 CollectionItem *colitem,
461 int width, int height)
463 DirItem *item = (DirItem *) colitem->data;
464 MaskedPixmap *image = item->image;
465 int image_y = MAX(0, MAX_ICON_HEIGHT - image->height);
466 int low_top = height
467 - fixed_font->descent - 2 - fixed_font->ascent;
469 if (point_x < image->width + 2)
470 return point_x > 2 && point_y > image_y;
472 point_x -= MAX_ICON_WIDTH + 8;
474 if (point_y >= low_top)
475 return point_x < item->details_width;
476 if (point_y >= low_top - item_font->ascent - item_font->descent)
477 return point_x < item->name_width;
478 return FALSE;
481 static gboolean test_point_small(Collection *collection,
482 int point_x, int point_y,
483 CollectionItem *colitem,
484 int width, int height)
486 DirItem *item = (DirItem *) colitem->data;
487 MaskedPixmap *image = item->image;
488 int image_y = MAX(0, SMALL_ICON_HEIGHT - image->height);
489 int low_top = height
490 - fixed_font->descent - 2 - item_font->ascent;
491 int iwidth = MIN(SMALL_ICON_WIDTH, image->width);
493 if (point_x < iwidth + 2)
494 return point_x > 2 && point_y > image_y;
496 point_x -= SMALL_ICON_WIDTH + 4;
498 if (point_y >= low_top)
499 return point_x < item->name_width;
500 return FALSE;
503 static void draw_small_icon(GtkWidget *widget,
504 GdkRectangle *area,
505 DirItem *item,
506 gboolean selected)
508 GdkGC *gc = selected ? widget->style->white_gc
509 : widget->style->black_gc;
510 MaskedPixmap *image = item->image;
511 int width, height, image_x, image_y;
513 if (!image)
514 return;
516 if (!image->sm_pixmap)
517 pixmap_make_small(image);
519 width = MIN(image->sm_width, SMALL_ICON_WIDTH);
520 height = MIN(image->sm_height, SMALL_ICON_HEIGHT);
521 image_x = area->x + ((area->width - width) >> 1);
523 gdk_gc_set_clip_mask(gc, item->image->sm_mask);
525 image_y = MAX(0, SMALL_ICON_HEIGHT - image->sm_height);
526 gdk_gc_set_clip_origin(gc, image_x, area->y + image_y);
527 gdk_draw_pixmap(widget->window, gc,
528 item->image->sm_pixmap,
529 0, 0, /* Source x,y */
530 image_x, area->y + image_y, /* Dest x,y */
531 width, height);
533 if (selected)
535 gdk_gc_set_function(gc, GDK_INVERT);
536 gdk_draw_rectangle(widget->window,
538 TRUE, image_x, area->y + image_y,
539 width, height);
540 gdk_gc_set_function(gc, GDK_COPY);
543 if (item->flags & ITEM_FLAG_SYMLINK)
545 gdk_gc_set_clip_origin(gc, image_x, area->y + 8);
546 gdk_gc_set_clip_mask(gc,
547 default_pixmap[TYPE_SYMLINK]->mask);
548 gdk_draw_pixmap(widget->window, gc,
549 default_pixmap[TYPE_SYMLINK]->pixmap,
550 0, 0, /* Source x,y */
551 image_x, area->y + 8, /* Dest x,y */
552 -1, -1);
554 else if (item->flags & ITEM_FLAG_MOUNT_POINT)
556 int type = item->flags & ITEM_FLAG_MOUNTED
557 ? TYPE_MOUNTED
558 : TYPE_UNMOUNTED;
559 MaskedPixmap *mp = default_pixmap[type];
561 if (!mp->sm_pixmap)
562 pixmap_make_small(mp);
563 gdk_gc_set_clip_origin(gc, image_x, area->y + 8);
564 gdk_gc_set_clip_mask(gc, mp->sm_mask);
565 gdk_draw_pixmap(widget->window, gc,
566 mp->sm_pixmap,
567 0, 0, /* Source x,y */
568 image_x, area->y + 8, /* Dest x,y */
569 -1, -1);
572 gdk_gc_set_clip_mask(gc, NULL);
573 gdk_gc_set_clip_origin(gc, 0, 0);
576 static void draw_large_icon(GtkWidget *widget,
577 GdkRectangle *area,
578 DirItem *item,
579 gboolean selected)
581 MaskedPixmap *image = item->image;
582 int width = MIN(image->width, MAX_ICON_WIDTH);
583 int height = MIN(image->height, MAX_ICON_WIDTH);
584 int image_x = area->x + ((area->width - width) >> 1);
585 int image_y;
586 GdkGC *gc = selected ? widget->style->white_gc
587 : widget->style->black_gc;
589 gdk_gc_set_clip_mask(gc, item->image->mask);
591 image_y = MAX(0, MAX_ICON_HEIGHT - image->height);
592 gdk_gc_set_clip_origin(gc, image_x, area->y + image_y);
593 gdk_draw_pixmap(widget->window, gc,
594 item->image->pixmap,
595 0, 0, /* Source x,y */
596 image_x, area->y + image_y, /* Dest x,y */
597 width, height);
599 if (selected)
601 gdk_gc_set_function(gc, GDK_INVERT);
602 gdk_draw_rectangle(widget->window,
604 TRUE, image_x, area->y + image_y,
605 width, height);
606 gdk_gc_set_function(gc, GDK_COPY);
609 if (item->flags & ITEM_FLAG_SYMLINK)
611 gdk_gc_set_clip_origin(gc, image_x, area->y + 8);
612 gdk_gc_set_clip_mask(gc,
613 default_pixmap[TYPE_SYMLINK]->mask);
614 gdk_draw_pixmap(widget->window, gc,
615 default_pixmap[TYPE_SYMLINK]->pixmap,
616 0, 0, /* Source x,y */
617 image_x, area->y + 8, /* Dest x,y */
618 -1, -1);
620 else if (item->flags & ITEM_FLAG_MOUNT_POINT)
622 int type = item->flags & ITEM_FLAG_MOUNTED
623 ? TYPE_MOUNTED
624 : TYPE_UNMOUNTED;
625 gdk_gc_set_clip_origin(gc, image_x, area->y + 8);
626 gdk_gc_set_clip_mask(gc,
627 default_pixmap[type]->mask);
628 gdk_draw_pixmap(widget->window, gc,
629 default_pixmap[type]->pixmap,
630 0, 0, /* Source x,y */
631 image_x, area->y + 8, /* Dest x,y */
632 -1, -1);
635 gdk_gc_set_clip_mask(gc, NULL);
636 gdk_gc_set_clip_origin(gc, 0, 0);
639 static void draw_string(GtkWidget *widget,
640 GdkFont *font,
641 char *string,
642 int x,
643 int y,
644 int width,
645 int area_width,
646 gboolean selected)
648 int text_height = font->ascent + font->descent;
649 GdkRectangle clip;
650 GdkGC *gc = selected ? widget->style->white_gc
651 : widget->style->black_gc;
653 if (selected)
654 gtk_paint_flat_box(widget->style, widget->window,
655 GTK_STATE_SELECTED, GTK_SHADOW_NONE,
656 NULL, widget, "text",
657 x, y - font->ascent,
658 MIN(width, area_width),
659 text_height);
661 if (width > area_width)
663 clip.x = x;
664 clip.y = y - font->ascent;
665 clip.width = area_width;
666 clip.height = text_height;
667 gdk_gc_set_clip_origin(gc, 0, 0);
668 gdk_gc_set_clip_rectangle(gc, &clip);
671 gdk_draw_text(widget->window,
672 font,
674 x, y,
675 string, strlen(string));
677 if (width > area_width)
679 if (!red_gc)
681 red_gc = gdk_gc_new(widget->window);
682 gdk_gc_set_foreground(red_gc, &red);
684 gdk_draw_rectangle(widget->window, red_gc, TRUE,
685 x + area_width - 1, clip.y, 1, text_height);
686 gdk_gc_set_clip_rectangle(gc, NULL);
690 /* Return a string (valid until next call) giving details
691 * of this item.
693 char *details(DirItem *item)
695 mode_t m = item->mode;
696 static guchar *buf = NULL;
698 if (buf)
699 g_free(buf);
701 if (item->lstat_errno)
702 buf = g_strdup_printf(_("lstat(2) failed: %s"),
703 g_strerror(item->lstat_errno));
704 else
705 buf = g_strdup_printf("%s %s %-8.8s %-8.8s %s %s",
706 item->flags & ITEM_FLAG_APPDIR? "App " :
707 S_ISDIR(m) ? "Dir " :
708 S_ISCHR(m) ? "Char" :
709 S_ISBLK(m) ? "Blck" :
710 S_ISLNK(m) ? "Link" :
711 S_ISSOCK(m) ? "Sock" :
712 S_ISFIFO(m) ? "Pipe" : "File",
713 pretty_permissions(m),
714 user_name(item->uid),
715 group_name(item->gid),
716 format_size_aligned(item->size),
717 pretty_time(&item->mtime));
718 return buf;
721 static void draw_item_full_info(GtkWidget *widget,
722 CollectionItem *colitem,
723 GdkRectangle *area)
725 DirItem *item = (DirItem *) colitem->data;
726 MaskedPixmap *image = item->image;
727 int text_x = area->x + MAX_ICON_WIDTH + 8;
728 int low_text_y = area->y + area->height - fixed_font->descent - 2;
729 gboolean selected = colitem->selected;
730 GdkRectangle pic_area;
731 int text_area_width = area->width - (text_x - area->x);
733 pic_area.x = area->x;
734 pic_area.y = area->y;
735 pic_area.width = image->width + 8;
736 pic_area.height = area->height;
738 draw_large_icon(widget, &pic_area, item, selected);
740 draw_string(widget,
741 item_font,
742 item->leafname,
743 text_x,
744 low_text_y - item_font->descent - fixed_font->ascent,
745 item->name_width,
746 text_area_width,
747 selected);
748 draw_string(widget,
749 fixed_font,
750 details(item),
751 text_x, low_text_y,
752 item->details_width,
753 text_area_width,
754 selected);
756 if (item->lstat_errno)
757 return;
759 /* Underline the effective permissions */
760 gdk_draw_rectangle(widget->window,
761 selected ? widget->style->white_gc
762 : widget->style->black_gc,
763 TRUE,
764 text_x - 1 + fixed_width *
765 (5 + 4 * applicable(item->uid, item->gid)),
766 low_text_y + fixed_font->descent - 1,
767 fixed_width * 3 + 1, 1);
770 static void draw_item_small(GtkWidget *widget,
771 CollectionItem *colitem,
772 GdkRectangle *area)
774 DirItem *item = (DirItem *) colitem->data;
775 int text_x = area->x + SMALL_ICON_WIDTH + 4;
776 int low_text_y = area->y + area->height - item_font->descent - 2;
777 gboolean selected = colitem->selected;
778 GdkRectangle pic_area;
780 pic_area.x = area->x;
781 pic_area.y = area->y;
782 pic_area.width = SMALL_ICON_WIDTH;
783 pic_area.height = SMALL_ICON_HEIGHT;
785 draw_small_icon(widget, &pic_area, item, selected);
787 draw_string(widget,
788 item_font,
789 item->leafname,
790 text_x,
791 low_text_y,
792 item->name_width,
793 area->width - (text_x - area->x),
794 selected);
797 static void draw_item_large(GtkWidget *widget,
798 CollectionItem *colitem,
799 GdkRectangle *area)
801 DirItem *item = (DirItem *) colitem->data;
802 int text_width = item->name_width;
803 int text_x = area->x + ((area->width - text_width) >> 1);
804 int text_y = area->y + area->height - item_font->descent - 2;
805 gboolean selected = colitem->selected;
807 draw_large_icon(widget, area, item, selected);
809 if (text_x < area->x)
810 text_x = area->x;
812 draw_string(widget,
813 item_font,
814 item->leafname,
815 text_x, text_y,
816 item->name_width,
817 area->width,
818 selected);
821 static void show_menu(Collection *collection, GdkEventButton *event,
822 int item, gpointer user_data)
824 show_filer_menu((FilerWindow *) user_data, event, item);
827 /* Returns TRUE iff the directory still exists. */
828 static gboolean may_rescan(FilerWindow *filer_window, gboolean warning)
830 Directory *dir;
832 g_return_val_if_fail(filer_window != NULL, FALSE);
834 /* We do a fresh lookup (rather than update) because the inode may
835 * have changed.
837 dir = g_fscache_lookup(dir_cache, filer_window->path);
838 if (!dir)
840 if (warning)
841 delayed_error(PROJECT, _("Directory missing/deleted"));
842 gtk_widget_destroy(filer_window->window);
843 return FALSE;
845 if (dir == filer_window->directory)
846 g_fscache_data_unref(dir_cache, dir);
847 else
849 detach(filer_window);
850 filer_window->directory = dir;
851 attach(filer_window);
854 return TRUE;
857 /* Another app has grabbed the selection */
858 static gint collection_lose_selection(GtkWidget *widget,
859 GdkEventSelection *event)
861 if (window_with_selection &&
862 window_with_selection->collection == COLLECTION(widget))
864 FilerWindow *filer_window = window_with_selection;
865 window_with_selection = NULL;
866 collection_clear_selection(filer_window->collection);
869 return TRUE;
872 /* Someone wants us to send them the selection */
873 static void selection_get(GtkWidget *widget,
874 GtkSelectionData *selection_data,
875 guint info,
876 guint time,
877 gpointer data)
879 GString *reply, *header;
880 FilerWindow *filer_window;
881 int i;
882 Collection *collection;
884 filer_window = gtk_object_get_data(GTK_OBJECT(widget), "filer_window");
886 reply = g_string_new(NULL);
887 header = g_string_new(NULL);
889 switch (info)
891 case TARGET_STRING:
892 g_string_sprintf(header, " %s",
893 make_path(filer_window->path, "")->str);
894 break;
895 case TARGET_URI_LIST:
896 g_string_sprintf(header, " file://%s%s",
897 our_host_name(),
898 make_path(filer_window->path, "")->str);
899 break;
902 collection = filer_window->collection;
903 for (i = 0; i < collection->number_of_items; i++)
905 if (collection->items[i].selected)
907 DirItem *item =
908 (DirItem *) collection->items[i].data;
910 g_string_append(reply, header->str);
911 g_string_append(reply, item->leafname);
914 /* This works, but I don't think I like it... */
915 /* g_string_append_c(reply, ' '); */
917 gtk_selection_data_set(selection_data, xa_string,
918 8, reply->str + 1, reply->len - 1);
919 g_string_free(reply, TRUE);
920 g_string_free(header, TRUE);
923 /* No items are now selected. This might be because another app claimed
924 * the selection or because the user unselected all the items.
926 static void lose_selection(Collection *collection,
927 guint time,
928 gpointer user_data)
930 FilerWindow *filer_window = (FilerWindow *) user_data;
932 if (window_with_selection == filer_window)
934 window_with_selection = NULL;
935 gtk_selection_owner_set(NULL,
936 GDK_SELECTION_PRIMARY,
937 time);
941 static void gain_selection(Collection *collection,
942 guint time,
943 gpointer user_data)
945 FilerWindow *filer_window = (FilerWindow *) user_data;
947 if (gtk_selection_owner_set(GTK_WIDGET(collection),
948 GDK_SELECTION_PRIMARY,
949 time))
951 window_with_selection = filer_window;
953 else
954 collection_clear_selection(filer_window->collection);
957 int sort_by_name(const void *item1, const void *item2)
959 if (o_sort_nocase)
960 return g_strcasecmp((*((DirItem **)item1))->leafname,
961 (*((DirItem **)item2))->leafname);
962 return strcmp((*((DirItem **)item1))->leafname,
963 (*((DirItem **)item2))->leafname);
966 int sort_by_type(const void *item1, const void *item2)
968 const DirItem *i1 = (DirItem *) ((CollectionItem *) item1)->data;
969 const DirItem *i2 = (DirItem *) ((CollectionItem *) item2)->data;
970 MIME_type *m1, *m2;
972 int diff = i1->base_type - i2->base_type;
974 if (!diff)
975 diff = (i1->flags & ITEM_FLAG_APPDIR)
976 - (i2->flags & ITEM_FLAG_APPDIR);
977 if (diff)
978 return diff > 0 ? 1 : -1;
980 m1 = i1->mime_type;
981 m2 = i2->mime_type;
983 if (m1 && m2)
985 diff = strcmp(m1->media_type, m2->media_type);
986 if (!diff)
987 diff = strcmp(m1->subtype, m2->subtype);
989 else if (m1 || m2)
990 diff = m1 ? 1 : -1;
991 else
992 diff = 0;
994 if (diff)
995 return diff > 0 ? 1 : -1;
997 return sort_by_name(item1, item2);
1000 int sort_by_date(const void *item1, const void *item2)
1002 const DirItem *i1 = (DirItem *) ((CollectionItem *) item1)->data;
1003 const DirItem *i2 = (DirItem *) ((CollectionItem *) item2)->data;
1005 return i1->mtime > i2->mtime ? -1 :
1006 i1->mtime < i2->mtime ? 1 :
1007 sort_by_name(item1, item2);
1010 int sort_by_size(const void *item1, const void *item2)
1012 const DirItem *i1 = (DirItem *) ((CollectionItem *) item1)->data;
1013 const DirItem *i2 = (DirItem *) ((CollectionItem *) item2)->data;
1015 return i1->size > i2->size ? -1 :
1016 i1->size < i2->size ? 1 :
1017 sort_by_name(item1, item2);
1020 static void open_item(Collection *collection,
1021 gpointer item_data, int item_number,
1022 gpointer user_data)
1024 FilerWindow *filer_window = (FilerWindow *) user_data;
1025 GdkEvent *event;
1026 GdkEventButton *bevent;
1027 GdkEventKey *kevent;
1028 OpenFlags flags = 0;
1030 event = (GdkEvent *) gtk_get_current_event();
1032 bevent = (GdkEventButton *) event;
1033 kevent = (GdkEventKey *) event;
1035 switch (event->type)
1037 case GDK_2BUTTON_PRESS:
1038 case GDK_BUTTON_PRESS:
1039 case GDK_BUTTON_RELEASE:
1040 if (bevent->state & GDK_SHIFT_MASK)
1041 flags |= OPEN_SHIFT;
1043 if (o_new_window_on_1 ^ (bevent->button == 1))
1044 flags |= OPEN_SAME_WINDOW;
1046 if (bevent->button != 1)
1047 flags |= OPEN_CLOSE_WINDOW;
1049 if (o_single_click == FALSE &&
1050 (bevent->state & GDK_CONTROL_MASK) != 0)
1051 flags ^= OPEN_SAME_WINDOW | OPEN_CLOSE_WINDOW;
1052 break;
1053 case GDK_KEY_PRESS:
1054 flags |= OPEN_SAME_WINDOW;
1055 if (kevent->state & GDK_SHIFT_MASK)
1056 flags |= OPEN_SHIFT;
1057 break;
1058 default:
1059 break;
1062 filer_openitem(filer_window, item_number, flags);
1065 /* Return the full path to the directory containing object 'path'.
1066 * Relative paths are resolved from the filerwindow's path.
1068 static void follow_symlink(FilerWindow *filer_window, char *path,
1069 gboolean same_window)
1071 char *real, *slash;
1072 char *new_dir;
1074 if (path[0] != '/')
1075 path = make_path(filer_window->path, path)->str;
1077 real = pathdup(path);
1078 slash = strrchr(real, '/');
1079 if (!slash)
1081 g_free(real);
1082 delayed_error(PROJECT,
1083 _("Broken symlink (or you don't have permission "
1084 "to follow it)."));
1085 return;
1088 *slash = '\0';
1090 if (*real)
1091 new_dir = real;
1092 else
1093 new_dir = "/";
1095 if (filer_window->panel_type || !same_window)
1097 FilerWindow *new;
1099 new = filer_opendir(new_dir, PANEL_NO);
1100 filer_set_autoselect(new, slash + 1);
1102 else
1103 filer_change_to(filer_window, new_dir, slash + 1);
1105 g_free(real);
1108 /* Open the item (or add it to the shell command minibuffer) */
1109 void filer_openitem(FilerWindow *filer_window, int item_number, OpenFlags flags)
1111 gboolean shift = (flags & OPEN_SHIFT) != 0;
1112 gboolean close_mini = flags & OPEN_FROM_MINI;
1113 gboolean same_window = (flags & OPEN_SAME_WINDOW) != 0
1114 && !filer_window->panel_type;
1115 gboolean close_window = (flags & OPEN_CLOSE_WINDOW) != 0
1116 && !filer_window->panel_type;
1117 GtkWidget *widget;
1118 char *full_path;
1119 DirItem *item = (DirItem *)
1120 filer_window->collection->items[item_number].data;
1121 gboolean wink = TRUE, destroy = FALSE;
1123 widget = filer_window->window;
1124 if (filer_window->mini_type == MINI_SHELL)
1126 minibuffer_add(filer_window, item->leafname);
1127 return;
1130 full_path = make_path(filer_window->path,
1131 item->leafname)->str;
1133 if (item->flags & ITEM_FLAG_SYMLINK && shift)
1135 char path[MAXPATHLEN + 1];
1136 int got;
1138 got = readlink(make_path(filer_window->path,
1139 item->leafname)->str,
1140 path, MAXPATHLEN);
1141 if (got < 0)
1142 delayed_error(PROJECT, g_strerror(errno));
1143 else
1145 g_return_if_fail(got <= MAXPATHLEN);
1146 path[got] = '\0';
1148 follow_symlink(filer_window, path,
1149 flags & OPEN_SAME_WINDOW);
1151 return;
1154 switch (item->base_type)
1156 case TYPE_DIRECTORY:
1157 if (item->flags & ITEM_FLAG_APPDIR && !shift)
1159 run_app(make_path(filer_window->path,
1160 item->leafname)->str);
1161 if (close_window)
1162 destroy = TRUE;
1163 break;
1166 if (item->flags & ITEM_FLAG_MOUNT_POINT && shift)
1168 action_mount(filer_window, item);
1169 if (item->flags & ITEM_FLAG_MOUNTED)
1170 break;
1173 if (same_window)
1175 wink = FALSE;
1176 filer_change_to(filer_window, full_path, NULL);
1177 close_mini = FALSE;
1179 else
1180 filer_opendir(full_path, PANEL_NO);
1181 break;
1182 case TYPE_FILE:
1183 if ((item->flags & ITEM_FLAG_EXEC_FILE) && !shift)
1185 char *argv[] = {NULL, NULL};
1187 argv[0] = full_path;
1189 if (spawn_full(argv, filer_window->path))
1191 if (close_window)
1192 destroy = TRUE;
1194 else
1195 report_error(PROJECT,
1196 _("Failed to fork() child"));
1198 else
1200 GString *message;
1201 MIME_type *type = shift ? &text_plain
1202 : item->mime_type;
1204 g_return_if_fail(type != NULL);
1206 if (type_open(full_path, type))
1208 if (close_window)
1209 destroy = TRUE;
1211 else
1213 message = g_string_new(NULL);
1214 g_string_sprintf(message,
1215 _("No run action specified for files of this type (%s/%s) - "
1216 "you can set a run action using by choosing `Set Run Action' "
1217 "from the Window menu"),
1218 type->media_type,
1219 type->subtype);
1220 report_error(PROJECT, message->str);
1221 g_string_free(message, TRUE);
1224 break;
1225 default:
1226 report_error("open_item",
1227 "I don't know how to open that");
1228 break;
1231 if (destroy)
1232 gtk_widget_destroy(filer_window->window);
1233 else
1235 if (wink)
1236 collection_wink_item(filer_window->collection,
1237 item_number);
1238 if (close_mini)
1239 minibuffer_hide(filer_window);
1243 static gint pointer_in(GtkWidget *widget,
1244 GdkEventCrossing *event,
1245 FilerWindow *filer_window)
1247 may_rescan(filer_window, TRUE);
1248 return FALSE;
1251 static gint focus_in(GtkWidget *widget,
1252 GdkEventFocus *event,
1253 FilerWindow *filer_window)
1255 window_with_focus = filer_window;
1257 return FALSE;
1260 static gint focus_out(GtkWidget *widget,
1261 GdkEventFocus *event,
1262 FilerWindow *filer_window)
1264 /* TODO: Shade the cursor */
1266 return FALSE;
1269 /* Handle keys that can't be bound with the menu */
1270 static gint key_press_event(GtkWidget *widget,
1271 GdkEventKey *event,
1272 FilerWindow *filer_window)
1274 switch (event->keyval)
1276 case GDK_BackSpace:
1277 change_to_parent(filer_window);
1278 break;
1279 default:
1280 return FALSE;
1283 return TRUE;
1286 static void toolbar_refresh_clicked(GtkWidget *widget,
1287 FilerWindow *filer_window)
1289 GdkEvent *event;
1291 event = gtk_get_current_event();
1292 if (event->type == GDK_BUTTON_RELEASE &&
1293 ((GdkEventButton *) event)->button != 1)
1295 filer_opendir(filer_window->path, PANEL_NO);
1297 else
1299 full_refresh();
1300 filer_update_dir(filer_window, TRUE);
1304 static void toolbar_home_clicked(GtkWidget *widget, FilerWindow *filer_window)
1306 GdkEvent *event;
1308 event = gtk_get_current_event();
1309 if (event->type == GDK_BUTTON_RELEASE &&
1310 ((GdkEventButton *) event)->button != 1)
1312 filer_opendir(home_dir, PANEL_NO);
1314 else
1315 filer_change_to(filer_window, home_dir, NULL);
1318 static void toolbar_up_clicked(GtkWidget *widget, FilerWindow *filer_window)
1320 GdkEvent *event;
1322 event = gtk_get_current_event();
1323 if (event->type == GDK_BUTTON_RELEASE &&
1324 ((GdkEventButton *) event)->button != 1)
1326 filer_open_parent(filer_window);
1328 else
1329 change_to_parent(filer_window);
1332 void change_to_parent(FilerWindow *filer_window)
1334 char *copy;
1335 char *slash;
1337 if (filer_window->path[0] == '/' && filer_window->path[1] == '\0')
1338 return; /* Already in the root */
1340 copy = g_strdup(filer_window->path);
1341 slash = strrchr(copy, '/');
1343 if (slash)
1345 *slash = '\0';
1346 filer_change_to(filer_window,
1347 *copy ? copy : "/",
1348 slash + 1);
1350 else
1351 g_warning("No / in directory path!\n");
1353 g_free(copy);
1357 /* Make filer_window display path. When finished, highlight item 'from', or
1358 * the first item if from is NULL. If there is currently no cursor then
1359 * simply wink 'from' (if not NULL).
1361 void filer_change_to(FilerWindow *filer_window, char *path, char *from)
1363 char *from_dup;
1364 char *real_path = pathdup(path);
1366 if (o_unique_filer_windows)
1368 FilerWindow *fw;
1370 fw = find_filer_window(real_path, filer_window);
1371 if (fw)
1372 gtk_widget_destroy(fw->window);
1375 from_dup = from && *from ? g_strdup(from) : NULL;
1377 detach(filer_window);
1378 g_free(filer_window->path);
1379 filer_window->path = real_path;
1381 filer_window->directory = g_fscache_lookup(dir_cache,
1382 filer_window->path);
1383 if (filer_window->directory)
1385 g_free(filer_window->auto_select);
1386 filer_window->had_cursor =
1387 filer_window->collection->cursor_item != -1
1388 || filer_window->had_cursor;
1389 filer_window->auto_select = from_dup;
1391 filer_set_title(filer_window);
1392 collection_set_cursor_item(filer_window->collection, -1);
1393 attach(filer_window);
1395 if (filer_window->mini_type == MINI_PATH)
1396 gtk_idle_add((GtkFunction) minibuffer_show_cb,
1397 filer_window);
1399 else
1401 char *error;
1403 g_free(from_dup);
1404 error = g_strdup_printf(_("Directory '%s' is not accessible"),
1405 path);
1406 delayed_error(PROJECT, error);
1407 g_free(error);
1408 gtk_widget_destroy(filer_window->window);
1412 void filer_open_parent(FilerWindow *filer_window)
1414 char *copy;
1415 char *slash;
1417 if (filer_window->path[0] == '/' && filer_window->path[1] == '\0')
1418 return; /* Already in the root */
1420 copy = g_strdup(filer_window->path);
1421 slash = strrchr(copy, '/');
1423 if (slash)
1425 *slash = '\0';
1426 filer_opendir(*copy ? copy : "/", PANEL_NO);
1428 else
1429 g_warning("No / in directory path!\n");
1431 g_free(copy);
1434 int selected_item_number(Collection *collection)
1436 int i;
1438 g_return_val_if_fail(collection != NULL, -1);
1439 g_return_val_if_fail(IS_COLLECTION(collection), -1);
1440 g_return_val_if_fail(collection->number_selected == 1, -1);
1442 for (i = 0; i < collection->number_of_items; i++)
1443 if (collection->items[i].selected)
1444 return i;
1446 g_warning("selected_item: number_selected is wrong\n");
1448 return -1;
1451 DirItem *selected_item(Collection *collection)
1453 int item;
1455 item = selected_item_number(collection);
1457 if (item > -1)
1458 return (DirItem *) collection->items[item].data;
1459 return NULL;
1462 static int filer_confirm_close(GtkWidget *widget, GdkEvent *event,
1463 FilerWindow *window)
1465 /* TODO: We can open lots of these - very irritating! */
1466 return get_choice(_("Close panel?"),
1467 _("You have tried to close a panel via the window "
1468 "manager - I usually find that this is accidental... "
1469 "really close?"),
1470 2, _("Remove"), _("Cancel")) != 0;
1473 /* Make the items as narrow as possible */
1474 static void shrink_width(FilerWindow *filer_window)
1476 int i;
1477 Collection *col = filer_window->collection;
1478 int width = MIN_ITEM_WIDTH;
1479 int this_width;
1480 DisplayStyle style = filer_window->display_style;
1481 int text_height;
1483 text_height = item_font->ascent + item_font->descent;
1485 for (i = 0; i < col->number_of_items; i++)
1487 this_width = calc_width(filer_window,
1488 (DirItem *) col->items[i].data);
1489 if (this_width > width)
1490 width = this_width;
1493 collection_set_item_size(filer_window->collection,
1494 width,
1495 style == FULL_INFO ? MAX_ICON_HEIGHT + 4 :
1496 style == SMALL_ICONS ? MAX(text_height, SMALL_ICON_HEIGHT) + 4
1497 : text_height + MAX_ICON_HEIGHT + 8);
1500 void filer_set_sort_fn(FilerWindow *filer_window,
1501 int (*fn)(const void *a, const void *b))
1503 if (filer_window->sort_fn == fn)
1504 return;
1506 filer_window->sort_fn = fn;
1507 last_sort_fn = fn;
1509 collection_qsort(filer_window->collection,
1510 filer_window->sort_fn);
1512 update_options_label();
1515 void filer_style_set(FilerWindow *filer_window, DisplayStyle style)
1517 if (filer_window->display_style == style)
1518 return;
1520 if (filer_window->panel_type)
1521 style = LARGE_ICONS;
1522 else
1523 last_display_style = style;
1525 filer_window->display_style = style;
1527 switch (style)
1529 case SMALL_ICONS:
1530 collection_set_functions(filer_window->collection,
1531 draw_item_small, test_point_small);
1532 break;
1533 case FULL_INFO:
1534 collection_set_functions(filer_window->collection,
1535 draw_item_full_info, test_point_full_info);
1536 break;
1537 default:
1538 collection_set_functions(filer_window->collection,
1539 draw_item_large, test_point_large);
1540 break;
1543 shrink_width(filer_window);
1545 update_options_label();
1548 FilerWindow *filer_opendir(char *path, PanelType panel_type)
1550 GtkWidget *hbox, *scrollbar, *collection;
1551 FilerWindow *filer_window;
1552 GtkTargetEntry target_table[] =
1554 {"text/uri-list", 0, TARGET_URI_LIST},
1555 {"STRING", 0, TARGET_STRING},
1557 char *real_path;
1559 real_path = pathdup(path);
1561 if (o_unique_filer_windows && panel_type == PANEL_NO)
1563 FilerWindow *fw;
1565 fw = find_filer_window(real_path, NULL);
1567 if (fw)
1569 /* TODO: this should bring the window to the front
1570 * at the same coordinates.
1572 gtk_widget_hide(fw->window);
1573 gtk_widget_show(fw->window);
1574 g_free(real_path);
1575 return fw;
1579 filer_window = g_new(FilerWindow, 1);
1580 filer_window->minibuffer = NULL;
1581 filer_window->minibuffer_label = NULL;
1582 filer_window->minibuffer_area = NULL;
1583 filer_window->path = real_path;
1584 filer_window->scanning = FALSE;
1585 filer_window->had_cursor = FALSE;
1586 filer_window->auto_select = NULL;
1587 filer_window->mini_type = MINI_NONE;
1589 filer_window->directory = g_fscache_lookup(dir_cache,
1590 filer_window->path);
1591 if (!filer_window->directory)
1593 char *error;
1595 error = g_strdup_printf(_("Directory '%s' not found."), path);
1596 delayed_error(PROJECT, error);
1597 g_free(error);
1598 g_free(filer_window->path);
1599 g_free(filer_window);
1600 return NULL;
1603 filer_window->show_hidden = last_show_hidden;
1604 filer_window->panel_type = panel_type;
1605 filer_window->temp_item_selected = FALSE;
1606 filer_window->sort_fn = last_sort_fn;
1607 filer_window->flags = (FilerFlags) 0;
1608 filer_window->display_style = UNKNOWN_STYLE;
1610 filer_window->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1611 filer_set_title(filer_window);
1613 collection = collection_new(NULL);
1614 gtk_object_set_data(GTK_OBJECT(collection),
1615 "filer_window", filer_window);
1616 filer_window->collection = COLLECTION(collection);
1618 gtk_widget_add_events(filer_window->window, GDK_ENTER_NOTIFY);
1619 gtk_signal_connect(GTK_OBJECT(filer_window->window),
1620 "enter-notify-event",
1621 GTK_SIGNAL_FUNC(pointer_in), filer_window);
1622 gtk_signal_connect(GTK_OBJECT(filer_window->window), "focus_in_event",
1623 GTK_SIGNAL_FUNC(focus_in), filer_window);
1624 gtk_signal_connect(GTK_OBJECT(filer_window->window), "focus_out_event",
1625 GTK_SIGNAL_FUNC(focus_out), filer_window);
1626 gtk_signal_connect(GTK_OBJECT(filer_window->window), "destroy",
1627 filer_window_destroyed, filer_window);
1629 gtk_signal_connect(GTK_OBJECT(filer_window->collection), "open_item",
1630 open_item, filer_window);
1631 gtk_signal_connect(GTK_OBJECT(collection), "show_menu",
1632 show_menu, filer_window);
1633 gtk_signal_connect(GTK_OBJECT(collection), "gain_selection",
1634 gain_selection, filer_window);
1635 gtk_signal_connect(GTK_OBJECT(collection), "lose_selection",
1636 lose_selection, filer_window);
1637 gtk_signal_connect(GTK_OBJECT(collection), "drag_selection",
1638 drag_selection, filer_window);
1639 gtk_signal_connect(GTK_OBJECT(collection), "drag_data_get",
1640 drag_data_get, filer_window);
1641 gtk_signal_connect(GTK_OBJECT(collection), "selection_clear_event",
1642 GTK_SIGNAL_FUNC(collection_lose_selection), NULL);
1643 gtk_signal_connect (GTK_OBJECT(collection), "selection_get",
1644 GTK_SIGNAL_FUNC(selection_get), NULL);
1645 gtk_selection_add_targets(collection, GDK_SELECTION_PRIMARY,
1646 target_table,
1647 sizeof(target_table) / sizeof(*target_table));
1649 filer_style_set(filer_window, last_display_style);
1650 drag_set_dest(filer_window);
1652 if (panel_type)
1654 int swidth, sheight, iwidth, iheight;
1655 GtkWidget *frame, *win = filer_window->window;
1657 gtk_window_set_wmclass(GTK_WINDOW(win), "ROX-Panel",
1658 PROJECT);
1659 collection_set_panel(filer_window->collection, TRUE);
1660 gtk_signal_connect(GTK_OBJECT(filer_window->window),
1661 "delete_event",
1662 GTK_SIGNAL_FUNC(filer_confirm_close),
1663 filer_window);
1665 gdk_window_get_size(GDK_ROOT_PARENT(), &swidth, &sheight);
1666 iwidth = filer_window->collection->item_width;
1667 iheight = filer_window->collection->item_height;
1670 int height = iheight + PANEL_BORDER;
1671 int y = panel_type == PANEL_TOP
1672 ? -PANEL_BORDER
1673 : sheight - height - PANEL_BORDER;
1675 gtk_widget_set_usize(collection, swidth, height);
1676 gtk_widget_set_uposition(win, 0, y);
1679 frame = gtk_frame_new(NULL);
1680 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
1681 gtk_container_add(GTK_CONTAINER(frame), collection);
1682 gtk_container_add(GTK_CONTAINER(win), frame);
1684 gtk_widget_show_all(frame);
1685 gtk_widget_realize(win);
1686 if (override_redirect)
1687 gdk_window_set_override_redirect(win->window, TRUE);
1688 make_panel_window(win->window);
1690 else
1692 GtkWidget *vbox;
1693 int col_height = ROW_HEIGHT_LARGE * 3;
1695 gtk_signal_connect(GTK_OBJECT(collection),
1696 "key_press_event",
1697 GTK_SIGNAL_FUNC(key_press_event), filer_window);
1698 gtk_window_set_default_size(GTK_WINDOW(filer_window->window),
1699 filer_window->display_style == LARGE_ICONS ? 400 : 512,
1700 o_toolbar == TOOLBAR_NONE ? col_height:
1701 o_toolbar == TOOLBAR_NORMAL ? col_height + 24 :
1702 col_height + 38);
1704 hbox = gtk_hbox_new(FALSE, 0);
1705 gtk_container_add(GTK_CONTAINER(filer_window->window),
1706 hbox);
1708 vbox = gtk_vbox_new(FALSE, 0);
1709 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
1711 if (o_toolbar != TOOLBAR_NONE)
1713 GtkWidget *toolbar;
1715 toolbar = create_toolbar(filer_window);
1716 gtk_box_pack_start(GTK_BOX(vbox), toolbar,
1717 FALSE, TRUE, 0);
1718 gtk_widget_show_all(toolbar);
1721 gtk_box_pack_start(GTK_BOX(vbox), collection, TRUE, TRUE, 0);
1723 create_minibuffer(filer_window);
1724 gtk_box_pack_start(GTK_BOX(vbox), filer_window->minibuffer_area,
1725 FALSE, TRUE, 0);
1727 scrollbar = gtk_vscrollbar_new(COLLECTION(collection)->vadj);
1728 gtk_box_pack_start(GTK_BOX(hbox), scrollbar, FALSE, TRUE, 0);
1729 gtk_accel_group_attach(filer_keys,
1730 GTK_OBJECT(filer_window->window));
1731 gtk_window_set_focus(GTK_WINDOW(filer_window->window),
1732 collection);
1734 gtk_widget_show(hbox);
1735 gtk_widget_show(vbox);
1736 gtk_widget_show(scrollbar);
1737 gtk_widget_show(collection);
1740 number_of_windows++;
1741 gtk_widget_show(filer_window->window);
1742 attach(filer_window);
1744 all_filer_windows = g_list_prepend(all_filer_windows, filer_window);
1746 return filer_window;
1749 static gint clear_scanning_display(FilerWindow *filer_window)
1751 if (filer_exists(filer_window))
1752 filer_set_title(filer_window);
1753 return FALSE;
1756 static void set_scanning_display(FilerWindow *filer_window, gboolean scanning)
1758 if (scanning == filer_window->scanning)
1759 return;
1760 filer_window->scanning = scanning;
1762 if (scanning)
1763 filer_set_title(filer_window);
1764 else
1765 gtk_timeout_add(300, (GtkFunction) clear_scanning_display,
1766 filer_window);
1769 static GtkWidget *create_toolbar(FilerWindow *filer_window)
1771 GtkWidget *frame, *box;
1773 if (o_toolbar == TOOLBAR_GNOME)
1775 frame = gtk_handle_box_new();
1776 box = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1777 GTK_TOOLBAR_BOTH);
1778 gtk_container_set_border_width(GTK_CONTAINER(box), 2);
1779 gtk_toolbar_set_space_style(GTK_TOOLBAR(box),
1780 GTK_TOOLBAR_SPACE_LINE);
1781 gtk_toolbar_set_button_relief(GTK_TOOLBAR(box),
1782 GTK_RELIEF_NONE);
1784 else
1786 frame = gtk_frame_new(NULL);
1787 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
1789 box = gtk_hbutton_box_new();
1790 gtk_button_box_set_child_size_default(16, 16);
1791 gtk_hbutton_box_set_spacing_default(2);
1792 gtk_button_box_set_layout(GTK_BUTTON_BOX(box),
1793 GTK_BUTTONBOX_START);
1796 gtk_container_add(GTK_CONTAINER(frame), box);
1798 add_button(box, TOOLBAR_UP_ICON,
1799 GTK_SIGNAL_FUNC(toolbar_up_clicked),
1800 filer_window,
1801 _("Up"), _("Change to parent directory"));
1802 add_button(box, TOOLBAR_HOME_ICON,
1803 GTK_SIGNAL_FUNC(toolbar_home_clicked),
1804 filer_window,
1805 _("Home"), _("Change to home directory"));
1806 add_button(box, TOOLBAR_REFRESH_ICON,
1807 GTK_SIGNAL_FUNC(toolbar_refresh_clicked),
1808 filer_window,
1809 _("Rescan"), _("Rescan directory contents"));
1811 return frame;
1814 /* This is used to simulate a click when button 3 is used (GtkButton
1815 * normally ignores this). Currently, this button does not pop in -
1816 * this may be fixed in future versions of GTK+.
1818 static gint toolbar_other_button = 0;
1819 static gint toolbar_adjust_pressed(GtkButton *button,
1820 GdkEventButton *event,
1821 FilerWindow *filer_window)
1823 gint b = event->button;
1825 if ((b == 2 || b == 3) && toolbar_other_button == 0)
1827 toolbar_other_button = event->button;
1828 gtk_grab_add(GTK_WIDGET(button));
1829 gtk_button_pressed(button);
1832 return TRUE;
1835 static gint toolbar_adjust_released(GtkButton *button,
1836 GdkEventButton *event,
1837 FilerWindow *filer_window)
1839 if (event->button == toolbar_other_button)
1841 toolbar_other_button = 0;
1842 gtk_grab_remove(GTK_WIDGET(button));
1843 gtk_button_released(button);
1846 return TRUE;
1849 static void add_button(GtkWidget *box, int pixmap,
1850 GtkSignalFunc cb, FilerWindow *filer_window,
1851 char *label, char *tip)
1853 GtkWidget *button, *icon;
1855 icon = gtk_pixmap_new(default_pixmap[pixmap]->pixmap,
1856 default_pixmap[pixmap]->mask);
1858 if (o_toolbar == TOOLBAR_GNOME)
1860 gtk_toolbar_append_element(GTK_TOOLBAR(box),
1861 GTK_TOOLBAR_CHILD_BUTTON,
1862 NULL,
1863 label,
1864 tip, NULL,
1865 icon,
1866 cb, filer_window);
1868 else
1870 button = gtk_button_new();
1871 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
1873 gtk_container_add(GTK_CONTAINER(button), icon);
1874 gtk_signal_connect(GTK_OBJECT(button), "button_press_event",
1875 GTK_SIGNAL_FUNC(toolbar_adjust_pressed), filer_window);
1876 gtk_signal_connect(GTK_OBJECT(button), "button_release_event",
1877 GTK_SIGNAL_FUNC(toolbar_adjust_released), filer_window);
1878 gtk_signal_connect(GTK_OBJECT(button), "clicked",
1879 cb, filer_window);
1881 gtk_tooltips_set_tip(tooltips, button, tip, NULL);
1883 gtk_container_add(GTK_CONTAINER(box), button);
1887 /* Build up some option widgets to go in the options dialog, but don't
1888 * fill them in yet.
1890 static GtkWidget *create_options()
1892 GtkWidget *vbox, *menu, *hbox, *slide;
1894 vbox = gtk_vbox_new(FALSE, 0);
1895 gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
1897 display_label = gtk_label_new("<>");
1898 gtk_label_set_line_wrap(GTK_LABEL(display_label), TRUE);
1899 gtk_box_pack_start(GTK_BOX(vbox), display_label, FALSE, TRUE, 0);
1901 toggle_sort_nocase =
1902 gtk_check_button_new_with_label(_("Ignore case when sorting"));
1903 gtk_box_pack_start(GTK_BOX(vbox), toggle_sort_nocase, FALSE, TRUE, 0);
1905 toggle_new_window_on_1 =
1906 gtk_check_button_new_with_label(
1907 _("New window on button 1 (RISC OS style)"));
1908 gtk_box_pack_start(GTK_BOX(vbox), toggle_new_window_on_1,
1909 FALSE, TRUE, 0);
1911 toggle_menu_on_2 =
1912 gtk_check_button_new_with_label(
1913 _("Menu on button 2 (RISC OS style)"));
1914 gtk_box_pack_start(GTK_BOX(vbox), toggle_menu_on_2, FALSE, TRUE, 0);
1916 toggle_single_click =
1917 gtk_check_button_new_with_label(_("Single-click nagivation"));
1918 gtk_box_pack_start(GTK_BOX(vbox), toggle_single_click, FALSE, TRUE, 0);
1920 toggle_unique_filer_windows =
1921 gtk_check_button_new_with_label(_("Unique windows"));
1922 gtk_box_pack_start(GTK_BOX(vbox), toggle_unique_filer_windows,
1923 FALSE, TRUE, 0);
1925 hbox = gtk_hbox_new(FALSE, 4);
1926 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
1928 gtk_box_pack_start(GTK_BOX(hbox),
1929 gtk_label_new(_("Toolbar type for new windows")),
1930 FALSE, TRUE, 0);
1931 menu_toolbar = gtk_option_menu_new();
1932 menu = gtk_menu_new();
1933 gtk_menu_append(GTK_MENU(menu),
1934 gtk_menu_item_new_with_label(_("None")));
1935 gtk_menu_append(GTK_MENU(menu),
1936 gtk_menu_item_new_with_label(_("Normal")));
1937 gtk_menu_append(GTK_MENU(menu),
1938 gtk_menu_item_new_with_label(_("GNOME")));
1939 gtk_option_menu_set_menu(GTK_OPTION_MENU(menu_toolbar), menu);
1940 gtk_box_pack_start(GTK_BOX(hbox), menu_toolbar, TRUE, TRUE, 0);
1942 hbox = gtk_hbox_new(FALSE, 4);
1943 gtk_box_pack_start(GTK_BOX(hbox),
1944 gtk_label_new(_("Max Large Icons width")),
1945 TRUE, TRUE, 0);
1946 adj_large_truncate = GTK_ADJUSTMENT(gtk_adjustment_new(0,
1947 MIN_TRUNCATE, MAX_TRUNCATE, 1, 10, 0));
1948 slide = gtk_hscale_new(adj_large_truncate);
1949 gtk_widget_set_usize(slide, MAX_TRUNCATE, 24);
1950 gtk_scale_set_draw_value(GTK_SCALE(slide), FALSE);
1951 gtk_box_pack_start(GTK_BOX(hbox), slide, FALSE, TRUE, 0);
1952 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
1954 hbox = gtk_hbox_new(FALSE, 4);
1955 gtk_box_pack_start(GTK_BOX(hbox),
1956 gtk_label_new(_("Max Small Icons width")),
1957 TRUE, TRUE, 0);
1958 adj_small_truncate = GTK_ADJUSTMENT(gtk_adjustment_new(0,
1959 MIN_TRUNCATE, MAX_TRUNCATE, 1, 10, 0));
1960 slide = gtk_hscale_new(adj_small_truncate);
1961 gtk_widget_set_usize(slide, MAX_TRUNCATE, 24);
1962 gtk_scale_set_draw_value(GTK_SCALE(slide), FALSE);
1963 gtk_box_pack_start(GTK_BOX(hbox), slide, FALSE, TRUE, 0);
1964 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
1966 return vbox;
1969 static void update_options_label(void)
1971 guchar *str;
1973 str = g_strdup_printf(_("The last used display style (%s) and sort "
1974 "function (Sort By %s) will be saved if you click on "
1975 "Save."), style_to_name(), sort_fn_to_name());
1976 gtk_label_set_text(GTK_LABEL(display_label), str);
1977 g_free(str);
1980 /* Reflect current state by changing the widgets in the options box */
1981 static void update_options()
1983 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_sort_nocase),
1984 o_sort_nocase);
1985 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_new_window_on_1),
1986 o_new_window_on_1);
1987 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_menu_on_2),
1988 collection_menu_button == 2 ? 1 : 0);
1989 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_single_click),
1990 o_single_click);
1991 gtk_toggle_button_set_active(
1992 GTK_TOGGLE_BUTTON(toggle_unique_filer_windows),
1993 o_unique_filer_windows);
1994 gtk_option_menu_set_history(GTK_OPTION_MENU(menu_toolbar), o_toolbar);
1996 gtk_adjustment_set_value(adj_small_truncate, o_small_truncate);
1997 gtk_adjustment_set_value(adj_large_truncate, o_large_truncate);
1999 update_options_label();
2002 /* Set current values by reading the states of the widgets in the options box */
2003 static void set_options()
2005 GtkWidget *item, *menu;
2006 GList *list;
2007 gboolean old_case = o_sort_nocase;
2008 GList *next = all_filer_windows;
2010 o_sort_nocase = gtk_toggle_button_get_active(
2011 GTK_TOGGLE_BUTTON(toggle_sort_nocase));
2013 o_new_window_on_1 = gtk_toggle_button_get_active(
2014 GTK_TOGGLE_BUTTON(toggle_new_window_on_1));
2016 collection_menu_button = gtk_toggle_button_get_active(
2017 GTK_TOGGLE_BUTTON(toggle_menu_on_2)) ? 2 : 3;
2019 o_single_click = gtk_toggle_button_get_active(
2020 GTK_TOGGLE_BUTTON(toggle_single_click));
2022 o_unique_filer_windows = gtk_toggle_button_get_active(
2023 GTK_TOGGLE_BUTTON(toggle_unique_filer_windows));
2025 collection_single_click = o_single_click ? TRUE : FALSE;
2027 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(menu_toolbar));
2028 item = gtk_menu_get_active(GTK_MENU(menu));
2029 list = gtk_container_children(GTK_CONTAINER(menu));
2030 o_toolbar = (ToolbarType) g_list_index(list, item);
2031 g_list_free(list);
2033 o_small_truncate = adj_small_truncate->value;
2034 o_large_truncate = adj_large_truncate->value;
2036 while (next)
2038 FilerWindow *filer_window = (FilerWindow *) next->data;
2040 if (o_sort_nocase != old_case)
2042 collection_qsort(filer_window->collection,
2043 filer_window->sort_fn);
2045 shrink_width(filer_window);
2047 next = next->next;
2051 static guchar *style_to_name(void)
2053 return last_display_style == LARGE_ICONS ? _("Large Icons") :
2054 last_display_style == SMALL_ICONS ? _("Small Icons") :
2055 _("Full Info");
2058 static guchar *sort_fn_to_name(void)
2060 return last_sort_fn == sort_by_name ? _("Name") :
2061 last_sort_fn == sort_by_type ? _("Type") :
2062 last_sort_fn == sort_by_date ? _("Date") :
2063 _("Size");
2066 static void save_options()
2068 guchar *tmp;
2070 option_write("filer_sort_nocase", o_sort_nocase ? "1" : "0");
2071 option_write("filer_new_window_on_1", o_new_window_on_1 ? "1" : "0");
2072 option_write("filer_menu_on_2",
2073 collection_menu_button == 2 ? "1" : "0");
2074 option_write("filer_single_click", o_single_click ? "1" : "0");
2075 option_write("filer_unique_windows",
2076 o_unique_filer_windows ? "1" : "0");
2077 option_write("filer_display_style",
2078 last_display_style == LARGE_ICONS ? "Large Icons" :
2079 last_display_style == SMALL_ICONS ? "Small Icons" :
2080 "Full Info");
2081 option_write("filer_sort_by",
2082 last_sort_fn == sort_by_name ? "Name" :
2083 last_sort_fn == sort_by_type ? "Type" :
2084 last_sort_fn == sort_by_date ? "Date" :
2085 "Size");
2086 option_write("filer_toolbar", o_toolbar == TOOLBAR_NONE ? "None" :
2087 o_toolbar == TOOLBAR_NORMAL ? "Normal" :
2088 o_toolbar == TOOLBAR_GNOME ? "GNOME" :
2089 "Unknown");
2091 tmp = g_strdup_printf("%d, %d", o_large_truncate, o_small_truncate);
2092 option_write("filer_truncate", tmp);
2093 g_free(tmp);
2096 static char *filer_sort_nocase(char *data)
2098 o_sort_nocase = atoi(data) != 0;
2099 return NULL;
2102 static char *filer_new_window_on_1(char *data)
2104 o_new_window_on_1 = atoi(data) != 0;
2105 return NULL;
2108 static char *filer_menu_on_2(char *data)
2110 collection_menu_button = atoi(data) != 0 ? 2 : 3;
2111 return NULL;
2114 static char *filer_single_click(char *data)
2116 o_single_click = atoi(data) != 0;
2117 collection_single_click = o_single_click ? TRUE : FALSE;
2118 return NULL;
2121 static char *filer_unique_windows(char *data)
2123 o_unique_filer_windows = atoi(data) != 0;
2124 return NULL;
2127 static char *filer_display_style(char *data)
2129 if (g_strcasecmp(data, "Large Icons") == 0)
2130 last_display_style = LARGE_ICONS;
2131 else if (g_strcasecmp(data, "Small Icons") == 0)
2132 last_display_style = SMALL_ICONS;
2133 else if (g_strcasecmp(data, "Full Info") == 0)
2134 last_display_style = FULL_INFO;
2135 else
2136 return _("Unknown display style");
2138 return NULL;
2141 static char *filer_sort_by(char *data)
2143 if (g_strcasecmp(data, "Name") == 0)
2144 last_sort_fn = sort_by_name;
2145 else if (g_strcasecmp(data, "Type") == 0)
2146 last_sort_fn = sort_by_type;
2147 else if (g_strcasecmp(data, "Date") == 0)
2148 last_sort_fn = sort_by_date;
2149 else if (g_strcasecmp(data, "Size") == 0)
2150 last_sort_fn = sort_by_size;
2151 else
2152 return _("Unknown sort type");
2154 return NULL;
2157 static char *filer_truncate(char *data)
2159 guchar *comma;
2161 comma = strchr(data, ',');
2162 if (!comma)
2163 return "Missing , in filer_truncate";
2165 o_large_truncate = CLAMP(atoi(data), MIN_TRUNCATE, MAX_TRUNCATE);
2166 o_small_truncate = CLAMP(atoi(comma + 1), MIN_TRUNCATE, MAX_TRUNCATE);
2168 return NULL;
2171 static char *filer_toolbar(char *data)
2173 if (g_strcasecmp(data, "None") == 0)
2174 o_toolbar = TOOLBAR_NONE;
2175 else if (g_strcasecmp(data, "Normal") == 0)
2176 o_toolbar = TOOLBAR_NORMAL;
2177 else if (g_strcasecmp(data, "GNOME") == 0)
2178 o_toolbar = TOOLBAR_GNOME;
2179 else
2180 return _("Unknown toolbar type");
2182 return NULL;
2185 /* Note that filer_window may not exist after this call. */
2186 void filer_update_dir(FilerWindow *filer_window, gboolean warning)
2188 if (may_rescan(filer_window, warning))
2189 dir_update(filer_window->directory, filer_window->path);
2192 void filer_set_hidden(FilerWindow *filer_window, gboolean hidden)
2194 Directory *dir = filer_window->directory;
2196 if (filer_window->show_hidden == hidden)
2197 return;
2199 filer_window->show_hidden = hidden;
2200 last_show_hidden = hidden;
2202 g_fscache_data_ref(dir_cache, dir);
2203 detach(filer_window);
2204 filer_window->directory = dir;
2205 attach(filer_window);
2208 /* Refresh the various caches even if we don't think we need to */
2209 void full_refresh(void)
2211 mount_update(TRUE);
2214 /* See whether a filer window with a given path already exists
2215 * and is different from diff.
2217 static FilerWindow *find_filer_window(char *path, FilerWindow *diff)
2219 GList *next = all_filer_windows;
2221 while (next)
2223 FilerWindow *filer_window = (FilerWindow *) next->data;
2225 if (filer_window->panel_type == PANEL_NO &&
2226 filer_window != diff &&
2227 strcmp(path, filer_window->path) == 0)
2229 return filer_window;
2232 next = next->next;
2235 return NULL;
2238 /* This path has been mounted/umounted/deleted some files - update all dirs */
2239 void filer_check_mounted(char *path)
2241 GList *next = all_filer_windows;
2242 int len;
2244 len = strlen(path);
2246 while (next)
2248 FilerWindow *filer_window = (FilerWindow *) next->data;
2250 next = next->next;
2252 if (strncmp(path, filer_window->path, len) == 0)
2254 char s = filer_window->path[len];
2256 if (s == '/' || s == '\0')
2257 filer_update_dir(filer_window, FALSE);
2262 /* Like minibuffer_show(), except that:
2263 * - It returns FALSE (to be used from an idle callback)
2264 * - It checks that the filer window still exists.
2266 static gboolean minibuffer_show_cb(FilerWindow *filer_window)
2268 if (filer_exists(filer_window))
2269 minibuffer_show(filer_window, MINI_PATH);
2270 return FALSE;
2273 gboolean filer_exists(FilerWindow *filer_window)
2275 GList *next;
2277 for (next = all_filer_windows; next; next = next->next)
2279 FilerWindow *fw = (FilerWindow *) next->data;
2281 if (fw == filer_window)
2282 return TRUE;
2285 return FALSE;
2288 /* Highlight (wink or cursor) this item in the filer window. If the item
2289 * isn't already there but we're scanning then highlight it if it
2290 * appears later.
2292 void filer_set_autoselect(FilerWindow *filer_window, guchar *leaf)
2294 Collection *col = filer_window->collection;
2295 int i;
2297 g_free(filer_window->auto_select);
2298 filer_window->auto_select = NULL;
2300 for (i = 0; i < col->number_of_items; i++)
2302 DirItem *item = (DirItem *) col->items[i].data;
2304 if (strcmp(item->leafname, leaf) == 0)
2306 if (col->cursor_item != -1)
2307 collection_set_cursor_item(col, i);
2308 else
2309 collection_wink_item(col, i);
2310 return;
2314 filer_window->auto_select = g_strdup(leaf);
2317 static void filer_set_title(FilerWindow *filer_window)
2319 if (filer_window->scanning)
2321 guchar *title;
2323 title = g_strdup_printf(_("%s (Scanning)"), filer_window->path);
2324 gtk_window_set_title(GTK_WINDOW(filer_window->window),
2325 title);
2326 g_free(title);
2328 else
2329 gtk_window_set_title(GTK_WINDOW(filer_window->window),
2330 filer_window->path);