[libgd] main-toolbar: add a set_labels_menu() method
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgd] main-toolbar: add a set_labels_menu() method
- Date: Thu, 30 Aug 2012 01:59:07 +0000 (UTC)
commit 34075dfa480e645165d6da60d87bc623ecbdb2d9
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Aug 27 22:09:58 2012 -0400
main-toolbar: add a set_labels_menu() method
This method adds a menu to the labels section in the center of the
toolbar. It can be disabled by setting the model back to NULL.
https://bugzilla.gnome.org/show_bug.cgi?id=677050
libgd/gd-main-toolbar.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++-
libgd/gd-main-toolbar.h | 3 ++
2 files changed, 67 insertions(+), 1 deletions(-)
---
diff --git a/libgd/gd-main-toolbar.c b/libgd/gd-main-toolbar.c
index 9f1ef56..a6b35cf 100644
--- a/libgd/gd-main-toolbar.c
+++ b/libgd/gd-main-toolbar.c
@@ -42,9 +42,13 @@ struct _GdMainToolbarPrivate {
GtkWidget *left_grid;
+ GtkWidget *labels_grid;
GtkWidget *title_label;
GtkWidget *detail_label;
+ GtkWidget *center_menu;
+ GtkWidget *center_menu_child;
+
GtkWidget *right_grid;
};
@@ -205,7 +209,7 @@ gd_main_toolbar_constructed (GObject *obj)
GTK_WIDGET (self->priv->center_group));
/* centered label group */
- grid = gtk_grid_new ();
+ self->priv->labels_grid = grid = gtk_grid_new ();
gtk_widget_set_halign (grid, GTK_ALIGN_CENTER);
gtk_widget_set_valign (grid, GTK_ALIGN_CENTER);
gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
@@ -351,6 +355,65 @@ add_button_internal (GdMainToolbar *self,
}
/**
+ * gd_main_toolbar_set_labels_menu:
+ * @self:
+ * @menu: (allow-none):
+ *
+ */
+void
+gd_main_toolbar_set_labels_menu (GdMainToolbar *self,
+ GMenuModel *menu)
+{
+ GtkWidget *button, *grid, *w;
+
+ if (menu == NULL &&
+ ((gtk_widget_get_parent (self->priv->labels_grid) == GTK_WIDGET (self->priv->center_group)) ||
+ self->priv->center_menu_child == NULL))
+ return;
+
+ if (menu != NULL)
+ {
+ g_object_ref (self->priv->labels_grid);
+ gtk_container_remove (GTK_CONTAINER (self->priv->center_group),
+ self->priv->labels_grid);
+
+ self->priv->center_menu_child = grid = gtk_grid_new ();
+ gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
+ gtk_container_add (GTK_CONTAINER (grid), self->priv->labels_grid);
+ g_object_unref (self->priv->labels_grid);
+
+ w = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
+ gtk_container_add (GTK_CONTAINER (grid), w);
+
+ self->priv->center_menu = button = gtk_menu_button_new ();
+ gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->center_menu),
+ "selection-menu");
+ gtk_widget_destroy (gtk_bin_get_child (GTK_BIN (button)));
+ gtk_widget_set_halign (button, GTK_ALIGN_CENTER);
+ gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), menu);
+ gtk_container_add (GTK_CONTAINER (self->priv->center_menu), grid);
+
+ gtk_container_add (GTK_CONTAINER (self->priv->center_group), button);
+ }
+ else
+ {
+ g_object_ref (self->priv->labels_grid);
+ gtk_container_remove (GTK_CONTAINER (self->priv->center_menu_child),
+ self->priv->labels_grid);
+ gtk_widget_destroy (self->priv->center_menu);
+
+ self->priv->center_menu = NULL;
+ self->priv->center_menu_child = NULL;
+
+ gtk_container_add (GTK_CONTAINER (self->priv->center_group),
+ self->priv->labels_grid);
+ g_object_unref (self->priv->labels_grid);
+ }
+
+ gtk_widget_show_all (GTK_WIDGET (self->priv->center_group));
+}
+
+/**
* gd_main_toolbar_add_button:
* @self:
* @icon_name: (allow-none):
diff --git a/libgd/gd-main-toolbar.h b/libgd/gd-main-toolbar.h
index 5d4c7e7..6ad8c3a 100644
--- a/libgd/gd-main-toolbar.h
+++ b/libgd/gd-main-toolbar.h
@@ -74,6 +74,9 @@ void gd_main_toolbar_set_labels (GdMainToolbar *self,
const gchar *primary,
const gchar *detail);
+void gd_main_toolbar_set_labels_menu (GdMainToolbar *self,
+ GMenuModel *menu);
+
void gd_main_toolbar_clear (GdMainToolbar *self);
GtkWidget * gd_main_toolbar_add_button (GdMainToolbar *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]