NeoMutt  2025-12-11-435-g4ac674
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 <stdbool.h>
31#include <stdio.h>
32#include "mutt/lib.h"
33#include "core/lib.h"
34#include "gui/lib.h"
35#include "functions.h"
36#include "key/lib.h"
37#include "menu/lib.h"
38#include "pattern_data.h"
39
43static int op_generic_select_entry(struct PatternData *pd, const struct KeyEvent *event)
44{
45 const int index = menu_get_index(pd->menu);
46 struct PatternEntry *entry = ARRAY_GET(&pd->entries, index);
47
48 if (entry)
49 buf_strcpy(pd->buf, entry->tag);
50
51 pd->done = true;
52 pd->selection = true;
53 return FR_SUCCESS;
54}
55
59static int op_quit(struct PatternData *pd, const struct KeyEvent *event)
60{
61 pd->done = true;
62 pd->selection = false;
63 return FR_SUCCESS;
64}
65
66// -----------------------------------------------------------------------------
67
71static const struct PatternFunction PatternFunctions[] = {
72 // clang-format off
73 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
74 { OP_QUIT, op_quit },
75 { OP_EXIT, op_quit },
76 { 0, NULL },
77 // clang-format on
78};
79
83int pattern_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
84{
85 // The Dispatcher may be called on any Window in the Dialog
86 struct MuttWindow *dlg = dialog_find(win);
87 if (!event || !dlg || !dlg->wdata)
88 return FR_ERROR;
89
90 const int op = event->op;
91 struct Menu *menu = dlg->wdata;
92 struct PatternData *pd = menu->mdata;
93 if (!pd)
94 return FR_ERROR;
95
96 int rc = FR_UNKNOWN;
97 for (size_t i = 0; PatternFunctions[i].op != OP_NULL; i++)
98 {
99 const struct PatternFunction *fn = &PatternFunctions[i];
100 if (fn->op == op)
101 {
102 rc = fn->function(pd, event);
103 break;
104 }
105 }
106
107 if (rc == FR_UNKNOWN) // Not our function
108 return rc;
109
110 const char *result = dispatcher_get_retval_name(rc);
111 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
112
113 return rc;
114}
#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: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 AliasMenuData *mdata, const struct KeyEvent *event)
select the current entry - Implements alias_function_t -
Definition functions.c:248
int pattern_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Pattern function - Implements function_dispatcher_t -.
Definition functions.c:83
static int op_quit(struct HistoryData *hd, const struct KeyEvent *event)
Quit this menu - Implements history_function_t -.
Definition functions.c:57
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
Convenience wrapper for the gui headers.
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:164
Convenience wrapper for the library headers.
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition opcodes.c:48
static const struct PatternFunction PatternFunctions[]
All the NeoMutt functions that the Pattern supports.
Definition functions.c:71
Pattern functions.
Private Pattern Data.
#define NONULL(x)
Definition string2.h:44
An event such as a keypress.
Definition get.h:50
Definition lib.h:80
void * mdata
Private data.
Definition lib.h:149
void * wdata
Private data.
Data to pass to the Pattern Functions.
struct Menu * menu
Pattern Menu.
struct PatternEntryArray entries
Patterns for the Menu.
bool done
Should we close the Dialog?
struct Buffer * buf
Buffer for the results.
bool selection
Was a selection made?
A line in the Pattern Completion menu.
const char * tag
Copied to buffer if selected.
A NeoMutt function.
Definition functions.h:50
int op
Op code, e.g. OP_GENERIC_SELECT_ENTRY.
Definition functions.h:51
pattern_function_t function
Function to call.
Definition functions.h:52