1/* $OpenBSD$ */
2
3/*
4 * Copyright (c) 2012 Thomas Adam <[email protected]>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <sys/types.h>
20
21#include "tmux.h"
22
23/*
24 * Enter a mode.
25 */
26
27static enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmdq_item *);
28
29const struct cmd_entry cmd_choose_tree_entry = {
30 .name = "choose-tree",
31 .alias = NULL,
32
33 .args = { "F:Gf:NO:rst:wZ", 0, 1 },
34 .usage = "[-GNrswZ] [-F format] [-f filter] [-O sort-order] "
35 CMD_TARGET_PANE_USAGE " [template]",
36
37 .target = { 't', CMD_FIND_PANE, 0 },
38
39 .flags = 0,
40 .exec = cmd_choose_tree_exec
41};
42
43const struct cmd_entry cmd_choose_client_entry = {
44 .name = "choose-client",
45 .alias = NULL,
46
47 .args = { "F:f:NO:rt:Z", 0, 1 },
48 .usage = "[-NrZ] [-F format] [-f filter] [-O sort-order] "
49 CMD_TARGET_PANE_USAGE " [template]",
50
51 .target = { 't', CMD_FIND_PANE, 0 },
52
53 .flags = 0,
54 .exec = cmd_choose_tree_exec
55};
56
57const struct cmd_entry cmd_choose_buffer_entry = {
58 .name = "choose-buffer",
59 .alias = NULL,
60
61 .args = { "F:f:NO:rt:Z", 0, 1 },
62 .usage = "[-NrZ] [-F format] [-f filter] [-O sort-order] "
63 CMD_TARGET_PANE_USAGE " [template]",
64
65 .target = { 't', CMD_FIND_PANE, 0 },
66
67 .flags = 0,
68 .exec = cmd_choose_tree_exec
69};
70
71static enum cmd_retval
72cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
73{
74 struct args *args = self->args;
75 struct window_pane *wp = item->target.wp;
76 const struct window_mode *mode;
77
78 if (self->entry == &cmd_choose_buffer_entry) {
79 if (paste_get_top(NULL) == NULL)
80 return (CMD_RETURN_NORMAL);
81 mode = &window_buffer_mode;
82 } else if (self->entry == &cmd_choose_client_entry) {
83 if (server_client_how_many() == 0)
84 return (CMD_RETURN_NORMAL);
85 mode = &window_client_mode;
86 } else
87 mode = &window_tree_mode;
88
89 window_pane_set_mode(wp, mode, &item->target, args);
90 return (CMD_RETURN_NORMAL);
91}
92