r4475: When reading the output from 'du' for the Properties box, set the channel's
[rox-filer.git] / ROX-Filer / src / toolbar.c
blob5456412f34eb4e9bf19af236cec767ffd1d09bd4
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2005, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* toolbar.c - for the button bars that go along the tops of windows */
24 #include "config.h"
26 #include <string.h>
28 #include "global.h"
30 #include "toolbar.h"
31 #include "options.h"
32 #include "support.h"
33 #include "main.h"
34 #include "menu.h"
35 #include "dnd.h"
36 #include "filer.h"
37 #include "display.h"
38 #include "pixmaps.h"
39 #include "bind.h"
40 #include "type.h"
41 #include "dir.h"
42 #include "diritem.h"
43 #include "view_iface.h"
44 #include "bookmarks.h"
45 #include "gui_support.h"
47 typedef struct _Tool Tool;
49 typedef enum {DROP_NONE, DROP_TO_PARENT, DROP_TO_HOME, DROP_BOOKMARK} DropDest;
51 struct _Tool {
52 const gchar *label;
53 const gchar *name;
54 const gchar *tip; /* Tooltip */
55 void (*clicked)(GtkWidget *w, FilerWindow *filer_window);
56 DropDest drop_action;
57 gboolean enabled;
58 gboolean menu; /* Activate on button-press */
61 Option o_toolbar, o_toolbar_info, o_toolbar_disable;
62 Option o_toolbar_min_width;
64 static FilerWindow *filer_window_being_counted;
66 /* TRUE if the button presses (or released) should open a new window,
67 * rather than reusing the existing one.
69 #define NEW_WIN_BUTTON(button_event) \
70 (o_new_button_1.int_value \
71 ? ((GdkEventButton *) button_event)->button == 1 \
72 : ((GdkEventButton *) button_event)->button != 1)
74 /* Static prototypes */
75 static void toolbar_close_clicked(GtkWidget *widget, FilerWindow *filer_window);
76 static void toolbar_up_clicked(GtkWidget *widget, FilerWindow *filer_window);
77 static void toolbar_home_clicked(GtkWidget *widget, FilerWindow *filer_window);
78 static void toolbar_bookmarks_clicked(GtkWidget *widget,
79 FilerWindow *filer_window);
80 static void toolbar_help_clicked(GtkWidget *widget, FilerWindow *filer_window);
81 static void toolbar_refresh_clicked(GtkWidget *widget,
82 FilerWindow *filer_window);
83 static void toolbar_size_clicked(GtkWidget *widget, FilerWindow *filer_window);
84 static void toolbar_autosize_clicked(GtkWidget *widget, FilerWindow *filer_window);
85 static void toolbar_details_clicked(GtkWidget *widget,
86 FilerWindow *filer_window);
87 static void toolbar_hidden_clicked(GtkWidget *widget,
88 FilerWindow *filer_window);
89 static void toolbar_select_clicked(GtkWidget *widget,
90 FilerWindow *filer_window);
91 static void toolbar_sort_clicked(GtkWidget *widget,
92 FilerWindow *filer_window);
93 static GtkWidget *add_button(GtkWidget *bar, Tool *tool,
94 FilerWindow *filer_window);
95 static GtkWidget *create_toolbar(FilerWindow *filer_window);
96 static gboolean drag_motion(GtkWidget *widget,
97 GdkDragContext *context,
98 gint x,
99 gint y,
100 guint time,
101 FilerWindow *filer_window);
102 static void drag_leave(GtkWidget *widget,
103 GdkDragContext *context,
104 guint32 time,
105 FilerWindow *filer_window);
106 static void handle_drops(FilerWindow *filer_window,
107 GtkWidget *button,
108 DropDest dest);
109 static void toggle_selected(GtkToggleButton *widget, gpointer data);
110 static void option_notify(void);
111 static GList *build_tool_options(Option *option, xmlNode *node, guchar *label);
112 static void tally_items(gpointer key, gpointer value, gpointer data);
114 static Tool all_tools[] = {
115 {N_("Close"), GTK_STOCK_CLOSE, N_("Close filer window"),
116 toolbar_close_clicked, DROP_NONE, FALSE,
117 FALSE},
119 {N_("Up"), GTK_STOCK_GO_UP, N_("Change to parent directory"),
120 toolbar_up_clicked, DROP_TO_PARENT, TRUE,
121 FALSE},
123 {N_("Home"), GTK_STOCK_HOME, N_("Change to home directory"),
124 toolbar_home_clicked, DROP_TO_HOME, TRUE,
125 FALSE},
127 {N_("Bookmarks"), ROX_STOCK_BOOKMARKS, N_("Bookmarks menu"),
128 toolbar_bookmarks_clicked, DROP_BOOKMARK, FALSE,
129 TRUE},
131 {N_("Scan"), GTK_STOCK_REFRESH, N_("Rescan directory contents"),
132 toolbar_refresh_clicked, DROP_NONE, TRUE,
133 FALSE},
135 {N_("Size"), GTK_STOCK_ZOOM_IN, N_("Change icon size"),
136 toolbar_size_clicked, DROP_NONE, TRUE,
137 FALSE},
139 {N_("Size"), GTK_STOCK_ZOOM_FIT, N_("Automatic size mode"),
140 toolbar_autosize_clicked, DROP_NONE, TRUE,
141 FALSE},
143 {N_("Details"), ROX_STOCK_SHOW_DETAILS, N_("Show extra details"),
144 toolbar_details_clicked, DROP_NONE, TRUE,
145 FALSE},
147 {N_("Sort"), GTK_STOCK_SORT_ASCENDING, N_("Change sort criteria"),
148 toolbar_sort_clicked, DROP_NONE, FALSE,
149 FALSE},
151 {N_("Hidden"), ROX_STOCK_SHOW_HIDDEN, N_("Show/hide hidden files"),
152 toolbar_hidden_clicked, DROP_NONE, TRUE,
153 FALSE},
155 {N_("Select"), ROX_STOCK_SELECT, N_("Select all/invert selection"),
156 toolbar_select_clicked, DROP_NONE, FALSE,
157 FALSE},
159 {N_("Help"), GTK_STOCK_HELP, N_("Show ROX-Filer help"),
160 toolbar_help_clicked, DROP_NONE, TRUE,
161 FALSE},
165 /****************************************************************
166 * EXTERNAL INTERFACE *
167 ****************************************************************/
169 void toolbar_init(void)
171 option_add_int(&o_toolbar, "toolbar_type", TOOLBAR_NORMAL);
172 option_add_int(&o_toolbar_info, "toolbar_show_info", 1);
173 option_add_string(&o_toolbar_disable, "toolbar_disable",
174 GTK_STOCK_CLOSE);
175 option_add_int(&o_toolbar_min_width, "toolbar_min_width", 1);
176 option_add_notify(option_notify);
178 option_register_widget("tool-options", build_tool_options);
181 void toolbar_update_info(FilerWindow *filer_window)
183 gchar *label;
184 ViewIface *view;
185 int n_selected;
187 g_return_if_fail(filer_window != NULL);
189 if (o_toolbar.int_value == TOOLBAR_NONE || !o_toolbar_info.int_value)
190 return; /* Not showing info */
192 if (filer_window->target_cb)
193 return;
195 view = filer_window->view;
197 n_selected = view_count_selected(view);
199 if (n_selected == 0)
201 gchar *s = NULL;
202 int n_items;
204 if (filer_window->scanning)
206 gtk_label_set_text(
207 GTK_LABEL(filer_window->toolbar_text), "");
208 return;
211 if (!(filer_window->show_hidden ||
212 filer_window->temp_show_hidden) ||
213 filer_window->filter!=FILER_SHOW_ALL)
215 GHashTable *hash = filer_window->directory->known_items;
216 int tally = 0;
218 filer_window_being_counted=filer_window;
219 g_hash_table_foreach(hash, tally_items, &tally);
221 if (tally)
222 s = g_strdup_printf(_(" (%u hidden)"), tally);
225 n_items = view_count_items(view);
227 if (n_items)
228 label = g_strdup_printf("%d %s%s",
229 n_items,
230 n_items != 1 ? _("items") : _("item"),
231 s ? s : "");
232 else /* (French plurals work differently for zero) */
233 label = g_strdup_printf(_("No items%s"),
234 s ? s : "");
235 g_free(s);
237 else
239 double size = 0;
240 ViewIter iter;
241 DirItem *item;
243 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
245 while ((item = iter.next(&iter)))
247 if (item->base_type != TYPE_DIRECTORY &&
248 item->base_type != TYPE_UNKNOWN)
249 size += (double) item->size;
252 label = g_strdup_printf(_("%u selected (%s)"),
253 n_selected, format_double_size(size));
256 gtk_label_set_text(GTK_LABEL(filer_window->toolbar_text), label);
257 g_free(label);
260 /* Create, destroy or recreate toolbar for this window so that it
261 * matches the option setting.
263 void toolbar_update_toolbar(FilerWindow *filer_window)
265 g_return_if_fail(filer_window != NULL);
267 if (filer_window->toolbar)
269 gtk_widget_destroy(filer_window->toolbar);
270 filer_window->toolbar = NULL;
271 filer_window->toolbar_text = NULL;
274 if (o_toolbar.int_value != TOOLBAR_NONE)
276 filer_window->toolbar = create_toolbar(filer_window);
277 gtk_box_pack_start(filer_window->toplevel_vbox,
278 filer_window->toolbar, FALSE, TRUE, 0);
279 gtk_box_reorder_child(filer_window->toplevel_vbox,
280 filer_window->toolbar, 0);
281 gtk_widget_show_all(filer_window->toolbar);
284 filer_target_mode(filer_window, NULL, NULL, NULL);
285 toolbar_update_info(filer_window);
288 /****************************************************************
289 * INTERNAL FUNCTIONS *
290 ****************************************************************/
292 static void toolbar_help_clicked(GtkWidget *widget, FilerWindow *filer_window)
294 GdkEvent *event;
296 event = gtk_get_current_event();
297 if (event->type == GDK_BUTTON_RELEASE &&
298 ((GdkEventButton *) event)->button != 1)
299 menu_rox_help(NULL, HELP_MANUAL, NULL);
300 else
301 filer_opendir(make_path(app_dir, "Help"), NULL, NULL);
302 gdk_event_free(event);
305 static void toolbar_refresh_clicked(GtkWidget *widget,
306 FilerWindow *filer_window)
308 GdkEvent *event;
310 event = gtk_get_current_event();
311 if (event->type == GDK_BUTTON_RELEASE &&
312 ((GdkEventButton *) event)->button != 1)
314 filer_opendir(filer_window->sym_path, filer_window, NULL);
316 else
317 filer_refresh(filer_window);
318 gdk_event_free(event);
321 static void toolbar_home_clicked(GtkWidget *widget, FilerWindow *filer_window)
323 GdkEvent *event;
325 event = gtk_get_current_event();
326 if (event->type == GDK_BUTTON_RELEASE && NEW_WIN_BUTTON(event))
328 filer_opendir(home_dir, filer_window, NULL);
330 else
331 filer_change_to(filer_window, home_dir, NULL);
332 gdk_event_free(event);
335 static void toolbar_bookmarks_clicked(GtkWidget *widget,
336 FilerWindow *filer_window)
338 GdkEvent *event;
340 g_return_if_fail(filer_window != NULL);
342 event = gtk_get_current_event();
343 if (event->type == GDK_BUTTON_PRESS &&
344 ((GdkEventButton *) event)->button == 1)
346 bookmarks_show_menu(filer_window);
348 else if (event->type == GDK_BUTTON_RELEASE &&
349 ((GdkEventButton *) event)->button != 1)
351 bookmarks_edit();
353 gdk_event_free(event);
356 static void toolbar_close_clicked(GtkWidget *widget, FilerWindow *filer_window)
358 GdkEvent *event;
360 g_return_if_fail(filer_window != NULL);
362 event = gtk_get_current_event();
363 if (event->type == GDK_BUTTON_RELEASE &&
364 ((GdkEventButton *) event)->button != 1)
366 filer_opendir(filer_window->sym_path, filer_window, NULL);
368 else if (!filer_window_delete(filer_window->window, NULL, filer_window))
369 gtk_widget_destroy(filer_window->window);
370 gdk_event_free(event);
373 static void toolbar_up_clicked(GtkWidget *widget, FilerWindow *filer_window)
375 GdkEvent *event;
377 event = gtk_get_current_event();
378 if (event->type == GDK_BUTTON_RELEASE && NEW_WIN_BUTTON(event))
380 filer_open_parent(filer_window);
382 else
383 change_to_parent(filer_window);
384 gdk_event_free(event);
387 static void toolbar_autosize_clicked(GtkWidget *widget, FilerWindow *filer_window)
389 GdkEventButton *bev;
391 bev = (GdkEventButton *) gtk_get_current_event();
392 if (bev->type == GDK_BUTTON_RELEASE)
394 display_set_layout(filer_window, AUTO_SIZE_ICONS, filer_window->details_type,
395 TRUE);
397 gdk_event_free((GdkEvent *) bev);
400 static void toolbar_size_clicked(GtkWidget *widget, FilerWindow *filer_window)
402 GdkEventButton *bev;
404 bev = (GdkEventButton *) gtk_get_current_event();
405 if (bev->type == GDK_BUTTON_RELEASE)
406 display_change_size(filer_window, bev->button == 1);
407 gdk_event_free((GdkEvent *) bev);
410 static void toolbar_sort_clicked(GtkWidget *widget,
411 FilerWindow *filer_window)
413 GdkEventButton *bev;
414 int i, current, next, next_wrapped;
415 gboolean adjust;
416 GtkSortType dir;
417 gchar *tip;
419 static const SortType sorts[]={
420 SORT_NAME, SORT_TYPE, SORT_DATE, SORT_SIZE,
421 SORT_OWNER, SORT_GROUP,
423 static const char *sort_names[] = {
424 N_("Sort by name"), N_("Sort by type"), N_("Sort by date"),
425 N_("Sort by size"), N_("Sort by owner"), N_("Sort by group"),
428 bev = (GdkEventButton *) gtk_get_current_event();
429 adjust = (bev->button != 1) && bev->type == GDK_BUTTON_RELEASE;
430 gdk_event_free((GdkEvent *) bev);
432 current = -1;
433 dir = filer_window->sort_order;
434 for (i=0; i < G_N_ELEMENTS(sort_names); i++)
436 if (filer_window->sort_type == sorts[i])
438 current = i;
439 break;
443 if (current == -1)
444 next = 0;
445 else if (adjust)
446 next = current - 1;
447 else
448 next = current + 1;
450 next_wrapped = next % G_N_ELEMENTS(sorts);
452 if (next_wrapped != next)
453 dir = (dir == GTK_SORT_ASCENDING)
454 ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING;
456 display_set_sort_type(filer_window, sorts[next_wrapped], dir);
457 tip = g_strconcat(_(sort_names[next_wrapped]), ", ",
458 dir == GTK_SORT_ASCENDING
459 ? _("ascending") : _("descending"),
460 NULL);
461 tooltip_show(tip);
462 g_free(tip);
465 static void toolbar_details_clicked(GtkWidget *widget,
466 FilerWindow *filer_window)
468 if (filer_window->view_type == VIEW_TYPE_DETAILS)
469 filer_set_view_type(filer_window, VIEW_TYPE_COLLECTION);
470 else
471 filer_set_view_type(filer_window, VIEW_TYPE_DETAILS);
474 static void toolbar_hidden_clicked(GtkWidget *widget,
475 FilerWindow *filer_window)
477 display_set_hidden(filer_window, !filer_window->show_hidden);
480 static gboolean invert_cb(ViewIter *iter, gpointer data)
482 return !view_get_selected((ViewIface *) data, iter);
485 static void toolbar_select_clicked(GtkWidget *widget, FilerWindow *filer_window)
487 GdkEvent *event;
489 event = gtk_get_current_event();
490 if (event->type == GDK_BUTTON_RELEASE)
492 if (((GdkEventButton *) event)->button == 1)
493 view_select_all(filer_window->view);
494 else
495 view_select_if(filer_window->view, invert_cb,
496 filer_window->view);
498 filer_window->temp_item_selected = FALSE;
499 gdk_event_free(event);
502 /* If filer_window is NULL, the toolbar is for the options window */
503 static GtkWidget *create_toolbar(FilerWindow *filer_window)
505 GtkWidget *bar;
506 GtkWidget *b;
507 int i;
508 int width;
510 bar = gtk_toolbar_new();
512 if (o_toolbar.int_value == TOOLBAR_NORMAL || !filer_window)
513 gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_ICONS);
514 else if (o_toolbar.int_value == TOOLBAR_HORIZONTAL)
515 gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_BOTH_HORIZ);
516 else
517 gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_BOTH);
519 width=0;
520 for (i = 0; i < sizeof(all_tools) / sizeof(*all_tools); i++)
522 Tool *tool = &all_tools[i];
523 GtkRequisition req;
525 if (filer_window && !tool->enabled)
526 continue;
528 b = add_button(bar, tool, filer_window);
530 gtk_widget_size_request(b, &req);
531 width+=req.width;
533 if (filer_window && tool->drop_action != DROP_NONE)
534 handle_drops(filer_window, b, tool->drop_action);
537 if (filer_window)
539 if(o_toolbar_min_width.int_value)
541 /* Make the toolbar wide enough for all icons to be
542 seen, plus a little for the (start of the) text
543 label */
544 gtk_widget_set_size_request(bar, width+32, -1);
545 } else {
546 gtk_widget_set_size_request(bar, 100, -1);
549 filer_window->toolbar_text = gtk_label_new("");
550 gtk_misc_set_alignment(GTK_MISC(filer_window->toolbar_text),
551 0, 0.5);
552 gtk_toolbar_append_widget(GTK_TOOLBAR(bar),
553 filer_window->toolbar_text, NULL, NULL);
556 return bar;
559 /* This is used to simulate a click when button 3 is used (GtkButton
560 * normally ignores this).
562 static gint toolbar_other_button = 0;
563 static gint toolbar_button_pressed(GtkButton *button,
564 GdkEventButton *event,
565 FilerWindow *filer_window)
567 gint b = event->button;
568 Tool *tool;
570 tool = g_object_get_data(G_OBJECT(button), "rox-tool");
571 g_return_val_if_fail(tool != NULL, TRUE);
573 if (tool->menu && b == 1)
575 tool->clicked((GtkWidget *) button, filer_window);
576 return TRUE;
579 if ((b == 2 || b == 3) && toolbar_other_button == 0)
581 toolbar_other_button = event->button;
582 gtk_grab_add(GTK_WIDGET(button));
583 gtk_button_pressed(button);
585 return TRUE;
588 return FALSE;
591 static gint toolbar_button_released(GtkButton *button,
592 GdkEventButton *event,
593 FilerWindow *filer_window)
595 if (event->button == toolbar_other_button)
597 toolbar_other_button = 0;
598 gtk_grab_remove(GTK_WIDGET(button));
599 gtk_button_released(button);
601 return TRUE;
604 return FALSE;
607 /* If filer_window is NULL, the toolbar is for the options window */
608 static GtkWidget *add_button(GtkWidget *bar, Tool *tool,
609 FilerWindow *filer_window)
611 GtkWidget *button, *icon_widget;
613 icon_widget = gtk_image_new_from_stock(tool->name,
614 GTK_ICON_SIZE_LARGE_TOOLBAR);
616 button = gtk_toolbar_insert_element(GTK_TOOLBAR(bar),
617 filer_window ? GTK_TOOLBAR_CHILD_BUTTON
618 : GTK_TOOLBAR_CHILD_TOGGLEBUTTON,
619 NULL,
620 _(tool->label),
621 _(tool->tip), NULL,
622 icon_widget,
623 NULL, NULL, /* CB, userdata */
624 GTK_TOOLBAR(bar)->num_children);
625 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
627 if (o_toolbar.int_value == TOOLBAR_HORIZONTAL)
629 GtkWidget *hbox, *label;
630 GList *kids;
631 hbox = GTK_BIN(button)->child;
632 kids = gtk_container_get_children(GTK_CONTAINER(hbox));
633 label = g_list_nth_data(kids, 1);
634 g_list_free(kids);
636 if (label)
638 gtk_box_set_child_packing(GTK_BOX(hbox), label,
639 TRUE, TRUE, 0, GTK_PACK_END);
640 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
644 g_object_set_data(G_OBJECT(button), "rox-tool", tool);
646 if (filer_window)
648 g_signal_connect(button, "clicked",
649 G_CALLBACK(tool->clicked), filer_window);
650 g_signal_connect(button, "button_press_event",
651 G_CALLBACK(toolbar_button_pressed), filer_window);
652 g_signal_connect(button, "button_release_event",
653 G_CALLBACK(toolbar_button_released), filer_window);
655 else
657 g_signal_connect(button, "clicked",
658 G_CALLBACK(toggle_selected), NULL);
659 g_object_set_data(G_OBJECT(button), "tool_name",
660 (gpointer) tool->name);
663 return button;
666 static void toggle_selected(GtkToggleButton *widget, gpointer data)
668 option_check_widget(&o_toolbar_disable);
671 /* Called during the drag when the mouse is in a widget registered
672 * as a drop target. Returns TRUE if we can accept the drop.
674 static gboolean drag_motion(GtkWidget *widget,
675 GdkDragContext *context,
676 gint x,
677 gint y,
678 guint time,
679 FilerWindow *filer_window)
681 GdkDragAction action = context->suggested_action;
682 DropDest dest;
683 gpointer type = (gpointer) drop_dest_dir;
685 dest = (DropDest) g_object_get_data(G_OBJECT(widget), "toolbar_dest");
687 if ((context->actions & GDK_ACTION_ASK) && o_dnd_left_menu.int_value &&
688 dest != DROP_BOOKMARK)
690 guint state;
691 gdk_window_get_pointer(NULL, NULL, NULL, &state);
692 if (state & GDK_BUTTON1_MASK)
693 action = GDK_ACTION_ASK;
696 if (dest == DROP_TO_HOME)
697 g_dataset_set_data(context, "drop_dest_path",
698 (gchar *) home_dir);
699 else if (dest == DROP_BOOKMARK)
700 type = (gpointer) drop_dest_bookmark;
701 else
702 g_dataset_set_data_full(context, "drop_dest_path",
703 g_path_get_dirname(filer_window->sym_path),
704 g_free);
706 g_dataset_set_data(context, "drop_dest_type", type);
707 gdk_drag_status(context, action, time);
709 dnd_spring_load(context, filer_window);
710 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
712 return TRUE;
715 static void drag_leave(GtkWidget *widget,
716 GdkDragContext *context,
717 guint32 time,
718 FilerWindow *filer_window)
720 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NONE);
721 dnd_spring_abort();
724 static void handle_drops(FilerWindow *filer_window,
725 GtkWidget *button,
726 DropDest dest)
728 make_drop_target(button, 0);
729 g_signal_connect(button, "drag_motion",
730 G_CALLBACK(drag_motion), filer_window);
731 g_signal_connect(button, "drag_leave",
732 G_CALLBACK(drag_leave), filer_window);
733 g_object_set_data(G_OBJECT(button), "toolbar_dest", (gpointer) dest);
736 static void tally_items(gpointer key, gpointer value, gpointer data)
738 guchar *leafname = (guchar *) key;
739 int *tally = (int *) data;
741 if (!filer_match_filter(filer_window_being_counted, leafname))
742 (*tally)++;
745 static void option_notify(void)
747 int i;
748 gboolean changed = FALSE;
749 guchar *list = o_toolbar_disable.value;
751 for (i = 0; i < sizeof(all_tools) / sizeof(*all_tools); i++)
753 Tool *tool = &all_tools[i];
754 gboolean old = tool->enabled;
756 tool->enabled = !in_list(tool->name, list);
758 if (old != tool->enabled)
759 changed = TRUE;
762 if (changed || o_toolbar.has_changed || o_toolbar_info.has_changed)
764 GList *next;
766 for (next = all_filer_windows; next; next = next->next)
768 FilerWindow *filer_window = (FilerWindow *) next->data;
770 toolbar_update_toolbar(filer_window);
775 static void update_tools(Option *option)
777 GList *next, *kids;
779 kids = gtk_container_get_children(GTK_CONTAINER(option->widget));
781 for (next = kids; next; next = next->next)
783 GtkToggleButton *kid = (GtkToggleButton *) next->data;
784 guchar *name;
786 name = g_object_get_data(G_OBJECT(kid), "tool_name");
788 g_return_if_fail(name != NULL);
790 gtk_toggle_button_set_active(kid,
791 !in_list(name, option->value));
794 g_list_free(kids);
797 static guchar *read_tools(Option *option)
799 GList *next, *kids;
800 GString *list;
801 guchar *retval;
803 list = g_string_new(NULL);
805 kids = gtk_container_get_children(GTK_CONTAINER(option->widget));
807 for (next = kids; next; next = next->next)
809 GtkToggleButton *kid = (GtkToggleButton *) next->data;
810 guchar *name;
812 if (!gtk_toggle_button_get_active(kid))
814 name = g_object_get_data(G_OBJECT(kid), "tool_name");
815 g_return_val_if_fail(name != NULL, list->str);
817 if (list->len)
818 g_string_append(list, ", ");
819 g_string_append(list, name);
823 g_list_free(kids);
824 retval = list->str;
825 g_string_free(list, FALSE);
827 return retval;
830 static GList *build_tool_options(Option *option, xmlNode *node, guchar *label)
832 GtkWidget *bar;
834 g_return_val_if_fail(option != NULL, NULL);
836 bar = create_toolbar(NULL);
838 option->update_widget = update_tools;
839 option->read_widget = read_tools;
840 option->widget = bar;
842 return g_list_append(NULL, bar);