Skip to content

Commit

Permalink
Fix support for action items in plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
andoma committed May 20, 2016
1 parent 0d2753f commit 7440536
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions glwskins/flat/items/list/action.view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ widget(container_z, {

widget(icon, {
style: "ListItemIcon";
source: "skin:https://icons/ic_" + $self.subtype + "_48px.svg";
});

widget(label, {
Expand Down
18 changes: 15 additions & 3 deletions res/ecmascript/modules/showtime/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,26 @@ Item.prototype.disable = function() {
this.root.enabled = false;
}

Item.prototype.addOptAction = function(title, action) {
Item.prototype.destroyOption = function(item) {
prop.destroy(item);
}

Item.prototype.addOptAction = function(title, func, subtype) {
var node = prop.createRoot();
node.type = 'action';
node.metadata.title = title;
node.enabled = true;
node.action = action;

node.subtype = subtype;

prop.subscribe(node.eventSink, function(type, val) {
if(type == "action" && val.indexOf('Activate') != -1)
func();
}, {
autoDestroy: true,
actionAsArray: true,
});
prop.setParent(node, this.root.options);
return node;
}


Expand Down
24 changes: 22 additions & 2 deletions src/ecmascript/es_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct es_prop_sub {
es_resource_t eps_super;
prop_sub_t *eps_sub;
char eps_autodestry;
char eps_action_as_array;
} es_prop_sub_t;

static void
Expand Down Expand Up @@ -627,14 +628,30 @@ es_sub_cb(void *opaque, prop_event_t event, ...)
const event_payload_t *ep = (const event_payload_t *)e;
nargs = 2;
duk_push_string(ctx, "action");
duk_push_string(ctx, ep->payload);

if(eps->eps_action_as_array) {
duk_push_array(ctx);
duk_push_string(ctx, ep->payload);
duk_put_prop_index(ctx, -2, 0);
} else {
duk_push_string(ctx, ep->payload);
}

} else if(e->e_type == EVENT_ACTION_VECTOR) {
const event_action_vector_t *eav = (const event_action_vector_t *)e;
assert(eav->num > 0);
nargs = 2;
duk_push_string(ctx, "action");
duk_push_string(ctx, action_code2str(eav->actions[0]));

if(eps->eps_action_as_array) {
duk_push_array(ctx);
for(int i = 0; i < eav->num; i++) {
duk_push_string(ctx, action_code2str(eav->actions[i]));
duk_put_prop_index(ctx, -2, i);
}
} else {
duk_push_string(ctx, action_code2str(eav->actions[0]));
}

} else if(e->e_type == EVENT_UNICODE) {
const event_int_t *eu = (const event_int_t *)e;
Expand Down Expand Up @@ -710,6 +727,9 @@ es_prop_subscribe(duk_context *ctx)
if(es_prop_is_true(ctx, 2, "earlyChildDelete"))
flags |= PROP_SUB_EARLY_DEL_CHILD;

if(es_prop_is_true(ctx, 2, "actionAsArray"))
eps->eps_action_as_array = 1;

eps->eps_sub =
prop_subscribe(flags,
PROP_TAG_ROOT, p,
Expand Down

0 comments on commit 7440536

Please sign in to comment.