Skip to content

Commit

Permalink
EosActionMenu: Implemented the functionality to add a GtkAction and h…
Browse files Browse the repository at this point in the history
…ave it linked to a EosActionButton in the menu. Added example code in action-buttons.js

[endlessm/eos-sdk#79]
  • Loading branch information
felipeerias committed Jun 21, 2013
1 parent 68124bb commit a590e08
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 29 deletions.
5 changes: 2 additions & 3 deletions endless/eosactionmenu-private.h
Expand Up @@ -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,
Expand Down
81 changes: 69 additions & 12 deletions endless/eosactionmenu.c
Expand Up @@ -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) \
Expand Down Expand Up @@ -53,6 +60,11 @@ eos_action_menu_init (EosActionMenu *menu)

/* ******* LIFECYCLE ******* */

/*
* eos_action_menu_new:
*
* Returns: a new instance
*/
GtkWidget *
eos_action_menu_new ()
{
Expand All @@ -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)
{
Expand All @@ -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)
Expand All @@ -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)
Expand Down
47 changes: 33 additions & 14 deletions test/smoke-tests/action-buttons.js
Expand Up @@ -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" });

Expand Down

0 comments on commit a590e08

Please sign in to comment.