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)
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
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 */
30 #include <sys/param.h>
37 #include <gdk/gdkkeysyms.h>
38 #include "collection.h"
42 #include "gui_support.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
59 # define SMALL_ICON_WIDTH 24
61 # define SMALL_ICON_WIDTH 48
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
;
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"),
111 /* The values correspond to the menu indexes in the option widget */
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
, MaskedPixmap
*icon
,
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
,
163 static void draw_string(GtkWidget
*widget
,
171 static void draw_item_large(GtkWidget
*widget
,
172 CollectionItem
*item
,
174 static void draw_item_small(GtkWidget
*widget
,
175 CollectionItem
*item
,
177 static void draw_item_full_info(GtkWidget
*widget
,
178 CollectionItem
*colitem
,
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
,
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
,
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
;
213 static GdkCursor
*busy_cursor
= NULL
;
214 static GtkTooltips
*tooltips
= NULL
;
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
;
244 if (strcmp(leafname
, r
[i
]->leafname
) == 0)
251 static void update_item(FilerWindow
*filer_window
, DirItem
*item
)
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'))
263 i
= collection_find_item(filer_window
->collection
, item
, dir_item_cmp
);
266 collection_draw_item(filer_window
->collection
, i
, TRUE
);
268 g_warning("Failed to find '%s'\n", item
->leafname
);
271 static void update_display(Directory
*dir
,
274 FilerWindow
*filer_window
)
278 int cursor
= filer_window
->collection
->cursor_item
;
280 Collection
*collection
= filer_window
->collection
;
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
)
297 if (strcmp(as
, item
->leafname
) != 0)
300 cursor
= collection
->number_of_items
- 1;
301 if (filer_window
->had_cursor
)
303 collection_set_cursor_item(collection
,
305 filer_window
->mini_cursor_base
= cursor
;
308 collection_wink_item(collection
,
312 if (old_num
!= collection
->number_of_items
)
313 collection_qsort(filer_window
->collection
,
314 filer_window
->sort_fn
);
317 collection_delete_if(filer_window
->collection
,
322 set_scanning_display(filer_window
, TRUE
);
325 if (filer_window
->window
->window
)
326 gdk_window_set_cursor(
327 filer_window
->window
->window
,
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
);
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
);
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
,
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)
392 static int calc_width(FilerWindow
*filer_window
, DirItem
*item
)
394 int pix_width
= item
->image
->width
;
397 switch (filer_window
->display_style
)
400 return MAX_ICON_WIDTH
+ 12 +
401 MAX(item
->details_width
, item
->name_width
);
403 return SMALL_ICON_WIDTH
+ 12 + item
->name_width
;
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
;
416 if (leafname
[0] == '.')
418 if (filer_window
->show_hidden
== FALSE
|| leafname
[1] == '\0'
419 || (leafname
[1] == '.' && leafname
[2] == '\0'))
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
,
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;
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
;
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
);
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
;
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
);
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
;
503 static void draw_small_icon(GtkWidget
*widget
,
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
;
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 */
535 gdk_gc_set_function(gc
, GDK_INVERT
);
536 gdk_draw_rectangle(widget
->window
,
538 TRUE
, image_x
, area
->y
+ image_y
,
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
, im_symlink
->mask
);
547 gdk_draw_pixmap(widget
->window
, gc
, im_symlink
->pixmap
,
548 0, 0, /* Source x,y */
549 image_x
, area
->y
+ 8, /* Dest x,y */
552 else if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
554 MaskedPixmap
*mp
= item
->flags
& ITEM_FLAG_MOUNTED
559 pixmap_make_small(mp
);
560 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ 8);
561 gdk_gc_set_clip_mask(gc
, mp
->sm_mask
);
562 gdk_draw_pixmap(widget
->window
, gc
,
564 0, 0, /* Source x,y */
565 image_x
, area
->y
+ 8, /* Dest x,y */
569 gdk_gc_set_clip_mask(gc
, NULL
);
570 gdk_gc_set_clip_origin(gc
, 0, 0);
573 static void draw_large_icon(GtkWidget
*widget
,
578 MaskedPixmap
*image
= item
->image
;
579 int width
= MIN(image
->width
, MAX_ICON_WIDTH
);
580 int height
= MIN(image
->height
, MAX_ICON_WIDTH
);
581 int image_x
= area
->x
+ ((area
->width
- width
) >> 1);
583 GdkGC
*gc
= selected
? widget
->style
->white_gc
584 : widget
->style
->black_gc
;
586 gdk_gc_set_clip_mask(gc
, item
->image
->mask
);
588 image_y
= MAX(0, MAX_ICON_HEIGHT
- image
->height
);
589 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ image_y
);
590 gdk_draw_pixmap(widget
->window
, gc
,
592 0, 0, /* Source x,y */
593 image_x
, area
->y
+ image_y
, /* Dest x,y */
598 gdk_gc_set_function(gc
, GDK_INVERT
);
599 gdk_draw_rectangle(widget
->window
,
601 TRUE
, image_x
, area
->y
+ image_y
,
603 gdk_gc_set_function(gc
, GDK_COPY
);
606 if (item
->flags
& ITEM_FLAG_SYMLINK
)
608 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ 8);
609 gdk_gc_set_clip_mask(gc
, im_symlink
->mask
);
610 gdk_draw_pixmap(widget
->window
, gc
, im_symlink
->pixmap
,
611 0, 0, /* Source x,y */
612 image_x
, area
->y
+ 8, /* Dest x,y */
615 else if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
617 MaskedPixmap
*mp
= item
->flags
& ITEM_FLAG_MOUNTED
621 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ 8);
622 gdk_gc_set_clip_mask(gc
, mp
->mask
);
623 gdk_draw_pixmap(widget
->window
, gc
, mp
->pixmap
,
624 0, 0, /* Source x,y */
625 image_x
, area
->y
+ 8, /* Dest x,y */
629 gdk_gc_set_clip_mask(gc
, NULL
);
630 gdk_gc_set_clip_origin(gc
, 0, 0);
633 static void draw_string(GtkWidget
*widget
,
642 int text_height
= font
->ascent
+ font
->descent
;
644 GdkGC
*gc
= selected
? widget
->style
->white_gc
645 : widget
->style
->black_gc
;
648 gtk_paint_flat_box(widget
->style
, widget
->window
,
649 GTK_STATE_SELECTED
, GTK_SHADOW_NONE
,
650 NULL
, widget
, "text",
652 MIN(width
, area_width
),
655 if (width
> area_width
)
658 clip
.y
= y
- font
->ascent
;
659 clip
.width
= area_width
;
660 clip
.height
= text_height
;
661 gdk_gc_set_clip_origin(gc
, 0, 0);
662 gdk_gc_set_clip_rectangle(gc
, &clip
);
665 gdk_draw_text(widget
->window
,
669 string
, strlen(string
));
671 if (width
> area_width
)
675 red_gc
= gdk_gc_new(widget
->window
);
676 gdk_gc_set_foreground(red_gc
, &red
);
678 gdk_draw_rectangle(widget
->window
, red_gc
, TRUE
,
679 x
+ area_width
- 1, clip
.y
, 1, text_height
);
680 gdk_gc_set_clip_rectangle(gc
, NULL
);
684 /* Return a string (valid until next call) giving details
687 char *details(DirItem
*item
)
689 mode_t m
= item
->mode
;
690 static guchar
*buf
= NULL
;
695 if (item
->lstat_errno
)
696 buf
= g_strdup_printf(_("lstat(2) failed: %s"),
697 g_strerror(item
->lstat_errno
));
699 buf
= g_strdup_printf("%s %s %-8.8s %-8.8s %s %s",
700 item
->flags
& ITEM_FLAG_APPDIR
? "App " :
701 S_ISDIR(m
) ? "Dir " :
702 S_ISCHR(m
) ? "Char" :
703 S_ISBLK(m
) ? "Blck" :
704 S_ISLNK(m
) ? "Link" :
705 S_ISSOCK(m
) ? "Sock" :
706 S_ISFIFO(m
) ? "Pipe" : "File",
707 pretty_permissions(m
),
708 user_name(item
->uid
),
709 group_name(item
->gid
),
710 format_size_aligned(item
->size
),
711 pretty_time(&item
->mtime
));
715 static void draw_item_full_info(GtkWidget
*widget
,
716 CollectionItem
*colitem
,
719 DirItem
*item
= (DirItem
*) colitem
->data
;
720 MaskedPixmap
*image
= item
->image
;
721 int text_x
= area
->x
+ MAX_ICON_WIDTH
+ 8;
722 int low_text_y
= area
->y
+ area
->height
- fixed_font
->descent
- 2;
723 gboolean selected
= colitem
->selected
;
724 GdkRectangle pic_area
;
725 int text_area_width
= area
->width
- (text_x
- area
->x
);
727 pic_area
.x
= area
->x
;
728 pic_area
.y
= area
->y
;
729 pic_area
.width
= image
->width
+ 8;
730 pic_area
.height
= area
->height
;
732 draw_large_icon(widget
, &pic_area
, item
, selected
);
738 low_text_y
- item_font
->descent
- fixed_font
->ascent
,
750 if (item
->lstat_errno
)
753 /* Underline the effective permissions */
754 gdk_draw_rectangle(widget
->window
,
755 selected
? widget
->style
->white_gc
756 : widget
->style
->black_gc
,
758 text_x
- 1 + fixed_width
*
759 (5 + 4 * applicable(item
->uid
, item
->gid
)),
760 low_text_y
+ fixed_font
->descent
- 1,
761 fixed_width
* 3 + 1, 1);
764 static void draw_item_small(GtkWidget
*widget
,
765 CollectionItem
*colitem
,
768 DirItem
*item
= (DirItem
*) colitem
->data
;
769 int text_x
= area
->x
+ SMALL_ICON_WIDTH
+ 4;
770 int low_text_y
= area
->y
+ area
->height
- item_font
->descent
- 2;
771 gboolean selected
= colitem
->selected
;
772 GdkRectangle pic_area
;
774 pic_area
.x
= area
->x
;
775 pic_area
.y
= area
->y
;
776 pic_area
.width
= SMALL_ICON_WIDTH
;
777 pic_area
.height
= SMALL_ICON_HEIGHT
;
779 draw_small_icon(widget
, &pic_area
, item
, selected
);
787 area
->width
- (text_x
- area
->x
),
791 static void draw_item_large(GtkWidget
*widget
,
792 CollectionItem
*colitem
,
795 DirItem
*item
= (DirItem
*) colitem
->data
;
796 int text_width
= item
->name_width
;
797 int text_x
= area
->x
+ ((area
->width
- text_width
) >> 1);
798 int text_y
= area
->y
+ area
->height
- item_font
->descent
- 2;
799 gboolean selected
= colitem
->selected
;
801 draw_large_icon(widget
, area
, item
, selected
);
803 if (text_x
< area
->x
)
815 static void show_menu(Collection
*collection
, GdkEventButton
*event
,
816 int item
, gpointer user_data
)
818 show_filer_menu((FilerWindow
*) user_data
, event
, item
);
821 /* Returns TRUE iff the directory still exists. */
822 static gboolean
may_rescan(FilerWindow
*filer_window
, gboolean warning
)
826 g_return_val_if_fail(filer_window
!= NULL
, FALSE
);
828 /* We do a fresh lookup (rather than update) because the inode may
831 dir
= g_fscache_lookup(dir_cache
, filer_window
->path
);
835 delayed_error(PROJECT
, _("Directory missing/deleted"));
836 gtk_widget_destroy(filer_window
->window
);
839 if (dir
== filer_window
->directory
)
840 g_fscache_data_unref(dir_cache
, dir
);
843 detach(filer_window
);
844 filer_window
->directory
= dir
;
845 attach(filer_window
);
851 /* Another app has grabbed the selection */
852 static gint
collection_lose_selection(GtkWidget
*widget
,
853 GdkEventSelection
*event
)
855 if (window_with_selection
&&
856 window_with_selection
->collection
== COLLECTION(widget
))
858 FilerWindow
*filer_window
= window_with_selection
;
859 window_with_selection
= NULL
;
860 collection_clear_selection(filer_window
->collection
);
866 /* Someone wants us to send them the selection */
867 static void selection_get(GtkWidget
*widget
,
868 GtkSelectionData
*selection_data
,
873 GString
*reply
, *header
;
874 FilerWindow
*filer_window
;
876 Collection
*collection
;
878 filer_window
= gtk_object_get_data(GTK_OBJECT(widget
), "filer_window");
880 reply
= g_string_new(NULL
);
881 header
= g_string_new(NULL
);
886 g_string_sprintf(header
, " %s",
887 make_path(filer_window
->path
, "")->str
);
889 case TARGET_URI_LIST
:
890 g_string_sprintf(header
, " file://%s%s",
892 make_path(filer_window
->path
, "")->str
);
896 collection
= filer_window
->collection
;
897 for (i
= 0; i
< collection
->number_of_items
; i
++)
899 if (collection
->items
[i
].selected
)
902 (DirItem
*) collection
->items
[i
].data
;
904 g_string_append(reply
, header
->str
);
905 g_string_append(reply
, item
->leafname
);
908 /* This works, but I don't think I like it... */
909 /* g_string_append_c(reply, ' '); */
911 gtk_selection_data_set(selection_data
, xa_string
,
912 8, reply
->str
+ 1, reply
->len
- 1);
913 g_string_free(reply
, TRUE
);
914 g_string_free(header
, TRUE
);
917 /* No items are now selected. This might be because another app claimed
918 * the selection or because the user unselected all the items.
920 static void lose_selection(Collection
*collection
,
924 FilerWindow
*filer_window
= (FilerWindow
*) user_data
;
926 if (window_with_selection
== filer_window
)
928 window_with_selection
= NULL
;
929 gtk_selection_owner_set(NULL
,
930 GDK_SELECTION_PRIMARY
,
935 static void gain_selection(Collection
*collection
,
939 FilerWindow
*filer_window
= (FilerWindow
*) user_data
;
941 if (gtk_selection_owner_set(GTK_WIDGET(collection
),
942 GDK_SELECTION_PRIMARY
,
945 window_with_selection
= filer_window
;
948 collection_clear_selection(filer_window
->collection
);
951 int sort_by_name(const void *item1
, const void *item2
)
954 return g_strcasecmp((*((DirItem
**)item1
))->leafname
,
955 (*((DirItem
**)item2
))->leafname
);
956 return strcmp((*((DirItem
**)item1
))->leafname
,
957 (*((DirItem
**)item2
))->leafname
);
960 int sort_by_type(const void *item1
, const void *item2
)
962 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
963 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
966 int diff
= i1
->base_type
- i2
->base_type
;
969 diff
= (i1
->flags
& ITEM_FLAG_APPDIR
)
970 - (i2
->flags
& ITEM_FLAG_APPDIR
);
972 return diff
> 0 ? 1 : -1;
979 diff
= strcmp(m1
->media_type
, m2
->media_type
);
981 diff
= strcmp(m1
->subtype
, m2
->subtype
);
989 return diff
> 0 ? 1 : -1;
991 return sort_by_name(item1
, item2
);
994 int sort_by_date(const void *item1
, const void *item2
)
996 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
997 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
999 return i1
->mtime
> i2
->mtime
? -1 :
1000 i1
->mtime
< i2
->mtime
? 1 :
1001 sort_by_name(item1
, item2
);
1004 int sort_by_size(const void *item1
, const void *item2
)
1006 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
1007 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
1009 return i1
->size
> i2
->size
? -1 :
1010 i1
->size
< i2
->size
? 1 :
1011 sort_by_name(item1
, item2
);
1014 static void open_item(Collection
*collection
,
1015 gpointer item_data
, int item_number
,
1018 FilerWindow
*filer_window
= (FilerWindow
*) user_data
;
1020 GdkEventButton
*bevent
;
1021 GdkEventKey
*kevent
;
1022 OpenFlags flags
= 0;
1024 event
= (GdkEvent
*) gtk_get_current_event();
1026 bevent
= (GdkEventButton
*) event
;
1027 kevent
= (GdkEventKey
*) event
;
1029 switch (event
->type
)
1031 case GDK_2BUTTON_PRESS
:
1032 case GDK_BUTTON_PRESS
:
1033 case GDK_BUTTON_RELEASE
:
1034 if (bevent
->state
& GDK_SHIFT_MASK
)
1035 flags
|= OPEN_SHIFT
;
1037 if (o_new_window_on_1
^ (bevent
->button
== 1))
1038 flags
|= OPEN_SAME_WINDOW
;
1040 if (bevent
->button
!= 1)
1041 flags
|= OPEN_CLOSE_WINDOW
;
1043 if (o_single_click
== FALSE
&&
1044 (bevent
->state
& GDK_CONTROL_MASK
) != 0)
1045 flags
^= OPEN_SAME_WINDOW
| OPEN_CLOSE_WINDOW
;
1048 flags
|= OPEN_SAME_WINDOW
;
1049 if (kevent
->state
& GDK_SHIFT_MASK
)
1050 flags
|= OPEN_SHIFT
;
1056 filer_openitem(filer_window
, item_number
, flags
);
1059 /* Return the full path to the directory containing object 'path'.
1060 * Relative paths are resolved from the filerwindow's path.
1062 static void follow_symlink(FilerWindow
*filer_window
, char *path
,
1063 gboolean same_window
)
1069 path
= make_path(filer_window
->path
, path
)->str
;
1071 real
= pathdup(path
);
1072 slash
= strrchr(real
, '/');
1076 delayed_error(PROJECT
,
1077 _("Broken symlink (or you don't have permission "
1089 if (filer_window
->panel_type
|| !same_window
)
1093 new = filer_opendir(new_dir
, PANEL_NO
);
1094 filer_set_autoselect(new, slash
+ 1);
1097 filer_change_to(filer_window
, new_dir
, slash
+ 1);
1102 /* Open the item (or add it to the shell command minibuffer) */
1103 void filer_openitem(FilerWindow
*filer_window
, int item_number
, OpenFlags flags
)
1105 gboolean shift
= (flags
& OPEN_SHIFT
) != 0;
1106 gboolean close_mini
= flags
& OPEN_FROM_MINI
;
1107 gboolean same_window
= (flags
& OPEN_SAME_WINDOW
) != 0
1108 && !filer_window
->panel_type
;
1109 gboolean close_window
= (flags
& OPEN_CLOSE_WINDOW
) != 0
1110 && !filer_window
->panel_type
;
1113 DirItem
*item
= (DirItem
*)
1114 filer_window
->collection
->items
[item_number
].data
;
1115 gboolean wink
= TRUE
, destroy
= FALSE
;
1117 widget
= filer_window
->window
;
1118 if (filer_window
->mini_type
== MINI_SHELL
)
1120 minibuffer_add(filer_window
, item
->leafname
);
1124 full_path
= make_path(filer_window
->path
,
1125 item
->leafname
)->str
;
1127 if (item
->flags
& ITEM_FLAG_SYMLINK
&& shift
)
1129 char path
[MAXPATHLEN
+ 1];
1132 got
= readlink(make_path(filer_window
->path
,
1133 item
->leafname
)->str
,
1136 delayed_error(PROJECT
, g_strerror(errno
));
1139 g_return_if_fail(got
<= MAXPATHLEN
);
1142 follow_symlink(filer_window
, path
,
1143 flags
& OPEN_SAME_WINDOW
);
1148 switch (item
->base_type
)
1150 case TYPE_DIRECTORY
:
1151 if (item
->flags
& ITEM_FLAG_APPDIR
&& !shift
)
1153 run_app(make_path(filer_window
->path
,
1154 item
->leafname
)->str
);
1160 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
&& shift
)
1162 action_mount(filer_window
, item
);
1163 if (item
->flags
& ITEM_FLAG_MOUNTED
)
1170 filer_change_to(filer_window
, full_path
, NULL
);
1174 filer_opendir(full_path
, PANEL_NO
);
1177 if ((item
->flags
& ITEM_FLAG_EXEC_FILE
) && !shift
)
1179 char *argv
[] = {NULL
, NULL
};
1181 argv
[0] = full_path
;
1183 if (spawn_full(argv
, filer_window
->path
))
1189 report_error(PROJECT
,
1190 _("Failed to fork() child"));
1195 MIME_type
*type
= shift
? &text_plain
1198 g_return_if_fail(type
!= NULL
);
1200 if (type_open(full_path
, type
))
1207 message
= g_string_new(NULL
);
1208 g_string_sprintf(message
,
1209 _("No run action specified for files of this type (%s/%s) - "
1210 "you can set a run action using by choosing `Set Run Action' "
1211 "from the Window menu"),
1214 report_error(PROJECT
, message
->str
);
1215 g_string_free(message
, TRUE
);
1220 report_error("open_item",
1221 "I don't know how to open that");
1226 gtk_widget_destroy(filer_window
->window
);
1230 collection_wink_item(filer_window
->collection
,
1233 minibuffer_hide(filer_window
);
1237 static gint
pointer_in(GtkWidget
*widget
,
1238 GdkEventCrossing
*event
,
1239 FilerWindow
*filer_window
)
1241 may_rescan(filer_window
, TRUE
);
1245 static gint
focus_in(GtkWidget
*widget
,
1246 GdkEventFocus
*event
,
1247 FilerWindow
*filer_window
)
1249 window_with_focus
= filer_window
;
1254 static gint
focus_out(GtkWidget
*widget
,
1255 GdkEventFocus
*event
,
1256 FilerWindow
*filer_window
)
1258 /* TODO: Shade the cursor */
1263 /* Handle keys that can't be bound with the menu */
1264 static gint
key_press_event(GtkWidget
*widget
,
1266 FilerWindow
*filer_window
)
1268 switch (event
->keyval
)
1271 change_to_parent(filer_window
);
1280 static void toolbar_help_clicked(GtkWidget
*widget
, FilerWindow
*filer_window
)
1282 filer_opendir(make_path(getenv("APP_DIR"), "Help")->str
, PANEL_NO
);
1285 static void toolbar_refresh_clicked(GtkWidget
*widget
,
1286 FilerWindow
*filer_window
)
1290 event
= gtk_get_current_event();
1291 if (event
->type
== GDK_BUTTON_RELEASE
&&
1292 ((GdkEventButton
*) event
)->button
!= 1)
1294 filer_opendir(filer_window
->path
, PANEL_NO
);
1299 filer_update_dir(filer_window
, TRUE
);
1303 static void toolbar_home_clicked(GtkWidget
*widget
, FilerWindow
*filer_window
)
1307 event
= gtk_get_current_event();
1308 if (event
->type
== GDK_BUTTON_RELEASE
&&
1309 ((GdkEventButton
*) event
)->button
!= 1)
1311 filer_opendir(home_dir
, PANEL_NO
);
1314 filer_change_to(filer_window
, home_dir
, NULL
);
1317 static void toolbar_up_clicked(GtkWidget
*widget
, FilerWindow
*filer_window
)
1321 event
= gtk_get_current_event();
1322 if (event
->type
== GDK_BUTTON_RELEASE
&&
1323 ((GdkEventButton
*) event
)->button
!= 1)
1325 filer_open_parent(filer_window
);
1328 change_to_parent(filer_window
);
1331 void change_to_parent(FilerWindow
*filer_window
)
1336 if (filer_window
->path
[0] == '/' && filer_window
->path
[1] == '\0')
1337 return; /* Already in the root */
1339 copy
= g_strdup(filer_window
->path
);
1340 slash
= strrchr(copy
, '/');
1345 filer_change_to(filer_window
,
1350 g_warning("No / in directory path!\n");
1356 /* Make filer_window display path. When finished, highlight item 'from', or
1357 * the first item if from is NULL. If there is currently no cursor then
1358 * simply wink 'from' (if not NULL).
1360 void filer_change_to(FilerWindow
*filer_window
, char *path
, char *from
)
1363 char *real_path
= pathdup(path
);
1365 if (o_unique_filer_windows
)
1369 fw
= find_filer_window(real_path
, filer_window
);
1371 gtk_widget_destroy(fw
->window
);
1374 from_dup
= from
&& *from
? g_strdup(from
) : NULL
;
1376 detach(filer_window
);
1377 g_free(filer_window
->path
);
1378 filer_window
->path
= real_path
;
1380 filer_window
->directory
= g_fscache_lookup(dir_cache
,
1381 filer_window
->path
);
1382 if (filer_window
->directory
)
1384 g_free(filer_window
->auto_select
);
1385 filer_window
->had_cursor
=
1386 filer_window
->collection
->cursor_item
!= -1
1387 || filer_window
->had_cursor
;
1388 filer_window
->auto_select
= from_dup
;
1390 filer_set_title(filer_window
);
1391 collection_set_cursor_item(filer_window
->collection
, -1);
1392 attach(filer_window
);
1394 if (filer_window
->mini_type
== MINI_PATH
)
1395 gtk_idle_add((GtkFunction
) minibuffer_show_cb
,
1403 error
= g_strdup_printf(_("Directory '%s' is not accessible"),
1405 delayed_error(PROJECT
, error
);
1407 gtk_widget_destroy(filer_window
->window
);
1411 void filer_open_parent(FilerWindow
*filer_window
)
1416 if (filer_window
->path
[0] == '/' && filer_window
->path
[1] == '\0')
1417 return; /* Already in the root */
1419 copy
= g_strdup(filer_window
->path
);
1420 slash
= strrchr(copy
, '/');
1425 filer_opendir(*copy
? copy
: "/", PANEL_NO
);
1428 g_warning("No / in directory path!\n");
1433 int selected_item_number(Collection
*collection
)
1437 g_return_val_if_fail(collection
!= NULL
, -1);
1438 g_return_val_if_fail(IS_COLLECTION(collection
), -1);
1439 g_return_val_if_fail(collection
->number_selected
== 1, -1);
1441 for (i
= 0; i
< collection
->number_of_items
; i
++)
1442 if (collection
->items
[i
].selected
)
1445 g_warning("selected_item: number_selected is wrong\n");
1450 DirItem
*selected_item(Collection
*collection
)
1454 item
= selected_item_number(collection
);
1457 return (DirItem
*) collection
->items
[item
].data
;
1461 static int filer_confirm_close(GtkWidget
*widget
, GdkEvent
*event
,
1462 FilerWindow
*window
)
1464 /* TODO: We can open lots of these - very irritating! */
1465 return get_choice(_("Close panel?"),
1466 _("You have tried to close a panel via the window "
1467 "manager - I usually find that this is accidental... "
1469 2, _("Remove"), _("Cancel")) != 0;
1472 /* Make the items as narrow as possible */
1473 static void shrink_width(FilerWindow
*filer_window
)
1476 Collection
*col
= filer_window
->collection
;
1477 int width
= MIN_ITEM_WIDTH
;
1479 DisplayStyle style
= filer_window
->display_style
;
1482 text_height
= item_font
->ascent
+ item_font
->descent
;
1484 for (i
= 0; i
< col
->number_of_items
; i
++)
1486 this_width
= calc_width(filer_window
,
1487 (DirItem
*) col
->items
[i
].data
);
1488 if (this_width
> width
)
1492 collection_set_item_size(filer_window
->collection
,
1494 style
== FULL_INFO
? MAX_ICON_HEIGHT
+ 4 :
1495 style
== SMALL_ICONS
? MAX(text_height
, SMALL_ICON_HEIGHT
) + 4
1496 : text_height
+ MAX_ICON_HEIGHT
+ 8);
1499 void filer_set_sort_fn(FilerWindow
*filer_window
,
1500 int (*fn
)(const void *a
, const void *b
))
1502 if (filer_window
->sort_fn
== fn
)
1505 filer_window
->sort_fn
= fn
;
1508 collection_qsort(filer_window
->collection
,
1509 filer_window
->sort_fn
);
1511 update_options_label();
1514 void filer_style_set(FilerWindow
*filer_window
, DisplayStyle style
)
1516 if (filer_window
->display_style
== style
)
1519 if (filer_window
->panel_type
)
1520 style
= LARGE_ICONS
;
1522 last_display_style
= style
;
1524 filer_window
->display_style
= style
;
1529 collection_set_functions(filer_window
->collection
,
1530 draw_item_small
, test_point_small
);
1533 collection_set_functions(filer_window
->collection
,
1534 draw_item_full_info
, test_point_full_info
);
1537 collection_set_functions(filer_window
->collection
,
1538 draw_item_large
, test_point_large
);
1542 shrink_width(filer_window
);
1544 update_options_label();
1547 FilerWindow
*filer_opendir(char *path
, PanelType panel_type
)
1549 GtkWidget
*hbox
, *scrollbar
, *collection
;
1550 FilerWindow
*filer_window
;
1551 GtkTargetEntry target_table
[] =
1553 {"text/uri-list", 0, TARGET_URI_LIST
},
1554 {"STRING", 0, TARGET_STRING
},
1558 real_path
= pathdup(path
);
1560 if (o_unique_filer_windows
&& panel_type
== PANEL_NO
)
1564 fw
= find_filer_window(real_path
, NULL
);
1568 /* TODO: this should bring the window to the front
1569 * at the same coordinates.
1571 gtk_widget_hide(fw
->window
);
1572 gtk_widget_show(fw
->window
);
1578 filer_window
= g_new(FilerWindow
, 1);
1579 filer_window
->minibuffer
= NULL
;
1580 filer_window
->minibuffer_label
= NULL
;
1581 filer_window
->minibuffer_area
= NULL
;
1582 filer_window
->path
= real_path
;
1583 filer_window
->scanning
= FALSE
;
1584 filer_window
->had_cursor
= FALSE
;
1585 filer_window
->auto_select
= NULL
;
1586 filer_window
->mini_type
= MINI_NONE
;
1588 filer_window
->directory
= g_fscache_lookup(dir_cache
,
1589 filer_window
->path
);
1590 if (!filer_window
->directory
)
1594 error
= g_strdup_printf(_("Directory '%s' not found."), path
);
1595 delayed_error(PROJECT
, error
);
1597 g_free(filer_window
->path
);
1598 g_free(filer_window
);
1602 filer_window
->show_hidden
= last_show_hidden
;
1603 filer_window
->panel_type
= panel_type
;
1604 filer_window
->temp_item_selected
= FALSE
;
1605 filer_window
->sort_fn
= last_sort_fn
;
1606 filer_window
->flags
= (FilerFlags
) 0;
1607 filer_window
->display_style
= UNKNOWN_STYLE
;
1609 filer_window
->window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
1610 filer_set_title(filer_window
);
1612 collection
= collection_new(NULL
);
1613 gtk_object_set_data(GTK_OBJECT(collection
),
1614 "filer_window", filer_window
);
1615 filer_window
->collection
= COLLECTION(collection
);
1617 gtk_widget_add_events(filer_window
->window
, GDK_ENTER_NOTIFY
);
1618 gtk_signal_connect(GTK_OBJECT(filer_window
->window
),
1619 "enter-notify-event",
1620 GTK_SIGNAL_FUNC(pointer_in
), filer_window
);
1621 gtk_signal_connect(GTK_OBJECT(filer_window
->window
), "focus_in_event",
1622 GTK_SIGNAL_FUNC(focus_in
), filer_window
);
1623 gtk_signal_connect(GTK_OBJECT(filer_window
->window
), "focus_out_event",
1624 GTK_SIGNAL_FUNC(focus_out
), filer_window
);
1625 gtk_signal_connect(GTK_OBJECT(filer_window
->window
), "destroy",
1626 filer_window_destroyed
, filer_window
);
1628 gtk_signal_connect(GTK_OBJECT(filer_window
->collection
), "open_item",
1629 open_item
, filer_window
);
1630 gtk_signal_connect(GTK_OBJECT(collection
), "show_menu",
1631 show_menu
, filer_window
);
1632 gtk_signal_connect(GTK_OBJECT(collection
), "gain_selection",
1633 gain_selection
, filer_window
);
1634 gtk_signal_connect(GTK_OBJECT(collection
), "lose_selection",
1635 lose_selection
, filer_window
);
1636 gtk_signal_connect(GTK_OBJECT(collection
), "drag_selection",
1637 drag_selection
, filer_window
);
1638 gtk_signal_connect(GTK_OBJECT(collection
), "drag_data_get",
1639 drag_data_get
, filer_window
);
1640 gtk_signal_connect(GTK_OBJECT(collection
), "selection_clear_event",
1641 GTK_SIGNAL_FUNC(collection_lose_selection
), NULL
);
1642 gtk_signal_connect (GTK_OBJECT(collection
), "selection_get",
1643 GTK_SIGNAL_FUNC(selection_get
), NULL
);
1644 gtk_selection_add_targets(collection
, GDK_SELECTION_PRIMARY
,
1646 sizeof(target_table
) / sizeof(*target_table
));
1648 filer_style_set(filer_window
, last_display_style
);
1649 drag_set_dest(filer_window
);
1653 int swidth
, sheight
, iwidth
, iheight
;
1654 GtkWidget
*frame
, *win
= filer_window
->window
;
1656 gtk_window_set_wmclass(GTK_WINDOW(win
), "ROX-Panel",
1658 collection_set_panel(filer_window
->collection
, TRUE
);
1659 gtk_signal_connect(GTK_OBJECT(filer_window
->window
),
1661 GTK_SIGNAL_FUNC(filer_confirm_close
),
1664 gdk_window_get_size(GDK_ROOT_PARENT(), &swidth
, &sheight
);
1665 iwidth
= filer_window
->collection
->item_width
;
1666 iheight
= filer_window
->collection
->item_height
;
1669 int height
= iheight
+ PANEL_BORDER
;
1670 int y
= panel_type
== PANEL_TOP
1672 : sheight
- height
- PANEL_BORDER
;
1674 gtk_widget_set_usize(collection
, swidth
, height
);
1675 gtk_widget_set_uposition(win
, 0, y
);
1678 frame
= gtk_frame_new(NULL
);
1679 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_OUT
);
1680 gtk_container_add(GTK_CONTAINER(frame
), collection
);
1681 gtk_container_add(GTK_CONTAINER(win
), frame
);
1683 gtk_widget_show_all(frame
);
1684 gtk_widget_realize(win
);
1685 if (override_redirect
)
1686 gdk_window_set_override_redirect(win
->window
, TRUE
);
1687 make_panel_window(win
->window
);
1692 int col_height
= ROW_HEIGHT_LARGE
* 3;
1694 gtk_signal_connect(GTK_OBJECT(collection
),
1696 GTK_SIGNAL_FUNC(key_press_event
), filer_window
);
1697 gtk_window_set_default_size(GTK_WINDOW(filer_window
->window
),
1698 filer_window
->display_style
== LARGE_ICONS
? 400 : 512,
1699 o_toolbar
== TOOLBAR_NONE
? col_height
:
1700 o_toolbar
== TOOLBAR_NORMAL
? col_height
+ 24 :
1703 hbox
= gtk_hbox_new(FALSE
, 0);
1704 gtk_container_add(GTK_CONTAINER(filer_window
->window
),
1707 vbox
= gtk_vbox_new(FALSE
, 0);
1708 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, TRUE
, TRUE
, 0);
1710 if (o_toolbar
!= TOOLBAR_NONE
)
1714 toolbar
= create_toolbar(filer_window
);
1715 gtk_box_pack_start(GTK_BOX(vbox
), toolbar
,
1717 gtk_widget_show_all(toolbar
);
1720 gtk_box_pack_start(GTK_BOX(vbox
), collection
, TRUE
, TRUE
, 0);
1722 create_minibuffer(filer_window
);
1723 gtk_box_pack_start(GTK_BOX(vbox
), filer_window
->minibuffer_area
,
1726 scrollbar
= gtk_vscrollbar_new(COLLECTION(collection
)->vadj
);
1727 gtk_box_pack_start(GTK_BOX(hbox
), scrollbar
, FALSE
, TRUE
, 0);
1728 gtk_accel_group_attach(filer_keys
,
1729 GTK_OBJECT(filer_window
->window
));
1730 gtk_window_set_focus(GTK_WINDOW(filer_window
->window
),
1733 gtk_widget_show(hbox
);
1734 gtk_widget_show(vbox
);
1735 gtk_widget_show(scrollbar
);
1736 gtk_widget_show(collection
);
1739 number_of_windows
++;
1740 gtk_widget_show(filer_window
->window
);
1741 attach(filer_window
);
1743 all_filer_windows
= g_list_prepend(all_filer_windows
, filer_window
);
1745 return filer_window
;
1748 static gint
clear_scanning_display(FilerWindow
*filer_window
)
1750 if (filer_exists(filer_window
))
1751 filer_set_title(filer_window
);
1755 static void set_scanning_display(FilerWindow
*filer_window
, gboolean scanning
)
1757 if (scanning
== filer_window
->scanning
)
1759 filer_window
->scanning
= scanning
;
1762 filer_set_title(filer_window
);
1764 gtk_timeout_add(300, (GtkFunction
) clear_scanning_display
,
1768 static GtkWidget
*create_toolbar(FilerWindow
*filer_window
)
1770 GtkWidget
*frame
, *box
;
1772 if (o_toolbar
== TOOLBAR_GNOME
)
1774 frame
= gtk_handle_box_new();
1775 box
= gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL
,
1777 gtk_container_set_border_width(GTK_CONTAINER(box
), 2);
1778 gtk_toolbar_set_space_style(GTK_TOOLBAR(box
),
1779 GTK_TOOLBAR_SPACE_LINE
);
1780 gtk_toolbar_set_button_relief(GTK_TOOLBAR(box
),
1785 frame
= gtk_frame_new(NULL
);
1786 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_OUT
);
1788 box
= gtk_hbutton_box_new();
1789 gtk_button_box_set_child_size_default(16, 16);
1790 gtk_hbutton_box_set_spacing_default(0);
1791 gtk_button_box_set_layout(GTK_BUTTON_BOX(box
),
1792 GTK_BUTTONBOX_START
);
1795 gtk_container_add(GTK_CONTAINER(frame
), box
);
1797 add_button(box
, im_up_icon
,
1798 GTK_SIGNAL_FUNC(toolbar_up_clicked
),
1800 _("Up"), _("Change to parent directory"));
1801 add_button(box
, im_home_icon
,
1802 GTK_SIGNAL_FUNC(toolbar_home_clicked
),
1804 _("Home"), _("Change to home directory"));
1805 add_button(box
, im_refresh_icon
,
1806 GTK_SIGNAL_FUNC(toolbar_refresh_clicked
),
1808 _("Rescan"), _("Rescan directory contents"));
1809 add_button(box
, im_help
,
1810 GTK_SIGNAL_FUNC(toolbar_help_clicked
),
1812 _("Help"), _("Show ROX-Filer help"));
1817 /* This is used to simulate a click when button 3 is used (GtkButton
1818 * normally ignores this). Currently, this button does not pop in -
1819 * this may be fixed in future versions of GTK+.
1821 static gint toolbar_other_button
= 0;
1822 static gint
toolbar_adjust_pressed(GtkButton
*button
,
1823 GdkEventButton
*event
,
1824 FilerWindow
*filer_window
)
1826 gint b
= event
->button
;
1828 if ((b
== 2 || b
== 3) && toolbar_other_button
== 0)
1830 toolbar_other_button
= event
->button
;
1831 gtk_grab_add(GTK_WIDGET(button
));
1832 gtk_button_pressed(button
);
1838 static gint
toolbar_adjust_released(GtkButton
*button
,
1839 GdkEventButton
*event
,
1840 FilerWindow
*filer_window
)
1842 if (event
->button
== toolbar_other_button
)
1844 toolbar_other_button
= 0;
1845 gtk_grab_remove(GTK_WIDGET(button
));
1846 gtk_button_released(button
);
1852 static void add_button(GtkWidget
*box
, MaskedPixmap
*icon
,
1853 GtkSignalFunc cb
, FilerWindow
*filer_window
,
1854 char *label
, char *tip
)
1856 GtkWidget
*button
, *icon_widget
;
1858 icon_widget
= gtk_pixmap_new(icon
->pixmap
, icon
->mask
);
1860 if (o_toolbar
== TOOLBAR_GNOME
)
1862 gtk_toolbar_append_element(GTK_TOOLBAR(box
),
1863 GTK_TOOLBAR_CHILD_BUTTON
,
1872 button
= gtk_button_new();
1873 gtk_button_set_relief(GTK_BUTTON(button
), GTK_RELIEF_NONE
);
1874 GTK_WIDGET_UNSET_FLAGS(button
, GTK_CAN_FOCUS
);
1876 gtk_container_add(GTK_CONTAINER(button
), icon_widget
);
1877 gtk_signal_connect(GTK_OBJECT(button
), "button_press_event",
1878 GTK_SIGNAL_FUNC(toolbar_adjust_pressed
), filer_window
);
1879 gtk_signal_connect(GTK_OBJECT(button
), "button_release_event",
1880 GTK_SIGNAL_FUNC(toolbar_adjust_released
), filer_window
);
1881 gtk_signal_connect(GTK_OBJECT(button
), "clicked",
1884 gtk_tooltips_set_tip(tooltips
, button
, tip
, NULL
);
1886 gtk_container_add(GTK_CONTAINER(box
), button
);
1890 /* Build up some option widgets to go in the options dialog, but don't
1893 static GtkWidget
*create_options()
1895 GtkWidget
*vbox
, *menu
, *hbox
, *slide
;
1897 vbox
= gtk_vbox_new(FALSE
, 0);
1898 gtk_container_set_border_width(GTK_CONTAINER(vbox
), 4);
1900 display_label
= gtk_label_new("<>");
1901 gtk_label_set_line_wrap(GTK_LABEL(display_label
), TRUE
);
1902 gtk_box_pack_start(GTK_BOX(vbox
), display_label
, FALSE
, TRUE
, 0);
1904 toggle_sort_nocase
=
1905 gtk_check_button_new_with_label(_("Ignore case when sorting"));
1906 gtk_box_pack_start(GTK_BOX(vbox
), toggle_sort_nocase
, FALSE
, TRUE
, 0);
1908 toggle_new_window_on_1
=
1909 gtk_check_button_new_with_label(
1910 _("New window on button 1 (RISC OS style)"));
1911 gtk_box_pack_start(GTK_BOX(vbox
), toggle_new_window_on_1
,
1915 gtk_check_button_new_with_label(
1916 _("Menu on button 2 (RISC OS style)"));
1917 gtk_box_pack_start(GTK_BOX(vbox
), toggle_menu_on_2
, FALSE
, TRUE
, 0);
1919 toggle_single_click
=
1920 gtk_check_button_new_with_label(_("Single-click nagivation"));
1921 gtk_box_pack_start(GTK_BOX(vbox
), toggle_single_click
, FALSE
, TRUE
, 0);
1923 toggle_unique_filer_windows
=
1924 gtk_check_button_new_with_label(_("Unique windows"));
1925 gtk_box_pack_start(GTK_BOX(vbox
), toggle_unique_filer_windows
,
1928 hbox
= gtk_hbox_new(FALSE
, 4);
1929 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, TRUE
, 0);
1931 gtk_box_pack_start(GTK_BOX(hbox
),
1932 gtk_label_new(_("Toolbar type for new windows")),
1934 menu_toolbar
= gtk_option_menu_new();
1935 menu
= gtk_menu_new();
1936 gtk_menu_append(GTK_MENU(menu
),
1937 gtk_menu_item_new_with_label(_("None")));
1938 gtk_menu_append(GTK_MENU(menu
),
1939 gtk_menu_item_new_with_label(_("Normal")));
1940 gtk_menu_append(GTK_MENU(menu
),
1941 gtk_menu_item_new_with_label(_("GNOME")));
1942 gtk_option_menu_set_menu(GTK_OPTION_MENU(menu_toolbar
), menu
);
1943 gtk_box_pack_start(GTK_BOX(hbox
), menu_toolbar
, TRUE
, TRUE
, 0);
1945 hbox
= gtk_hbox_new(FALSE
, 4);
1946 gtk_box_pack_start(GTK_BOX(hbox
),
1947 gtk_label_new(_("Max Large Icons width")),
1949 adj_large_truncate
= GTK_ADJUSTMENT(gtk_adjustment_new(0,
1950 MIN_TRUNCATE
, MAX_TRUNCATE
, 1, 10, 0));
1951 slide
= gtk_hscale_new(adj_large_truncate
);
1952 gtk_widget_set_usize(slide
, MAX_TRUNCATE
, 24);
1953 gtk_scale_set_draw_value(GTK_SCALE(slide
), FALSE
);
1954 gtk_box_pack_start(GTK_BOX(hbox
), slide
, FALSE
, TRUE
, 0);
1955 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, TRUE
, 0);
1957 hbox
= gtk_hbox_new(FALSE
, 4);
1958 gtk_box_pack_start(GTK_BOX(hbox
),
1959 gtk_label_new(_("Max Small Icons width")),
1961 adj_small_truncate
= GTK_ADJUSTMENT(gtk_adjustment_new(0,
1962 MIN_TRUNCATE
, MAX_TRUNCATE
, 1, 10, 0));
1963 slide
= gtk_hscale_new(adj_small_truncate
);
1964 gtk_widget_set_usize(slide
, MAX_TRUNCATE
, 24);
1965 gtk_scale_set_draw_value(GTK_SCALE(slide
), FALSE
);
1966 gtk_box_pack_start(GTK_BOX(hbox
), slide
, FALSE
, TRUE
, 0);
1967 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, TRUE
, 0);
1972 static void update_options_label(void)
1976 str
= g_strdup_printf(_("The last used display style (%s) and sort "
1977 "function (Sort By %s) will be saved if you click on "
1978 "Save."), style_to_name(), sort_fn_to_name());
1979 gtk_label_set_text(GTK_LABEL(display_label
), str
);
1983 /* Reflect current state by changing the widgets in the options box */
1984 static void update_options()
1986 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_sort_nocase
),
1988 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_new_window_on_1
),
1990 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_menu_on_2
),
1991 collection_menu_button
== 2 ? 1 : 0);
1992 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_single_click
),
1994 gtk_toggle_button_set_active(
1995 GTK_TOGGLE_BUTTON(toggle_unique_filer_windows
),
1996 o_unique_filer_windows
);
1997 gtk_option_menu_set_history(GTK_OPTION_MENU(menu_toolbar
), o_toolbar
);
1999 gtk_adjustment_set_value(adj_small_truncate
, o_small_truncate
);
2000 gtk_adjustment_set_value(adj_large_truncate
, o_large_truncate
);
2002 update_options_label();
2005 /* Set current values by reading the states of the widgets in the options box */
2006 static void set_options()
2008 GtkWidget
*item
, *menu
;
2010 gboolean old_case
= o_sort_nocase
;
2011 GList
*next
= all_filer_windows
;
2013 o_sort_nocase
= gtk_toggle_button_get_active(
2014 GTK_TOGGLE_BUTTON(toggle_sort_nocase
));
2016 o_new_window_on_1
= gtk_toggle_button_get_active(
2017 GTK_TOGGLE_BUTTON(toggle_new_window_on_1
));
2019 collection_menu_button
= gtk_toggle_button_get_active(
2020 GTK_TOGGLE_BUTTON(toggle_menu_on_2
)) ? 2 : 3;
2022 o_single_click
= gtk_toggle_button_get_active(
2023 GTK_TOGGLE_BUTTON(toggle_single_click
));
2025 o_unique_filer_windows
= gtk_toggle_button_get_active(
2026 GTK_TOGGLE_BUTTON(toggle_unique_filer_windows
));
2028 collection_single_click
= o_single_click
? TRUE
: FALSE
;
2030 menu
= gtk_option_menu_get_menu(GTK_OPTION_MENU(menu_toolbar
));
2031 item
= gtk_menu_get_active(GTK_MENU(menu
));
2032 list
= gtk_container_children(GTK_CONTAINER(menu
));
2033 o_toolbar
= (ToolbarType
) g_list_index(list
, item
);
2036 o_small_truncate
= adj_small_truncate
->value
;
2037 o_large_truncate
= adj_large_truncate
->value
;
2041 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
2043 if (o_sort_nocase
!= old_case
)
2045 collection_qsort(filer_window
->collection
,
2046 filer_window
->sort_fn
);
2048 shrink_width(filer_window
);
2054 static guchar
*style_to_name(void)
2056 return last_display_style
== LARGE_ICONS
? _("Large Icons") :
2057 last_display_style
== SMALL_ICONS
? _("Small Icons") :
2061 static guchar
*sort_fn_to_name(void)
2063 return last_sort_fn
== sort_by_name
? _("Name") :
2064 last_sort_fn
== sort_by_type
? _("Type") :
2065 last_sort_fn
== sort_by_date
? _("Date") :
2069 static void save_options()
2073 option_write("filer_sort_nocase", o_sort_nocase
? "1" : "0");
2074 option_write("filer_new_window_on_1", o_new_window_on_1
? "1" : "0");
2075 option_write("filer_menu_on_2",
2076 collection_menu_button
== 2 ? "1" : "0");
2077 option_write("filer_single_click", o_single_click
? "1" : "0");
2078 option_write("filer_unique_windows",
2079 o_unique_filer_windows
? "1" : "0");
2080 option_write("filer_display_style",
2081 last_display_style
== LARGE_ICONS
? "Large Icons" :
2082 last_display_style
== SMALL_ICONS
? "Small Icons" :
2084 option_write("filer_sort_by",
2085 last_sort_fn
== sort_by_name
? "Name" :
2086 last_sort_fn
== sort_by_type
? "Type" :
2087 last_sort_fn
== sort_by_date
? "Date" :
2089 option_write("filer_toolbar", o_toolbar
== TOOLBAR_NONE
? "None" :
2090 o_toolbar
== TOOLBAR_NORMAL
? "Normal" :
2091 o_toolbar
== TOOLBAR_GNOME
? "GNOME" :
2094 tmp
= g_strdup_printf("%d, %d", o_large_truncate
, o_small_truncate
);
2095 option_write("filer_truncate", tmp
);
2099 static char *filer_sort_nocase(char *data
)
2101 o_sort_nocase
= atoi(data
) != 0;
2105 static char *filer_new_window_on_1(char *data
)
2107 o_new_window_on_1
= atoi(data
) != 0;
2111 static char *filer_menu_on_2(char *data
)
2113 collection_menu_button
= atoi(data
) != 0 ? 2 : 3;
2117 static char *filer_single_click(char *data
)
2119 o_single_click
= atoi(data
) != 0;
2120 collection_single_click
= o_single_click
? TRUE
: FALSE
;
2124 static char *filer_unique_windows(char *data
)
2126 o_unique_filer_windows
= atoi(data
) != 0;
2130 static char *filer_display_style(char *data
)
2132 if (g_strcasecmp(data
, "Large Icons") == 0)
2133 last_display_style
= LARGE_ICONS
;
2134 else if (g_strcasecmp(data
, "Small Icons") == 0)
2135 last_display_style
= SMALL_ICONS
;
2136 else if (g_strcasecmp(data
, "Full Info") == 0)
2137 last_display_style
= FULL_INFO
;
2139 return _("Unknown display style");
2144 static char *filer_sort_by(char *data
)
2146 if (g_strcasecmp(data
, "Name") == 0)
2147 last_sort_fn
= sort_by_name
;
2148 else if (g_strcasecmp(data
, "Type") == 0)
2149 last_sort_fn
= sort_by_type
;
2150 else if (g_strcasecmp(data
, "Date") == 0)
2151 last_sort_fn
= sort_by_date
;
2152 else if (g_strcasecmp(data
, "Size") == 0)
2153 last_sort_fn
= sort_by_size
;
2155 return _("Unknown sort type");
2160 static char *filer_truncate(char *data
)
2164 comma
= strchr(data
, ',');
2166 return "Missing , in filer_truncate";
2168 o_large_truncate
= CLAMP(atoi(data
), MIN_TRUNCATE
, MAX_TRUNCATE
);
2169 o_small_truncate
= CLAMP(atoi(comma
+ 1), MIN_TRUNCATE
, MAX_TRUNCATE
);
2174 static char *filer_toolbar(char *data
)
2176 if (g_strcasecmp(data
, "None") == 0)
2177 o_toolbar
= TOOLBAR_NONE
;
2178 else if (g_strcasecmp(data
, "Normal") == 0)
2179 o_toolbar
= TOOLBAR_NORMAL
;
2180 else if (g_strcasecmp(data
, "GNOME") == 0)
2181 o_toolbar
= TOOLBAR_GNOME
;
2183 return _("Unknown toolbar type");
2188 /* Note that filer_window may not exist after this call. */
2189 void filer_update_dir(FilerWindow
*filer_window
, gboolean warning
)
2191 if (may_rescan(filer_window
, warning
))
2192 dir_update(filer_window
->directory
, filer_window
->path
);
2195 void filer_set_hidden(FilerWindow
*filer_window
, gboolean hidden
)
2197 Directory
*dir
= filer_window
->directory
;
2199 if (filer_window
->show_hidden
== hidden
)
2202 filer_window
->show_hidden
= hidden
;
2203 last_show_hidden
= hidden
;
2205 g_fscache_data_ref(dir_cache
, dir
);
2206 detach(filer_window
);
2207 filer_window
->directory
= dir
;
2208 attach(filer_window
);
2211 /* Refresh the various caches even if we don't think we need to */
2212 void full_refresh(void)
2217 /* See whether a filer window with a given path already exists
2218 * and is different from diff.
2220 static FilerWindow
*find_filer_window(char *path
, FilerWindow
*diff
)
2222 GList
*next
= all_filer_windows
;
2226 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
2228 if (filer_window
->panel_type
== PANEL_NO
&&
2229 filer_window
!= diff
&&
2230 strcmp(path
, filer_window
->path
) == 0)
2232 return filer_window
;
2241 /* This path has been mounted/umounted/deleted some files - update all dirs */
2242 void filer_check_mounted(char *path
)
2244 GList
*next
= all_filer_windows
;
2251 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
2255 if (strncmp(path
, filer_window
->path
, len
) == 0)
2257 char s
= filer_window
->path
[len
];
2259 if (s
== '/' || s
== '\0')
2260 filer_update_dir(filer_window
, FALSE
);
2265 /* Like minibuffer_show(), except that:
2266 * - It returns FALSE (to be used from an idle callback)
2267 * - It checks that the filer window still exists.
2269 static gboolean
minibuffer_show_cb(FilerWindow
*filer_window
)
2271 if (filer_exists(filer_window
))
2272 minibuffer_show(filer_window
, MINI_PATH
);
2276 gboolean
filer_exists(FilerWindow
*filer_window
)
2280 for (next
= all_filer_windows
; next
; next
= next
->next
)
2282 FilerWindow
*fw
= (FilerWindow
*) next
->data
;
2284 if (fw
== filer_window
)
2291 /* Highlight (wink or cursor) this item in the filer window. If the item
2292 * isn't already there but we're scanning then highlight it if it
2295 void filer_set_autoselect(FilerWindow
*filer_window
, guchar
*leaf
)
2297 Collection
*col
= filer_window
->collection
;
2300 g_free(filer_window
->auto_select
);
2301 filer_window
->auto_select
= NULL
;
2303 for (i
= 0; i
< col
->number_of_items
; i
++)
2305 DirItem
*item
= (DirItem
*) col
->items
[i
].data
;
2307 if (strcmp(item
->leafname
, leaf
) == 0)
2309 if (col
->cursor_item
!= -1)
2310 collection_set_cursor_item(col
, i
);
2312 collection_wink_item(col
, i
);
2317 filer_window
->auto_select
= g_strdup(leaf
);
2320 static void filer_set_title(FilerWindow
*filer_window
)
2322 if (filer_window
->scanning
)
2326 title
= g_strdup_printf(_("%s (Scanning)"), filer_window
->path
);
2327 gtk_window_set_title(GTK_WINDOW(filer_window
->window
),
2332 gtk_window_set_title(GTK_WINDOW(filer_window
->window
),
2333 filer_window
->path
);