]> git.sur5r.net Git - glabels/blob - glabels2/src/mdi.c
Moved HIG inspired alert dialog to its own module (alert.[ch]).
[glabels] / glabels2 / src / mdi.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  mdi.c:  gLabels MDI 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
23 /*
24  * This file is based on gedit-mdi.c from gedit2:
25  *
26  * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
27  * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi 
28  * Copyright (C) 2002  Paolo Maggi 
29  *
30  */
31 #include <config.h>
32
33 #include <libgnome/libgnome.h>
34 #include <libgnomeui/libgnomeui.h>
35 #include <libgnomevfs/gnome-vfs.h>
36
37 #include <string.h>
38
39 #include "mdi.h"
40 #include "mdi-child.h"
41 #include "glabels.h"
42 #include "menus.h"
43 #include "prefs.h"
44 #include "recent.h" 
45 #include "file.h"
46 #include "view.h"
47 #include "debug.h"
48 #include "gnome-recent-view.h"
49 #include "alert.h"
50
51 #include <bonobo/bonobo-ui-util.h>
52 #include <bonobo/bonobo-control.h>
53
54 #include <gconf/gconf-client.h>
55
56 /*========================================================*/
57 /* Private macros and constants.                          */
58 /*========================================================*/
59
60 #define DEFAULT_WINDOW_WIDTH  500
61 #define DEFAULT_WINDOW_HEIGHT 375
62
63 /*========================================================*/
64 /* Private types.                                         */
65 /*========================================================*/
66
67 struct _glMDIPrivate
68 {
69         gint untitled_number;
70 };
71
72
73 /*========================================================*/
74 /* Private globals.                                       */
75 /*========================================================*/
76
77 static BonoboMDIClass *parent_class = NULL;
78
79
80 /*========================================================*/
81 /* Private function prototypes.                           */
82 /*========================================================*/
83
84 static void gl_mdi_class_init   (glMDIClass     *klass);
85 static void gl_mdi_init                 (glMDI  *mdi);
86 static void gl_mdi_finalize             (GObject        *object);
87
88 static void gl_mdi_app_created_cb       (BonoboMDI *mdi, BonoboWindow *win);
89 static void gl_mdi_set_app_toolbar_style        (BonoboWindow *win);
90 static void gl_mdi_set_app_statusbar_style      (BonoboWindow *win);
91
92 static gint gl_mdi_add_child_cb (BonoboMDI *mdi, BonoboMDIChild *child);
93 static gint gl_mdi_add_view_cb (BonoboMDI *mdi, GtkWidget *view);
94 static gint gl_mdi_remove_child_cb (BonoboMDI *mdi, BonoboMDIChild *child);
95 static gint gl_mdi_remove_view_cb (BonoboMDI *mdi, GtkWidget *view);
96
97 static void gl_mdi_view_changed_cb (BonoboMDI *mdi, GtkWidget *old_view);
98 static void gl_mdi_child_changed_cb (BonoboMDI *mdi, BonoboMDIChild *old_child);
99 static void gl_mdi_child_state_changed_cb (glMDIChild *child);
100
101 static void gl_mdi_set_active_window_undo_redo_verbs_sensitivity (BonoboMDI *mdi);
102
103 static void gl_mdi_view_menu_item_toggled_cb (
104                         BonoboUIComponent           *ui_component,
105                         const char                  *path,
106                         Bonobo_UIComponent_EventType type,
107                         const char                  *state,
108                         BonoboWindow                *win);
109
110 \f
111 /*****************************************************************************/
112 /* Boilerplate object stuff.                                                 */
113 /*****************************************************************************/
114 GType
115 gl_mdi_get_type (void)
116 {
117         static GType mdi_type = 0;
118
119         if (mdi_type == 0)
120         {
121                 static const GTypeInfo our_info =
122                 {
123                         sizeof (glMDIClass),
124                         NULL,           /* base_init */
125                         NULL,           /* base_finalize */
126                         (GClassInitFunc) gl_mdi_class_init,
127                         NULL,           /* class_finalize */
128                         NULL,           /* class_data */
129                         sizeof (glMDI),
130                         0,              /* n_preallocs */
131                         (GInstanceInitFunc) gl_mdi_init
132                 };
133
134                 mdi_type = g_type_register_static (BONOBO_TYPE_MDI,
135                                                     "glMDI",
136                                                     &our_info,
137                                                     0);
138         }
139
140         return mdi_type;
141 }
142
143 static void
144 gl_mdi_class_init (glMDIClass *klass)
145 {
146         GObjectClass *object_class = G_OBJECT_CLASS (klass);
147
148         gl_debug (DEBUG_MDI, "START");
149
150         parent_class = g_type_class_peek_parent (klass);
151
152         object_class->finalize = gl_mdi_finalize;
153
154         gl_debug (DEBUG_MDI, "END");
155 }
156
157 static void 
158 gl_mdi_init (glMDI  *mdi)
159 {
160         gl_debug (DEBUG_MDI, "START");
161
162         bonobo_mdi_construct (BONOBO_MDI (mdi), "glabels", "gLabels",
163                               DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
164         
165         mdi->priv = g_new0 (glMDIPrivate, 1);
166
167         mdi->priv->untitled_number = 0; 
168
169         bonobo_mdi_set_ui_template_file (BONOBO_MDI (mdi),
170                                          GLABELS_UI_DIR "glabels-ui.xml",
171                                          gl_verbs);
172         
173         bonobo_mdi_set_child_list_path (BONOBO_MDI (mdi), "/menu/Documents/");
174
175         /* Connect signals */
176         g_signal_connect (G_OBJECT (mdi), "top_window_created",
177                           G_CALLBACK (gl_mdi_app_created_cb), NULL);
178         
179         g_signal_connect (G_OBJECT (mdi), "add_child",
180                           G_CALLBACK (gl_mdi_add_child_cb), NULL);
181         g_signal_connect (G_OBJECT (mdi), "add_view",
182                           G_CALLBACK (gl_mdi_add_view_cb), NULL);
183         
184         g_signal_connect (G_OBJECT (mdi), "remove_child",
185                           G_CALLBACK (gl_mdi_remove_child_cb), NULL);
186         g_signal_connect (G_OBJECT (mdi), "remove_view",
187                           G_CALLBACK (gl_mdi_remove_view_cb), NULL);
188
189         g_signal_connect (G_OBJECT (mdi), "child_changed",
190                           G_CALLBACK (gl_mdi_child_changed_cb), NULL);
191         g_signal_connect (G_OBJECT (mdi), "view_changed",
192                           G_CALLBACK (gl_mdi_view_changed_cb), NULL);
193
194         g_signal_connect (G_OBJECT (mdi), "all_windows_destroyed",
195                           G_CALLBACK (gl_file_exit), NULL);
196
197         gl_debug (DEBUG_MDI, "END");
198 }
199
200 static void
201 gl_mdi_finalize (GObject *object)
202 {
203         glMDI *mdi;
204
205         gl_debug (DEBUG_MDI, "START");
206
207         g_return_if_fail (object != NULL);
208         
209         mdi = GL_MDI (object);
210
211         g_return_if_fail (GL_IS_MDI (mdi));
212         g_return_if_fail (mdi->priv != NULL);
213
214         G_OBJECT_CLASS (parent_class)->finalize (object);
215
216         g_free (mdi->priv);
217
218         gl_debug (DEBUG_MDI, "END");
219 }
220
221
222 /*****************************************************************************/
223 /* NEW mdi objecg.                                                           */
224 /*****************************************************************************/
225 glMDI*
226 gl_mdi_new (void)
227 {
228         glMDI *mdi;
229
230         gl_debug (DEBUG_MDI, "START");
231
232         mdi = GL_MDI (g_object_new (GL_TYPE_MDI, NULL));
233         g_return_val_if_fail (mdi != NULL, NULL);
234         
235         gl_debug (DEBUG_MDI, "END");
236         return mdi;
237 }
238
239 /*---------------------------------------------------------------------------*/
240 /* App created callback.                                                     */
241 /*---------------------------------------------------------------------------*/
242 static void
243 gl_mdi_app_created_cb (BonoboMDI *mdi, BonoboWindow *win)
244 {
245         GtkWidget *widget;
246         BonoboControl *control;
247         BonoboUIComponent *ui_component;
248         GnomeRecentView *view;
249         GnomeRecentModel *model;
250
251         static GtkTargetEntry drag_types[] =
252         {
253                 { "text/uri-list", 0, 0 },
254         };
255
256         static gint n_drag_types =
257                 sizeof (drag_types) / sizeof (drag_types [0]);
258
259         gl_debug (DEBUG_MDI, "START");
260         
261         ui_component = bonobo_mdi_get_ui_component_from_window (win);
262         g_return_if_fail (ui_component != NULL);
263         
264         /* Set the toolbar style according to prefs */
265         gl_mdi_set_app_toolbar_style (win);
266                 
267         /* Add listener fo the view menu */
268         bonobo_ui_component_add_listener (ui_component, "ViewToolbar", 
269                         (BonoboUIListenerFn)gl_mdi_view_menu_item_toggled_cb, 
270                         (gpointer)win);
271
272         bonobo_ui_component_add_listener (ui_component, "ToolbarSystem", 
273                         (BonoboUIListenerFn)gl_mdi_view_menu_item_toggled_cb, 
274                         (gpointer)win);
275         bonobo_ui_component_add_listener (ui_component, "ToolbarIcon", 
276                         (BonoboUIListenerFn)gl_mdi_view_menu_item_toggled_cb, 
277                         (gpointer)win);
278         bonobo_ui_component_add_listener (ui_component, "ToolbarIconText", 
279                         (BonoboUIListenerFn)gl_mdi_view_menu_item_toggled_cb, 
280                         (gpointer)win);
281         bonobo_ui_component_add_listener (ui_component, "ToolbarTooltips", 
282                         (BonoboUIListenerFn)gl_mdi_view_menu_item_toggled_cb, 
283                         (gpointer)win);
284
285
286         gl_menus_set_verb_list_sensitive (ui_component, 
287                                           gl_menus_no_docs_sensible_verbs,
288                                           FALSE);
289
290         /* add a GeditRecentView object */
291         model = gl_recent_get_model ();
292         view = GNOME_RECENT_VIEW (gnome_recent_view_bonobo_new (ui_component,
293                                                                 "/menu/File/Recents"));
294         gnome_recent_view_set_model (view, model);
295         
296         g_signal_connect (G_OBJECT (view), "activate",
297                           G_CALLBACK (gl_file_open_recent), win);
298
299         gl_debug (DEBUG_MDI, "END");
300 }
301
302 /*---------------------------------------------------------------------------*/
303 /* Menu item togglded callback.                                              */
304 /*---------------------------------------------------------------------------*/
305 static void
306 gl_mdi_view_menu_item_toggled_cb (
307                         BonoboUIComponent           *ui_component,
308                         const char                  *path,
309                         Bonobo_UIComponent_EventType type,
310                         const char                  *state,
311                         BonoboWindow                *win)
312 {
313         gboolean s;
314
315         gl_debug (DEBUG_MDI, "%s toggled to '%s'", path, state);
316
317         s = (strcmp (state, "1") == 0);
318
319         if ((strcmp (path, "ViewToolbar") == 0) &&
320             (s != gl_prefs->toolbar_visible))
321         {
322                 gl_prefs->toolbar_visible = s;
323                 gl_mdi_set_app_toolbar_style (win);
324
325                 return;
326         }
327
328         if (s && (strcmp (path, "ToolbarSystem") == 0) &&
329             (gl_prefs->toolbar_buttons_style != GL_TOOLBAR_SYSTEM))
330         {               
331                 gl_prefs->toolbar_buttons_style = GL_TOOLBAR_SYSTEM;
332                 gl_mdi_set_app_toolbar_style (win);
333
334                 return;
335         }
336
337         if (s && (strcmp (path, "ToolbarIcon") == 0) &&
338             (gl_prefs->toolbar_buttons_style != GL_TOOLBAR_ICONS))
339         {               
340                 gl_prefs->toolbar_buttons_style = GL_TOOLBAR_ICONS;
341                 gl_mdi_set_app_toolbar_style (win);
342
343                 return;
344         }
345
346         if (s && (strcmp (path, "ToolbarIconText") == 0) &&
347             (gl_prefs->toolbar_buttons_style != GL_TOOLBAR_ICONS_AND_TEXT))
348         {               
349                 gl_prefs->toolbar_buttons_style = GL_TOOLBAR_ICONS_AND_TEXT;
350                 gl_mdi_set_app_toolbar_style (win);
351
352                 return;
353         }
354
355         if ((strcmp (path, "ToolbarTooltips") == 0) &&
356             (s != gl_prefs->toolbar_view_tooltips))
357         {
358                 gl_prefs->toolbar_view_tooltips = s;
359                 gl_mdi_set_app_toolbar_style (win);
360
361                 return;
362         }
363
364 }
365
366 /*---------------------------------------------------------------------------*/
367 /* Set toolbar style.                                                        */
368 /*---------------------------------------------------------------------------*/
369 static void
370 gl_mdi_set_app_toolbar_style (BonoboWindow *win)
371 {
372         BonoboUIComponent *ui_component;
373         GConfClient *client;
374         gboolean labels;
375
376         gl_debug (DEBUG_MDI, "START");
377         
378         g_return_if_fail (BONOBO_IS_WINDOW (win));
379                         
380         ui_component = bonobo_mdi_get_ui_component_from_window (win);
381         g_return_if_fail (ui_component != NULL);
382                         
383         bonobo_ui_component_freeze (ui_component, NULL);
384
385         /* Updated view menu */
386         gl_menus_set_verb_state (ui_component, 
387                                     "/commands/ViewToolbar",
388                                     gl_prefs->toolbar_visible);
389
390         gl_menus_set_verb_sensitive (ui_component, 
391                                         "/commands/ToolbarSystem",
392                                         gl_prefs->toolbar_visible);
393         gl_menus_set_verb_sensitive (ui_component, 
394                                         "/commands/ToolbarIcon",
395                                         gl_prefs->toolbar_visible);
396         gl_menus_set_verb_sensitive (ui_component, 
397                                         "/commands/ToolbarIconText",
398                                         gl_prefs->toolbar_visible);
399         gl_menus_set_verb_sensitive (ui_component, 
400                                         "/commands/ToolbarTooltips",
401                                         gl_prefs->toolbar_visible);
402
403         gl_menus_set_verb_state (ui_component, 
404                                     "/commands/ToolbarSystem",
405                                     gl_prefs->toolbar_buttons_style == GL_TOOLBAR_SYSTEM);
406
407         gl_menus_set_verb_state (ui_component, 
408                                     "/commands/ToolbarIcon",
409                                     gl_prefs->toolbar_buttons_style == GL_TOOLBAR_ICONS);
410
411         gl_menus_set_verb_state (ui_component, 
412                                     "/commands/ToolbarIconText",
413                                     gl_prefs->toolbar_buttons_style == GL_TOOLBAR_ICONS_AND_TEXT);
414
415         gl_menus_set_verb_state (ui_component, 
416                                     "/commands/ToolbarTooltips",
417                                     gl_prefs->toolbar_view_tooltips);
418
419         
420         /* Actually update toolbar style */
421         bonobo_ui_component_set_prop (
422                 ui_component, "/Toolbar",
423                 "tips", gl_prefs->toolbar_view_tooltips ? "1" : "0",
424                 NULL);
425         
426         switch (gl_prefs->toolbar_buttons_style)
427         {
428                 case GL_TOOLBAR_SYSTEM:
429                                                 
430                         client = gconf_client_get_default ();
431                         if (client == NULL) 
432                                 goto error;
433
434                         labels = gconf_client_get_bool (client, 
435                                         "/desktop/gnome/interface/toolbar-labels", NULL);
436
437                         g_object_unref (G_OBJECT (client));
438                         
439                         if (labels)
440                         {                       
441                                 gl_debug (DEBUG_MDI, "SYSTEM: BOTH");
442                                 bonobo_ui_component_set_prop (
443                                         ui_component, "/Toolbar", "look", "both", NULL);
444                         
445                         }
446                         else
447                         {
448                                 gl_debug (DEBUG_MDI, "SYSTEM: ICONS");
449                                 bonobo_ui_component_set_prop (
450                                         ui_component, "/Toolbar", "look", "icons", NULL);
451                         }
452         
453                         break;
454                         
455                 case GL_TOOLBAR_ICONS:
456                         gl_debug (DEBUG_MDI, "GLABELS: ICONS");
457                         bonobo_ui_component_set_prop (
458                                 ui_component, "/Toolbar", "look", "icon", NULL);
459                         
460                         break;
461                         
462                 case GL_TOOLBAR_ICONS_AND_TEXT:
463                         gl_debug (DEBUG_MDI, "GLABELS: ICONS_AND_TEXT");
464                         bonobo_ui_component_set_prop (
465                                 ui_component, "/Toolbar", "look", "both", NULL);
466                         
467                         break;
468                 default:
469                         goto error;
470                         break;
471         }
472         
473         bonobo_ui_component_set_prop (
474                         ui_component, "/Toolbar",
475                         "hidden", gl_prefs->toolbar_visible ? "0":"1", NULL);
476
477  error:
478         bonobo_ui_component_thaw (ui_component, NULL);
479
480         gl_debug (DEBUG_MDI, "END");
481 }
482
483
484 /*---------------------------------------------------------------------------*/
485 /* Child state changed callback.                                             */
486 /*---------------------------------------------------------------------------*/
487 static void 
488 gl_mdi_child_state_changed_cb (glMDIChild *child)
489 {
490         gl_debug (DEBUG_MDI, "START");
491
492         if (bonobo_mdi_get_active_child (BONOBO_MDI (glabels_mdi)) != BONOBO_MDI_CHILD (child))
493                 return;
494         
495         gl_mdi_set_active_window_title (BONOBO_MDI (glabels_mdi));
496         gl_mdi_set_active_window_verbs_sensitivity (BONOBO_MDI (glabels_mdi));
497
498         gl_debug (DEBUG_MDI, "END");
499 }
500
501 /*---------------------------------------------------------------------------*/
502 /* Child undo/redo state changed callback.                                   */
503 /*---------------------------------------------------------------------------*/
504 static void 
505 gl_mdi_child_undo_redo_state_changed_cb (glMDIChild *child)
506 {
507         gl_debug (DEBUG_MDI, "START");
508
509         if (bonobo_mdi_get_active_child (BONOBO_MDI (glabels_mdi)) != BONOBO_MDI_CHILD (child))
510                 return;
511         
512         gl_mdi_set_active_window_undo_redo_verbs_sensitivity (BONOBO_MDI (glabels_mdi));
513         gl_debug (DEBUG_MDI, "END");
514 }
515
516 /*---------------------------------------------------------------------------*/
517 /* Add child callback.                                                       */
518 /*---------------------------------------------------------------------------*/
519 static gint 
520 gl_mdi_add_child_cb (BonoboMDI *mdi, BonoboMDIChild *child)
521 {
522         gl_debug (DEBUG_MDI, "START");
523
524         g_signal_connect (G_OBJECT (child), "state_changed",
525                           G_CALLBACK (gl_mdi_child_state_changed_cb), 
526                           NULL);
527         g_signal_connect (G_OBJECT (child), "undo_redo_state_changed",
528                           G_CALLBACK (gl_mdi_child_undo_redo_state_changed_cb), 
529                           NULL);
530
531         gl_debug (DEBUG_MDI, "END");
532         return TRUE;
533 }
534
535 /*---------------------------------------------------------------------------*/
536 /* Add view callback.                                                        */
537 /*---------------------------------------------------------------------------*/
538 static gint 
539 gl_mdi_add_view_cb (BonoboMDI *mdi, GtkWidget *view)
540 {
541         gl_debug (DEBUG_MDI, "START");
542         gl_debug (DEBUG_MDI, "END");
543         return TRUE;
544 }
545
546 /*---------------------------------------------------------------------------*/
547 /* Remove child callback.                                                    */
548 /*---------------------------------------------------------------------------*/
549 static gint 
550 gl_mdi_remove_child_cb (BonoboMDI *mdi, BonoboMDIChild *child)
551 {
552         glLabel* doc;
553         gboolean close = TRUE;
554         
555         gl_debug (DEBUG_MDI, "START");
556
557         g_return_val_if_fail (child != NULL, FALSE);
558         g_return_val_if_fail (GL_MDI_CHILD (child)->label != NULL, FALSE);
559
560         doc = GL_MDI_CHILD (child)->label;
561
562         if (gl_label_is_modified (doc))
563         {
564                 GtkWidget *msgbox, *w;
565                 gchar *fname = NULL, *msg = NULL;
566                 gint ret;
567                 gboolean exiting;
568
569                 w = GTK_WIDGET (g_list_nth_data (bonobo_mdi_child_get_views (child), 0));
570                         
571                 if(w != NULL)
572                         bonobo_mdi_set_active_view (mdi, w);
573
574                 fname = gl_label_get_short_name (doc);
575
576                 msg = g_strdup_printf (_("Save changes to document \"%s\" before closing?"),
577                                         fname);
578
579                 msgbox = gl_alert_dialog_new (GTK_WINDOW (bonobo_mdi_get_active_window (mdi)),
580                                 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
581                                 GTK_MESSAGE_WARNING,
582                                 GTK_BUTTONS_NONE,
583                                 msg,
584                                 _("Your changes will be lost if you don't save them."));
585
586                 gtk_dialog_add_button (GTK_DIALOG (msgbox),
587                                        _("Close without saving"),
588                                        GTK_RESPONSE_NO);
589
590                 if (glabels_close_x_button_pressed)
591                         exiting = FALSE;
592                 else if (glabels_exit_button_pressed)
593                         exiting = TRUE;
594                 else
595                 {
596                         /* Delete event generated */
597                         if (g_list_length (bonobo_mdi_get_windows (BONOBO_MDI (glabels_mdi))) == 1)
598                                 exiting = TRUE;
599                         else
600                                 exiting = FALSE;
601                 }
602
603                 
604                 gtk_dialog_add_button (GTK_DIALOG (msgbox), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
605
606                 gtk_dialog_add_button (GTK_DIALOG (msgbox),
607                                 GTK_STOCK_SAVE,
608                                 GTK_RESPONSE_YES);
609
610                 gtk_dialog_set_default_response (GTK_DIALOG (msgbox), GTK_RESPONSE_YES);
611
612                 gtk_window_set_resizable (GTK_WINDOW (msgbox), FALSE);
613
614                 ret = gtk_dialog_run (GTK_DIALOG (msgbox));
615                 
616                 gtk_widget_destroy (msgbox);
617
618                 g_free (fname);
619                 g_free (msg);
620                 
621                 switch (ret)
622                 {
623                         case GTK_RESPONSE_YES:
624                                 close = gl_file_save (GL_MDI_CHILD (child));
625                                 break;
626                         case GTK_RESPONSE_NO:
627                                 close = TRUE;
628                                 break;
629                         default:
630                                 close = FALSE;
631                 }
632
633                 gl_debug (DEBUG_MDI, "CLOSE: %s", close ? "TRUE" : "FALSE");
634         }
635         
636         /* FIXME: there is a bug if you "close all" >1 docs, don't save the document
637          * and then don't close the last one.
638          */
639         /* Disable to avoid the bug */
640         /*
641         if (close)
642         {
643                 g_signal_handlers_disconnect_by_func (child, 
644                                                       G_CALLBACK (gl_mdi_child_state_changed_cb),
645                                                       NULL);
646                 g_signal_handlers_disconnect_by_func (GTK_OBJECT (child), 
647                                                       G_CALLBACK (gl_mdi_child_undo_redo_state_changed_cb),
648                                                       NULL);
649         }
650         */
651         
652         gl_debug (DEBUG_MDI, "END");
653         return close;
654 }
655
656 /*---------------------------------------------------------------------------*/
657 /* Remove view callback.                                                     */
658 /*---------------------------------------------------------------------------*/
659 static gint 
660 gl_mdi_remove_view_cb (BonoboMDI *mdi,  GtkWidget *view)
661 {
662         gl_debug (DEBUG_MDI, "");
663         gl_debug (DEBUG_MDI, "END");
664
665         return TRUE;
666 }
667
668 /*****************************************************************************/
669 /* Set title of active window.                                               */
670 /*****************************************************************************/
671 void 
672 gl_mdi_set_active_window_title (BonoboMDI *mdi)
673 {
674         BonoboMDIChild* active_child = NULL;
675         glLabel* doc = NULL;
676         gchar* docname = NULL;
677         gchar* title = NULL;
678         
679         gl_debug (DEBUG_MDI, "START");
680
681         
682         active_child = bonobo_mdi_get_active_child (mdi);
683         if (active_child == NULL)
684                 return;
685
686         doc = GL_MDI_CHILD (active_child)->label;
687         g_return_if_fail (doc != NULL);
688         
689         /* Set active window title */
690         docname = gl_label_get_short_name (doc);
691         g_return_if_fail (docname != NULL);
692
693         if (gl_label_is_modified (doc))
694         {
695                 title = g_strdup_printf ("%s %s - glabels",
696                                          docname, _("(modified)"));
697         } 
698         else 
699         {
700                 title = g_strdup_printf ("%s - glabels", docname);
701
702         }
703
704         gtk_window_set_title (GTK_WINDOW (bonobo_mdi_get_active_window (mdi)), title);
705         
706         g_free (docname);
707         g_free (title);
708
709         gl_debug (DEBUG_MDI, "END");
710 }
711
712 /*---------------------------------------------------------------------------*/
713 /* Child changed callback.                                                   */
714 /*---------------------------------------------------------------------------*/
715 static 
716 void gl_mdi_child_changed_cb (BonoboMDI *mdi, BonoboMDIChild *old_child)
717 {
718         gl_debug (DEBUG_MDI, "START");
719
720         gl_mdi_set_active_window_title (mdi);   
721
722         gl_debug (DEBUG_MDI, "END");
723 }
724
725 /*---------------------------------------------------------------------------*/
726 /* View changed callback.                                                    */
727 /*---------------------------------------------------------------------------*/
728 static 
729 void gl_mdi_view_changed_cb (BonoboMDI *mdi, GtkWidget *old_view)
730 {
731         BonoboWindow *win;
732         GtkWidget* status;
733         GtkWidget *active_view;
734         
735         gl_debug (DEBUG_MDI, "START");
736
737         gl_mdi_set_active_window_verbs_sensitivity (mdi);
738
739         active_view = bonobo_mdi_get_active_view (mdi);
740                 
741         win = bonobo_mdi_get_active_window (mdi);
742         g_return_if_fail (win != NULL);
743
744         gl_debug (DEBUG_MDI, "END");
745 }
746
747 /*****************************************************************************/
748 /* Set sensitivity of verbs in active window.                                */
749 /*****************************************************************************/
750 void 
751 gl_mdi_set_active_window_verbs_sensitivity (BonoboMDI *mdi)
752 {
753         /* FIXME: it is too slooooooow! - Paolo */
754
755         BonoboWindow* active_window = NULL;
756         BonoboMDIChild* active_child = NULL;
757         glLabel* doc = NULL;
758         BonoboUIComponent *ui_component;
759         
760         gl_debug (DEBUG_MDI, "START");
761         
762         active_window = bonobo_mdi_get_active_window (mdi);
763
764         if (active_window == NULL)
765                 return;
766         
767         ui_component = bonobo_mdi_get_ui_component_from_window (active_window);
768         g_return_if_fail (ui_component != NULL);
769         
770         active_child = bonobo_mdi_get_active_child (mdi);
771         
772         bonobo_ui_component_freeze (ui_component, NULL);
773         
774         if (active_child == NULL)
775         {
776                 gl_menus_set_verb_list_sensitive (ui_component, 
777                                 gl_menus_no_docs_sensible_verbs, FALSE);
778                 goto end;
779         }
780         else
781         {
782                 gl_menus_set_verb_list_sensitive (ui_component, 
783                                 gl_menus_all_sensible_verbs, TRUE);
784         }
785
786         doc = GL_MDI_CHILD (active_child)->label;
787         g_return_if_fail (doc != NULL);
788
789         if (!gl_label_can_undo (doc))
790                 gl_menus_set_verb_sensitive (ui_component,
791                                              "/commands/EditUndo", FALSE);
792
793         if (!gl_label_can_redo (doc))
794                 gl_menus_set_verb_sensitive (ui_component,
795                                              "/commands/EditRedo", FALSE);
796
797         if (!gl_label_is_modified (doc))
798         {
799                 gl_menus_set_verb_list_sensitive (ui_component, 
800                                 gl_menus_not_modified_doc_sensible_verbs,
801                                                   FALSE);
802                 goto end;
803         }
804
805 end:
806         bonobo_ui_component_thaw (ui_component, NULL);
807
808         gl_debug (DEBUG_MDI, "END");
809 }
810
811
812 /*****************************************************************************/
813 /* Set sensitivity of undo/redo verbs in active window.                      */
814 /*****************************************************************************/
815 static void 
816 gl_mdi_set_active_window_undo_redo_verbs_sensitivity (BonoboMDI *mdi)
817 {
818         BonoboWindow* active_window = NULL;
819         BonoboMDIChild* active_child = NULL;
820         glLabel* doc = NULL;
821         BonoboUIComponent *ui_component;
822         
823         gl_debug (DEBUG_MDI, "START");
824         
825         active_window = bonobo_mdi_get_active_window (mdi);
826         g_return_if_fail (active_window != NULL);
827         
828         ui_component = bonobo_mdi_get_ui_component_from_window (active_window);
829         g_return_if_fail (ui_component != NULL);
830         
831         active_child = bonobo_mdi_get_active_child (mdi);
832         doc = GL_MDI_CHILD (active_child)->label;
833         g_return_if_fail (doc != NULL);
834
835         bonobo_ui_component_freeze (ui_component, NULL);
836
837         gl_menus_set_verb_sensitive (ui_component, "/commands/EditUndo", 
838                         gl_label_can_undo (doc));       
839
840         gl_menus_set_verb_sensitive (ui_component, "/commands/EditRedo", 
841                         gl_label_can_redo (doc));       
842
843         bonobo_ui_component_thaw (ui_component, NULL);
844
845         gl_debug (DEBUG_MDI, "END");
846 }
847