NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sidebar.c
Go to the documentation of this file.
1
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", sb_parse_sidebar_pin, 0 },
52 { "sidebar_unpin", sb_parse_sidebar_unpin, 0 },
53
54 // Deprecated
55 { "sidebar_whitelist", sb_parse_sidebar_pin, 0 },
56 { "unsidebar_whitelist", sb_parse_sidebar_unpin, 0 },
57 { NULL, NULL, 0 },
58 // clang-format on
59};
60
67{
68 const bool c_sidebar_visible = cs_subset_bool(NeoMutt->sub, "sidebar_visible");
69 if (!c_sidebar_visible)
70 return NULL;
71
73 if (wdata->hil_index < 0)
74 return NULL;
75
76 struct SbEntry **sbep = ARRAY_GET(&wdata->entries, wdata->hil_index);
77 if (!sbep)
78 return NULL;
79
80 return (*sbep)->mailbox;
81}
82
91void sb_add_mailbox(struct SidebarWindowData *wdata, struct Mailbox *m)
92{
93 if (!m)
94 return;
95
96 struct SbEntry **sbep = NULL;
97 ARRAY_FOREACH(sbep, &wdata->entries)
98 {
99 if ((*sbep)->mailbox == m)
100 return;
101 }
102
103 /* Any new/deleted mailboxes will cause a refresh. As long as
104 * they're valid, our pointers will be updated in prepare_sidebar() */
105
106 struct IndexSharedData *shared = wdata->shared;
107 struct SbEntry *entry = MUTT_MEM_CALLOC(1, struct SbEntry);
108 entry->mailbox = m;
109
110 if (wdata->top_index < 0)
111 wdata->top_index = ARRAY_SIZE(&wdata->entries);
112 if (wdata->bot_index < 0)
113 wdata->bot_index = ARRAY_SIZE(&wdata->entries);
114 if ((wdata->opn_index < 0) && shared->mailbox &&
116 {
117 wdata->opn_index = ARRAY_SIZE(&wdata->entries);
118 }
119
120 ARRAY_ADD(&wdata->entries, entry);
121}
122
128void sb_remove_mailbox(struct SidebarWindowData *wdata, const struct Mailbox *m)
129{
130 struct SbEntry **sbep = NULL;
131 ARRAY_FOREACH(sbep, &wdata->entries)
132 {
133 if ((*sbep)->mailbox != m)
134 continue;
135
136 struct SbEntry *sbe_remove = *sbep;
137 ARRAY_REMOVE(&wdata->entries, sbep);
138 FREE(&sbe_remove);
139
140 if (wdata->opn_index == ARRAY_FOREACH_IDX_sbep)
141 {
142 // Open item was deleted
143 wdata->opn_index = -1;
144 }
145 else if ((wdata->opn_index > 0) && (wdata->opn_index > ARRAY_FOREACH_IDX_sbep))
146 {
147 // Open item is still visible, so adjust the index
148 wdata->opn_index--;
149 }
150
151 if (wdata->hil_index == ARRAY_FOREACH_IDX_sbep)
152 {
153 // If possible, keep the highlight where it is
154 struct SbEntry **sbep_cur = ARRAY_GET(&wdata->entries, ARRAY_FOREACH_IDX_sbep);
155 if (!sbep_cur)
156 {
157 // The last entry was deleted, so backtrack
158 sb_prev(wdata);
159 }
160 else if ((*sbep)->is_hidden)
161 {
162 // Find the next unhidden entry, or the previous
163 if (!sb_next(wdata) && !sb_prev(wdata))
164 wdata->hil_index = -1;
165 }
166 }
167 else if ((wdata->hil_index > 0) && (wdata->hil_index > ARRAY_FOREACH_IDX_sbep))
168 {
169 // Highlighted item is still visible, so adjust the index
170 wdata->hil_index--;
171 }
172 break;
173 }
174}
175
182{
183 wdata->opn_index = -1;
184
185 struct SbEntry **sbep = NULL;
186 ARRAY_FOREACH(sbep, &wdata->entries)
187 {
188 if (m && m->visible)
189 {
190 if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
191 {
192 wdata->opn_index = ARRAY_FOREACH_IDX_sbep;
193 wdata->hil_index = ARRAY_FOREACH_IDX_sbep;
194 break;
195 }
196 }
197 (*sbep)->is_hidden = !(*sbep)->mailbox->visible;
198 }
199}
200
204void sb_init(void)
205{
207
208 // Set a default style
210 ac->attrs = A_UNDERLINE;
211
212 // Listen for dialog creation events
215}
216
220void sb_cleanup(void)
221{
225}
#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:73
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 sb_parse_sidebar_pin(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'sidebar_pin' command - Implements Command::parse() -.
Definition: commands.c:41
enum CommandResult sb_parse_sidebar_unpin(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'sidebar_unpin' command - Implements Command::parse() -.
Definition: commands.c:60
int sb_insertion_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: observer.c:473
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:55
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
Convenience wrapper for the library headers.
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:661
@ 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.
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:204
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:128
void sb_cleanup(void)
Clean up the Sidebar.
Definition: sidebar.c:220
void sb_set_current_mailbox(struct SidebarWindowData *wdata, struct Mailbox *m)
Set the current Mailbox.
Definition: sidebar.c:181
struct ListHead SidebarPinned
List of mailboxes to always display in the sidebar.
Definition: sidebar.c:44
void sb_add_mailbox(struct SidebarWindowData *wdata, struct Mailbox *m)
Add a Mailbox to the Sidebar.
Definition: sidebar.c:91
struct Mailbox * sb_get_highlight(struct MuttWindow *win)
Get the Mailbox that's highlighted in the sidebar.
Definition: sidebar.c:66
Key value store.
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.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
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:41
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:45
Sidebar private Window data -.
Definition: private.h:88
int top_index
First mailbox visible in sidebar.
Definition: private.h:93
int bot_index
Last mailbox visible in sidebar.
Definition: private.h:96
int hil_index
Highlighted mailbox.
Definition: private.h:95
struct IndexSharedData * shared
Shared Index Data.
Definition: private.h:90
int opn_index
Current (open) mailbox.
Definition: private.h:94
struct MuttWindow * win
Sidebar Window.
Definition: private.h:89
struct SbEntryArray entries
Items to display in the sidebar.
Definition: private.h:91