NeoMutt  2025-12-11-872-g385a04
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
44 const struct KeyEvent *event)
45{
46 struct PatternData *pd = fdata->pd;
47 const int index = menu_get_index(pd->menu);
48 struct PatternEntry *entry = ARRAY_GET(&pd->entries, index);
49
50 if (entry)
51 buf_strcpy(pd->buf, entry->tag);
52
53 pd->done = true;
54 pd->selection = true;
55 return FR_SUCCESS;
56}
57
65static int op_quit(struct PatternFunctionData *fdata, const struct KeyEvent *event)
66{
67 struct PatternData *pd = fdata->pd;
68 pd->done = true;
69 pd->selection = false;
70 return FR_SUCCESS;
71}
72
73// -----------------------------------------------------------------------------
74
78static const struct PatternFunction PatternFunctions[] = {
79 // clang-format off
80 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
81 { OP_QUIT, op_quit },
82 { OP_EXIT, op_quit },
83 { 0, NULL },
84 // clang-format on
85};
86
90int pattern_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
91{
92 // The Dispatcher may be called on any Window in the Dialog
93 struct MuttWindow *dlg = dialog_find(win);
94 if (!event || !dlg || !dlg->wdata)
95 {
97 return FR_ERROR;
98 }
99
100 const int op = event->op;
101 struct Menu *menu = dlg->wdata;
102 struct PatternData *pd = menu->mdata;
103 if (!pd)
104 {
106 return FR_ERROR;
107 }
108
109 struct PatternFunctionData fdata = {
110 .n = NeoMutt,
111 .pd = pd,
112 };
113
114 int rc = FR_UNKNOWN;
115 for (size_t i = 0; PatternFunctions[i].op != OP_NULL; i++)
116 {
117 const struct PatternFunction *fn = &PatternFunctions[i];
118 if (fn->op == op)
119 {
120 rc = fn->function(&fdata, event);
121 break;
122 }
123 }
124
125 if (rc == FR_UNKNOWN) // Not our function
126 return rc;
127
128 const char *result = dispatcher_get_retval_name(rc);
129 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
130
132 return rc;
133}
#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:349
int pattern_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Pattern function - Implements function_dispatcher_t -.
Definition functions.c:90
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.
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
static const struct PatternFunction PatternFunctions[]
All the NeoMutt functions that the Pattern supports.
Definition functions.c:78
Pattern functions.
Private Pattern Data.
#define NONULL(x)
Definition string2.h:44
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.
Container for Accounts, Notifications.
Definition neomutt.h:41
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.
Data passed to Pattern worker functions.
Definition functions.h:33
struct PatternData * pd
Pattern data.
Definition functions.h:35
A NeoMutt function.
Definition functions.h:57
int op
Op code, e.g. OP_GENERIC_SELECT_ENTRY.
Definition functions.h:58
pattern_function_t function
Function to call.
Definition functions.h:59