NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
functions.c
Go to the documentation of this file.
1
22
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 "key/lib.h"
36#include "menu/lib.h"
37
41static int op_generic_select_entry(struct HistoryData *hd, const struct KeyEvent *event)
42{
43 const int index = menu_get_index(hd->menu);
44
45 const char **pentry = ARRAY_GET(hd->matches, index);
46 if (pentry)
47 buf_strcpy(hd->buf, *pentry);
48
49 hd->done = true;
50 hd->selection = true;
51 return FR_SUCCESS;
52}
53
61static int op_quit(struct HistoryData *hd, const struct KeyEvent *event)
62{
63 hd->done = true;
64 hd->selection = false;
65 return FR_SUCCESS;
66}
67
68// -----------------------------------------------------------------------------
69
73static const struct HistoryFunction HistoryFunctions[] = {
74 // clang-format off
75 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
76 { OP_QUIT, op_quit },
77 { OP_EXIT, op_quit },
78 { 0, NULL },
79 // clang-format on
80};
81
85int history_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
86{
87 // The Dispatcher may be called on any Window in the Dialog
88 struct MuttWindow *dlg = dialog_find(win);
89 if (!event || !dlg || !dlg->wdata)
90 {
92 return FR_ERROR;
93 }
94
95 const int op = event->op;
96 struct Menu *menu = dlg->wdata;
97 struct HistoryData *hd = menu->mdata;
98 if (!hd)
99 {
101 return FR_ERROR;
102 }
103
104 int rc = FR_UNKNOWN;
105 for (size_t i = 0; HistoryFunctions[i].op != OP_NULL; i++)
106 {
107 const struct HistoryFunction *fn = &HistoryFunctions[i];
108 if (fn->op == op)
109 {
110 rc = fn->function(hd, event);
111 break;
112 }
113 }
114
115 if (rc == FR_UNKNOWN) // Not our function
116 return rc;
117
118 const char *result = dispatcher_get_retval_name(rc);
119 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
120
122 return rc;
123}
#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:55
void dispatcher_flush_on_error(int rv)
Flush pending keys after a dispatch error.
Definition dispatcher.c:65
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
@ FR_UNKNOWN
Unknown function.
Definition dispatcher.h:34
@ FR_ERROR
Valid function - error occurred.
Definition dispatcher.h:39
static int op_generic_select_entry(struct AliasFunctionData *fdata, const struct KeyEvent *event)
select the current entry - Implements alias_function_t -
Definition functions.c:392
int history_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a History function - Implements function_dispatcher_t -.
Definition functions.c:85
static int op_quit(struct HistoryData *hd, const struct KeyEvent *event)
Quit this menu - Implements history_function_t -.
Definition functions.c:61
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
Convenience wrapper for the gui headers.
static const struct HistoryFunction HistoryFunctions[]
All the NeoMutt functions that the History supports.
Definition functions.c:73
History functions.
Manage keymappings.
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
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:155
Convenience wrapper for the library headers.
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition opcodes.c:48
#define NONULL(x)
Definition string2.h:44
Data to pass to the History Functions.
Definition functions.h:35
struct Menu * menu
History Menu.
Definition functions.h:39
struct Buffer * buf
Buffer for the results.
Definition functions.h:38
struct StringArray * matches
History entries.
Definition functions.h:40
bool done
Should we close the Dialog?
Definition functions.h:36
bool selection
Was a selection made?
Definition functions.h:37
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
An event such as a keypress.
Definition get.h:75
Definition lib.h:86
void * mdata
Private data.
Definition lib.h:155
void * wdata
Private data.