NeoMutt  2024-12-12-19-ge4b57e
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 (void)
 Set up the Sidebar.
 
void sb_cleanup (void)
 Clean up the Sidebar.
 

Variables

struct ListHead SidebarPinned = STAILQ_HEAD_INITIALIZER(SidebarPinned)
 List of mailboxes to always display in the sidebar.
 
static 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 64 of file sidebar.c.

65{
66 const bool c_sidebar_visible = cs_subset_bool(NeoMutt->sub, "sidebar_visible");
67 if (!c_sidebar_visible)
68 return NULL;
69
71 if (wdata->hil_index < 0)
72 return NULL;
73
74 struct SbEntry **sbep = ARRAY_GET(&wdata->entries, wdata->hil_index);
75 if (!sbep)
76 return NULL;
77
78 return (*sbep)->mailbox;
79}
#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.
Definition: mutt_window.h:145
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
Info about folders in the sidebar.
Definition: private.h:41
Sidebar private Window data -.
Definition: private.h:88
int hil_index
Highlighted mailbox.
Definition: private.h:95
struct MuttWindow * win
Sidebar Window.
Definition: private.h:89
struct SbEntryArray entries
Items to display in the sidebar.
Definition: private.h:91
+ 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 89 of file sidebar.c.

90{
91 if (!m)
92 return;
93
94 struct SbEntry **sbep = NULL;
95 ARRAY_FOREACH(sbep, &wdata->entries)
96 {
97 if ((*sbep)->mailbox == m)
98 return;
99 }
100
101 /* Any new/deleted mailboxes will cause a refresh. As long as
102 * they're valid, our pointers will be updated in prepare_sidebar() */
103
104 struct IndexSharedData *shared = wdata->shared;
105 struct SbEntry *entry = MUTT_MEM_CALLOC(1, struct SbEntry);
106 entry->mailbox = m;
107
108 if (wdata->top_index < 0)
109 wdata->top_index = ARRAY_SIZE(&wdata->entries);
110 if (wdata->bot_index < 0)
111 wdata->bot_index = ARRAY_SIZE(&wdata->entries);
112 if ((wdata->opn_index < 0) && shared->mailbox &&
114 {
115 wdata->opn_index = ARRAY_SIZE(&wdata->entries);
116 }
117
118 ARRAY_ADD(&wdata->entries, entry);
119}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
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:81
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:45
int top_index
First mailbox visible in sidebar.
Definition: private.h:93
int bot_index
Last mailbox visible in sidebar.
Definition: private.h:96
struct IndexSharedData * shared
Shared Index Data.
Definition: private.h:90
int opn_index
Current (open) mailbox.
Definition: private.h:94
+ 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 126 of file sidebar.c.

127{
128 struct SbEntry **sbep = NULL;
129 ARRAY_FOREACH(sbep, &wdata->entries)
130 {
131 if ((*sbep)->mailbox != m)
132 continue;
133
134 struct SbEntry *sbe_remove = *sbep;
135 ARRAY_REMOVE(&wdata->entries, sbep);
136 FREE(&sbe_remove);
137
138 if (wdata->opn_index == ARRAY_FOREACH_IDX)
139 {
140 // Open item was deleted
141 wdata->opn_index = -1;
142 }
143 else if ((wdata->opn_index > 0) && (wdata->opn_index > ARRAY_FOREACH_IDX))
144 {
145 // Open item is still visible, so adjust the index
146 wdata->opn_index--;
147 }
148
149 if (wdata->hil_index == ARRAY_FOREACH_IDX)
150 {
151 // If possible, keep the highlight where it is
152 struct SbEntry **sbep_cur = ARRAY_GET(&wdata->entries, ARRAY_FOREACH_IDX);
153 if (!sbep_cur)
154 {
155 // The last entry was deleted, so backtrack
156 sb_prev(wdata);
157 }
158 else if ((*sbep)->is_hidden)
159 {
160 // Find the next unhidden entry, or the previous
161 if (!sb_next(wdata) && !sb_prev(wdata))
162 wdata->hil_index = -1;
163 }
164 }
165 else if ((wdata->hil_index > 0) && (wdata->hil_index > ARRAY_FOREACH_IDX))
166 {
167 // Highlighted item is still visible, so adjust the index
168 wdata->hil_index--;
169 }
170 break;
171 }
172}
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition: array.h:267
#define FREE(x)
Definition: memory.h:55
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
+ 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 179 of file sidebar.c.

180{
181 wdata->opn_index = -1;
182
183 struct SbEntry **sbep = NULL;
184 ARRAY_FOREACH(sbep, &wdata->entries)
185 {
186 if (m && m->visible)
187 {
188 if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
189 {
190 wdata->opn_index = ARRAY_FOREACH_IDX;
191 wdata->hil_index = ARRAY_FOREACH_IDX;
192 break;
193 }
194 }
195 (*sbep)->is_hidden = !(*sbep)->mailbox->visible;
196 }
197}
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:130
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_init()

void sb_init ( void  )

Set up the Sidebar.

Definition at line 202 of file sidebar.c.

203{
205
206 // Set a default style
208 ac->attrs = A_UNDERLINE;
209
210 // Listen for dialog creation events
213}
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:64
void commands_register(const struct Command *cmds, const size_t num_cmds)
Add commands to Commands array.
Definition: command.c:53
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: dialog.c:80
int sb_insertion_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: observer.c:473
#define mutt_array_size(x)
Definition: memory.h:38
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:57
static const struct Command SbCommands[]
Sidebar Commands.
Definition: sidebar.c:49
A curses colour and its attributes.
Definition: attr.h:66
int attrs
Text attributes, e.g. A_BOLD.
Definition: attr.h:69
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_cleanup()

void sb_cleanup ( void  )

Clean up the Sidebar.

Definition at line 218 of file sidebar.c.

219{
223}
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
struct ListHead SidebarPinned
List of mailboxes to always display in the sidebar.
Definition: sidebar.c:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ SidebarPinned

struct ListHead SidebarPinned = STAILQ_HEAD_INITIALIZER(SidebarPinned)

List of mailboxes to always display in the sidebar.

Definition at line 44 of file sidebar.c.

◆ SbCommands

const struct Command SbCommands[]
static
Initial value:
= {
{ "sidebar_pin", sb_parse_sidebar_pin, 0 },
{ "sidebar_unpin", sb_parse_sidebar_unpin, 0 },
{ "sidebar_whitelist", sb_parse_sidebar_pin, 0 },
{ "unsidebar_whitelist", sb_parse_sidebar_unpin, 0 },
}
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

Sidebar Commands.

Definition at line 49 of file sidebar.c.