NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Sidebar Function API

Prototype for a Sidebar Function. More...

+ Collaboration diagram for Sidebar Function API:

Functions

static int op_sidebar_first (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the first unhidden mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_last (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the last unhidden mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_next (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the next unhidden mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_next_new (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the next new mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_open (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Open highlighted mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_page_down (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the first entry in the next page of mailboxes - Implements sidebar_function_t -.
 
static int op_sidebar_page_up (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the last entry in the previous page of mailboxes - Implements sidebar_function_t -.
 
static int op_sidebar_prev (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the previous unhidden mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_prev_new (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the previous new mailbox - Implements sidebar_function_t -.
 
static int op_sidebar_toggle_visible (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Make the sidebar (in)visible - Implements sidebar_function_t -.
 
static int op_sidebar_toggle_virtual (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Deprecated - Implements sidebar_function_t -.
 
static int op_sidebar_abort_search (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Close the Sidebar Search - Implements sidebar_function_t -.
 
static int op_sidebar_start_search (struct SidebarFunctionData *fdata, const struct KeyEvent *event)
 Selects the last unhidden mailbox - Implements sidebar_function_t -.
 

Detailed Description

Prototype for a Sidebar Function.

Parameters
fdataSidebar Function context data
eventEvent to process
Return values
enumFunctionRetval
Precondition
fdata is not NULL
event is not NULL

Function Documentation

◆ op_sidebar_first()

static int op_sidebar_first ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Selects the first unhidden mailbox - Implements sidebar_function_t -.

Definition at line 237 of file functions.c.

238{
239 struct SidebarWindowData *wdata = fdata->wdata;
240 if (!mutt_window_is_visible(wdata->win))
241 return FR_NO_ACTION;
242
243 if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
244 return FR_NO_ACTION;
245
246 int orig_hil_index = wdata->hil_index;
247
248 wdata->hil_index = 0;
249 if ((*ARRAY_GET(&wdata->entries, wdata->hil_index))->is_hidden)
250 if (!sb_next(wdata))
251 wdata->hil_index = orig_hil_index;
252
253 if (orig_hil_index == wdata->hil_index)
254 return FR_NO_ACTION;
255
256 wdata->win->actions |= WA_RECALC;
257 return FR_SUCCESS;
258}
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
@ FR_NO_ACTION
Valid function - no action performed.
Definition dispatcher.h:38
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
@ WA_RECALC
Recalculate the contents of the Window.
bool sb_next(struct SidebarWindowData *wdata)
Find the next unhidden Mailbox.
Definition functions.c:119
void * wdata
Private data.
struct SidebarWindowData * wdata
Sidebar window data.
Definition functions.h:35
Sidebar private Window data -.
Definition private.h:89
+ Here is the call graph for this function:

◆ op_sidebar_last()

static int op_sidebar_last ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Selects the last unhidden mailbox - Implements sidebar_function_t -.

Definition at line 263 of file functions.c.

264{
265 struct SidebarWindowData *wdata = fdata->wdata;
266 if (!mutt_window_is_visible(wdata->win))
267 return FR_NO_ACTION;
268
269 if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
270 return FR_NO_ACTION;
271
272 int orig_hil_index = wdata->hil_index;
273
274 wdata->hil_index = ARRAY_SIZE(&wdata->entries);
275 if (!sb_prev(wdata))
276 wdata->hil_index = orig_hil_index;
277
278 if (orig_hil_index == wdata->hil_index)
279 return FR_NO_ACTION;
280
281 wdata->win->actions |= WA_RECALC;
282 return FR_SUCCESS;
283}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
bool sb_prev(struct SidebarWindowData *wdata)
Find the previous unhidden Mailbox.
Definition functions.c:194
+ Here is the call graph for this function:

◆ op_sidebar_next()

static int op_sidebar_next ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Selects the next unhidden mailbox - Implements sidebar_function_t -.

Definition at line 288 of file functions.c.

289{
290 struct SidebarWindowData *wdata = fdata->wdata;
291 if (!mutt_window_is_visible(wdata->win))
292 return FR_NO_ACTION;
293
294 if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
295 return FR_NO_ACTION;
296
297 const int count = event->count;
298 if (count > 0)
299 {
300 if (!sb_next_n(wdata, count))
301 return FR_NO_ACTION;
302 }
303 else
304 {
305 if (!sb_next(wdata))
306 {
307 mutt_message(_("You are on the last entry"));
308 return FR_ERROR;
309 }
310 }
311
312 wdata->win->actions |= WA_RECALC;
313 return FR_SUCCESS;
314}
@ FR_ERROR
Valid function - error occurred.
Definition dispatcher.h:39
#define mutt_message(...)
Definition logging2.h:93
#define _(a)
Definition message.h:28
static bool sb_next_n(struct SidebarWindowData *wdata, int count)
Move down N unhidden Mailboxes, capping at the last.
Definition functions.c:141
+ Here is the call graph for this function:

◆ op_sidebar_next_new()

static int op_sidebar_next_new ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Selects the next new mailbox - Implements sidebar_function_t -.

Search down the list of mail folders for one containing new mail.

Definition at line 321 of file functions.c.

322{
323 struct SidebarWindowData *wdata = fdata->wdata;
324 if (!mutt_window_is_visible(wdata->win))
325 return FR_NO_ACTION;
326
327 const size_t max_entries = ARRAY_SIZE(&wdata->entries);
328 if ((max_entries == 0) || (wdata->hil_index < 0))
329 return FR_NO_ACTION;
330
331 const int count = MAX(event->count, 1);
332 const bool c_sidebar_next_new_wrap = cs_subset_bool(fdata->n->sub, "sidebar_next_new_wrap");
333 int orig_hil_index = wdata->hil_index;
334
335 for (int i = 0; i < count; i++)
336 {
337 struct SbEntry **sbep = NULL;
338 if ((sbep = sb_next_new(wdata, wdata->hil_index + 1, max_entries)) ||
339 (c_sidebar_next_new_wrap && (sbep = sb_next_new(wdata, 0, wdata->hil_index))))
340 {
341 wdata->hil_index = ARRAY_IDX(&wdata->entries, sbep);
342 }
343 else
344 {
345 break;
346 }
347 }
348
349 if (wdata->hil_index == orig_hil_index)
350 return FR_NO_ACTION;
351
352 wdata->win->actions |= WA_RECALC;
353 return FR_SUCCESS;
354}
#define ARRAY_IDX(head, elem)
Return the index of an element of the array.
Definition array.h:324
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
#define MAX(a, b)
Return the maximum of two values.
Definition memory.h:38
static struct SbEntry ** sb_next_new(struct SidebarWindowData *wdata, size_t begin, size_t end)
Return the next mailbox with new messages.
Definition functions.c:178
int count
Optional count prefix, e.g. 3 for 3j
Definition get.h:78
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
Info about folders in the sidebar.
Definition private.h:40
struct NeoMutt * n
NeoMutt application data.
Definition functions.h:33
int hil_index
Highlighted mailbox.
Definition private.h:96
struct MuttWindow * win
Sidebar Window.
Definition private.h:90
struct SbEntryArray entries
Items to display in the sidebar.
Definition private.h:92
+ Here is the call graph for this function:

◆ op_sidebar_open()

static int op_sidebar_open ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Open highlighted mailbox - Implements sidebar_function_t -.

Definition at line 359 of file functions.c.

360{
361 struct SidebarWindowData *wdata = fdata->wdata;
362 struct MuttWindow *win_sidebar = wdata->win;
363 if (!mutt_window_is_visible(win_sidebar))
364 return FR_NO_ACTION;
365
366 struct MuttWindow *dlg = dialog_find(win_sidebar);
367 index_change_folder(dlg, sb_get_highlight(win_sidebar));
368 return FR_SUCCESS;
369}
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition dialog.c:89
void index_change_folder(struct MuttWindow *dlg, struct Mailbox *m)
Change the current folder, cautiously.
Definition dlg_index.c:1490
struct Mailbox * sb_get_highlight(struct MuttWindow *win)
Get the Mailbox that's highlighted in the sidebar.
Definition sidebar.c:74
+ Here is the call graph for this function:

◆ op_sidebar_page_down()

static int op_sidebar_page_down ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Selects the first entry in the next page of mailboxes - Implements sidebar_function_t -.

Definition at line 374 of file functions.c.

375{
376 struct SidebarWindowData *wdata = fdata->wdata;
377 if (!mutt_window_is_visible(wdata->win))
378 return FR_NO_ACTION;
379
380 if (ARRAY_EMPTY(&wdata->entries) || (wdata->bot_index < 0))
381 return FR_NO_ACTION;
382
383 int orig_hil_index = wdata->hil_index;
384 const int page_size = wdata->win->state.rows;
385 const int count = MAX(event->count, 1);
386
387 if (!sb_next_n(wdata, count * page_size))
388 return FR_NO_ACTION;
389
390 /* If we landed on a hidden entry, go up to the last unhidden one */
391 if ((*ARRAY_GET(&wdata->entries, wdata->hil_index))->is_hidden)
392 sb_prev(wdata);
393
394 if (orig_hil_index == wdata->hil_index)
395 return FR_NO_ACTION;
396
397 wdata->repage = true;
398 wdata->win->actions |= WA_RECALC;
399 return FR_SUCCESS;
400}
+ Here is the call graph for this function:

◆ op_sidebar_page_up()

static int op_sidebar_page_up ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Selects the last entry in the previous page of mailboxes - Implements sidebar_function_t -.

Definition at line 405 of file functions.c.

406{
407 struct SidebarWindowData *wdata = fdata->wdata;
408 if (!mutt_window_is_visible(wdata->win))
409 return FR_NO_ACTION;
410
411 if (ARRAY_EMPTY(&wdata->entries) || (wdata->top_index < 0))
412 return FR_NO_ACTION;
413
414 int orig_hil_index = wdata->hil_index;
415 const int page_size = wdata->win->state.rows;
416 const int count = MAX(event->count, 1);
417
418 if (!sb_prev_n(wdata, count * page_size))
419 return FR_NO_ACTION;
420
421 /* If we landed on a hidden entry, go down to the last unhidden one */
422 if ((*ARRAY_GET(&wdata->entries, wdata->hil_index))->is_hidden)
423 sb_next(wdata);
424
425 if (orig_hil_index == wdata->hil_index)
426 return FR_NO_ACTION;
427
428 wdata->repage = true;
429 wdata->win->actions |= WA_RECALC;
430 return FR_SUCCESS;
431}
static bool sb_prev_n(struct SidebarWindowData *wdata, int count)
Move up N unhidden Mailboxes, capping at the first.
Definition functions.c:159
+ Here is the call graph for this function:

◆ op_sidebar_prev()

static int op_sidebar_prev ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Selects the previous unhidden mailbox - Implements sidebar_function_t -.

Definition at line 436 of file functions.c.

437{
438 struct SidebarWindowData *wdata = fdata->wdata;
439 if (!mutt_window_is_visible(wdata->win))
440 return FR_NO_ACTION;
441
442 if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
443 return FR_NO_ACTION;
444
445 const int count = event->count;
446 if (count > 0)
447 {
448 if (!sb_prev_n(wdata, count))
449 return FR_NO_ACTION;
450 }
451 else
452 {
453 if (!sb_prev(wdata))
454 {
455 mutt_message(_("You are on the first entry"));
456 return FR_ERROR;
457 }
458 }
459
460 wdata->win->actions |= WA_RECALC;
461 return FR_SUCCESS;
462}
+ Here is the call graph for this function:

◆ op_sidebar_prev_new()

static int op_sidebar_prev_new ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Selects the previous new mailbox - Implements sidebar_function_t -.

Search up the list of mail folders for one containing new mail.

Definition at line 469 of file functions.c.

470{
471 struct SidebarWindowData *wdata = fdata->wdata;
472 if (!mutt_window_is_visible(wdata->win))
473 return FR_NO_ACTION;
474
475 const size_t max_entries = ARRAY_SIZE(&wdata->entries);
476 if ((max_entries == 0) || (wdata->hil_index < 0))
477 return FR_NO_ACTION;
478
479 const int count = MAX(event->count, 1);
480 const bool c_sidebar_next_new_wrap = cs_subset_bool(fdata->n->sub, "sidebar_next_new_wrap");
481 int orig_hil_index = wdata->hil_index;
482
483 for (int i = 0; i < count; i++)
484 {
485 struct SbEntry **sbep = NULL;
486 if ((sbep = sb_prev_new(wdata, 0, wdata->hil_index)) ||
487 (c_sidebar_next_new_wrap &&
488 (sbep = sb_prev_new(wdata, wdata->hil_index + 1, max_entries))))
489 {
490 wdata->hil_index = ARRAY_IDX(&wdata->entries, sbep);
491 }
492 else
493 {
494 break;
495 }
496 }
497
498 if (wdata->hil_index == orig_hil_index)
499 return FR_NO_ACTION;
500
501 wdata->win->actions |= WA_RECALC;
502 return FR_SUCCESS;
503}
static struct SbEntry ** sb_prev_new(struct SidebarWindowData *wdata, size_t begin, size_t end)
Return the previous mailbox with new messages.
Definition functions.c:220
+ Here is the call graph for this function:

◆ op_sidebar_toggle_visible()

static int op_sidebar_toggle_visible ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Make the sidebar (in)visible - Implements sidebar_function_t -.

Definition at line 508 of file functions.c.

510{
511 bool_str_toggle(fdata->n->sub, "sidebar_visible", NULL);
512 mutt_window_reflow(NULL);
513 return FR_SUCCESS;
514}
int bool_str_toggle(struct ConfigSubset *sub, const char *name, struct Buffer *err)
Toggle the value of a bool.
Definition bool.c:231
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
+ Here is the call graph for this function:

◆ op_sidebar_toggle_virtual()

static int op_sidebar_toggle_virtual ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Deprecated - Implements sidebar_function_t -.

Definition at line 519 of file functions.c.

521{
522 return FR_SUCCESS;
523}

◆ op_sidebar_abort_search()

static int op_sidebar_abort_search ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Close the Sidebar Search - Implements sidebar_function_t -.

Close the Sidebar Search without a selection.

Definition at line 597 of file functions.c.

599{
600 struct SidebarWindowData *wdata = fdata->wdata;
601 if (wdata->search_active)
602 return FR_DONE;
603 else
604 return FR_NO_ACTION;
605}
@ FR_DONE
Exit the Dialog.
Definition dispatcher.h:36

◆ op_sidebar_start_search()

static int op_sidebar_start_search ( struct SidebarFunctionData * fdata,
const struct KeyEvent * event )
static

Selects the last unhidden mailbox - Implements sidebar_function_t -.

Definition at line 610 of file functions.c.

612{
613 struct SidebarWindowData *wdata = fdata->wdata;
614 if (ARRAY_EMPTY(&wdata->entries) || (wdata->hil_index < 0))
615 {
616 mutt_warning(_("There are no mailboxes"));
617 return FR_ERROR;
618 }
619
620 const bool was_visible = cs_subset_bool(fdata->n->sub, "sidebar_visible");
621 if (!was_visible)
622 {
623 cs_subset_str_native_set(fdata->n->sub, "sidebar_visible", true, NULL);
624 mutt_window_reflow(NULL);
625 }
626
627 struct Buffer *buf = buf_pool_get();
628 int orghlidx = wdata->hil_index;
629
630 struct SbEntry **sbep = NULL;
631 ARRAY_FOREACH(sbep, &wdata->entries)
632 {
633 struct SbEntry *sbe = *sbep;
634 if (sbe->box[0] == '\0')
636 }
637
638 int rc = FR_NO_ACTION;
639 wdata->search_active = true;
640
641 if (mw_get_field_notify(_("Sidebar search: "), buf, MUTT_COMP_UNBUFFERED,
642 HC_NONE, NULL, NULL, sidebar_matcher_cb, wdata->win,
644 {
645 wdata->hil_index = orghlidx;
646 goto done;
647 }
648
649 if (!buf || buf_is_empty(buf) || (wdata->hil_index == -1))
650 {
651 wdata->hil_index = orghlidx;
652 goto done;
653 }
654
655 ARRAY_FOREACH(sbep, &wdata->entries)
656 {
657 struct SbEntry *sbe = *sbep;
658 sbe->score = -1;
659 }
660 rc = FR_SUCCESS;
661
662done:
663 ARRAY_FOREACH(sbep, &wdata->entries)
664 {
665 (*sbep)->mailbox->visible = true;
666 }
667 wdata->search_active = false;
668 wdata->repage = false;
669 wdata->win->actions |= WA_RECALC;
670
671 if (rc == FR_SUCCESS)
672 {
673 struct MuttWindow *dlg = dialog_find(wdata->win);
675 }
676
677 if (!was_visible)
678 {
679 cs_subset_str_native_set(fdata->n->sub, "sidebar_visible", false, NULL);
680 mutt_window_reflow(NULL);
681 }
682
683 buf_pool_release(&buf);
684 return rc;
685}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
int mw_get_field_notify(const char *prompt, struct Buffer *buf, CompletionFlags complete, enum HistoryClass hclass, const struct CompleteOps *comp_api, void *cdata, get_field_callback_t callback, void *cb_data, const struct MenuDefinition *md, function_dispatcher_t fn_disp)
Ask the user for a string and call a notify function on keypress.
Definition window.c:299
@ MUTT_COMP_UNBUFFERED
Ignore macro buffer.
Definition wdata.h:49
int sb_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Sidebar function - Implements function_dispatcher_t -.
Definition functions.c:714
#define mutt_warning(...)
Definition logging2.h:92
@ HC_NONE
No History.
Definition lib.h:64
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
static void sidebar_matcher_cb(const char *text, void *data)
React to keys as they are entered - Implements get_field_callback_t.
Definition functions.c:528
void sb_entry_set_display_name(struct SbEntry *entry)
Set the display name for an SbEntry.
Definition window.c:306
String manipulation buffer.
Definition buffer.h:36
int score
Fuzzy-match score.
Definition private.h:47
char box[256]
Mailbox path (possibly abbreviated)
Definition private.h:41
struct SidebarModuleData * mod_data
Sidebar module data.
Definition functions.h:34
struct MenuDefinition * md_sidebar
Sidebar Menu Definition.
Definition module_data.h:34
bool search_active
Sidebar Search is running.
Definition private.h:99
bool repage
Force RECALC to recompute the paging used for the overlays.
Definition private.h:98
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:303
+ Here is the call graph for this function: