mirror of
https://github.com/labwc/labwc.git
synced 2025-11-04 13:30:07 -05:00
action: support arguments of int type
This commit is contained in:
parent
4a531daef8
commit
3a6a04215c
1 changed files with 35 additions and 0 deletions
35
src/action.c
35
src/action.c
|
|
@ -23,6 +23,7 @@
|
|||
enum action_arg_type {
|
||||
LAB_ACTION_ARG_STR = 0,
|
||||
LAB_ACTION_ARG_BOOL,
|
||||
LAB_ACTION_ARG_INT,
|
||||
};
|
||||
|
||||
struct action_arg {
|
||||
|
|
@ -42,6 +43,11 @@ struct action_arg_bool {
|
|||
bool value;
|
||||
};
|
||||
|
||||
struct action_arg_int {
|
||||
struct action_arg base;
|
||||
int value;
|
||||
};
|
||||
|
||||
enum action_type {
|
||||
ACTION_TYPE_INVALID = 0,
|
||||
ACTION_TYPE_NONE,
|
||||
|
|
@ -134,6 +140,18 @@ action_arg_add_bool(struct action *action, char *key, bool value)
|
|||
wl_list_append(&action->args, &arg->base.link);
|
||||
}
|
||||
|
||||
static void
|
||||
action_arg_add_int(struct action *action, char *key, int value)
|
||||
{
|
||||
struct action_arg_int *arg = znew(*arg);
|
||||
arg->base.type = LAB_ACTION_ARG_INT;
|
||||
if (key) {
|
||||
arg->base.key = xstrdup(key);
|
||||
}
|
||||
arg->value = value;
|
||||
wl_list_append(&action->args, &arg->base.link);
|
||||
}
|
||||
|
||||
void
|
||||
action_arg_from_xml_node(struct action *action, char *nodename, char *content)
|
||||
{
|
||||
|
|
@ -247,6 +265,23 @@ get_arg_value_bool(struct action *action, const char *key, bool default_value)
|
|||
return default_value;
|
||||
}
|
||||
|
||||
static int
|
||||
get_arg_value_int(struct action *action, const char *key, int default_value)
|
||||
{
|
||||
assert(key);
|
||||
struct action_arg *arg;
|
||||
wl_list_for_each(arg, &action->args, link) {
|
||||
if (!arg->key) {
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(key, arg->key)) {
|
||||
assert(arg->type == LAB_ACTION_ARG_INT);
|
||||
return ((struct action_arg_int *)arg)->value;
|
||||
}
|
||||
}
|
||||
return default_value;
|
||||
}
|
||||
|
||||
static struct action_arg *
|
||||
action_get_first_arg(struct action *action)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue