[glade3] * src/glade-window.c: Added one palette per project, setting the palette's project requires that e



commit fc47ae2d045736b853b010510a428a680b55e07b
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Thu Jan 6 17:25:50 2011 +0900

    	* src/glade-window.c: Added one palette per project, setting the palette's project
    	requires that every item update itself for the support for the project target version,
    	this was causing notebook page switches between projects to be very slow (actually
    	costing an entire second), with one palette for each project the project switch
    	is drastically improved.

 ChangeLog          |    6 +++
 src/glade-window.c |  115 ++++++++++++++++++++++++++++++---------------------
 2 files changed, 74 insertions(+), 47 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4f033ad..44e2dd2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,12 @@
 	* gladeui/glade-project.c: Show selected widget when selection changes and
 	Cancel any queued selection from glade_project_selection_changed.
 
+	* src/glade-window.c: Added one palette per project, setting the palette's project
+	requires that every item update itself for the support for the project target version,
+	this was causing notebook page switches between projects to be very slow (actually
+	costing an entire second), with one palette for each project the project switch
+	is drastically improved.
+
 2011-01-05  Tristan Van Berkom <tristanvb openismus com>
 
 	* gladeui/Makefile.am, gladeui/glade-signal-class.[ch], gladeui/glade-widget-adaptor.c,
diff --git a/src/glade-window.c b/src/glade-window.c
index 2b26fef..ef5614d 100644
--- a/src/glade-window.c
+++ b/src/glade-window.c
@@ -101,16 +101,16 @@ struct _GladeWindowPrivate
   GladeDesignView *active_view;
   gint num_tabs;
 
-  GtkWidget *inspectors_notebook;
+  GtkWidget *palettes_notebook;         /* Cached per project palettes */
+  GtkWidget *inspectors_notebook;       /* Cached per project inspectors */
 
   GladeEditor  *editor;                 /* The editor */
-  GladePalette *palette;                /* The palette */
 
   GtkWidget *statusbar;                 /* A pointer to the status bar. */
   guint statusbar_menu_context_id;      /* The context id of the menu bar */
   guint statusbar_actions_context_id;   /* The context id of actions messages */
 
-  GtkUIManager *ui;             /* The UIManager */
+  GtkUIManager *ui;                     /* The UIManager */
   guint projects_list_menu_ui_id;       /* Merge id for projects list menu */
 
   GtkActionGroup *static_actions;       /* All the static actions */
@@ -499,8 +499,6 @@ project_selection_changed_cb (GladeProject * project, GladeWindow * window)
         {
           glade_widget = glade_widget_get_from_gobject (G_OBJECT (list->data));
 
-          glade_widget_show (glade_widget);
-
           clean_actions (window);
           if (glade_widget_get_actions (glade_widget))
             add_actions (window, glade_widget, glade_widget_get_actions (glade_widget));
@@ -1675,14 +1673,16 @@ notebook_switch_page_cb (GtkNotebook * notebook,
 
   project = glade_design_view_get_project (view);
 
-  glade_palette_set_project (window->priv->palette, project);
-
   refresh_title (window);
+
   set_sensitivity_according_to_project (window, project);
 
-  /* switch to the project's inspector */
+  /* switch to the project's inspector/palette */
   gtk_notebook_set_current_page (GTK_NOTEBOOK
                                  (window->priv->inspectors_notebook), page_num);
+  gtk_notebook_set_current_page (GTK_NOTEBOOK
+                                 (window->priv->palettes_notebook), page_num);
+
 
   /* activate the corresponding item in the project menu */
   action_name = g_strdup_printf ("Tab_%d", page_num);
@@ -1719,7 +1719,8 @@ notebook_tab_added_cb (GtkNotebook * notebook,
                        guint page_num, GladeWindow * window)
 {
   GladeProject *project;
-  GtkWidget *inspector;
+  GtkWidget *inspector, *palette;
+  GtkAction *action;
 
   ++window->priv->num_tabs;
 
@@ -1748,18 +1749,37 @@ notebook_tab_added_cb (GtkNotebook * notebook,
   inspector = glade_inspector_new ();
   gtk_widget_show (inspector);
   glade_inspector_set_project (GLADE_INSPECTOR (inspector), project);
+  gtk_notebook_append_page (GTK_NOTEBOOK (window->priv->inspectors_notebook),
+                            inspector, NULL);
+
+  /* create palette */
+  palette = glade_palette_new ();
+  gtk_widget_show (palette);
+  glade_palette_set_show_selector_button (GLADE_PALETTE (palette), FALSE);
+  glade_palette_set_project (GLADE_PALETTE (palette), project);
+
+  action = gtk_action_group_get_action (window->priv->static_actions, "UseSmallIcons");
+  glade_palette_set_use_small_item_icons (GLADE_PALETTE (palette),
+					  gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
+
+  action = gtk_action_group_get_action (window->priv->static_actions, "IconsAndLabels");
+  glade_palette_set_item_appearance (GLADE_PALETTE (palette),
+				     gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)));
+
+  gtk_notebook_append_page (GTK_NOTEBOOK (window->priv->palettes_notebook),
+                            palette, NULL);
 
   if (GPOINTER_TO_INT
       (g_object_get_data (G_OBJECT (view), "view-added-while-loading")))
     {
       gtk_widget_set_sensitive (inspector, FALSE);
+      gtk_widget_set_sensitive (palette, FALSE);
       g_signal_connect (project, "parse-finished",
                         G_CALLBACK (set_widget_sensitive_on_load), inspector);
+      g_signal_connect (project, "parse-finished",
+                        G_CALLBACK (set_widget_sensitive_on_load), palette);
     }
 
-  gtk_notebook_append_page (GTK_NOTEBOOK (window->priv->inspectors_notebook),
-                            inspector, NULL);
-
   set_sensitivity_according_to_project (window, project);
 
   refresh_projects_list_menu (window);
@@ -1784,10 +1804,6 @@ notebook_tab_removed_cb (GtkNotebook     *notebook,
   if (window->priv->num_tabs == 0)
     {
       gtk_widget_set_sensitive (GTK_WIDGET (window->priv->editor), FALSE);
-      gtk_widget_set_sensitive (GTK_WIDGET (window->priv->palette), FALSE);
-
-      glade_palette_set_project (window->priv->palette, NULL);
-
       window->priv->active_view = NULL;
     }
 
@@ -1809,8 +1825,8 @@ notebook_tab_removed_cb (GtkNotebook     *notebook,
                                         G_CALLBACK (on_pointer_mode_changed),
                                         window);
 
-  gtk_notebook_remove_page (GTK_NOTEBOOK (window->priv->inspectors_notebook),
-                            page_num);
+  gtk_notebook_remove_page (GTK_NOTEBOOK (window->priv->inspectors_notebook), page_num);
+  gtk_notebook_remove_page (GTK_NOTEBOOK (window->priv->palettes_notebook), page_num);
 
   clean_actions (window);
 
@@ -1860,23 +1876,38 @@ recent_chooser_item_activated_cb (GtkRecentChooser * chooser,
 }
 
 static void
-palette_appearance_change_cb (GtkRadioAction * action,
-                              GtkRadioAction * current, GladeWindow * window)
+palette_appearance_change_cb (GtkRadioAction *action,
+                              GtkRadioAction *current, 
+			      GladeWindow    *window)
 {
+  GList *children, *l;
   gint value;
 
   value = gtk_radio_action_get_current_value (action);
 
-  glade_palette_set_item_appearance (window->priv->palette, value);
-
+  children = gtk_container_get_children (GTK_CONTAINER (window->priv->palettes_notebook));
+  for (l = children; l; l = l->next)
+    {
+      if (GLADE_IS_PALETTE (l->data))
+	glade_palette_set_item_appearance (GLADE_PALETTE (l->data), value);
+    }
+  g_list_free (children);
 }
 
 static void
 palette_toggle_small_icons_cb (GtkAction * action, GladeWindow * window)
 {
-  glade_palette_set_use_small_item_icons (window->priv->palette,
-                                          gtk_toggle_action_get_active
-                                          (GTK_TOGGLE_ACTION (action)));
+  GList *children, *l;
+
+  children = gtk_container_get_children (GTK_CONTAINER (window->priv->palettes_notebook));
+  for (l = children; l; l = l->next)
+    {
+      if (GLADE_IS_PALETTE (l->data))
+	glade_palette_set_use_small_item_icons (GLADE_PALETTE (l->data),
+						gtk_toggle_action_get_active
+						(GTK_TOGGLE_ACTION (action)));
+    }
+  g_list_free (children);
 }
 
 static gboolean
@@ -3231,19 +3262,13 @@ glade_window_config_load (GladeWindow * window)
 
   gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->priv->notebook), show_tabs);
 
-  action =
-      gtk_action_group_get_action (window->priv->static_actions,
-                                   "ToolbarVisible");
+  action = gtk_action_group_get_action (window->priv->static_actions, "ToolbarVisible");
   gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), show_toolbar);
 
-  action =
-      gtk_action_group_get_action (window->priv->static_actions,
-                                   "ProjectTabsVisible");
+  action = gtk_action_group_get_action (window->priv->static_actions, "ProjectTabsVisible");
   gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), show_tabs);
 
-  action =
-      gtk_action_group_get_action (window->priv->static_actions,
-                                   "StatusbarVisible");
+  action = gtk_action_group_get_action (window->priv->static_actions, "StatusbarVisible");
   gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), show_tabs);
 
   /* Paned positions */
@@ -3311,7 +3336,6 @@ glade_window_init (GladeWindow * window)
   GtkWidget *hpaned2;
   GtkWidget *vpaned;
   GtkWidget *menubar;
-  GtkWidget *palette;
   GtkWidget *dockitem;
   GtkWidget *widget;
   GtkWidget *sep;
@@ -3328,12 +3352,9 @@ glade_window_init (GladeWindow * window)
 
   /* editor */
   priv->editor = GLADE_EDITOR (glade_editor_new ());
+  gtk_widget_show (GTK_WIDGET (priv->editor));
   g_object_ref_sink (G_OBJECT (priv->editor));
 
-  /* palette */
-  priv->palette = GLADE_PALETTE (glade_palette_new ());
-  g_object_ref_sink (G_OBJECT (priv->palette));
-
   /* menubar */
   menubar = construct_menu (window);
   gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, TRUE, 0);
@@ -3403,19 +3424,19 @@ glade_window_init (GladeWindow * window)
   gtk_paned_pack2 (GTK_PANED (hpaned2), priv->notebook, TRUE, FALSE);
   gtk_widget_show (priv->notebook);
 
-  /* palette */
-  palette = GTK_WIDGET (priv->palette);
-  glade_palette_set_show_selector_button (GLADE_PALETTE (palette), FALSE);
-  gtk_paned_pack1 (GTK_PANED (hpaned2), palette, FALSE, FALSE);
-  setup_dock (&priv->docks[DOCK_PALETTE], palette, 200, 540,
+  /* palettes */
+  priv->palettes_notebook = gtk_notebook_new ();
+  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->palettes_notebook), FALSE);
+  gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->palettes_notebook), FALSE);
+  gtk_paned_pack1 (GTK_PANED (hpaned2), priv->palettes_notebook, FALSE, FALSE);
+  setup_dock (&priv->docks[DOCK_PALETTE], priv->palettes_notebook, 200, 540,
               _("Palette"), "palette", hpaned2, TRUE);
-  gtk_widget_show (palette);
+  gtk_widget_show (priv->palettes_notebook);
 
   /* inspectors */
   priv->inspectors_notebook = gtk_notebook_new ();
   gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->inspectors_notebook), FALSE);
-  gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->inspectors_notebook),
-                                FALSE);
+  gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->inspectors_notebook), FALSE);
   gtk_widget_show (priv->inspectors_notebook);
   gtk_paned_pack1 (GTK_PANED (vpaned), priv->inspectors_notebook, FALSE, FALSE);
   setup_dock (&priv->docks[DOCK_INSPECTOR], priv->inspectors_notebook, 300, 540,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]