r4718: Removed an unused variable (Thomas Leonard).
[rox-filer/translations.git] / ROX-Filer / src / toolbar.c
blob047fbd0c3c12fc2a3735b7e6bea9a94b1fc7a4e7
1 /*
2 * ROX-Filer, filer for the ROX desktop project
3 * Copyright (C) 2006, Thomas Leonard and others (see changelog for details).
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
20 /* toolbar.c - for the button bars that go along the tops of windows */
22 #include "config.h"
24 #include <string.h>
26 #include "global.h"
28 #include "toolbar.h"
29 #include "options.h"
30 #include "support.h"
31 #include "main.h"
32 #include "menu.h"
33 #include "dnd.h"
34 #include "filer.h"
35 #include "display.h"
36 #include "pixmaps.h"
37 #include "bind.h"
38 #include "type.h"
39 #include "dir.h"
40 #include "diritem.h"
41 #include "view_iface.h"
42 #include "bookmarks.h"
43 #include "gui_support.h"
45 typedef struct _Tool Tool;
47 typedef enum {DROP_NONE, DROP_TO_PARENT, DROP_TO_HOME, DROP_BOOKMARK} DropDest;
49 struct _Tool {
50 const gchar *label;
51 const gchar *name;
52 const gchar *tip; /* Tooltip */
53 void (*clicked)(GtkWidget *w, FilerWindow *filer_window);
54 DropDest drop_action;
55 gboolean enabled;
56 gboolean menu; /* Activate on button-press */
59 Option o_toolbar, o_toolbar_info, o_toolbar_disable;
60 Option o_toolbar_min_width;
62 static FilerWindow *filer_window_being_counted;
64 /* TRUE if the button presses (or released) should open a new window,
65 * rather than reusing the existing one.
67 #define NEW_WIN_BUTTON(button_event) \
68 (o_new_button_1.int_value \
69 ? ((GdkEventButton *) button_event)->button == 1 \
70 : ((GdkEventButton *) button_event)->button != 1)
72 /* Static prototypes */
73 static void toolbar_close_clicked(GtkWidget *widget, FilerWindow *filer_window);
74 static void toolbar_up_clicked(GtkWidget *widget, FilerWindow *filer_window);
75 static void toolbar_home_clicked(GtkWidget *widget, FilerWindow *filer_window);
76 static void toolbar_bookmarks_clicked(GtkWidget *widget,
77 FilerWindow *filer_window);
78 static void toolbar_help_clicked(GtkWidget *widget, FilerWindow *filer_window);
79 static void toolbar_refresh_clicked(GtkWidget *widget,
80 FilerWindow *filer_window);
81 static void toolbar_size_clicked(GtkWidget *widget, FilerWindow *filer_window);
82 static void toolbar_autosize_clicked(GtkWidget *widget, FilerWindow *filer_window);
83 static void toolbar_details_clicked(GtkWidget *widget,
84 FilerWindow *filer_window);
85 static void toolbar_hidden_clicked(GtkWidget *widget,
86 FilerWindow *filer_window);
87 static void toolbar_select_clicked(GtkWidget *widget,
88 FilerWindow *filer_window);
89 static void toolbar_sort_clicked(GtkWidget *widget,
90 FilerWindow *filer_window);
91 static GtkWidget *add_button(GtkWidget *bar, Tool *tool,
92 FilerWindow *filer_window);
93 static GtkWidget *create_toolbar(FilerWindow *filer_window);
94 static gboolean drag_motion(GtkWidget *widget,
95 GdkDragContext *context,
96 gint x,
97 gint y,
98 guint time,
99 FilerWindow *filer_window);
100 static void drag_leave(GtkWidget *widget,
101 GdkDragContext *context,
102 guint32 time,
103 FilerWindow *filer_window);
104 static void handle_drops(FilerWindow *filer_window,
105 GtkWidget *button,
106 DropDest dest);
107 static void toggle_selected(GtkToggleButton *widget, gpointer data);
108 static void option_notify(void);
109 static GList *build_tool_options(Option *option, xmlNode *node, guchar *label);
110 static void tally_items(gpointer key, gpointer value, gpointer data);
112 static Tool all_tools[] = {
113 {N_("Close"), GTK_STOCK_CLOSE, N_("Close filer window"),
114 toolbar_close_clicked, DROP_NONE, FALSE,
115 FALSE},
117 {N_("Up"), GTK_STOCK_GO_UP, N_("Change to parent directory"),
118 toolbar_up_clicked, DROP_TO_PARENT, TRUE,
119 FALSE},
121 {N_("Home"), GTK_STOCK_HOME, N_("Change to home directory"),
122 toolbar_home_clicked, DROP_TO_HOME, TRUE,
123 FALSE},
125 {N_("Bookmarks"), ROX_STOCK_BOOKMARKS, N_("Bookmarks menu"),
126 toolbar_bookmarks_clicked, DROP_BOOKMARK, FALSE,
127 TRUE},
129 {N_("Scan"), GTK_STOCK_REFRESH, N_("Rescan directory contents"),
130 toolbar_refresh_clicked, DROP_NONE, TRUE,
131 FALSE},
133 {N_("Size"), GTK_STOCK_ZOOM_IN, N_("Change icon size"),
134 toolbar_size_clicked, DROP_NONE, TRUE,
135 FALSE},
137 {N_("Size"), GTK_STOCK_ZOOM_FIT, N_("Automatic size mode"),
138 toolbar_autosize_clicked, DROP_NONE, TRUE,
139 FALSE},
141 {N_("Details"), ROX_STOCK_SHOW_DETAILS, N_("Show extra details"),
142 toolbar_details_clicked, DROP_NONE, TRUE,
143 FALSE},
145 {N_("Sort"), GTK_STOCK_SORT_ASCENDING, N_("Change sort criteria"),
146 toolbar_sort_clicked, DROP_NONE, FALSE,
147 FALSE},
149 {N_("Hidden"), ROX_STOCK_SHOW_HIDDEN, N_("Left: Show/hide hidden files\n"
150 "Right: Show/hide thumbnails"),
151 toolbar_hidden_clicked, DROP_NONE, TRUE,
152 FALSE},
154 {N_("Select"), ROX_STOCK_SELECT, N_("Select all/invert selection"),
155 toolbar_select_clicked, DROP_NONE, FALSE,
156 FALSE},
158 {N_("Help"), GTK_STOCK_HELP, N_("Show ROX-Filer help"),
159 toolbar_help_clicked, DROP_NONE, TRUE,
160 FALSE},
164 /****************************************************************
165 * EXTERNAL INTERFACE *
166 ****************************************************************/
168 void toolbar_init(void)
170 option_add_int(&o_toolbar, "toolbar_type", TOOLBAR_NORMAL);
171 option_add_int(&o_toolbar_info, "toolbar_show_info", 1);
172 option_add_string(&o_toolbar_disable, "toolbar_disable",
173 GTK_STOCK_CLOSE);
174 option_add_int(&o_toolbar_min_width, "toolbar_min_width", 1);
175 option_add_notify(option_notify);
177 option_register_widget("tool-options", build_tool_options);
180 void toolbar_update_info(FilerWindow *filer_window)
182 gchar *label;
183 ViewIface *view;
184 int n_selected;
186 g_return_if_fail(filer_window != NULL);
188 if (o_toolbar.int_value == TOOLBAR_NONE || !o_toolbar_info.int_value)
189 return; /* Not showing info */
191 if (filer_window->target_cb)
192 return;
194 view = filer_window->view;
196 n_selected = view_count_selected(view);
198 if (n_selected == 0)
200 gchar *s = NULL;
201 int n_items;
203 if (filer_window->scanning)
205 gtk_label_set_text(
206 GTK_LABEL(filer_window->toolbar_text), "");
207 return;
210 if (!(filer_window->show_hidden ||
211 filer_window->temp_show_hidden) ||
212 filer_window->filter!=FILER_SHOW_ALL)
214 GHashTable *hash = filer_window->directory->known_items;
215 int tally = 0;
217 filer_window_being_counted=filer_window;
218 g_hash_table_foreach(hash, tally_items, &tally);
220 if (tally)
221 s = g_strdup_printf(_(" (%u hidden)"), tally);
224 n_items = view_count_items(view);
226 if (n_items)
227 label = g_strdup_printf("%d %s%s",
228 n_items,
229 n_items != 1 ? _("items") : _("item"),
230 s ? s : "");
231 else /* (French plurals work differently for zero) */
232 label = g_strdup_printf(_("No items%s"),
233 s ? s : "");
234 g_free(s);
236 else
238 double size = 0;
239 ViewIter iter;
240 DirItem *item;
242 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
244 while ((item = iter.next(&iter)))
246 if (item->base_type != TYPE_DIRECTORY &&
247 item->base_type != TYPE_UNKNOWN)
248 size += (double) item->size;
251 label = g_strdup_printf(_("%u selected (%s)"),
252 n_selected, format_double_size(size));
255 gtk_label_set_text(GTK_LABEL(filer_window->toolbar_text), label);
256 g_free(label);
259 /* Create, destroy or recreate toolbar for this window so that it
260 * matches the option setting.
262 void toolbar_update_toolbar(FilerWindow *filer_window)
264 g_return_if_fail(filer_window != NULL);
266 if (filer_window->toolbar)
268 gtk_widget_destroy(filer_window->toolbar);
269 filer_window->toolbar = NULL;
270 filer_window->toolbar_text = NULL;
273 if (o_toolbar.int_value != TOOLBAR_NONE)
275 filer_window->toolbar = create_toolbar(filer_window);
276 gtk_box_pack_start(filer_window->toplevel_vbox,
277 filer_window->toolbar, FALSE, TRUE, 0);
278 gtk_box_reorder_child(filer_window->toplevel_vbox,
279 filer_window->toolbar, 0);
280 gtk_widget_show_all(filer_window->toolbar);
283 filer_target_mode(filer_window, NULL, NULL, NULL);
284 toolbar_update_info(filer_window);
287 /****************************************************************
288 * INTERNAL FUNCTIONS *
289 ****************************************************************/
291 static void toolbar_help_clicked(GtkWidget *widget, FilerWindow *filer_window)
293 GdkEvent *event;
295 event = gtk_get_current_event();
296 if (event->type == GDK_BUTTON_RELEASE &&
297 ((GdkEventButton *) event)->button != 1)
298 menu_rox_help(NULL, HELP_MANUAL, NULL);
299 else
300 filer_opendir(make_path(app_dir, "Help"), NULL, NULL);
301 gdk_event_free(event);
304 static void toolbar_refresh_clicked(GtkWidget *widget,
305 FilerWindow *filer_window)
307 GdkEvent *event;
309 event = gtk_get_current_event();
310 if (event->type == GDK_BUTTON_RELEASE &&
311 ((GdkEventButton *) event)->button != 1)
313 filer_opendir(filer_window->sym_path, filer_window, NULL);
315 else
316 filer_refresh(filer_window);
317 gdk_event_free(event);
320 static void toolbar_home_clicked(GtkWidget *widget, FilerWindow *filer_window)
322 GdkEvent *event;
324 event = gtk_get_current_event();
325 if (event->type == GDK_BUTTON_RELEASE && NEW_WIN_BUTTON(event))
327 filer_opendir(home_dir, filer_window, NULL);
329 else
330 filer_change_to(filer_window, home_dir, NULL);
331 gdk_event_free(event);
334 static void toolbar_bookmarks_clicked(GtkWidget *widget,
335 FilerWindow *filer_window)
337 GdkEvent *event;
339 g_return_if_fail(filer_window != NULL);
341 event = gtk_get_current_event();
342 if (event->type == GDK_BUTTON_PRESS &&
343 ((GdkEventButton *) event)->button == 1)
345 bookmarks_show_menu(filer_window);
347 else if (event->type == GDK_BUTTON_RELEASE &&
348 ((GdkEventButton *) event)->button != 1)
350 bookmarks_edit();
352 gdk_event_free(event);
355 static void toolbar_close_clicked(GtkWidget *widget, FilerWindow *filer_window)
357 GdkEvent *event;
359 g_return_if_fail(filer_window != NULL);
361 event = gtk_get_current_event();
362 if (event->type == GDK_BUTTON_RELEASE &&
363 ((GdkEventButton *) event)->button != 1)
365 filer_opendir(filer_window->sym_path, filer_window, NULL);
367 else if (!filer_window_delete(filer_window->window, NULL, filer_window))
368 gtk_widget_destroy(filer_window->window);
369 gdk_event_free(event);
372 static void toolbar_up_clicked(GtkWidget *widget, FilerWindow *filer_window)
374 GdkEvent *event;
376 event = gtk_get_current_event();
377 if (event->type == GDK_BUTTON_RELEASE && NEW_WIN_BUTTON(event))
379 filer_open_parent(filer_window);
381 else
382 change_to_parent(filer_window);
383 gdk_event_free(event);
386 static void toolbar_autosize_clicked(GtkWidget *widget, FilerWindow *filer_window)
388 GdkEventButton *bev;
390 bev = (GdkEventButton *) gtk_get_current_event();
391 if (bev->type == GDK_BUTTON_RELEASE)
393 display_set_layout(filer_window, AUTO_SIZE_ICONS, filer_window->details_type,
394 TRUE);
396 gdk_event_free((GdkEvent *) bev);
399 static void toolbar_size_clicked(GtkWidget *widget, FilerWindow *filer_window)
401 GdkEventButton *bev;
403 bev = (GdkEventButton *) gtk_get_current_event();
404 if (bev->type == GDK_BUTTON_RELEASE)
405 display_change_size(filer_window, bev->button == 1);
406 gdk_event_free((GdkEvent *) bev);
409 static void toolbar_sort_clicked(GtkWidget *widget,
410 FilerWindow *filer_window)
412 GdkEventButton *bev;
413 int i, current, next, next_wrapped;
414 gboolean adjust;
415 GtkSortType dir;
416 gchar *tip;
418 static const SortType sorts[]={
419 SORT_NAME, SORT_TYPE, SORT_DATE, SORT_SIZE,
420 SORT_OWNER, SORT_GROUP,
422 static const char *sort_names[] = {
423 N_("Sort by name"), N_("Sort by type"), N_("Sort by date"),
424 N_("Sort by size"), N_("Sort by owner"), N_("Sort by group"),
427 bev = (GdkEventButton *) gtk_get_current_event();
428 adjust = (bev->button != 1) && bev->type == GDK_BUTTON_RELEASE;
429 gdk_event_free((GdkEvent *) bev);
431 current = -1;
432 dir = filer_window->sort_order;
433 for (i=0; i < G_N_ELEMENTS(sort_names); i++)
435 if (filer_window->sort_type == sorts[i])
437 current = i;
438 break;
442 if (current == -1)
443 next = 0;
444 else if (adjust)
445 next = current - 1;
446 else
447 next = current + 1;
449 next_wrapped = next % G_N_ELEMENTS(sorts);
451 if (next_wrapped != next)
452 dir = (dir == GTK_SORT_ASCENDING)
453 ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING;
455 display_set_sort_type(filer_window, sorts[next_wrapped], dir);
456 tip = g_strconcat(_(sort_names[next_wrapped]), ", ",
457 dir == GTK_SORT_ASCENDING
458 ? _("ascending") : _("descending"),
459 NULL);
460 tooltip_show(tip);
461 g_free(tip);
464 static void toolbar_details_clicked(GtkWidget *widget,
465 FilerWindow *filer_window)
467 if (filer_window->view_type == VIEW_TYPE_DETAILS)
468 filer_set_view_type(filer_window, VIEW_TYPE_COLLECTION);
469 else
470 filer_set_view_type(filer_window, VIEW_TYPE_DETAILS);
473 static void toolbar_hidden_clicked(GtkWidget *widget,
474 FilerWindow *filer_window)
476 GdkEvent *event;
478 event = gtk_get_current_event();
479 if (event->type == GDK_BUTTON_RELEASE &&
480 ((GdkEventButton *) event)->button == 1)
482 display_set_hidden(filer_window, !filer_window->show_hidden);
484 else
486 display_set_thumbs(filer_window, !filer_window->show_thumbs);
490 static gboolean invert_cb(ViewIter *iter, gpointer data)
492 return !view_get_selected((ViewIface *) data, iter);
495 static void toolbar_select_clicked(GtkWidget *widget, FilerWindow *filer_window)
497 GdkEvent *event;
499 event = gtk_get_current_event();
500 if (event->type == GDK_BUTTON_RELEASE)
502 if (((GdkEventButton *) event)->button == 1)
503 view_select_all(filer_window->view);
504 else
505 view_select_if(filer_window->view, invert_cb,
506 filer_window->view);
508 filer_window->temp_item_selected = FALSE;
509 gdk_event_free(event);
512 /* If filer_window is NULL, the toolbar is for the options window */
513 static GtkWidget *create_toolbar(FilerWindow *filer_window)
515 GtkWidget *bar;
516 GtkWidget *b;
517 int i;
518 int width;
520 bar = gtk_toolbar_new();
522 if (o_toolbar.int_value == TOOLBAR_NORMAL || !filer_window)
523 gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_ICONS);
524 else if (o_toolbar.int_value == TOOLBAR_HORIZONTAL)
525 gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_BOTH_HORIZ);
526 else
527 gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_BOTH);
529 width=0;
530 for (i = 0; i < sizeof(all_tools) / sizeof(*all_tools); i++)
532 Tool *tool = &all_tools[i];
533 GtkRequisition req;
535 if (filer_window && !tool->enabled)
536 continue;
538 b = add_button(bar, tool, filer_window);
540 gtk_widget_size_request(b, &req);
541 width+=req.width;
543 if (filer_window && tool->drop_action != DROP_NONE)
544 handle_drops(filer_window, b, tool->drop_action);
547 if (filer_window)
549 if(o_toolbar_min_width.int_value)
551 /* Make the toolbar wide enough for all icons to be
552 seen, plus a little for the (start of the) text
553 label */
554 gtk_widget_set_size_request(bar, width+32, -1);
555 } else {
556 gtk_widget_set_size_request(bar, 100, -1);
559 filer_window->toolbar_text = gtk_label_new("");
560 gtk_misc_set_alignment(GTK_MISC(filer_window->toolbar_text),
561 0, 0.5);
562 gtk_toolbar_append_widget(GTK_TOOLBAR(bar),
563 filer_window->toolbar_text, NULL, NULL);
566 return bar;
569 /* This is used to simulate a click when button 3 is used (GtkButton
570 * normally ignores this).
572 static gint toolbar_other_button = 0;
573 static gint toolbar_button_pressed(GtkButton *button,
574 GdkEventButton *event,
575 FilerWindow *filer_window)
577 gint b = event->button;
578 Tool *tool;
580 tool = g_object_get_data(G_OBJECT(button), "rox-tool");
581 g_return_val_if_fail(tool != NULL, TRUE);
583 if (tool->menu && b == 1)
585 tool->clicked((GtkWidget *) button, filer_window);
586 return TRUE;
589 if ((b == 2 || b == 3) && toolbar_other_button == 0)
591 toolbar_other_button = event->button;
592 gtk_grab_add(GTK_WIDGET(button));
593 gtk_button_pressed(button);
595 return TRUE;
598 return FALSE;
601 static gint toolbar_button_released(GtkButton *button,
602 GdkEventButton *event,
603 FilerWindow *filer_window)
605 if (event->button == toolbar_other_button)
607 toolbar_other_button = 0;
608 gtk_grab_remove(GTK_WIDGET(button));
609 gtk_button_released(button);
611 return TRUE;
614 return FALSE;
617 /* If filer_window is NULL, the toolbar is for the options window */
618 static GtkWidget *add_button(GtkWidget *bar, Tool *tool,
619 FilerWindow *filer_window)
621 GtkWidget *button, *icon_widget;
623 icon_widget = gtk_image_new_from_stock(tool->name,
624 GTK_ICON_SIZE_LARGE_TOOLBAR);
626 button = gtk_toolbar_insert_element(GTK_TOOLBAR(bar),
627 filer_window ? GTK_TOOLBAR_CHILD_BUTTON
628 : GTK_TOOLBAR_CHILD_TOGGLEBUTTON,
629 NULL,
630 _(tool->label),
631 _(tool->tip), NULL,
632 icon_widget,
633 NULL, NULL, /* CB, userdata */
634 GTK_TOOLBAR(bar)->num_children);
635 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
637 if (o_toolbar.int_value == TOOLBAR_HORIZONTAL)
639 GtkWidget *hbox, *label;
640 GList *kids;
641 hbox = GTK_BIN(button)->child;
642 kids = gtk_container_get_children(GTK_CONTAINER(hbox));
643 label = g_list_nth_data(kids, 1);
644 g_list_free(kids);
646 if (label)
648 gtk_box_set_child_packing(GTK_BOX(hbox), label,
649 TRUE, TRUE, 0, GTK_PACK_END);
650 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
654 g_object_set_data(G_OBJECT(button), "rox-tool", tool);
656 if (filer_window)
658 g_signal_connect(button, "clicked",
659 G_CALLBACK(tool->clicked), filer_window);
660 g_signal_connect(button, "button_press_event",
661 G_CALLBACK(toolbar_button_pressed), filer_window);
662 g_signal_connect(button, "button_release_event",
663 G_CALLBACK(toolbar_button_released), filer_window);
665 else
667 g_signal_connect(button, "clicked",
668 G_CALLBACK(toggle_selected), NULL);
669 g_object_set_data(G_OBJECT(button), "tool_name",
670 (gpointer) tool->name);
673 return button;
676 static void toggle_selected(GtkToggleButton *widget, gpointer data)
678 option_check_widget(&o_toolbar_disable);
681 /* Called during the drag when the mouse is in a widget registered
682 * as a drop target. Returns TRUE if we can accept the drop.
684 static gboolean drag_motion(GtkWidget *widget,
685 GdkDragContext *context,
686 gint x,
687 gint y,
688 guint time,
689 FilerWindow *filer_window)
691 GdkDragAction action = context->suggested_action;
692 DropDest dest;
693 gpointer type = (gpointer) drop_dest_dir;
695 dest = (DropDest) g_object_get_data(G_OBJECT(widget), "toolbar_dest");
697 if ((context->actions & GDK_ACTION_ASK) && o_dnd_left_menu.int_value &&
698 dest != DROP_BOOKMARK)
700 guint state;
701 gdk_window_get_pointer(NULL, NULL, NULL, &state);
702 if (state & GDK_BUTTON1_MASK)
703 action = GDK_ACTION_ASK;
706 if (dest == DROP_TO_HOME)
707 g_dataset_set_data(context, "drop_dest_path",
708 (gchar *) home_dir);
709 else if (dest == DROP_BOOKMARK)
710 type = (gpointer) drop_dest_bookmark;
711 else
712 g_dataset_set_data_full(context, "drop_dest_path",
713 g_path_get_dirname(filer_window->sym_path),
714 g_free);
716 g_dataset_set_data(context, "drop_dest_type", type);
717 gdk_drag_status(context, action, time);
719 dnd_spring_load(context, filer_window);
720 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
722 return TRUE;
725 static void drag_leave(GtkWidget *widget,
726 GdkDragContext *context,
727 guint32 time,
728 FilerWindow *filer_window)
730 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NONE);
731 dnd_spring_abort();
734 static void handle_drops(FilerWindow *filer_window,
735 GtkWidget *button,
736 DropDest dest)
738 make_drop_target(button, 0);
739 g_signal_connect(button, "drag_motion",
740 G_CALLBACK(drag_motion), filer_window);
741 g_signal_connect(button, "drag_leave",
742 G_CALLBACK(drag_leave), filer_window);
743 g_object_set_data(G_OBJECT(button), "toolbar_dest", (gpointer) dest);
746 static void tally_items(gpointer key, gpointer value, gpointer data)
748 DirItem *item = (DirItem *) value;
749 int *tally = (int *) data;
751 if (!filer_match_filter(filer_window_being_counted, item))
752 (*tally)++;
755 static void option_notify(void)
757 int i;
758 gboolean changed = FALSE;
759 guchar *list = o_toolbar_disable.value;
761 for (i = 0; i < sizeof(all_tools) / sizeof(*all_tools); i++)
763 Tool *tool = &all_tools[i];
764 gboolean old = tool->enabled;
766 tool->enabled = !in_list(tool->name, list);
768 if (old != tool->enabled)
769 changed = TRUE;
772 if (changed || o_toolbar.has_changed || o_toolbar_info.has_changed)
774 GList *next;
776 for (next = all_filer_windows; next; next = next->next)
778 FilerWindow *filer_window = (FilerWindow *) next->data;
780 toolbar_update_toolbar(filer_window);
785 static void update_tools(Option *option)
787 GList *next, *kids;
789 kids = gtk_container_get_children(GTK_CONTAINER(option->widget));
791 for (next = kids; next; next = next->next)
793 GtkToggleButton *kid = (GtkToggleButton *) next->data;
794 guchar *name;
796 name = g_object_get_data(G_OBJECT(kid), "tool_name");
798 g_return_if_fail(name != NULL);
800 gtk_toggle_button_set_active(kid,
801 !in_list(name, option->value));
804 g_list_free(kids);
807 static guchar *read_tools(Option *option)
809 GList *next, *kids;
810 GString *list;
811 guchar *retval;
813 list = g_string_new(NULL);
815 kids = gtk_container_get_children(GTK_CONTAINER(option->widget));
817 for (next = kids; next; next = next->next)
819 GtkToggleButton *kid = (GtkToggleButton *) next->data;
820 guchar *name;
822 if (!gtk_toggle_button_get_active(kid))
824 name = g_object_get_data(G_OBJECT(kid), "tool_name");
825 g_return_val_if_fail(name != NULL, list->str);
827 if (list->len)
828 g_string_append(list, ", ");
829 g_string_append(list, name);
833 g_list_free(kids);
834 retval = list->str;
835 g_string_free(list, FALSE);
837 return retval;
840 static GList *build_tool_options(Option *option, xmlNode *node, guchar *label)
842 GtkWidget *bar;
844 g_return_val_if_fail(option != NULL, NULL);
846 bar = create_toolbar(NULL);
848 option->update_widget = update_tools;
849 option->read_widget = read_tools;
850 option->widget = bar;
852 return g_list_append(NULL, bar);