NeoMutt  2025-12-11-58-g09398d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
sidebar.c
Go to the documentation of this file.
1
25
31
32#include "config.h"
33#include <stdbool.h>
34#include <stdio.h>
35#include "private.h"
36#include "mutt/lib.h"
37#include "config/lib.h"
38#include "core/lib.h"
39#include "gui/lib.h"
40#include "lib.h"
41#include "color/lib.h"
42#include "index/lib.h"
43
45
49static const struct Command SbCommands[] = {
50 // clang-format off
51 { "sidebar_pin", parse_sidebar_pin, 0,
52 N_("Pin a mailbox in the sidebar (keep visible)"),
53 N_("sidebar_pin <mailbox> [ <mailbox> ... ]"),
54 "optionalfeatures.html#sidebar-pin" },
55 { "sidebar_unpin", parse_sidebar_unpin, 0,
56 N_("Unpin a previously pinned mailbox in the sidebar"),
57 N_("sidebar_unpin { * | <mailbox> ... }"),
58 "optionalfeatures.html#sidebar-pin" },
59
60 // Deprecated
61 { "sidebar_whitelist", parse_sidebar_pin, 0, NULL, NULL, NULL, CF_SYNONYM },
62 { "unsidebar_whitelist", parse_sidebar_unpin, 0, NULL, NULL, NULL, CF_SYNONYM },
63
64 { NULL, NULL, 0, NULL, NULL, NULL, CF_NO_FLAGS },
65 // clang-format on
66};
67
74{
75 const bool c_sidebar_visible = cs_subset_bool(NeoMutt->sub, "sidebar_visible");
76 if (!c_sidebar_visible)
77 return NULL;
78
80 if (wdata->hil_index < 0)
81 return NULL;
82
83 struct SbEntry **sbep = ARRAY_GET(&wdata->entries, wdata->hil_index);
84 if (!sbep)
85 return NULL;
86
87 return (*sbep)->mailbox;
88}
89
98void sb_add_mailbox(struct SidebarWindowData *wdata, struct Mailbox *m)
99{
100 if (!m)
101 return;
102
103 struct SbEntry **sbep = NULL;
104 ARRAY_FOREACH(sbep, &wdata->entries)
105 {
106 if ((*sbep)->mailbox == m)
107 return;
108 }
109
110 /* Any new/deleted mailboxes will cause a refresh. As long as
111 * they're valid, our pointers will be updated in prepare_sidebar() */
112
113 struct IndexSharedData *shared = wdata->shared;
114 struct SbEntry *entry = MUTT_MEM_CALLOC(1, struct SbEntry);
115 entry->mailbox = m;
116
117 if (wdata->top_index < 0)
118 wdata->top_index = ARRAY_SIZE(&wdata->entries);
119 if (wdata->bot_index < 0)
120 wdata->bot_index = ARRAY_SIZE(&wdata->entries);
121 if ((wdata->opn_index < 0) && shared->mailbox &&
123 {
124 wdata->opn_index = ARRAY_SIZE(&wdata->entries);
125 }
126
127 ARRAY_ADD(&wdata->entries, entry);
128}
129
135void sb_remove_mailbox(struct SidebarWindowData *wdata, const struct Mailbox *m)
136{
137 struct SbEntry **sbep = NULL;
138 ARRAY_FOREACH(sbep, &wdata->entries)
139 {
140 if ((*sbep)->mailbox != m)
141 continue;
142
143 struct SbEntry *sbe_remove = *sbep;
144 ARRAY_REMOVE(&wdata->entries, sbep);
145 FREE(&sbe_remove);
146
147 if (wdata->opn_index == ARRAY_FOREACH_IDX_sbep)
148 {
149 // Open item was deleted
150 wdata->opn_index = -1;
151 }
152 else if ((wdata->opn_index > 0) && (wdata->opn_index > ARRAY_FOREACH_IDX_sbep))
153 {
154 // Open item is still visible, so adjust the index
155 wdata->opn_index--;
156 }
157
158 if (wdata->hil_index == ARRAY_FOREACH_IDX_sbep)
159 {
160 // If possible, keep the highlight where it is
161 struct SbEntry **sbep_cur = ARRAY_GET(&wdata->entries, ARRAY_FOREACH_IDX_sbep);
162 if (!sbep_cur)
163 {
164 // The last entry was deleted, so backtrack
165 sb_prev(wdata);
166 }
167 else if ((*sbep)->is_hidden)
168 {
169 // Find the next unhidden entry, or the previous
170 if (!sb_next(wdata) && !sb_prev(wdata))
171 wdata->hil_index = -1;
172 }
173 }
174 else if ((wdata->hil_index > 0) && (wdata->hil_index > ARRAY_FOREACH_IDX_sbep))
175 {
176 // Highlighted item is still visible, so adjust the index
177 wdata->hil_index--;
178 }
179 break;
180 }
181}
182
189{
190 wdata->opn_index = -1;
191
192 struct SbEntry **sbep = NULL;
193 ARRAY_FOREACH(sbep, &wdata->entries)
194 {
195 if (m && m->visible)
196 {
197 if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
198 {
199 wdata->opn_index = ARRAY_FOREACH_IDX_sbep;
200 wdata->hil_index = ARRAY_FOREACH_IDX_sbep;
201 break;
202 }
203 }
204 (*sbep)->is_hidden = !(*sbep)->mailbox->visible;
205 }
206}
207
211void sb_init(void)
212{
214
215 // Set a default style
217 ac->attrs = A_UNDERLINE;
218
219 // Listen for dialog creation events
222}
223
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:156
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition array.h:323
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:214
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
Color and attribute parsing.
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition simple.c:95
@ MT_COLOR_SIDEBAR_HIGHLIGHT
Select cursor.
Definition color.h:72
#define CF_SYNONYM
Command is a synonym for another command.
Definition command.h:47
#define CF_NO_FLAGS
No flags are set.
Definition command.h:46
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.
bool commands_register(struct CommandArray *ca, const struct Command *cmds)
Add commands to Commands array.
Definition command.c:51
Convenience wrapper for the core headers.
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition dialog.c:80
enum CommandResult parse_sidebar_unpin(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'sidebar_unpin' command - Implements Command::parse() -.
Definition commands.c:71
enum CommandResult parse_sidebar_pin(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'sidebar_pin' command - Implements Command::parse() -.
Definition commands.c:43
int sb_insertion_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition observer.c:474
Convenience wrapper for the gui headers.
GUI manage the main index (list of emails)
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition list.c:123
#define FREE(x)
Definition memory.h:62
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:47
Convenience wrapper for the library headers.
#define N_(a)
Definition message.h:32
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:660
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:57
#define STAILQ_HEAD_INITIALIZER(head)
Definition queue.h:324
bool sb_prev(struct SidebarWindowData *wdata)
Find the previous unhidden Mailbox.
Definition functions.c:86
bool sb_next(struct SidebarWindowData *wdata)
Find the next unhidden Mailbox.
Definition functions.c:47
GUI display the mailboxes in a side panel.
GUI display the mailboxes in a side panel.
struct ListHead SidebarPinned
List of mailboxes to always display in the sidebar.
Definition sidebar.c:44
struct SidebarWindowData * sb_wdata_get(struct MuttWindow *win)
Get the Sidebar data for this window.
Definition wdata.c:77
void sb_init(void)
Set up the Sidebar.
Definition sidebar.c:211
static const struct Command SbCommands[]
Sidebar Commands.
Definition sidebar.c:49
void sb_remove_mailbox(struct SidebarWindowData *wdata, const struct Mailbox *m)
Remove a Mailbox from the Sidebar.
Definition sidebar.c:135
void sb_cleanup(void)
Clean up the Sidebar.
Definition sidebar.c:227
void sb_set_current_mailbox(struct SidebarWindowData *wdata, struct Mailbox *m)
Set the current Mailbox.
Definition sidebar.c:188
void sb_add_mailbox(struct SidebarWindowData *wdata, struct Mailbox *m)
Add a Mailbox to the Sidebar.
Definition sidebar.c:98
struct Mailbox * sb_get_highlight(struct MuttWindow *win)
Get the Mailbox that's highlighted in the sidebar.
Definition sidebar.c:73
A curses colour and its attributes.
Definition attr.h:66
int attrs
Text attributes, e.g. A_BOLD.
Definition attr.h:69
Data shared between Index, Pager and Sidebar.
Definition shared_data.h:37
struct Mailbox * mailbox
Current Mailbox.
Definition shared_data.h:41
A mailbox.
Definition mailbox.h:79
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition mailbox.h:81
bool visible
True if a result of "mailboxes".
Definition mailbox.h:130
void * wdata
Private data.
Container for Accounts, Notifications.
Definition neomutt.h:43
struct CommandArray commands
NeoMutt commands.
Definition neomutt.h:51
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:47
Info about folders in the sidebar.
Definition private.h:40
struct Mailbox * mailbox
Mailbox this represents.
Definition private.h:44
bool is_hidden
Don't show, e.g. $sidebar_new_mail_only.
Definition private.h:45
Sidebar private Window data -.
Definition private.h:87
int top_index
First mailbox visible in sidebar.
Definition private.h:92
int bot_index
Last mailbox visible in sidebar.
Definition private.h:95
int hil_index
Highlighted mailbox.
Definition private.h:94
struct IndexSharedData * shared
Shared Index Data.
Definition private.h:89
int opn_index
Current (open) mailbox.
Definition private.h:93
struct MuttWindow * win
Sidebar Window.
Definition private.h:88
struct SbEntryArray entries
Items to display in the sidebar.
Definition private.h:90