[gtranslator] Sync toolbareditor from upstream



commit 0b231a89adf47f745aaaf1185be85ce7ca3f4b15
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Mon Mar 28 20:56:54 2011 +0200

    Sync toolbareditor from upstream

 src/gtr-window.c                         |    3 -
 src/toolbareditor/egg-editable-toolbar.c |   86 +++++++++++++++++++++++++++---
 src/toolbareditor/egg-editable-toolbar.h |    4 ++
 src/toolbareditor/egg-toolbar-editor.c   |   10 +++-
 src/toolbareditor/egg-toolbars-model.c   |   18 ++++++
 5 files changed, 108 insertions(+), 13 deletions(-)
---
diff --git a/src/gtr-window.c b/src/gtr-window.c
index 9501d0b..4583d64 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -1722,9 +1722,6 @@ gtr_window_draw (GtrWindow * window)
                    "model",
                    _gtr_application_get_toolbars_model (GTR_APP), NULL));
 
-  gtk_style_context_add_class (gtk_widget_get_style_context (priv->toolbar),
-                               GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
-
   egg_editable_toolbar_show (EGG_EDITABLE_TOOLBAR (priv->toolbar),
                              "DefaultToolBar");
   gtk_box_pack_start (GTK_BOX (priv->main_box),
diff --git a/src/toolbareditor/egg-editable-toolbar.c b/src/toolbareditor/egg-editable-toolbar.c
index ddb24d6..1a756fc 100644
--- a/src/toolbareditor/egg-editable-toolbar.c
+++ b/src/toolbareditor/egg-editable-toolbar.c
@@ -79,6 +79,9 @@ struct _EggEditableToolbarPrivate
   guint        dnd_pending;
   GtkToolbar  *dnd_toolbar;
   GtkToolItem *dnd_toolitem;
+
+  gboolean set_primary_class;
+  gchar *primary_name;
 };
 
 G_DEFINE_TYPE (EggEditableToolbar, egg_editable_toolbar, GTK_TYPE_VBOX);
@@ -439,7 +442,11 @@ configure_item_cursor (GtkToolItem *item,
           cursor = gdk_cursor_new_for_display (gdk_screen_get_display (screen),
 					       GDK_HAND2);
           gdk_window_set_cursor (window, cursor);
+#if GTK_CHECK_VERSION (3,0,0)
+          g_object_unref (cursor);
+#else
           gdk_cursor_unref (cursor);
+#endif
 
           gtk_drag_source_set (widget, GDK_BUTTON1_MASK, dest_drag_types,
                                G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE);
@@ -487,8 +494,8 @@ configure_item_cursor (GtkToolItem *item,
                 }
               else if (stock_id)
                 {
-                  pixbuf = gtk_widget_render_icon (widget, stock_id,
-	                                           GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
+                  pixbuf = gtk_widget_render_icon_pixbuf (widget, stock_id,
+                                                          GTK_ICON_SIZE_LARGE_TOOLBAR);
                 }
               g_free (icon_name);
               g_free (stock_id);
@@ -858,6 +865,10 @@ toolbar_visibility_refresh (EggEditableToolbar *etoolbar)
   char action_name[40];
   char *action_label;
   char *tmp;
+  gboolean primary_class_set;
+  GtkStyleContext *context;
+  const gchar *toolbar_name;
+  gboolean visible;
 
   if (priv == NULL || priv->model == NULL || priv->manager == NULL ||
       priv->visibility_paths == NULL || priv->actions == NULL)
@@ -883,9 +894,12 @@ toolbar_visibility_refresh (EggEditableToolbar *etoolbar)
   showing = GTK_WIDGET_VISIBLE (etoolbar);
 #endif
 
+  primary_class_set = !priv->set_primary_class;
+
   n_toolbars = egg_toolbars_model_n_toolbars (priv->model);
   for (i = 0; i < n_toolbars; i++)
     {
+      toolbar_name = egg_toolbars_model_toolbar_nth (priv->model, i);
       string = g_string_sized_new (0);
       n_items = egg_toolbars_model_n_items (priv->model, i);
       for (k = 0, j = 0; j < n_items; j++)
@@ -963,14 +977,33 @@ toolbar_visibility_refresh (EggEditableToolbar *etoolbar)
       gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
 						    & EGG_TB_MODEL_NOT_REMOVABLE) == 0);
       gtk_action_set_sensitive (GTK_ACTION (action), showing);
+
 #if GTK_CHECK_VERSION(2,20,0)
-      gtk_toggle_action_set_active (action, gtk_widget_get_visible
-				    (get_dock_nth (etoolbar, i)));
+      visible = gtk_widget_get_visible (get_dock_nth (etoolbar, i));
 #else
-      gtk_toggle_action_set_active (action, GTK_WIDGET_VISIBLE
-				    (get_dock_nth (etoolbar, i)));
+      visible = GTK_WIDGET_VISIBLE (get_dock_nth (etoolbar, i));
 #endif
 
+      gtk_toggle_action_set_active (action, visible);
+      context = gtk_widget_get_style_context (get_toolbar_nth (etoolbar, i));
+
+      /* apply the primary toolbar class to the first toolbar we see,
+       * or to that specified by the primary name, if any.
+       */
+      if (!primary_class_set && visible &&
+          ((g_strcmp0 (priv->primary_name, toolbar_name) == 0) ||
+           (priv->primary_name == NULL)))
+        {
+          primary_class_set = TRUE;
+          gtk_style_context_add_class (context, GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
+        }
+      else
+        {
+          gtk_style_context_remove_class (context, GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
+        }
+
+      gtk_widget_reset_style (get_toolbar_nth (etoolbar, i));
+
       for (list = priv->visibility_paths; list != NULL; list = g_list_next (list))
         {
 	  gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
@@ -1381,6 +1414,9 @@ egg_editable_toolbar_dispose (GObject *object)
   g_free (priv->popup_path);
   priv->popup_path = NULL;
 
+  g_free (priv->primary_name);
+  priv->primary_name = NULL;
+
   if (priv->manager != NULL)
     {
       if (priv->visibility_id)
@@ -1428,6 +1464,12 @@ egg_editable_toolbar_set_ui_manager (EggEditableToolbar *etoolbar,
   toolbar_visibility_refresh (etoolbar);
 }
 
+/**
+ * egg_editable_toolbar_get_selected:
+ * @etoolbar:
+ *
+ * Returns: (transfer none):
+ **/
 GtkWidget * egg_editable_toolbar_get_selected (EggEditableToolbar   *etoolbar)
 {
   return etoolbar->priv->selected;
@@ -1784,7 +1826,7 @@ new_separator_pixbuf (void)
   GtkWidget *separator;
   GdkPixbuf *pixbuf;
 
-  separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
+  separator = gtk_vseparator_new ();
   pixbuf = new_pixbuf_from_widget (separator);
   return pixbuf;
 }
@@ -1818,8 +1860,38 @@ _egg_editable_toolbar_new_separator_image (void)
   return image;
 }
 
+/**
+ * egg_editable_toolbar_get_model:
+ * @etoolbar:
+ *
+ * Returns: (transfer none):
+ **/
 EggToolbarsModel *
 egg_editable_toolbar_get_model (EggEditableToolbar *etoolbar)
 {
   return etoolbar->priv->model;
 }
+
+/**
+ * egg_editable_toolbar_get_manager:
+ *
+ * Return value: (transfer none):
+ */
+GtkUIManager *
+egg_editable_toolbar_get_manager (EggEditableToolbar *etoolbar)
+{
+  return etoolbar->priv->manager;
+}
+
+void
+egg_editable_toolbar_set_primary_class (EggEditableToolbar *etoolbar,
+                                        gboolean set,
+                                        const gchar *name)
+{
+  etoolbar->priv->set_primary_class = set;
+
+  g_free (etoolbar->priv->primary_name);
+  etoolbar->priv->primary_name = g_strdup (name);
+
+  toolbar_visibility_refresh (etoolbar);
+}
diff --git a/src/toolbareditor/egg-editable-toolbar.h b/src/toolbareditor/egg-editable-toolbar.h
index 8537ba8..b08f68a 100644
--- a/src/toolbareditor/egg-editable-toolbar.h
+++ b/src/toolbareditor/egg-editable-toolbar.h
@@ -82,6 +82,10 @@ void                egg_editable_toolbar_set_selected    (EggEditableToolbar   *
 void              egg_editable_toolbar_add_visibility    (EggEditableToolbar   *etoolbar,
 							  const char           *path);
 
+void              egg_editable_toolbar_set_primary_class (EggEditableToolbar *etoolbar,
+                                                          gboolean            set,
+                                                          const gchar        *path);
+
 /* Private Functions */
 
 GtkWidget 	   *_egg_editable_toolbar_new_separator_image (void);
diff --git a/src/toolbareditor/egg-toolbar-editor.c b/src/toolbareditor/egg-toolbar-editor.c
index 30f6bfd..bf76ca8 100644
--- a/src/toolbareditor/egg-toolbar-editor.c
+++ b/src/toolbareditor/egg-toolbar-editor.c
@@ -363,7 +363,11 @@ set_drag_cursor (GtkWidget *widget)
   cursor = gdk_cursor_new_for_display (gdk_screen_get_display (screen),
 				       GDK_HAND2);
   gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
+#if GTK_CHECK_VERSION (3,0,0)
+  g_object_unref (cursor);
+#else
   gdk_cursor_unref (cursor);
+#endif
 }
 
 static void
@@ -380,8 +384,8 @@ event_box_realize_cb (GtkWidget *widget, GtkImage *icon)
       GdkPixbuf *pixbuf;
 
       gtk_image_get_stock (icon, &stock_id, NULL);
-      pixbuf = gtk_widget_render_icon (widget, stock_id,
-	                               GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
+      pixbuf = gtk_widget_render_icon_pixbuf (widget, stock_id,
+                                              GTK_ICON_SIZE_LARGE_TOOLBAR);
       gtk_drag_source_set_icon_pixbuf (widget, pixbuf);
       g_object_unref (pixbuf);
     }
@@ -543,7 +547,7 @@ append_table (GtkTable *table, GList *items, gint y, gint width)
 
       if (y > 0)
         {
-          item = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+          item = gtk_hseparator_new ();
           alignment = gtk_alignment_new (0.5, 0.5, 1.0, 0.0);
           gtk_container_add (GTK_CONTAINER (alignment), item);
           gtk_widget_show (alignment);
diff --git a/src/toolbareditor/egg-toolbars-model.c b/src/toolbareditor/egg-toolbars-model.c
index b9a5f44..31a6d5e 100644
--- a/src/toolbareditor/egg-toolbars-model.c
+++ b/src/toolbareditor/egg-toolbars-model.c
@@ -946,12 +946,24 @@ egg_toolbars_model_toolbar_nth (EggToolbarsModel *model,
   return tdata->name;
 }
 
+/**
+ * egg_toolbars_model_get_types:
+ * @model:
+ *
+ * Returns: (transfer none) (element-type EggToolbarsItemType):
+ */
 GList *
 egg_toolbars_model_get_types (EggToolbarsModel *model)
 {
   return model->priv->types;
 }
 
+/**
+ * egg_toolbars_model_set_types:
+ * @model:
+ * @types: (element-type EggToolbarsItemType):
+ *
+ */
 void
 egg_toolbars_model_set_types (EggToolbarsModel *model, GList *types)
 {
@@ -966,6 +978,12 @@ fill_avail_array (gpointer key, gpointer value, GPtrArray *array)
       g_ptr_array_add (array, key);
 }
 
+/**
+ * egg_toolbars_model_get_name_avail:
+ * @model:
+ *
+ * Returns: (element-type utf8) (transfer container):
+ */
 GPtrArray *
 egg_toolbars_model_get_name_avail (EggToolbarsModel *model)
 {



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