NeoMutt  2022-04-29-249-gaae397
Teaching an old dog new tricks
DOXYGEN
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#include "opcodes.h"
37
41static int op_exit(struct PatternData *pd, int op)
42{
43 pd->done = true;
44 pd->selection = false;
45 return FR_SUCCESS;
46}
47
51static int op_generic_select_entry(struct PatternData *pd, int op)
52{
53 const int index = menu_get_index(pd->menu);
54 struct PatternEntry *entry = ((struct PatternEntry *) pd->menu->mdata) + index;
55 mutt_str_copy(pd->buf, entry->tag, pd->buflen);
56
57 pd->done = true;
58 pd->selection = true;
59 return FR_SUCCESS;
60}
61
62// -----------------------------------------------------------------------------
63
68 // clang-format off
69 { OP_EXIT, op_exit },
70 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
71 { 0, NULL },
72 // clang-format on
73};
74
79{
80 if (!win || !win->wdata)
81 return FR_UNKNOWN;
82
83 struct MuttWindow *dlg = dialog_find(win);
84 if (!dlg)
85 return FR_ERROR;
86
87 struct PatternData *pd = dlg->wdata;
88
89 int rc = FR_UNKNOWN;
90 for (size_t i = 0; PatternFunctions[i].op != OP_NULL; i++)
91 {
92 const struct PatternFunction *fn = &PatternFunctions[i];
93 if (fn->op == op)
94 {
95 rc = fn->function(pd, op);
96 break;
97 }
98 }
99
100 if (rc == FR_UNKNOWN) // Not our function
101 return rc;
102
103 const char *result = dispacher_get_retval_name(rc);
104 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
105
106 return rc;
107}
Convenience wrapper for the core headers.
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition: dialog.c:83
const char * dispacher_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
int pattern_function_dispatcher(struct MuttWindow *win, int op)
Perform a Pattern function - Implements function_dispatcher_t -.
Definition: functions.c:78
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static int op_exit(struct PatternData *pd, int op)
Exit this menu - Implements pattern_function_t -.
Definition: functions.c:41
static int op_generic_select_entry(struct PatternData *pd, int op)
Select the current entry - Implements pattern_function_t -.
Definition: functions.c:51
Convenience wrapper for the gui headers.
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
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:154
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:652
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:46
All user-callable functions.
struct PatternFunction PatternFunctions[]
All the NeoMutt functions that the Pattern supports.
Definition: functions.c:67
Sidebar functions.
GUI display the mailboxes in a side panel.
#define NONULL(x)
Definition: string2.h:37
void * mdata
Private data.
Definition: lib.h:137
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:34
const char * tag
Copied to buffer if selected.
Definition: private.h:36
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