NeoMutt  2025-12-11-980-ge38c27
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
sidebar.c File Reference

GUI display the mailboxes in a side panel. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "color/lib.h"
#include "index/lib.h"
+ Include dependency graph for sidebar.c:

Go to the source code of this file.

Functions

struct Mailboxsb_get_highlight (struct MuttWindow *win)
 Get the Mailbox that's highlighted in the sidebar.
 
void sb_add_mailbox (struct SidebarWindowData *wdata, struct Mailbox *m)
 Add a Mailbox to the Sidebar.
 
void sb_remove_mailbox (struct SidebarWindowData *wdata, const struct Mailbox *m)
 Remove a Mailbox from the Sidebar.
 
void sb_set_current_mailbox (struct SidebarWindowData *wdata, struct Mailbox *m)
 Set the current Mailbox.
 
void sb_init (struct MuttWindow *all_dialogs_window)
 Set up the Sidebar.
 
void sb_cleanup (struct ListHead *sidebar_pinned, struct MuttWindow *all_dialogs_window)
 Clean up the Sidebar.
 

Variables

const struct Command SbCommands []
 Sidebar Commands.
 

Detailed Description

GUI display the mailboxes in a side panel.

Authors
  • Kevin J. McCarthy
  • Richard Russon
  • Pietro Cerutti
  • Whitney Cumber

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file sidebar.c.

Function Documentation

◆ sb_get_highlight()

struct Mailbox * sb_get_highlight ( struct MuttWindow * win)

Get the Mailbox that's highlighted in the sidebar.

Parameters
winSidebar Window
Return values
ptrMailbox

Definition at line 73 of file sidebar.c.

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 || (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}
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
struct SidebarWindowData * sb_wdata_get(struct MuttWindow *win)
Get the Sidebar data for this window.
Definition wdata.c:77
void * wdata
Private data.
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
Info about folders in the sidebar.
Definition private.h:40
Sidebar private Window data -.
Definition private.h:90
int hil_index
Highlighted mailbox.
Definition private.h:97
struct MuttWindow * win
Sidebar Window.
Definition private.h:91
struct SbEntryArray entries
Items to display in the sidebar.
Definition private.h:93
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_add_mailbox()

void sb_add_mailbox ( struct SidebarWindowData * wdata,
struct Mailbox * m )

Add a Mailbox to the Sidebar.

Parameters
wdataSidebar data
mMailbox to add

The Sidebar will be re-sorted, and the indices updated, when sb_recalc() is called.

Definition at line 98 of file sidebar.c.

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 entry->score = -1;
117
118 if (wdata->top_index < 0)
119 wdata->top_index = ARRAY_SIZE(&wdata->entries);
120 if (wdata->bot_index < 0)
121 wdata->bot_index = ARRAY_SIZE(&wdata->entries);
122 if ((wdata->opn_index < 0) && shared->mailbox &&
124 {
125 wdata->opn_index = ARRAY_SIZE(&wdata->entries);
126 }
127
128 ARRAY_ADD(&wdata->entries, entry);
129}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:666
Data shared between Index, Pager and Sidebar.
Definition shared_data.h:37
struct Mailbox * mailbox
Current Mailbox.
Definition shared_data.h:41
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition mailbox.h:83
int score
Fuzzy-match score.
Definition private.h:47
struct Mailbox * mailbox
Mailbox this represents.
Definition private.h:44
int top_index
First mailbox visible in sidebar.
Definition private.h:95
int bot_index
Last mailbox visible in sidebar.
Definition private.h:98
struct IndexSharedData * shared
Shared Index Data.
Definition private.h:92
int opn_index
Current (open) mailbox.
Definition private.h:96
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_remove_mailbox()

void sb_remove_mailbox ( struct SidebarWindowData * wdata,
const struct Mailbox * m )

Remove a Mailbox from the Sidebar.

Parameters
wdataSidebar data
mMailbox to remove

Definition at line 136 of file sidebar.c.

137{
138 struct SbEntry **sbep = NULL;
139 ARRAY_FOREACH(sbep, &wdata->entries)
140 {
141 if ((*sbep)->mailbox != m)
142 continue;
143
144 struct SbEntry *sbe_remove = *sbep;
145 ARRAY_REMOVE(&wdata->entries, sbep);
146 FREE(&sbe_remove);
147
148 if (wdata->opn_index == ARRAY_FOREACH_IDX_sbep)
149 {
150 // Open item was deleted
151 wdata->opn_index = -1;
152 }
153 else if ((wdata->opn_index > 0) && (wdata->opn_index > ARRAY_FOREACH_IDX_sbep))
154 {
155 // Open item is still visible, so adjust the index
156 wdata->opn_index--;
157 }
158
159 if (wdata->hil_index == ARRAY_FOREACH_IDX_sbep)
160 {
161 // If possible, keep the highlight where it is
162 struct SbEntry **sbep_cur = ARRAY_GET(&wdata->entries, ARRAY_FOREACH_IDX_sbep);
163 if (!sbep_cur)
164 {
165 // The last entry was deleted, so backtrack
166 sb_prev(wdata);
167 }
168 else if ((*sbep_cur)->is_hidden)
169 {
170 // Find the next unhidden entry, or the previous
171 if (!sb_next(wdata) && !sb_prev(wdata))
172 wdata->hil_index = -1;
173 }
174 }
175 else if ((wdata->hil_index > 0) && (wdata->hil_index > ARRAY_FOREACH_IDX_sbep))
176 {
177 // Highlighted item is still visible, so adjust the index
178 wdata->hil_index--;
179 }
180 break;
181 }
182}
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition array.h:355
bool sb_prev(struct SidebarWindowData *wdata)
Find the previous unhidden Mailbox.
bool sb_next(struct SidebarWindowData *wdata)
Find the next unhidden Mailbox.
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_set_current_mailbox()

void sb_set_current_mailbox ( struct SidebarWindowData * wdata,
struct Mailbox * m )

Set the current Mailbox.

Parameters
wdataSidebar data
mMailbox

Definition at line 189 of file sidebar.c.

190{
191 wdata->opn_index = -1;
192
193 struct SbEntry **sbep = NULL;
194 ARRAY_FOREACH(sbep, &wdata->entries)
195 {
196 if (m && m->visible)
197 {
198 if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
199 {
200 wdata->opn_index = ARRAY_FOREACH_IDX_sbep;
201 wdata->hil_index = ARRAY_FOREACH_IDX_sbep;
202 break;
203 }
204 }
205 (*sbep)->is_hidden = !(*sbep)->mailbox->visible;
206 }
207}
bool visible
True if a result of "mailboxes".
Definition mailbox.h:132
bool is_hidden
Don't show, e.g. $sidebar_new_mail_only.
Definition private.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_init()

void sb_init ( struct MuttWindow * all_dialogs_window)

Set up the Sidebar.

Parameters
all_dialogs_windowAll Dialogs Window

Definition at line 213 of file sidebar.c.

214{
215 // Set a default style, if unset
217 if (!attr_color_is_set(ac))
218 ac->attrs = A_UNDERLINE;
219
220 if (all_dialogs_window)
221 {
222 // Listen for dialog creation events
223 notify_observer_add(all_dialogs_window->notify, NT_WINDOW,
225 }
226}
bool attr_color_is_set(const struct AttrColor *ac)
Is the object coloured?
Definition attr.c:178
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition simple.c:98
@ MT_COLOR_SIDEBAR_HIGHLIGHT
Select cursor.
Definition color.h:71
int sb_insertion_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition observer.c:485
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
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:58
A curses colour and its attributes.
Definition attr.h:65
int attrs
Text attributes, e.g. A_BOLD.
Definition attr.h:68
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_cleanup()

void sb_cleanup ( struct ListHead * sidebar_pinned,
struct MuttWindow * all_dialogs_window )

Clean up the Sidebar.

Parameters
sidebar_pinnedList of pinned sidebar entries
all_dialogs_windowAll Dialogs Window

Definition at line 233 of file sidebar.c.

234{
235 if (all_dialogs_window)
237 mutt_list_free(sidebar_pinned);
238}
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition list.c:123
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ SbCommands

const struct Command SbCommands[]
Initial value:
= {
N_("Pin a mailbox in the sidebar (keep visible)"),
N_("sidebar-pin <mailbox> [ <mailbox> ... ]"),
"optionalfeatures.html#sidebar-pin" },
N_("Unpin a previously pinned mailbox in the sidebar"),
N_("sidebar-unpin { * | <mailbox> ... }"),
"optionalfeatures.html#sidebar-pin" },
{ "sidebar_pin", CMD_NONE, NULL, "sidebar-pin", NULL, NULL, CF_SYNONYM },
{ "sidebar_unpin", CMD_NONE, NULL, "sidebar-unpin", NULL, NULL, CF_SYNONYM },
{ "sidebar_whitelist", CMD_NONE, NULL, "sidebar-pin", NULL, NULL, CF_SYNONYM },
{ "unsidebar_whitelist", CMD_NONE, NULL, "sidebar-unpin", NULL, NULL, CF_SYNONYM },
{ NULL, CMD_NONE, NULL, NULL, NULL, NULL, CF_NONE },
}
@ CF_SYNONYM
Command is a synonym for another command.
Definition command.h:50
@ CF_NONE
No flags are set.
Definition command.h:49
@ CMD_SIDEBAR_PIN
:sidebar-pin
Definition command.h:114
@ CMD_SIDEBAR_UNPIN
:sidebar-unpin
Definition command.h:115
@ CMD_NONE
No Command.
Definition command.h:62
enum CommandResult parse_sidebar_pin(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'sidebar-pin' command - Implements Command::parse() -.
Definition commands.c:45
enum CommandResult parse_sidebar_unpin(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'sidebar-unpin' command - Implements Command::parse() -.
Definition commands.c:76
#define N_(a)
Definition message.h:32

Sidebar Commands.

Definition at line 47 of file sidebar.c.

47 {
48 // clang-format off
49 { "sidebar-pin", CMD_SIDEBAR_PIN, parse_sidebar_pin,
50 N_("Pin a mailbox in the sidebar (keep visible)"),
51 N_("sidebar-pin <mailbox> [ <mailbox> ... ]"),
52 "optionalfeatures.html#sidebar-pin" },
53 { "sidebar-unpin", CMD_SIDEBAR_UNPIN, parse_sidebar_unpin,
54 N_("Unpin a previously pinned mailbox in the sidebar"),
55 N_("sidebar-unpin { * | <mailbox> ... }"),
56 "optionalfeatures.html#sidebar-pin" },
57
58 // Deprecated
59 { "sidebar_pin", CMD_NONE, NULL, "sidebar-pin", NULL, NULL, CF_SYNONYM },
60 { "sidebar_unpin", CMD_NONE, NULL, "sidebar-unpin", NULL, NULL, CF_SYNONYM },
61 { "sidebar_whitelist", CMD_NONE, NULL, "sidebar-pin", NULL, NULL, CF_SYNONYM },
62 { "unsidebar_whitelist", CMD_NONE, NULL, "sidebar-unpin", NULL, NULL, CF_SYNONYM },
63
64 { NULL, CMD_NONE, NULL, NULL, NULL, NULL, CF_NONE },
65 // clang-format on
66};