aboutsummaryrefslogtreecommitdiff
path: root/mode-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'mode-tree.c')
-rw-r--r--mode-tree.c81
1 files changed, 50 insertions, 31 deletions
diff --git a/mode-tree.c b/mode-tree.c
index b9fa5f65..645e2ae9 100644
--- a/mode-tree.c
+++ b/mode-tree.c
@@ -256,8 +256,8 @@ mode_tree_expand_current(struct mode_tree_data *mtd)
}
}
-void
-mode_tree_set_current(struct mode_tree_data *mtd, uint64_t tag)
+static int
+mode_tree_get_tag(struct mode_tree_data *mtd, uint64_t tag, u_int *found)
{
u_int i;
@@ -266,15 +266,41 @@ mode_tree_set_current(struct mode_tree_data *mtd, uint64_t tag)
break;
}
if (i != mtd->line_size) {
- mtd->current = i;
+ *found = i;
+ return (1);
+ }
+ return (0);
+}
+
+void
+mode_tree_expand(struct mode_tree_data *mtd, uint64_t tag)
+{
+ u_int found;
+
+ if (!mode_tree_get_tag(mtd, tag, &found))
+ return;
+ if (!mtd->line_list[found].item->expanded) {
+ mtd->line_list[found].item->expanded = 1;
+ mode_tree_build(mtd);
+ }
+}
+
+int
+mode_tree_set_current(struct mode_tree_data *mtd, uint64_t tag)
+{
+ u_int found;
+
+ if (mode_tree_get_tag(mtd, tag, &found)) {
+ mtd->current = found;
if (mtd->current > mtd->height - 1)
mtd->offset = mtd->current - mtd->height + 1;
else
mtd->offset = 0;
- } else {
- mtd->current = 0;
- mtd->offset = 0;
+ return (1);
}
+ mtd->current = 0;
+ mtd->offset = 0;
+ return (0);
}
u_int
@@ -531,7 +557,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
memcpy(&gc0, &grid_default_cell, sizeof gc0);
memcpy(&gc, &grid_default_cell, sizeof gc);
- style_apply(&gc, oo, "mode-style");
+ style_apply(&gc, oo, "mode-style", NULL);
w = mtd->width;
h = mtd->height;
@@ -847,6 +873,10 @@ mode_tree_display_menu(struct mode_tree_data *mtd, struct client *c, u_int x,
mtm->itemdata = mti->itemdata;
mtd->references++;
+ if (x >= (menu->width + 4) / 2)
+ x -= (menu->width + 4) / 2;
+ else
+ x = 0;
if (menu_display(menu, 0, NULL, x, y, c, NULL, mode_tree_menu_callback,
mtm) != 0)
menu_free(menu);
@@ -1059,33 +1089,22 @@ void
mode_tree_run_command(struct client *c, struct cmd_find_state *fs,
const char *template, const char *name)
{
- struct cmdq_item *new_item;
- char *command;
- struct cmd_parse_result *pr;
+ struct cmdq_state *state;
+ char *command, *error;
+ enum cmd_parse_status status;
command = cmd_template_replace(template, name, 1);
- if (command == NULL || *command == '\0') {
- free(command);
- return;
- }
-
- pr = cmd_parse_from_string(command, NULL);
- switch (pr->status) {
- case CMD_PARSE_EMPTY:
- break;
- case CMD_PARSE_ERROR:
- if (c != NULL) {
- *pr->error = toupper((u_char)*pr->error);
- status_message_set(c, "%s", pr->error);
+ if (command != NULL && *command != '\0') {
+ state = cmdq_new_state(fs, NULL, 0);
+ status = cmd_parse_and_append(command, NULL, c, state, &error);
+ if (status == CMD_PARSE_ERROR) {
+ if (c != NULL) {
+ *error = toupper((u_char)*error);
+ status_message_set(c, "%s", error);
+ }
+ free(error);
}
- free(pr->error);
- break;
- case CMD_PARSE_SUCCESS:
- new_item = cmdq_get_command(pr->cmdlist, fs, NULL, 0);
- cmdq_append(c, new_item);
- cmd_list_free(pr->cmdlist);
- break;
+ cmdq_free_state(state);
}
-
free(command);
}