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 FilerWindow
*find_filer_window(char *path
, FilerWindow
*diff
);
188 static void filer_set_title(FilerWindow
*filer_window
);
189 static gboolean
exists(FilerWindow
*filer_window
);
191 static GdkAtom xa_string
;
198 static GdkCursor
*busy_cursor
= NULL
;
199 static GtkTooltips
*tooltips
= NULL
;
203 xa_string
= gdk_atom_intern("STRING", FALSE
);
205 options_sections
= g_slist_prepend(options_sections
, &options
);
206 option_register("filer_new_window_on_1", filer_new_window_on_1
);
207 option_register("filer_menu_on_2", filer_menu_on_2
);
208 option_register("filer_single_click", filer_single_click
);
209 option_register("filer_unique_windows", filer_unique_windows
);
210 option_register("filer_toolbar", filer_toolbar
);
211 option_register("filer_display_style", filer_display_style
);
212 option_register("filer_sort_by", filer_sort_by
);
214 busy_cursor
= gdk_cursor_new(GDK_WATCH
);
216 tooltips
= gtk_tooltips_new();
219 static gboolean
if_deleted(gpointer item
, gpointer removed
)
221 int i
= ((GPtrArray
*) removed
)->len
;
222 DirItem
**r
= (DirItem
**) ((GPtrArray
*) removed
)->pdata
;
223 char *leafname
= ((DirItem
*) item
)->leafname
;
227 if (strcmp(leafname
, r
[i
]->leafname
) == 0)
234 static void update_item(FilerWindow
*filer_window
, DirItem
*item
)
237 char *leafname
= item
->leafname
;
239 if (leafname
[0] == '.')
241 if (filer_window
->show_hidden
== FALSE
|| leafname
[1] == '\0'
242 || (leafname
[1] == '.' && leafname
[2] == '\0'))
246 i
= collection_find_item(filer_window
->collection
, item
, dir_item_cmp
);
249 collection_draw_item(filer_window
->collection
, i
, TRUE
);
251 g_warning("Failed to find '%s'\n", item
->leafname
);
254 static void update_display(Directory
*dir
,
257 FilerWindow
*filer_window
)
260 int cursor
= filer_window
->collection
->cursor_item
;
262 Collection
*collection
= filer_window
->collection
;
267 as
= filer_window
->auto_select
;
269 for (i
= 0; i
< items
->len
; i
++)
271 DirItem
*item
= (DirItem
*) items
->pdata
[i
];
273 add_item(filer_window
, item
);
275 if (cursor
!= -1 || !as
)
278 if (strcmp(as
, item
->leafname
) != 0)
281 cursor
= collection
->number_of_items
- 1;
282 if (filer_window
->had_cursor
)
284 collection_set_cursor_item(collection
,
286 filer_window
->mini_cursor_base
= cursor
;
289 collection_wink_item(collection
,
293 collection_qsort(filer_window
->collection
,
294 filer_window
->sort_fn
);
297 collection_delete_if(filer_window
->collection
,
302 set_scanning_display(filer_window
, TRUE
);
305 if (filer_window
->window
->window
)
306 gdk_window_set_cursor(
307 filer_window
->window
->window
,
309 shrink_width(filer_window
);
310 if (filer_window
->had_cursor
&&
311 collection
->cursor_item
== -1)
313 collection_set_cursor_item(collection
, 0);
314 filer_window
->had_cursor
= FALSE
;
316 set_scanning_display(filer_window
, FALSE
);
319 for (i
= 0; i
< items
->len
; i
++)
321 DirItem
*item
= (DirItem
*) items
->pdata
[i
];
323 update_item(filer_window
, item
);
325 collection_qsort(filer_window
->collection
,
326 filer_window
->sort_fn
);
331 static void attach(FilerWindow
*filer_window
)
333 gdk_window_set_cursor(filer_window
->window
->window
, busy_cursor
);
334 collection_clear(filer_window
->collection
);
335 filer_window
->scanning
= TRUE
;
336 dir_attach(filer_window
->directory
, (DirCallback
) update_display
,
338 filer_set_title(filer_window
);
341 static void detach(FilerWindow
*filer_window
)
343 g_return_if_fail(filer_window
->directory
!= NULL
);
345 dir_detach(filer_window
->directory
,
346 (DirCallback
) update_display
, filer_window
);
347 g_fscache_data_unref(dir_cache
, filer_window
->directory
);
348 filer_window
->directory
= NULL
;
351 static void filer_window_destroyed(GtkWidget
*widget
,
352 FilerWindow
*filer_window
)
354 all_filer_windows
= g_list_remove(all_filer_windows
, filer_window
);
356 if (window_with_selection
== filer_window
)
357 window_with_selection
= NULL
;
358 if (window_with_focus
== filer_window
)
359 window_with_focus
= NULL
;
361 if (filer_window
->directory
)
362 detach(filer_window
);
364 g_free(filer_window
->auto_select
);
365 g_free(filer_window
->path
);
366 g_free(filer_window
);
368 if (--number_of_windows
< 1)
372 static int calc_width(FilerWindow
*filer_window
, DirItem
*item
)
374 int pix_width
= item
->image
->width
;
376 switch (filer_window
->display_style
)
379 return MAX_ICON_WIDTH
+ 12 +
380 MAX(item
->details_width
, item
->name_width
);
382 return SMALL_ICON_WIDTH
+ 12 + item
->name_width
;
384 return MAX(pix_width
, item
->name_width
) + 4;
388 /* Add a single object to a directory display */
389 static void add_item(FilerWindow
*filer_window
, DirItem
*item
)
391 char *leafname
= item
->leafname
;
394 if (leafname
[0] == '.')
396 if (filer_window
->show_hidden
== FALSE
|| leafname
[1] == '\0'
397 || (leafname
[1] == '.' && leafname
[2] == '\0'))
401 item_width
= calc_width(filer_window
, item
);
402 if (item_width
> filer_window
->collection
->item_width
)
403 collection_set_item_size(filer_window
->collection
,
405 filer_window
->collection
->item_height
);
406 collection_insert(filer_window
->collection
, item
);
409 /* Is a point inside an item? */
410 static gboolean
test_point_large(Collection
*collection
,
411 int point_x
, int point_y
,
412 CollectionItem
*colitem
,
413 int width
, int height
)
415 DirItem
*item
= (DirItem
*) colitem
->data
;
416 int text_height
= item_font
->ascent
+ item_font
->descent
;
417 MaskedPixmap
*image
= item
->image
;
418 int image_y
= MAX(0, MAX_ICON_HEIGHT
- image
->height
);
419 int image_width
= (image
->width
>> 1) + 2;
420 int text_width
= (item
->name_width
>> 1) + 2;
423 if (point_y
< image_y
)
424 return FALSE
; /* Too high up (don't worry about too low) */
426 if (point_y
<= image_y
+ image
->height
+ 2)
427 x_limit
= image_width
;
428 else if (point_y
> height
- text_height
- 2)
429 x_limit
= text_width
;
431 x_limit
= MIN(image_width
, text_width
);
433 return ABS(point_x
- (width
>> 1)) < x_limit
;
436 static gboolean
test_point_full_info(Collection
*collection
,
437 int point_x
, int point_y
,
438 CollectionItem
*colitem
,
439 int width
, int height
)
441 DirItem
*item
= (DirItem
*) colitem
->data
;
442 MaskedPixmap
*image
= item
->image
;
443 int image_y
= MAX(0, MAX_ICON_HEIGHT
- image
->height
);
445 - fixed_font
->descent
- 2 - fixed_font
->ascent
;
447 if (point_x
< image
->width
+ 2)
448 return point_x
> 2 && point_y
> image_y
;
450 point_x
-= MAX_ICON_WIDTH
+ 8;
452 if (point_y
>= low_top
)
453 return point_x
< item
->details_width
;
454 if (point_y
>= low_top
- item_font
->ascent
- item_font
->descent
)
455 return point_x
< item
->name_width
;
459 static gboolean
test_point_small(Collection
*collection
,
460 int point_x
, int point_y
,
461 CollectionItem
*colitem
,
462 int width
, int height
)
464 DirItem
*item
= (DirItem
*) colitem
->data
;
465 MaskedPixmap
*image
= item
->image
;
466 int image_y
= MAX(0, SMALL_ICON_HEIGHT
- image
->height
);
468 - fixed_font
->descent
- 2 - item_font
->ascent
;
469 int iwidth
= MIN(SMALL_ICON_WIDTH
, image
->width
);
471 if (point_x
< iwidth
+ 2)
472 return point_x
> 2 && point_y
> image_y
;
474 point_x
-= SMALL_ICON_WIDTH
+ 4;
476 if (point_y
>= low_top
)
477 return point_x
< item
->name_width
;
481 static void draw_small_icon(GtkWidget
*widget
,
486 MaskedPixmap
*image
= item
->image
;
487 int width
= MIN(image
->width
, SMALL_ICON_WIDTH
);
488 int height
= MIN(image
->height
, SMALL_ICON_HEIGHT
);
489 int image_x
= area
->x
+ ((area
->width
- width
) >> 1);
491 GdkGC
*gc
= selected
? widget
->style
->white_gc
492 : widget
->style
->black_gc
;
496 gdk_gc_set_clip_mask(gc
, item
->image
->mask
);
498 image_y
= MAX(0, SMALL_ICON_HEIGHT
- image
->height
);
499 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ image_y
);
500 gdk_draw_pixmap(widget
->window
, gc
,
502 0, 0, /* Source x,y */
503 image_x
, area
->y
+ image_y
, /* Dest x,y */
508 gdk_gc_set_function(gc
, GDK_INVERT
);
509 gdk_draw_rectangle(widget
->window
,
511 TRUE
, image_x
, area
->y
+ image_y
,
513 gdk_gc_set_function(gc
, GDK_COPY
);
516 if (item
->flags
& ITEM_FLAG_SYMLINK
)
518 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ 8);
519 gdk_gc_set_clip_mask(gc
,
520 default_pixmap
[TYPE_SYMLINK
].mask
);
521 gdk_draw_pixmap(widget
->window
, gc
,
522 default_pixmap
[TYPE_SYMLINK
].pixmap
,
523 0, 0, /* Source x,y */
524 image_x
, area
->y
+ 8, /* Dest x,y */
527 else if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
529 int type
= item
->flags
& ITEM_FLAG_MOUNTED
532 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ 8);
533 gdk_gc_set_clip_mask(gc
,
534 default_pixmap
[type
].mask
);
535 gdk_draw_pixmap(widget
->window
, gc
,
536 default_pixmap
[type
].pixmap
,
537 0, 0, /* Source x,y */
538 image_x
, area
->y
+ 8, /* Dest x,y */
542 gdk_gc_set_clip_mask(gc
, NULL
);
543 gdk_gc_set_clip_origin(gc
, 0, 0);
546 static void draw_large_icon(GtkWidget
*widget
,
551 MaskedPixmap
*image
= item
->image
;
552 int width
= MIN(image
->width
, MAX_ICON_WIDTH
);
553 int height
= MIN(image
->height
, MAX_ICON_WIDTH
);
554 int image_x
= area
->x
+ ((area
->width
- width
) >> 1);
556 GdkGC
*gc
= selected
? widget
->style
->white_gc
557 : widget
->style
->black_gc
;
559 gdk_gc_set_clip_mask(gc
, item
->image
->mask
);
561 image_y
= MAX(0, MAX_ICON_HEIGHT
- image
->height
);
562 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ image_y
);
563 gdk_draw_pixmap(widget
->window
, gc
,
565 0, 0, /* Source x,y */
566 image_x
, area
->y
+ image_y
, /* Dest x,y */
571 gdk_gc_set_function(gc
, GDK_INVERT
);
572 gdk_draw_rectangle(widget
->window
,
574 TRUE
, image_x
, area
->y
+ image_y
,
576 gdk_gc_set_function(gc
, GDK_COPY
);
579 if (item
->flags
& ITEM_FLAG_SYMLINK
)
581 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ 8);
582 gdk_gc_set_clip_mask(gc
,
583 default_pixmap
[TYPE_SYMLINK
].mask
);
584 gdk_draw_pixmap(widget
->window
, gc
,
585 default_pixmap
[TYPE_SYMLINK
].pixmap
,
586 0, 0, /* Source x,y */
587 image_x
, area
->y
+ 8, /* Dest x,y */
590 else if (item
->flags
& ITEM_FLAG_MOUNT_POINT
)
592 int type
= item
->flags
& ITEM_FLAG_MOUNTED
595 gdk_gc_set_clip_origin(gc
, image_x
, area
->y
+ 8);
596 gdk_gc_set_clip_mask(gc
,
597 default_pixmap
[type
].mask
);
598 gdk_draw_pixmap(widget
->window
, gc
,
599 default_pixmap
[type
].pixmap
,
600 0, 0, /* Source x,y */
601 image_x
, area
->y
+ 8, /* Dest x,y */
605 gdk_gc_set_clip_mask(gc
, NULL
);
606 gdk_gc_set_clip_origin(gc
, 0, 0);
609 static void draw_string(GtkWidget
*widget
,
617 int text_height
= font
->ascent
+ font
->descent
;
620 gtk_paint_flat_box(widget
->style
, widget
->window
,
621 GTK_STATE_SELECTED
, GTK_SHADOW_NONE
,
622 NULL
, widget
, "text",
627 gdk_draw_text(widget
->window
,
629 selected
? widget
->style
->white_gc
630 : widget
->style
->black_gc
,
632 string
, strlen(string
));
635 /* Return a string (valid until next call) giving details
638 char *details(DirItem
*item
)
640 mode_t m
= item
->mode
;
641 static guchar
*buf
= NULL
;
646 if (item
->lstat_errno
)
647 buf
= g_strdup_printf("lstat(2) failed: %s",
648 g_strerror(item
->lstat_errno
));
650 buf
= g_strdup_printf("%s %s %-8.8s %-8.8s %s %s",
651 item
->flags
& ITEM_FLAG_APPDIR
? "App " :
652 S_ISDIR(m
) ? "Dir " :
653 S_ISCHR(m
) ? "Char" :
654 S_ISBLK(m
) ? "Blck" :
655 S_ISLNK(m
) ? "Link" :
656 S_ISSOCK(m
) ? "Sock" :
657 S_ISFIFO(m
) ? "Pipe" : "File",
658 pretty_permissions(m
),
659 user_name(item
->uid
),
660 group_name(item
->gid
),
661 format_size_aligned(item
->size
),
662 pretty_time(&item
->mtime
));
666 static void draw_item_full_info(GtkWidget
*widget
,
667 CollectionItem
*colitem
,
670 DirItem
*item
= (DirItem
*) colitem
->data
;
671 MaskedPixmap
*image
= item
->image
;
672 int text_x
= area
->x
+ MAX_ICON_WIDTH
+ 8;
673 int low_text_y
= area
->y
+ area
->height
- fixed_font
->descent
- 2;
674 gboolean selected
= colitem
->selected
;
675 GdkRectangle pic_area
;
677 pic_area
.x
= area
->x
;
678 pic_area
.y
= area
->y
;
679 pic_area
.width
= image
->width
+ 8;
680 pic_area
.height
= area
->height
;
682 draw_large_icon(widget
, &pic_area
, item
, selected
);
688 low_text_y
- item_font
->descent
- fixed_font
->ascent
,
698 if (item
->lstat_errno
)
701 /* Underline the effective permissions */
702 gdk_draw_rectangle(widget
->window
,
703 selected
? widget
->style
->white_gc
704 : widget
->style
->black_gc
,
706 text_x
- 1 + fixed_width
*
707 (5 + 4 * applicable(item
->uid
, item
->gid
)),
708 low_text_y
+ fixed_font
->descent
- 1,
709 fixed_width
* 3 + 1, 1);
712 static void draw_item_small(GtkWidget
*widget
,
713 CollectionItem
*colitem
,
716 DirItem
*item
= (DirItem
*) colitem
->data
;
717 int text_x
= area
->x
+ SMALL_ICON_WIDTH
+ 4;
718 int low_text_y
= area
->y
+ area
->height
- item_font
->descent
- 2;
719 gboolean selected
= colitem
->selected
;
720 GdkRectangle pic_area
;
722 pic_area
.x
= area
->x
;
723 pic_area
.y
= area
->y
;
724 pic_area
.width
= SMALL_ICON_WIDTH
;
725 pic_area
.height
= SMALL_ICON_HEIGHT
;
727 draw_small_icon(widget
, &pic_area
, item
, selected
);
738 static void draw_item_large(GtkWidget
*widget
,
739 CollectionItem
*colitem
,
742 DirItem
*item
= (DirItem
*) colitem
->data
;
743 int text_x
= area
->x
+ ((area
->width
- item
->name_width
) >> 1);
744 int text_y
= area
->y
+ area
->height
- item_font
->descent
- 2;
745 gboolean selected
= colitem
->selected
;
747 draw_large_icon(widget
, area
, item
, selected
);
752 text_x
, text_y
, item
->name_width
,
756 static void show_menu(Collection
*collection
, GdkEventButton
*event
,
757 int item
, gpointer user_data
)
759 show_filer_menu((FilerWindow
*) user_data
, event
, item
);
762 /* Returns TRUE iff the directory still exists. */
763 static gboolean
may_rescan(FilerWindow
*filer_window
, gboolean warning
)
767 g_return_val_if_fail(filer_window
!= NULL
, FALSE
);
769 /* We do a fresh lookup (rather than update) because the inode may
772 dir
= g_fscache_lookup(dir_cache
, filer_window
->path
);
776 delayed_error("ROX-Filer", "Directory missing/deleted");
777 gtk_widget_destroy(filer_window
->window
);
780 if (dir
== filer_window
->directory
)
781 g_fscache_data_unref(dir_cache
, dir
);
784 detach(filer_window
);
785 filer_window
->directory
= dir
;
786 attach(filer_window
);
792 /* Another app has grabbed the selection */
793 static gint
collection_lose_selection(GtkWidget
*widget
,
794 GdkEventSelection
*event
)
796 if (window_with_selection
&&
797 window_with_selection
->collection
== COLLECTION(widget
))
799 FilerWindow
*filer_window
= window_with_selection
;
800 window_with_selection
= NULL
;
801 collection_clear_selection(filer_window
->collection
);
807 /* Someone wants us to send them the selection */
808 static void selection_get(GtkWidget
*widget
,
809 GtkSelectionData
*selection_data
,
814 GString
*reply
, *header
;
815 FilerWindow
*filer_window
;
817 Collection
*collection
;
819 filer_window
= gtk_object_get_data(GTK_OBJECT(widget
), "filer_window");
821 reply
= g_string_new(NULL
);
822 header
= g_string_new(NULL
);
827 g_string_sprintf(header
, " %s",
828 make_path(filer_window
->path
, "")->str
);
830 case TARGET_URI_LIST
:
831 g_string_sprintf(header
, " file://%s%s",
833 make_path(filer_window
->path
, "")->str
);
837 collection
= filer_window
->collection
;
838 for (i
= 0; i
< collection
->number_of_items
; i
++)
840 if (collection
->items
[i
].selected
)
843 (DirItem
*) collection
->items
[i
].data
;
845 g_string_append(reply
, header
->str
);
846 g_string_append(reply
, item
->leafname
);
849 /* This works, but I don't think I like it... */
850 /* g_string_append_c(reply, ' '); */
852 gtk_selection_data_set(selection_data
, xa_string
,
853 8, reply
->str
+ 1, reply
->len
- 1);
854 g_string_free(reply
, TRUE
);
855 g_string_free(header
, TRUE
);
858 /* No items are now selected. This might be because another app claimed
859 * the selection or because the user unselected all the items.
861 static void lose_selection(Collection
*collection
,
865 FilerWindow
*filer_window
= (FilerWindow
*) user_data
;
867 if (window_with_selection
== filer_window
)
869 window_with_selection
= NULL
;
870 gtk_selection_owner_set(NULL
,
871 GDK_SELECTION_PRIMARY
,
876 static void gain_selection(Collection
*collection
,
880 FilerWindow
*filer_window
= (FilerWindow
*) user_data
;
882 if (gtk_selection_owner_set(GTK_WIDGET(collection
),
883 GDK_SELECTION_PRIMARY
,
886 window_with_selection
= filer_window
;
889 collection_clear_selection(filer_window
->collection
);
892 int sort_by_name(const void *item1
, const void *item2
)
894 return strcmp((*((DirItem
**)item1
))->leafname
,
895 (*((DirItem
**)item2
))->leafname
);
898 int sort_by_type(const void *item1
, const void *item2
)
900 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
901 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
904 int diff
= i1
->base_type
- i2
->base_type
;
907 diff
= (i1
->flags
& ITEM_FLAG_APPDIR
)
908 - (i2
->flags
& ITEM_FLAG_APPDIR
);
910 return diff
> 0 ? 1 : -1;
917 diff
= strcmp(m1
->media_type
, m2
->media_type
);
919 diff
= strcmp(m1
->subtype
, m2
->subtype
);
927 return diff
> 0 ? 1 : -1;
929 return sort_by_name(item1
, item2
);
932 int sort_by_date(const void *item1
, const void *item2
)
934 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
935 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
937 return i1
->mtime
> i2
->mtime
? -1 :
938 i1
->mtime
< i2
->mtime
? 1 :
939 sort_by_name(item1
, item2
);
942 int sort_by_size(const void *item1
, const void *item2
)
944 const DirItem
*i1
= (DirItem
*) ((CollectionItem
*) item1
)->data
;
945 const DirItem
*i2
= (DirItem
*) ((CollectionItem
*) item2
)->data
;
947 return i1
->size
> i2
->size
? -1 :
948 i1
->size
< i2
->size
? 1 :
949 sort_by_name(item1
, item2
);
952 static void open_item(Collection
*collection
,
953 gpointer item_data
, int item_number
,
956 FilerWindow
*filer_window
= (FilerWindow
*) user_data
;
958 GdkEventButton
*bevent
;
962 event
= (GdkEvent
*) gtk_get_current_event();
964 bevent
= (GdkEventButton
*) event
;
965 kevent
= (GdkEventKey
*) event
;
969 case GDK_2BUTTON_PRESS
:
970 case GDK_BUTTON_PRESS
:
971 case GDK_BUTTON_RELEASE
:
972 if (bevent
->state
& GDK_SHIFT_MASK
)
975 if (o_new_window_on_1
^ (bevent
->button
== 1))
976 flags
|= OPEN_SAME_WINDOW
;
978 if (bevent
->button
!= 1)
979 flags
|= OPEN_CLOSE_WINDOW
;
981 if (o_single_click
== FALSE
&&
982 (bevent
->state
& GDK_CONTROL_MASK
) != 0)
983 flags
^= OPEN_SAME_WINDOW
| OPEN_CLOSE_WINDOW
;
986 flags
|= OPEN_SAME_WINDOW
;
987 if (kevent
->state
& GDK_SHIFT_MASK
)
994 filer_openitem(filer_window
, item_number
, flags
);
997 /* Return the full path to the directory containing object 'path'.
998 * Relative paths are resolved from the filerwindow's path.
1000 static void follow_symlink(FilerWindow
*filer_window
, char *path
,
1001 gboolean same_window
)
1007 path
= make_path(filer_window
->path
, path
)->str
;
1009 real
= pathdup(path
);
1010 slash
= strrchr(real
, '/');
1014 delayed_error("ROX-Filer",
1015 "Broken symlink (or you don't have permission "
1027 if (filer_window
->panel_type
|| !same_window
)
1031 new = filer_opendir(new_dir
, PANEL_NO
);
1032 filer_set_autoselect(new, slash
+ 1);
1035 filer_change_to(filer_window
, new_dir
, slash
+ 1);
1040 void filer_openitem(FilerWindow
*filer_window
, int item_number
, OpenFlags flags
)
1042 gboolean shift
= (flags
& OPEN_SHIFT
) != 0;
1043 gboolean close_mini
= flags
& OPEN_FROM_MINI
;
1044 gboolean same_window
= (flags
& OPEN_SAME_WINDOW
) != 0
1045 && !filer_window
->panel_type
;
1046 gboolean close_window
= (flags
& OPEN_CLOSE_WINDOW
) != 0
1047 && !filer_window
->panel_type
;
1050 DirItem
*item
= (DirItem
*)
1051 filer_window
->collection
->items
[item_number
].data
;
1052 gboolean wink
= TRUE
, destroy
= FALSE
;
1054 widget
= filer_window
->window
;
1055 full_path
= make_path(filer_window
->path
,
1056 item
->leafname
)->str
;
1058 if (item
->flags
& ITEM_FLAG_SYMLINK
&& shift
)
1060 char path
[MAXPATHLEN
+ 1];
1063 got
= readlink(make_path(filer_window
->path
,
1064 item
->leafname
)->str
,
1067 delayed_error("ROX-Filer", g_strerror(errno
));
1070 g_return_if_fail(got
<= MAXPATHLEN
);
1073 follow_symlink(filer_window
, path
,
1074 flags
& OPEN_SAME_WINDOW
);
1079 switch (item
->base_type
)
1081 case TYPE_DIRECTORY
:
1082 if (item
->flags
& ITEM_FLAG_APPDIR
&& !shift
)
1084 run_app(make_path(filer_window
->path
,
1085 item
->leafname
)->str
);
1091 if (item
->flags
& ITEM_FLAG_MOUNT_POINT
&& shift
)
1093 action_mount(filer_window
, item
);
1094 if (item
->flags
& ITEM_FLAG_MOUNTED
)
1101 filer_change_to(filer_window
, full_path
, NULL
);
1105 filer_opendir(full_path
, PANEL_NO
);
1108 if ((item
->flags
& ITEM_FLAG_EXEC_FILE
) && !shift
)
1110 char *argv
[] = {NULL
, NULL
};
1112 argv
[0] = full_path
;
1114 if (spawn_full(argv
, filer_window
->path
))
1120 report_error("ROX-Filer",
1121 "Failed to fork() child");
1126 MIME_type
*type
= shift
? &text_plain
1129 g_return_if_fail(type
!= NULL
);
1131 if (type_open(full_path
, type
))
1138 message
= g_string_new(NULL
);
1139 g_string_sprintf(message
, "No open "
1140 "action specified for files of "
1141 "this type (%s/%s)",
1144 report_error("ROX-Filer", message
->str
);
1145 g_string_free(message
, TRUE
);
1150 report_error("open_item",
1151 "I don't know how to open that");
1156 gtk_widget_destroy(filer_window
->window
);
1160 collection_wink_item(filer_window
->collection
,
1163 minibuffer_hide(filer_window
);
1167 static gint
pointer_in(GtkWidget
*widget
,
1168 GdkEventCrossing
*event
,
1169 FilerWindow
*filer_window
)
1171 may_rescan(filer_window
, TRUE
);
1175 static gint
focus_in(GtkWidget
*widget
,
1176 GdkEventFocus
*event
,
1177 FilerWindow
*filer_window
)
1179 window_with_focus
= filer_window
;
1184 static gint
focus_out(GtkWidget
*widget
,
1185 GdkEventFocus
*event
,
1186 FilerWindow
*filer_window
)
1188 /* TODO: Shade the cursor */
1193 /* Handle keys that can't be bound with the menu */
1194 static gint
key_press_event(GtkWidget
*widget
,
1196 FilerWindow
*filer_window
)
1198 switch (event
->keyval
)
1201 change_to_parent(filer_window
);
1210 static void toolbar_refresh_clicked(GtkWidget
*widget
,
1211 FilerWindow
*filer_window
)
1214 update_dir(filer_window
, TRUE
);
1217 static void toolbar_home_clicked(GtkWidget
*widget
, FilerWindow
*filer_window
)
1219 filer_change_to(filer_window
, home_dir
, NULL
);
1222 static void toolbar_up_clicked(GtkWidget
*widget
, FilerWindow
*filer_window
)
1224 change_to_parent(filer_window
);
1227 void change_to_parent(FilerWindow
*filer_window
)
1232 if (filer_window
->path
[0] == '/' && filer_window
->path
[1] == '\0')
1233 return; /* Already in the root */
1235 copy
= g_strdup(filer_window
->path
);
1236 slash
= strrchr(copy
, '/');
1241 filer_change_to(filer_window
,
1246 g_warning("No / in directory path!\n");
1252 /* Make filer_window display path. When finished, highlight item 'from', or
1253 * the first item if from is NULL. If there is currently no cursor then
1254 * simply wink 'from' (if not NULL).
1256 void filer_change_to(FilerWindow
*filer_window
, char *path
, char *from
)
1259 char *real_path
= pathdup(path
);
1261 if (o_unique_filer_windows
)
1265 fw
= find_filer_window(real_path
, filer_window
);
1267 gtk_widget_destroy(fw
->window
);
1270 from_dup
= from
&& *from
? g_strdup(from
) : NULL
;
1272 detach(filer_window
);
1273 g_free(filer_window
->path
);
1274 filer_window
->path
= real_path
;
1276 filer_window
->directory
= g_fscache_lookup(dir_cache
,
1277 filer_window
->path
);
1278 if (filer_window
->directory
)
1280 g_free(filer_window
->auto_select
);
1281 filer_window
->had_cursor
=
1282 filer_window
->collection
->cursor_item
!= -1
1283 || filer_window
->had_cursor
;
1284 filer_window
->auto_select
= from_dup
;
1286 filer_set_title(filer_window
);
1287 collection_set_cursor_item(filer_window
->collection
, -1);
1288 attach(filer_window
);
1290 if (GTK_WIDGET_VISIBLE(filer_window
->minibuffer
))
1291 gtk_idle_add((GtkFunction
) minibuffer_show_cb
,
1299 error
= g_strdup_printf("Directory '%s' is not accessible.",
1301 delayed_error("ROX-Filer", error
);
1303 gtk_widget_destroy(filer_window
->window
);
1307 int selected_item_number(Collection
*collection
)
1311 g_return_val_if_fail(collection
!= NULL
, -1);
1312 g_return_val_if_fail(IS_COLLECTION(collection
), -1);
1313 g_return_val_if_fail(collection
->number_selected
== 1, -1);
1315 for (i
= 0; i
< collection
->number_of_items
; i
++)
1316 if (collection
->items
[i
].selected
)
1319 g_warning("selected_item: number_selected is wrong\n");
1324 DirItem
*selected_item(Collection
*collection
)
1328 item
= selected_item_number(collection
);
1331 return (DirItem
*) collection
->items
[item
].data
;
1335 static int filer_confirm_close(GtkWidget
*widget
, GdkEvent
*event
,
1336 FilerWindow
*window
)
1338 /* TODO: We can open lots of these - very irritating! */
1339 return get_choice("Close panel?",
1340 "You have tried to close a panel via the window "
1341 "manager - I usually find that this is accidental... "
1343 2, "Remove", "Cancel") != 0;
1346 /* Make the items as narrow as possible */
1347 static void shrink_width(FilerWindow
*filer_window
)
1350 Collection
*col
= filer_window
->collection
;
1351 int width
= MIN_ITEM_WIDTH
;
1353 DisplayStyle style
= filer_window
->display_style
;
1356 text_height
= item_font
->ascent
+ item_font
->descent
;
1358 for (i
= 0; i
< col
->number_of_items
; i
++)
1360 this_width
= calc_width(filer_window
,
1361 (DirItem
*) col
->items
[i
].data
);
1362 if (this_width
> width
)
1366 collection_set_item_size(filer_window
->collection
,
1368 style
== FULL_INFO
? MAX_ICON_HEIGHT
+ 4 :
1369 style
== SMALL_ICONS
? MAX(text_height
, SMALL_ICON_HEIGHT
) + 4
1370 : text_height
+ MAX_ICON_HEIGHT
+ 8);
1373 void filer_set_sort_fn(FilerWindow
*filer_window
,
1374 int (*fn
)(const void *a
, const void *b
))
1376 if (filer_window
->sort_fn
== fn
)
1379 filer_window
->sort_fn
= fn
;
1382 collection_qsort(filer_window
->collection
,
1383 filer_window
->sort_fn
);
1385 update_options_label();
1388 void filer_style_set(FilerWindow
*filer_window
, DisplayStyle style
)
1390 if (filer_window
->display_style
== style
)
1393 if (filer_window
->panel_type
)
1394 style
= LARGE_ICONS
;
1396 last_display_style
= style
;
1398 filer_window
->display_style
= style
;
1403 collection_set_functions(filer_window
->collection
,
1404 draw_item_small
, test_point_small
);
1407 collection_set_functions(filer_window
->collection
,
1408 draw_item_full_info
, test_point_full_info
);
1411 collection_set_functions(filer_window
->collection
,
1412 draw_item_large
, test_point_large
);
1416 shrink_width(filer_window
);
1418 update_options_label();
1421 FilerWindow
*filer_opendir(char *path
, PanelType panel_type
)
1423 GtkWidget
*hbox
, *scrollbar
, *collection
;
1424 FilerWindow
*filer_window
;
1425 GtkTargetEntry target_table
[] =
1427 {"text/uri-list", 0, TARGET_URI_LIST
},
1428 {"STRING", 0, TARGET_STRING
},
1432 real_path
= pathdup(path
);
1434 if (o_unique_filer_windows
&& panel_type
== PANEL_NO
)
1438 fw
= find_filer_window(real_path
, NULL
);
1442 /* TODO: this should bring the window to the front
1443 * at the same coordinates.
1445 gtk_widget_hide(fw
->window
);
1446 gtk_widget_show(fw
->window
);
1452 filer_window
= g_new(FilerWindow
, 1);
1453 filer_window
->minibuffer
= NULL
;
1454 filer_window
->path
= real_path
;
1455 filer_window
->scanning
= FALSE
;
1456 filer_window
->had_cursor
= FALSE
;
1457 filer_window
->auto_select
= NULL
;
1459 filer_window
->directory
= g_fscache_lookup(dir_cache
,
1460 filer_window
->path
);
1461 if (!filer_window
->directory
)
1465 error
= g_strdup_printf("Directory '%s' not found.", path
);
1466 delayed_error("ROX-Filer", error
);
1468 g_free(filer_window
->path
);
1469 g_free(filer_window
);
1473 filer_window
->show_hidden
= last_show_hidden
;
1474 filer_window
->panel_type
= panel_type
;
1475 filer_window
->temp_item_selected
= FALSE
;
1476 filer_window
->sort_fn
= last_sort_fn
;
1477 filer_window
->flags
= (FilerFlags
) 0;
1478 filer_window
->display_style
= UNKNOWN_STYLE
;
1480 filer_window
->window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
1481 filer_set_title(filer_window
);
1483 collection
= collection_new(NULL
);
1484 gtk_object_set_data(GTK_OBJECT(collection
),
1485 "filer_window", filer_window
);
1486 filer_window
->collection
= COLLECTION(collection
);
1488 gtk_widget_add_events(filer_window
->window
, GDK_ENTER_NOTIFY
);
1489 gtk_signal_connect(GTK_OBJECT(filer_window
->window
),
1490 "enter-notify-event",
1491 GTK_SIGNAL_FUNC(pointer_in
), filer_window
);
1492 gtk_signal_connect(GTK_OBJECT(filer_window
->window
), "focus_in_event",
1493 GTK_SIGNAL_FUNC(focus_in
), filer_window
);
1494 gtk_signal_connect(GTK_OBJECT(filer_window
->window
), "focus_out_event",
1495 GTK_SIGNAL_FUNC(focus_out
), filer_window
);
1496 gtk_signal_connect(GTK_OBJECT(filer_window
->window
), "destroy",
1497 filer_window_destroyed
, filer_window
);
1499 gtk_signal_connect(GTK_OBJECT(filer_window
->collection
), "open_item",
1500 open_item
, filer_window
);
1501 gtk_signal_connect(GTK_OBJECT(collection
), "show_menu",
1502 show_menu
, filer_window
);
1503 gtk_signal_connect(GTK_OBJECT(collection
), "gain_selection",
1504 gain_selection
, filer_window
);
1505 gtk_signal_connect(GTK_OBJECT(collection
), "lose_selection",
1506 lose_selection
, filer_window
);
1507 gtk_signal_connect(GTK_OBJECT(collection
), "drag_selection",
1508 drag_selection
, filer_window
);
1509 gtk_signal_connect(GTK_OBJECT(collection
), "drag_data_get",
1510 drag_data_get
, filer_window
);
1511 gtk_signal_connect(GTK_OBJECT(collection
), "selection_clear_event",
1512 GTK_SIGNAL_FUNC(collection_lose_selection
), NULL
);
1513 gtk_signal_connect (GTK_OBJECT(collection
), "selection_get",
1514 GTK_SIGNAL_FUNC(selection_get
), NULL
);
1515 gtk_selection_add_targets(collection
, GDK_SELECTION_PRIMARY
,
1517 sizeof(target_table
) / sizeof(*target_table
));
1519 filer_style_set(filer_window
, last_display_style
);
1520 drag_set_dest(filer_window
);
1524 int swidth
, sheight
, iwidth
, iheight
;
1525 GtkWidget
*frame
, *win
= filer_window
->window
;
1527 gtk_window_set_wmclass(GTK_WINDOW(win
), "ROX-Panel",
1529 collection_set_panel(filer_window
->collection
, TRUE
);
1530 gtk_signal_connect(GTK_OBJECT(filer_window
->window
),
1532 GTK_SIGNAL_FUNC(filer_confirm_close
),
1535 gdk_window_get_size(GDK_ROOT_PARENT(), &swidth
, &sheight
);
1536 iwidth
= filer_window
->collection
->item_width
;
1537 iheight
= filer_window
->collection
->item_height
;
1540 int height
= iheight
+ PANEL_BORDER
;
1541 int y
= panel_type
== PANEL_TOP
1543 : sheight
- height
- PANEL_BORDER
;
1545 gtk_widget_set_usize(collection
, swidth
, height
);
1546 gtk_widget_set_uposition(win
, 0, y
);
1549 frame
= gtk_frame_new(NULL
);
1550 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_OUT
);
1551 gtk_container_add(GTK_CONTAINER(frame
), collection
);
1552 gtk_container_add(GTK_CONTAINER(win
), frame
);
1554 gtk_widget_show_all(frame
);
1555 gtk_widget_realize(win
);
1556 if (override_redirect
)
1557 gdk_window_set_override_redirect(win
->window
, TRUE
);
1558 make_panel_window(win
->window
);
1563 int col_height
= ROW_HEIGHT_LARGE
* 3;
1565 gtk_signal_connect(GTK_OBJECT(collection
),
1567 GTK_SIGNAL_FUNC(key_press_event
), filer_window
);
1568 gtk_window_set_default_size(GTK_WINDOW(filer_window
->window
),
1569 filer_window
->display_style
== LARGE_ICONS
? 400 : 512,
1570 o_toolbar
== TOOLBAR_NONE
? col_height
:
1571 o_toolbar
== TOOLBAR_NORMAL
? col_height
+ 24 :
1574 hbox
= gtk_hbox_new(FALSE
, 0);
1575 gtk_container_add(GTK_CONTAINER(filer_window
->window
),
1578 vbox
= gtk_vbox_new(FALSE
, 0);
1579 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, TRUE
, TRUE
, 0);
1581 if (o_toolbar
!= TOOLBAR_NONE
)
1585 toolbar
= create_toolbar(filer_window
);
1586 gtk_box_pack_start(GTK_BOX(vbox
), toolbar
,
1588 gtk_widget_show_all(toolbar
);
1591 gtk_box_pack_start(GTK_BOX(vbox
), collection
, TRUE
, TRUE
, 0);
1593 filer_window
->minibuffer
= create_minibuffer(filer_window
);
1594 gtk_box_pack_start(GTK_BOX(vbox
), filer_window
->minibuffer
,
1597 scrollbar
= gtk_vscrollbar_new(COLLECTION(collection
)->vadj
);
1598 gtk_box_pack_start(GTK_BOX(hbox
), scrollbar
, FALSE
, TRUE
, 0);
1599 gtk_accel_group_attach(filer_keys
,
1600 GTK_OBJECT(filer_window
->window
));
1601 gtk_window_set_focus(GTK_WINDOW(filer_window
->window
),
1604 gtk_widget_show(hbox
);
1605 gtk_widget_show(vbox
);
1606 gtk_widget_show(scrollbar
);
1607 gtk_widget_show(collection
);
1610 number_of_windows
++;
1611 gtk_widget_show(filer_window
->window
);
1612 attach(filer_window
);
1614 all_filer_windows
= g_list_prepend(all_filer_windows
, filer_window
);
1616 return filer_window
;
1619 static gint
clear_scanning_display(FilerWindow
*filer_window
)
1621 if (exists(filer_window
))
1622 filer_set_title(filer_window
);
1626 static void set_scanning_display(FilerWindow
*filer_window
, gboolean scanning
)
1628 if (scanning
== filer_window
->scanning
)
1630 filer_window
->scanning
= scanning
;
1633 filer_set_title(filer_window
);
1635 gtk_timeout_add(300, (GtkFunction
) clear_scanning_display
,
1639 static GtkWidget
*create_toolbar(FilerWindow
*filer_window
)
1641 GtkWidget
*frame
, *box
;
1643 if (o_toolbar
== TOOLBAR_GNOME
)
1645 frame
= gtk_handle_box_new();
1646 box
= gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL
,
1648 gtk_container_set_border_width(GTK_CONTAINER(box
), 2);
1649 gtk_toolbar_set_space_style(GTK_TOOLBAR(box
),
1650 GTK_TOOLBAR_SPACE_LINE
);
1651 gtk_toolbar_set_button_relief(GTK_TOOLBAR(box
),
1656 frame
= gtk_frame_new(NULL
);
1657 gtk_frame_set_shadow_type(GTK_FRAME(frame
), GTK_SHADOW_OUT
);
1659 box
= gtk_hbutton_box_new();
1660 gtk_button_box_set_child_size_default(16, 16);
1661 gtk_hbutton_box_set_spacing_default(2);
1662 gtk_button_box_set_layout(GTK_BUTTON_BOX(box
),
1663 GTK_BUTTONBOX_START
);
1666 gtk_container_add(GTK_CONTAINER(frame
), box
);
1668 add_button(box
, TOOLBAR_UP_ICON
,
1669 GTK_SIGNAL_FUNC(toolbar_up_clicked
),
1671 "Up", "Change to parent directory");
1672 add_button(box
, TOOLBAR_HOME_ICON
,
1673 GTK_SIGNAL_FUNC(toolbar_home_clicked
),
1675 "Home", "Change to home directory");
1676 add_button(box
, TOOLBAR_REFRESH_ICON
,
1677 GTK_SIGNAL_FUNC(toolbar_refresh_clicked
),
1679 "Rescan", "Rescan directory contents");
1684 static void add_button(GtkWidget
*box
, int pixmap
,
1685 GtkSignalFunc cb
, FilerWindow
*filer_window
,
1686 char *label
, char *tip
)
1688 GtkWidget
*button
, *icon
;
1690 icon
= gtk_pixmap_new(default_pixmap
[pixmap
].pixmap
,
1691 default_pixmap
[pixmap
].mask
);
1693 if (o_toolbar
== TOOLBAR_GNOME
)
1695 gtk_toolbar_append_element(GTK_TOOLBAR(box
),
1696 GTK_TOOLBAR_CHILD_BUTTON
,
1705 button
= gtk_button_new();
1706 GTK_WIDGET_UNSET_FLAGS(button
, GTK_CAN_FOCUS
);
1708 gtk_container_add(GTK_CONTAINER(button
), icon
);
1709 gtk_signal_connect(GTK_OBJECT(button
), "clicked",
1712 gtk_tooltips_set_tip(tooltips
, button
, tip
, NULL
);
1714 gtk_container_add(GTK_CONTAINER(box
), button
);
1718 /* Build up some option widgets to go in the options dialog, but don't
1721 static GtkWidget
*create_options()
1723 GtkWidget
*vbox
, *menu
, *hbox
;
1725 vbox
= gtk_vbox_new(FALSE
, 0);
1726 gtk_container_set_border_width(GTK_CONTAINER(vbox
), 4);
1728 display_label
= gtk_label_new("<>");
1729 gtk_label_set_line_wrap(GTK_LABEL(display_label
), TRUE
);
1730 gtk_box_pack_start(GTK_BOX(vbox
), display_label
, FALSE
, TRUE
, 0);
1732 toggle_new_window_on_1
=
1733 gtk_check_button_new_with_label("New window on button 1 "
1735 gtk_box_pack_start(GTK_BOX(vbox
), toggle_new_window_on_1
,
1739 gtk_check_button_new_with_label("Menu on button 2 "
1741 gtk_box_pack_start(GTK_BOX(vbox
), toggle_menu_on_2
, FALSE
, TRUE
, 0);
1743 toggle_single_click
=
1744 gtk_check_button_new_with_label("Single-click nagivation");
1745 gtk_box_pack_start(GTK_BOX(vbox
), toggle_single_click
, FALSE
, TRUE
, 0);
1747 toggle_unique_filer_windows
=
1748 gtk_check_button_new_with_label("Unique windows");
1749 gtk_box_pack_start(GTK_BOX(vbox
), toggle_unique_filer_windows
, FALSE
, TRUE
, 0);
1751 hbox
= gtk_hbox_new(FALSE
, 4);
1752 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, TRUE
, 0);
1754 gtk_box_pack_start(GTK_BOX(hbox
),
1755 gtk_label_new("Toolbar type for new windows"),
1757 menu_toolbar
= gtk_option_menu_new();
1758 menu
= gtk_menu_new();
1759 gtk_menu_append(GTK_MENU(menu
), gtk_menu_item_new_with_label("None"));
1760 gtk_menu_append(GTK_MENU(menu
), gtk_menu_item_new_with_label("Normal"));
1761 gtk_menu_append(GTK_MENU(menu
), gtk_menu_item_new_with_label("GNOME"));
1762 gtk_option_menu_set_menu(GTK_OPTION_MENU(menu_toolbar
), menu
);
1763 gtk_box_pack_start(GTK_BOX(hbox
), menu_toolbar
, TRUE
, TRUE
, 0);
1768 static void update_options_label(void)
1772 str
= g_strdup_printf("The last used display style (%s) and sort "
1773 "function (Sort By %s) will be saved if you click on "
1774 "Save.", style_to_name(), sort_fn_to_name());
1775 gtk_label_set_text(GTK_LABEL(display_label
), str
);
1779 /* Reflect current state by changing the widgets in the options box */
1780 static void update_options()
1782 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_new_window_on_1
),
1784 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_menu_on_2
),
1785 collection_menu_button
== 2 ? 1 : 0);
1786 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_single_click
),
1788 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_unique_filer_windows
),
1789 o_unique_filer_windows
);
1790 gtk_option_menu_set_history(GTK_OPTION_MENU(menu_toolbar
), o_toolbar
);
1792 update_options_label();
1795 /* Set current values by reading the states of the widgets in the options box */
1796 static void set_options()
1798 GtkWidget
*item
, *menu
;
1801 o_new_window_on_1
= gtk_toggle_button_get_active(
1802 GTK_TOGGLE_BUTTON(toggle_new_window_on_1
));
1804 collection_menu_button
= gtk_toggle_button_get_active(
1805 GTK_TOGGLE_BUTTON(toggle_menu_on_2
)) ? 2 : 3;
1807 o_single_click
= gtk_toggle_button_get_active(
1808 GTK_TOGGLE_BUTTON(toggle_single_click
));
1810 o_unique_filer_windows
= gtk_toggle_button_get_active(
1811 GTK_TOGGLE_BUTTON(toggle_unique_filer_windows
));
1813 collection_single_click
= o_single_click
? TRUE
: FALSE
;
1815 menu
= gtk_option_menu_get_menu(GTK_OPTION_MENU(menu_toolbar
));
1816 item
= gtk_menu_get_active(GTK_MENU(menu
));
1817 list
= gtk_container_children(GTK_CONTAINER(menu
));
1818 o_toolbar
= (ToolbarType
) g_list_index(list
, item
);
1823 static guchar
*style_to_name(void)
1825 return last_display_style
== LARGE_ICONS
? "Large Icons" :
1826 last_display_style
== SMALL_ICONS
? "Small Icons" :
1830 static guchar
*sort_fn_to_name(void)
1832 return last_sort_fn
== sort_by_name
? "Name" :
1833 last_sort_fn
== sort_by_type
? "Type" :
1834 last_sort_fn
== sort_by_date
? "Date" :
1838 static void save_options()
1840 option_write("filer_new_window_on_1", o_new_window_on_1
? "1" : "0");
1841 option_write("filer_menu_on_2",
1842 collection_menu_button
== 2 ? "1" : "0");
1843 option_write("filer_single_click", o_single_click
? "1" : "0");
1844 option_write("filer_unique_windows", o_unique_filer_windows
? "1" : "0");
1845 option_write("filer_display_style", style_to_name());
1846 option_write("filer_sort_by", sort_fn_to_name());
1847 option_write("filer_toolbar", o_toolbar
== TOOLBAR_NONE
? "None" :
1848 o_toolbar
== TOOLBAR_NORMAL
? "Normal" :
1849 o_toolbar
== TOOLBAR_GNOME
? "GNOME" :
1853 static char *filer_new_window_on_1(char *data
)
1855 o_new_window_on_1
= atoi(data
) != 0;
1859 static char *filer_menu_on_2(char *data
)
1861 collection_menu_button
= atoi(data
) != 0 ? 2 : 3;
1865 static char *filer_single_click(char *data
)
1867 o_single_click
= atoi(data
) != 0;
1868 collection_single_click
= o_single_click
? TRUE
: FALSE
;
1872 static char *filer_unique_windows(char *data
)
1874 o_unique_filer_windows
= atoi(data
) != 0;
1878 static char *filer_display_style(char *data
)
1880 if (g_strcasecmp(data
, "Large Icons") == 0)
1881 last_display_style
= LARGE_ICONS
;
1882 else if (g_strcasecmp(data
, "Small Icons") == 0)
1883 last_display_style
= SMALL_ICONS
;
1884 else if (g_strcasecmp(data
, "Full Info") == 0)
1885 last_display_style
= FULL_INFO
;
1887 return "Unknown display style";
1892 static char *filer_sort_by(char *data
)
1894 if (g_strcasecmp(data
, "Name") == 0)
1895 last_sort_fn
= sort_by_name
;
1896 else if (g_strcasecmp(data
, "Type") == 0)
1897 last_sort_fn
= sort_by_type
;
1898 else if (g_strcasecmp(data
, "Date") == 0)
1899 last_sort_fn
= sort_by_date
;
1900 else if (g_strcasecmp(data
, "Size") == 0)
1901 last_sort_fn
= sort_by_size
;
1903 return "Unknown sort type";
1908 static char *filer_toolbar(char *data
)
1910 if (g_strcasecmp(data
, "None") == 0)
1911 o_toolbar
= TOOLBAR_NONE
;
1912 else if (g_strcasecmp(data
, "Normal") == 0)
1913 o_toolbar
= TOOLBAR_NORMAL
;
1914 else if (g_strcasecmp(data
, "GNOME") == 0)
1915 o_toolbar
= TOOLBAR_GNOME
;
1917 return "Unknown toolbar type";
1922 /* Note that filer_window may not exist after this call. */
1923 void update_dir(FilerWindow
*filer_window
, gboolean warning
)
1925 if (may_rescan(filer_window
, warning
))
1926 dir_update(filer_window
->directory
, filer_window
->path
);
1929 void filer_set_hidden(FilerWindow
*filer_window
, gboolean hidden
)
1931 Directory
*dir
= filer_window
->directory
;
1933 if (filer_window
->show_hidden
== hidden
)
1936 filer_window
->show_hidden
= hidden
;
1937 last_show_hidden
= hidden
;
1939 g_fscache_data_ref(dir_cache
, dir
);
1940 detach(filer_window
);
1941 filer_window
->directory
= dir
;
1942 attach(filer_window
);
1945 /* Refresh the various caches even if we don't think we need to */
1946 void full_refresh(void)
1951 /* See whether a filer window with a given path already exists
1952 * and is different from diff.
1954 static FilerWindow
*find_filer_window(char *path
, FilerWindow
*diff
)
1956 GList
*next
= all_filer_windows
;
1960 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1962 if (filer_window
->panel_type
== PANEL_NO
&&
1963 filer_window
!= diff
&&
1964 strcmp(path
, filer_window
->path
) == 0)
1966 return filer_window
;
1975 /* This path has been mounted/umounted/deleted some files - update all dirs */
1976 void filer_check_mounted(char *path
)
1978 GList
*next
= all_filer_windows
;
1985 FilerWindow
*filer_window
= (FilerWindow
*) next
->data
;
1989 if (strncmp(path
, filer_window
->path
, len
) == 0)
1991 char s
= filer_window
->path
[len
];
1993 if (s
== '/' || s
== '\0')
1994 update_dir(filer_window
, FALSE
);
1999 /* Like minibuffer_show(), except that:
2000 * - It returns FALSE (to be used from an idle callback)
2001 * - It checks that the filer window still exists.
2003 static gboolean
minibuffer_show_cb(FilerWindow
*filer_window
)
2005 if (exists(filer_window
))
2006 minibuffer_show(filer_window
);
2010 static gboolean
exists(FilerWindow
*filer_window
)
2014 for (next
= all_filer_windows
; next
; next
= next
->next
)
2016 FilerWindow
*fw
= (FilerWindow
*) next
->data
;
2018 if (fw
== filer_window
)
2025 /* Highlight (wink or cursor) this item in the filer window. If the item
2026 * isn't already there but we're scanning then highlight it if it
2029 void filer_set_autoselect(FilerWindow
*filer_window
, guchar
*leaf
)
2031 Collection
*col
= filer_window
->collection
;
2034 g_free(filer_window
->auto_select
);
2035 filer_window
->auto_select
= NULL
;
2037 for (i
= 0; i
< col
->number_of_items
; i
++)
2039 DirItem
*item
= (DirItem
*) col
->items
[i
].data
;
2041 if (strcmp(item
->leafname
, leaf
) == 0)
2043 if (col
->cursor_item
!= -1)
2044 collection_set_cursor_item(col
, i
);
2046 collection_wink_item(col
, i
);
2051 filer_window
->auto_select
= g_strdup(leaf
);
2054 static void filer_set_title(FilerWindow
*filer_window
)
2056 if (filer_window
->scanning
)
2060 title
= g_strdup_printf("%s (Scanning)", filer_window
->path
);
2061 gtk_window_set_title(GTK_WINDOW(filer_window
->window
),
2066 gtk_window_set_title(GTK_WINDOW(filer_window
->window
),
2067 filer_window
->path
);