]> git.sur5r.net Git - glabels/blob - glabels2/src/ui.c
Added menu entry to toggle visibility of property toolbar. Also added entry to toggl...
[glabels] / glabels2 / src / ui.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  ui.c:  GLabels ui module
5  *
6  *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22 #include <config.h>
23
24 #include "recent-files/egg-recent-view.h"
25 #include "recent-files/egg-recent-view-bonobo.h"
26 #include <gconf/gconf-client.h>
27
28 #include "ui.h"
29 #include "ui-util.h"
30 #include "commands.h"
31 #include "tools.h"
32 #include "recent.h" 
33 #include "file.h"
34 #include "prefs.h"
35
36 #include "debug.h"
37
38 /*==========================================================================*/
39 /* Private macros and constants.                                            */
40 /*==========================================================================*/
41 #define GLABELS_UI_XML GLABELS_UI_DIR "glabels-ui.xml"
42
43 /*==========================================================================*/
44 /* Private types.                                                           */
45 /*==========================================================================*/
46
47
48 /*==========================================================================*/
49 /* Private globals                                                          */
50 /*==========================================================================*/
51
52 static BonoboUIVerb gl_ui_verbs [] = {
53         BONOBO_UI_VERB ("FileNew",               gl_cmd_file_new),
54         BONOBO_UI_VERB ("FileProperties",        gl_cmd_file_properties),
55         BONOBO_UI_VERB ("FileOpen",              gl_cmd_file_open),
56         BONOBO_UI_VERB ("FileSave",              gl_cmd_file_save),
57         BONOBO_UI_VERB ("FileSaveAs",            gl_cmd_file_save_as),
58         BONOBO_UI_VERB ("FilePrint",             gl_cmd_file_print),
59         BONOBO_UI_VERB ("FileClose",             gl_cmd_file_close),
60         BONOBO_UI_VERB ("FileExit",              gl_cmd_file_exit),
61         BONOBO_UI_VERB ("EditCut",               gl_cmd_edit_cut),
62         BONOBO_UI_VERB ("EditCopy",              gl_cmd_edit_copy),
63         BONOBO_UI_VERB ("EditPaste",             gl_cmd_edit_paste),
64         BONOBO_UI_VERB ("EditDelete",            gl_cmd_edit_delete),
65         BONOBO_UI_VERB ("EditSelectAll",         gl_cmd_edit_select_all),
66         BONOBO_UI_VERB ("EditUnSelectAll",       gl_cmd_edit_unselect_all),
67         BONOBO_UI_VERB ("ToolsArrow",            gl_tools_arrow),
68         BONOBO_UI_VERB ("ToolsText",             gl_tools_text),
69         BONOBO_UI_VERB ("ToolsBox",              gl_tools_box),
70         BONOBO_UI_VERB ("ToolsLine",             gl_tools_line),
71         BONOBO_UI_VERB ("ToolsEllipse",          gl_tools_ellipse),
72         BONOBO_UI_VERB ("ToolsImage",            gl_tools_image),
73         BONOBO_UI_VERB ("ToolsBarcode",          gl_tools_barcode),
74         BONOBO_UI_VERB ("ToolsZoomIn",           gl_tools_zoomin),
75         BONOBO_UI_VERB ("ToolsZoomOut",          gl_tools_zoomout),
76         BONOBO_UI_VERB ("ToolsZoom1to1",         gl_tools_zoom1to1),
77         BONOBO_UI_VERB ("ToolsZoomToFit",        gl_tools_zoom_to_fit),
78         BONOBO_UI_VERB ("ToolsMergeProperties",  gl_tools_merge_properties),
79         BONOBO_UI_VERB ("ToolsRaiseObjects",     gl_tools_raise_objects),
80         BONOBO_UI_VERB ("ToolsLowerObjects",     gl_tools_lower_objects),
81         BONOBO_UI_VERB ("ToolsRotateLeft",       gl_tools_rotate_objects_left),
82         BONOBO_UI_VERB ("ToolsRotateRight",      gl_tools_rotate_objects_right),
83         BONOBO_UI_VERB ("ToolsFlipHorizontal",   gl_tools_flip_objects_horiz),
84         BONOBO_UI_VERB ("ToolsFlipVertical",     gl_tools_flip_objects_vert),
85         BONOBO_UI_VERB ("ToolsAlignLeft",        gl_tools_align_objects_left),
86         BONOBO_UI_VERB ("ToolsAlignRight",       gl_tools_align_objects_right),
87         BONOBO_UI_VERB ("ToolsAlignHCenter",     gl_tools_align_objects_hcenter),
88         BONOBO_UI_VERB ("ToolsAlignTop",         gl_tools_align_objects_top),
89         BONOBO_UI_VERB ("ToolsAlignBottom",      gl_tools_align_objects_bottom),
90         BONOBO_UI_VERB ("ToolsAlignVCenter",     gl_tools_align_objects_vcenter),
91         BONOBO_UI_VERB ("ToolsCenterHorizontal", gl_tools_center_objects_horiz),
92         BONOBO_UI_VERB ("ToolsCenterVertical",   gl_tools_center_objects_vert),
93         BONOBO_UI_VERB ("SettingsPreferences",   gl_cmd_settings_preferences),
94         BONOBO_UI_VERB ("HelpContents",          gl_cmd_help_contents),
95         BONOBO_UI_VERB ("About",                 gl_cmd_help_about),
96
97         BONOBO_UI_VERB_END
98 };
99
100 static gchar* doc_verbs [] = {
101         "/commands/FileProperties",
102         "/commands/FileSave",
103         "/commands/FileSaveAs",
104         "/commands/FilePrint",
105         "/commands/FilePrintPreview",
106         "/commands/FileClose",
107         "/commands/FileCloseAll",
108         "/commands/EditUndo",
109         "/commands/EditRedo",
110         "/commands/EditCut",
111         "/commands/EditCopy",
112         "/commands/EditPaste",
113         "/commands/EditDelete",
114         "/commands/EditSelectAll",
115         "/commands/EditUnSelectAll",
116         "/commands/ToolsArrow",
117         "/commands/ToolsText",
118         "/commands/ToolsLine",
119         "/commands/ToolsBox",
120         "/commands/ToolsEllipse",
121         "/commands/ToolsImage",
122         "/commands/ToolsBarcode",
123         "/commands/ToolsZoomIn",
124         "/commands/ToolsZoomOut",
125         "/commands/ToolsZoom1to1",
126         "/commands/ToolsZoomToFit",
127         "/commands/ToolsMergeProperties",
128         "/commands/ToolsRaiseObjects",
129         "/commands/ToolsLowerObjects",
130         "/commands/ToolsRotateLeft",
131         "/commands/ToolsRotateRight",
132         "/commands/ToolsFlipHorizontal",
133         "/commands/ToolsFlipVertical",
134         "/commands/ToolsAlignLeft",
135         "/commands/ToolsAlignRight",
136         "/commands/ToolsAlignHCenter",
137         "/commands/ToolsAlignTop",
138         "/commands/ToolsAlignBottom",
139         "/commands/ToolsAlignVCenter",
140         "/commands/ToolsCenterHorizontal",
141         "/commands/ToolsCenterVertical",
142         "/menu/Objects/CreateObjects",
143         "/menu/Objects/Order",
144         "/menu/Objects/RotateFlip",
145         "/menu/Objects/AlignHoriz",
146         "/menu/Objects/AlignVert",
147         "/commands/ViewGrid",
148         "/commands/ViewMarkup",
149
150         NULL
151 };
152
153 static gchar* doc_modified_verbs [] = {
154         "/commands/FileSave",
155
156         NULL
157 };
158
159 static gchar* selection_verbs [] = {
160         "/commands/EditCut",
161         "/commands/EditCopy",
162         "/commands/EditDelete",
163         "/commands/EditUnSelectAll",
164         "/commands/ToolsRaiseObjects",
165         "/commands/ToolsLowerObjects",
166         "/commands/ToolsRotateLeft",
167         "/commands/ToolsRotateRight",
168         "/commands/ToolsFlipHorizontal",
169         "/commands/ToolsFlipVertical",
170         "/commands/ToolsCenterHorizontal",
171         "/commands/ToolsCenterVertical",
172         "/menu/Objects/Order",
173         "/menu/Objects/RotateFlip",
174         "/menu/Objects/AlignHoriz",
175         "/menu/Objects/AlignVert",
176
177         NULL
178 };
179
180 static gchar* atomic_selection_verbs [] = {
181
182         NULL
183 };
184
185 static gchar* multi_selection_verbs [] = {
186         "/commands/ToolsAlignLeft",
187         "/commands/ToolsAlignRight",
188         "/commands/ToolsAlignHCenter",
189         "/commands/ToolsAlignTop",
190         "/commands/ToolsAlignBottom",
191         "/commands/ToolsAlignVCenter",
192
193         NULL
194 };
195
196
197 /*==========================================================================*/
198 /* Local function prototypes                                                */
199 /*==========================================================================*/
200
201 static void view_menu_item_toggled_cb     (BonoboUIComponent           *ui_component,
202                                            const char                  *path,
203                                            Bonobo_UIComponent_EventType type,
204                                            const char                  *state,
205                                            BonoboWindow                *win);
206
207 static void set_app_main_toolbar_style    (BonoboUIComponent           *ui_component);
208
209 static void set_app_drawing_toolbar_style (BonoboUIComponent           *ui_component);
210
211 static void set_app_property_toolbar_style (BonoboUIComponent           *ui_component);
212
213 static void set_view_style                (BonoboUIComponent           *ui_component);
214
215
216 \f
217 /*****************************************************************************/
218 /* Initialize UI component for given window.                                 */
219 /*****************************************************************************/
220 void
221 gl_ui_init (BonoboUIComponent *ui_component,
222             BonoboWindow      *win,
223             GtkWidget         *cursor_info_frame,
224             GtkWidget         *zoom_info_frame)
225 {
226         EggRecentView   *recent_view;
227         EggRecentModel  *recent_model;
228         BonoboControl   *control;
229
230         gl_debug (DEBUG_UI, "START");
231
232         gl_debug (DEBUG_UI, "window = %p", win);
233
234         g_return_if_fail (ui_component != NULL);
235
236         bonobo_ui_engine_config_set_path (bonobo_window_get_ui_engine (win),
237                                           "/glabels/UIConfig/kvps");
238         gl_debug (DEBUG_UI, "Path set");
239
240         bonobo_ui_util_set_ui (ui_component,
241                                "", GLABELS_UI_XML, "gLabels", NULL);
242         gl_debug (DEBUG_UI, "UI set");
243
244         bonobo_ui_component_add_verb_list_with_data(ui_component,
245                                                     gl_ui_verbs, win);
246         gl_debug (DEBUG_UI, "verb list added");
247
248         /* Set the toolbar style according to prefs */
249         set_app_main_toolbar_style (ui_component);
250                 
251         /* Add listener for the view menu */
252         bonobo_ui_component_add_listener (ui_component, "ViewMainToolbar", 
253                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
254                         (gpointer)win);
255
256         bonobo_ui_component_add_listener (ui_component, "MainToolbarSystem", 
257                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
258                         (gpointer)win);
259         bonobo_ui_component_add_listener (ui_component, "MainToolbarIcon", 
260                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
261                         (gpointer)win);
262         bonobo_ui_component_add_listener (ui_component, "MainToolbarIconText", 
263                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
264                         (gpointer)win);
265         bonobo_ui_component_add_listener (ui_component, "MainToolbarTooltips", 
266                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
267                         (gpointer)win);
268
269         /* Set the toolbar style according to prefs */
270         set_app_drawing_toolbar_style (ui_component);
271                 
272         /* Add listener for the view menu */
273         bonobo_ui_component_add_listener (ui_component, "ViewDrawingToolbar", 
274                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
275                         (gpointer)win);
276
277         bonobo_ui_component_add_listener (ui_component, "DrawingToolbarSystem", 
278                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
279                         (gpointer)win);
280         bonobo_ui_component_add_listener (ui_component, "DrawingToolbarIcon", 
281                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
282                         (gpointer)win);
283         bonobo_ui_component_add_listener (ui_component, "DrawingToolbarIconText", 
284                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
285                         (gpointer)win);
286         bonobo_ui_component_add_listener (ui_component, "DrawingToolbarTooltips", 
287                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
288                         (gpointer)win);
289
290         /* Set the toolbar style according to prefs */
291         set_app_property_toolbar_style (ui_component);
292                 
293         /* Add listener for the view menu */
294         bonobo_ui_component_add_listener (ui_component, "ViewPropertyToolbar", 
295                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
296                         (gpointer)win);
297
298         bonobo_ui_component_add_listener (ui_component, "PropertyToolbarTooltips", 
299                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
300                         (gpointer)win);
301
302
303         /* Set view grid and markup visibility according to prefs */
304         set_view_style (ui_component);
305                 
306         /* Add listener for the view grid & markup */
307         bonobo_ui_component_add_listener (ui_component, "ViewGrid", 
308                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
309                         (gpointer)win);
310         bonobo_ui_component_add_listener (ui_component, "ViewMarkup", 
311                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
312                         (gpointer)win);
313
314         gl_ui_util_set_verb_list_sensitive (ui_component, doc_verbs, FALSE);
315
316         /* Status bar */
317         gl_debug (DEBUG_UI, "START Setup status bar.");
318
319         bonobo_ui_component_set_prop (ui_component,
320                                       "/status", "hidden", "0", NULL);
321
322         control = bonobo_control_new (cursor_info_frame);
323         bonobo_ui_component_object_set (ui_component,
324                                         "/status/Cursor", BONOBO_OBJREF (control), NULL);
325         bonobo_object_unref (BONOBO_OBJECT (control));
326         bonobo_ui_component_set_prop (ui_component,
327                                       "/status/Cursor", "hidden", "0", NULL);
328
329         control = bonobo_control_new (zoom_info_frame);
330         bonobo_ui_component_object_set (ui_component,
331                                         "/status/Zoom", BONOBO_OBJREF (control), NULL);
332         bonobo_object_unref (BONOBO_OBJECT (control));
333         bonobo_ui_component_set_prop (ui_component,
334                                       "/status/Zoom", "hidden", "0", NULL);
335
336         gl_debug (DEBUG_UI, "END Setup status bar.");
337
338
339         /* add an eggRecentView object */
340         recent_model = gl_recent_get_model ();
341         recent_view  =
342                 EGG_RECENT_VIEW (egg_recent_view_bonobo_new (ui_component,
343                                                              "/menu/File/Recents"));
344         egg_recent_view_set_model (recent_view, recent_model);
345
346         g_signal_connect (G_OBJECT (recent_view), "activate",
347                           G_CALLBACK (gl_file_open_recent), win);
348
349         /* Squirrel away a copy to be unreferenced in gl_ui_unref() */
350         g_object_set_data (G_OBJECT (ui_component), "recent-view", recent_view);
351
352         gl_debug (DEBUG_UI, "END");
353 }
354
355 /*****************************************************************************/
356 /* Unref wrapper.                                                            */
357 /*****************************************************************************/
358 void
359 gl_ui_unref (BonoboUIComponent *ui_component)
360 {
361         EggRecentView *recent_view;
362
363         /* Pull out recent view to unreference. */
364         recent_view = g_object_get_data (G_OBJECT(ui_component), "recent-view");
365         if (recent_view) {
366                 g_object_unref (recent_view);
367         }
368
369         bonobo_object_unref(ui_component);
370 }
371
372 /*****************************************************************************/
373 /* Update all verbs of given UI component.                                   */
374 /*****************************************************************************/
375 void
376 gl_ui_update_all (BonoboUIComponent *ui_component,
377                   glView            *view)
378 {
379         glLabel *label;
380
381         gl_debug (DEBUG_UI, "START");
382
383         bonobo_ui_component_freeze (ui_component, NULL);
384
385         gl_ui_util_set_verb_list_sensitive (ui_component, doc_verbs, TRUE);
386
387         label = view->label;
388         g_return_if_fail (label != NULL);
389
390         gl_ui_util_set_verb_sensitive (ui_component, "/commands/EditUndo",
391                                        gl_label_can_undo (label));
392         gl_ui_util_set_verb_sensitive (ui_component, "/commands/EditRedo",
393                                        gl_label_can_redo (label));
394
395         gl_ui_util_set_verb_list_sensitive (ui_component, 
396                                             doc_modified_verbs,
397                                             gl_label_is_modified (label));
398
399         gl_ui_util_set_verb_sensitive (ui_component, "/commands/ToolsZoomIn",
400                                        !gl_view_is_zoom_max (view));
401         gl_ui_util_set_verb_sensitive (ui_component, "/commands/ToolsZoomOut",
402                                        !gl_view_is_zoom_min (view));
403
404         gl_ui_util_set_verb_list_sensitive (ui_component,
405                                             selection_verbs,
406                                             !gl_view_is_selection_empty (view));
407
408         gl_ui_util_set_verb_list_sensitive (ui_component,
409                                             atomic_selection_verbs,
410                                             gl_view_is_selection_atomic (view));
411
412         gl_ui_util_set_verb_list_sensitive (ui_component,
413                                             multi_selection_verbs,
414                                             !gl_view_is_selection_empty (view)
415                                             && !gl_view_is_selection_atomic (view));
416
417         bonobo_ui_component_thaw (ui_component, NULL);
418
419         gl_debug (DEBUG_UI, "END");
420 }
421
422 /*****************************************************************************/
423 /* Update all verbs of given UI component to "no document" state.            */
424 /*****************************************************************************/
425 void
426 gl_ui_update_nodoc (BonoboUIComponent *ui_component)
427 {
428         gl_debug (DEBUG_UI, "START");
429
430         bonobo_ui_component_freeze (ui_component, NULL);
431         
432         gl_ui_util_set_verb_list_sensitive (ui_component, doc_verbs, FALSE);
433
434         bonobo_ui_component_thaw (ui_component, NULL);
435
436         gl_debug (DEBUG_UI, "END");
437 }
438
439 /*****************************************************************************/
440 /* Update label modified verbs of given UI component.                        */
441 /*****************************************************************************/
442 void
443 gl_ui_update_modified_verbs (BonoboUIComponent *ui_component,
444                              glLabel           *label)
445 {
446         gl_debug (DEBUG_UI, "START");
447
448         bonobo_ui_component_freeze (ui_component, NULL);
449
450         gl_ui_util_set_verb_list_sensitive (ui_component, 
451                                             doc_modified_verbs,
452                                             gl_label_is_modified (label));
453
454         bonobo_ui_component_thaw (ui_component, NULL);
455
456         gl_debug (DEBUG_UI, "END");
457 }
458
459 /*****************************************************************************/
460 /* Update verbs associated with selection state of given UI component.       */
461 /*****************************************************************************/
462 void
463 gl_ui_update_selection_verbs (BonoboUIComponent *ui_component,
464                               glView            *view)
465 {
466         gl_debug (DEBUG_UI, "START");
467
468         bonobo_ui_component_freeze (ui_component, NULL);
469
470         gl_ui_util_set_verb_list_sensitive (ui_component,
471                                             selection_verbs,
472                                             !gl_view_is_selection_empty (view));
473
474         gl_ui_util_set_verb_list_sensitive (ui_component,
475                                             atomic_selection_verbs,
476                                             gl_view_is_selection_atomic (view));
477
478         gl_ui_util_set_verb_list_sensitive (ui_component,
479                                             multi_selection_verbs,
480                                             !gl_view_is_selection_empty (view)
481                                             && !gl_view_is_selection_atomic (view));
482
483         bonobo_ui_component_thaw (ui_component, NULL);
484
485         gl_debug (DEBUG_UI, "END");
486 }
487
488 /*****************************************************************************/
489 /* Update verbs associated with zoom level of given UI component.            */
490 /*****************************************************************************/
491 void
492 gl_ui_update_zoom_verbs (BonoboUIComponent *ui_component,
493                          glView            *view)
494 {
495         gl_debug (DEBUG_UI, "START");
496
497         bonobo_ui_component_freeze (ui_component, NULL);
498
499         gl_ui_util_set_verb_sensitive (ui_component, "/commands/ToolsZoomIn",
500                                        !gl_view_is_zoom_max (view));
501         gl_ui_util_set_verb_sensitive (ui_component, "/commands/ToolsZoomOut",
502                                        !gl_view_is_zoom_min (view));
503
504         bonobo_ui_component_thaw (ui_component, NULL);
505
506         gl_debug (DEBUG_UI, "END");
507 }
508
509 /*****************************************************************************/
510 /* Update undo/redo verbs of given UI component.                             */
511 /*****************************************************************************/
512 void
513 gl_ui_update_undo_redo_verbs (BonoboUIComponent *ui_component,
514                               glLabel           *label)
515 {
516         gl_debug (DEBUG_UI, "START");
517
518         bonobo_ui_component_freeze (ui_component, NULL);
519
520         gl_ui_util_set_verb_sensitive (ui_component,
521                                        "/commands/EditUndo",
522                                        gl_label_can_undo (label));
523
524         gl_ui_util_set_verb_sensitive (ui_component,
525                                        "/commands/EditRedo",
526                                        gl_label_can_redo (label));
527
528         bonobo_ui_component_thaw (ui_component, NULL);
529
530         gl_debug (DEBUG_UI, "END");
531 }
532
533 /*---------------------------------------------------------------------------*/
534 /* PRIVATE.  View menu item toggled callback.                                */
535 /*---------------------------------------------------------------------------*/
536 static void
537 view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
538                            const char                  *path,
539                            Bonobo_UIComponent_EventType type,
540                            const char                  *state,
541                            BonoboWindow                *win)
542 {
543         gboolean s;
544
545         gl_debug (DEBUG_UI, "");
546
547         s = (strcmp (state, "1") == 0);
548
549         if (strcmp (path, "ViewMainToolbar") == 0)
550         {
551                 gl_prefs->main_toolbar_visible = s;
552                 set_app_main_toolbar_style (ui_component);
553                 gl_prefs_model_save_settings (gl_prefs);
554
555                 return;
556         }
557
558         if (s && (strcmp (path, "MainToolbarSystem") == 0))
559         {               
560                 gl_prefs->main_toolbar_buttons_style = GL_TOOLBAR_SYSTEM;
561                 set_app_main_toolbar_style (ui_component);
562                 gl_prefs_model_save_settings (gl_prefs);
563
564                 return;
565         }
566
567         if (s && (strcmp (path, "MainToolbarIcon") == 0))
568         {               
569                 gl_prefs->main_toolbar_buttons_style = GL_TOOLBAR_ICONS;
570                 set_app_main_toolbar_style (ui_component);
571                 gl_prefs_model_save_settings (gl_prefs);
572
573                 return;
574         }
575
576         if (s && (strcmp (path, "MainToolbarIconText") == 0))
577         {               
578                 gl_prefs->main_toolbar_buttons_style = GL_TOOLBAR_ICONS_AND_TEXT;
579                 set_app_main_toolbar_style (ui_component);
580                 gl_prefs_model_save_settings (gl_prefs);
581
582                 return;
583         }
584
585         if (strcmp (path, "MainToolbarTooltips") == 0)
586         {
587                 gl_prefs->main_toolbar_view_tooltips = s;
588                 set_app_main_toolbar_style (ui_component);
589                 gl_prefs_model_save_settings (gl_prefs);
590
591                 return;
592         }
593
594         if (strcmp (path, "ViewDrawingToolbar") == 0)
595         {
596                 gl_prefs->drawing_toolbar_visible = s;
597                 set_app_drawing_toolbar_style (ui_component);
598                 gl_prefs_model_save_settings (gl_prefs);
599
600                 return;
601         }
602
603         if (s && (strcmp (path, "DrawingToolbarSystem") == 0))
604         {               
605                 gl_prefs->drawing_toolbar_buttons_style = GL_TOOLBAR_SYSTEM;
606                 set_app_drawing_toolbar_style (ui_component);
607                 gl_prefs_model_save_settings (gl_prefs);
608
609                 return;
610         }
611
612         if (s && (strcmp (path, "DrawingToolbarIcon") == 0))
613         {               
614                 gl_prefs->drawing_toolbar_buttons_style = GL_TOOLBAR_ICONS;
615                 set_app_drawing_toolbar_style (ui_component);
616                 gl_prefs_model_save_settings (gl_prefs);
617
618                 return;
619         }
620
621         if (s && (strcmp (path, "DrawingToolbarIconText") == 0))
622         {               
623                 gl_prefs->drawing_toolbar_buttons_style = GL_TOOLBAR_ICONS_AND_TEXT;
624                 set_app_drawing_toolbar_style (ui_component);
625                 gl_prefs_model_save_settings (gl_prefs);
626
627                 return;
628         }
629
630         if (strcmp (path, "DrawingToolbarTooltips") == 0)
631         {
632                 gl_prefs->drawing_toolbar_view_tooltips = s;
633                 set_app_drawing_toolbar_style (ui_component);
634                 gl_prefs_model_save_settings (gl_prefs);
635
636                 return;
637         }
638
639         if (strcmp (path, "ViewPropertyToolbar") == 0)
640         {
641                 gl_prefs->property_toolbar_visible = s;
642                 set_app_property_toolbar_style (ui_component);
643                 gl_prefs_model_save_settings (gl_prefs);
644
645                 return;
646         }
647
648         if (strcmp (path, "PropertyToolbarTooltips") == 0)
649         {
650                 gl_prefs->property_toolbar_view_tooltips = s;
651                 set_app_property_toolbar_style (ui_component);
652                 gl_prefs_model_save_settings (gl_prefs);
653
654                 return;
655         }
656
657         if (strcmp (path, "ViewGrid") == 0)
658         {
659                 gl_prefs->grid_visible = s;
660                 if (s) {
661                         gl_view_show_grid (GL_VIEW(GL_WINDOW(win)->view));
662                 } else {
663                         gl_view_hide_grid (GL_VIEW(GL_WINDOW(win)->view));
664                 }
665                 gl_prefs_model_save_settings (gl_prefs);
666
667                 return;
668         }
669
670         if (strcmp (path, "ViewMarkup") == 0)
671         {
672                 gl_prefs->markup_visible = s;
673                 if (s) {
674                         gl_view_show_markup (GL_VIEW(GL_WINDOW(win)->view));
675                 } else {
676                         gl_view_hide_markup (GL_VIEW(GL_WINDOW(win)->view));
677                 }
678                 gl_prefs_model_save_settings (gl_prefs);
679
680                 return;
681         }
682
683 }
684
685 /*---------------------------------------------------------------------------*/
686 /* PRIVATE.  Set main toolbar style.                                         */
687 /*---------------------------------------------------------------------------*/
688 static void
689 set_app_main_toolbar_style (BonoboUIComponent *ui_component)
690 {
691         GConfClient *client;
692         gboolean labels;
693
694         gl_debug (DEBUG_UI, "START");
695
696         g_return_if_fail (BONOBO_IS_UI_COMPONENT (ui_component));
697                         
698         bonobo_ui_component_freeze (ui_component, NULL);
699
700         /* Updated view menu */
701         gl_ui_util_set_verb_state (ui_component, 
702                                    "/commands/ViewMainToolbar",
703                                    gl_prefs->main_toolbar_visible);
704
705         gl_ui_util_set_verb_sensitive (ui_component, 
706                                        "/commands/MainToolbarSystem",
707                                        gl_prefs->main_toolbar_visible);
708         gl_ui_util_set_verb_sensitive (ui_component, 
709                                        "/commands/MainToolbarIcon",
710                                        gl_prefs->main_toolbar_visible);
711         gl_ui_util_set_verb_sensitive (ui_component, 
712                                        "/commands/MainToolbarIconText",
713                                        gl_prefs->main_toolbar_visible);
714         gl_ui_util_set_verb_sensitive (ui_component, 
715                                        "/commands/MainToolbarTooltips",
716                                        gl_prefs->main_toolbar_visible);
717
718         gl_ui_util_set_verb_state (ui_component, 
719                                    "/commands/MainToolbarSystem",
720                                    gl_prefs->main_toolbar_buttons_style == GL_TOOLBAR_SYSTEM);
721
722         gl_ui_util_set_verb_state (ui_component, 
723                                    "/commands/MainToolbarIcon",
724                                    gl_prefs->main_toolbar_buttons_style == GL_TOOLBAR_ICONS);
725
726         gl_ui_util_set_verb_state (ui_component, 
727                                    "/commands/MainToolbarIconText",
728                                    gl_prefs->main_toolbar_buttons_style == GL_TOOLBAR_ICONS_AND_TEXT);
729
730         gl_ui_util_set_verb_state (ui_component, 
731                                    "/commands/MainToolbarTooltips",
732                                    gl_prefs->main_toolbar_view_tooltips);
733
734         
735         /* Actually update main_toolbar style */
736         bonobo_ui_component_set_prop (
737                 ui_component, "/MainToolbar",
738                 "tips", gl_prefs->main_toolbar_view_tooltips ? "1" : "0",
739                 NULL);
740         
741         switch (gl_prefs->main_toolbar_buttons_style)
742         {
743                 case GL_TOOLBAR_SYSTEM:
744                                                 
745                         client = gconf_client_get_default ();
746                         if (client == NULL) 
747                                 goto error;
748
749                         labels = gconf_client_get_bool (client, 
750                                         "/desktop/gnome/interface/toolbar-labels", NULL);
751
752                         g_object_unref (G_OBJECT (client));
753                         
754                         if (labels)
755                         {                       
756                                 bonobo_ui_component_set_prop (
757                                         ui_component, "/MainToolbar", "look", "both", NULL);
758                         
759                         }
760                         else
761                         {
762                                 bonobo_ui_component_set_prop (
763                                         ui_component, "/MainToolbar", "look", "icons", NULL);
764                         }
765         
766                         break;
767                         
768                 case GL_TOOLBAR_ICONS:
769                         bonobo_ui_component_set_prop (
770                                 ui_component, "/MainToolbar", "look", "icon", NULL);
771                         
772                         break;
773                         
774                 case GL_TOOLBAR_ICONS_AND_TEXT:
775                         bonobo_ui_component_set_prop (
776                                 ui_component, "/MainToolbar", "look", "both", NULL);
777                         
778                         break;
779                 default:
780                         goto error;
781                         break;
782         }
783         
784         bonobo_ui_component_set_prop (
785                         ui_component, "/MainToolbar",
786                         "hidden", gl_prefs->main_toolbar_visible ? "0":"1", NULL);
787
788  error:
789         bonobo_ui_component_thaw (ui_component, NULL);
790
791         gl_debug (DEBUG_UI, "END");
792 }
793
794
795 /*---------------------------------------------------------------------------*/
796 /* PRIVATE.  Set drawing toolbar style.                                      */
797 /*---------------------------------------------------------------------------*/
798 static void
799 set_app_drawing_toolbar_style (BonoboUIComponent *ui_component)
800 {
801         GConfClient *client;
802         gboolean labels;
803
804         gl_debug (DEBUG_UI, "START");
805
806         g_return_if_fail (BONOBO_IS_UI_COMPONENT(ui_component));
807                         
808         bonobo_ui_component_freeze (ui_component, NULL);
809
810         /* Updated view menu */
811         gl_ui_util_set_verb_state (ui_component, 
812                                    "/commands/ViewDrawingToolbar",
813                                    gl_prefs->drawing_toolbar_visible);
814
815         gl_ui_util_set_verb_sensitive (ui_component, 
816                                        "/commands/DrawingToolbarSystem",
817                                        gl_prefs->drawing_toolbar_visible);
818         gl_ui_util_set_verb_sensitive (ui_component, 
819                                        "/commands/DrawingToolbarIcon",
820                                        gl_prefs->drawing_toolbar_visible);
821         gl_ui_util_set_verb_sensitive (ui_component, 
822                                        "/commands/DrawingToolbarIconText",
823                                        gl_prefs->drawing_toolbar_visible);
824         gl_ui_util_set_verb_sensitive (ui_component, 
825                                        "/commands/DrawingToolbarTooltips",
826                                        gl_prefs->drawing_toolbar_visible);
827
828         gl_ui_util_set_verb_state (
829                 ui_component, 
830                 "/commands/DrawingToolbarSystem",
831                 gl_prefs->drawing_toolbar_buttons_style == GL_TOOLBAR_SYSTEM);
832
833         gl_ui_util_set_verb_state (
834                 ui_component, 
835                 "/commands/DrawingToolbarIcon",
836                 gl_prefs->drawing_toolbar_buttons_style == GL_TOOLBAR_ICONS);
837
838         gl_ui_util_set_verb_state (
839                 ui_component, 
840                 "/commands/DrawingToolbarIconText",
841                 gl_prefs->drawing_toolbar_buttons_style == GL_TOOLBAR_ICONS_AND_TEXT);
842
843         gl_ui_util_set_verb_state (ui_component, 
844                         "/commands/DrawingToolbarTooltips",
845                         gl_prefs->drawing_toolbar_view_tooltips);
846
847         
848         /* Actually update drawing_toolbar style */
849         bonobo_ui_component_set_prop (
850                 ui_component, "/DrawingToolbar",
851                 "tips", gl_prefs->drawing_toolbar_view_tooltips ? "1" : "0",
852                 NULL);
853         
854         switch (gl_prefs->drawing_toolbar_buttons_style)
855         {
856                 case GL_TOOLBAR_SYSTEM:
857                                                 
858                         client = gconf_client_get_default ();
859                         if (client == NULL) 
860                                 goto error;
861
862                         labels = gconf_client_get_bool (client, 
863                                         "/desktop/gnome/interface/toolbar-labels", NULL);
864
865                         g_object_unref (G_OBJECT (client));
866                         
867                         if (labels)
868                         {                       
869                                 bonobo_ui_component_set_prop (
870                                         ui_component, "/DrawingToolbar", "look", "both", NULL);
871                         
872                         }
873                         else
874                         {
875                                 bonobo_ui_component_set_prop (
876                                         ui_component, "/DrawingToolbar", "look", "icons", NULL);
877                         }
878         
879                         break;
880                         
881                 case GL_TOOLBAR_ICONS:
882                         bonobo_ui_component_set_prop (
883                                 ui_component, "/DrawingToolbar", "look", "icon", NULL);
884                         
885                         break;
886                         
887                 case GL_TOOLBAR_ICONS_AND_TEXT:
888                         bonobo_ui_component_set_prop (
889                                 ui_component, "/DrawingToolbar", "look", "both", NULL);
890                         
891                         break;
892                 default:
893                         goto error;
894                         break;
895         }
896         
897         bonobo_ui_component_set_prop (
898                         ui_component, "/DrawingToolbar",
899                         "hidden", gl_prefs->drawing_toolbar_visible ? "0":"1", NULL);
900
901  error:
902         bonobo_ui_component_thaw (ui_component, NULL);
903
904         gl_debug (DEBUG_UI, "END");
905 }
906
907 /*---------------------------------------------------------------------------*/
908 /* PRIVATE.  Set property toolbar style.                                     */
909 /*---------------------------------------------------------------------------*/
910 static void
911 set_app_property_toolbar_style (BonoboUIComponent *ui_component)
912 {
913         GConfClient *client;
914         gboolean labels;
915
916         gl_debug (DEBUG_UI, "START");
917
918         g_return_if_fail (BONOBO_IS_UI_COMPONENT(ui_component));
919                         
920         bonobo_ui_component_freeze (ui_component, NULL);
921
922         /* Updated view menu */
923         gl_ui_util_set_verb_state (ui_component, 
924                                    "/commands/ViewPropertyToolbar",
925                                    gl_prefs->property_toolbar_visible);
926
927         gl_ui_util_set_verb_sensitive (ui_component, 
928                                        "/commands/PropertyToolbarTooltips",
929                                        gl_prefs->property_toolbar_visible);
930
931         gl_ui_util_set_verb_state (ui_component, 
932                         "/commands/PropertyToolbarTooltips",
933                         gl_prefs->property_toolbar_view_tooltips);
934
935         
936         /* Actually update property_toolbar style */
937         bonobo_ui_component_set_prop (
938                 ui_component, "/PropertyToolbar",
939                 "tips", gl_prefs->property_toolbar_view_tooltips ? "1" : "0",
940                 NULL);
941         
942         bonobo_ui_component_set_prop (
943                         ui_component, "/PropertyToolbar",
944                         "hidden", gl_prefs->property_toolbar_visible ? "0":"1", NULL);
945
946         bonobo_ui_component_thaw (ui_component, NULL);
947
948         gl_debug (DEBUG_UI, "END");
949 }
950
951 /*---------------------------------------------------------------------------*/
952 /* PRIVATE.  Set visibility of grid and markup.                              */
953 /*---------------------------------------------------------------------------*/
954 static void
955 set_view_style (BonoboUIComponent *ui_component)
956 {
957         GConfClient *client;
958         gboolean labels;
959
960         gl_debug (DEBUG_UI, "START");
961
962         g_return_if_fail (BONOBO_IS_UI_COMPONENT(ui_component));
963                         
964         bonobo_ui_component_freeze (ui_component, NULL);
965
966         gl_ui_util_set_verb_state (ui_component, 
967                                    "/commands/ViewGrid",
968                                    gl_prefs->grid_visible);
969
970         gl_ui_util_set_verb_state (ui_component, 
971                                    "/commands/ViewMarkup",
972                                    gl_prefs->markup_visible);
973
974  error:
975         bonobo_ui_component_thaw (ui_component, NULL);
976
977         gl_debug (DEBUG_UI, "END");
978 }
979
980