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 #ifndef VIFM__MENUS__MENUS_H__ 21 #define VIFM__MENUS__MENUS_H__ 22 23 #include <stddef.h> /* wchar_t */ 24 25 struct view_t; 26 27 /* Result of handling key sequence by menu-specific shortcut handler. */ 28 typedef enum 29 { 30 KHR_REFRESH_WINDOW, /* Menu window refresh is needed. */ 31 KHR_CLOSE_MENU, /* Menu mode should be left. */ 32 KHR_MORPHED_MENU, /* Menu was morphed modmenu_morph_into_cline. */ 33 KHR_UNHANDLED, /* Passed key wasn't handled. */ 34 } 35 KHandlerResponse; 36 37 /* Opaque declaration of structure describing menu state. */ 38 typedef struct menu_state_t menu_state_t; 39 40 /* Menu data related to specific menu rather than to state of menu mode or its 41 * UI. */ 42 typedef struct menu_data_t 43 { 44 int top; /* Index of first visible item. */ 45 int len; /* Number of menu items. */ 46 int pos; /* Menu item under the cursor. */ 47 int hor_pos; /* Horizontal offset. */ 48 49 char *title; /* Title of the menu. */ 50 char **items; /* Contains titles of all menu items. */ 51 52 /* Contains additional string data, associated with each of menu items, can be 53 * NULL. */ 54 char **data; 55 56 /* Contains additional pointers for each menu entry, can be NULL. */ 57 void **void_data; 58 59 /* Menu-specific shortcut handler, can be NULL. Returns code that specifies 60 * both taken actions and what should be done next. */ 61 KHandlerResponse (*key_handler)(struct view_t *view, struct menu_data_t *m, 62 const wchar_t keys[]); 63 64 /* Callback that is called when menu item is selected. Should return non-zero 65 * to stay in menu mode. */ 66 int (*execute_handler)(struct view_t *view, struct menu_data_t *m); 67 68 /* Text displayed by menus_enter() function in case menu is empty, it can be 69 * NULL if this cannot happen. */ 70 char *empty_msg; 71 72 /* Base for relative paths for navigation. */ 73 char *cwd; 74 75 /* For filetype background, mime flags and such. */ 76 int extra_data; 77 78 /* Whether this menu when non-empty should be saved for future use on closing 79 * menu. */ 80 int stashable; 81 82 menu_state_t *state; /* Opaque pointer to menu mode state. */ 83 int initialized; /* Marker that shows whether menu data needs freeing. */ 84 } 85 menu_data_t; 86 87 /* Menu data management. */ 88 89 /* Fills fields of menu_data_t structure with some safe values. empty_msg is 90 * text displayed by menus_enter() function in case menu is empty, it can be 91 * NULL if this cannot happen and will be freed by menus_reset_data(). */ 92 void menus_init_data(menu_data_t *m, struct view_t *view, char title[], 93 char empty_msg[]); 94 95 /* Changes active menu data. */ 96 void menus_replace_data(menu_data_t *m); 97 98 /* Frees resources associated with the menu and clears menu window. */ 99 void menus_reset_data(menu_data_t *m); 100 101 /* Menu entering/reentering and transformation. */ 102 103 /* Prepares menu, draws it and switches to the menu mode. Returns non-zero if 104 * status bar message should be saved. */ 105 int menus_enter(menu_state_t *m, struct view_t *view); 106 107 /* Restore previously saved menu. Returns non-zero if status bar message should 108 * be saved. */ 109 int menus_unstash(struct view_t *view); 110 111 /* Moves menu items into custom view. Returns zero on success, otherwise 112 * non-zero is returned. */ 113 int menus_to_custom_view(menu_state_t *m, struct view_t *view, int very); 114 115 /* Either makes a menu or custom view out of command output. Returns non-zero 116 * if status bar message should be saved. */ 117 int menus_capture(struct view_t *view, const char cmd[], int user_sh, 118 menu_data_t *m, int custom_view, int very_custom_view); 119 120 /* Menu drawing. */ 121 122 /* Erases current menu item in menu window. */ 123 void menus_erase_current(menu_state_t *m); 124 125 /* Redraws all screen elements used by menus. */ 126 void menus_full_redraw(menu_state_t *m); 127 128 /* Redraws only menu list itself. */ 129 void menus_partial_redraw(menu_state_t *m); 130 131 /* Menu operations. */ 132 133 /* Updates current position in the menu. */ 134 void menus_set_pos(menu_state_t *m, int pos); 135 136 /* Removes current menu item and redraws the menu. */ 137 void menus_remove_current(menu_state_t *ms); 138 139 /* Navigates to/open path specification. Specification can contain colon 140 * followed by a line number when try_open is not zero. Returns zero on 141 * successful parsing and performed try to handle the file otherwise non-zero is 142 * returned. */ 143 int menus_goto_file(menu_data_t *m, struct view_t *view, const char spec[], 144 int try_open); 145 146 /* Navigates to directory from a menu. */ 147 void menus_goto_dir(struct view_t *view, const char path[]); 148 149 /* Menu search. */ 150 151 /* Performs search of pattern among menu items. NULL pattern requests use of 152 * the last used pattern. Returns new value for save_msg flag, but when 153 * print_errors isn't requested can return -1 to indicate issues with the 154 * pattern. */ 155 int menus_search(const char pattern[], menu_data_t *m, int print_errors); 156 157 /* Resets search state of the menu according to specified parameters. */ 158 void menus_search_reset(menu_state_t *m, int backward, int new_repeat_count); 159 160 /* Reset search highlight of a menu. */ 161 void menus_search_reset_hilight(menu_state_t *m); 162 163 /* Performs search in requested direction. Either continues the previous one or 164 * restarts it. */ 165 void menus_search_repeat(menu_state_t *m, int backward); 166 167 /* Prints results or error message about search operation to the user. */ 168 void menus_search_print_msg(const menu_state_t *m); 169 170 /* Retrieves number of search matches in the menu. Returns the number. */ 171 int menus_search_matched(menu_state_t *m); 172 173 /* Auxiliary functions related to menus. */ 174 175 /* Forms list of target files/directories in the current view and possibly 176 * changes working directory to use relative paths. On success returns newly 177 * allocated string, which should be freed by the caller, otherwise NULL is 178 * returned. */ 179 char * menus_get_targets(struct view_t *view); 180 181 /* Predefined key handler for processing keys on elements of file lists. 182 * Returns code that specifies both taken actions and what should be done 183 * next. */ 184 KHandlerResponse menus_def_khandler(struct view_t *view, menu_data_t *m, 185 const wchar_t keys[]); 186 187 #endif /* VIFM__MENUS__MENUS_H__ */ 188 189 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ 190 /* vim: set cinoptions+=t0 filetype=c : */ 191