NeoMutt  2025-12-11-596-g7cc1dd
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
functions.c
Go to the documentation of this file.
1
23
29
30#include "config.h"
31#include <stddef.h>
32#include "mutt/lib.h"
33#include "config/lib.h"
34#include "core/lib.h"
35#include "gui/lib.h"
36#include "mutt.h"
37#include "functions.h"
38#include "key/lib.h"
39#include "menu/lib.h"
40#include "pattern/lib.h"
41
44
45// clang-format off
49static const struct MenuFuncOp OpPostponed[] = { /* map: postpone */
50 { "exit", OP_EXIT },
51 { "delete-entry", OP_DELETE },
52 { "undelete-entry", OP_UNDELETE },
53 { NULL, 0 },
54};
55
59static const struct MenuOpSeq PostponedDefaultBindings[] = { /* map: postpone */
60 { OP_DELETE, "d" },
61 { OP_EXIT, "q" },
62 { OP_UNDELETE, "u" },
63 { 0, NULL },
64};
65// clang-format on
66
70void postponed_init_keys(struct SubMenu *sm_generic)
71{
72 struct MenuDefinition *md = NULL;
73 struct SubMenu *sm = NULL;
74
76 md = km_register_menu(MENU_POSTPONE, "postpone");
77 km_menu_add_submenu(md, sm);
78 km_menu_add_submenu(md, sm_generic);
80
81 MdPostpone = md;
82}
83
87static int op_delete(struct PostponeData *pd, const struct KeyEvent *event)
88{
89 struct Menu *menu = pd->menu;
90 struct MailboxView *mv = pd->mailbox_view;
91 struct Mailbox *m = mv->mailbox;
92
93 const int index = menu_get_index(menu);
94 /* should deleted draft messages be saved in the trash folder? */
95 mutt_set_flag(m, m->emails[index], MUTT_DELETE, (event->op == OP_DELETE), true);
97 const bool c_resolve = cs_subset_bool(NeoMutt->sub, "resolve");
98 if (c_resolve && (index < (menu->max - 1)))
99 {
100 menu_set_index(menu, index + 1);
101 if (index >= (menu->top + menu->page_len))
102 {
103 menu->top = index;
105 }
106 }
107 else
108 {
110 }
111
112 return FR_SUCCESS;
113}
114
118static int op_exit(struct PostponeData *pd, const struct KeyEvent *event)
119{
120 pd->done = true;
121 return FR_SUCCESS;
122}
123
127static int op_generic_select_entry(struct PostponeData *pd, const struct KeyEvent *event)
128{
129 int index = menu_get_index(pd->menu);
130 struct MailboxView *mv = pd->mailbox_view;
131 struct Mailbox *m = mv->mailbox;
132 pd->email = m->emails[index];
133 pd->done = true;
134 return FR_SUCCESS;
135}
136
140static int op_search(struct PostponeData *pd, const struct KeyEvent *event)
141{
143 switch (event->op)
144 {
145 case OP_SEARCH:
146 flags |= SEARCH_PROMPT;
147 pd->search_state->reverse = false;
148 break;
149 case OP_SEARCH_REVERSE:
150 flags |= SEARCH_PROMPT;
151 pd->search_state->reverse = true;
152 break;
153 case OP_SEARCH_NEXT:
154 break;
155 case OP_SEARCH_OPPOSITE:
156 flags |= SEARCH_OPPOSITE;
157 break;
158 }
159
160 int index = menu_get_index(pd->menu);
161 struct MailboxView *mv = pd->mailbox_view;
162 index = mutt_search_command(mv, pd->menu, index, pd->search_state, flags);
163 if (index != -1)
164 menu_set_index(pd->menu, index);
165
166 return FR_SUCCESS;
167}
168
169// -----------------------------------------------------------------------------
170
174static const struct PostponeFunction PostponeFunctions[] = {
175 // clang-format off
176 { OP_DELETE, op_delete },
177 { OP_EXIT, op_exit },
178 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
179 { OP_SEARCH, op_search },
180 { OP_SEARCH_NEXT, op_search },
181 { OP_SEARCH_OPPOSITE, op_search },
182 { OP_SEARCH_REVERSE, op_search },
183 { OP_UNDELETE, op_delete },
184 { 0, NULL },
185 // clang-format on
186};
187
191int postpone_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
192{
193 // The Dispatcher may be called on any Window in the Dialog
194 struct MuttWindow *dlg = dialog_find(win);
195 if (!event || !dlg || !dlg->wdata)
196 return FR_ERROR;
197
198 const int op = event->op;
199 struct Menu *menu = dlg->wdata;
200 struct PostponeData *pd = menu->mdata;
201 if (!pd)
202 return FR_ERROR;
203
204 int rc = FR_UNKNOWN;
205 for (size_t i = 0; PostponeFunctions[i].op != OP_NULL; i++)
206 {
207 const struct PostponeFunction *fn = &PostponeFunctions[i];
208 if (fn->op == op)
209 {
210 rc = fn->function(pd, event);
211 break;
212 }
213 }
214
215 if (rc == FR_UNKNOWN) // Not our function
216 return rc;
217
218 const char *result = dispatcher_get_retval_name(rc);
219 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
220
221 return rc;
222}
223
230{
231 if (!dlg)
232 return NULL;
233
234 struct Menu *menu = dlg->wdata;
235 struct PostponeData *pd = menu->mdata;
236 if (!pd)
237 return NULL;
238
239 return pd->mailbox_view;
240}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
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:40
@ FR_UNKNOWN
Unknown function.
Definition dispatcher.h:34
@ FR_ERROR
Valid function - error occurred.
Definition dispatcher.h:39
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:54
static int op_generic_select_entry(struct AliasMenuData *mdata, const struct KeyEvent *event)
select the current entry - Implements alias_function_t -
Definition functions.c:248
static int op_search(struct AliasMenuData *mdata, const struct KeyEvent *event)
search for a regular expression - Implements alias_function_t -
Definition functions.c:386
static int op_exit(struct AliasMenuData *mdata, const struct KeyEvent *event)
exit this menu - Implements alias_function_t -
Definition functions.c:234
static int op_delete(struct AliasMenuData *mdata, const struct KeyEvent *event)
delete the current entry - Implements alias_function_t -
Definition functions.c:197
int postpone_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Postpone function - Implements function_dispatcher_t -.
Definition functions.c:191
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
Convenience wrapper for the gui headers.
void km_menu_add_submenu(struct MenuDefinition *md, struct SubMenu *sm)
Add a SubMenu to a Menu Definition.
Definition init.c:123
struct SubMenu * km_register_submenu(const struct MenuFuncOp functions[])
Register a submenu.
Definition init.c:91
struct MenuDefinition * km_register_menu(int menu, const char *name)
Register a menu.
Definition init.c:107
void km_menu_add_bindings(struct MenuDefinition *md, const struct MenuOpSeq bindings[])
Add Keybindings to a Menu.
Definition init.c:136
Manage keymappings.
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
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:188
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:164
#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:178
Convenience wrapper for the library headers.
Many unsorted constants and some structs.
short PostCount
Number of postponed (draft) emails.
Definition postpone.c:55
@ MUTT_DELETE
Messages to be deleted.
Definition mutt.h:94
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:478
void postponed_init_keys(struct SubMenu *sm_generic)
Initialise the Postponed Keybindings - Implements ::init_keys_api.
Definition functions.c:70
static const struct MenuFuncOp OpPostponed[]
Functions for the Postpone Menu.
Definition functions.c:49
static const struct MenuOpSeq PostponedDefaultBindings[]
Key bindings for the Postpone Menu.
Definition functions.c:59
struct MenuDefinition * MdPostpone
Postpone Menu Definition.
Definition functions.c:43
struct MailboxView * postponed_get_mailbox_view(struct MuttWindow *dlg)
Extract the Mailbox from the Postponed Dialog.
Definition functions.c:229
static const struct PostponeFunction PostponeFunctions[]
All the NeoMutt functions that the Postpone supports.
Definition functions.c:174
Postponed Email Functions.
#define SEARCH_OPPOSITE
Search in the opposite direction.
uint8_t SearchFlags
Flags for a specific search, e.g. SEARCH_PROMPT.
#define SEARCH_NO_FLAGS
No flags are set.
#define SEARCH_PROMPT
Ask for search input.
#define NONULL(x)
Definition string2.h:44
An event such as a keypress.
Definition get.h:50
int op
Function opcode, e.g. OP_HELP.
Definition get.h:52
View of a Mailbox.
Definition mview.h:40
struct Mailbox * mailbox
Current Mailbox.
Definition mview.h:51
A mailbox.
Definition mailbox.h:78
int msg_count
Total number of messages.
Definition mailbox.h:87
struct Email ** emails
Array of Emails.
Definition mailbox.h:95
int msg_deleted
Number of deleted messages.
Definition mailbox.h:92
Functions for a Dialog or Window.
Definition menu.h:80
Mapping between a function and an operation.
Definition menu.h:38
Mapping between an operation and a key sequence.
Definition menu.h:48
Definition lib.h:80
int top
Entry that is the top of the current page.
Definition lib.h:92
void * mdata
Private data.
Definition lib.h:149
int max
Number of entries in the menu.
Definition lib.h:82
int page_len
Number of entries per screen.
Definition lib.h:85
void * wdata
Private data.
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
Data to pass to the Postpone Functions.
Definition functions.h:37
struct Email * email
Selected Email.
Definition functions.h:40
struct SearchState * search_state
State of the current search.
Definition functions.h:42
bool done
Should we close the Dialog?
Definition functions.h:41
struct MailboxView * mailbox_view
Postponed Mailbox view.
Definition functions.h:38
struct Menu * menu
Postponed Menu.
Definition functions.h:39
A NeoMutt function.
Definition functions.h:64
postpone_function_t function
Function to call.
Definition functions.h:66
int op
Op code, e.g. OP_DELETE.
Definition functions.h:65
bool reverse
search backwards
Collection of related functions.
Definition menu.h:68
@ MENU_POSTPONE
Select a postponed email.
Definition type.h:47