NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
functions.c
Go to the documentation of this file.
1
29#include "config.h"
30#include "mutt/lib.h"
31#include "core/lib.h"
32#include "gui/lib.h"
33#include "functions.h"
34#include "menu/lib.h"
35
39static int op_generic_select_entry(struct HistoryData *hd, int op)
40{
41 const int index = menu_get_index(hd->menu);
42
43 const char **pentry = ARRAY_GET(hd->matches, index);
44 if (pentry)
45 buf_strcpy(hd->buf, *pentry);
46
47 hd->done = true;
48 hd->selection = true;
49 return FR_SUCCESS;
50}
51
55static int op_quit(struct HistoryData *hd, int op)
56{
57 hd->done = true;
58 hd->selection = false;
59 return FR_SUCCESS;
60}
61
62// -----------------------------------------------------------------------------
63
67static const struct HistoryFunction HistoryFunctions[] = {
68 // clang-format off
69 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
70 { OP_QUIT, op_quit },
71 { 0, NULL },
72 // clang-format on
73};
74
79{
80 // The Dispatcher may be called on any Window in the Dialog
81 struct MuttWindow *dlg = dialog_find(win);
82 if (!dlg || !dlg->wdata)
83 return FR_ERROR;
84
85 struct Menu *menu = dlg->wdata;
86 struct HistoryData *hd = menu->mdata;
87
88 int rc = FR_UNKNOWN;
89 for (size_t i = 0; HistoryFunctions[i].op != OP_NULL; i++)
90 {
91 const struct HistoryFunction *fn = &HistoryFunctions[i];
92 if (fn->op == op)
93 {
94 rc = fn->function(hd, op);
95 break;
96 }
97 }
98
99 if (rc == FR_UNKNOWN) // Not our function
100 return rc;
101
102 const char *result = dispatcher_get_retval_name(rc);
103 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
104
105 return rc;
106}
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
Convenience wrapper for the core headers.
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition: dialog.c:89
const char * dispatcher_get_retval_name(int rv)
Get the name of a return value.
Definition: dispatcher.c:54
@ FR_SUCCESS
Valid function - successfully performed.
Definition: dispatcher.h:39
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
@ FR_ERROR
Valid function - error occurred.
Definition: dispatcher.h:38
static int op_generic_select_entry(struct AliasMenuData *mdata, int op)
select the current entry - Implements alias_function_t -
Definition: functions.c:214
int history_function_dispatcher(struct MuttWindow *win, int op)
Perform a History function - Implements function_dispatcher_t -.
Definition: functions.c:78
static int op_quit(struct HistoryData *hd, int op)
Quit this menu - Implements history_function_t -.
Definition: functions.c:55
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
Convenience wrapper for the gui headers.
static const struct HistoryFunction HistoryFunctions[]
All the NeoMutt functions that the History supports.
Definition: functions.c:67
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
GUI present the user with a selectable list.
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:160
Convenience wrapper for the library headers.
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
Sidebar functions.
#define NONULL(x)
Definition: string2.h:37
Data to pass to the History Functions.
Definition: functions.h:38
struct Menu * menu
History Menu.
Definition: functions.h:42
struct Buffer * buf
Buffer for the results.
Definition: functions.h:41
struct HistoryArray * matches
History entries.
Definition: functions.h:43
bool done
Should we close the Dialog?
Definition: functions.h:39
bool selection
Was a selection made?
Definition: functions.h:40
A NeoMutt function.
Definition: functions.h:62
history_function_t function
Function to call.
Definition: functions.h:64
int op
Op code, e.g. OP_GENERIC_SELECT_ENTRY.
Definition: functions.h:63
Definition: lib.h:79
void * mdata
Private data.
Definition: lib.h:147
void * wdata
Private data.
Definition: mutt_window.h:144