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