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 <stddef.h>
31#include "mutt/lib.h"
32#include "config/lib.h"
33#include "core/lib.h"
34#include "gui/lib.h"
35#include "mutt.h"
36#include "functions.h"
37#include "menu/lib.h"
38#include "pattern/lib.h"
39#include "opcodes.h"
40#include "protos.h"
41
42struct Email;
43
47static int op_delete(struct PostponeData *pd, int op)
48{
49 struct Menu *menu = pd->menu;
50 struct Mailbox *m = pd->mailbox;
51
52 const int index = menu_get_index(menu);
53 /* should deleted draft messages be saved in the trash folder? */
54 mutt_set_flag(m, m->emails[index], MUTT_DELETE, (op == OP_DELETE));
56 const bool c_resolve = cs_subset_bool(NeoMutt->sub, "resolve");
57 if (c_resolve && (index < (menu->max - 1)))
58 {
59 menu_set_index(menu, index + 1);
60 if (index >= (menu->top + menu->page_len))
61 {
62 menu->top = index;
64 }
65 }
66 else
67 {
69 }
70
71 return FR_SUCCESS;
72}
73
77static int op_exit(struct PostponeData *pd, int op)
78{
79 pd->done = true;
80 return FR_SUCCESS;
81}
82
86static int op_generic_select_entry(struct PostponeData *pd, int op)
87{
88 int index = menu_get_index(pd->menu);
89 pd->email = pd->mailbox->emails[index];
90 pd->done = true;
91 return FR_SUCCESS;
92}
93
97static int op_search(struct PostponeData *pd, int op)
98{
99 int index = menu_get_index(pd->menu);
100 index = mutt_search_command(pd->mailbox, pd->menu, index, op);
101 if (index != -1)
102 menu_set_index(pd->menu, index);
103
104 return FR_SUCCESS;
105}
106
107// -----------------------------------------------------------------------------
108
113 // clang-format off
114 { OP_DELETE, op_delete },
115 { OP_EXIT, op_exit },
116 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
117 { OP_SEARCH, op_search },
118 { OP_SEARCH_NEXT, op_search },
119 { OP_SEARCH_OPPOSITE, op_search },
120 { OP_SEARCH_REVERSE, op_search },
121 { OP_UNDELETE, op_delete },
122 { 0, NULL },
123 // clang-format on
124};
125
130{
131 if (!win || !win->wdata)
132 return FR_UNKNOWN;
133
134 struct MuttWindow *dlg = dialog_find(win);
135 if (!dlg)
136 return FR_ERROR;
137
138 struct PostponeData *pd = dlg->wdata;
139
140 int rc = FR_UNKNOWN;
141 for (size_t i = 0; PostponeFunctions[i].op != OP_NULL; i++)
142 {
143 const struct PostponeFunction *fn = &PostponeFunctions[i];
144 if (fn->op == op)
145 {
146 rc = fn->function(pd, op);
147 break;
148 }
149 }
150
151 if (rc == FR_UNKNOWN) // Not our function
152 return rc;
153
154 const char *result = dispacher_get_retval_name(rc);
155 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
156
157 return rc;
158}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Convenience wrapper for the config headers.
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 postpone_function_dispatcher(struct MuttWindow *win, int op)
Perform a Postpone function - Implements function_dispatcher_t -.
Definition: functions.c:129
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static int op_delete(struct PostponeData *pd, int op)
Delete the current entry - Implements postpone_function_t -.
Definition: functions.c:47
static int op_search(struct PostponeData *pd, int op)
Search for a regular expression - Implements postpone_function_t -.
Definition: functions.c:97
static int op_exit(struct PostponeData *pd, int op)
Exit this menu - Implements postpone_function_t -.
Definition: functions.c:77
static int op_generic_select_entry(struct PostponeData *pd, int op)
Select the current entry - Implements postpone_function_t -.
Definition: functions.c:86
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.
#define MENU_REDRAW_INDEX
Redraw the index.
Definition: lib.h:56
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:178
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:154
#define MENU_REDRAW_CURRENT
Redraw the current line of the menu.
Definition: lib.h:58
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:168
Convenience wrapper for the library headers.
Many unsorted constants and some structs.
@ MUTT_DELETE
Messages to be deleted.
Definition: mutt.h:95
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:46
All user-callable functions.
Match patterns to emails.
int mutt_search_command(struct Mailbox *m, struct Menu *menu, int cur, int op)
Perform a search.
Definition: pattern.c:494
struct PostponeFunction PostponeFunctions[]
All the NeoMutt functions that the Postpone supports.
Definition: functions.c:112
short PostCount
Definition: postpone.c:58
Prototypes for many functions.
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:63
Sidebar functions.
#define NONULL(x)
Definition: string2.h:37
The envelope/body of an email.
Definition: email.h:37
A mailbox.
Definition: mailbox.h:79
int msg_count
Total number of messages.
Definition: mailbox.h:88
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:93
Definition: lib.h:69
int top
Entry that is the top of the current page.
Definition: lib.h:80
int max
Number of entries in the menu.
Definition: lib.h:71
int page_len
Number of entries per screen.
Definition: lib.h:74
void * wdata
Private data.
Definition: mutt_window.h:145
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Data to pass to the Postpone Functions.
Definition: functions.h:34
struct Email * email
Selected Email.
Definition: functions.h:38
struct Mailbox * mailbox
Postponed Mailbox.
Definition: functions.h:36
bool done
Should we close the Dialog?
Definition: functions.h:35
struct Menu * menu
Postponed Menu.
Definition: functions.h:37
A NeoMutt function.
Definition: functions.h:57
postpone_function_t function
Function to call.
Definition: functions.h:59
int op
Op code, e.g. OP_DELETE.
Definition: functions.h:58