/src/neomutt/history/functions.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * @file |
3 | | * History functions |
4 | | * |
5 | | * @authors |
6 | | * Copyright (C) 2022-2023 Richard Russon <rich@flatcap.org> |
7 | | * |
8 | | * @copyright |
9 | | * This program is free software: you can redistribute it and/or modify it under |
10 | | * the terms of the GNU General Public License as published by the Free Software |
11 | | * Foundation, either version 2 of the License, or (at your option) any later |
12 | | * version. |
13 | | * |
14 | | * This program is distributed in the hope that it will be useful, but WITHOUT |
15 | | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
16 | | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
17 | | * details. |
18 | | * |
19 | | * You should have received a copy of the GNU General Public License along with |
20 | | * this program. If not, see <http://www.gnu.org/licenses/>. |
21 | | */ |
22 | | |
23 | | /** |
24 | | * @page history_functions History functions |
25 | | * |
26 | | * History functions |
27 | | */ |
28 | | |
29 | | #include "config.h" |
30 | | #include <stddef.h> |
31 | | #include "mutt/lib.h" |
32 | | #include "core/lib.h" |
33 | | #include "gui/lib.h" |
34 | | #include "functions.h" |
35 | | #include "menu/lib.h" |
36 | | |
37 | | /** |
38 | | * op_generic_select_entry - Select the current entry - Implements ::history_function_t - @ingroup history_function_api |
39 | | */ |
40 | | static int op_generic_select_entry(struct HistoryData *hd, int op) |
41 | | { |
42 | | const int index = menu_get_index(hd->menu); |
43 | | |
44 | | const char **pentry = ARRAY_GET(hd->matches, index); |
45 | | if (pentry) |
46 | | buf_strcpy(hd->buf, *pentry); |
47 | | |
48 | | hd->done = true; |
49 | | hd->selection = true; |
50 | | return FR_SUCCESS; |
51 | | } |
52 | | |
53 | | /** |
54 | | * op_quit - Quit this menu - Implements ::history_function_t - @ingroup history_function_api |
55 | | */ |
56 | | static int op_quit(struct HistoryData *hd, int op) |
57 | | { |
58 | | hd->done = true; |
59 | | hd->selection = false; |
60 | | return FR_SUCCESS; |
61 | | } |
62 | | |
63 | | // ----------------------------------------------------------------------------- |
64 | | |
65 | | /** |
66 | | * HistoryFunctions - All the NeoMutt functions that the History supports |
67 | | */ |
68 | | static const struct HistoryFunction HistoryFunctions[] = { |
69 | | // clang-format off |
70 | | { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry }, |
71 | | { OP_QUIT, op_quit }, |
72 | | { 0, NULL }, |
73 | | // clang-format on |
74 | | }; |
75 | | |
76 | | /** |
77 | | * history_function_dispatcher - Perform a History function - Implements ::function_dispatcher_t - @ingroup dispatcher_api |
78 | | */ |
79 | | int history_function_dispatcher(struct MuttWindow *win, int op) |
80 | 0 | { |
81 | | // The Dispatcher may be called on any Window in the Dialog |
82 | 0 | struct MuttWindow *dlg = dialog_find(win); |
83 | 0 | if (!dlg || !dlg->wdata) |
84 | 0 | return FR_ERROR; |
85 | | |
86 | 0 | struct Menu *menu = dlg->wdata; |
87 | 0 | struct HistoryData *hd = menu->mdata; |
88 | |
|
89 | 0 | int rc = FR_UNKNOWN; |
90 | 0 | for (size_t i = 0; HistoryFunctions[i].op != OP_NULL; i++) |
91 | 0 | { |
92 | 0 | const struct HistoryFunction *fn = &HistoryFunctions[i]; |
93 | 0 | if (fn->op == op) |
94 | 0 | { |
95 | 0 | rc = fn->function(hd, op); |
96 | 0 | break; |
97 | 0 | } |
98 | 0 | } |
99 | |
|
100 | 0 | if (rc == FR_UNKNOWN) // Not our function |
101 | 0 | return rc; |
102 | | |
103 | 0 | const char *result = dispatcher_get_retval_name(rc); |
104 | 0 | mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result)); |
105 | |
|
106 | 0 | return rc; |
107 | 0 | } |