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 32
56 #define ROW_HEIGHT_FULL_INFO 44
57 #define SMALL_ICON_HEIGHT 20
58 #define SMALL_ICON_WIDTH 48
59 #define MAX_ICON_HEIGHT 42
60 #define MAX_ICON_WIDTH 48
61 #define PANEL_BORDER 2
62 #define MIN_ITEM_WIDTH 64
64 extern int collection_menu_button
;
65 extern gboolean collection_single_click
;
67 FilerWindow
*window_with_focus
= NULL
;
68 GList
*all_filer_windows
= NULL
;
70 static DisplayStyle last_display_style
= LARGE_ICONS
;
71 static gboolean last_show_hidden
= FALSE
;
72 static int (*last_sort_fn
)(const void *a
, const void *b
) = sort_by_type
;
74 static FilerWindow
*window_with_selection
= NULL
;
77 static guchar
*style_to_name(void);
78 static guchar
*sort_fn_to_name(void);
79 static void update_options_label(void);
81 static GtkWidget
*create_options();
82 static void update_options();
83 static void set_options();
84 static void save_options();
85 static char *filer_single_click(char *data
);
86 static char *filer_unique_windows(char *data
);
87 static char *filer_menu_on_2(char *data
);
88 static char *filer_new_window_on_1(char *data
);
89 static char *filer_toolbar(char *data
);
90 static char *filer_display_style(char *data
);
91 static char *filer_sort_by(char *data
);
93 static OptionsSection options
=
95 "Filer window options",
102 /* The values correspond to the menu indexes in the option widget */
108 static ToolbarType o_toolbar
= TOOLBAR_NORMAL
;
109 static GtkWidget
*menu_toolbar
;
111 static GtkWidget
*display_label
;
113 static gboolean o_single_click
= FALSE
;
114 static GtkWidget
*toggle_single_click
;
115 static gboolean o_new_window_on_1
= FALSE
; /* Button 1 => New window */
116 static GtkWidget
*toggle_new_window_on_1
;
117 static GtkWidget
*toggle_menu_on_2
;
118 static GtkWidget
*toggle_unique_filer_windows
;
119 gboolean o_unique_filer_windows
= FALSE
;
121 /* Static prototypes */
122 static void attach(FilerWindow
*filer_window
);
123 static void detach(FilerWindow
*filer_window
);
124 static void filer_window_destroyed(GtkWidget
*widget
,
125 FilerWindow
*filer_window
);
126 static void show_menu(Collection
*collection
, GdkEventButton
*event
,
127 int number_selected
, gpointer user_data
);
128 static gint
focus_in(GtkWidget
*widget
,
129 GdkEventFocus
*event
,
130 FilerWindow
*filer_window
);
131 static gint
focus_out(GtkWidget
*widget
,
132 GdkEventFocus
*event
,
133 FilerWindow
*filer_window
);
134 static void add_item(FilerWindow
*filer_window
, DirItem
*item
);
135 static void toolbar_up_clicked(GtkWidget
*widget
, FilerWindow
*filer_window
);
136 static void toolbar_home_clicked(GtkWidget
*widget
, FilerWindow
*filer_window
);
137 static void add_button(GtkWidget
*box
, int pixmap
,
138 GtkSignalFunc cb
, FilerWindow
*filer_window
,
139 char *label
, char *tip
);
140 static GtkWidget
*create_toolbar(FilerWindow
*filer_window
);
141 static int filer_confirm_close(GtkWidget
*widget
, GdkEvent
*event
,
142 FilerWindow
*window
);
143 static int calc_width(FilerWindow
*filer_window
, DirItem
*item
);
144 static void draw_large_icon(GtkWidget
*widget
,
148 static void draw_string(GtkWidget
*widget
,
155 static void draw_item_large(GtkWidget
*widget
,
156 CollectionItem
*item
,
158 static void draw_item_small(GtkWidget
*widget
,
159 CollectionItem
*item
,
161 static void draw_item_full_info(GtkWidget
*widget
,
162 CollectionItem
*colitem
,
164 static gboolean
test_point_large(Collection
*collection
,
165 int point_x
, int point_y
,
166 CollectionItem
*item
,
167 int width
, int height
);
168 static gboolean
test_point_small(Collection
*collection
,
169 int point_x
, int point_y
,
170 CollectionItem
*item
,
171 int width
, int height
);
172 static gboolean
test_point_full_info(Collection
*collection
,
173 int point_x
, int point_y
,
174 CollectionItem
*item
,
175 int width
, int height
);
176 static void update_display(Directory
*dir
,
179 FilerWindow
*filer_window
);
180 static void set_scanning_display(FilerWindow
*filer_window
, gboolean scanning
);
181 static void shrink_width(FilerWindow
*filer_window
);
182 static gboolean
may_rescan(FilerWindow
*filer_window
, gboolean warning
);
183 static void open_item(Collection
*collection
,
184 gpointer item_data
, int item_number
,
186 static gboolean
minibuffer_show_cb(FilerWindow
*filer_window
);
187 static void set_autoselect(FilerWindow
*filer_window
, guchar
*leaf
);
188 static FilerWindow
*find_filer_window(char *path
, FilerWindow
*diff
);
189 static void filer_set_title(FilerWindow
*filer_window
);
190 static gboolean
exists(FilerWindow
*filer_window
);
192 static GdkAtom xa_string
;
199 static GdkCursor
*busy_cursor
= NULL
;
200 static GtkTooltips
*tooltips
= NULL
;
204 xa_string
= gdk_atom_intern("STRING", FALSE
);
206 options_sections
= g_slist_prepend(options_sections
, &options
);
207 option_register("filer_new_window_on_1", filer_new_window_on_1
);
208 option_register("filer_menu_on_2", filer_menu_on_2
);
209 option_register("filer_single_click", filer_single_click
);
210 option_register("filer_unique_windows", filer_unique_windows
);
211 option_register("filer_toolbar", filer_toolbar
);
212 option_register("filer_display_style", filer_display_style
);
213 option_register("filer_sort_by", filer_sort_by
);
215 busy_cursor
= gdk_cursor_new(GDK_WATCH
);
217 tooltips
= gtk_tooltips_new();
220 static gboolean
if_deleted(gpointer item
, gpointer removed
)
222 int i
= ((GPtrArray
*) removed
)->len
;
223 DirItem
**r
= (DirItem
**) ((GPtrArray
*) removed
)->pdata
;
224 char *leafname
= ((DirItem
*) item
)->leafname
;
228 if (strcmp(leafname
, r
[i
]->leafname
) == 0)
235 static void update_item(FilerWindow
*filer_window
, DirItem
*item
)
238 char *leafname
= item
->leafname
;
240 if (leafname
[0] == '.')
242 if (filer_window
->show_hidden
== FALSE
|| leafname
[1] == '\0'
243 || (leafname
[1] == '.' && leafname
[2] == '\0'))
247 i
= collection_find_item(filer_window
->collection
, item
, dir_item_cmp
);
250 collection_draw_item(filer_window
->collection
, i
, TRUE
);
252 g_warning("Failed to find '%s'\n", item
->leafname
);
255 static void update_display(Directory
*dir
,
258 FilerWindow
*filer_window
)
261 int cursor
= filer_window
->collection
->cursor_item
;
263 Collection
*collection
= filer_window
->collection
;
268 as
= filer_window
->auto_select
;
270 for (i
= 0; i
< items
->len
; i
++)
272 DirItem
*item
= (DirItem
*) items
->pdata
[i
];
274 add_item(filer_window
, item
);
276 if (cursor
!= -1 || !as
)
279 if (strcmp(as
, item
->leafname
) != 0)
282 cursor
= collection
->number_of_items
- 1;
283 if (filer_window
->had_cursor
)
285 collection_set_cursor_item(collection
,
287 filer_window
->mini_cursor_base
= cursor
;
290 collection_wink_item(collection
,
294 collection_qsort(filer_window
->collection
,
295 filer_window
->sort_fn
);
298 collection_delete_if(filer_window
->collection
,
303 set_scanning_display(filer_window
, TRUE
);
306 if (filer_window
->window
->window
)
307 gdk_window_set_cursor(
308 filer_window
->window
->window
,
310 shrink_width(filer_window
);
311 if (filer_window
->had_cursor
&&
312 collection
->cursor_item
== -1)
314 collection_set_cursor_item(collection
, 0);
315 filer_window
->had_cursor
= FALSE
;
317 set_scanning_display(filer_window
, FALSE
);
320 for (i
= 0; i
< items
->len
; i
++)
322 DirItem
*item
= (DirItem
*) items
->pdata
[i
];
324 update_item(filer_window
, item
);
326 collection_qsort(filer_window
->collection
,
327 filer_window
->sort_fn
);
332 static void attach(FilerWindow
*filer_window
)
334 gdk_window_set_cursor(filer_window
->window
->window
, busy_cursor
);
335 collection_clear(filer_window
->collection
);
336 filer_window
->scanning
= TRUE
;
337 dir_attach(filer_window
->directory
, (DirCallback
) update_display
,
339 filer_set_title(filer_window
);
342 static void detach(FilerWindow
*filer_window
)
344 g_return_if_fail(filer_window
->directory
!= NULL
);
346 dir_detach(filer_window
->directory
,
347 (DirCallback
) update_display
, filer_window
);
348 g_fscache_data_unref(dir_cache
, filer_window
->directory
);
349 filer_window
->directory
= NULL
;
352 static void filer_window_destroyed(GtkWidget
*widget
,
353 FilerWindow
*filer_window
)
355 all_filer_windows
= g_list_remove(all_filer_windows
, filer_window
);
357 if (window_with_selection
== filer_window
)
358 window_with_selection
= NULL
;
359 if (window_with_focus
== filer_window
)
360 window_with_focus
= NULL
;
362 if (filer_window
->directory
)
363 detach(filer_window
);
365 g_free(filer_window
->auto_select
);
366 g_free(filer_window
->path
);
367 g_free(filer_window
);
369 if (--number_of_windows
< 1)
373 static int calc_width(FilerWindow
*filer_window
, DirItem
*item
)
375 int pix_width
= item
->image
->width
;
377 switch (filer_window
->display_style
)
380 return MAX_ICON_WIDTH
+ 12 +
381 MAX(item
->details_width
, item
->name_width
);
383 return SMALL_ICON_WIDTH
+ 12 + item
->name_width
;
385 return MAX(pix_width
, item
->name_width
) + 4;
389 /* Add a single object to a directory display */
390 static void add_item(FilerWindow
*filer_window
, DirItem
*item
)
392 char *leafname
= item
->leafname
;
395 if (leafname
[0] == '.')
397 if (filer_window
->show_hidden
== FALSE
|| leafname
[1] == '\0'
398 || (leafname
[1] == '.' && leafname
[2] == '\0'))
402 item_width
= calc_width(filer_window
, item
);
403 if (item_width
> filer_window
->collection
->item_width
)
404 collection_set_item_size(filer_window
->collection
,
406 filer_window
->collection
->item_height
);
407 collection_insert(filer_window
->collection
, item
);
410 /* Is a point inside an item? */
411 static gboolean
test_point_large(Collection
*collection
,
412 int point_x
, int point_y
,
413 CollectionItem
*colitem
,
414 int width
, int height
)
416 DirItem
*item
= (DirItem
*) colitem
->data
;
417 int text_height
= item_font
->ascent
+ item_font
->descent
;
418 MaskedPixmap
*image
= item
->image
;
419 int image_y
= MAX(0, MAX_ICON_HEIGHT
- image
->height
);
420 int image_width
= (image
->width
>> 1) + 2;
421 int text_width
= (item
->name_width
>> 1) + 2;
424 if (point_y
< image_y
)
425 return FALSE
; /* Too high up (don't worry about too low) */
427 if (point_y
<= image_y
+ image
->height
+ 2)
428 x_limit
= image_width
;
429 else if (point_y
> height
- text_height
- 2)
430 x_limit
= text_width
;
432 x_limit
= MIN(image_width
, text_width
);
434 return ABS(point_x
- (width
>> 1)) < x_limit
;
437 static gboolean
test_point_full_info(Collection
*collection
,
438 int point_x
, int point_y
,
439 CollectionItem
*colitem
,
440 int width
, int height
)
442 DirItem
*item
= (DirItem
*) colitem
->data
;
443 MaskedPixmap
*image
= item
->image
;
444 int image_y
= MAX(0, MAX_ICON_HEIGHT
- image
->height
);
446 - fixed_font
->descent
- 2 - fixed_font
->ascent
;
448 if (point_x
< image
->width
+ 2)
449 return point_x
> 2 && point_y
> image_y
;
451 point_x
-= MAX_ICON_WIDTH
+ 8;
453 if (point_y
>= low_top
)
454 return point_x
< item
->details_width
;
455 if (point_y
>= low_top
- item_font
->ascent
- item_font
->descent
)
456 return point_x
< item
->name_width
;
460 static gboolean
test_point_small(Collection
*collection
,
461 int point_x
, int point_y
,
462 CollectionItem
*colitem
,
463 int width
, int height
)
465 DirItem
*item
= (DirItem
*) colitem
->data
;
466 MaskedPixmap
*image
= item
->image
;
467 int image_y
= MAX(0, SMALL_ICON_HEIGHT
- image
->height
);
469 - fixed_font
->descent
- 2 - item_font
->ascent
;
470 int iwidth
= MIN(SMALL_ICON_WIDTH
, image
->width
);
472 if (point_x
< iwidth
+ 2)
473 return point_x
> 2 && point_y
> image_y
;
475 point_x
-= SMALL_ICON_WIDTH
+ 4;
477 if (point_y
>= low_top
)
478 return point_x
< item
->name_width
;
482 static void draw_small_icon(GtkWidget
*widget
,
487 MaskedPixmap
*image
= item
->image
;
488 int width
= MIN(image
->width
, SMALL_ICON_WIDTH
);
489 int height
= MIN(image
->height
, SMALL_ICON_HEIGHT
);
490 int image_x
= area
->x
+ ((area
->width
- width
) >> 1);
492 GdkGC
*gc
= selected
? widget
->style
->white_gc
493 : widget
->style
->black_gc
;
497 gdk_gc_set_clip_mask(gc
, item
->image
->mask
);
499 image_y
= MAX(0, SMALL_ICON_HEIGHT
- image
->height
);
500 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ image_y
);
501 gdk_draw_pixmap(widget
->window
, gc
,
503 0, 0, /* Source x,y */
504 image_x
, area
->y
+ image_y
, /* Dest x,y */
509 gdk_gc_set_function(gc
, GDK_INVERT
);
510 gdk_draw_rectangle(widget
->window
,
512 TRUE
, image_x
, area
->y
+ image_y
,
514 gdk_gc_set_function(gc
, GDK_COPY
);
517 if (item
->flags
& ITEM_FLAG_SYMLINK
)
519 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ 8);
520 gdk_gc_set_clip_mask(gc
,
521 default_pixmap
[TYPE_SYMLINK
].mask
);
522 gdk_draw_pixmap(widget
->window
, gc
,
523 default_pixmap
[TYPE_SYMLINK
].pixmap
,
524 0, 0, /* Source x,y */
525 image_x
, area
->y
+ 8, /* Dest x,y */
528 else if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
530 int type
= item
->flags
& ITEM_FLAG_MOUNTED
533 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ 8);
534 gdk_gc_set_clip_mask(gc
,
535 default_pixmap
[type
].mask
);
536 gdk_draw_pixmap(widget
->window
, gc
,
537 default_pixmap
[type
].pixmap
,
538 0, 0, /* Source x,y */
539 image_x
, area
->y
+ 8, /* Dest x,y */
543 gdk_gc_set_clip_mask(gc
, NULL
);
544 gdk_gc_set_clip_origin(gc
, 0, 0);
547 static void draw_large_icon(GtkWidget
*widget
,
552 MaskedPixmap
*image
= item
->image
;
553 int width
= MIN(image
->width
, MAX_ICON_WIDTH
);
554 int height
= MIN(image
->height
, MAX_ICON_WIDTH
);
555 int image_x
= area
->x
+ ((area
->width
- width
) >> 1);
557 GdkGC
*gc
= selected
? widget
->style
->white_gc
558 : widget
->style
->black_gc
;
560 gdk_gc_set_clip_mask(gc
, item
->image
->mask
);
562 image_y
= MAX(0, MAX_ICON_HEIGHT
- image
->height
);
563 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ image_y
);
564 gdk_draw_pixmap(widget
->window
, gc
,
566 0, 0, /* Source x,y */
567 image_x
, area
->y
+ image_y
, /* Dest x,y */
572 gdk_gc_set_function(gc
, GDK_INVERT
);
573 gdk_draw_rectangle(widget
->window
,
575 TRUE
, image_x
, area
->y
+ image_y
,
577 gdk_gc_set_function(gc
, GDK_COPY
);
580 if (item
->flags
& ITEM_FLAG_SYMLINK
)
582 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ 8);
583 gdk_gc_set_clip_mask(gc
,
584 default_pixmap
[TYPE_SYMLINK
].mask
);
585 gdk_draw_pixmap(widget
->window
, gc
,
586 default_pixmap
[TYPE_SYMLINK
].pixmap
,
587 0, 0, /* Source x,y */
588 image_x
, area
->y
+ 8, /* Dest x,y */
591 else if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
593 int type
= item
->flags
& ITEM_FLAG_MOUNTED
596 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ 8);
597 gdk_gc_set_clip_mask(gc
,
598 default_pixmap
[type
].mask
);
599 gdk_draw_pixmap(widget
->window
, gc
,
600 default_pixmap
[type
].pixmap
,
601 0, 0, /* Source x,y */
602 image_x
, area
->y
+ 8, /* Dest x,y */
606 gdk_gc_set_clip_mask(gc
, NULL
);
607 gdk_gc_set_clip_origin(gc
, 0, 0);
610 static void draw_string(GtkWidget
*widget
,
618 int text_height
= font
->ascent
+ font
->descent
;
621 gtk_paint_flat_box(widget
->style
, widget
->window
,
622 GTK_STATE_SELECTED
, GTK_SHADOW_NONE
,
623 NULL
, widget
, "text",
628 gdk_draw_text(widget
->window
,
630 selected
? widget
->style
->white_gc
631 : widget
->style
->black_gc
,
633 string
, strlen(string
));
636 /* Return a string (valid until next call) giving details
639 char *details(DirItem
*item
)
641 mode_t m
= item
->mode
;
642 static guchar
*buf
= NULL
;
647 if (item
->lstat_errno
)
648 buf
= g_strdup_printf("lstat(2) failed: %s",
649 g_strerror(item
->lstat_errno
));
651 buf
= g_strdup_printf("%s %s %-8.8s %-8.8s %s %s",
652 item
->flags
& ITEM_FLAG_APPDIR
? "App " :
653 S_ISDIR(m
) ? "Dir " :
654 S_ISCHR(m
) ? "Char" :
655 S_ISBLK(m
) ? "Blck" :
656 S_ISLNK(m
) ? "Link" :
657 S_ISSOCK(m
) ? "Sock" :
658 S_ISFIFO(m
) ? "Pipe" : "File",
659 pretty_permissions(m
),
660 user_name(item
->uid
),
661 group_name(item
->gid
),
662 format_size_aligned(item
->size
),
663 pretty_time(&item
->mtime
));
667 static void draw_item_full_info(GtkWidget
*widget
,
668 CollectionItem
*colitem
,
671 DirItem
*item
= (DirItem
*) colitem
->data
;
672 MaskedPixmap
*image
= item
->image
;
673 int text_x
= area
->x
+ MAX_ICON_WIDTH
+ 8;
674 int low_text_y
= area
->y
+ area
->height
- fixed_font
->descent
- 2;
675 gboolean selected
= colitem
->selected
;
676 GdkRectangle pic_area
;
678 pic_area
.x
= area
->x
;
679 pic_area
.y
= area
->y
;
680 pic_area
.width
= image
->width
+ 8;
681 pic_area
.height
= area
->height
;
683 draw_large_icon(widget
, &pic_area
, item
, selected
);
689 low_text_y
- item_font
->descent
- fixed_font
->ascent
,
699 if (item
->lstat_errno
)
702 /* Underline the effective permissions */
703 gdk_draw_rectangle(widget
->window
,
704 selected
? widget
->style
->white_gc
705 : widget
->style
->black_gc
,
707 text_x
- 1 + fixed_width
*
708 (5 + 4 * applicable(item
->uid
, item
->gid
)),
709 low_text_y
+ fixed_font
->descent
- 1,
710 fixed_width
* 3 + 1, 1);
713 static void draw_item_small(GtkWidget
*widget
,
714 CollectionItem
*colitem
,
717 DirItem
*item
= (DirItem
*) colitem
->data
;
718 int text_x
= area
->x
+ SMALL_ICON_WIDTH
+ 4;
719 int low_text_y
= area
->y
+ area
->height
- item_font
->descent
- 2;
720 gboolean selected
= colitem
->selected
;
721 GdkRectangle pic_area
;
723 pic_area
.x
= area
->x
;
724 pic_area
.y
= area
->y
;
725 pic_area
.width
= SMALL_ICON_WIDTH
;
726 pic_area
.height
= SMALL_ICON_HEIGHT
;
728 draw_small_icon(widget
, &pic_area
, item
, selected
);
739 static void draw_item_large(GtkWidget
*widget
,
740 CollectionItem
*colitem
,
743 DirItem
*item
= (DirItem
*) colitem
->data
;
744 int text_x
= area
->x
+ ((area
->width
- item
->name_width
) >> 1);
745 int text_y
= area
->y
+ area
->height
- item_font
->descent
- 2;
746 gboolean selected
= colitem
->selected
;
748 draw_large_icon(widget
, area
, item
, selected
);
753 text_x
, text_y
, item
->name_width
,
757 static void show_menu(Collection
*collection
, GdkEventButton
*event
,
758 int item
, gpointer user_data
)
760 show_filer_menu((FilerWindow
*) user_data
, event
, item
);
763 /* Returns TRUE iff the directory still exists. */
764 static gboolean
may_rescan(FilerWindow
*filer_window
, gboolean warning
)
768 g_return_val_if_fail(filer_window
!= NULL
, FALSE
);
770 /* We do a fresh lookup (rather than update) because the inode may
773 dir
= g_fscache_lookup(dir_cache
, filer_window
->path
);
777 delayed_error("ROX-Filer", "Directory missing/deleted");
778 gtk_widget_destroy(filer_window
->window
);
781 if (dir
== filer_window
->directory
)
782 g_fscache_data_unref(dir_cache
, dir
);
785 detach(filer_window
);
786 filer_window
->directory
= dir
;
787 attach(filer_window
);
793 /* Another app has grabbed the selection */
794 static gint
collection_lose_selection(GtkWidget
*widget
,
795 GdkEventSelection
*event
)
797 if (window_with_selection
&&
798 window_with_selection
->collection
== COLLECTION(widget
))
800 FilerWindow
*filer_window
= window_with_selection
;
801 window_with_selection
= NULL
;
802 collection_clear_selection(filer_window
->collection
);
808 /* Someone wants us to send them the selection */
809 static void selection_get(GtkWidget
*widget
,
810 GtkSelectionData
*selection_data
,
815 GString
*reply
, *header
;
816 FilerWindow
*filer_window
;
818 Collection
*collection
;
820 filer_window
= gtk_object_get_data(GTK_OBJECT(widget
), "filer_window");
822 reply
= g_string_new(NULL
);
823 header
= g_string_new(NULL
);
828 g_string_sprintf(header
, " %s",
829 make_path(filer_window
->path
, "")->str
);
831 case TARGET_URI_LIST
:
832 g_string_sprintf(header
, " file://%s%s",
834 make_path(filer_window
->path
, "")->str
);
838 collection
= filer_window
->collection
;
839 for (i
= 0; i
< collection
->number_of_items
; i
++)
841 if (collection
->items
[i
].selected
)
844 (DirItem
*) collection
->items
[i
].data
;
846 g_string_append(reply
, header
->str
);
847 g_string_append(reply
, item
->leafname
);
850 /* This works, but I don't think I like it... */
851 /* g_string_append_c(reply, ' '); */
853 gtk_selection_data_set(selection_data
, xa_string
,
854 8, reply
->str
+ 1, reply
->len
- 1);
855 g_string_free(reply
, TRUE
);
856 g_string_free(header
, TRUE
);
859 /* No items are now selected. This might be because another app claimed
860 * the selection or because the user unselected all the items.
862 static void lose_selection(Collection
*collection
,
866 FilerWindow
*filer_window
= (FilerWindow
*) user_data
;
868 if (window_with_selection
== filer_window
)
870 window_with_selection
= NULL
;
871 gtk_selection_owner_set(NULL
,
872 GDK_SELECTION_PRIMARY
,
877 static void gain_selection(Collection
*collection
,
881 FilerWindow
*filer_window
= (FilerWindow
*) user_data
;
883 if (gtk_selection_owner_set(GTK_WIDGET(collection
),
884 GDK_SELECTION_PRIMARY
,
887 window_with_selection
= filer_window
;
890 collection_clear_selection(filer_window
->collection
);
893 int sort_by_name(const void *item1
, const void *item2
)
895 return strcmp((*((DirItem
**)item1
))->leafname
,
896 (*((DirItem
**)item2
))->leafname
);
899 int sort_by_type(const void *item1
, const void *item2
)
901 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
902 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
905 int diff
= i1
->base_type
- i2
->base_type
;
908 diff
= (i1
->flags
& ITEM_FLAG_APPDIR
)
909 - (i2
->flags
& ITEM_FLAG_APPDIR
);
911 return diff
> 0 ? 1 : -1;
918 diff
= strcmp(m1
->media_type
, m2
->media_type
);
920 diff
= strcmp(m1
->subtype
, m2
->subtype
);
928 return diff
> 0 ? 1 : -1;
930 return sort_by_name(item1
, item2
);
933 int sort_by_date(const void *item1
, const void *item2
)
935 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
936 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
938 return i1
->mtime
> i2
->mtime
? -1 :
939 i1
->mtime
< i2
->mtime
? 1 :
940 sort_by_name(item1
, item2
);
943 int sort_by_size(const void *item1
, const void *item2
)
945 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
946 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
948 return i1
->size
> i2
->size
? -1 :
949 i1
->size
< i2
->size
? 1 :
950 sort_by_name(item1
, item2
);
953 static void open_item(Collection
*collection
,
954 gpointer item_data
, int item_number
,
957 FilerWindow
*filer_window
= (FilerWindow
*) user_data
;
959 GdkEventButton
*bevent
;
963 event
= (GdkEvent
*) gtk_get_current_event();
965 bevent
= (GdkEventButton
*) event
;
966 kevent
= (GdkEventKey
*) event
;
970 case GDK_2BUTTON_PRESS
:
971 case GDK_BUTTON_PRESS
:
972 case GDK_BUTTON_RELEASE
:
973 if (bevent
->state
& GDK_SHIFT_MASK
)
976 if (o_new_window_on_1
^ (bevent
->button
== 1))
977 flags
|= OPEN_SAME_WINDOW
;
979 if (bevent
->button
!= 1)
980 flags
|= OPEN_CLOSE_WINDOW
;
982 if (o_single_click
== FALSE
&&
983 (bevent
->state
& GDK_CONTROL_MASK
) != 0)
984 flags
^= OPEN_SAME_WINDOW
| OPEN_CLOSE_WINDOW
;
987 flags
|= OPEN_SAME_WINDOW
;
988 if (kevent
->state
& GDK_SHIFT_MASK
)
995 filer_openitem(filer_window
, item_number
, flags
);
998 /* Return the full path to the directory containing object 'path'.
999 * Relative paths are resolved from the filerwindow's path.
1001 static void follow_symlink(FilerWindow
*filer_window
, char *path
,
1002 gboolean same_window
)
1008 path
= make_path(filer_window
->path
, path
)->str
;
1010 real
= pathdup(path
);
1011 slash
= strrchr(real
, '/');
1015 delayed_error("ROX-Filer",
1016 "Broken symlink (or you don't have permission "
1028 if (filer_window
->panel_type
|| !same_window
)
1032 new = filer_opendir(new_dir
, PANEL_NO
);
1033 set_autoselect(new, slash
+ 1);
1036 filer_change_to(filer_window
, new_dir
, slash
+ 1);
1041 void filer_openitem(FilerWindow
*filer_window
, int item_number
, OpenFlags flags
)
1043 gboolean shift
= (flags
& OPEN_SHIFT
) != 0;
1044 gboolean close_mini
= flags
& OPEN_FROM_MINI
;
1045 gboolean same_window
= (flags
& OPEN_SAME_WINDOW
) != 0
1046 && !filer_window
->panel_type
;
1047 gboolean close_window
= (flags
& OPEN_CLOSE_WINDOW
) != 0
1048 && !filer_window
->panel_type
;
1051 DirItem
*item
= (DirItem
*)
1052 filer_window
->collection
->items
[item_number
].data
;
1053 gboolean wink
= TRUE
, destroy
= FALSE
;
1055 widget
= filer_window
->window
;
1056 full_path
= make_path(filer_window
->path
,
1057 item
->leafname
)->str
;
1059 if (item
->flags
& ITEM_FLAG_SYMLINK
&& shift
)
1061 char path
[MAXPATHLEN
+ 1];
1064 got
= readlink(make_path(filer_window
->path
,
1065 item
->leafname
)->str
,
1068 delayed_error("ROX-Filer", g_strerror(errno
));
1071 g_return_if_fail(got
<= MAXPATHLEN
);
1074 follow_symlink(filer_window
, path
,
1075 flags
& OPEN_SAME_WINDOW
);
1080 switch (item
->base_type
)
1082 case TYPE_DIRECTORY
:
1083 if (item
->flags
& ITEM_FLAG_APPDIR
&& !shift
)
1085 run_app(make_path(filer_window
->path
,
1086 item
->leafname
)->str
);
1092 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
&& shift
)
1094 action_mount(filer_window
, item
);
1095 if (item
->flags
& ITEM_FLAG_MOUNTED
)
1102 filer_change_to(filer_window
, full_path
, NULL
);
1106 filer_opendir(full_path
, PANEL_NO
);
1109 if ((item
->flags
& ITEM_FLAG_EXEC_FILE
) && !shift
)
1111 char *argv
[] = {NULL
, NULL
};
1113 argv
[0] = full_path
;
1115 if (spawn_full(argv
, filer_window
->path
))
1121 report_error("ROX-Filer",
1122 "Failed to fork() child");
1127 MIME_type
*type
= shift
? &text_plain
1130 g_return_if_fail(type
!= NULL
);
1132 if (type_open(full_path
, type
))
1139 message
= g_string_new(NULL
);
1140 g_string_sprintf(message
, "No open "
1141 "action specified for files of "
1142 "this type (%s/%s)",
1145 report_error("ROX-Filer", message
->str
);
1146 g_string_free(message
, TRUE
);
1151 report_error("open_item",
1152 "I don't know how to open that");
1157 gtk_widget_destroy(filer_window
->window
);
1161 collection_wink_item(filer_window
->collection
,
1164 minibuffer_hide(filer_window
);
1168 static gint
pointer_in(GtkWidget
*widget
,
1169 GdkEventCrossing
*event
,
1170 FilerWindow
*filer_window
)
1172 may_rescan(filer_window
, TRUE
);
1176 static gint
focus_in(GtkWidget
*widget
,
1177 GdkEventFocus
*event
,
1178 FilerWindow
*filer_window
)
1180 window_with_focus
= filer_window
;
1185 static gint
focus_out(GtkWidget
*widget
,
1186 GdkEventFocus
*event
,
1187 FilerWindow
*filer_window
)
1189 /* TODO: Shade the cursor */
1194 /* Handle keys that can't be bound with the menu */
1195 static gint
key_press_event(GtkWidget
*widget
,
1197 FilerWindow
*filer_window
)
1199 switch (event
->keyval
)
1202 change_to_parent(filer_window
);
1211 static void toolbar_refresh_clicked(GtkWidget
*widget
,
1212 FilerWindow
*filer_window
)
1215 update_dir(filer_window
, TRUE
);
1218 static void toolbar_home_clicked(GtkWidget
*widget
, FilerWindow
*filer_window
)
1220 filer_change_to(filer_window
, home_dir
, NULL
);
1223 static void toolbar_up_clicked(GtkWidget
*widget
, FilerWindow
*filer_window
)
1225 change_to_parent(filer_window
);
1228 void change_to_parent(FilerWindow
*filer_window
)
1233 if (filer_window
->path
[0] == '/' && filer_window
->path
[1] == '\0')
1234 return; /* Already in the root */
1236 copy
= g_strdup(filer_window
->path
);
1237 slash
= strrchr(copy
, '/');
1242 filer_change_to(filer_window
,
1247 g_warning("No / in directory path!\n");
1253 /* Make filer_window display path. When finished, highlight item 'from', or
1254 * the first item if from is NULL. If there is currently no cursor then
1255 * simply wink 'from' (if not NULL).
1257 void filer_change_to(FilerWindow
*filer_window
, char *path
, char *from
)
1260 char *real_path
= pathdup(path
);
1262 if (o_unique_filer_windows
)
1266 fw
= find_filer_window(real_path
, filer_window
);
1268 gtk_widget_destroy(fw
->window
);
1271 from_dup
= from
&& *from
? g_strdup(from
) : NULL
;
1273 detach(filer_window
);
1274 g_free(filer_window
->path
);
1275 filer_window
->path
= real_path
;
1277 filer_window
->directory
= g_fscache_lookup(dir_cache
,
1278 filer_window
->path
);
1279 if (filer_window
->directory
)
1281 g_free(filer_window
->auto_select
);
1282 filer_window
->had_cursor
=
1283 filer_window
->collection
->cursor_item
!= -1
1284 || filer_window
->had_cursor
;
1285 filer_window
->auto_select
= from_dup
;
1287 filer_set_title(filer_window
);
1288 collection_set_cursor_item(filer_window
->collection
, -1);
1289 attach(filer_window
);
1291 if (GTK_WIDGET_VISIBLE(filer_window
->minibuffer
))
1292 gtk_idle_add((GtkFunction
) minibuffer_show_cb
,
1300 error
= g_strdup_printf("Directory '%s' is not accessible.",
1302 delayed_error("ROX-Filer", error
);
1304 gtk_widget_destroy(filer_window
->window
);
1308 int selected_item_number(Collection
*collection
)
1312 g_return_val_if_fail(collection
!= NULL
, -1);
1313 g_return_val_if_fail(IS_COLLECTION(collection
), -1);
1314 g_return_val_if_fail(collection
->number_selected
== 1, -1);
1316 for (i
= 0; i
< collection
->number_of_items
; i
++)
1317 if (collection
->items
[i
].selected
)
1320 g_warning("selected_item: number_selected is wrong\n");
1325 DirItem
*selected_item(Collection
*collection
)
1329 item
= selected_item_number(collection
);
1332 return (DirItem
*) collection
->items
[item
].data
;
1336 static int filer_confirm_close(GtkWidget
*widget
, GdkEvent
*event
,
1337 FilerWindow
*window
)
1339 /* TODO: We can open lots of these - very irritating! */
1340 return get_choice("Close panel?",
1341 "You have tried to close a panel via the window "
1342 "manager - I usually find that this is accidental... "
1344 2, "Remove", "Cancel") != 0;
1347 /* Make the items as narrow as possible */
1348 static void shrink_width(FilerWindow
*filer_window
)
1351 Collection
*col
= filer_window
->collection
;
1352 int width
= MIN_ITEM_WIDTH
;
1354 DisplayStyle style
= filer_window
->display_style
;
1357 text_height
= item_font
->ascent
+ item_font
->descent
;
1359 for (i
= 0; i
< col
->number_of_items
; i
++)
1361 this_width
= calc_width(filer_window
,
1362 (DirItem
*) col
->items
[i
].data
);
1363 if (this_width
> width
)
1367 collection_set_item_size(filer_window
->collection
,
1369 style
== FULL_INFO
? MAX_ICON_HEIGHT
+ 4 :
1370 style
== SMALL_ICONS
? MAX(text_height
, SMALL_ICON_HEIGHT
) + 4
1371 : text_height
+ MAX_ICON_HEIGHT
+ 8);
1374 void filer_set_sort_fn(FilerWindow
*filer_window
,
1375 int (*fn
)(const void *a
, const void *b
))
1377 if (filer_window
->sort_fn
== fn
)
1380 filer_window
->sort_fn
= fn
;
1383 collection_qsort(filer_window
->collection
,
1384 filer_window
->sort_fn
);
1386 update_options_label();
1389 void filer_style_set(FilerWindow
*filer_window
, DisplayStyle style
)
1391 if (filer_window
->display_style
== style
)
1394 if (filer_window
->panel_type
)
1395 style
= LARGE_ICONS
;
1397 last_display_style
= style
;
1399 filer_window
->display_style
= style
;
1404 collection_set_functions(filer_window
->collection
,
1405 draw_item_small
, test_point_small
);
1408 collection_set_functions(filer_window
->collection
,
1409 draw_item_full_info
, test_point_full_info
);
1412 collection_set_functions(filer_window
->collection
,
1413 draw_item_large
, test_point_large
);
1417 shrink_width(filer_window
);
1419 update_options_label();
1422 FilerWindow
*filer_opendir(char *path
, PanelType panel_type
)
1424 GtkWidget
*hbox
, *scrollbar
, *collection
;
1425 FilerWindow
*filer_window
;
1426 GtkTargetEntry target_table
[] =
1428 {"text/uri-list", 0, TARGET_URI_LIST
},
1429 {"STRING", 0, TARGET_STRING
},
1433 real_path
= pathdup(path
);
1435 if (o_unique_filer_windows
&& panel_type
== PANEL_NO
)
1439 fw
= find_filer_window(real_path
, NULL
);
1443 /* TODO: this should bring the window to the front
1444 * at the same coordinates.
1446 gtk_widget_hide(fw
->window
);
1447 gtk_widget_show(fw
->window
);
1453 filer_window
= g_new(FilerWindow
, 1);
1454 filer_window
->minibuffer
= NULL
;
1455 filer_window
->path
= real_path
;
1456 filer_window
->scanning
= FALSE
;
1457 filer_window
->had_cursor
= FALSE
;
1458 filer_window
->auto_select
= NULL
;
1460 filer_window
->directory
= g_fscache_lookup(dir_cache
,
1461 filer_window
->path
);
1462 if (!filer_window
->directory
)
1466 error
= g_strdup_printf("Directory '%s' not found.", path
);
1467 delayed_error("ROX-Filer", error
);
1469 g_free(filer_window
->path
);
1470 g_free(filer_window
);
1474 filer_window
->show_hidden
= last_show_hidden
;
1475 filer_window
->panel_type
= panel_type
;
1476 filer_window
->temp_item_selected
= FALSE
;
1477 filer_window
->sort_fn
= last_sort_fn
;
1478 filer_window
->flags
= (FilerFlags
) 0;
1479 filer_window
->display_style
= UNKNOWN_STYLE
;
1481 filer_window
->window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
1482 filer_set_title(filer_window
);
1484 collection
= collection_new(NULL
);
1485 gtk_object_set_data(GTK_OBJECT(collection
),
1486 "filer_window", filer_window
);
1487 filer_window
->collection
= COLLECTION(collection
);
1489 gtk_widget_add_events(filer_window
->window
, GDK_ENTER_NOTIFY
);
1490 gtk_signal_connect(GTK_OBJECT(filer_window
->window
),
1491 "enter-notify-event",
1492 GTK_SIGNAL_FUNC(pointer_in
), filer_window
);
1493 gtk_signal_connect(GTK_OBJECT(filer_window
->window
), "focus_in_event",
1494 GTK_SIGNAL_FUNC(focus_in
), filer_window
);
1495 gtk_signal_connect(GTK_OBJECT(filer_window
->window
), "focus_out_event",
1496 GTK_SIGNAL_FUNC(focus_out
), filer_window
);
1497 gtk_signal_connect(GTK_OBJECT(filer_window
->window
), "destroy",
1498 filer_window_destroyed
, filer_window
);
1500 gtk_signal_connect(GTK_OBJECT(filer_window
->collection
), "open_item",
1501 open_item
, filer_window
);
1502 gtk_signal_connect(GTK_OBJECT(collection
), "show_menu",
1503 show_menu
, filer_window
);
1504 gtk_signal_connect(GTK_OBJECT(collection
), "gain_selection",
1505 gain_selection
, filer_window
);
1506 gtk_signal_connect(GTK_OBJECT(collection
), "lose_selection",
1507 lose_selection
, filer_window
);
1508 gtk_signal_connect(GTK_OBJECT(collection
), "drag_selection",
1509 drag_selection
, filer_window
);
1510 gtk_signal_connect(GTK_OBJECT(collection
), "drag_data_get",
1511 drag_data_get
, filer_window
);
1512 gtk_signal_connect(GTK_OBJECT(collection
), "selection_clear_event",
1513 GTK_SIGNAL_FUNC(collection_lose_selection
), NULL
);
1514 gtk_signal_connect (GTK_OBJECT(collection
), "selection_get",
1515 GTK_SIGNAL_FUNC(selection_get
), NULL
);
1516 gtk_selection_add_targets(collection
, GDK_SELECTION_PRIMARY
,
1518 sizeof(target_table
) / sizeof(*target_table
));
1520 filer_style_set(filer_window
, last_display_style
);
1521 drag_set_dest(filer_window
);
1525 int swidth
, sheight
, iwidth
, iheight
;
1526 GtkWidget
*frame
, *win
= filer_window
->window
;
1528 gtk_window_set_wmclass(GTK_WINDOW(win
), "ROX-Panel",
1530 collection_set_panel(filer_window
->collection
, TRUE
);
1531 gtk_signal_connect(GTK_OBJECT(filer_window
->window
),
1533 GTK_SIGNAL_FUNC(filer_confirm_close
),
1536 gdk_window_get_size(GDK_ROOT_PARENT(), &swidth
, &sheight
);
1537 iwidth
= filer_window
->collection
->item_width
;
1538 iheight
= filer_window
->collection
->item_height
;
1541 int height
= iheight
+ PANEL_BORDER
;
1542 int y
= panel_type
== PANEL_TOP
1544 : sheight
- height
- PANEL_BORDER
;
1546 gtk_widget_set_usize(collection
, swidth
, height
);
1547 gtk_widget_set_uposition(win
, 0, y
);
1550 frame
= gtk_frame_new(NULL
);
1551 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_OUT
);
1552 gtk_container_add(GTK_CONTAINER(frame
), collection
);
1553 gtk_container_add(GTK_CONTAINER(win
), frame
);
1555 gtk_widget_show_all(frame
);
1556 gtk_widget_realize(win
);
1557 if (override_redirect
)
1558 gdk_window_set_override_redirect(win
->window
, TRUE
);
1559 make_panel_window(win
->window
);
1564 int col_height
= ROW_HEIGHT_LARGE
* 3;
1566 gtk_signal_connect(GTK_OBJECT(collection
),
1568 GTK_SIGNAL_FUNC(key_press_event
), filer_window
);
1569 gtk_window_set_default_size(GTK_WINDOW(filer_window
->window
),
1570 filer_window
->display_style
== LARGE_ICONS
? 400 : 512,
1571 o_toolbar
== TOOLBAR_NONE
? col_height
:
1572 o_toolbar
== TOOLBAR_NORMAL
? col_height
+ 24 :
1575 hbox
= gtk_hbox_new(FALSE
, 0);
1576 gtk_container_add(GTK_CONTAINER(filer_window
->window
),
1579 vbox
= gtk_vbox_new(FALSE
, 0);
1580 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, TRUE
, TRUE
, 0);
1582 if (o_toolbar
!= TOOLBAR_NONE
)
1586 toolbar
= create_toolbar(filer_window
);
1587 gtk_box_pack_start(GTK_BOX(vbox
), toolbar
,
1589 gtk_widget_show_all(toolbar
);
1592 gtk_box_pack_start(GTK_BOX(vbox
), collection
, TRUE
, TRUE
, 0);
1594 filer_window
->minibuffer
= create_minibuffer(filer_window
);
1595 gtk_box_pack_start(GTK_BOX(vbox
), filer_window
->minibuffer
,
1598 scrollbar
= gtk_vscrollbar_new(COLLECTION(collection
)->vadj
);
1599 gtk_box_pack_start(GTK_BOX(hbox
), scrollbar
, FALSE
, TRUE
, 0);
1600 gtk_accel_group_attach(filer_keys
,
1601 GTK_OBJECT(filer_window
->window
));
1602 gtk_window_set_focus(GTK_WINDOW(filer_window
->window
),
1605 gtk_widget_show(hbox
);
1606 gtk_widget_show(vbox
);
1607 gtk_widget_show(scrollbar
);
1608 gtk_widget_show(collection
);
1611 number_of_windows
++;
1612 gtk_widget_show(filer_window
->window
);
1613 attach(filer_window
);
1615 all_filer_windows
= g_list_prepend(all_filer_windows
, filer_window
);
1617 return filer_window
;
1620 static gint
clear_scanning_display(FilerWindow
*filer_window
)
1622 if (exists(filer_window
))
1623 filer_set_title(filer_window
);
1627 static void set_scanning_display(FilerWindow
*filer_window
, gboolean scanning
)
1629 if (scanning
== filer_window
->scanning
)
1631 filer_window
->scanning
= scanning
;
1634 filer_set_title(filer_window
);
1636 gtk_timeout_add(300, (GtkFunction
) clear_scanning_display
,
1640 static GtkWidget
*create_toolbar(FilerWindow
*filer_window
)
1642 GtkWidget
*frame
, *box
;
1644 if (o_toolbar
== TOOLBAR_GNOME
)
1646 frame
= gtk_handle_box_new();
1647 box
= gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL
,
1649 gtk_container_set_border_width(GTK_CONTAINER(box
), 2);
1650 gtk_toolbar_set_space_style(GTK_TOOLBAR(box
),
1651 GTK_TOOLBAR_SPACE_LINE
);
1652 gtk_toolbar_set_button_relief(GTK_TOOLBAR(box
),
1657 frame
= gtk_frame_new(NULL
);
1658 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_OUT
);
1660 box
= gtk_hbutton_box_new();
1661 gtk_button_box_set_child_size_default(16, 16);
1662 gtk_hbutton_box_set_spacing_default(2);
1663 gtk_button_box_set_layout(GTK_BUTTON_BOX(box
),
1664 GTK_BUTTONBOX_START
);
1667 gtk_container_add(GTK_CONTAINER(frame
), box
);
1669 add_button(box
, TOOLBAR_UP_ICON
,
1670 GTK_SIGNAL_FUNC(toolbar_up_clicked
),
1672 "Up", "Change to parent directory");
1673 add_button(box
, TOOLBAR_HOME_ICON
,
1674 GTK_SIGNAL_FUNC(toolbar_home_clicked
),
1676 "Home", "Change to home directory");
1677 add_button(box
, TOOLBAR_REFRESH_ICON
,
1678 GTK_SIGNAL_FUNC(toolbar_refresh_clicked
),
1680 "Rescan", "Rescan directory contents");
1685 static void add_button(GtkWidget
*box
, int pixmap
,
1686 GtkSignalFunc cb
, FilerWindow
*filer_window
,
1687 char *label
, char *tip
)
1689 GtkWidget
*button
, *icon
;
1691 icon
= gtk_pixmap_new(default_pixmap
[pixmap
].pixmap
,
1692 default_pixmap
[pixmap
].mask
);
1694 if (o_toolbar
== TOOLBAR_GNOME
)
1696 gtk_toolbar_append_element(GTK_TOOLBAR(box
),
1697 GTK_TOOLBAR_CHILD_BUTTON
,
1706 button
= gtk_button_new();
1707 GTK_WIDGET_UNSET_FLAGS(button
, GTK_CAN_FOCUS
);
1709 gtk_container_add(GTK_CONTAINER(button
), icon
);
1710 gtk_signal_connect(GTK_OBJECT(button
), "clicked",
1713 gtk_tooltips_set_tip(tooltips
, button
, tip
, NULL
);
1715 gtk_container_add(GTK_CONTAINER(box
), button
);
1719 /* Build up some option widgets to go in the options dialog, but don't
1722 static GtkWidget
*create_options()
1724 GtkWidget
*vbox
, *menu
, *hbox
;
1726 vbox
= gtk_vbox_new(FALSE
, 0);
1727 gtk_container_set_border_width(GTK_CONTAINER(vbox
), 4);
1729 display_label
= gtk_label_new("<>");
1730 gtk_label_set_line_wrap(GTK_LABEL(display_label
), TRUE
);
1731 gtk_box_pack_start(GTK_BOX(vbox
), display_label
, FALSE
, TRUE
, 0);
1733 toggle_new_window_on_1
=
1734 gtk_check_button_new_with_label("New window on button 1 "
1736 gtk_box_pack_start(GTK_BOX(vbox
), toggle_new_window_on_1
,
1740 gtk_check_button_new_with_label("Menu on button 2 "
1742 gtk_box_pack_start(GTK_BOX(vbox
), toggle_menu_on_2
, FALSE
, TRUE
, 0);
1744 toggle_single_click
=
1745 gtk_check_button_new_with_label("Single-click nagivation");
1746 gtk_box_pack_start(GTK_BOX(vbox
), toggle_single_click
, FALSE
, TRUE
, 0);
1748 toggle_unique_filer_windows
=
1749 gtk_check_button_new_with_label("Unique windows");
1750 gtk_box_pack_start(GTK_BOX(vbox
), toggle_unique_filer_windows
, FALSE
, TRUE
, 0);
1752 hbox
= gtk_hbox_new(FALSE
, 4);
1753 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, TRUE
, 0);
1755 gtk_box_pack_start(GTK_BOX(hbox
),
1756 gtk_label_new("Toolbar type for new windows"),
1758 menu_toolbar
= gtk_option_menu_new();
1759 menu
= gtk_menu_new();
1760 gtk_menu_append(GTK_MENU(menu
), gtk_menu_item_new_with_label("None"));
1761 gtk_menu_append(GTK_MENU(menu
), gtk_menu_item_new_with_label("Normal"));
1762 gtk_menu_append(GTK_MENU(menu
), gtk_menu_item_new_with_label("GNOME"));
1763 gtk_option_menu_set_menu(GTK_OPTION_MENU(menu_toolbar
), menu
);
1764 gtk_box_pack_start(GTK_BOX(hbox
), menu_toolbar
, TRUE
, TRUE
, 0);
1769 static void update_options_label(void)
1773 str
= g_strdup_printf("The last used display style (%s) and sort "
1774 "function (Sort By %s) will be saved if you click on "
1775 "Save.", style_to_name(), sort_fn_to_name());
1776 gtk_label_set_text(GTK_LABEL(display_label
), str
);
1780 /* Reflect current state by changing the widgets in the options box */
1781 static void update_options()
1783 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_new_window_on_1
),
1785 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_menu_on_2
),
1786 collection_menu_button
== 2 ? 1 : 0);
1787 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_single_click
),
1789 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_unique_filer_windows
),
1790 o_unique_filer_windows
);
1791 gtk_option_menu_set_history(GTK_OPTION_MENU(menu_toolbar
), o_toolbar
);
1793 update_options_label();
1796 /* Set current values by reading the states of the widgets in the options box */
1797 static void set_options()
1799 GtkWidget
*item
, *menu
;
1802 o_new_window_on_1
= gtk_toggle_button_get_active(
1803 GTK_TOGGLE_BUTTON(toggle_new_window_on_1
));
1805 collection_menu_button
= gtk_toggle_button_get_active(
1806 GTK_TOGGLE_BUTTON(toggle_menu_on_2
)) ? 2 : 3;
1808 o_single_click
= gtk_toggle_button_get_active(
1809 GTK_TOGGLE_BUTTON(toggle_single_click
));
1811 o_unique_filer_windows
= gtk_toggle_button_get_active(
1812 GTK_TOGGLE_BUTTON(toggle_unique_filer_windows
));
1814 collection_single_click
= o_single_click
? TRUE
: FALSE
;
1816 menu
= gtk_option_menu_get_menu(GTK_OPTION_MENU(menu_toolbar
));
1817 item
= gtk_menu_get_active(GTK_MENU(menu
));
1818 list
= gtk_container_children(GTK_CONTAINER(menu
));
1819 o_toolbar
= (ToolbarType
) g_list_index(list
, item
);
1824 static guchar
*style_to_name(void)
1826 return last_display_style
== LARGE_ICONS
? "Large Icons" :
1827 last_display_style
== SMALL_ICONS
? "Small Icons" :
1831 static guchar
*sort_fn_to_name(void)
1833 return last_sort_fn
== sort_by_name
? "Name" :
1834 last_sort_fn
== sort_by_type
? "Type" :
1835 last_sort_fn
== sort_by_date
? "Date" :
1839 static void save_options()
1841 option_write("filer_new_window_on_1", o_new_window_on_1
? "1" : "0");
1842 option_write("filer_menu_on_2",
1843 collection_menu_button
== 2 ? "1" : "0");
1844 option_write("filer_single_click", o_single_click
? "1" : "0");
1845 option_write("filer_unique_windows", o_unique_filer_windows
? "1" : "0");
1846 option_write("filer_display_style", style_to_name());
1847 option_write("filer_sort_by", sort_fn_to_name());
1848 option_write("filer_toolbar", o_toolbar
== TOOLBAR_NONE
? "None" :
1849 o_toolbar
== TOOLBAR_NORMAL
? "Normal" :
1850 o_toolbar
== TOOLBAR_GNOME
? "GNOME" :
1854 static char *filer_new_window_on_1(char *data
)
1856 o_new_window_on_1
= atoi(data
) != 0;
1860 static char *filer_menu_on_2(char *data
)
1862 collection_menu_button
= atoi(data
) != 0 ? 2 : 3;
1866 static char *filer_single_click(char *data
)
1868 o_single_click
= atoi(data
) != 0;
1869 collection_single_click
= o_single_click
? TRUE
: FALSE
;
1873 static char *filer_unique_windows(char *data
)
1875 o_unique_filer_windows
= atoi(data
) != 0;
1879 static char *filer_display_style(char *data
)
1881 if (g_strcasecmp(data
, "Large Icons") == 0)
1882 last_display_style
= LARGE_ICONS
;
1883 else if (g_strcasecmp(data
, "Small Icons") == 0)
1884 last_display_style
= SMALL_ICONS
;
1885 else if (g_strcasecmp(data
, "Full Info") == 0)
1886 last_display_style
= FULL_INFO
;
1888 return "Unknown display style";
1893 static char *filer_sort_by(char *data
)
1895 if (g_strcasecmp(data
, "Name") == 0)
1896 last_sort_fn
= sort_by_name
;
1897 else if (g_strcasecmp(data
, "Type") == 0)
1898 last_sort_fn
= sort_by_type
;
1899 else if (g_strcasecmp(data
, "Date") == 0)
1900 last_sort_fn
= sort_by_date
;
1901 else if (g_strcasecmp(data
, "Size") == 0)
1902 last_sort_fn
= sort_by_size
;
1904 return "Unknown sort type";
1909 static char *filer_toolbar(char *data
)
1911 if (g_strcasecmp(data
, "None") == 0)
1912 o_toolbar
= TOOLBAR_NONE
;
1913 else if (g_strcasecmp(data
, "Normal") == 0)
1914 o_toolbar
= TOOLBAR_NORMAL
;
1915 else if (g_strcasecmp(data
, "GNOME") == 0)
1916 o_toolbar
= TOOLBAR_GNOME
;
1918 return "Unknown toolbar type";
1923 /* Note that filer_window may not exist after this call. */
1924 void update_dir(FilerWindow
*filer_window
, gboolean warning
)
1926 if (may_rescan(filer_window
, warning
))
1927 dir_update(filer_window
->directory
, filer_window
->path
);
1930 void filer_set_hidden(FilerWindow
*filer_window
, gboolean hidden
)
1932 Directory
*dir
= filer_window
->directory
;
1934 if (filer_window
->show_hidden
== hidden
)
1937 filer_window
->show_hidden
= hidden
;
1938 last_show_hidden
= hidden
;
1940 g_fscache_data_ref(dir_cache
, dir
);
1941 detach(filer_window
);
1942 filer_window
->directory
= dir
;
1943 attach(filer_window
);
1946 /* Refresh the various caches even if we don't think we need to */
1947 void full_refresh(void)
1952 /* See whether a filer window with a given path already exists
1953 * and is different from diff.
1955 static FilerWindow
*find_filer_window(char *path
, FilerWindow
*diff
)
1957 GList
*next
= all_filer_windows
;
1961 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1963 if (filer_window
->panel_type
== PANEL_NO
&&
1964 filer_window
!= diff
&&
1965 strcmp(path
, filer_window
->path
) == 0)
1967 return filer_window
;
1976 /* This path has been mounted/umounted/deleted some files - update all dirs */
1977 void filer_check_mounted(char *path
)
1979 GList
*next
= all_filer_windows
;
1986 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1990 if (strncmp(path
, filer_window
->path
, len
) == 0)
1992 char s
= filer_window
->path
[len
];
1994 if (s
== '/' || s
== '\0')
1995 update_dir(filer_window
, FALSE
);
2000 /* Like minibuffer_show(), except that:
2001 * - It returns FALSE (to be used from an idle callback)
2002 * - It checks that the filer window still exists.
2004 static gboolean
minibuffer_show_cb(FilerWindow
*filer_window
)
2006 if (exists(filer_window
))
2007 minibuffer_show(filer_window
);
2011 static gboolean
exists(FilerWindow
*filer_window
)
2015 for (next
= all_filer_windows
; next
; next
= next
->next
)
2017 FilerWindow
*fw
= (FilerWindow
*) next
->data
;
2019 if (fw
== filer_window
)
2026 /* Highlight (wink or cursor) this item in the filer window. If the item
2027 * isn't already there but we're scanning then highlight it if it
2030 static void set_autoselect(FilerWindow
*filer_window
, guchar
*leaf
)
2032 Collection
*col
= filer_window
->collection
;
2035 g_free(filer_window
->auto_select
);
2036 filer_window
->auto_select
= NULL
;
2038 for (i
= 0; i
< col
->number_of_items
; i
++)
2040 DirItem
*item
= (DirItem
*) col
->items
[i
].data
;
2042 if (strcmp(item
->leafname
, leaf
) == 0)
2044 if (col
->cursor_item
!= -1)
2045 collection_set_cursor_item(col
, i
);
2047 collection_wink_item(col
, i
);
2052 filer_window
->auto_select
= g_strdup(leaf
);
2055 static void filer_set_title(FilerWindow
*filer_window
)
2057 if (filer_window
->scanning
)
2061 title
= g_strdup_printf("%s (Scanning)", filer_window
->path
);
2062 gtk_window_set_title(GTK_WINDOW(filer_window
->window
),
2067 gtk_window_set_title(GTK_WINDOW(filer_window
->window
),
2068 filer_window
->path
);