r3861: Simplify code to set minibuffer text to red on error (Dennis). Also set
[rox-filer/translations.git] / ROX-Filer / src / toolbar.c
blob0f0c4d54026811750b19a53559e524edeaba2cef
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 if (o_toolbar.int_value == TOOLBAR_NONE || !o_toolbar_info.int_value)
188 return; /* Not showing info */
190 if (filer_window->target_cb)
191 return;
193 view = filer_window->view;
195 n_selected = view_count_selected(view);
197 if (n_selected == 0)
199 gchar *s = NULL;
200 int n_items;
202 if (filer_window->scanning)
204 gtk_label_set_text(
205 GTK_LABEL(filer_window->toolbar_text), "");
206 return;
209 if (!(filer_window->show_hidden ||
210 filer_window->temp_show_hidden) ||
211 filer_window->filter!=FILER_SHOW_ALL)
213 GHashTable *hash = filer_window->directory->known_items;
214 int tally = 0;
216 filer_window_being_counted=filer_window;
217 g_hash_table_foreach(hash, tally_items, &tally);
219 if (tally)
220 s = g_strdup_printf(_(" (%u hidden)"), tally);
223 n_items = view_count_items(view);
225 if (n_items)
226 label = g_strdup_printf("%d %s%s",
227 n_items,
228 n_items != 1 ? _("items") : _("item"),
229 s ? s : "");
230 else /* (French plurals work differently for zero) */
231 label = g_strdup_printf(_("No items%s"),
232 s ? s : "");
233 g_free(s);
235 else
237 double size = 0;
238 ViewIter iter;
239 DirItem *item;
241 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
243 while ((item = iter.next(&iter)))
245 if (item->base_type != TYPE_DIRECTORY &&
246 item->base_type != TYPE_UNKNOWN)
247 size += (double) item->size;
250 label = g_strdup_printf(_("%u selected (%s)"),
251 n_selected, format_double_size(size));
254 gtk_label_set_text(GTK_LABEL(filer_window->toolbar_text), label);
255 g_free(label);
258 /* Create, destroy or recreate toolbar for this window so that it
259 * matches the option setting.
261 void toolbar_update_toolbar(FilerWindow *filer_window)
263 g_return_if_fail(filer_window != NULL);
265 if (filer_window->toolbar)
267 gtk_widget_destroy(filer_window->toolbar);
268 filer_window->toolbar = NULL;
269 filer_window->toolbar_text = NULL;
272 if (o_toolbar.int_value != TOOLBAR_NONE)
274 filer_window->toolbar = create_toolbar(filer_window);
275 gtk_box_pack_start(filer_window->toplevel_vbox,
276 filer_window->toolbar, FALSE, TRUE, 0);
277 gtk_box_reorder_child(filer_window->toplevel_vbox,
278 filer_window->toolbar, 0);
279 gtk_widget_show_all(filer_window->toolbar);
282 filer_target_mode(filer_window, NULL, NULL, NULL);
283 toolbar_update_info(filer_window);
286 /****************************************************************
287 * INTERNAL FUNCTIONS *
288 ****************************************************************/
290 static void toolbar_help_clicked(GtkWidget *widget, FilerWindow *filer_window)
292 GdkEvent *event;
294 event = gtk_get_current_event();
295 if (event->type == GDK_BUTTON_RELEASE &&
296 ((GdkEventButton *) event)->button != 1)
297 menu_rox_help(NULL, HELP_MANUAL, NULL);
298 else
299 filer_opendir(make_path(app_dir, "Help"), NULL, NULL);
302 static void toolbar_refresh_clicked(GtkWidget *widget,
303 FilerWindow *filer_window)
305 GdkEvent *event;
307 event = gtk_get_current_event();
308 if (event->type == GDK_BUTTON_RELEASE &&
309 ((GdkEventButton *) event)->button != 1)
311 filer_opendir(filer_window->sym_path, filer_window, NULL);
313 else
314 filer_refresh(filer_window);
317 static void toolbar_home_clicked(GtkWidget *widget, FilerWindow *filer_window)
319 GdkEvent *event;
321 event = gtk_get_current_event();
322 if (event->type == GDK_BUTTON_RELEASE && NEW_WIN_BUTTON(event))
324 filer_opendir(home_dir, filer_window, NULL);
326 else
327 filer_change_to(filer_window, home_dir, NULL);
330 static void toolbar_bookmarks_clicked(GtkWidget *widget,
331 FilerWindow *filer_window)
333 GdkEvent *event;
335 g_return_if_fail(filer_window != NULL);
337 event = gtk_get_current_event();
338 if (event->type == GDK_BUTTON_PRESS &&
339 ((GdkEventButton *) event)->button == 1)
341 bookmarks_show_menu(filer_window);
343 else if (event->type == GDK_BUTTON_RELEASE &&
344 ((GdkEventButton *) event)->button != 1)
346 bookmarks_edit();
350 static void toolbar_close_clicked(GtkWidget *widget, FilerWindow *filer_window)
352 GdkEvent *event;
354 g_return_if_fail(filer_window != NULL);
356 event = gtk_get_current_event();
357 if (event->type == GDK_BUTTON_RELEASE &&
358 ((GdkEventButton *) event)->button != 1)
360 filer_opendir(filer_window->sym_path, filer_window, NULL);
362 else if (!filer_window_delete(filer_window->window, NULL, filer_window))
363 gtk_widget_destroy(filer_window->window);
366 static void toolbar_up_clicked(GtkWidget *widget, FilerWindow *filer_window)
368 GdkEvent *event;
370 event = gtk_get_current_event();
371 if (event->type == GDK_BUTTON_RELEASE && NEW_WIN_BUTTON(event))
373 filer_open_parent(filer_window);
375 else
376 change_to_parent(filer_window);
379 static void toolbar_autosize_clicked(GtkWidget *widget, FilerWindow *filer_window)
381 GdkEventButton *bev;
383 bev = (GdkEventButton *) gtk_get_current_event();
384 if (bev->type != GDK_BUTTON_RELEASE)
385 return;
387 display_set_layout(filer_window, AUTO_SIZE_ICONS, filer_window->details_type,
388 TRUE);
391 static void toolbar_size_clicked(GtkWidget *widget, FilerWindow *filer_window)
393 GdkEventButton *bev;
395 bev = (GdkEventButton *) gtk_get_current_event();
396 if (bev->type != GDK_BUTTON_RELEASE)
397 return;
399 display_change_size(filer_window, bev->button == 1);
402 static void toolbar_sort_clicked(GtkWidget *widget,
403 FilerWindow *filer_window)
405 GdkEventButton *bev;
406 int i, current, next, next_wrapped;
407 gboolean adjust;
408 GtkSortType dir;
409 gchar *tip;
411 static const SortType sorts[]={
412 SORT_NAME, SORT_TYPE, SORT_DATE, SORT_SIZE,
413 SORT_OWNER, SORT_GROUP,
415 static const char *sort_names[] = {
416 N_("Sort by name"), N_("Sort by type"), N_("Sort by date"),
417 N_("Sort by size"), N_("Sort by owner"), N_("Sort by group"),
420 bev = (GdkEventButton *) gtk_get_current_event();
421 adjust = (bev->button != 1) && bev->type == GDK_BUTTON_RELEASE;
423 current = -1;
424 dir = filer_window->sort_order;
425 for (i=0; i < G_N_ELEMENTS(sort_names); i++)
427 if (filer_window->sort_type == sorts[i])
429 current = i;
430 break;
434 if (current == -1)
435 next = 0;
436 else if (adjust)
437 next = current - 1;
438 else
439 next = current + 1;
441 next_wrapped = next % G_N_ELEMENTS(sorts);
443 if (next_wrapped != next)
444 dir = (dir == GTK_SORT_ASCENDING)
445 ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING;
447 display_set_sort_type(filer_window, sorts[next_wrapped], dir);
448 tip = g_strconcat(_(sort_names[next_wrapped]), ", ",
449 dir == GTK_SORT_ASCENDING
450 ? _("ascending") : _("descending"),
451 NULL);
452 tooltip_show(tip);
453 g_free(tip);
456 static void toolbar_details_clicked(GtkWidget *widget,
457 FilerWindow *filer_window)
459 if (filer_window->view_type == VIEW_TYPE_DETAILS)
460 filer_set_view_type(filer_window, VIEW_TYPE_COLLECTION);
461 else
462 filer_set_view_type(filer_window, VIEW_TYPE_DETAILS);
465 static void toolbar_hidden_clicked(GtkWidget *widget,
466 FilerWindow *filer_window)
468 display_set_hidden(filer_window, !filer_window->show_hidden);
471 static gboolean invert_cb(ViewIter *iter, gpointer data)
473 return !view_get_selected((ViewIface *) data, iter);
476 static void toolbar_select_clicked(GtkWidget *widget, FilerWindow *filer_window)
478 GdkEvent *event;
480 event = gtk_get_current_event();
481 if (event->type == GDK_BUTTON_RELEASE)
483 if (((GdkEventButton *) event)->button == 1)
484 view_select_all(filer_window->view);
485 else
486 view_select_if(filer_window->view, invert_cb,
487 filer_window->view);
489 filer_window->temp_item_selected = FALSE;
492 /* If filer_window is NULL, the toolbar is for the options window */
493 static GtkWidget *create_toolbar(FilerWindow *filer_window)
495 GtkWidget *bar;
496 GtkWidget *b;
497 int i;
498 int width;
500 bar = gtk_toolbar_new();
502 if (o_toolbar.int_value == TOOLBAR_NORMAL || !filer_window)
503 gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_ICONS);
504 else if (o_toolbar.int_value == TOOLBAR_HORIZONTAL)
505 gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_BOTH_HORIZ);
506 else
507 gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_BOTH);
509 width=0;
510 for (i = 0; i < sizeof(all_tools) / sizeof(*all_tools); i++)
512 Tool *tool = &all_tools[i];
513 GtkRequisition req;
515 if (filer_window && !tool->enabled)
516 continue;
518 b = add_button(bar, tool, filer_window);
520 gtk_widget_size_request(b, &req);
521 width+=req.width;
523 if (filer_window && tool->drop_action != DROP_NONE)
524 handle_drops(filer_window, b, tool->drop_action);
527 if (filer_window)
529 if(o_toolbar_min_width.int_value)
531 /* Make the toolbar wide enough for all icons to be
532 seen, plus a little for the (start of the) text
533 label */
534 gtk_widget_set_size_request(bar, width+32, -1);
535 } else {
536 gtk_widget_set_size_request(bar, 100, -1);
539 filer_window->toolbar_text = gtk_label_new("");
540 gtk_misc_set_alignment(GTK_MISC(filer_window->toolbar_text),
541 0, 0.5);
542 gtk_toolbar_append_widget(GTK_TOOLBAR(bar),
543 filer_window->toolbar_text, NULL, NULL);
546 return bar;
549 /* This is used to simulate a click when button 3 is used (GtkButton
550 * normally ignores this).
552 static gint toolbar_other_button = 0;
553 static gint toolbar_button_pressed(GtkButton *button,
554 GdkEventButton *event,
555 FilerWindow *filer_window)
557 gint b = event->button;
558 Tool *tool;
560 tool = g_object_get_data(G_OBJECT(button), "rox-tool");
561 g_return_val_if_fail(tool != NULL, TRUE);
563 if (tool->menu && b == 1)
565 tool->clicked((GtkWidget *) button, filer_window);
566 return TRUE;
569 if ((b == 2 || b == 3) && toolbar_other_button == 0)
571 toolbar_other_button = event->button;
572 gtk_grab_add(GTK_WIDGET(button));
573 gtk_button_pressed(button);
575 return TRUE;
578 return FALSE;
581 static gint toolbar_button_released(GtkButton *button,
582 GdkEventButton *event,
583 FilerWindow *filer_window)
585 if (event->button == toolbar_other_button)
587 toolbar_other_button = 0;
588 gtk_grab_remove(GTK_WIDGET(button));
589 gtk_button_released(button);
591 return TRUE;
594 return FALSE;
597 /* If filer_window is NULL, the toolbar is for the options window */
598 static GtkWidget *add_button(GtkWidget *bar, Tool *tool,
599 FilerWindow *filer_window)
601 GtkWidget *button, *icon_widget;
603 icon_widget = gtk_image_new_from_stock(tool->name,
604 GTK_ICON_SIZE_LARGE_TOOLBAR);
606 button = gtk_toolbar_insert_element(GTK_TOOLBAR(bar),
607 filer_window ? GTK_TOOLBAR_CHILD_BUTTON
608 : GTK_TOOLBAR_CHILD_TOGGLEBUTTON,
609 NULL,
610 _(tool->label),
611 _(tool->tip), NULL,
612 icon_widget,
613 NULL, NULL, /* CB, userdata */
614 GTK_TOOLBAR(bar)->num_children);
615 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
617 if (o_toolbar.int_value == TOOLBAR_HORIZONTAL)
619 GtkWidget *hbox, *label;
620 GList *kids;
621 hbox = GTK_BIN(button)->child;
622 kids = gtk_container_get_children(GTK_CONTAINER(hbox));
623 label = g_list_nth_data(kids, 1);
624 g_list_free(kids);
626 if (label)
628 gtk_box_set_child_packing(GTK_BOX(hbox), label,
629 TRUE, TRUE, 0, GTK_PACK_END);
630 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
634 g_object_set_data(G_OBJECT(button), "rox-tool", tool);
636 if (filer_window)
638 g_signal_connect(button, "clicked",
639 G_CALLBACK(tool->clicked), filer_window);
640 g_signal_connect(button, "button_press_event",
641 G_CALLBACK(toolbar_button_pressed), filer_window);
642 g_signal_connect(button, "button_release_event",
643 G_CALLBACK(toolbar_button_released), filer_window);
645 else
647 g_signal_connect(button, "clicked",
648 G_CALLBACK(toggle_selected), NULL);
649 g_object_set_data(G_OBJECT(button), "tool_name",
650 (gpointer) tool->name);
653 return button;
656 static void toggle_selected(GtkToggleButton *widget, gpointer data)
658 option_check_widget(&o_toolbar_disable);
661 /* Called during the drag when the mouse is in a widget registered
662 * as a drop target. Returns TRUE if we can accept the drop.
664 static gboolean drag_motion(GtkWidget *widget,
665 GdkDragContext *context,
666 gint x,
667 gint y,
668 guint time,
669 FilerWindow *filer_window)
671 GdkDragAction action = context->suggested_action;
672 DropDest dest;
673 gpointer type = (gpointer) drop_dest_dir;
675 dest = (DropDest) g_object_get_data(G_OBJECT(widget), "toolbar_dest");
677 if ((context->actions & GDK_ACTION_ASK) && o_dnd_left_menu.int_value &&
678 dest != DROP_BOOKMARK)
680 guint state;
681 gdk_window_get_pointer(NULL, NULL, NULL, &state);
682 if (state & GDK_BUTTON1_MASK)
683 action = GDK_ACTION_ASK;
686 if (dest == DROP_TO_HOME)
687 g_dataset_set_data(context, "drop_dest_path",
688 (gchar *) home_dir);
689 else if (dest == DROP_BOOKMARK)
690 type = (gpointer) drop_dest_bookmark;
691 else
692 g_dataset_set_data_full(context, "drop_dest_path",
693 g_path_get_dirname(filer_window->sym_path),
694 g_free);
696 g_dataset_set_data(context, "drop_dest_type", type);
697 gdk_drag_status(context, action, time);
699 dnd_spring_load(context, filer_window);
700 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
702 return TRUE;
705 static void drag_leave(GtkWidget *widget,
706 GdkDragContext *context,
707 guint32 time,
708 FilerWindow *filer_window)
710 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NONE);
711 dnd_spring_abort();
714 static void handle_drops(FilerWindow *filer_window,
715 GtkWidget *button,
716 DropDest dest)
718 make_drop_target(button, 0);
719 g_signal_connect(button, "drag_motion",
720 G_CALLBACK(drag_motion), filer_window);
721 g_signal_connect(button, "drag_leave",
722 G_CALLBACK(drag_leave), filer_window);
723 g_object_set_data(G_OBJECT(button), "toolbar_dest", (gpointer) dest);
726 static void tally_items(gpointer key, gpointer value, gpointer data)
728 guchar *leafname = (guchar *) key;
729 int *tally = (int *) data;
731 if (!filer_match_filter(filer_window_being_counted, leafname))
732 (*tally)++;
735 static void option_notify(void)
737 int i;
738 gboolean changed = FALSE;
739 guchar *list = o_toolbar_disable.value;
741 for (i = 0; i < sizeof(all_tools) / sizeof(*all_tools); i++)
743 Tool *tool = &all_tools[i];
744 gboolean old = tool->enabled;
746 tool->enabled = !in_list(tool->name, list);
748 if (old != tool->enabled)
749 changed = TRUE;
752 if (changed || o_toolbar.has_changed || o_toolbar_info.has_changed)
754 GList *next;
756 for (next = all_filer_windows; next; next = next->next)
758 FilerWindow *filer_window = (FilerWindow *) next->data;
760 toolbar_update_toolbar(filer_window);
765 static void update_tools(Option *option)
767 GList *next, *kids;
769 kids = gtk_container_get_children(GTK_CONTAINER(option->widget));
771 for (next = kids; next; next = next->next)
773 GtkToggleButton *kid = (GtkToggleButton *) next->data;
774 guchar *name;
776 name = g_object_get_data(G_OBJECT(kid), "tool_name");
778 g_return_if_fail(name != NULL);
780 gtk_toggle_button_set_active(kid,
781 !in_list(name, option->value));
784 g_list_free(kids);
787 static guchar *read_tools(Option *option)
789 GList *next, *kids;
790 GString *list;
791 guchar *retval;
793 list = g_string_new(NULL);
795 kids = gtk_container_get_children(GTK_CONTAINER(option->widget));
797 for (next = kids; next; next = next->next)
799 GtkToggleButton *kid = (GtkToggleButton *) next->data;
800 guchar *name;
802 if (!gtk_toggle_button_get_active(kid))
804 name = g_object_get_data(G_OBJECT(kid), "tool_name");
805 g_return_val_if_fail(name != NULL, list->str);
807 if (list->len)
808 g_string_append(list, ", ");
809 g_string_append(list, name);
813 g_list_free(kids);
814 retval = list->str;
815 g_string_free(list, FALSE);
817 return retval;
820 static GList *build_tool_options(Option *option, xmlNode *node, guchar *label)
822 GtkWidget *bar;
824 g_return_val_if_fail(option != NULL, NULL);
826 bar = create_toolbar(NULL);
828 option->update_widget = update_tools;
829 option->read_widget = read_tools;
830 option->widget = bar;
832 return g_list_append(NULL, bar);