NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
functions.c
Go to the documentation of this file.
1
30#include "config.h"
31#ifdef _MAKEDOC
32#include "docs/makedoc_defs.h"
33#else
34#include <stddef.h>
35#include "mutt/lib.h"
36#include "config/lib.h"
37#include "core/lib.h"
38#include "gui/lib.h"
39#include "mutt.h"
40#include "key/lib.h"
41#include "menu/lib.h"
42#include "pattern/lib.h"
43#include "functions.h"
44#include "mview.h"
45#include "protos.h"
46#endif
47
48// clang-format off
52const struct MenuFuncOp OpPostponed[] = { /* map: postpone */
53 { "exit", OP_EXIT },
54 { "delete-entry", OP_DELETE },
55 { "undelete-entry", OP_UNDELETE },
56 { NULL, 0 },
57};
58
62const struct MenuOpSeq PostponedDefaultBindings[] = { /* map: postpone */
63 { OP_DELETE, "d" },
64 { OP_EXIT, "q" },
65 { OP_UNDELETE, "u" },
66 { 0, NULL },
67};
68// clang-format on
69
73static int op_delete(struct PostponeData *pd, int op)
74{
75 struct Menu *menu = pd->menu;
76 struct MailboxView *mv = pd->mailbox_view;
77 struct Mailbox *m = mv->mailbox;
78
79 const int index = menu_get_index(menu);
80 /* should deleted draft messages be saved in the trash folder? */
81 mutt_set_flag(m, m->emails[index], MUTT_DELETE, (op == OP_DELETE), true);
83 const bool c_resolve = cs_subset_bool(NeoMutt->sub, "resolve");
84 if (c_resolve && (index < (menu->max - 1)))
85 {
86 menu_set_index(menu, index + 1);
87 if (index >= (menu->top + menu->page_len))
88 {
89 menu->top = index;
91 }
92 }
93 else
94 {
96 }
97
98 return FR_SUCCESS;
99}
100
104static int op_exit(struct PostponeData *pd, int op)
105{
106 pd->done = true;
107 return FR_SUCCESS;
108}
109
113static int op_generic_select_entry(struct PostponeData *pd, int op)
114{
115 int index = menu_get_index(pd->menu);
116 struct MailboxView *mv = pd->mailbox_view;
117 struct Mailbox *m = mv->mailbox;
118 pd->email = m->emails[index];
119 pd->done = true;
120 return FR_SUCCESS;
121}
122
126static int op_search(struct PostponeData *pd, int op)
127{
129 switch (op)
130 {
131 case OP_SEARCH:
132 flags |= SEARCH_PROMPT;
133 pd->search_state->reverse = false;
134 break;
135 case OP_SEARCH_REVERSE:
136 flags |= SEARCH_PROMPT;
137 pd->search_state->reverse = true;
138 break;
139 case OP_SEARCH_NEXT:
140 break;
141 case OP_SEARCH_OPPOSITE:
142 flags |= SEARCH_OPPOSITE;
143 break;
144 }
145
146 int index = menu_get_index(pd->menu);
147 struct MailboxView *mv = pd->mailbox_view;
148 index = mutt_search_command(mv, pd->menu, index, pd->search_state, flags);
149 if (index != -1)
150 menu_set_index(pd->menu, index);
151
152 return FR_SUCCESS;
153}
154
155// -----------------------------------------------------------------------------
156
160static const struct PostponeFunction PostponeFunctions[] = {
161 // clang-format off
162 { OP_DELETE, op_delete },
163 { OP_EXIT, op_exit },
164 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
165 { OP_SEARCH, op_search },
166 { OP_SEARCH_NEXT, op_search },
167 { OP_SEARCH_OPPOSITE, op_search },
168 { OP_SEARCH_REVERSE, op_search },
169 { OP_UNDELETE, op_delete },
170 { 0, NULL },
171 // clang-format on
172};
173
178{
179 if (!win || !win->wdata)
180 return FR_UNKNOWN;
181
182 struct MuttWindow *dlg = dialog_find(win);
183 if (!dlg)
184 return FR_ERROR;
185
186 struct PostponeData *pd = dlg->wdata;
187
188 int rc = FR_UNKNOWN;
189 for (size_t i = 0; PostponeFunctions[i].op != OP_NULL; i++)
190 {
191 const struct PostponeFunction *fn = &PostponeFunctions[i];
192 if (fn->op == op)
193 {
194 rc = fn->function(pd, op);
195 break;
196 }
197 }
198
199 if (rc == FR_UNKNOWN) // Not our function
200 return rc;
201
202 const char *result = dispatcher_get_retval_name(rc);
203 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
204
205 return rc;
206}
207
214{
215 if (!dlg)
216 return NULL;
217
218 struct PostponeData *pd = dlg->wdata;
219 if (!pd)
220 return NULL;
221
222 return pd->mailbox_view;
223}
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:57
static int op_delete(struct AliasMenuData *mdata, int op)
delete the current entry - Implements alias_function_t -
Definition: functions.c:159
static int op_generic_select_entry(struct AliasMenuData *mdata, int op)
select the current entry - Implements alias_function_t -
Definition: functions.c:205
static int op_exit(struct AliasMenuData *mdata, int op)
exit this menu - Implements alias_function_t -
Definition: functions.c:191
static int op_search(struct AliasMenuData *mdata, int op)
search for a regular expression - Implements alias_function_t -
Definition: functions.c:310
int postpone_function_dispatcher(struct MuttWindow *win, int op)
Perform a Postpone function - Implements function_dispatcher_t -.
Definition: functions.c:177
#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:56
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:184
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:160
#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:174
Convenience wrapper for the library headers.
Many unsorted constants and some structs.
@ MUTT_DELETE
Messages to be deleted.
Definition: mutt.h:75
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:456
const struct MenuFuncOp OpPostponed[]
Functions for the Postpone Menu.
Definition: functions.c:52
const struct MenuOpSeq PostponedDefaultBindings[]
Key bindings for the Postpone Menu.
Definition: functions.c:62
struct MailboxView * postponed_get_mailbox_view(struct MuttWindow *dlg)
Extract the Mailbox from the Postponed Dialog.
Definition: functions.c:213
static const struct PostponeFunction PostponeFunctions[]
All the NeoMutt functions that the Postpone supports.
Definition: functions.c:160
short PostCount
Number of postponed (draft) emails.
Definition: postpone.c:58
Prototypes for many functions.
#define SEARCH_OPPOSITE
Search in the opposite direction.
Definition: search_state.h:46
uint8_t SearchFlags
Flags for a specific search, e.g. SEARCH_PROMPT.
Definition: search_state.h:43
#define SEARCH_NO_FLAGS
No flags are set.
Definition: search_state.h:44
#define SEARCH_PROMPT
Ask for search input.
Definition: search_state.h:45
Sidebar functions.
#define NONULL(x)
Definition: string2.h:37
View of a Mailbox.
Definition: mview.h:40
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:51
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:101
Mapping between an operation and a key sequence.
Definition: lib.h:110
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:111
Definition: lib.h:79
int top
Entry that is the top of the current page.
Definition: lib.h:90
int max
Number of entries in the menu.
Definition: lib.h:81
int page_len
Number of entries per screen.
Definition: lib.h:84
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:40