NeoMutt  2024-03-23-147-g885fbc
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 "private.h"
31#include "mutt/lib.h"
32#include "core/lib.h"
33#include "gui/lib.h"
34#include "functions.h"
35#include "menu/lib.h"
36
40static int op_generic_select_entry(struct PatternData *pd, int op)
41{
42 const int index = menu_get_index(pd->menu);
43 struct PatternEntry *entry = ((struct PatternEntry *) pd->menu->mdata) + index;
44 mutt_str_copy(pd->buf, entry->tag, pd->buflen);
45
46 pd->done = true;
47 pd->selection = true;
48 return FR_SUCCESS;
49}
50
54static int op_quit(struct PatternData *pd, int op)
55{
56 pd->done = true;
57 pd->selection = false;
58 return FR_SUCCESS;
59}
60
61// -----------------------------------------------------------------------------
62
66static const struct PatternFunction PatternFunctions[] = {
67 // clang-format off
68 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
69 { OP_QUIT, op_quit },
70 { 0, NULL },
71 // clang-format on
72};
73
78{
79 if (!win || !win->wdata)
80 return FR_UNKNOWN;
81
82 struct MuttWindow *dlg = dialog_find(win);
83 if (!dlg)
84 return FR_ERROR;
85
86 struct PatternData *pd = dlg->wdata;
87
88 int rc = FR_UNKNOWN;
89 for (size_t i = 0; PatternFunctions[i].op != OP_NULL; i++)
90 {
91 const struct PatternFunction *fn = &PatternFunctions[i];
92 if (fn->op == op)
93 {
94 rc = fn->function(pd, 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}
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:205
int pattern_function_dispatcher(struct MuttWindow *win, int op)
Perform a Pattern function - Implements function_dispatcher_t -.
Definition: functions.c:77
static int op_quit(struct HistoryData *hd, int op)
Quit this menu - Implements history_function_t -.
Definition: functions.c:52
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
Convenience wrapper for the gui headers.
@ 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.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:630
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:66
Sidebar functions.
GUI display the mailboxes in a side panel.
#define NONULL(x)
Definition: string2.h:37
void * mdata
Private data.
Definition: lib.h:147
void * wdata
Private data.
Definition: mutt_window.h:145
Data to pass to the Pattern Functions.
Definition: functions.h:35
char * buf
Buffer for the results.
Definition: functions.h:38
struct Menu * menu
Pattern Menu.
Definition: functions.h:40
bool done
Should we close the Dialog?
Definition: functions.h:36
size_t buflen
Length of the results buffer.
Definition: functions.h:39
bool selection
Was a selection made?
Definition: functions.h:37
A line in the Pattern Completion menu.
Definition: private.h:37
const char * tag
Copied to buffer if selected.
Definition: private.h:39
A NeoMutt function.
Definition: functions.h:59
int op
Op code, e.g. OP_GENERIC_SELECT_ENTRY.
Definition: functions.h:60
pattern_function_t function
Function to call.
Definition: functions.h:61