15494e770Schristos /* $OpenBSD$ */
2928fc495Schristos
3928fc495Schristos /*
4928fc495Schristos * Copyright (c) 2012 Thomas Adam <thomas@xteddy.org>
5928fc495Schristos *
6928fc495Schristos * Permission to use, copy, modify, and distribute this software for any
7928fc495Schristos * purpose with or without fee is hereby granted, provided that the above
8928fc495Schristos * copyright notice and this permission notice appear in all copies.
9928fc495Schristos *
10928fc495Schristos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11928fc495Schristos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12928fc495Schristos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13928fc495Schristos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14928fc495Schristos * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15928fc495Schristos * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16928fc495Schristos * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17928fc495Schristos */
18928fc495Schristos
19928fc495Schristos #include <sys/types.h>
20928fc495Schristos
21928fc495Schristos #include "tmux.h"
22928fc495Schristos
23928fc495Schristos /*
24c9ad075bSchristos * Enter a mode.
25928fc495Schristos */
26928fc495Schristos
276db26757Swiz static enum args_parse_type cmd_choose_tree_args_parse(struct args *args,
286db26757Swiz u_int idx, char **cause);
296db26757Swiz static enum cmd_retval cmd_choose_tree_exec(struct cmd *,
306db26757Swiz struct cmdq_item *);
31928fc495Schristos
32928fc495Schristos const struct cmd_entry cmd_choose_tree_entry = {
33ed4e6cd4Schristos .name = "choose-tree",
34ed4e6cd4Schristos .alias = NULL,
35ed4e6cd4Schristos
366db26757Swiz .args = { "F:f:GK:NO:rst:wZ", 0, 1, cmd_choose_tree_args_parse },
379fb66d81Schristos .usage = "[-GNrswZ] [-F format] [-f filter] [-K key-format] "
389fb66d81Schristos "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
39ed4e6cd4Schristos
40c9ad075bSchristos .target = { 't', CMD_FIND_PANE, 0 },
41ed4e6cd4Schristos
42ed4e6cd4Schristos .flags = 0,
43ed4e6cd4Schristos .exec = cmd_choose_tree_exec
44928fc495Schristos };
45928fc495Schristos
46c9ad075bSchristos const struct cmd_entry cmd_choose_client_entry = {
47c9ad075bSchristos .name = "choose-client",
48ed4e6cd4Schristos .alias = NULL,
49ed4e6cd4Schristos
506db26757Swiz .args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
519fb66d81Schristos .usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
529fb66d81Schristos "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
53ed4e6cd4Schristos
54c9ad075bSchristos .target = { 't', CMD_FIND_PANE, 0 },
55ed4e6cd4Schristos
56ed4e6cd4Schristos .flags = 0,
57ed4e6cd4Schristos .exec = cmd_choose_tree_exec
58928fc495Schristos };
59928fc495Schristos
60c9ad075bSchristos const struct cmd_entry cmd_choose_buffer_entry = {
61c9ad075bSchristos .name = "choose-buffer",
62ed4e6cd4Schristos .alias = NULL,
63ed4e6cd4Schristos
646db26757Swiz .args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
659fb66d81Schristos .usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
669fb66d81Schristos "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
679fb66d81Schristos
689fb66d81Schristos .target = { 't', CMD_FIND_PANE, 0 },
699fb66d81Schristos
709fb66d81Schristos .flags = 0,
719fb66d81Schristos .exec = cmd_choose_tree_exec
729fb66d81Schristos };
739fb66d81Schristos
749fb66d81Schristos const struct cmd_entry cmd_customize_mode_entry = {
759fb66d81Schristos .name = "customize-mode",
769fb66d81Schristos .alias = NULL,
779fb66d81Schristos
786db26757Swiz .args = { "F:f:Nt:Z", 0, 0, NULL },
799fb66d81Schristos .usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE,
80ed4e6cd4Schristos
81c9ad075bSchristos .target = { 't', CMD_FIND_PANE, 0 },
82ed4e6cd4Schristos
83ed4e6cd4Schristos .flags = 0,
84ed4e6cd4Schristos .exec = cmd_choose_tree_exec
85928fc495Schristos };
86928fc495Schristos
876db26757Swiz static enum args_parse_type
cmd_choose_tree_args_parse(__unused struct args * args,__unused u_int idx,__unused char ** cause)886db26757Swiz cmd_choose_tree_args_parse(__unused struct args *args, __unused u_int idx,
896db26757Swiz __unused char **cause)
906db26757Swiz {
916db26757Swiz return (ARGS_PARSE_COMMANDS_OR_STRING);
926db26757Swiz }
936db26757Swiz
944e179ddaSchristos static enum cmd_retval
cmd_choose_tree_exec(struct cmd * self,struct cmdq_item * item)954e179ddaSchristos cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
96928fc495Schristos {
979fb66d81Schristos struct args *args = cmd_get_args(self);
989fb66d81Schristos struct cmd_find_state *target = cmdq_get_target(item);
999fb66d81Schristos struct window_pane *wp = target->wp;
100c9ad075bSchristos const struct window_mode *mode;
101928fc495Schristos
1029fb66d81Schristos if (cmd_get_entry(self) == &cmd_choose_buffer_entry) {
103*c23f9150Swiz if (paste_is_empty())
104928fc495Schristos return (CMD_RETURN_NORMAL);
105c9ad075bSchristos mode = &window_buffer_mode;
1069fb66d81Schristos } else if (cmd_get_entry(self) == &cmd_choose_client_entry) {
107c9ad075bSchristos if (server_client_how_many() == 0)
108c9ad075bSchristos return (CMD_RETURN_NORMAL);
109c9ad075bSchristos mode = &window_client_mode;
1109fb66d81Schristos } else if (cmd_get_entry(self) == &cmd_customize_mode_entry)
1119fb66d81Schristos mode = &window_customize_mode;
1129fb66d81Schristos else
113c9ad075bSchristos mode = &window_tree_mode;
114928fc495Schristos
1159fb66d81Schristos window_pane_set_mode(wp, NULL, mode, target, args);
116928fc495Schristos return (CMD_RETURN_NORMAL);
117928fc495Schristos }
118