1 /* vifm
2 * Copyright (C) 2001 Ken Steen.
3 * Copyright (C) 2011 xaizek.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include "locate_menu.h"
21
22 #include <stdlib.h> /* free() */
23 #include <string.h> /* strdup() */
24
25 #include "../cfg/config.h"
26 #include "../ui/statusbar.h"
27 #include "../ui/ui.h"
28 #include "../utils/macros.h"
29 #include "../utils/path.h"
30 #include "../utils/str.h"
31 #include "../macros.h"
32 #include "../running.h"
33 #include "menus.h"
34
35 static int execute_locate_cb(view_t *view, menu_data_t *m);
36
37 int
show_locate_menu(view_t * view,const char args[])38 show_locate_menu(view_t *view, const char args[])
39 {
40 enum { M_a, M_u, M_U, };
41
42 char *cmd;
43 char *margs;
44 int save_msg;
45 custom_macro_t macros[] = {
46 [M_a] = { .letter = 'a', .value = args, .uses_left = 1, .group = -1 },
47
48 [M_u] = { .letter = 'u', .value = "", .uses_left = 1, .group = -1 },
49 [M_U] = { .letter = 'U', .value = "", .uses_left = 1, .group = -1 },
50 };
51
52 static menu_data_t m;
53 margs = (args[0] == '-') ? strdup(args) : shell_like_escape(args, 0);
54 menus_init_data(&m, view, format_str("Locate %s", margs),
55 strdup("No files found"));
56 free(margs);
57
58 m.stashable = 1;
59 m.execute_handler = &execute_locate_cb;
60 m.key_handler = &menus_def_khandler;
61
62 cmd = ma_expand_custom(cfg.locate_prg, ARRAY_LEN(macros), macros, MA_NOOPT);
63
64 ui_sb_msg("locate...");
65 save_msg = menus_capture(view, cmd, 0, &m, macros[M_u].explicit_use,
66 macros[M_U].explicit_use);
67 free(cmd);
68
69 return save_msg;
70 }
71
72 /* Callback that is called when menu item is selected. Should return non-zero
73 * to stay in menu mode. */
74 static int
execute_locate_cb(view_t * view,menu_data_t * m)75 execute_locate_cb(view_t *view, menu_data_t *m)
76 {
77 (void)menus_goto_file(m, view, m->items[m->pos], 0);
78 return 0;
79 }
80
81 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
82 /* vim: set cinoptions+=t0 filetype=c : */
83