summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Erias Morandeira <femorandeira@igalia.com>2013-05-29 16:41:58 +0200
committerFelipe Erias Morandeira <femorandeira@igalia.com>2013-06-21 14:14:14 +0100
commita590e08267771472dd5c89ce01c1ffcbb21cb978 (patch)
tree1d873b429f7d0b5a7bfdee5dd99da143a59581d8
parent68124bb0bb06a865f21e0b28b8944a670d9cd6fd (diff)
EosActionMenu: Implemented the functionality to add a GtkAction and have it linked to a EosActionButton in the menu. Added example code in action-buttons.js
[endlessm/eos-sdk#79]
-rw-r--r--endless/eosactionmenu-private.h5
-rw-r--r--endless/eosactionmenu.c81
-rw-r--r--test/smoke-tests/action-buttons.js47
3 files changed, 104 insertions, 29 deletions
diff --git a/endless/eosactionmenu-private.h b/endless/eosactionmenu-private.h
index 181e467..14c33d4 100644
--- a/endless/eosactionmenu-private.h
+++ b/endless/eosactionmenu-private.h
@@ -54,9 +54,8 @@ EOS_SDK_ALL_API_VERSIONS
GtkWidget *eos_action_menu_new ();
EOS_SDK_ALL_API_VERSIONS
-GtkAction *eos_action_menu_add_action (EosActionMenu *menu,
- const gchar *first_property_name,
- ...);
+void eos_action_menu_add_action (EosActionMenu *menu,
+ GtkAction *action);
EOS_SDK_ALL_API_VERSIONS
GtkAction *eos_action_menu_get_action (EosActionMenu *menu,
diff --git a/endless/eosactionmenu.c b/endless/eosactionmenu.c
index fa09e02..5f44958 100644
--- a/endless/eosactionmenu.c
+++ b/endless/eosactionmenu.c
@@ -10,6 +10,13 @@
#define _EOS_STYLE_CLASS_ACTION_MENU "action-menu"
+/**
+ * SECTION:action-menu
+ * @short_description: Adding actions to the page
+ * @title: Action Menu
+ */
+
+
G_DEFINE_TYPE (EosActionMenu, eos_action_menu, GTK_TYPE_GRID)
#define EOS_ACTION_MENU_PRIVATE(o) \
@@ -53,6 +60,11 @@ eos_action_menu_init (EosActionMenu *menu)
/* ******* LIFECYCLE ******* */
+/*
+ * eos_action_menu_new:
+ *
+ * Returns: a new instance
+ */
GtkWidget *
eos_action_menu_new ()
{
@@ -73,38 +85,69 @@ eos_action_menu_finalize (GObject *object)
/* ******* ACTION GROUP MGMT ******* */
-GtkAction *
+/**
+ * eos_action_menu_add_action:
+ * @menu: a #EosActionMenu
+ * @action: a #GtkAction: name, label, icon-name, is-important.
+ *
+ * Adds an action to the #EosActionMenu, using its name, label, icon-name and
+ * is-important properties.
+ */
+void
eos_action_menu_add_action (EosActionMenu *menu,
- const gchar *first_property_name,
- ...)
+ GtkAction *action)
{
EosActionMenuPrivate *priv;
- GtkAction *action;
- va_list var_args;
g_return_val_if_fail (EOS_IS_ACTION_MENU (menu), NULL);
- menu->priv = EOS_ACTION_MENU_PRIVATE (menu);
+ priv = menu->priv;
- va_start (var_args, first_property_name);
- action = (GtkAction*) g_object_new_valist (GTK_TYPE_ACTION, first_property_name, var_args);
- va_end (var_args);
+ if (action)
+ {
+ gtk_action_group_add_action (priv->action_group, action);
+
+ EosActionButtonSize size = gtk_action_get_is_important (action) ?
+ EOS_ACTION_BUTTON_SIZE_PRIMARY :
+ EOS_ACTION_BUTTON_SIZE_SECONDARY;
+
+ GtkWidget *action_button = eos_action_button_new (size,
+ gtk_action_get_label (action),
+ gtk_action_get_icon_name (action));
- gtk_action_group_add_action(priv->action_group, action);
+ gtk_activatable_set_related_action (GTK_ACTIVATABLE (action_button), action);
- // TODO : create and wire up the action button
+ // TODO : maybe we need a finer control, taking is-important into account?
+ gtk_grid_attach_next_to (GTK_GRID (menu), action_button, NULL,
+ GTK_POS_BOTTOM, 1, 1);
+ }
}
+/**
+ * eos_action_menu_get_action:
+ * @menu: an #EosActionMenu
+ * @name: the name of the action to retrieve
+ *
+ * Retrieves an action.
+ *
+ * Returns: (transfer none): the #GtkAction
+ */
GtkAction *
eos_action_menu_get_action (EosActionMenu *menu,
const gchar *name)
{
EosActionMenuPrivate *priv;
g_return_val_if_fail (EOS_IS_ACTION_MENU (menu), NULL);
- menu->priv = EOS_ACTION_MENU_PRIVATE (menu);
+ priv = menu->priv;
return gtk_action_group_get_action (priv->action_group, name);
}
+/**
+ * eos_action_list_actions:
+ * @menu: an #EosActionMenu
+ *
+ * Returns: (element-type GList) (transfer container): an allocated list of the action objects in the action group
+ */
GList *
eos_action_list_actions (EosActionMenu *menu)
{
@@ -115,6 +158,13 @@ eos_action_list_actions (EosActionMenu *menu)
return gtk_action_group_list_actions (priv->action_group);
}
+/**
+ * eos_action_menu_remove_action:
+ * @menu: an #EosActionMenu
+ * @action: the action to remove
+ *
+ * Removes an action
+ */
void
eos_action_menu_remove_action (EosActionMenu *menu,
GtkAction *action)
@@ -126,6 +176,13 @@ eos_action_menu_remove_action (EosActionMenu *menu,
gtk_action_group_remove_action(priv->action_group, action);
}
+/**
+ * eos_action_menu_remove_action_by_name:
+ * @menu: an #EosActionMenu
+ * @name: the name of the action to remove
+ *
+ * Removes the action with the given name
+ */
void
eos_action_menu_remove_action_by_name (EosActionMenu *menu,
const gchar *name)
diff --git a/test/smoke-tests/action-buttons.js b/test/smoke-tests/action-buttons.js
index 04e3ae9..54d0fc1 100644
--- a/test/smoke-tests/action-buttons.js
+++ b/test/smoke-tests/action-buttons.js
@@ -13,22 +13,41 @@ const TestApplication = new Lang.Class ({
vfunc_startup: function() {
this.parent();
- this._page = new Gtk.Grid();
+ this._page = new Endless.ActionMenu();
- /* should be using Endless.EOS_ACTION_BUTTON_SIZE_PRIMARY */
-
- this._eosButton0 = new Endless.ActionButton({size: 0, label: 'SMILE', 'icon-id': 'face-smile-symbolic' });
- this._page.attach(this._eosButton0, 0, 0, 1, 1);
-
- this._eosButton1 = new Endless.ActionButton({size: 1, label: 'POUT', 'icon-id': 'face-sad-symbolic' });
- this._page.attach(this._eosButton1, 0, 1, 1, 1);
-
- this._eosButton2 = new Endless.ActionButton({size: 2, label: '', 'icon-id': 'edit-delete-symbolic' });
- this._page.attach(this._eosButton2, 0, 2, 1, 1);
-
- this._eosButton3 = new Endless.ActionButton({size: 3, label: '', 'icon-id': 'object-select-symbolic' });
- this._page.attach(this._eosButton3, 0, 3, 1, 1);
+ this._page.add_action (new Gtk.Action({
+ name: 'select',
+ 'icon-name': 'object-select-symbolic',
+ label: 'select stuff',
+ 'is-important': true }));
+ this._page.get_action('select').connect('activate',
+ Lang.bind(this, function () {
+ var md = new Gtk.MessageDialog({modal:true, title:"Information",
+ message_type:Gtk.MessageType.INFO,
+ buttons:Gtk.ButtonsType.OK, text:"Select button pressed!"});
+ md.run();
+ md.destroy();
+ }));
+
+ this._page.add_action (new Gtk.Action({
+ name: 'delete',
+ 'icon-name': 'edit-delete-symbolic',
+ label: 'delete stuff',
+ 'is-important': false }));
+
+ this._page.add_action (new Gtk.Action({
+ name: 'smile',
+ 'icon-name': 'face-smile-symbolic',
+ label: 'smile',
+ 'is-important': false }));
+
+ this._page.add_action (new Gtk.Action({
+ name: 'sadface',
+ 'icon-name': 'face-sad-symbolic',
+ label: 'sadface',
+ 'is-important': false }));
+
this._pm = new Endless.PageManager();
this._pm.add(this._page, { name: "page" });