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 "mutt/lib.h"
31#include "core/lib.h"
32#include "gui/lib.h"
33#include "functions.h"
34#include "menu/lib.h"
35#include "opcodes.h"
36
40static int op_exit(struct HistoryData *hd, int op)
41{
42 hd->done = true;
43 hd->selection = false;
44 return FR_SUCCESS;
45}
46
50static int op_generic_select_entry(struct HistoryData *hd, int op)
51{
52 const int index = menu_get_index(hd->menu);
53 mutt_str_copy(hd->buf, hd->matches[index], hd->buflen);
54
55 hd->done = true;
56 hd->selection = true;
57 return FR_SUCCESS;
58}
59
60// -----------------------------------------------------------------------------
61
66 // clang-format off
67 { OP_EXIT, op_exit },
68 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
69 { 0, NULL },
70 // clang-format on
71};
72
77{
78 if (!win || !win->wdata)
79 return FR_UNKNOWN;
80
81 struct MuttWindow *dlg = dialog_find(win);
82 if (!dlg)
83 return FR_ERROR;
84
85 struct HistoryData *hd = dlg->wdata;
86
87 int rc = FR_UNKNOWN;
88 for (size_t i = 0; HistoryFunctions[i].op != OP_NULL; i++)
89 {
90 const struct HistoryFunction *fn = &HistoryFunctions[i];
91 if (fn->op == op)
92 {
93 rc = fn->function(hd, op);
94 break;
95 }
96 }
97
98 if (rc == FR_UNKNOWN) // Not our function
99 return rc;
100
101 const char *result = dispacher_get_retval_name(rc);
102 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
103
104 return rc;
105}
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 history_function_dispatcher(struct MuttWindow *win, int op)
Perform a History function - Implements function_dispatcher_t -.
Definition: functions.c:76
static int op_exit(struct HistoryData *hd, int op)
Exit this menu - Implements history_function_t -.
Definition: functions.c:40
static int op_generic_select_entry(struct HistoryData *hd, int op)
Select the current entry - Implements history_function_t -.
Definition: functions.c:50
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
Convenience wrapper for the gui headers.
struct HistoryFunction HistoryFunctions[]
All the NeoMutt functions that the History supports.
Definition: functions.c:65
@ 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.
Sidebar functions.
#define NONULL(x)
Definition: string2.h:37
Data to pass to the History Functions.
Definition: functions.h:35
size_t buflen
Length of the results buffer.
Definition: functions.h:39
struct Menu * menu
History Menu.
Definition: functions.h:40
char ** matches
History entries.
Definition: functions.h:41
bool done
Should we close the Dialog?
Definition: functions.h:36
char * buf
Buffer for the results.
Definition: functions.h:38
bool selection
Was a selection made?
Definition: functions.h:37
A NeoMutt function.
Definition: functions.h:61
history_function_t function
Function to call.
Definition: functions.h:63
int op
Op code, e.g. OP_GENERIC_SELECT_ENTRY.
Definition: functions.h:62
void * wdata
Private data.
Definition: mutt_window.h:145