NeoMutt  2023-11-03-85-g512e01
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#ifdef _MAKEDOC
31#include "docs/makedoc_defs.h"
32#else
33#include <stddef.h>
34#include "mutt/lib.h"
35#include "config/lib.h"
36#include "core/lib.h"
37#include "gui/lib.h"
38#include "mutt.h"
39#include "key/lib.h"
40#include "menu/lib.h"
41#include "pattern/lib.h"
42#include "functions.h"
43#include "mview.h"
44#include "protos.h"
45#endif
46
47// clang-format off
51const struct MenuFuncOp OpPostponed[] = { /* map: postpone */
52 { "exit", OP_EXIT },
53 { "delete-entry", OP_DELETE },
54 { "undelete-entry", OP_UNDELETE },
55 { NULL, 0 },
56};
57
61const struct MenuOpSeq PostponedDefaultBindings[] = { /* map: postpone */
62 { OP_DELETE, "d" },
63 { OP_EXIT, "q" },
64 { OP_UNDELETE, "u" },
65 { 0, NULL },
66};
67// clang-format on
68
72static int op_delete(struct PostponeData *pd, int op)
73{
74 struct Menu *menu = pd->menu;
75 struct MailboxView *mv = pd->mailbox_view;
76 struct Mailbox *m = mv->mailbox;
77
78 const int index = menu_get_index(menu);
79 /* should deleted draft messages be saved in the trash folder? */
80 mutt_set_flag(m, m->emails[index], MUTT_DELETE, (op == OP_DELETE), true);
82 const bool c_resolve = cs_subset_bool(NeoMutt->sub, "resolve");
83 if (c_resolve && (index < (menu->max - 1)))
84 {
85 menu_set_index(menu, index + 1);
86 if (index >= (menu->top + menu->page_len))
87 {
88 menu->top = index;
90 }
91 }
92 else
93 {
95 }
96
97 return FR_SUCCESS;
98}
99
103static int op_exit(struct PostponeData *pd, int op)
104{
105 pd->done = true;
106 return FR_SUCCESS;
107}
108
112static int op_generic_select_entry(struct PostponeData *pd, int op)
113{
114 int index = menu_get_index(pd->menu);
115 struct MailboxView *mv = pd->mailbox_view;
116 struct Mailbox *m = mv->mailbox;
117 pd->email = m->emails[index];
118 pd->done = true;
119 return FR_SUCCESS;
120}
121
125static int op_search(struct PostponeData *pd, int op)
126{
128 switch (op)
129 {
130 case OP_SEARCH:
131 flags |= SEARCH_PROMPT;
132 pd->search_state->reverse = false;
133 break;
134 case OP_SEARCH_REVERSE:
135 flags |= SEARCH_PROMPT;
136 pd->search_state->reverse = true;
137 break;
138 case OP_SEARCH_NEXT:
139 break;
140 case OP_SEARCH_OPPOSITE:
141 flags |= SEARCH_OPPOSITE;
142 break;
143 }
144
145 int index = menu_get_index(pd->menu);
146 struct MailboxView *mv = pd->mailbox_view;
147 index = mutt_search_command(mv, pd->menu, index, pd->search_state, flags);
148 if (index != -1)
149 menu_set_index(pd->menu, index);
150
151 return FR_SUCCESS;
152}
153
154// -----------------------------------------------------------------------------
155
159static const struct PostponeFunction PostponeFunctions[] = {
160 // clang-format off
161 { OP_DELETE, op_delete },
162 { OP_EXIT, op_exit },
163 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
164 { OP_SEARCH, op_search },
165 { OP_SEARCH_NEXT, op_search },
166 { OP_SEARCH_OPPOSITE, op_search },
167 { OP_SEARCH_REVERSE, op_search },
168 { OP_UNDELETE, op_delete },
169 { 0, NULL },
170 // clang-format on
171};
172
177{
178 if (!win || !win->wdata)
179 return FR_UNKNOWN;
180
181 struct MuttWindow *dlg = dialog_find(win);
182 if (!dlg)
183 return FR_ERROR;
184
185 struct PostponeData *pd = dlg->wdata;
186
187 int rc = FR_UNKNOWN;
188 for (size_t i = 0; PostponeFunctions[i].op != OP_NULL; i++)
189 {
190 const struct PostponeFunction *fn = &PostponeFunctions[i];
191 if (fn->op == op)
192 {
193 rc = fn->function(pd, op);
194 break;
195 }
196 }
197
198 if (rc == FR_UNKNOWN) // Not our function
199 return rc;
200
201 const char *result = dispatcher_get_retval_name(rc);
202 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
203
204 return rc;
205}
206
213{
214 if (!dlg)
215 return NULL;
216
217 struct PostponeData *pd = dlg->wdata;
218 if (!pd)
219 return NULL;
220
221 return pd->mailbox_view;
222}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
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: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
void mutt_set_flag(struct Mailbox *m, struct Email *e, enum MessageType flag, bool bf, bool upd_mbox)
Set a flag on an email.
Definition: flags.c:53
static int op_delete(struct AliasMenuData *mdata, int op)
delete the current entry - Implements alias_function_t -
Definition: functions.c:158
static int op_generic_select_entry(struct AliasMenuData *mdata, int op)
select the current entry - Implements alias_function_t -
Definition: functions.c:204
static int op_exit(struct AliasMenuData *mdata, int op)
exit this menu - Implements alias_function_t -
Definition: functions.c:190
static int op_search(struct AliasMenuData *mdata, int op)
search for a regular expression - Implements alias_function_t -
Definition: functions.c:309
int postpone_function_dispatcher(struct MuttWindow *win, int op)
Perform a Postpone function - Implements function_dispatcher_t -.
Definition: functions.c:176
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
Convenience wrapper for the gui headers.
Manage keymappings.
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
GUI present the user with a selectable list.
#define MENU_REDRAW_INDEX
Redraw the index.
Definition: lib.h:57
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:180
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:156
#define MENU_REDRAW_CURRENT
Redraw the current line of the menu.
Definition: lib.h:59
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:170
Convenience wrapper for the library headers.
Many unsorted constants and some structs.
@ MUTT_DELETE
Messages to be deleted.
Definition: mutt.h:74
View of a Mailbox.
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
Match patterns to emails.
int mutt_search_command(struct MailboxView *mv, struct Menu *menu, int cur, struct SearchState *state, SearchFlags flags)
Perform a search.
Definition: pattern.c:438
const struct MenuFuncOp OpPostponed[]
Functions for the Postpone Menu.
Definition: functions.c:51
const struct MenuOpSeq PostponedDefaultBindings[]
Key bindings for the Postpone Menu.
Definition: functions.c:61
struct MailboxView * postponed_get_mailbox_view(struct MuttWindow *dlg)
Extract the Mailbox from the Postponed Dialog.
Definition: functions.c:212
static const struct PostponeFunction PostponeFunctions[]
All the NeoMutt functions that the Postpone supports.
Definition: functions.c:159
short PostCount
Number of postponed (draft) emails.
Definition: postpone.c:56
Prototypes for many functions.
#define SEARCH_OPPOSITE
Search in the opposite direction.
Definition: search_state.h:45
uint8_t SearchFlags
Flags for a specific search, e.g. SEARCH_PROMPT.
Definition: search_state.h:42
#define SEARCH_NO_FLAGS
No flags are set.
Definition: search_state.h:43
#define SEARCH_PROMPT
Ask for search input.
Definition: search_state.h:44
Sidebar functions.
#define NONULL(x)
Definition: string2.h:37
View of a Mailbox.
Definition: mview.h:39
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:50
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
Mapping between a function and an operation.
Definition: lib.h:102
Mapping between an operation and a key sequence.
Definition: lib.h:111
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:112
Definition: lib.h:70
int top
Entry that is the top of the current page.
Definition: lib.h:81
int max
Number of entries in the menu.
Definition: lib.h:72
int page_len
Number of entries per screen.
Definition: lib.h:75
void * wdata
Private data.
Definition: mutt_window.h:145
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
Data to pass to the Postpone Functions.
Definition: functions.h:34
struct Email * email
Selected Email.
Definition: functions.h:37
struct SearchState * search_state
State of the current search.
Definition: functions.h:39
bool done
Should we close the Dialog?
Definition: functions.h:38
struct MailboxView * mailbox_view
Postponed Mailbox view.
Definition: functions.h:35
struct Menu * menu
Postponed Menu.
Definition: functions.h:36
A NeoMutt function.
Definition: functions.h:58
postpone_function_t function
Function to call.
Definition: functions.h:60
int op
Op code, e.g. OP_DELETE.
Definition: functions.h:59
bool reverse
search backwards
Definition: search_state.h:39