NeoMutt  2024-11-14-34-g5aaf0d
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 <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 "menu/lib.h"
37#include "pattern_data.h"
38
42static int op_generic_select_entry(struct PatternData *pd, int op)
43{
44 const int index = menu_get_index(pd->menu);
45 struct PatternEntry *entry = ARRAY_GET(&pd->entries, index);
46
47 if (entry)
48 buf_strcpy(pd->buf, entry->tag);
49
50 pd->done = true;
51 pd->selection = true;
52 return FR_SUCCESS;
53}
54
58static int op_quit(struct PatternData *pd, int op)
59{
60 pd->done = true;
61 pd->selection = false;
62 return FR_SUCCESS;
63}
64
65// -----------------------------------------------------------------------------
66
70static const struct PatternFunction PatternFunctions[] = {
71 // clang-format off
72 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
73 { OP_QUIT, op_quit },
74 { 0, NULL },
75 // clang-format on
76};
77
82{
83 // The Dispatcher may be called on any Window in the Dialog
84 struct MuttWindow *dlg = dialog_find(win);
85 if (!dlg || !dlg->wdata)
86 return FR_ERROR;
87
88 struct Menu *menu = dlg->wdata;
89 struct PatternData *pd = menu->mdata;
90
91 int rc = FR_UNKNOWN;
92 for (size_t i = 0; PatternFunctions[i].op != OP_NULL; i++)
93 {
94 const struct PatternFunction *fn = &PatternFunctions[i];
95 if (fn->op == op)
96 {
97 rc = fn->function(pd, op);
98 break;
99 }
100 }
101
102 if (rc == FR_UNKNOWN) // Not our function
103 return rc;
104
105 const char *result = dispatcher_get_retval_name(rc);
106 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
107
108 return rc;
109}
#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: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:214
int pattern_function_dispatcher(struct MuttWindow *win, int op)
Perform a Pattern function - Implements function_dispatcher_t -.
Definition: functions.c:81
static int op_quit(struct HistoryData *hd, int op)
Quit this menu - Implements history_function_t -.
Definition: functions.c:55
#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.
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:70
Private Pattern Data.
Sidebar functions.
#define NONULL(x)
Definition: string2.h:37
Definition: lib.h:79
void * mdata
Private data.
Definition: lib.h:147
void * wdata
Private data.
Definition: mutt_window.h:144
Data to pass to the Pattern Functions.
Definition: pattern_data.h:47
struct Menu * menu
Pattern Menu.
Definition: pattern_data.h:51
struct PatternEntryArray entries
Patterns for the Menu.
Definition: pattern_data.h:52
bool done
Should we close the Dialog?
Definition: pattern_data.h:48
struct Buffer * buf
Buffer for the results.
Definition: pattern_data.h:50
bool selection
Was a selection made?
Definition: pattern_data.h:49
A line in the Pattern Completion menu.
Definition: pattern_data.h:35
const char * tag
Copied to buffer if selected.
Definition: pattern_data.h:37
A NeoMutt function.
Definition: functions.h:46
int op
Op code, e.g. OP_GENERIC_SELECT_ENTRY.
Definition: functions.h:47
pattern_function_t function
Function to call.
Definition: functions.h:48