[gnome-documents] main-toolbar: add icon/label parameters to the add_menu() method
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] main-toolbar: add icon/label parameters to the add_menu() method
- Date: Thu, 19 Jul 2012 01:52:34 +0000 (UTC)
commit c1a8d898cee853144fca25a593d64198a06aac8f
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Jul 18 21:42:46 2012 -0400
main-toolbar: add icon/label parameters to the add_menu() method
Also add a add_toggle() method, which will be useful for other kind of
buttons eventually.
src/lib/gd-main-toolbar.c | 160 ++++++++++++++++++++++++++++++++++----------
src/lib/gd-main-toolbar.h | 9 ++-
src/mainToolbar.js | 29 +++------
3 files changed, 140 insertions(+), 58 deletions(-)
---
diff --git a/src/lib/gd-main-toolbar.c b/src/lib/gd-main-toolbar.c
index 349bf79..9f1ef56 100644
--- a/src/lib/gd-main-toolbar.c
+++ b/src/lib/gd-main-toolbar.c
@@ -26,6 +26,12 @@
G_DEFINE_TYPE (GdMainToolbar, gd_main_toolbar, GTK_TYPE_TOOLBAR)
+typedef enum {
+ CHILD_NORMAL = 0,
+ CHILD_TOGGLE = 1,
+ CHILD_MENU = 2,
+} ChildType;
+
struct _GdMainToolbarPrivate {
GtkSizeGroup *size_group;
GtkSizeGroup *vertical_size_group;
@@ -85,11 +91,48 @@ get_vertical_size_group (void)
}
static GtkWidget *
-get_symbolic_button (const gchar *icon_name)
+get_empty_button (ChildType type)
+{
+ GtkWidget *button;
+
+ switch (type)
+ {
+ case CHILD_MENU:
+ button = gtk_menu_button_new ();
+ break;
+ case CHILD_TOGGLE:
+ button = gtk_toggle_button_new ();
+ break;
+ case CHILD_NORMAL:
+ default:
+ button = gtk_button_new ();
+ break;
+ }
+
+ return button;
+}
+
+static GtkWidget *
+get_symbolic_button (const gchar *icon_name,
+ ChildType type)
{
GtkWidget *button, *w;
- button = gtk_button_new ();
+ switch (type)
+ {
+ case CHILD_MENU:
+ button = gtk_menu_button_new ();
+ gtk_widget_destroy (gtk_bin_get_child (GTK_BIN (button)));
+ break;
+ case CHILD_TOGGLE:
+ button = gtk_toggle_button_new ();
+ break;
+ case CHILD_NORMAL:
+ default:
+ button = gtk_button_new ();
+ break;
+ }
+
gtk_style_context_add_class (gtk_widget_get_style_context (button), "raised");
w = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
@@ -101,15 +144,34 @@ get_symbolic_button (const gchar *icon_name)
}
static GtkWidget *
-get_text_button (const gchar *label)
+get_text_button (const gchar *label,
+ ChildType type)
{
- GtkWidget *w;
+ GtkWidget *button, *w;
- w = gtk_button_new_with_label (label);
- gtk_widget_set_vexpand (w, TRUE);
- gtk_style_context_add_class (gtk_widget_get_style_context (w), "raised");
+ switch (type)
+ {
+ case CHILD_MENU:
+ button = gtk_menu_button_new ();
+ gtk_widget_destroy (gtk_bin_get_child (GTK_BIN (button)));
+
+ w = gtk_label_new (label);
+ gtk_widget_show (w);
+ gtk_container_add (GTK_CONTAINER (button), w);
+ break;
+ case CHILD_TOGGLE:
+ button = gtk_toggle_button_new_with_label (label);
+ break;
+ case CHILD_NORMAL:
+ default:
+ button = gtk_button_new_with_label (label);
+ break;
+ }
- return w;
+ gtk_widget_set_vexpand (button, TRUE);
+ gtk_style_context_add_class (gtk_widget_get_style_context (button), "raised");
+
+ return button;
}
static void
@@ -254,32 +316,28 @@ gd_main_toolbar_new (void)
return g_object_new (GD_TYPE_MAIN_TOOLBAR, NULL);
}
-/**
- * gd_main_toolbar_add_button:
- * @self:
- * @icon_name: (allow-none):
- * @label: (allow-none):
- * @pack_start:
- *
- * Returns: (transfer none):
- */
-GtkWidget *
-gd_main_toolbar_add_button (GdMainToolbar *self,
- const gchar *icon_name,
- const gchar *label,
- gboolean pack_start)
+static GtkWidget *
+add_button_internal (GdMainToolbar *self,
+ const gchar *icon_name,
+ const gchar *label,
+ gboolean pack_start,
+ ChildType type)
{
GtkWidget *button;
if (icon_name != NULL)
{
- button = get_symbolic_button (icon_name);
+ button = get_symbolic_button (icon_name, type);
if (label != NULL)
gtk_widget_set_tooltip_text (button, label);
}
else if (label != NULL)
{
- button = get_text_button (label);
+ button = get_text_button (label, type);
+ }
+ else
+ {
+ button = get_empty_button (type);
}
if (pack_start)
@@ -293,27 +351,55 @@ gd_main_toolbar_add_button (GdMainToolbar *self,
}
/**
- * gd_main_toolbar_add_menu:
+ * gd_main_toolbar_add_button:
* @self:
+ * @icon_name: (allow-none):
+ * @label: (allow-none):
* @pack_start:
*
* Returns: (transfer none):
*/
GtkWidget *
-gd_main_toolbar_add_menu (GdMainToolbar *self,
+gd_main_toolbar_add_button (GdMainToolbar *self,
+ const gchar *icon_name,
+ const gchar *label,
gboolean pack_start)
{
- GtkWidget *menuButton;
-
- menuButton = gtk_menu_button_new ();
-
- if (pack_start)
- gtk_container_add (GTK_CONTAINER (self->priv->left_grid), menuButton);
- else
- gtk_container_add (GTK_CONTAINER (self->priv->right_grid), menuButton);
-
- gtk_widget_show_all (menuButton);
+ return add_button_internal (self, icon_name, label, pack_start, CHILD_NORMAL);
+}
- return menuButton;
+/**
+ * gd_main_toolbar_add_menu:
+ * @self:
+ * @icon_name: (allow-none):
+ * @label: (allow-none):
+ * @pack_start:
+ *
+ * Returns: (transfer none):
+ */
+GtkWidget *
+gd_main_toolbar_add_menu (GdMainToolbar *self,
+ const gchar *icon_name,
+ const gchar *label,
+ gboolean pack_start)
+{
+ return add_button_internal (self, icon_name, label, pack_start, CHILD_MENU);
}
+/**
+ * gd_main_toolbar_add_toggle:
+ * @self:
+ * @icon_name: (allow-none):
+ * @label: (allow-none):
+ * @pack_start:
+ *
+ * Returns: (transfer none):
+ */
+GtkWidget *
+gd_main_toolbar_add_toggle (GdMainToolbar *self,
+ const gchar *icon_name,
+ const gchar *label,
+ gboolean pack_start)
+{
+ return add_button_internal (self, icon_name, label, pack_start, CHILD_TOGGLE);
+}
diff --git a/src/lib/gd-main-toolbar.h b/src/lib/gd-main-toolbar.h
index 6506394..5d4c7e7 100644
--- a/src/lib/gd-main-toolbar.h
+++ b/src/lib/gd-main-toolbar.h
@@ -81,9 +81,16 @@ GtkWidget * gd_main_toolbar_add_button (GdMainToolbar *self,
const gchar *label,
gboolean pack_start);
-GtkWidget * gd_main_toolbar_add_menu (GdMainToolbar *self,
+GtkWidget * gd_main_toolbar_add_toggle (GdMainToolbar *self,
+ const gchar *icon_name,
+ const gchar *label,
gboolean pack_start);
+GtkWidget * gd_main_toolbar_add_menu (GdMainToolbar *self,
+ const gchar *icon_name,
+ const gchar *label,
+ gboolean pack_start);
+
G_END_DECLS
#endif /* __GD_MAIN_TOOLBAR_H__ */
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index 40115c4..d3c0b8c 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -245,16 +245,14 @@ const MainToolbar = new Lang.Class({
function() {
Global.documentManager.setActiveItem(null);
}));
-
- //menu button, on the right of the toolbar (false)
- this._menuButton =
- this.widget.add_menu( false );
- this._initMenus();
- let menu = new Gtk.Menu.new_from_model(this.menuModel);
- menu.show();
- this._menuButton.set_menu( menu );
- Global.screen = this.widget.get_screen();
- Global.menuWidget = this._menuButton;//TO DO change this, not global
+
+ // menu button, on the right of the toolbar
+ let menuModel = new Gio.Menu();
+ menuModel.append_item(Gio.MenuItem.new(_("Open"), 'app.open-current'));
+ menuModel.append_item(Gio.MenuItem.new(_("Print"), 'app.print-current'));
+
+ let menuButton = this.widget.add_menu('emblem-system-symbolic', null, false);
+ menuButton.set_menu_model(menuModel);
},
_populateForOverview: function() {
@@ -320,16 +318,7 @@ const MainToolbar = new Lang.Class({
}));
this._setToolbarTitle();
- },
-
- _initMenus: function() {
- this.menuModel = new Gio.Menu();
-
- let menuItemOpen = Gio.MenuItem.new(_("Open"), 'app.open');
- let menuItemPrint = Gio.MenuItem.new(_("Print"), 'app.print');
- this.menuModel.append_item(menuItemOpen);
- this.menuModel.append_item(menuItemPrint);
- },
+ }
});
const PreviewToolbar = new Lang.Class({
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]