r3119: Updated manual.
[rox-filer.git] / ROX-Filer / src / toolbar.c
blobbce600e6625632e2420f56af313155f07d6ff747
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2003, 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;
63 static GtkTooltips *tooltips = NULL;
65 /* TRUE if the button presses (or released) should open a new window,
66 * rather than reusing the existing one.
68 #define NEW_WIN_BUTTON(button_event) \
69 (o_new_button_1.int_value \
70 ? ((GdkEventButton *) button_event)->button == 1 \
71 : ((GdkEventButton *) button_event)->button != 1)
73 /* Static prototypes */
74 static void toolbar_close_clicked(GtkWidget *widget, FilerWindow *filer_window);
75 static void toolbar_up_clicked(GtkWidget *widget, FilerWindow *filer_window);
76 static void toolbar_home_clicked(GtkWidget *widget, FilerWindow *filer_window);
77 static void toolbar_bookmarks_clicked(GtkWidget *widget,
78 FilerWindow *filer_window);
79 static void toolbar_help_clicked(GtkWidget *widget, FilerWindow *filer_window);
80 static void toolbar_refresh_clicked(GtkWidget *widget,
81 FilerWindow *filer_window);
82 static void toolbar_size_clicked(GtkWidget *widget, FilerWindow *filer_window);
83 static void toolbar_autosize_clicked(GtkWidget *widget, FilerWindow *filer_window);
84 static void toolbar_details_clicked(GtkWidget *widget,
85 FilerWindow *filer_window);
86 static void toolbar_hidden_clicked(GtkWidget *widget,
87 FilerWindow *filer_window);
88 static void toolbar_select_clicked(GtkWidget *widget,
89 FilerWindow *filer_window);
90 static void toolbar_sort_clicked(GtkWidget *widget,
91 FilerWindow *filer_window);
92 static GtkWidget *add_button(GtkWidget *bar, Tool *tool,
93 FilerWindow *filer_window);
94 static GtkWidget *create_toolbar(FilerWindow *filer_window);
95 static gboolean drag_motion(GtkWidget *widget,
96 GdkDragContext *context,
97 gint x,
98 gint y,
99 guint time,
100 FilerWindow *filer_window);
101 static void drag_leave(GtkWidget *widget,
102 GdkDragContext *context,
103 guint32 time,
104 FilerWindow *filer_window);
105 static void handle_drops(FilerWindow *filer_window,
106 GtkWidget *button,
107 DropDest dest);
108 static void toggle_selected(GtkToggleButton *widget, gpointer data);
109 static void option_notify(void);
110 static GList *build_tool_options(Option *option, xmlNode *node, guchar *label);
111 static void tally_items(gpointer key, gpointer value, gpointer data);
113 static Tool all_tools[] = {
114 {N_("Close"), GTK_STOCK_CLOSE, N_("Close filer window"),
115 toolbar_close_clicked, DROP_NONE, FALSE,
116 FALSE},
118 {N_("Up"), GTK_STOCK_GO_UP, N_("Change to parent directory"),
119 toolbar_up_clicked, DROP_TO_PARENT, TRUE,
120 FALSE},
122 {N_("Home"), GTK_STOCK_HOME, N_("Change to home directory"),
123 toolbar_home_clicked, DROP_TO_HOME, TRUE,
124 FALSE},
126 {N_("Bookmarks"), ROX_STOCK_BOOKMARKS, N_("Bookmarks menu"),
127 toolbar_bookmarks_clicked, DROP_BOOKMARK, FALSE,
128 TRUE},
130 {N_("Scan"), GTK_STOCK_REFRESH, N_("Rescan directory contents"),
131 toolbar_refresh_clicked, DROP_NONE, TRUE,
132 FALSE},
134 {N_("Size"), GTK_STOCK_ZOOM_IN, N_("Change icon size"),
135 toolbar_size_clicked, DROP_NONE, TRUE,
136 FALSE},
138 {N_("Size"), GTK_STOCK_ZOOM_FIT, N_("Automatic size mode"),
139 toolbar_autosize_clicked, DROP_NONE, TRUE,
140 FALSE},
142 {N_("Details"), ROX_STOCK_SHOW_DETAILS, N_("Show extra details"),
143 toolbar_details_clicked, DROP_NONE, TRUE,
144 FALSE},
146 {N_("Sort"), GTK_STOCK_SORT_ASCENDING, N_("Change sort criteria"),
147 toolbar_sort_clicked, DROP_NONE, FALSE,
148 FALSE},
150 {N_("Hidden"), ROX_STOCK_SHOW_HIDDEN, N_("Show/hide hidden files"),
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_notify(option_notify);
176 tooltips = gtk_tooltips_new();
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)
211 GHashTable *hash = filer_window->directory->known_items;
212 int tally = 0;
214 g_hash_table_foreach(hash, tally_items, &tally);
216 if (tally)
217 s = g_strdup_printf(_(" (%u hidden)"), tally);
220 n_items = view_count_items(view);
222 if (n_items)
223 label = g_strdup_printf("%d %s%s",
224 n_items,
225 n_items != 1 ? _("items") : _("item"),
226 s ? s : "");
227 else /* (French plurals work differently for zero) */
228 label = g_strdup_printf(_("No items%s"),
229 s ? s : "");
230 g_free(s);
232 else
234 double size = 0;
235 ViewIter iter;
236 DirItem *item;
238 view_get_iter(filer_window->view, &iter, VIEW_ITER_SELECTED);
240 while ((item = iter.next(&iter)))
241 if (item->base_type != TYPE_DIRECTORY)
242 size += (double) item->size;
244 label = g_strdup_printf(_("%u selected (%s)"),
245 n_selected, format_double_size(size));
248 gtk_label_set_text(GTK_LABEL(filer_window->toolbar_text), label);
249 g_free(label);
252 /* Create, destroy or recreate toolbar for this window so that it
253 * matches the option setting.
255 void toolbar_update_toolbar(FilerWindow *filer_window)
257 g_return_if_fail(filer_window != NULL);
259 if (filer_window->toolbar)
261 gtk_widget_destroy(filer_window->toolbar);
262 filer_window->toolbar = NULL;
263 filer_window->toolbar_text = NULL;
266 if (o_toolbar.int_value != TOOLBAR_NONE)
268 filer_window->toolbar = create_toolbar(filer_window);
269 gtk_box_pack_start(filer_window->toplevel_vbox,
270 filer_window->toolbar, FALSE, TRUE, 0);
271 gtk_box_reorder_child(filer_window->toplevel_vbox,
272 filer_window->toolbar, 0);
273 gtk_widget_show_all(filer_window->toolbar);
276 filer_target_mode(filer_window, NULL, NULL, NULL);
277 toolbar_update_info(filer_window);
280 /****************************************************************
281 * INTERNAL FUNCTIONS *
282 ****************************************************************/
284 static void toolbar_help_clicked(GtkWidget *widget, FilerWindow *filer_window)
286 GdkEvent *event;
288 event = gtk_get_current_event();
289 if (event->type == GDK_BUTTON_RELEASE &&
290 ((GdkEventButton *) event)->button != 1)
291 menu_rox_help(NULL, HELP_MANUAL, NULL);
292 else
293 filer_opendir(make_path(app_dir, "Help"), NULL, NULL);
296 static void toolbar_refresh_clicked(GtkWidget *widget,
297 FilerWindow *filer_window)
299 GdkEvent *event;
301 event = gtk_get_current_event();
302 if (event->type == GDK_BUTTON_RELEASE &&
303 ((GdkEventButton *) event)->button != 1)
305 filer_opendir(filer_window->sym_path, filer_window, NULL);
307 else
308 filer_refresh(filer_window);
311 static void toolbar_home_clicked(GtkWidget *widget, FilerWindow *filer_window)
313 GdkEvent *event;
315 event = gtk_get_current_event();
316 if (event->type == GDK_BUTTON_RELEASE && NEW_WIN_BUTTON(event))
318 filer_opendir(home_dir, filer_window, NULL);
320 else
321 filer_change_to(filer_window, home_dir, NULL);
324 static void toolbar_bookmarks_clicked(GtkWidget *widget,
325 FilerWindow *filer_window)
327 GdkEvent *event;
329 g_return_if_fail(filer_window != NULL);
331 event = gtk_get_current_event();
332 if (event->type == GDK_BUTTON_PRESS &&
333 ((GdkEventButton *) event)->button == 1)
335 bookmarks_show_menu(filer_window);
337 else if (event->type == GDK_BUTTON_RELEASE &&
338 ((GdkEventButton *) event)->button != 1)
340 bookmarks_edit();
344 static void toolbar_close_clicked(GtkWidget *widget, FilerWindow *filer_window)
346 GdkEvent *event;
348 g_return_if_fail(filer_window != NULL);
350 event = gtk_get_current_event();
351 if (event->type == GDK_BUTTON_RELEASE &&
352 ((GdkEventButton *) event)->button != 1)
354 filer_opendir(filer_window->sym_path, filer_window, NULL);
356 else if (!filer_window_delete(filer_window->window, NULL, filer_window))
357 gtk_widget_destroy(filer_window->window);
360 static void toolbar_up_clicked(GtkWidget *widget, FilerWindow *filer_window)
362 GdkEvent *event;
364 event = gtk_get_current_event();
365 if (event->type == GDK_BUTTON_RELEASE && NEW_WIN_BUTTON(event))
367 filer_open_parent(filer_window);
369 else
370 change_to_parent(filer_window);
373 static void toolbar_autosize_clicked(GtkWidget *widget, FilerWindow *filer_window)
375 GdkEventButton *bev;
377 bev = (GdkEventButton *) gtk_get_current_event();
378 if (bev->type != GDK_BUTTON_RELEASE)
379 return;
381 display_set_layout(filer_window, AUTO_SIZE_ICONS, filer_window->details_type,
382 TRUE);
385 static void toolbar_size_clicked(GtkWidget *widget, FilerWindow *filer_window)
387 GdkEventButton *bev;
389 bev = (GdkEventButton *) gtk_get_current_event();
390 if (bev->type != GDK_BUTTON_RELEASE)
391 return;
393 display_change_size(filer_window, bev->button == 1);
396 static void toolbar_sort_clicked(GtkWidget *widget,
397 FilerWindow *filer_window)
399 GdkEventButton *bev;
400 int i, current, next, next_wrapped;
401 gboolean adjust;
402 GtkSortType dir;
403 gchar *tip;
405 static const SortType sorts[]={
406 SORT_NAME, SORT_TYPE, SORT_DATE, SORT_SIZE,
407 SORT_OWNER, SORT_GROUP,
409 static const char *sort_names[] = {
410 N_("Sort by name"), N_("Sort by type"), N_("Sort by date"),
411 N_("Sort by size"), N_("Sort by owner"), N_("Sort by group"),
414 bev = (GdkEventButton *) gtk_get_current_event();
415 adjust = (bev->button != 1) && bev->type == GDK_BUTTON_RELEASE;
417 current = -1;
418 dir = filer_window->sort_order;
419 for (i=0; i < G_N_ELEMENTS(sort_names); i++)
421 if (filer_window->sort_type == sorts[i])
423 current = i;
424 break;
428 if (current == -1)
429 next = 0;
430 else if (adjust)
431 next = current - 1;
432 else
433 next = current + 1;
435 next_wrapped = next % G_N_ELEMENTS(sorts);
437 if (next_wrapped != next)
438 dir = (dir == GTK_SORT_ASCENDING)
439 ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING;
441 display_set_sort_type(filer_window, sorts[next_wrapped], dir);
442 tip = g_strconcat(_(sort_names[next_wrapped]), ", ",
443 dir == GTK_SORT_ASCENDING
444 ? _("ascending") : _("descending"),
445 NULL);
446 tooltip_show(tip);
447 g_free(tip);
450 static void toolbar_details_clicked(GtkWidget *widget,
451 FilerWindow *filer_window)
453 if (filer_window->view_type == VIEW_TYPE_DETAILS)
454 filer_set_view_type(filer_window, VIEW_TYPE_COLLECTION);
455 else
456 filer_set_view_type(filer_window, VIEW_TYPE_DETAILS);
459 static void toolbar_hidden_clicked(GtkWidget *widget,
460 FilerWindow *filer_window)
462 display_set_hidden(filer_window, !filer_window->show_hidden);
465 static gboolean invert_cb(ViewIter *iter, gpointer data)
467 return !view_get_selected((ViewIface *) data, iter);
470 static void toolbar_select_clicked(GtkWidget *widget, FilerWindow *filer_window)
472 GdkEvent *event;
474 event = gtk_get_current_event();
475 if (event->type == GDK_BUTTON_RELEASE)
477 if (((GdkEventButton *) event)->button == 1)
478 view_select_all(filer_window->view);
479 else
480 view_select_if(filer_window->view, invert_cb,
481 filer_window->view);
483 filer_window->temp_item_selected = FALSE;
486 /* If filer_window is NULL, the toolbar is for the options window */
487 static GtkWidget *create_toolbar(FilerWindow *filer_window)
489 GtkWidget *bar;
490 GtkWidget *b;
491 int i;
493 bar = gtk_toolbar_new();
494 if (filer_window)
495 gtk_widget_set_size_request(bar, 100, -1);
497 if (o_toolbar.int_value == TOOLBAR_NORMAL || !filer_window)
498 gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_ICONS);
499 else if (o_toolbar.int_value == TOOLBAR_HORIZONTAL)
500 gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_BOTH_HORIZ);
501 else
502 gtk_toolbar_set_style(GTK_TOOLBAR(bar), GTK_TOOLBAR_BOTH);
504 for (i = 0; i < sizeof(all_tools) / sizeof(*all_tools); i++)
506 Tool *tool = &all_tools[i];
508 if (filer_window && !tool->enabled)
509 continue;
511 b = add_button(bar, tool, filer_window);
512 if (filer_window && tool->drop_action != DROP_NONE)
513 handle_drops(filer_window, b, tool->drop_action);
516 if (filer_window)
518 filer_window->toolbar_text = gtk_label_new("");
519 gtk_misc_set_alignment(GTK_MISC(filer_window->toolbar_text),
520 0, 0.5);
521 gtk_toolbar_append_widget(GTK_TOOLBAR(bar),
522 filer_window->toolbar_text, NULL, NULL);
525 return bar;
528 /* This is used to simulate a click when button 3 is used (GtkButton
529 * normally ignores this).
531 static gint toolbar_other_button = 0;
532 static gint toolbar_button_pressed(GtkButton *button,
533 GdkEventButton *event,
534 FilerWindow *filer_window)
536 gint b = event->button;
537 Tool *tool;
539 tool = g_object_get_data(G_OBJECT(button), "rox-tool");
540 g_return_val_if_fail(tool != NULL, TRUE);
542 if (tool->menu && b == 1)
544 tool->clicked((GtkWidget *) button, filer_window);
545 return TRUE;
548 if ((b == 2 || b == 3) && toolbar_other_button == 0)
550 toolbar_other_button = event->button;
551 gtk_grab_add(GTK_WIDGET(button));
552 gtk_button_pressed(button);
554 return TRUE;
557 return FALSE;
560 static gint toolbar_button_released(GtkButton *button,
561 GdkEventButton *event,
562 FilerWindow *filer_window)
564 if (event->button == toolbar_other_button)
566 toolbar_other_button = 0;
567 gtk_grab_remove(GTK_WIDGET(button));
568 gtk_button_released(button);
570 return TRUE;
573 return FALSE;
576 /* If filer_window is NULL, the toolbar is for the options window */
577 static GtkWidget *add_button(GtkWidget *bar, Tool *tool,
578 FilerWindow *filer_window)
580 GtkWidget *button, *icon_widget;
582 icon_widget = gtk_image_new_from_stock(tool->name,
583 GTK_ICON_SIZE_LARGE_TOOLBAR);
585 button = gtk_toolbar_insert_element(GTK_TOOLBAR(bar),
586 filer_window ? GTK_TOOLBAR_CHILD_BUTTON
587 : GTK_TOOLBAR_CHILD_TOGGLEBUTTON,
588 NULL,
589 _(tool->label),
590 _(tool->tip), NULL,
591 icon_widget,
592 NULL, NULL, /* CB, userdata */
593 GTK_TOOLBAR(bar)->num_children);
595 if (o_toolbar.int_value == TOOLBAR_HORIZONTAL)
597 GtkWidget *hbox, *label;
598 GList *kids;
599 hbox = GTK_BIN(button)->child;
600 kids = gtk_container_get_children(GTK_CONTAINER(hbox));
601 label = g_list_nth_data(kids, 1);
602 g_list_free(kids);
604 if (label)
606 gtk_box_set_child_packing(GTK_BOX(hbox), label,
607 TRUE, TRUE, 0, GTK_PACK_END);
608 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
612 g_object_set_data(G_OBJECT(button), "rox-tool", tool);
614 if (filer_window)
616 g_signal_connect(button, "clicked",
617 G_CALLBACK(tool->clicked), filer_window);
618 g_signal_connect(button, "button_press_event",
619 G_CALLBACK(toolbar_button_pressed), filer_window);
620 g_signal_connect(button, "button_release_event",
621 G_CALLBACK(toolbar_button_released), filer_window);
623 else
625 g_signal_connect(button, "clicked",
626 G_CALLBACK(toggle_selected), NULL);
627 g_object_set_data(G_OBJECT(button), "tool_name",
628 (gpointer) tool->name);
631 return button;
634 static void toggle_selected(GtkToggleButton *widget, gpointer data)
636 option_check_widget(&o_toolbar_disable);
639 /* Called during the drag when the mouse is in a widget registered
640 * as a drop target. Returns TRUE if we can accept the drop.
642 static gboolean drag_motion(GtkWidget *widget,
643 GdkDragContext *context,
644 gint x,
645 gint y,
646 guint time,
647 FilerWindow *filer_window)
649 GdkDragAction action = context->suggested_action;
650 DropDest dest;
651 gpointer type = (gpointer) drop_dest_dir;
653 dest = (DropDest) g_object_get_data(G_OBJECT(widget), "toolbar_dest");
655 if ((context->actions & GDK_ACTION_ASK) && o_dnd_left_menu.int_value &&
656 dest != DROP_BOOKMARK)
658 guint state;
659 gdk_window_get_pointer(NULL, NULL, NULL, &state);
660 if (state & GDK_BUTTON1_MASK)
661 action = GDK_ACTION_ASK;
664 if (dest == DROP_TO_HOME)
665 g_dataset_set_data(context, "drop_dest_path",
666 (gchar *) home_dir);
667 else if (dest == DROP_BOOKMARK)
668 type = (gpointer) drop_dest_bookmark;
669 else
670 g_dataset_set_data_full(context, "drop_dest_path",
671 g_path_get_dirname(filer_window->sym_path),
672 g_free);
674 g_dataset_set_data(context, "drop_dest_type", type);
675 gdk_drag_status(context, action, time);
677 dnd_spring_load(context, filer_window);
678 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
680 return TRUE;
683 static void drag_leave(GtkWidget *widget,
684 GdkDragContext *context,
685 guint32 time,
686 FilerWindow *filer_window)
688 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NONE);
689 dnd_spring_abort();
692 static void handle_drops(FilerWindow *filer_window,
693 GtkWidget *button,
694 DropDest dest)
696 make_drop_target(button, 0);
697 g_signal_connect(button, "drag_motion",
698 G_CALLBACK(drag_motion), filer_window);
699 g_signal_connect(button, "drag_leave",
700 G_CALLBACK(drag_leave), filer_window);
701 g_object_set_data(G_OBJECT(button), "toolbar_dest", (gpointer) dest);
704 static void tally_items(gpointer key, gpointer value, gpointer data)
706 guchar *leafname = (guchar *) key;
707 int *tally = (int *) data;
709 if (leafname[0] == '.')
710 (*tally)++;
713 static void option_notify(void)
715 int i;
716 gboolean changed = FALSE;
717 guchar *list = o_toolbar_disable.value;
719 for (i = 0; i < sizeof(all_tools) / sizeof(*all_tools); i++)
721 Tool *tool = &all_tools[i];
722 gboolean old = tool->enabled;
724 tool->enabled = !in_list(tool->name, list);
726 if (old != tool->enabled)
727 changed = TRUE;
730 if (changed || o_toolbar.has_changed || o_toolbar_info.has_changed)
732 GList *next;
734 for (next = all_filer_windows; next; next = next->next)
736 FilerWindow *filer_window = (FilerWindow *) next->data;
738 toolbar_update_toolbar(filer_window);
743 static void update_tools(Option *option)
745 GList *next, *kids;
747 kids = gtk_container_get_children(GTK_CONTAINER(option->widget));
749 for (next = kids; next; next = next->next)
751 GtkToggleButton *kid = (GtkToggleButton *) next->data;
752 guchar *name;
754 name = g_object_get_data(G_OBJECT(kid), "tool_name");
756 g_return_if_fail(name != NULL);
758 gtk_toggle_button_set_active(kid,
759 !in_list(name, option->value));
762 g_list_free(kids);
765 static guchar *read_tools(Option *option)
767 GList *next, *kids;
768 GString *list;
769 guchar *retval;
771 list = g_string_new(NULL);
773 kids = gtk_container_get_children(GTK_CONTAINER(option->widget));
775 for (next = kids; next; next = next->next)
777 GtkToggleButton *kid = (GtkToggleButton *) next->data;
778 guchar *name;
780 if (!gtk_toggle_button_get_active(kid))
782 name = g_object_get_data(G_OBJECT(kid), "tool_name");
783 g_return_val_if_fail(name != NULL, list->str);
785 if (list->len)
786 g_string_append(list, ", ");
787 g_string_append(list, name);
791 g_list_free(kids);
792 retval = list->str;
793 g_string_free(list, FALSE);
795 return retval;
798 static GList *build_tool_options(Option *option, xmlNode *node, guchar *label)
800 GtkWidget *bar;
802 g_return_val_if_fail(option != NULL, NULL);
804 bar = create_toolbar(NULL);
806 option->update_widget = update_tools;
807 option->read_widget = read_tools;
808 option->widget = bar;
810 return g_list_append(NULL, bar);