diff options
author | nicm <nicm> | 2019-08-16 11:49:12 +0000 |
---|---|---|
committer | nicm <nicm> | 2019-08-16 11:49:12 +0000 |
commit | 37583f0a69d22668bdd47e0b30b61d8dac74bdf6 (patch) | |
tree | 6f2230c68121094ff70e15407120b0b55ae92f80 /mode-tree.c | |
parent | 5644d37876faf69ecf9f34cbd52e6cdfab83cf79 (diff) | |
download | rtmux-37583f0a69d22668bdd47e0b30b61d8dac74bdf6.tar.gz rtmux-37583f0a69d22668bdd47e0b30b61d8dac74bdf6.tar.bz2 rtmux-37583f0a69d22668bdd47e0b30b61d8dac74bdf6.zip |
Add a flag to reverse sort in the various choose modes, from Benjamin
Poirier in GitHub issue 1875.
Diffstat (limited to 'mode-tree.c')
-rw-r--r-- | mode-tree.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/mode-tree.c b/mode-tree.c index 03a91ef8..054989fb 100644 --- a/mode-tree.c +++ b/mode-tree.c @@ -39,7 +39,7 @@ struct mode_tree_data { const char **sort_list; u_int sort_size; - u_int sort_type; + struct mode_tree_sort_criteria sort_crit; mode_tree_build_cb buildcb; mode_tree_draw_cb drawcb; @@ -334,7 +334,6 @@ mode_tree_start(struct window_pane *wp, struct args *args, mtd->sort_list = sort_list; mtd->sort_size = sort_size; - mtd->sort_type = 0; mtd->preview = !args_has(args, 'N'); @@ -342,9 +341,10 @@ mode_tree_start(struct window_pane *wp, struct args *args, if (sort != NULL) { for (i = 0; i < sort_size; i++) { if (strcasecmp(sort, sort_list[i]) == 0) - mtd->sort_type = i; + mtd->sort_crit.field = i; } } + mtd->sort_crit.reversed = args_has(args, 'r'); if (args_has(args, 'f')) mtd->filter = xstrdup(args_get(args, 'f')); @@ -392,10 +392,10 @@ mode_tree_build(struct mode_tree_data *mtd) TAILQ_CONCAT(&mtd->saved, &mtd->children, entry); TAILQ_INIT(&mtd->children); - mtd->buildcb(mtd->modedata, mtd->sort_type, &tag, mtd->filter); + mtd->buildcb(mtd->modedata, &mtd->sort_crit, &tag, mtd->filter); mtd->no_matches = TAILQ_EMPTY(&mtd->children); if (mtd->no_matches) - mtd->buildcb(mtd->modedata, mtd->sort_type, &tag, NULL); + mtd->buildcb(mtd->modedata, &mtd->sort_crit, &tag, NULL); mode_tree_free_items(&mtd->saved); TAILQ_INIT(&mtd->saved); @@ -634,8 +634,9 @@ mode_tree_draw(struct mode_tree_data *mtd) screen_write_cursormove(&ctx, 0, h, 0); screen_write_box(&ctx, w, sy - h); - xasprintf(&text, " %s (sort: %s)", mti->name, - mtd->sort_list[mtd->sort_type]); + xasprintf(&text, " %s (sort: %s%s)", mti->name, + mtd->sort_list[mtd->sort_crit.field], + mtd->sort_crit.reversed ? ", reversed" : ""); if (w - 2 >= strlen(text)) { screen_write_cursormove(&ctx, 1, h, 0); screen_write_puts(&ctx, &gc0, "%s", text); @@ -993,9 +994,13 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key, } break; case 'O': - mtd->sort_type++; - if (mtd->sort_type == mtd->sort_size) - mtd->sort_type = 0; + mtd->sort_crit.field++; + if (mtd->sort_crit.field == mtd->sort_size) + mtd->sort_crit.field = 0; + mode_tree_build(mtd); + break; + case 'r': + mtd->sort_crit.reversed = !mtd->sort_crit.reversed; mode_tree_build(mtd); break; case KEYC_LEFT: |