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