~jjardon/glade/master

« back to all changes in this revision

Viewing changes to src/glade-window.c

  • Committer: Juan Pablo Ugarte
  • Date: 2012-04-27 03:04:25 UTC
  • Revision ID: git-v1:cb69ca99441aa2c7840136e9fedfc65b4c9b214a
Implemented Glade UI in Glade, side effect status bar started working again

src/glade-window.c:
 Use GtkBuilder and GResources to build GladeWindow contents
 Implemented menu with GtkActions
 Push tooltip for rencet manager and project actions

src/main.c: Register glade GResources

src/glade-resources.gresources.xml: Glade Gresource file

src/glade.glade: Glade UI GladeWindow, about and preferences dialog

src/glade-callbacks.h: callbacks declarations

src/Makefile.am: added glade-resource.c to source list

configure.ac:
 bumped version to 3.13
 added glib-compile-resources path program

glade-rules.mk: added common rules for GResources files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (C) 2001 Ximian, Inc.
3
3
 * Copyright (C) 2007 Vincent Geddes.
 
4
 * Copyright (C) 2012 Juan Pablo Ugarte.
4
5
 *
5
6
 * This program is free software; you can redistribute it and/or modify
6
7
 * it under the terms of the GNU General Public License as
20
21
 *   Chema Celorio <chema@celorio.com>
21
22
 *   Paolo Borelli <pborelli@katamail.com>
22
23
 *   Vincent Geddes <vgeddes@gnome.org>
 
24
 *   Juan Pablo Ugarte <juanpablougarte@gmail.com>
23
25
 */
24
26
 
25
27
#include <config.h>
26
28
 
27
29
#include "glade-window.h"
28
30
#include "glade-close-button.h"
 
31
#include "glade-resources.h"
 
32
#include "glade-callbacks.h"
29
33
 
30
34
#include <gladeui/glade.h>
31
 
#include <gladeui/glade-design-view.h>
32
35
#include <gladeui/glade-popup.h>
33
36
#include <gladeui/glade-inspector.h>
34
37
 
100
103
  GladeDesignView *active_view;
101
104
  gint num_tabs;
102
105
 
 
106
  GtkWindow *about_dialog;
 
107
  GtkWindow *preferences_dialog;
 
108
  
103
109
  GtkWidget *palettes_notebook;         /* Cached per project palettes */
104
110
  GtkWidget *inspectors_notebook;       /* Cached per project inspectors */
105
111
 
109
115
  guint statusbar_menu_context_id;      /* The context id of the menu bar */
110
116
  guint statusbar_actions_context_id;   /* The context id of actions messages */
111
117
 
112
 
  GtkUIManager *ui;                     /* The UIManager */
113
 
  guint projects_list_menu_ui_id;       /* Merge id for projects list menu */
 
118
  GtkAccelGroup *accelgroup;
 
119
  
 
120
  struct
 
121
        {
 
122
          GtkAction *save, *quit;
 
123
          GtkAction *undo, *redo, *cut, *copy, *paste, *delete;
 
124
          GtkAction *previous_project, *next_project;
 
125
          GtkAction *use_small_icons, *icons_and_labels;
 
126
          GtkAction *toolbar_visible, *project_tabs_visible, *statusbar_visible;
 
127
          GtkAction *selector;
 
128
        } action;
114
129
 
115
 
  GtkActionGroup *static_actions;       /* All the static actions */
116
130
  GtkActionGroup *project_actions;      /* All the project actions */
 
131
  GtkActionGroup *pointer_mode_actions;
117
132
  GtkActionGroup *projects_list_menu_actions;   /* Projects list menu actions */
118
133
 
 
134
  GtkMenuShell *project_menu;
 
135
  
119
136
  GtkRecentManager *recent_manager;
120
137
  GtkWidget *recent_menu;
121
138
 
122
139
  gchar *default_path;          /* the default path for open/save operations */
123
140
 
124
 
  GtkToggleToolButton *selector_button; /* the widget selector button (replaces the one in the palette) */
125
 
  GtkToggleToolButton *drag_resize_button;      /* sets the pointer to drag/resize mode */
126
 
  GtkToggleToolButton *margin_edit_button;      /* sets the pointer to margin edit mode */
127
 
  GtkToggleToolButton *align_edit_button;      /* sets the pointer to margin edit mode */
128
 
 
129
141
  GtkToolItem *undo;            /* customized buttons for undo/redo with history */
130
142
  GtkToolItem *redo;
131
143
 
141
153
  ToolDock docks[N_DOCKS];
142
154
};
143
155
 
144
 
static void refresh_undo_redo (GladeWindow *window, GladeProject *project);
145
 
 
146
 
static void recent_chooser_item_activated_cb (GtkRecentChooser * chooser,
147
 
                                              GladeWindow * window);
148
 
 
149
156
static void check_reload_project (GladeWindow * window, GladeProject * project);
150
157
 
151
 
static void glade_window_config_save (GladeWindow * window);
152
 
 
153
 
 
154
158
G_DEFINE_TYPE (GladeWindow, glade_window, GTK_TYPE_WINDOW)
155
159
 
156
160
/* the following functions are taken from gedit-utils.c */
157
 
static gchar *str_middle_truncate (const gchar * string,
158
 
                                   guint truncate_length)
 
161
static gchar *
 
162
str_middle_truncate (const gchar *string, guint truncate_length)
159
163
{
160
164
  GString *truncated;
161
165
  guint length;
207
211
 * Doubles underscore to avoid spurious menu accels - taken from gedit-utils.c
208
212
 */
209
213
static gchar *
210
 
escape_underscores (const gchar * text, gssize length)
 
214
escape_underscores (const gchar *text, gssize length)
211
215
{
212
216
  GString *str;
213
217
  const gchar *p;
254
258
#define MAX_TITLE_LENGTH 100
255
259
 
256
260
static gchar *
257
 
get_formatted_project_name_for_display (GladeProject * project,
 
261
get_formatted_project_name_for_display (GladeProject *project,
258
262
                                        FormatNameFlags format_flags)
259
263
{
260
264
  gchar *name, *pass1, *pass2, *pass3;
288
292
 
289
293
 
290
294
static void
291
 
refresh_title (GladeWindow * window)
 
295
refresh_title (GladeWindow *window)
292
296
{
293
297
  GladeProject *project;
294
298
  gchar *title, *name = NULL;
319
323
}
320
324
 
321
325
static const gchar *
322
 
get_default_path (GladeWindow * window)
 
326
get_default_path (GladeWindow *window)
323
327
{
324
328
  return window->priv->default_path;
325
329
}
326
330
 
327
331
static void
328
 
update_default_path (GladeWindow * window, const gchar * filename)
 
332
update_default_path (GladeWindow *window, const gchar *filename)
329
333
{
330
334
  gchar *path;
331
335
 
339
343
  g_free (path);
340
344
}
341
345
 
342
 
static GtkWidget *
343
 
create_recent_chooser_menu (GladeWindow * window, GtkRecentManager * manager)
344
 
{
345
 
  GtkWidget *recent_menu;
346
 
  GtkRecentFilter *filter;
347
 
 
348
 
  recent_menu = gtk_recent_chooser_menu_new_for_manager (manager);
349
 
 
350
 
  gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (recent_menu), TRUE);
351
 
  gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (recent_menu), FALSE);
352
 
  gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recent_menu),
353
 
                                    GTK_RECENT_SORT_MRU);
354
 
  gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU
355
 
                                            (recent_menu), TRUE);
356
 
 
357
 
  filter = gtk_recent_filter_new ();
358
 
  gtk_recent_filter_add_application (filter, g_get_application_name ());
359
 
  gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (recent_menu), filter);
360
 
 
361
 
  return recent_menu;
362
 
}
363
 
 
364
346
static void
365
 
activate_action (GtkToolButton * toolbutton, GladeWidgetAction * action)
 
347
activate_action (GtkToolButton *toolbutton, GladeWidgetAction *action)
366
348
{
367
349
  GladeWidget   *widget;
368
350
  GWActionClass *aclass = glade_widget_action_get_class (action);
374
356
}
375
357
 
376
358
static void
377
 
action_notify_sensitive (GObject * gobject, GParamSpec * arg1, GtkWidget * item)
 
359
action_notify_sensitive (GObject *gobject, GParamSpec *arg1, GtkWidget *item)
378
360
{
379
361
  GladeWidgetAction *action = GLADE_WIDGET_ACTION (gobject);
380
362
  gtk_widget_set_sensitive (item, glade_widget_action_get_sensitive (action));
381
363
}
382
364
 
383
365
static void
384
 
action_disconnect (gpointer data, GClosure * closure)
 
366
action_disconnect (gpointer data, GClosure *closure)
385
367
{
386
368
  g_signal_handlers_disconnect_matched (data, G_SIGNAL_MATCH_FUNC,
387
369
                                        0, 0, NULL,
389
371
}
390
372
 
391
373
static void
392
 
clean_actions (GladeWindow * window)
 
374
clean_actions (GladeWindow *window)
393
375
{
394
376
  GtkContainer *container = GTK_CONTAINER (window->priv->toolbar);
395
377
  GtkToolbar *bar = GTK_TOOLBAR (window->priv->toolbar);
404
386
}
405
387
 
406
388
static void
407
 
add_actions (GladeWindow * window, GladeWidget * widget, GList * actions)
 
389
add_actions (GladeWindow *window, GladeWidget *widget, GList *actions)
408
390
{
409
391
  GtkToolbar *bar = GTK_TOOLBAR (window->priv->toolbar);
410
392
  GtkToolItem *item = gtk_separator_tool_item_new ();
474
456
}
475
457
 
476
458
static void
477
 
project_selection_changed_cb (GladeProject * project, GladeWindow * window)
 
459
project_selection_changed_cb (GladeProject *project, GladeWindow *window)
478
460
{
479
461
  GladeProject *active_project;
480
462
  GladeWidget  *glade_widget = NULL;
510
492
}
511
493
 
512
494
static GladeDesignView *
513
 
get_active_view (GladeWindow * window)
 
495
get_active_view (GladeWindow *window)
514
496
{
515
497
  g_return_val_if_fail (GLADE_IS_WINDOW (window), NULL);
516
498
 
518
500
}
519
501
 
520
502
static gchar *
521
 
format_project_list_item_tooltip (GladeProject * project)
 
503
format_project_list_item_tooltip (GladeProject *project)
522
504
{
523
505
  gchar *tooltip, *path, *name;
524
506
 
555
537
}
556
538
 
557
539
static void
558
 
refresh_notebook_tab_for_project (GladeWindow * window, GladeProject * project)
 
540
refresh_notebook_tab_for_project (GladeWindow *window, GladeProject *project)
559
541
{
560
542
  GtkWidget *tab_label, *label, *view, *eventbox;
561
543
  GList *children, *l;
613
595
}
614
596
 
615
597
static void
616
 
project_targets_changed_cb (GladeProject * project, GladeWindow * window)
 
598
project_targets_changed_cb (GladeProject *project, GladeWindow *window)
617
599
{
618
600
  refresh_notebook_tab_for_project (window, project);
619
601
}
620
602
 
621
603
static void
 
604
change_menu_label (GtkAction *action,
 
605
                   const gchar *action_label,
 
606
                   const gchar *action_description)
 
607
{
 
608
  gchar *text, *tmp_text;
 
609
 
 
610
  g_return_if_fail (action_label != NULL);
 
611
 
 
612
  if (action_description == NULL)
 
613
    text = g_strdup (action_label);
 
614
  else
 
615
    {
 
616
      tmp_text = escape_underscores (action_description, -1);
 
617
      text = g_strdup_printf ("%s: %s", action_label, tmp_text);
 
618
      g_free (tmp_text);
 
619
    }
 
620
 
 
621
  gtk_action_set_label (action, text);
 
622
 
 
623
  g_free (text);
 
624
}
 
625
 
 
626
static void
 
627
refresh_undo_redo (GladeWindow *window, GladeProject *project)
 
628
{
 
629
  GladeCommand *undo = NULL, *redo = NULL;
 
630
  GladeWindowPrivate *priv = window->priv;
 
631
  gchar        *tooltip;
 
632
 
 
633
  if (project != NULL)
 
634
    {
 
635
      undo = glade_project_next_undo_item (project);
 
636
      redo = glade_project_next_redo_item (project);
 
637
    }
 
638
 
 
639
  /* Refresh Undo */
 
640
  gtk_action_set_sensitive (priv->action.undo, undo != NULL);
 
641
 
 
642
  change_menu_label (priv->action.undo, _("_Undo"),
 
643
                     undo ? glade_command_description (undo) : NULL);
 
644
 
 
645
  tooltip = g_strdup_printf (_("Undo: %s"),
 
646
                             undo ? glade_command_description (undo) : _("the last action"));
 
647
  g_object_set (priv->action.undo, "tooltip", tooltip, NULL);
 
648
  g_free (tooltip);
 
649
 
 
650
  /* Refresh Redo */
 
651
  gtk_action_set_sensitive (priv->action.redo, redo != NULL);
 
652
 
 
653
  change_menu_label (priv->action.redo, _("_Redo"),
 
654
                     redo ? glade_command_description (redo) : NULL);
 
655
 
 
656
  tooltip = g_strdup_printf (_("Redo: %s"),
 
657
                             redo ? glade_command_description (redo) : _("the last action"));
 
658
  g_object_set (priv->action.redo, "tooltip", tooltip, NULL);
 
659
  g_free (tooltip);
 
660
 
 
661
  /* Refresh menus */
 
662
  gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (priv->undo),
 
663
                                 glade_project_undo_items (project));
 
664
  gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (priv->redo),
 
665
                                 glade_project_redo_items (project));
 
666
}
 
667
 
 
668
static void
622
669
project_changed_cb (GladeProject *project, 
623
 
                    GladeCommand *command,
624
 
                    gboolean      execute,
625
 
                    GladeWindow  *window)
 
670
                    GladeCommand *command,
 
671
                    gboolean      execute,
 
672
                    GladeWindow  *window)
626
673
{
627
674
  GladeProject *active_project = get_active_project (window);
628
675
  
631
678
}
632
679
 
633
680
static void
634
 
refresh_projects_list_item (GladeWindow * window, GladeProject * project)
 
681
refresh_projects_list_item (GladeWindow *window, GladeProject *project)
635
682
{
636
683
  GtkAction *action;
637
684
  gchar *project_name;
661
708
}
662
709
 
663
710
static void
664
 
refresh_next_prev_project_sensitivity (GladeWindow * window)
 
711
refresh_next_prev_project_sensitivity (GladeWindow *window)
665
712
{
666
 
  GladeDesignView *view;
667
 
  GtkAction *action;
668
 
  gint view_number;
669
 
 
670
 
  view = get_active_view (window);
 
713
  GladeDesignView *view = get_active_view (window);
 
714
  GladeWindowPrivate *priv = window->priv;
671
715
 
672
716
  if (view != NULL)
673
717
    {
674
 
      view_number =
675
 
          gtk_notebook_page_num (GTK_NOTEBOOK (window->priv->notebook),
676
 
                                 GTK_WIDGET (view));
 
718
      gint view_number = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
 
719
                                                GTK_WIDGET (view));
677
720
      g_return_if_fail (view_number >= 0);
678
721
 
679
 
      action =
680
 
          gtk_action_group_get_action (window->priv->project_actions,
681
 
                                       "PreviousProject");
682
 
      gtk_action_set_sensitive (action, view_number != 0);
 
722
      gtk_action_set_sensitive (priv->action.previous_project, view_number != 0);
683
723
 
684
 
      action =
685
 
          gtk_action_group_get_action (window->priv->project_actions,
686
 
                                       "NextProject");
687
 
      gtk_action_set_sensitive (action,
 
724
      gtk_action_set_sensitive (priv->action.next_project,
688
725
                                view_number <
689
726
                                gtk_notebook_get_n_pages (GTK_NOTEBOOK
690
 
                                                          (window->priv->
691
 
                                                           notebook)) - 1);
 
727
                                                          (priv->notebook)) - 1);
692
728
    }
693
729
  else
694
730
    {
695
 
      action =
696
 
          gtk_action_group_get_action (window->priv->project_actions,
697
 
                                       "PreviousProject");
698
 
      gtk_action_set_sensitive (action, FALSE);
699
 
 
700
 
      action =
701
 
          gtk_action_group_get_action (window->priv->project_actions,
702
 
                                       "NextProject");
703
 
      gtk_action_set_sensitive (action, FALSE);
 
731
      gtk_action_set_sensitive (priv->action.previous_project, FALSE);
 
732
      gtk_action_set_sensitive (priv->action.next_project, FALSE);
704
733
    }
705
734
}
706
735
 
707
736
static void
708
 
new_cb (GtkAction * action, GladeWindow * window)
709
 
{
710
 
  glade_window_new_project (window);
711
 
}
712
 
 
713
 
static void
714
 
project_notify_handler_cb (GladeProject * project, GParamSpec * spec,
715
 
                           GladeWindow * window)
 
737
project_notify_handler_cb (GladeProject *project,
 
738
                           GParamSpec *spec,
 
739
                           GladeWindow *window)
716
740
{
717
741
  GladeProject *active_project = get_active_project (window);
718
 
  GtkAction    *action;
 
742
  GladeWindowPrivate *priv = window->priv;
719
743
 
720
744
  if (strcmp (spec->name, "path") == 0)
721
745
    {
736
760
    {
737
761
      refresh_notebook_tab_for_project (window, project);
738
762
 
739
 
      action =
740
 
          gtk_action_group_get_action (window->priv->project_actions, "Save");
741
 
      gtk_action_set_sensitive (action, !glade_project_get_readonly (project));
 
763
      gtk_action_set_sensitive (priv->action.save, !glade_project_get_readonly (project));
742
764
    }
743
765
  else if (strcmp (spec->name, "has-selection") == 0 && (project == active_project))
744
766
    {
745
 
      action =
746
 
          gtk_action_group_get_action (window->priv->project_actions, "Cut");
747
 
      gtk_action_set_sensitive (action,
748
 
                                glade_project_get_has_selection (project));
749
 
 
750
 
      action =
751
 
          gtk_action_group_get_action (window->priv->project_actions, "Copy");
752
 
      gtk_action_set_sensitive (action,
753
 
                                glade_project_get_has_selection (project));
754
 
 
755
 
      action =
756
 
          gtk_action_group_get_action (window->priv->project_actions, "Delete");
757
 
      gtk_action_set_sensitive (action,
 
767
      gtk_action_set_sensitive (priv->action.cut,
 
768
                                glade_project_get_has_selection (project));
 
769
      gtk_action_set_sensitive (priv->action.copy,
 
770
                                glade_project_get_has_selection (project));
 
771
      gtk_action_set_sensitive (priv->action.delete,
758
772
                                glade_project_get_has_selection (project));
759
773
    }
760
774
}
761
775
 
762
776
static void
763
 
clipboard_notify_handler_cb (GladeClipboard * clipboard, GParamSpec * spec,
 
777
clipboard_notify_handler_cb (GladeClipboard *clipboard,
 
778
                             GParamSpec *spec,
764
779
                             GladeWindow * window)
765
780
{
766
 
  GtkAction *action;
767
 
 
768
781
  if (strcmp (spec->name, "has-selection") == 0)
769
782
    {
770
 
      action =
771
 
          gtk_action_group_get_action (window->priv->project_actions, "Paste");
772
 
      gtk_action_set_sensitive (action,
 
783
      gtk_action_set_sensitive (window->priv->action.paste,
773
784
                                glade_clipboard_get_has_selection (clipboard));
774
785
    }
775
786
}
776
787
 
777
788
static void
778
789
on_pointer_mode_changed (GladeProject *project,
779
 
                         GParamSpec   *pspec, 
780
 
                         GladeWindow  *window)
 
790
                         GParamSpec   *pspec,
 
791
                         GladeWindow  *window)
781
792
{
782
793
  GladeProject *active_project = get_active_project (window);
783
794
  GladeWindowPrivate *priv = window->priv;
784
 
 
 
795
  GladePointerMode mode;
 
796
  
785
797
  if (!active_project)
786
798
    {
787
 
      gtk_widget_set_sensitive (GTK_WIDGET (priv->selector_button), FALSE);
 
799
      gtk_action_group_set_sensitive (priv->pointer_mode_actions, FALSE);
788
800
      return;
789
801
    }
790
802
  else if (active_project != project)
791
803
    return;
792
804
 
793
 
  gtk_widget_set_sensitive (GTK_WIDGET (priv->selector_button), TRUE);
 
805
  mode = glade_project_get_pointer_mode (project);
 
806
  if (mode == GLADE_POINTER_ADD_WIDGET) return;
794
807
 
795
 
  switch (glade_project_get_pointer_mode (project))
796
 
    {
797
 
      case GLADE_POINTER_SELECT:
798
 
        glade_project_set_add_item (active_project, NULL);
799
 
        gtk_toggle_tool_button_set_active (priv->selector_button, TRUE);
800
 
      break;
801
 
      case GLADE_POINTER_DRAG_RESIZE:
802
 
        gtk_toggle_tool_button_set_active (priv->drag_resize_button, TRUE);
803
 
      break;
804
 
      case GLADE_POINTER_MARGIN_EDIT:
805
 
        gtk_toggle_tool_button_set_active (priv->margin_edit_button, TRUE);
806
 
      break;
807
 
      case GLADE_POINTER_ALIGN_EDIT:
808
 
        gtk_toggle_tool_button_set_active (priv->align_edit_button, TRUE);
809
 
      break;
810
 
      default:
811
 
        gtk_toggle_tool_button_set_active (priv->selector_button, FALSE);
812
 
      break;
813
 
    }
 
808
  gtk_action_group_set_sensitive (priv->pointer_mode_actions, TRUE);
 
809
  gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action.selector),
 
810
                                      mode);
814
811
}
815
812
 
816
813
static void
817
814
set_sensitivity_according_to_project (GladeWindow  *window,
818
815
                                      GladeProject *project)
819
816
{
820
 
  GtkAction *action;
821
 
 
822
 
  action = gtk_action_group_get_action (window->priv->project_actions, "Save");
823
 
  gtk_action_set_sensitive (action, !glade_project_get_readonly (project));
824
 
 
825
 
  action = gtk_action_group_get_action (window->priv->project_actions, "Cut");
826
 
  gtk_action_set_sensitive (action, glade_project_get_has_selection (project));
827
 
 
828
 
  action = gtk_action_group_get_action (window->priv->project_actions, "Copy");
829
 
  gtk_action_set_sensitive (action, glade_project_get_has_selection (project));
830
 
 
831
 
  action = gtk_action_group_get_action (window->priv->project_actions, "Paste");
832
 
  gtk_action_set_sensitive (action,
 
817
  GladeWindowPrivate *priv = window->priv;
 
818
 
 
819
  gtk_action_set_sensitive (priv->action.save, !glade_project_get_readonly (project));
 
820
 
 
821
  gtk_action_set_sensitive (priv->action.cut, glade_project_get_has_selection (project));
 
822
 
 
823
  gtk_action_set_sensitive (priv->action.copy, glade_project_get_has_selection (project));
 
824
 
 
825
  gtk_action_set_sensitive (priv->action.paste,
833
826
                            glade_clipboard_get_has_selection
834
827
                            (glade_app_get_clipboard ()));
835
828
 
836
 
  action =
837
 
      gtk_action_group_get_action (window->priv->project_actions, "Delete");
838
 
  gtk_action_set_sensitive (action, glade_project_get_has_selection (project));
 
829
  gtk_action_set_sensitive (priv->action.delete, glade_project_get_has_selection (project));
839
830
 
840
831
  refresh_next_prev_project_sensitivity (window);
841
 
 
842
832
}
843
833
 
844
834
static void
845
 
recent_add (GladeWindow * window, const gchar * path)
 
835
recent_add (GladeWindow *window, const gchar *path)
846
836
{
847
837
  GtkRecentData *recent_data;
848
838
  gchar *uri;
897
887
 *
898
888
 */
899
889
static void
900
 
switch_to_project (GladeWindow * window, GladeProject * project)
 
890
switch_to_project (GladeWindow *window, GladeProject *project)
901
891
{
902
892
  GladeWindowPrivate *priv = window->priv;
903
893
  guint i, n = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
924
914
}
925
915
 
926
916
static void
927
 
projects_list_menu_activate_cb (GtkAction * action, GladeWindow * window)
 
917
projects_list_menu_activate_cb (GtkAction *action, GladeWindow *window)
928
918
{
929
 
  gint n;
930
 
 
931
919
  if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) == FALSE)
932
920
    return;
933
921
 
934
 
  n = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
935
 
  gtk_notebook_set_current_page (GTK_NOTEBOOK (window->priv->notebook), n);
 
922
  gtk_notebook_set_current_page (GTK_NOTEBOOK (window->priv->notebook),
 
923
                                 gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)));
936
924
}
937
925
 
938
926
static void
939
 
refresh_projects_list_menu (GladeWindow * window)
 
927
refresh_projects_list_menu (GladeWindow *window)
940
928
{
941
 
  GladeWindowPrivate *p = window->priv;
 
929
  GladeWindowPrivate *priv = window->priv;
942
930
  GList *actions, *l;
943
931
  GSList *group = NULL;
944
932
  gint n, i;
945
 
  guint id;
946
 
 
947
 
  if (p->projects_list_menu_ui_id != 0)
948
 
    gtk_ui_manager_remove_ui (p->ui, p->projects_list_menu_ui_id);
949
933
 
950
934
  /* Remove all current actions */
951
 
  actions = gtk_action_group_list_actions (p->projects_list_menu_actions);
 
935
  actions = gtk_action_group_list_actions (priv->projects_list_menu_actions);
952
936
  for (l = actions; l != NULL; l = l->next)
953
937
    {
954
 
      g_signal_handlers_disconnect_by_func (GTK_ACTION (l->data),
955
 
                                            G_CALLBACK
956
 
                                            (projects_list_menu_activate_cb),
 
938
      GtkAction *action = l->data;
 
939
      GSList *p, *proxies = gtk_action_get_proxies (action);
 
940
 
 
941
      /* Remove MenuItems */
 
942
      for (p = proxies; p; p = g_slist_next (p))
 
943
        if (GTK_IS_MENU_ITEM (p->data)) gtk_widget_destroy (p->data);
 
944
 
 
945
      g_signal_handlers_disconnect_by_func (action,
 
946
                                            G_CALLBACK (projects_list_menu_activate_cb),
957
947
                                            window);
958
 
      gtk_action_group_remove_action (p->projects_list_menu_actions,
959
 
                                      GTK_ACTION (l->data));
 
948
      gtk_action_group_remove_action (priv->projects_list_menu_actions, action);
960
949
    }
961
950
  g_list_free (actions);
962
951
 
963
 
  n = gtk_notebook_get_n_pages (GTK_NOTEBOOK (p->notebook));
964
 
 
965
 
  id = (n > 0) ? gtk_ui_manager_new_merge_id (p->ui) : 0;
 
952
  n = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
966
953
 
967
954
  /* Add an action for each project */
968
955
  for (i = 0; i < n; i++)
969
956
    {
970
 
      GtkWidget *view;
 
957
      GtkWidget *view, *item;
971
958
      GladeProject *project;
972
959
      GtkRadioAction *action;
973
960
      gchar action_name[32];
975
962
      gchar *tooltip;
976
963
      gchar accel[7];
977
964
 
978
 
      view = gtk_notebook_get_nth_page (GTK_NOTEBOOK (p->notebook), i);
 
965
      view = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), i);
979
966
      project = glade_design_view_get_project (GLADE_DESIGN_VIEW (view));
980
967
 
981
968
 
1012
999
      gtk_radio_action_set_group (action, group);
1013
1000
      group = gtk_radio_action_get_group (action);
1014
1001
 
1015
 
      gtk_action_group_add_action_with_accel (p->projects_list_menu_actions,
 
1002
      gtk_action_group_add_action_with_accel (priv->projects_list_menu_actions,
1016
1003
                                              GTK_ACTION (action), accel);
1017
1004
 
 
1005
      /* Create Menu Item*/
 
1006
      item = gtk_check_menu_item_new ();
 
1007
      gtk_menu_shell_append (priv->project_menu, item);
 
1008
      gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (item), TRUE);
 
1009
      gtk_activatable_set_related_action (GTK_ACTIVATABLE (item), GTK_ACTION (action));
 
1010
      gtk_widget_show (item);
 
1011
 
1018
1012
      g_signal_connect (action, "activate",
1019
1013
                        G_CALLBACK (projects_list_menu_activate_cb), window);
1020
1014
 
1021
 
      gtk_ui_manager_add_ui (p->ui, id,
1022
 
                             "/MenuBar/ProjectMenu/ProjectsListPlaceholder",
1023
 
                             action_name, action_name,
1024
 
                             GTK_UI_MANAGER_MENUITEM, FALSE);
1025
 
 
1026
 
      if (GLADE_DESIGN_VIEW (view) == p->active_view)
 
1015
      if (GLADE_DESIGN_VIEW (view) == priv->active_view)
1027
1016
        gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
1028
1017
 
1029
1018
      g_object_unref (action);
1031
1020
      g_free (project_name);
1032
1021
      g_free (tooltip);
1033
1022
    }
1034
 
 
1035
 
  p->projects_list_menu_ui_id = id;
1036
1023
}
1037
1024
 
1038
 
static void
1039
 
open_cb (GtkAction * action, GladeWindow * window)
 
1025
void
 
1026
on_open_action_activate (GtkAction *action, GladeWindow *window)
1040
1027
{
1041
1028
  GtkWidget *filechooser;
1042
1029
  gchar *path = NULL, *default_path;
1067
1054
}
1068
1055
 
1069
1056
static gboolean
1070
 
check_loading_project_for_save (GladeProject * project)
 
1057
check_loading_project_for_save (GladeProject *project)
1071
1058
{
1072
1059
  if (glade_project_is_loading (project))
1073
1060
    {
1083
1070
}
1084
1071
 
1085
1072
static void
1086
 
save (GladeWindow * window, GladeProject * project, const gchar * path)
 
1073
save (GladeWindow *window, GladeProject *project, const gchar *path)
1087
1074
{
1088
1075
  GError *error = NULL;
1089
1076
  gchar *display_name, *display_path = g_strdup (path);
1181
1168
}
1182
1169
 
1183
1170
static void
1184
 
save_as (GladeWindow * window)
 
1171
save_as (GladeWindow *window)
1185
1172
{
1186
1173
  GladeProject *project, *another_project;
1187
1174
  GtkWidget *filechooser;
1285
1272
  g_free (real_path);
1286
1273
}
1287
1274
 
1288
 
static void
1289
 
save_cb (GtkAction * action, GladeWindow * window)
 
1275
void
 
1276
on_save_action_activate (GtkAction *action, GladeWindow *window)
1290
1277
{
1291
1278
  GladeProject *project;
1292
1279
 
1310
1297
  save_as (window);
1311
1298
}
1312
1299
 
1313
 
static void
1314
 
save_as_cb (GtkAction * action, GladeWindow * window)
 
1300
void
 
1301
on_save_as_action_activate (GtkAction *action, GladeWindow *window)
1315
1302
{
1316
1303
  save_as (window);
1317
1304
}
1318
1305
 
1319
1306
static gboolean
1320
 
confirm_close_project (GladeWindow * window, GladeProject * project)
 
1307
confirm_close_project (GladeWindow *window, GladeProject *project)
1321
1308
{
1322
1309
  GtkWidget *dialog;
1323
1310
  gboolean close = FALSE;
1433
1420
}
1434
1421
 
1435
1422
static void
1436
 
do_close (GladeWindow * window, GladeProject * project)
 
1423
do_close (GladeWindow *window, GladeProject *project)
1437
1424
{
1438
1425
  GladeDesignView *view;
1439
1426
  gint n;
1456
1443
  g_object_unref (view);
1457
1444
}
1458
1445
 
1459
 
static void
1460
 
close_cb (GtkAction * action, GladeWindow * window)
 
1446
void
 
1447
on_close_action_activate (GtkAction *action, GladeWindow *window)
1461
1448
{
1462
1449
  GladeDesignView *view;
1463
1450
  GladeProject *project;
1479
1466
  do_close (window, project);
1480
1467
}
1481
1468
 
1482
 
static void
1483
 
quit_cb (GtkAction * action, GladeWindow * window)
1484
 
{
1485
 
  GList *list, *projects;
1486
 
 
1487
 
  projects = g_list_copy (glade_app_get_projects ());
1488
 
 
1489
 
  for (list = projects; list; list = list->next)
1490
 
    {
1491
 
      GladeProject *project = GLADE_PROJECT (list->data);
1492
 
 
1493
 
      if (glade_project_get_modified (project))
1494
 
        {
1495
 
          gboolean quit = confirm_close_project (window, project);
1496
 
          if (!quit)
1497
 
            {
1498
 
              g_list_free (projects);
1499
 
              return;
1500
 
            }
1501
 
        }
1502
 
    }
1503
 
 
1504
 
  for (list = projects; list; list = list->next)
1505
 
    {
1506
 
      GladeProject *project = GLADE_PROJECT (glade_app_get_projects ()->data);
1507
 
      do_close (window, project);
1508
 
    }
1509
 
 
1510
 
  glade_window_config_save (window);
1511
 
 
1512
 
  g_list_free (projects);
1513
 
 
1514
 
  gtk_main_quit ();
1515
 
}
1516
 
 
1517
 
static void
1518
 
copy_cb (GtkAction * action, GladeWindow * window)
 
1469
void
 
1470
on_copy_action_activate (GtkAction *action, GladeWindow *window)
1519
1471
{
1520
1472
  GladeProject *project;
1521
1473
 
1527
1479
  glade_project_copy_selection (project);
1528
1480
}
1529
1481
 
1530
 
static void
1531
 
cut_cb (GtkAction * action, GladeWindow * window)
 
1482
void
 
1483
on_cut_action_activate (GtkAction *action, GladeWindow *window)
1532
1484
{
1533
1485
  GladeProject *project;
1534
1486
 
1540
1492
  glade_project_command_cut (project);
1541
1493
}
1542
1494
 
1543
 
static void
1544
 
paste_cb (GtkAction * action, GladeWindow * window)
 
1495
void
 
1496
on_paste_action_activate (GtkAction *action, GladeWindow *window)
1545
1497
{
1546
1498
  GladeProject *project;
1547
1499
 
1553
1505
  glade_project_command_paste (project, NULL);
1554
1506
}
1555
1507
 
1556
 
static void
1557
 
delete_cb (GtkAction * action, GladeWindow * window)
 
1508
void
 
1509
on_delete_action_activate (GtkAction *action, GladeWindow *window)
1558
1510
{
1559
1511
  GladeProject *project;
1560
1512
 
1566
1518
  glade_project_command_delete (project);
1567
1519
}
1568
1520
 
1569
 
static void
1570
 
properties_cb (GtkAction * action, GladeWindow * window)
 
1521
void
 
1522
on_properties_action_activate (GtkAction *action, GladeWindow *window)
1571
1523
{
1572
1524
  GladeProject *project;
1573
1525
 
1579
1531
  glade_project_properties (project);
1580
1532
}
1581
1533
 
1582
 
static void
1583
 
undo_cb (GtkAction * action, GladeWindow * window)
 
1534
void
 
1535
on_undo_action_activate (GtkAction *action, GladeWindow *window)
1584
1536
{
1585
1537
  GladeProject *active_project = get_active_project (window);
1586
1538
 
1593
1545
  glade_project_undo (active_project);
1594
1546
}
1595
1547
 
1596
 
static void
1597
 
redo_cb (GtkAction * action, GladeWindow * window)
 
1548
void
 
1549
on_redo_action_activate (GtkAction *action, GladeWindow *window)
1598
1550
{
1599
1551
  GladeProject *active_project = get_active_project (window);
1600
1552
 
1608
1560
}
1609
1561
 
1610
1562
static void
1611
 
doc_search_cb (GladeEditor * editor,
1612
 
               const gchar * book,
1613
 
               const gchar * page, const gchar * search, GladeWindow * window)
 
1563
doc_search_cb (GladeEditor *editor,
 
1564
               const gchar *book,
 
1565
               const gchar *page,
 
1566
               const gchar *search,
 
1567
               GladeWindow *window)
1614
1568
{
1615
1569
  glade_util_search_devhelp (book, page, search);
1616
1570
}
1617
1571
 
1618
 
static void
1619
 
previous_project_cb (GtkAction * action, GladeWindow * window)
1620
 
{
1621
 
  gtk_notebook_prev_page (GTK_NOTEBOOK (window->priv->notebook));
1622
 
}
1623
 
 
1624
 
static void
1625
 
next_project_cb (GtkAction * action, GladeWindow * window)
1626
 
{
1627
 
  gtk_notebook_next_page (GTK_NOTEBOOK (window->priv->notebook));
1628
 
}
1629
 
 
1630
 
static void
1631
 
notebook_switch_page_cb (GtkNotebook * notebook,
1632
 
                         GtkWidget * page, guint page_num, GladeWindow * window)
1633
 
{
 
1572
void
 
1573
on_notebook_switch_page (GtkNotebook *notebook,
 
1574
                         GtkWidget *page,
 
1575
                         guint page_num,
 
1576
                         GladeWindow *window)
 
1577
{
 
1578
  GladeWindowPrivate *priv = window->priv;
1634
1579
  GladeDesignView *view;
1635
1580
  GladeProject *project;
1636
1581
  GtkAction *action;
1640
1585
 
1641
1586
  /* CHECK: I don't know why but it seems notebook_switch_page is called
1642
1587
     two times every time the user change the active tab */
1643
 
  if (view == window->priv->active_view)
 
1588
  if (view == priv->active_view)
1644
1589
    return;
1645
1590
 
1646
1591
  window->priv->active_view = view;
1653
1598
 
1654
1599
  /* switch to the project's inspector/palette */
1655
1600
  gtk_notebook_set_current_page (GTK_NOTEBOOK
1656
 
                                 (window->priv->inspectors_notebook), page_num);
 
1601
                                 (priv->inspectors_notebook), page_num);
1657
1602
  gtk_notebook_set_current_page (GTK_NOTEBOOK
1658
 
                                 (window->priv->palettes_notebook), page_num);
 
1603
                                 (priv->palettes_notebook), page_num);
1659
1604
 
1660
1605
 
1661
1606
  /* activate the corresponding item in the project menu */
1662
1607
  action_name = g_strdup_printf ("Tab_%d", page_num);
1663
1608
  action =
1664
 
      gtk_action_group_get_action (window->priv->projects_list_menu_actions,
 
1609
      gtk_action_group_get_action (priv->projects_list_menu_actions,
1665
1610
                                   action_name);
1666
1611
 
1667
1612
  /* sometimes the action doesn't exist yet, and the proper action
1695
1640
  gtk_widget_set_sensitive (widget, TRUE);
1696
1641
}
1697
1642
 
1698
 
static void
1699
 
notebook_tab_added_cb (GtkNotebook *notebook,
 
1643
void
 
1644
on_notebook_tab_added (GtkNotebook *notebook,
1700
1645
                       GladeDesignView *view,
1701
1646
                       guint page_num,
1702
1647
                       GladeWindow *window)
1703
1648
{
 
1649
  GladeWindowPrivate *priv = window->priv;
1704
1650
  GladeProject *project;
1705
1651
  GtkWidget *inspector, *palette;
1706
 
  GtkAction *action;
1707
1652
 
1708
1653
  ++window->priv->num_tabs;
1709
1654
 
1740
1685
  glade_palette_set_show_selector_button (GLADE_PALETTE (palette), FALSE);
1741
1686
  glade_palette_set_project (GLADE_PALETTE (palette), project);
1742
1687
 
1743
 
  action = gtk_action_group_get_action (window->priv->static_actions, "UseSmallIcons");
1744
1688
  glade_palette_set_use_small_item_icons (GLADE_PALETTE (palette),
1745
 
                                          gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
 
1689
                                          gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (priv->action.use_small_icons)));
1746
1690
 
1747
 
  action = gtk_action_group_get_action (window->priv->static_actions, "IconsAndLabels");
1748
1691
  glade_palette_set_item_appearance (GLADE_PALETTE (palette),
1749
 
                                     gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)));
 
1692
                                     gtk_radio_action_get_current_value (GTK_RADIO_ACTION (priv->action.icons_and_labels)));
1750
1693
 
1751
1694
  gtk_notebook_append_page (GTK_NOTEBOOK (window->priv->palettes_notebook),
1752
1695
                            palette, NULL);
1775
1718
 
1776
1719
}
1777
1720
 
1778
 
static void
1779
 
notebook_tab_removed_cb (GtkNotebook     *notebook,
 
1721
void
 
1722
on_notebook_tab_removed (GtkNotebook     *notebook,
1780
1723
                         GladeDesignView *view,
1781
1724
                         guint            page_num, 
1782
 
                         GladeWindow     *window)
 
1725
                         GladeWindow     *window)
1783
1726
{
1784
1727
  GladeProject *project;
1785
1728
 
1798
1741
                                        window);
1799
1742
  g_signal_handlers_disconnect_by_func (G_OBJECT (project),
1800
1743
                                        G_CALLBACK (project_selection_changed_cb), 
1801
 
                                        window);
 
1744
                                        window);
1802
1745
  g_signal_handlers_disconnect_by_func (G_OBJECT (project),
1803
1746
                                        G_CALLBACK (project_targets_changed_cb),
1804
1747
                                        window);
1835
1778
 
1836
1779
}
1837
1780
 
1838
 
static void
1839
 
recent_chooser_item_activated_cb (GtkRecentChooser * chooser,
1840
 
                                  GladeWindow * window)
 
1781
void
 
1782
on_open_recent_action_item_activated (GtkRecentChooser *chooser,
 
1783
                                      GladeWindow *window)
1841
1784
{
1842
1785
  gchar *uri, *path;
1843
1786
  GError *error = NULL;
1859
1802
  g_free (path);
1860
1803
}
1861
1804
 
1862
 
static void
1863
 
palette_appearance_change_cb (GtkRadioAction *action,
1864
 
                              GtkRadioAction *current, 
1865
 
                              GladeWindow    *window)
 
1805
void
 
1806
on_palette_appearance_radioaction_changed (GtkRadioAction *action,
 
1807
                                           GtkRadioAction *current,
 
1808
                                           GladeWindow    *window)
1866
1809
{
1867
1810
  GList *children, *l;
1868
1811
  gint value;
1869
1812
 
1870
 
  value = gtk_radio_action_get_current_value (action);
 
1813
  value = gtk_radio_action_get_current_value (current);
1871
1814
 
1872
1815
  children = gtk_container_get_children (GTK_CONTAINER (window->priv->palettes_notebook));
1873
1816
  for (l = children; l; l = l->next)
1874
1817
    {
1875
1818
      if (GLADE_IS_PALETTE (l->data))
1876
 
        glade_palette_set_item_appearance (GLADE_PALETTE (l->data), value);
 
1819
                glade_palette_set_item_appearance (GLADE_PALETTE (l->data), value);
1877
1820
    }
1878
1821
  g_list_free (children);
1879
1822
}
1880
1823
 
1881
 
static void
1882
 
palette_toggle_small_icons_cb (GtkAction * action, GladeWindow * window)
 
1824
void
 
1825
on_use_small_icons_action_toggled (GtkAction *action, GladeWindow *window)
1883
1826
{
1884
1827
  GList *children, *l;
1885
1828
 
1895
1838
}
1896
1839
 
1897
1840
static gboolean
1898
 
on_dock_deleted (GtkWidget * widget, GdkEvent * event, GtkAction * dock_action)
 
1841
on_dock_deleted (GtkWidget *widget, GdkEvent *event, GtkAction *dock_action)
1899
1842
{
1900
1843
  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (dock_action), TRUE);
1901
1844
  return TRUE;
1902
1845
}
1903
1846
 
1904
1847
static gboolean
1905
 
on_dock_resized (GtkWidget * window, GdkEventConfigure * event, ToolDock * dock)
 
1848
on_dock_resized (GtkWidget *window, GdkEventConfigure *event, ToolDock *dock)
1906
1849
{
1907
1850
  GdkWindow *gdk_window =
1908
1851
      gtk_widget_get_window (GTK_WIDGET
1922
1865
  return FALSE;
1923
1866
}
1924
1867
 
1925
 
static void
1926
 
toggle_dock_cb (GtkAction * action, GladeWindow * window)
 
1868
void
 
1869
on_dock_action_toggled (GtkAction *action, GladeWindow *window)
1927
1870
{
1928
1871
  GtkWidget *toplevel, *alignment;
1929
1872
  ToolDock *dock;
1989
1932
          !gtk_paned_get_child2 (GTK_PANED (dock->paned)))
1990
1933
        gtk_widget_hide (dock->paned);
1991
1934
 
1992
 
 
1993
 
      gtk_window_add_accel_group (GTK_WINDOW (toplevel),
1994
 
                                  gtk_ui_manager_get_accel_group (window->priv->
1995
 
                                                                  ui));
 
1935
      gtk_window_add_accel_group (GTK_WINDOW (toplevel), window->priv->accelgroup);
1996
1936
 
1997
1937
      g_signal_connect (G_OBJECT (toplevel), "key-press-event",
1998
1938
                        G_CALLBACK (glade_utils_hijack_key_press), window);
2003
1943
    }
2004
1944
}
2005
1945
 
2006
 
 
2007
 
static void
2008
 
toggle_toolbar_cb (GtkAction * action, GladeWindow * window)
 
1946
void
 
1947
on_toolbar_visible_action_toggled (GtkAction *action, GladeWindow *window)
2009
1948
{
2010
1949
  if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
2011
1950
    gtk_widget_show (window->priv->toolbar);
2013
1952
    gtk_widget_hide (window->priv->toolbar);
2014
1953
}
2015
1954
 
2016
 
static void
2017
 
toggle_statusbar_cb (GtkAction * action, GladeWindow * window)
 
1955
void
 
1956
on_statusbar_visible_action_toggled (GtkAction *action, GladeWindow *window)
2018
1957
{
2019
1958
  if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
2020
1959
    gtk_widget_show (window->priv->statusbar);
2022
1961
    gtk_widget_hide (window->priv->statusbar);
2023
1962
}
2024
1963
 
2025
 
static void
2026
 
toggle_tabs_cb (GtkAction * action, GladeWindow * window)
 
1964
void
 
1965
on_project_tabs_visible_action_toggled (GtkAction *action, GladeWindow *window)
2027
1966
{
2028
1967
  if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
2029
1968
    gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->priv->notebook), TRUE);
2031
1970
    gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->priv->notebook), FALSE);
2032
1971
}
2033
1972
 
2034
 
static void
2035
 
show_developer_manual_cb (GtkAction * action, GladeWindow * window)
 
1973
void
 
1974
on_reference_action_activate (GtkAction *action, GladeWindow *window)
2036
1975
{
2037
1976
  if (glade_util_have_devhelp ())
2038
1977
    {
2044
1983
  glade_util_url_show (URL_DEVELOPER_MANUAL);
2045
1984
}
2046
1985
 
2047
 
static void
2048
 
about_cb (GtkAction * action, GladeWindow * window)
 
1986
void
 
1987
on_about_action_activate (GtkAction *action, GladeWindow *window)
2049
1988
{
2050
 
  static const gchar *const authors[] = { "Chema Celorio <chema@ximian.com>",
2051
 
    "Joaquin Cuenca Abela <e98cuenc@yahoo.com>",
2052
 
    "Paolo Borelli <pborelli@katamail.com>",
2053
 
    "Archit Baweja <bighead@users.sourceforge.net>",
2054
 
    "Shane Butler <shane_b@operamail.com>",
2055
 
    "Tristan Van Berkom <tvb@gnome.org>",
2056
 
    "Ivan Wong <email@ivanwong.info>",
2057
 
    "Juan Pablo Ugarte <juanpablougarte@gmail.com>",
2058
 
    "Vincent Geddes <vincent.geddes@gmail.com>",
2059
 
    NULL
2060
 
  };
2061
 
 
2062
 
  static const gchar *const artists[] = { "Vincent Geddes <vgeddes@gnome.org>",
2063
 
    "Andreas Nilsson <andreas@andreasn.se>",
2064
 
    NULL
2065
 
  };
2066
 
 
2067
 
  static const gchar *const documenters[] =
2068
 
      { "GNOME Documentation Team <gnome-doc-list@gnome.org>",
2069
 
    "Sun GNOME Documentation Team <gdocteam@sun.com>",
2070
 
    NULL
2071
 
  };
2072
 
 
2073
 
  static const gchar license[] =
2074
 
      N_("Glade is free software; you can redistribute it and/or modify "
2075
 
         "it under the terms of the GNU General Public License as "
2076
 
         "published by the Free Software Foundation; either version 2 of the "
2077
 
         "License, or (at your option) any later version."
2078
 
         "\n\n"
2079
 
         "Glade is distributed in the hope that it will be useful, "
2080
 
         "but WITHOUT ANY WARRANTY; without even the implied warranty of "
2081
 
         "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the "
2082
 
         "GNU General Public License for more details."
2083
 
         "\n\n"
2084
 
         "You should have received a copy of the GNU General Public License "
2085
 
         "along with Glade; if not, write to the Free Software "
2086
 
         "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, "
2087
 
         "MA 02110-1301, USA.");
2088
 
 
2089
 
  static const gchar copyright[] =
2090
 
      "Copyright \xc2\xa9 2001-2006 Ximian, Inc.\n"
2091
 
      "Copyright \xc2\xa9 2001-2006 Joaquin Cuenca Abela, Paolo Borelli, et al.\n"
2092
 
      "Copyright \xc2\xa9 2001-2010 Tristan Van Berkom, Juan Pablo Ugarte, et al.";
2093
 
 
2094
 
  gtk_show_about_dialog (GTK_WINDOW (window),
2095
 
                         "name", g_get_application_name (),
2096
 
                         "logo-icon-name", "glade",
2097
 
                         "authors", authors,
2098
 
                         "artists", artists,
2099
 
                         "documenters", documenters,
2100
 
                         "translator-credits", _("translator-credits"),
2101
 
                         "comments",
2102
 
                         _("A user interface designer for GTK+ and GNOME."),
2103
 
                         "license", _(license), "wrap-license", TRUE,
2104
 
                         "copyright", copyright, "version", PACKAGE_VERSION,
2105
 
                         "website", PACKAGE_URL, NULL);
 
1989
  GladeWindowPrivate *priv = GLADE_WINDOW_GET_PRIVATE (window);
 
1990
  
 
1991
  gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (priv->about_dialog), PACKAGE_VERSION);
 
1992
  
 
1993
  gtk_window_present (priv->about_dialog);
2106
1994
}
2107
1995
 
2108
 
static const gchar ui_info[] =
2109
 
    "<ui>"
2110
 
    "  <menubar name='MenuBar'>"
2111
 
    "    <menu action='FileMenu'>"
2112
 
    "      <menuitem action='New'/>"
2113
 
    "      <menuitem action='Open'/>"
2114
 
    "      <menuitem action='OpenRecent'/>"
2115
 
    "      <separator/>"
2116
 
    "      <menuitem action='Save'/>"
2117
 
    "      <menuitem action='SaveAs'/>"
2118
 
    "      <separator/>"
2119
 
    "      <menuitem action='Properties'/>"
2120
 
    "      <separator/>"
2121
 
    "      <menuitem action='Close'/>"
2122
 
    "      <menuitem action='Quit'/>"
2123
 
    "    </menu>"
2124
 
    "    <menu action='EditMenu'>"
2125
 
    "      <menuitem action='Undo'/>"
2126
 
    "      <menuitem action='Redo'/>"
2127
 
    "      <separator/>"
2128
 
    "      <menuitem action='Cut'/>"
2129
 
    "      <menuitem action='Copy'/>"
2130
 
    "      <menuitem action='Paste'/>"
2131
 
    "      <menuitem action='Delete'/>"
2132
 
    "    </menu>"
2133
 
    "    <menu action='ViewMenu'>"
2134
 
    "      <menuitem action='ToolbarVisible'/>"
2135
 
    "      <menuitem action='StatusbarVisible'/>"
2136
 
    "      <menuitem action='ProjectTabsVisible'/>"
2137
 
    "      <menu action='PaletteAppearance'>"
2138
 
    "        <menuitem action='IconsAndLabels'/>"
2139
 
    "        <menuitem action='IconsOnly'/>"
2140
 
    "        <menuitem action='LabelsOnly'/>"
2141
 
    "        <separator/>"
2142
 
    "        <menuitem action='UseSmallIcons'/>"
2143
 
    "      </menu>"
2144
 
    "      <separator/>"
2145
 
    "      <menuitem action='DockPalette'/>"
2146
 
    "      <menuitem action='DockInspector'/>"
2147
 
    "      <menuitem action='DockEditor'/>"
2148
 
    "    </menu>"
2149
 
    "    <menu action='ProjectMenu'>"
2150
 
    "      <menuitem action='PreviousProject'/>"
2151
 
    "      <menuitem action='NextProject'/>"
2152
 
    "      <separator/>"
2153
 
    "      <placeholder name='ProjectsListPlaceholder'/>"
2154
 
    "    </menu>"
2155
 
    "    <menu action='HelpMenu'>"
2156
 
    "      <menuitem action='DeveloperReference'/>"
2157
 
    "      <separator/>"
2158
 
    "      <menuitem action='About'/>"
2159
 
    "    </menu>"
2160
 
    "  </menubar>"
2161
 
    "  <toolbar  name='ToolBar'>"
2162
 
    "    <toolitem action='New'/>"
2163
 
    "    <toolitem action='Open'/>"
2164
 
    "    <toolitem action='Save'/>"
2165
 
    "    <separator/>"
2166
 
    "    <toolitem action='Cut'/>"
2167
 
    "    <toolitem action='Copy'/>"
2168
 
    "    <toolitem action='Paste'/>" 
2169
 
    "  </toolbar>" "</ui>";
2170
 
 
2171
 
static GtkActionEntry static_entries[] = {
2172
 
  {"FileMenu", NULL, N_("_File")},
2173
 
  {"EditMenu", NULL, N_("_Edit")},
2174
 
  {"ViewMenu", NULL, N_("_View")},
2175
 
  {"ProjectMenu", NULL, N_("_Projects")},
2176
 
  {"HelpMenu", NULL, N_("_Help")},
2177
 
  {"UndoMenu", NULL, NULL},
2178
 
  {"RedoMenu", NULL, NULL},
2179
 
 
2180
 
  /* FileMenu */
2181
 
  {"New", GTK_STOCK_NEW, NULL, "<control>N",
2182
 
   N_("Create a new project"), G_CALLBACK (new_cb)},
2183
 
 
2184
 
  {"Open", GTK_STOCK_OPEN, N_("_Open\342\200\246"), "<control>O",
2185
 
   N_("Open a project"), G_CALLBACK (open_cb)},
2186
 
 
2187
 
  {"OpenRecent", NULL, N_("Open _Recent")},
2188
 
 
2189
 
  {"Quit", GTK_STOCK_QUIT, NULL, "<control>Q",
2190
 
   N_("Quit the program"), G_CALLBACK (quit_cb)},
2191
 
 
2192
 
  /* ViewMenu */
2193
 
  {"PaletteAppearance", NULL, N_("Palette _Appearance")},
2194
 
 
2195
 
  /* HelpMenu */
2196
 
  {"About", GTK_STOCK_ABOUT, NULL, NULL,
2197
 
   N_("About this application"), G_CALLBACK (about_cb)},
2198
 
 
2199
 
  {"DeveloperReference", NULL, N_("_Developer Reference"), NULL,
2200
 
   N_("Display the developer reference manual"),
2201
 
   G_CALLBACK (show_developer_manual_cb)}
2202
 
};
2203
 
 
2204
 
static guint n_static_entries = G_N_ELEMENTS (static_entries);
2205
 
 
2206
 
static GtkActionEntry project_entries[] = {
2207
 
 
2208
 
  /* FileMenu */
2209
 
  {"Save", GTK_STOCK_SAVE, NULL, "<control>S",
2210
 
   N_("Save the current project"), G_CALLBACK (save_cb)},
2211
 
 
2212
 
  {"SaveAs", GTK_STOCK_SAVE_AS, N_("Save _As\342\200\246"), NULL,
2213
 
   N_("Save the current project with a different name"),
2214
 
   G_CALLBACK (save_as_cb)},
2215
 
 
2216
 
  {"Close", GTK_STOCK_CLOSE, NULL, "<control>W",
2217
 
   N_("Close the current project"), G_CALLBACK (close_cb)},
2218
 
 
2219
 
  /* EditMenu */
2220
 
  {"Undo", GTK_STOCK_UNDO, NULL, "<control>Z",
2221
 
   N_("Undo the last action"), G_CALLBACK (undo_cb)},
2222
 
 
2223
 
  {"Redo", GTK_STOCK_REDO, NULL, "<shift><control>Z",
2224
 
   N_("Redo the last action"), G_CALLBACK (redo_cb)},
2225
 
 
2226
 
  {"Cut", GTK_STOCK_CUT, NULL, NULL,
2227
 
   N_("Cut the selection"), G_CALLBACK (cut_cb)},
2228
 
 
2229
 
  {"Copy", GTK_STOCK_COPY, NULL, NULL,
2230
 
   N_("Copy the selection"), G_CALLBACK (copy_cb)},
2231
 
 
2232
 
  {"Paste", GTK_STOCK_PASTE, NULL, NULL,
2233
 
   N_("Paste the clipboard"), G_CALLBACK (paste_cb)},
2234
 
 
2235
 
  {"Delete", GTK_STOCK_DELETE, NULL, "Delete",
2236
 
   N_("Delete the selection"), G_CALLBACK (delete_cb)},
2237
 
 
2238
 
  {"Properties", GTK_STOCK_PROPERTIES, NULL, "<control>P",
2239
 
   N_("Edit project properties"), G_CALLBACK (properties_cb)},
2240
 
 
2241
 
  /* ProjectsMenu */
2242
 
  {"PreviousProject", NULL, N_("_Previous Project"), "<control>Page_Up",
2243
 
   N_("Activate previous project"), G_CALLBACK (previous_project_cb)},
2244
 
 
2245
 
  {"NextProject", NULL, N_("_Next Project"), "<control>Page_Down",
2246
 
   N_("Activate next project"), G_CALLBACK (next_project_cb)}
2247
 
 
2248
 
 
2249
 
};
2250
 
 
2251
 
static guint n_project_entries = G_N_ELEMENTS (project_entries);
2252
 
 
2253
 
static GtkToggleActionEntry view_entries[] = {
2254
 
 
2255
 
  {"UseSmallIcons", NULL, N_("_Use Small Icons"), NULL,
2256
 
   N_("Show items using small icons"),
2257
 
   G_CALLBACK (palette_toggle_small_icons_cb), FALSE},
2258
 
 
2259
 
  {"DockPalette", NULL, N_("Dock _Palette"), NULL,
2260
 
   N_("Dock the palette into the main window"),
2261
 
   G_CALLBACK (toggle_dock_cb), TRUE},
2262
 
 
2263
 
  {"DockInspector", NULL, N_("Dock _Inspector"), NULL,
2264
 
   N_("Dock the inspector into the main window"),
2265
 
   G_CALLBACK (toggle_dock_cb), TRUE},
2266
 
 
2267
 
  {"DockEditor", NULL, N_("Dock Prop_erties"), NULL,
2268
 
   N_("Dock the editor into the main window"),
2269
 
   G_CALLBACK (toggle_dock_cb), TRUE},
2270
 
 
2271
 
  {"ToolbarVisible", NULL, N_("Tool_bar"), NULL,
2272
 
   N_("Show the toolbar"),
2273
 
   G_CALLBACK (toggle_toolbar_cb), TRUE},
2274
 
 
2275
 
  {"StatusbarVisible", NULL, N_("_Statusbar"), NULL,
2276
 
   N_("Show the statusbar"),
2277
 
   G_CALLBACK (toggle_statusbar_cb), TRUE},
2278
 
 
2279
 
  {"ProjectTabsVisible", NULL, N_("Project _Tabs"), NULL,
2280
 
   N_("Show notebook tabs for loaded projects"),
2281
 
   G_CALLBACK (toggle_tabs_cb), TRUE},
2282
 
 
2283
 
};
2284
 
 
2285
 
static guint n_view_entries = G_N_ELEMENTS (view_entries);
2286
 
 
2287
 
static GtkRadioActionEntry radio_entries[] = {
2288
 
 
2289
 
  {"IconsAndLabels", NULL, N_("Text _beside icons"), NULL,
2290
 
   N_("Display items as text beside icons"), GLADE_ITEM_ICON_AND_LABEL},
2291
 
 
2292
 
  {"IconsOnly", NULL, N_("_Icons only"), NULL,
2293
 
   N_("Display items as icons only"), GLADE_ITEM_ICON_ONLY},
2294
 
 
2295
 
  {"LabelsOnly", NULL, N_("_Text only"), NULL,
2296
 
   N_("Display items as text only"), GLADE_ITEM_LABEL_ONLY},
2297
 
};
2298
 
 
2299
 
static guint n_radio_entries = G_N_ELEMENTS (radio_entries);
2300
 
 
2301
1996
static void
2302
 
menu_item_selected_cb (GtkWidget * item, GladeWindow * window)
 
1997
menu_item_selected_cb (GtkWidget *item, GladeWindow *window)
2303
1998
{
2304
 
  GtkAction *action;
2305
 
  gchar *tooltip;
2306
 
 
2307
 
  action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (item));
2308
 
  g_object_get (G_OBJECT (action), "tooltip", &tooltip, NULL);
2309
 
 
2310
 
  if (tooltip != NULL)
 
1999
  gchar *tooltip = gtk_widget_get_tooltip_text (item);
 
2000
 
 
2001
  if (tooltip)
2311
2002
    gtk_statusbar_push (GTK_STATUSBAR (window->priv->statusbar),
2312
2003
                        window->priv->statusbar_menu_context_id, tooltip);
2313
2004
 
2323
2014
}
2324
2015
 
2325
2016
static void
2326
 
ui_connect_proxy_cb (GtkUIManager * ui,
2327
 
                     GtkAction * action,
2328
 
                     GtkWidget * proxy, GladeWindow * window)
 
2017
menu_item_connect (GtkWidget *item, GtkAction *action, GladeWindow *window)
2329
2018
{
2330
 
  if (GTK_IS_MENU_ITEM (proxy))
 
2019
  if (GTK_IS_MENU_ITEM (item))
2331
2020
    {
2332
 
      g_signal_connect (G_OBJECT (proxy), "select",
 
2021
      if (action == NULL)
 
2022
        action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (item));
 
2023
 
 
2024
      if (action)
 
2025
        {
 
2026
          gchar *tooltip;
 
2027
          g_object_get (G_OBJECT (action), "tooltip", &tooltip, NULL);
 
2028
          gtk_widget_set_tooltip_text (item, tooltip);
 
2029
          /* yeah dont actually show tooltips, we use the to push them to the status bar */
 
2030
          gtk_widget_set_has_tooltip (item, FALSE);
 
2031
          g_free (tooltip);
 
2032
          
 
2033
        }
 
2034
 
 
2035
      g_signal_connect (item, "select",
2333
2036
                        G_CALLBACK (menu_item_selected_cb), window);
2334
 
      g_signal_connect (G_OBJECT (proxy), "deselect",
 
2037
      g_signal_connect (item, "deselect",
2335
2038
                        G_CALLBACK (menu_item_deselected_cb), window);
2336
2039
    }
2337
2040
}
2338
2041
 
2339
2042
static void
2340
 
ui_disconnect_proxy_cb (GtkUIManager * manager,
2341
 
                        GtkAction * action,
2342
 
                        GtkWidget * proxy, GladeWindow * window)
2343
 
{
2344
 
  if (GTK_IS_MENU_ITEM (proxy))
2345
 
    {
2346
 
      g_signal_handlers_disconnect_by_func
2347
 
          (proxy, G_CALLBACK (menu_item_selected_cb), window);
2348
 
      g_signal_handlers_disconnect_by_func
2349
 
          (proxy, G_CALLBACK (menu_item_deselected_cb), window);
2350
 
    }
2351
 
}
2352
 
 
2353
 
static GtkWidget *
2354
 
construct_menu (GladeWindow * window)
2355
 
{
2356
 
  GError *error = NULL;
2357
 
 
2358
 
  window->priv->static_actions = gtk_action_group_new (ACTION_GROUP_STATIC);
2359
 
  gtk_action_group_set_translation_domain (window->priv->static_actions,
2360
 
                                           GETTEXT_PACKAGE);
2361
 
 
2362
 
  gtk_action_group_add_actions (window->priv->static_actions,
2363
 
                                static_entries, n_static_entries, window);
2364
 
  gtk_action_group_add_toggle_actions (window->priv->static_actions,
2365
 
                                       view_entries, n_view_entries, window);
2366
 
  gtk_action_group_add_radio_actions (window->priv->static_actions,
2367
 
                                      radio_entries, n_radio_entries,
2368
 
                                      GLADE_ITEM_ICON_ONLY,
2369
 
                                      G_CALLBACK (palette_appearance_change_cb),
2370
 
                                      window);
2371
 
 
2372
 
  window->priv->project_actions = gtk_action_group_new (ACTION_GROUP_PROJECT);
2373
 
  gtk_action_group_set_translation_domain (window->priv->project_actions,
2374
 
                                           GETTEXT_PACKAGE);
2375
 
 
2376
 
  gtk_action_group_add_actions (window->priv->project_actions,
2377
 
                                project_entries, n_project_entries, window);
2378
 
 
2379
 
  window->priv->projects_list_menu_actions =
2380
 
      gtk_action_group_new (ACTION_GROUP_PROJECTS_LIST_MENU);
2381
 
  gtk_action_group_set_translation_domain (window->priv->
2382
 
                                           projects_list_menu_actions,
2383
 
                                           GETTEXT_PACKAGE);
2384
 
 
2385
 
  window->priv->ui = gtk_ui_manager_new ();
2386
 
 
2387
 
  g_signal_connect (G_OBJECT (window->priv->ui), "connect-proxy",
2388
 
                    G_CALLBACK (ui_connect_proxy_cb), window);
2389
 
  g_signal_connect (G_OBJECT (window->priv->ui), "disconnect-proxy",
2390
 
                    G_CALLBACK (ui_disconnect_proxy_cb), window);
2391
 
 
2392
 
  gtk_ui_manager_insert_action_group (window->priv->ui,
2393
 
                                      window->priv->static_actions, 0);
2394
 
  gtk_ui_manager_insert_action_group (window->priv->ui,
2395
 
                                      window->priv->project_actions, 1);
2396
 
  gtk_ui_manager_insert_action_group (window->priv->ui,
2397
 
                                      window->priv->projects_list_menu_actions,
2398
 
                                      3);
2399
 
 
2400
 
  gtk_window_add_accel_group (GTK_WINDOW (window),
2401
 
                              gtk_ui_manager_get_accel_group (window->priv->
2402
 
                                                              ui));
2403
 
 
2404
 
  glade_app_set_accel_group (gtk_ui_manager_get_accel_group (window->priv->ui));
2405
 
 
2406
 
  if (!gtk_ui_manager_add_ui_from_string
2407
 
      (window->priv->ui, ui_info, -1, &error))
2408
 
    {
2409
 
      g_message ("Building menus failed: %s", error->message);
2410
 
      g_error_free (error);
2411
 
    }
2412
 
 
2413
 
  return gtk_ui_manager_get_widget (window->priv->ui, "/MenuBar");
 
2043
menu_item_disconnect (GtkWidget *item, GladeWindow *window)
 
2044
{
 
2045
  if (GTK_IS_MENU_ITEM (item))
 
2046
    {
 
2047
      g_signal_handlers_disconnect_by_func
 
2048
          (item, G_CALLBACK (menu_item_selected_cb), window);
 
2049
      g_signal_handlers_disconnect_by_func
 
2050
          (item, G_CALLBACK (menu_item_deselected_cb), window);
 
2051
    }
 
2052
}
 
2053
 
 
2054
void
 
2055
on_actiongroup_connect_proxy (GtkActionGroup *action_group,
 
2056
                              GtkAction *action,
 
2057
                              GtkWidget *proxy,
 
2058
                              GladeWindow *window)
 
2059
{
 
2060
  menu_item_connect (proxy, action, window);
 
2061
}
 
2062
 
 
2063
void
 
2064
on_actiongroup_disconnect_proxy (GtkActionGroup *action_group,
 
2065
                                 GtkAction *action,
 
2066
                                 GtkWidget *proxy,
 
2067
                                 GladeWindow *window)
 
2068
{
 
2069
  menu_item_disconnect (proxy, window);
 
2070
}
 
2071
 
 
2072
void
 
2073
on_recent_menu_insert (GtkMenuShell *menu_shell,
 
2074
                       GtkWidget    *child,
 
2075
                       gint          position,
 
2076
                       GladeWindow *window)
 
2077
{
 
2078
  menu_item_connect (child, NULL, window);
 
2079
}
 
2080
 
 
2081
void
 
2082
on_recent_menu_remove (GtkContainer *container,
 
2083
                       GtkWidget *widget,
 
2084
                       GladeWindow *window)
 
2085
{
 
2086
  menu_item_disconnect (widget, window);
 
2087
}
 
2088
 
 
2089
static void
 
2090
recent_menu_setup_callbacks (GtkWidget *menu, GladeWindow *window)
 
2091
{
 
2092
  GList *l, *list = gtk_container_get_children (GTK_CONTAINER (menu));
 
2093
 
 
2094
  for (l = list; l; l = g_list_next (l))
 
2095
    menu_item_connect (l->data, NULL, window);
 
2096
 
 
2097
  g_list_free (list);
 
2098
}
 
2099
 
 
2100
static void
 
2101
action_group_setup_callbacks (GtkActionGroup *action_group, GladeWindow *window)
 
2102
{
 
2103
  GList *l, *list = gtk_action_group_list_actions (action_group);
 
2104
 
 
2105
  for (l = list; l; l = g_list_next (l))
 
2106
    {
 
2107
      GtkAction *action = l->data;
 
2108
      GSList *p, *proxies = gtk_action_get_proxies (action);
 
2109
      gboolean is_recent = GTK_IS_RECENT_ACTION (action);
 
2110
 
 
2111
      for (p = proxies; p; p = g_slist_next (p))
 
2112
        {
 
2113
          GtkWidget *submenu, *proxy = p->data;
 
2114
 
 
2115
          menu_item_connect (proxy, action, window);
 
2116
 
 
2117
          if (is_recent && GTK_IS_MENU_ITEM (proxy) &&
 
2118
              (submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy))))
 
2119
            recent_menu_setup_callbacks (submenu, window);
 
2120
        }
 
2121
    }
 
2122
 
 
2123
  g_list_free (list);
2414
2124
}
2415
2125
 
2416
2126
enum
2423
2133
};
2424
2134
 
2425
2135
static void
2426
 
drag_data_received (GtkWidget * widget,
2427
 
                    GdkDragContext * context,
 
2136
drag_data_received (GtkWidget *widget,
 
2137
                    GdkDragContext *context,
2428
2138
                    gint x, gint y,
2429
 
                    GtkSelectionData * selection_data,
2430
 
                    guint info, guint time, GladeWindow * window)
 
2139
                    GtkSelectionData *selection_data,
 
2140
                    guint info,
 
2141
                    guint time,
 
2142
                    GladeWindow *window)
2431
2143
{
2432
2144
  gchar **uris, **str;
2433
2145
  const guchar *data;
2460
2172
}
2461
2173
 
2462
2174
static gboolean
2463
 
delete_event (GtkWindow * w, GdkEvent * event, GladeWindow * window)
 
2175
delete_event (GtkWindow *w, GdkEvent *event, GladeWindow *window)
2464
2176
{
2465
 
  quit_cb (NULL, window);
 
2177
  gtk_action_activate (window->priv->action.quit);
2466
2178
 
2467
2179
  /* return TRUE to stop other handlers */
2468
2180
  return TRUE;
2469
2181
}
2470
2182
 
2471
 
static void
2472
 
on_tool_button_toggled (GtkToggleToolButton *button, gpointer data)
2473
 
{
2474
 
  GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
2475
 
  
2476
 
  g_return_if_fail (GLADE_IS_WINDOW (toplevel));
2477
 
  
2478
 
  if (gtk_toggle_tool_button_get_active (button))
2479
 
      glade_project_set_pointer_mode (get_active_project (GLADE_WINDOW (toplevel)),
2480
 
                                      GPOINTER_TO_INT (data));
2481
 
}
2482
 
 
2483
 
static GtkToggleToolButton *
2484
 
create_tool_button (GtkToolbar *toolbar,
2485
 
                    GtkToggleToolButton *group,
2486
 
                    const gchar *label,
2487
 
                    const gchar *tooltip,
2488
 
                    GladePointerMode pointer_mode)
2489
 
{
2490
 
  GtkToolItem *button;
2491
 
  GdkPixbuf *pixbuf;
2492
 
 
2493
 
  if (group)
2494
 
    button = gtk_radio_tool_button_new_from_widget (GTK_RADIO_TOOL_BUTTON (group));
2495
 
  else
2496
 
    button = gtk_radio_tool_button_new (NULL);
2497
 
  
2498
 
  pixbuf = glade_project_pointer_mode_render_icon (pointer_mode, GTK_ICON_SIZE_LARGE_TOOLBAR);
2499
 
  if (pixbuf)
2500
 
    {
2501
 
      GtkWidget *image = gtk_image_new_from_pixbuf (pixbuf);
2502
 
      g_object_unref (pixbuf);
2503
 
      gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (button), image);
2504
 
      gtk_widget_show (image);
2505
 
    }
2506
 
 
2507
 
  gtk_tool_button_set_label (GTK_TOOL_BUTTON (button), label);
2508
 
  gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (button), tooltip);
2509
 
 
2510
 
  gtk_toolbar_insert (toolbar, button, -1);
2511
 
  gtk_widget_show (GTK_WIDGET (button));
2512
 
 
2513
 
  g_signal_connect (button, "toggled",
2514
 
                    G_CALLBACK (on_tool_button_toggled),
2515
 
                    GINT_TO_POINTER (pointer_mode));
2516
 
  
2517
 
  return GTK_TOGGLE_TOOL_BUTTON (button);
2518
 
}
2519
 
 
2520
 
static void
2521
 
tab_close_button_clicked_cb (GtkWidget * close_button, GladeProject * project)
 
2183
void
 
2184
on_selector_radioaction_changed (GtkRadioAction *action,
 
2185
                                 GtkRadioAction *current,
 
2186
                                 GladeWindow *window) 
 
2187
{
 
2188
  glade_project_set_pointer_mode (get_active_project (window),
 
2189
                                  gtk_radio_action_get_current_value (current));
 
2190
}
 
2191
 
 
2192
static void
 
2193
tab_close_button_clicked_cb (GtkWidget *close_button, GladeProject *project)
2522
2194
{
2523
2195
  GladeWindow *window = GLADE_WINDOW (glade_app_get_window ());
2524
2196
  gboolean close;
2556
2228
}
2557
2229
 
2558
2230
static void
2559
 
project_load_finished_cb (GladeProject * project, GtkWidget * tab_label)
 
2231
project_load_finished_cb (GladeProject *project, GtkWidget *tab_label)
2560
2232
{
2561
2233
  GtkWidget *progress, *label;
2562
2234
 
2568
2240
}
2569
2241
 
2570
2242
static GtkWidget *
2571
 
create_notebook_tab (GladeWindow * window, GladeProject * project,
 
2243
create_notebook_tab (GladeWindow *window,
 
2244
                     GladeProject *project,
2572
2245
                     gboolean for_file)
2573
2246
{
2574
2247
  GtkWidget *tab_label, *ebox, *hbox, *close_button, *label, *dummy_label;
2575
2248
  GtkWidget *progress;
2576
2249
 
2577
 
  tab_label = gtk_hbox_new (FALSE, 4);
 
2250
  tab_label = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
2578
2251
 
2579
2252
  ebox = gtk_event_box_new ();
2580
2253
  gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
2581
2254
  gtk_box_pack_start (GTK_BOX (tab_label), ebox, TRUE, TRUE, 0);
2582
2255
 
2583
 
  hbox = gtk_hbox_new (FALSE, 4);
 
2256
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
2584
2257
  gtk_container_add (GTK_CONTAINER (ebox), hbox);
2585
2258
 
2586
2259
  close_button = glade_close_button_new ();
2631
2304
}
2632
2305
 
2633
2306
static void
2634
 
add_project (GladeWindow * window, GladeProject * project, gboolean for_file)
 
2307
add_project (GladeWindow *window, GladeProject *project, gboolean for_file)
2635
2308
{
2636
2309
  GtkWidget *view, *label;
2637
2310
 
2660
2333
}
2661
2334
 
2662
2335
void
2663
 
glade_window_new_project (GladeWindow * window)
 
2336
glade_window_new_project (GladeWindow *window)
2664
2337
{
2665
2338
  GladeProject *project;
2666
2339
 
2678
2351
}
2679
2352
 
2680
2353
static gboolean
2681
 
open_project (GladeWindow * window, const gchar * path)
 
2354
open_project (GladeWindow *window, const gchar *path)
2682
2355
{
2683
2356
  GladeProject *project;
2684
2357
 
2702
2375
}
2703
2376
 
2704
2377
static void
2705
 
check_reload_project (GladeWindow * window, GladeProject * project)
 
2378
check_reload_project (GladeWindow *window, GladeProject *project)
2706
2379
{
2707
2380
  gchar *path;
2708
2381
  GtkWidget *dialog;
2795
2468
 * Returns: #TRUE if the project was opened
2796
2469
 */
2797
2470
gboolean
2798
 
glade_window_open_project (GladeWindow * window, const gchar * path)
 
2471
glade_window_open_project (GladeWindow *window, const gchar *path)
2799
2472
{
2800
2473
  GladeProject *project;
2801
2474
 
2817
2490
}
2818
2491
 
2819
2492
static void
2820
 
change_menu_label (GladeWindow * window,
2821
 
                   const gchar * path,
2822
 
                   const gchar * action_label, const gchar * action_description)
2823
 
{
2824
 
  GtkBin *bin;
2825
 
  GtkLabel *label;
2826
 
  gchar *text;
2827
 
  gchar *tmp_text;
2828
 
 
2829
 
  g_assert (GLADE_IS_WINDOW (window));
2830
 
  g_return_if_fail (path != NULL);
2831
 
  g_return_if_fail (action_label != NULL);
2832
 
 
2833
 
  bin = GTK_BIN (gtk_ui_manager_get_widget (window->priv->ui, path));
2834
 
  label = GTK_LABEL (gtk_bin_get_child (bin));
2835
 
 
2836
 
  if (action_description == NULL)
2837
 
    text = g_strdup (action_label);
2838
 
  else
2839
 
    {
2840
 
      tmp_text = escape_underscores (action_description, -1);
2841
 
      text = g_strdup_printf ("%s: %s", action_label, tmp_text);
2842
 
      g_free (tmp_text);
2843
 
    }
2844
 
 
2845
 
  gtk_label_set_text_with_mnemonic (label, text);
2846
 
 
2847
 
  g_free (text);
2848
 
}
2849
 
 
2850
 
static void
2851
 
refresh_undo_redo (GladeWindow *window, GladeProject *project)
2852
 
{
2853
 
  GladeCommand *undo = NULL, *redo = NULL;
2854
 
  GtkAction    *action;
2855
 
  gchar        *tooltip;
2856
 
 
2857
 
  if (project != NULL)
2858
 
    {
2859
 
      undo = glade_project_next_undo_item (project);
2860
 
      redo = glade_project_next_redo_item (project);
2861
 
    }
2862
 
 
2863
 
  /* Refresh Undo */
2864
 
  action = gtk_action_group_get_action (window->priv->project_actions, "Undo");
2865
 
  gtk_action_set_sensitive (action, undo != NULL);
2866
 
 
2867
 
  change_menu_label
2868
 
      (window, "/MenuBar/EditMenu/Undo", _("_Undo"),
2869
 
       undo ? glade_command_description (undo) : NULL);
2870
 
 
2871
 
  tooltip =
2872
 
      g_strdup_printf (_("Undo: %s"),
2873
 
                       undo ? glade_command_description (undo) : _("the last action"));
2874
 
  g_object_set (action, "tooltip", tooltip, NULL);
2875
 
  g_free (tooltip);
2876
 
 
2877
 
  /* Refresh Redo */
2878
 
  action = gtk_action_group_get_action (window->priv->project_actions, "Redo");
2879
 
  gtk_action_set_sensitive (action, redo != NULL);
2880
 
 
2881
 
  change_menu_label
2882
 
      (window, "/MenuBar/EditMenu/Redo", _("_Redo"),
2883
 
       redo ? glade_command_description (redo) : NULL);
2884
 
 
2885
 
  tooltip =
2886
 
      g_strdup_printf (_("Redo: %s"),
2887
 
                       redo ? glade_command_description (redo) : _("the last action"));
2888
 
  g_object_set (action, "tooltip", tooltip, NULL);
2889
 
  g_free (tooltip);
2890
 
 
2891
 
  /* Refresh menus */
2892
 
  gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (window->priv->undo),
2893
 
                                 glade_project_undo_items (project));
2894
 
  gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (window->priv->redo),
2895
 
                                 glade_project_redo_items (project));
2896
 
 
2897
 
}
2898
 
 
2899
 
static void
2900
 
glade_window_dispose (GObject * object)
 
2493
glade_window_dispose (GObject *object)
2901
2494
{
2902
2495
  GladeWindow *window = GLADE_WINDOW (object);
2903
2496
 
2911
2504
}
2912
2505
 
2913
2506
static void
2914
 
glade_window_finalize (GObject * object)
 
2507
glade_window_finalize (GObject *object)
2915
2508
{
2916
2509
  guint i;
2917
2510
 
2929
2522
 
2930
2523
 
2931
2524
static gboolean
2932
 
glade_window_configure_event (GtkWidget * widget, GdkEventConfigure * event)
 
2525
glade_window_configure_event (GtkWidget *widget, GdkEventConfigure *event)
2933
2526
{
2934
2527
  GladeWindow *window = GLADE_WINDOW (widget);
2935
2528
  gboolean retval;
2959
2552
}
2960
2553
 
2961
2554
static void
2962
 
key_file_set_window_position (GKeyFile * config,
2963
 
                              GdkRectangle * position,
 
2555
key_file_set_window_position (GKeyFile *config,
 
2556
                              GdkRectangle *position,
2964
2557
                              const char *id,
2965
2558
                              gboolean detached,
2966
 
                              gboolean save_detached, gboolean maximized)
 
2559
                              gboolean save_detached,
 
2560
                              gboolean maximized)
2967
2561
{
2968
2562
  char *key_x, *key_y, *key_width, *key_height, *key_detached, *key_maximized;
2969
2563
 
3003
2597
}
3004
2598
 
3005
2599
static void
3006
 
save_windows_config (GladeWindow * window, GKeyFile * config)
 
2600
save_windows_config (GladeWindow *window, GKeyFile *config)
3007
2601
{
3008
2602
  guint i;
3009
2603
  GdkWindow *gdk_window;
3041
2635
}
3042
2636
 
3043
2637
static void
3044
 
save_paned_position (GKeyFile * config, GtkWidget * paned, const gchar * name)
 
2638
save_paned_position (GKeyFile *config, GtkWidget *paned, const gchar *name)
3045
2639
{
3046
2640
  g_key_file_set_integer (config, name, "position",
3047
2641
                          gtk_paned_get_position (GTK_PANED (paned)));
3063
2657
}
3064
2658
 
3065
2659
static int
3066
 
key_file_get_int (GKeyFile * config,
3067
 
                  const char *group, const char *key, int default_value)
 
2660
key_file_get_int (GKeyFile *config,
 
2661
                  const char *group,
 
2662
                  const char *key,
 
2663
                  int default_value)
3068
2664
{
3069
2665
  if (g_key_file_has_key (config, group, key, NULL))
3070
2666
    return g_key_file_get_integer (config, group, key, NULL);
3073
2669
}
3074
2670
 
3075
2671
static void
3076
 
key_file_get_window_position (GKeyFile * config,
 
2672
key_file_get_window_position (GKeyFile *config,
3077
2673
                              const char *id,
3078
 
                              GdkRectangle * pos,
3079
 
                              gboolean * detached, gboolean * maximized)
 
2674
                              GdkRectangle *pos,
 
2675
                              gboolean *detached,
 
2676
                              gboolean *maximized)
3080
2677
{
3081
2678
  char *key_x, *key_y, *key_width, *key_height, *key_detached, *key_maximized;
3082
2679
 
3123
2720
  g_free (key_maximized);
3124
2721
}
3125
2722
 
3126
 
 
3127
2723
static void
3128
 
load_paned_position (GKeyFile * config, GtkWidget * pane, const gchar * name,
 
2724
load_paned_position (GKeyFile *config,
 
2725
                     GtkWidget *pane,
 
2726
                     const gchar *name,
3129
2727
                     gint default_position)
3130
2728
{
3131
2729
  gtk_paned_set_position (GTK_PANED (pane),
3134
2732
}
3135
2733
 
3136
2734
static gboolean
3137
 
fix_paned_positions_idle (GladeWindow * window)
 
2735
fix_paned_positions_idle (GladeWindow *window)
3138
2736
{
3139
2737
  /* When initially maximized/fullscreened we need to deffer this operation 
3140
2738
   */
3148
2746
}
3149
2747
 
3150
2748
static void
3151
 
glade_window_set_initial_size (GladeWindow * window, GKeyFile * config)
 
2749
glade_window_set_initial_size (GladeWindow *window, GKeyFile *config)
3152
2750
{
3153
2751
  GdkRectangle position = {
3154
2752
    G_MININT, G_MININT, GLADE_WINDOW_DEFAULT_WIDTH, GLADE_WINDOW_DEFAULT_HEIGHT
3177
2775
}
3178
2776
 
3179
2777
static void
3180
 
glade_window_config_load (GladeWindow * window)
 
2778
glade_window_config_load (GladeWindow *window)
3181
2779
{
3182
2780
  GKeyFile *config = glade_app_get_config ();
3183
2781
  gboolean show_toolbar, show_tabs, show_status;
3184
 
  GtkAction *action;
 
2782
  GladeWindowPrivate *priv = window->priv;
3185
2783
  GError *error = NULL;
3186
2784
 
3187
2785
  /* Initial main dimensions */
3216
2814
    }
3217
2815
 
3218
2816
  if (show_toolbar)
3219
 
    gtk_widget_show (window->priv->toolbar);
 
2817
    gtk_widget_show (priv->toolbar);
3220
2818
  else
3221
 
    gtk_widget_hide (window->priv->toolbar);
 
2819
    gtk_widget_hide (priv->toolbar);
3222
2820
 
3223
2821
  if (show_status)
3224
 
    gtk_widget_show (window->priv->statusbar);
 
2822
    gtk_widget_show (priv->statusbar);
3225
2823
  else
3226
 
    gtk_widget_hide (window->priv->statusbar);
3227
 
 
3228
 
  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->priv->notebook), show_tabs);
3229
 
 
3230
 
  action = gtk_action_group_get_action (window->priv->static_actions, "ToolbarVisible");
3231
 
  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), show_toolbar);
3232
 
 
3233
 
  action = gtk_action_group_get_action (window->priv->static_actions, "ProjectTabsVisible");
3234
 
  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), show_tabs);
3235
 
 
3236
 
  action = gtk_action_group_get_action (window->priv->static_actions, "StatusbarVisible");
3237
 
  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), show_tabs);
 
2824
    gtk_widget_hide (priv->statusbar);
 
2825
 
 
2826
  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), show_tabs);
 
2827
 
 
2828
  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (priv->action.toolbar_visible), show_toolbar);
 
2829
 
 
2830
  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (priv->action.project_tabs_visible), show_tabs);
 
2831
 
 
2832
  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (priv->action.statusbar_visible), show_tabs);
3238
2833
 
3239
2834
  /* Paned positions */
3240
2835
  load_paned_position (config, window->priv->left_pane, "left_pane", 200);
3250
2845
}
3251
2846
 
3252
2847
static void
3253
 
show_dock_first_time (GladeWindow * window,
3254
 
                      guint dock_type, const char *action_id)
 
2848
show_dock_first_time (GladeWindow *window, guint dock_type, GtkAction *action)
3255
2849
{
3256
2850
  GKeyFile *config;
3257
2851
  int detached = -1;
3258
2852
  gboolean maximized;
3259
 
  GtkAction *action;
3260
2853
  ToolDock *dock;
3261
2854
 
3262
 
  action =
3263
 
      gtk_action_group_get_action (window->priv->static_actions, action_id);
3264
2855
  g_object_set_data (G_OBJECT (action), "glade-dock-type",
3265
2856
                     GUINT_TO_POINTER (dock_type));
3266
2857
 
3282
2873
}
3283
2874
 
3284
2875
static void
3285
 
setup_dock (ToolDock * dock,
3286
 
            GtkWidget * dock_widget,
 
2876
setup_dock (ToolDock *dock,
 
2877
            GtkWidget *dock_widget,
3287
2878
            guint default_width,
3288
2879
            guint default_height,
3289
2880
            const char *window_title,
3290
 
            const char *id, GtkWidget * paned, gboolean first_child)
 
2881
            const char *id,
 
2882
            GtkWidget *paned,
 
2883
            gboolean first_child)
3291
2884
{
3292
2885
  dock->widget = dock_widget;
3293
2886
  dock->window_pos.x = dock->window_pos.y = G_MININT;
3301
2894
  dock->maximized = FALSE;
3302
2895
}
3303
2896
 
 
2897
void
 
2898
on_quit_action_activate (GtkAction *action, GladeWindow *window)
 
2899
{
 
2900
  GList *list, *projects;
 
2901
 
 
2902
  projects = g_list_copy (glade_app_get_projects ());
 
2903
 
 
2904
  for (list = projects; list; list = list->next)
 
2905
    {
 
2906
      GladeProject *project = GLADE_PROJECT (list->data);
 
2907
 
 
2908
      if (glade_project_get_modified (project))
 
2909
        {
 
2910
          gboolean quit = confirm_close_project (window, project);
 
2911
          if (!quit)
 
2912
            {
 
2913
              g_list_free (projects);
 
2914
              return;
 
2915
            }
 
2916
        }
 
2917
    }
 
2918
 
 
2919
  for (list = projects; list; list = list->next)
 
2920
    {
 
2921
      GladeProject *project = GLADE_PROJECT (glade_app_get_projects ()->data);
 
2922
      do_close (window, project);
 
2923
    }
 
2924
 
 
2925
  glade_window_config_save (window);
 
2926
 
 
2927
  g_list_free (projects);
 
2928
 
 
2929
  gtk_main_quit ();
 
2930
}
 
2931
 
 
2932
 
3304
2933
static void
3305
 
glade_window_init (GladeWindow * window)
 
2934
glade_window_init (GladeWindow *window)
3306
2935
{
3307
2936
  GladeWindowPrivate *priv;
3308
2937
 
3309
 
  GtkWidget *vbox;
3310
 
  GtkWidget *hpaned1;
3311
 
  GtkWidget *hpaned2;
3312
 
  GtkWidget *vpaned;
3313
 
  GtkWidget *menubar;
3314
 
  GtkWidget *dockitem;
3315
 
  GtkWidget *widget;
3316
 
  GtkWidget *sep;
3317
 
  GtkAction *undo_action, *redo_action;
3318
 
 
3319
2938
  window->priv = priv = GLADE_WINDOW_GET_PRIVATE (window);
3320
2939
 
3321
2940
  priv->default_path = NULL;
3322
2941
 
3323
2942
  priv->app = glade_app_new ();
3324
2943
 
3325
 
  vbox = gtk_vbox_new (FALSE, 0);
 
2944
}
 
2945
 
 
2946
#define GET_OBJECT(b,c,o) c(gtk_builder_get_object(b,o)) /*;g_warn_if_fail(gtk_builder_get_object(b,o))*/
 
2947
 
 
2948
static void
 
2949
glade_window_constructed (GObject *object)
 
2950
{
 
2951
  GladeWindowPrivate *priv = GLADE_WINDOW_GET_PRIVATE (object);
 
2952
  GtkBuilder *builder;  
 
2953
  GladeWindow *window;
 
2954
  GError *error = NULL;
 
2955
  GtkWidget *vbox;
 
2956
  GtkActionGroup *group;
 
2957
 
 
2958
  /* Chain up... */
 
2959
  G_OBJECT_CLASS (glade_window_parent_class)->constructed (object);
 
2960
  
 
2961
  /* Build UI */
 
2962
#if HAVE_GTK_BUILDER_ADD_FROM_RESOURCE
 
2963
  builder = gtk_builder_new ();
 
2964
  if (gtk_builder_add_from_resource (builder, "/org/gnome/glade/glade.glade", &error) == 0)
 
2965
        {
 
2966
          g_warning ("gtk_builder_add_from_resource() failed %s", (error) ? error->message : "");
 
2967
          return;
 
2968
        }
 
2969
#else
 
2970
  {
 
2971
        /*TODO: remove this once we depend on gtk 3.4 */
 
2972
    GBytes *glade_ui = g_resources_lookup_data ("/org/gnome/glade/glade.glade",
 
2973
                                                G_RESOURCE_LOOKUP_FLAGS_NONE,
 
2974
                                                NULL);
 
2975
        if (glade_ui == NULL) return;
 
2976
 
 
2977
        builder = gtk_builder_new ();
 
2978
        gtk_builder_add_from_string (builder, g_bytes_get_data (glade_ui, NULL), -1, NULL);
 
2979
  }
 
2980
#endif
 
2981
  
 
2982
  window = GLADE_WINDOW (object);
 
2983
 
 
2984
  priv->projects_list_menu_actions = GET_OBJECT (builder, GTK_ACTION_GROUP, "project_list_actiongroup");
 
2985
  g_object_ref_sink (priv->projects_list_menu_actions);
 
2986
 
 
2987
  /* recent files */
 
2988
  priv->recent_manager = gtk_recent_manager_get_default ();
 
2989
    {
 
2990
      GtkRecentFilter *filter = gtk_recent_filter_new ();
 
2991
      gtk_recent_filter_add_application (filter, g_get_application_name ());
 
2992
      gtk_recent_chooser_set_filter (GET_OBJECT (builder, GTK_RECENT_CHOOSER, "open_recent_action"),
 
2993
                                     filter);
 
2994
    }
 
2995
  
 
2996
  /* Fetch pointers */
 
2997
  vbox = GET_OBJECT (builder, GTK_WIDGET, "main_box");
 
2998
  priv->about_dialog   = GET_OBJECT (builder, GTK_WINDOW, "about_dialog");
 
2999
  priv->preferences_dialog = GET_OBJECT (builder, GTK_WINDOW, "preferences_dialog");
 
3000
 
 
3001
  priv->center_pane = GET_OBJECT (builder, GTK_WIDGET, "center_paned");
 
3002
  priv->left_pane = GET_OBJECT (builder, GTK_WIDGET, "left_paned");
 
3003
  priv->right_pane = GET_OBJECT (builder, GTK_WIDGET, "right_paned");
 
3004
 
 
3005
  priv->notebook = GET_OBJECT (builder, GTK_WIDGET, "notebook");
 
3006
  priv->palettes_notebook = GET_OBJECT (builder, GTK_WIDGET, "palettes_notebook");
 
3007
  priv->inspectors_notebook = GET_OBJECT (builder, GTK_WIDGET, "inspectors_notebook");
 
3008
  priv->editor = GET_OBJECT (builder, GLADE_EDITOR, "editor");
 
3009
  priv->statusbar = GET_OBJECT (builder, GTK_WIDGET, "statusbar");
 
3010
  priv->toolbar = GET_OBJECT (builder, GTK_WIDGET, "toolbar");
 
3011
  priv->project_menu = GET_OBJECT (builder, GTK_MENU_SHELL, "project_menu");
 
3012
 
 
3013
  priv->undo = GET_OBJECT (builder, GTK_TOOL_ITEM, "undo_toolbutton");
 
3014
  priv->redo = GET_OBJECT (builder, GTK_TOOL_ITEM, "redo_toolbutton");
 
3015
 
 
3016
  priv->accelgroup = GTK_ACCEL_GROUP (gtk_builder_get_object (builder, "accelgroup"));
 
3017
  gtk_window_add_accel_group (GTK_WINDOW (window), priv->accelgroup);
 
3018
 
 
3019
  /* Action groups */
 
3020
  priv->project_actions = GET_OBJECT (builder, GTK_ACTION_GROUP, "project_actiongroup");
 
3021
  action_group_setup_callbacks (priv->project_actions, window);
 
3022
  g_object_ref_sink (priv->project_actions);
 
3023
 
 
3024
  priv->pointer_mode_actions = GET_OBJECT (builder, GTK_ACTION_GROUP, "pointer_mode_actiongroup");
 
3025
  action_group_setup_callbacks (priv->pointer_mode_actions, window);
 
3026
  g_object_ref_sink (priv->pointer_mode_actions);
 
3027
  
 
3028
  group = GET_OBJECT (builder, GTK_ACTION_GROUP, "static_actiongroup");
 
3029
  action_group_setup_callbacks (group, window);
 
3030
  g_object_ref_sink (group);
 
3031
  
 
3032
  group = GET_OBJECT (builder, GTK_ACTION_GROUP, "view_actiongroup");
 
3033
  action_group_setup_callbacks (group, window);
 
3034
  g_object_ref_sink (group);
 
3035
 
 
3036
  /* Actions */
 
3037
  priv->action.save = GET_OBJECT (builder, GTK_ACTION, "save_action");
 
3038
  priv->action.quit = GET_OBJECT (builder, GTK_ACTION, "quit_action");
 
3039
  priv->action.undo = GET_OBJECT (builder, GTK_ACTION, "undo_action");
 
3040
  priv->action.redo = GET_OBJECT (builder, GTK_ACTION, "redo_action");
 
3041
  priv->action.cut = GET_OBJECT (builder, GTK_ACTION, "cut_action");
 
3042
  priv->action.copy = GET_OBJECT (builder, GTK_ACTION, "copy_action");
 
3043
  priv->action.paste = GET_OBJECT (builder, GTK_ACTION, "paste_action");
 
3044
  priv->action.delete = GET_OBJECT (builder, GTK_ACTION, "delete_action");
 
3045
  priv->action.previous_project = GET_OBJECT (builder, GTK_ACTION, "previous_project_action");
 
3046
  priv->action.next_project = GET_OBJECT (builder, GTK_ACTION, "next_project_action");
 
3047
  priv->action.use_small_icons = GET_OBJECT (builder, GTK_ACTION, "use_small_icons_action");
 
3048
  priv->action.icons_and_labels = GET_OBJECT (builder, GTK_ACTION, "icons_and_labels_radioaction");
 
3049
  priv->action.toolbar_visible = GET_OBJECT (builder, GTK_ACTION, "toolbar_visible_action");
 
3050
  priv->action.project_tabs_visible = GET_OBJECT (builder, GTK_ACTION, "project_tabs_visible_action");
 
3051
  priv->action.statusbar_visible = GET_OBJECT (builder, GTK_ACTION, "statusbar_visible_action");
 
3052
  priv->action.selector = GET_OBJECT (builder, GTK_ACTION, "selector_radioaction");
 
3053
  
3326
3054
  gtk_container_add (GTK_CONTAINER (window), vbox);
3327
 
 
3328
 
  /* editor */
3329
 
  priv->editor = GLADE_EDITOR (glade_editor_new ());
3330
 
  gtk_widget_show (GTK_WIDGET (priv->editor));
3331
 
  g_object_ref_sink (G_OBJECT (priv->editor));
3332
 
 
3333
 
  /* menubar */
3334
 
  menubar = construct_menu (window);
3335
 
  gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, TRUE, 0);
3336
 
  gtk_widget_show (menubar);
3337
 
 
3338
 
  /* toolbar */
3339
 
  priv->toolbar = gtk_ui_manager_get_widget (priv->ui, "/ToolBar");
3340
 
  gtk_style_context_add_class (gtk_widget_get_style_context (priv->toolbar),
3341
 
                               GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
3342
 
  gtk_box_pack_start (GTK_BOX (vbox), priv->toolbar, FALSE, TRUE, 0);
3343
 
  gtk_widget_show (priv->toolbar);
3344
 
 
3345
 
  /* undo/redo buttons */
3346
 
  priv->undo = gtk_menu_tool_button_new_from_stock (GTK_STOCK_UNDO);
3347
 
  priv->redo = gtk_menu_tool_button_new_from_stock (GTK_STOCK_REDO);
3348
 
  gtk_widget_show (GTK_WIDGET (priv->undo));
3349
 
  gtk_widget_show (GTK_WIDGET (priv->redo));
3350
 
  gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON
3351
 
                                               (priv->undo),
3352
 
                                               _("Go back in undo history"));
3353
 
  gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON
3354
 
                                               (priv->redo),
3355
 
                                               _("Go forward in undo history"));
3356
 
 
3357
 
  sep = GTK_WIDGET (gtk_separator_tool_item_new ());
3358
 
  gtk_widget_show (sep);
3359
 
  gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), GTK_TOOL_ITEM (sep), 3);
3360
 
  gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), GTK_TOOL_ITEM (priv->undo),
3361
 
                      4);
3362
 
  gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), GTK_TOOL_ITEM (priv->redo),
3363
 
                      5);
3364
 
 
3365
 
  undo_action = gtk_ui_manager_get_action (priv->ui, "/MenuBar/EditMenu/Undo");
3366
 
  redo_action = gtk_ui_manager_get_action (priv->ui, "/MenuBar/EditMenu/Redo");
3367
 
 
3368
 
  gtk_activatable_set_related_action (GTK_ACTIVATABLE (priv->undo),
3369
 
                                      undo_action);
3370
 
  gtk_activatable_set_related_action (GTK_ACTIVATABLE (priv->redo),
3371
 
                                      redo_action);
3372
 
 
3373
 
  /* main contents */
3374
 
  hpaned1 = gtk_hpaned_new ();
3375
 
  hpaned2 = gtk_hpaned_new ();
3376
 
  vpaned = gtk_vpaned_new ();
3377
 
  priv->center_pane = hpaned1;
3378
 
  priv->left_pane = hpaned2;
3379
 
  priv->right_pane = vpaned;
3380
 
 
3381
 
  gtk_container_set_border_width (GTK_CONTAINER (hpaned1), 2);
3382
 
 
3383
 
  gtk_box_pack_start (GTK_BOX (vbox), hpaned1, TRUE, TRUE, 0);
3384
 
  gtk_paned_pack1 (GTK_PANED (hpaned1), hpaned2, TRUE, FALSE);
3385
 
  gtk_paned_pack2 (GTK_PANED (hpaned1), vpaned, FALSE, FALSE);
3386
 
 
3387
 
  /* divider position between tree and editor */
3388
 
  gtk_paned_set_position (GTK_PANED (vpaned), 150);
3389
 
 
3390
 
  gtk_widget_show_all (hpaned1);
3391
 
  gtk_widget_show_all (hpaned2);
3392
 
  gtk_widget_show_all (vpaned);
3393
 
 
3394
 
  /* notebook */
3395
 
  priv->notebook = gtk_notebook_new ();
3396
 
  gtk_notebook_set_scrollable (GTK_NOTEBOOK (priv->notebook), TRUE);
3397
 
 
3398
 
  /* Show tabs (user preference) */
3399
 
  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), TRUE);
3400
 
  gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
3401
 
  gtk_paned_pack2 (GTK_PANED (hpaned2), priv->notebook, TRUE, FALSE);
3402
 
  gtk_widget_show (priv->notebook);
3403
 
 
3404
 
  /* palettes */
3405
 
  priv->palettes_notebook = gtk_notebook_new ();
3406
 
  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->palettes_notebook), FALSE);
3407
 
  gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->palettes_notebook), FALSE);
3408
 
  gtk_paned_pack1 (GTK_PANED (hpaned2), priv->palettes_notebook, FALSE, FALSE);
 
3055
  
 
3056
  /* Setup Docks */
3409
3057
  setup_dock (&priv->docks[DOCK_PALETTE], priv->palettes_notebook, 200, 540,
3410
 
              _("Palette"), "palette", hpaned2, TRUE);
3411
 
  gtk_widget_show (priv->palettes_notebook);
3412
 
 
3413
 
  /* inspectors */
3414
 
  priv->inspectors_notebook = gtk_notebook_new ();
3415
 
  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->inspectors_notebook), FALSE);
3416
 
  gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->inspectors_notebook), FALSE);
3417
 
  gtk_widget_show (priv->inspectors_notebook);
3418
 
  gtk_paned_pack1 (GTK_PANED (vpaned), priv->inspectors_notebook, FALSE, FALSE);
 
3058
              _("Palette"), "palette", priv->left_pane, TRUE);
3419
3059
  setup_dock (&priv->docks[DOCK_INSPECTOR], priv->inspectors_notebook, 300, 540,
3420
 
              _("Inspector"), "inspector", vpaned, TRUE);
3421
 
 
3422
 
  /* editor */
3423
 
  dockitem = GTK_WIDGET (priv->editor);
3424
 
  gtk_paned_pack2 (GTK_PANED (vpaned), dockitem, TRUE, FALSE);
3425
 
  gtk_widget_show_all (dockitem);
3426
 
  setup_dock (&priv->docks[DOCK_EDITOR], dockitem, 500, 700,
3427
 
              _("Properties"), "properties", vpaned, FALSE);
3428
 
 
3429
 
  show_dock_first_time (window, DOCK_PALETTE, "DockPalette");
3430
 
  show_dock_first_time (window, DOCK_INSPECTOR, "DockInspector");
3431
 
  show_dock_first_time (window, DOCK_EDITOR, "DockEditor");
 
3060
              _("Inspector"), "inspector", priv->right_pane, TRUE);
 
3061
  setup_dock (&priv->docks[DOCK_EDITOR], GTK_WIDGET (priv->editor), 500, 700,
 
3062
              _("Properties"), "properties", priv->right_pane, FALSE);
 
3063
  show_dock_first_time (window, DOCK_PALETTE, GET_OBJECT (builder, GTK_ACTION, "dock_palette_action"));
 
3064
  show_dock_first_time (window, DOCK_INSPECTOR, GET_OBJECT (builder, GTK_ACTION, "dock_inspector_action"));
 
3065
  show_dock_first_time (window, DOCK_EDITOR, GET_OBJECT (builder, GTK_ACTION, "dock_editor_action"));
3432
3066
 
3433
3067
  /* status bar */
3434
 
  priv->statusbar = gtk_statusbar_new ();
3435
 
  priv->statusbar_menu_context_id =
3436
 
      gtk_statusbar_get_context_id (GTK_STATUSBAR (priv->statusbar), "menu");
3437
 
  priv->statusbar_actions_context_id =
3438
 
      gtk_statusbar_get_context_id (GTK_STATUSBAR (priv->statusbar), "actions");
3439
 
  gtk_box_pack_end (GTK_BOX (vbox), priv->statusbar, FALSE, TRUE, 0);
3440
 
  gtk_widget_show (priv->statusbar);
3441
 
 
3442
 
 
3443
 
  gtk_widget_show (vbox);
3444
 
 
3445
 
  /* recent files */
3446
 
  priv->recent_manager = gtk_recent_manager_get_default ();
3447
 
 
3448
 
  priv->recent_menu = create_recent_chooser_menu (window, priv->recent_manager);
3449
 
 
3450
 
  g_signal_connect (priv->recent_menu,
3451
 
                    "item-activated",
3452
 
                    G_CALLBACK (recent_chooser_item_activated_cb), window);
3453
 
 
3454
 
  widget = gtk_ui_manager_get_widget (priv->ui, "/MenuBar/FileMenu/OpenRecent");
3455
 
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget), priv->recent_menu);
3456
 
 
3457
 
  /* palette selector & drag/resize buttons */
3458
 
  sep = GTK_WIDGET (gtk_separator_tool_item_new ());
3459
 
  gtk_widget_show (GTK_WIDGET (sep));
3460
 
  gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), GTK_TOOL_ITEM (sep), -1);
3461
 
   
3462
 
  priv->selector_button = create_tool_button (GTK_TOOLBAR (priv->toolbar),
3463
 
                                              NULL,
3464
 
                                              _("Select"),
3465
 
                                              _("Select widgets in the workspace"),
3466
 
                                              GLADE_POINTER_SELECT);
3467
 
  priv->drag_resize_button = create_tool_button (GTK_TOOLBAR (priv->toolbar),
3468
 
                                                 priv->selector_button,
3469
 
                                                 _("Drag Resize"),
3470
 
                                                 _("Drag and resize widgets in the workspace"),
3471
 
                                                 GLADE_POINTER_DRAG_RESIZE);
3472
 
  priv->margin_edit_button = create_tool_button (GTK_TOOLBAR (priv->toolbar),
3473
 
                                                 priv->selector_button,
3474
 
                                                 _("Margin Edit"),
3475
 
                                                 _("Edit widget margins"),
3476
 
                                                 GLADE_POINTER_MARGIN_EDIT);
3477
 
  priv->align_edit_button = create_tool_button (GTK_TOOLBAR (priv->toolbar),
3478
 
                                                priv->selector_button,
3479
 
                                                 _("Alignment Edit"),
3480
 
                                                 _("Edit widget alignment"),
3481
 
                                                GLADE_POINTER_ALIGN_EDIT);
 
3068
  priv->statusbar_menu_context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (priv->statusbar), "menu");
 
3069
  priv->statusbar_actions_context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (priv->statusbar), "actions");
3482
3070
 
3483
3071
  /* support for opening a file by dragging onto the project window */
3484
3072
  gtk_drag_dest_set (GTK_WIDGET (window),
3489
3077
  g_signal_connect (G_OBJECT (window), "drag-data-received",
3490
3078
                    G_CALLBACK (drag_data_received), window);
3491
3079
 
3492
 
  g_signal_connect (G_OBJECT (window), "delete_event",
 
3080
  g_signal_connect (G_OBJECT (window), "delete-event",
3493
3081
                    G_CALLBACK (delete_event), window);
3494
3082
 
3495
 
 
3496
 
  /* GtkNotebook signals  */
3497
 
  g_signal_connect (priv->notebook,
3498
 
                    "switch-page",
3499
 
                    G_CALLBACK (notebook_switch_page_cb), window);
3500
 
  g_signal_connect (priv->notebook,
3501
 
                    "page-added", G_CALLBACK (notebook_tab_added_cb), window);
3502
 
  g_signal_connect (priv->notebook,
3503
 
                    "page-removed",
3504
 
                    G_CALLBACK (notebook_tab_removed_cb), window);
3505
 
 
3506
3083
  /* GtkWindow events */
3507
3084
  g_signal_connect (G_OBJECT (window), "key-press-event",
3508
3085
                    G_CALLBACK (glade_utils_hijack_key_press), window);
3514
3091
 
3515
3092
  glade_app_set_window (GTK_WIDGET (window));
3516
3093
 
 
3094
  gtk_builder_connect_signals (builder, window);
 
3095
 
3517
3096
  glade_window_config_load (window);
3518
3097
 
3519
3098
#ifdef MAC_INTEGRATION
3520
 
  {
3521
 
    /* Fix up the menubar for MacOSX Quartz builds */
3522
 
    GtkWidget *sep;
3523
 
    GtkOSXApplication *theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
3524
 
    gtk_widget_hide (menubar);
3525
 
    gtk_osxapplication_set_menu_bar(theApp, GTK_MENU_SHELL(menubar));
3526
 
    widget =
3527
 
        gtk_ui_manager_get_widget (window->priv->ui, "/MenuBar/FileMenu/Quit");
3528
 
    gtk_widget_hide (widget);
3529
 
    widget =
3530
 
        gtk_ui_manager_get_widget (window->priv->ui, "/MenuBar/HelpMenu/About");
3531
 
    gtk_osxapplication_insert_app_menu_item (theApp, widget, 0);
3532
 
    sep = gtk_separator_menu_item_new();
3533
 
    g_object_ref(sep);
3534
 
    gtk_osxapplication_insert_app_menu_item (theApp, sep, 1);
3535
 
 
3536
 
    widget =
3537
 
        gtk_ui_manager_get_widget (window->priv->ui, "/MenuBar/FileMenu/Properties");
3538
 
    gtk_osxapplication_insert_app_menu_item  (theApp, widget, 2);
3539
 
    sep = gtk_separator_menu_item_new();
3540
 
    g_object_ref(sep);
3541
 
    gtk_osxapplication_insert_app_menu_item (theApp, sep, 3);
3542
 
 
3543
 
    widget =
3544
 
        gtk_ui_manager_get_widget (window->priv->ui, "/MenuBar/HelpMenu");
3545
 
    gtk_osxapplication_set_help_menu(theApp, GTK_MENU_ITEM(widget));
3546
 
 
3547
 
    g_signal_connect(theApp, "NSApplicationWillTerminate",
3548
 
                     G_CALLBACK(quit_cb), window);
3549
 
 
3550
 
    gtk_osxapplication_ready(theApp);
3551
 
  }
 
3099
        {
 
3100
          /* Fix up the menubar for MacOSX Quartz builds */
 
3101
          GtkWidget *menubar =GTK_WIDGET (gtk_builder_get_object (builder, "menubar"));
 
3102
 
 
3103
          GtkWidget *sep;
 
3104
          GtkOSXApplication *theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
 
3105
          gtk_widget_hide (menubar);
 
3106
          gtk_osxapplication_set_menu_bar(theApp, GTK_MENU_SHELL(menubar));
 
3107
          widget =
 
3108
                gtk_ui_manager_get_widget (window->priv->ui, "/MenuBar/FileMenu/Quit");
 
3109
          gtk_widget_hide (widget);
 
3110
          widget =
 
3111
                gtk_ui_manager_get_widget (window->priv->ui, "/MenuBar/HelpMenu/About");
 
3112
          gtk_osxapplication_insert_app_menu_item (theApp, widget, 0);
 
3113
          sep = gtk_separator_menu_item_new();
 
3114
          g_object_ref(sep);
 
3115
          gtk_osxapplication_insert_app_menu_item (theApp, sep, 1);
 
3116
 
 
3117
          widget =
 
3118
                gtk_ui_manager_get_widget (window->priv->ui, "/MenuBar/FileMenu/Properties");
 
3119
          gtk_osxapplication_insert_app_menu_item  (theApp, widget, 2);
 
3120
          sep = gtk_separator_menu_item_new();
 
3121
          g_object_ref(sep);
 
3122
          gtk_osxapplication_insert_app_menu_item (theApp, sep, 3);
 
3123
 
 
3124
          widget =
 
3125
                gtk_ui_manager_get_widget (window->priv->ui, "/MenuBar/HelpMenu");
 
3126
          gtk_osxapplication_set_help_menu(theApp, GTK_MENU_ITEM(widget));
 
3127
 
 
3128
          g_signal_connect(theApp, "NSApplicationWillTerminate",
 
3129
                           G_CALLBACK(on_quit_action_activate), window);
 
3130
 
 
3131
          gtk_osxapplication_ready(theApp);
 
3132
        }
3552
3133
#endif
3553
 
 
3554
 
 
 
3134
  g_object_unref (builder);
3555
3135
}
3556
3136
 
3557
3137
static void
3558
 
glade_window_class_init (GladeWindowClass * klass)
 
3138
glade_window_class_init (GladeWindowClass *klass)
3559
3139
{
3560
3140
  GObjectClass *object_class;
3561
3141
  GtkWidgetClass *widget_class;
3564
3144
  object_class = G_OBJECT_CLASS (klass);
3565
3145
  widget_class = GTK_WIDGET_CLASS (klass);
3566
3146
 
 
3147
  object_class->constructed = glade_window_constructed;
3567
3148
  object_class->dispose = glade_window_dispose;
3568
3149
  object_class->finalize = glade_window_finalize;
3569
3150
 
3594
3175
}
3595
3176
 
3596
3177
void
3597
 
glade_window_check_devhelp (GladeWindow * window)
 
3178
glade_window_check_devhelp (GladeWindow *window)
3598
3179
{
3599
3180
  g_return_if_fail (GLADE_IS_WINDOW (window));
3600
3181