NeoMutt  2024-03-23-142-g2b2e76
Teaching an old dog new tricks
No Matches
Go to the documentation of this file.
69#include "config.h"
70#include <stdbool.h>
71#include <stdio.h>
72#include "mutt/lib.h"
73#include "config/lib.h"
74#include "email/lib.h"
75#include "core/lib.h"
76#include "gui/lib.h"
77#include "expando/lib.h"
78#include "index/lib.h"
79#include "key/lib.h"
80#include "menu/lib.h"
81#include "pattern/lib.h"
82#include "functions.h"
83#include "hdrline.h"
84#include "mutt_logging.h"
85#include "mview.h"
88static const struct Mapping PostponedHelp[] = {
89 // clang-format off
90 { N_("Exit"), OP_EXIT },
91 { N_("Del"), OP_DELETE },
92 { N_("Undel"), OP_UNDELETE },
93 { N_("Help"), OP_HELP },
94 { NULL, 0 },
95 // clang-format on
103static int post_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
105 struct MailboxView *mv = menu->mdata;
106 struct Mailbox *m = mv->mailbox;
108 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
109 if (c_arrow_cursor)
110 {
111 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
112 max_cols -= (mutt_strwidth(c_arrow_string) + 1);
113 }
115 const struct Expando *c_index_format = cs_subset_expando(NeoMutt->sub, "index_format");
116 return mutt_make_string(buf, max_cols, c_index_format, m, -1, m->emails[line],
127 if (nc->event_type != NT_CONFIG)
128 return 0;
129 if (!nc->global_data || !nc->event_data)
130 return -1;
132 struct EventConfig *ev_c = nc->event_data;
134 if (!mutt_str_equal(ev_c->name, "index_format") && !mutt_str_equal(ev_c->name, "sort"))
135 return 0;
137 struct Menu *menu = nc->global_data;
139 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
141 return 0;
153 if (nc->event_type != NT_WINDOW)
154 return 0;
155 if (!nc->global_data || !nc->event_data)
156 return -1;
158 return 0;
160 struct MuttWindow *win_menu = nc->global_data;
161 struct EventWindow *ev_w = nc->event_data;
162 if (ev_w->win != win_menu)
163 return 0;
165 struct Menu *menu = win_menu->wdata;
170 mutt_debug(LL_DEBUG5, "window delete done\n");
171 return 0;
177static const struct AttrColor *post_color(struct Menu *menu, int line)
179 struct MailboxView *mv = menu->mdata;
180 if (!mv || (line < 0))
181 return NULL;
183 struct Mailbox *m = mv->mailbox;
184 if (!m)
185 return NULL;
187 struct Email *e = mutt_get_virt_email(m, line);
188 if (!e)
189 return NULL;
191 if (e->attr_color)
192 return e->attr_color;
195 return e->attr_color;
208struct Email *dlg_postponed(struct Mailbox *m)
211 // Required to number the emails
212 struct MailboxView *mv = mview_new(m, NeoMutt->notify);
214 struct Menu *menu = dlg->wdata;
216 menu->color = post_color;
217 menu->max = m->msg_count;
218 menu->mdata = mv;
219 menu->mdata_free = NULL; // Menu doesn't own the data
221 struct PostponeData pd = { mv, menu, NULL, false, search_state_new() };
222 dlg->wdata = &pd;
224 // NT_COLOR is handled by the SimpleDialog
228 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
229 sbar_set_title(sbar, _("Postponed Messages"));
231 /* The postponed mailbox is setup to have sorting disabled, but the global
232 * `$sort` variable may indicate something different. Sorting has to be
233 * disabled while the postpone menu is being displayed. */
234 const enum SortType c_sort = cs_subset_sort(NeoMutt->sub, "sort");
237 struct MuttWindow *old_focus = window_set_focus(menu->win);
238 // ---------------------------------------------------------------------------
239 // Event Loop
240 int op = OP_NULL;
241 do
242 {
243 menu_tagging_dispatcher(menu->win, op);
244 window_redraw(NULL);
247 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
248 if (op < 0)
249 continue;
250 if (op == OP_NULL)
251 {
253 continue;
254 }
257 int rc = postpone_function_dispatcher(dlg, op);
259 if (rc == FR_UNKNOWN)
260 rc = menu_function_dispatcher(menu->win, op);
261 if (rc == FR_UNKNOWN)
262 rc = global_function_dispatcher(NULL, op);
263 } while (!pd.done);
264 // ---------------------------------------------------------------------------
266 mview_free(&mv);
267 cs_subset_str_native_set(NeoMutt->sub, "sort", c_sort, NULL);
269 window_set_focus(old_focus);
270 simple_dialog_free(&dlg);
272 return;
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:267
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Definition: config_type.c:358
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition: curs_lib.c:443
Unknown function.
Definition: dispatcher.h:33
void mutt_set_header_color(struct Mailbox *m, struct Email *e)
Select a colour for a message.
Definition: dlg_index.c:1374
static const struct Mapping PostponedHelp[]
Help Bar for the Postponed email selection dialog.
Definition: dlg_postpone.c:88
Structs that make up an email.
Parse Expando string.
int km_dokey(enum MenuType mtype, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:463
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: get.c:293
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:230
int postpone_function_dispatcher(struct MuttWindow *win, int op)
Perform a Postpone function - Implements function_dispatcher_t -.
Definition: functions.c:177
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:172
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:318
struct Email * dlg_postponed(struct Mailbox *m)
Create a Menu to select a postponed message -.
Definition: dlg_postpone.c:208
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static const struct AttrColor * post_color(struct Menu *menu, int line)
Calculate the colour for a line of the postpone index - Implements Menu::color() -.
Definition: dlg_postpone.c:177
static int post_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Format an Email for the Menu - Implements Menu::make_entry() -.
Definition: dlg_postpone.c:103
static int postponed_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: dlg_postpone.c:151
static int postponed_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: dlg_postpone.c:125
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:168
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:132
int mutt_make_string(struct Buffer *buf, size_t max_cols, const struct Expando *exp, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
Create formatted strings using mailbox expandos.
Definition: hdrline.c:1797
String processing routines to generate the mail index.
GUI manage the main index (list of emails)
Manage keymappings.
No flags are set.
Definition: lib.h:51
Log at debug level 5.
Definition: logging2.h:47
Log at debug level 1.
Definition: logging2.h:43
GUI present the user with a selectable list.
Redraw everything.
Definition: lib.h:59
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:184
Convenience wrapper for the library headers.
#define N_(a)
Definition: message.h:32
#define _(a)
Definition: message.h:28
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:230
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:191
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:709
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:634
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:684
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:533
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
Postponed Dialog, dlg_postponed()
Definition: mutt_window.h:89
Window is about to be deleted.
Definition: mutt_window.h:229
struct Email * mutt_get_virt_email(struct Mailbox *m, int vnum)
Get a virtual Email.
Definition: mview.c:418
void mview_free(struct MailboxView **ptr)
Free a MailboxView.
Definition: mview.c:50
struct MailboxView * mview_new(struct Mailbox *m, struct Notify *parent)
Create a new MailboxView.
Definition: mview.c:91
View of a Mailbox.
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
Match patterns to emails.
This is a main index entry.
Definition: render.h:38
Reserve space for arrow_cursor.
Definition: render.h:37
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:227
void search_state_free(struct SearchState **ptr)
Free a SearchState.
Definition: search_state.c:51
struct SearchState * search_state_new(void)
Create a new SearchState.
Definition: search_state.c:39
Sidebar functions.
Methods for sorting.
Definition: sort2.h:34
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:40
A curses colour and its attributes.
Definition: attr.h:66
String manipulation buffer.
Definition: buffer.h:36
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
The envelope/body of an email.
Definition: email.h:39
const struct AttrColor * attr_color
Color-pair to use when displaying in the index.
Definition: email.h:115
A config-change event.
Definition: subset.h:71
const char * name
Name of config item that changed.
Definition: subset.h:73
An Event that happened to a Window.
Definition: mutt_window.h:239
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:240
Parsed Expando trees.
Definition: expando.h:41
View of a Mailbox.
Definition: mview.h:40
struct Menu * menu
Needed for pattern compilation.
Definition: mview.h:47
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
Mapping between user-readable string and a constant.
Definition: mapping.h:33
Definition: lib.h:79
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:86
const struct AttrColor *(* color)(struct Menu *menu, int line)
Definition: lib.h:143
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:161
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition: lib.h:106
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:87
void * mdata
Private data.
Definition: lib.h:147
int max
Number of entries in the menu.
Definition: lib.h:81
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct Notify * notify
Notifications handler.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
Data passed to a notification function.
Definition: observer.h:34
void * event_data
Data from notify_send()
Definition: observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:37
void * global_data
Data from notify_observer_add()
Definition: observer.h:39
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 Menu * menu
Postponed Menu.
Definition: functions.h:36
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition: subset.c:297
Select a postponed email.
Definition: type.h:57