NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
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 "index/lib.h"
#include "mutt_commands.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. More...
 
void sb_add_mailbox (struct SidebarWindowData *wdata, struct Mailbox *m)
 Add a Mailbox to the Sidebar. More...
 
void sb_remove_mailbox (struct SidebarWindowData *wdata, struct Mailbox *m)
 Remove a Mailbox from the Sidebar. More...
 
void sb_set_current_mailbox (struct SidebarWindowData *wdata, struct Mailbox *m)
 Set the current Mailbox. More...
 
void sb_init (void)
 Set up the Sidebar. More...
 
void sb_shutdown (void)
 Clean up the Sidebar. More...
 

Variables

struct ListHead SidebarWhitelist = STAILQ_HEAD_INITIALIZER(SidebarWhitelist)
 List of mailboxes to always display in the sidebar. More...
 
static const struct Command sb_commands []
 

Detailed Description

GUI display the mailboxes in a side panel.

Authors
  • Justin Hibbits
  • Thomer M. Gil
  • Richard Russon
  • Kevin J. McCarthy

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 58 of file sidebar.c.

59 {
60  const bool c_sidebar_visible =
61  cs_subset_bool(NeoMutt->sub, "sidebar_visible");
62  if (!c_sidebar_visible)
63  return NULL;
64 
65  struct SidebarWindowData *wdata = sb_wdata_get(win);
66  if (wdata->hil_index < 0)
67  return NULL;
68 
69  struct SbEntry **sbep = ARRAY_GET(&wdata->entries, wdata->hil_index);
70  if (!sbep)
71  return NULL;
72 
73  return (*sbep)->mailbox;
74 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
Sidebar private Window data -.
Definition: private.h:62
Info about folders in the sidebar.
Definition: private.h:39
int hil_index
Highlighted mailbox.
Definition: private.h:69
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
void * wdata
Private data.
Definition: mutt_window.h:145
+ 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 84 of file sidebar.c.

85 {
86  if (!m)
87  return;
88 
89  /* Any new/deleted mailboxes will cause a refresh. As long as
90  * they're valid, our pointers will be updated in prepare_sidebar() */
91 
92  struct IndexSharedData *shared = wdata->shared;
93  struct SbEntry *entry = mutt_mem_calloc(1, sizeof(struct SbEntry));
94  entry->mailbox = m;
95 
96  if (wdata->top_index < 0)
97  wdata->top_index = ARRAY_SIZE(&wdata->entries);
98  if (wdata->bot_index < 0)
99  wdata->bot_index = ARRAY_SIZE(&wdata->entries);
100  if ((wdata->opn_index < 0) && shared->mailbox &&
101  mutt_str_equal(m->realpath, shared->mailbox->realpath))
102  {
103  wdata->opn_index = ARRAY_SIZE(&wdata->entries);
104  }
105 
106  ARRAY_ADD(&wdata->entries, entry);
107 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
int opn_index
Current (open) mailbox.
Definition: private.h:68
int top_index
First mailbox visible in sidebar.
Definition: private.h:67
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
Info about folders in the sidebar.
Definition: private.h:39
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:44
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:152
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
int bot_index
Last mailbox visible in sidebar.
Definition: private.h:70
struct IndexSharedData * shared
Definition: private.h:64
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83
+ 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,
struct Mailbox m 
)

Remove a Mailbox from the Sidebar.

Parameters
wdataSidebar data
mMailbox to remove

Definition at line 114 of file sidebar.c.

115 {
116  struct SbEntry **sbep = NULL;
117  ARRAY_FOREACH(sbep, &wdata->entries)
118  {
119  if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
120  {
121  struct SbEntry *sbe_remove = *sbep;
122  ARRAY_REMOVE(&wdata->entries, sbep);
123  FREE(&sbe_remove);
124 
125  if (wdata->opn_index == ARRAY_FOREACH_IDX)
126  {
127  // Open item was deleted
128  wdata->opn_index = -1;
129  }
130  else if ((wdata->opn_index > 0) && (wdata->opn_index > ARRAY_FOREACH_IDX))
131  {
132  // Open item is still visible, so adjust the index
133  wdata->opn_index--;
134  }
135 
136  if (wdata->hil_index == ARRAY_FOREACH_IDX)
137  {
138  // If possible, keep the highlight where it is
139  struct SbEntry **sbep_cur = ARRAY_GET(&wdata->entries, ARRAY_FOREACH_IDX);
140  if (!sbep_cur)
141  {
142  // The last entry was deleted, so backtrack
143  select_prev(wdata);
144  }
145  else if ((*sbep)->is_hidden)
146  {
147  // Find the next unhidden entry, or the previous
148  if (!select_next(wdata))
149  if (!select_prev(wdata))
150  wdata->hil_index = -1;
151  }
152  }
153  else if ((wdata->hil_index > 0) && (wdata->hil_index > ARRAY_FOREACH_IDX))
154  {
155  // Highlighted item is still visible, so adjust the index
156  wdata->hil_index--;
157  }
158  break;
159  }
160  }
161 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
int opn_index
Current (open) mailbox.
Definition: private.h:68
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
Info about folders in the sidebar.
Definition: private.h:39
int hil_index
Highlighted mailbox.
Definition: private.h:69
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition: array.h:261
#define FREE(x)
Definition: memory.h:40
+ 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 168 of file sidebar.c.

169 {
170  wdata->opn_index = -1;
171 
172  struct SbEntry **sbep = NULL;
173  ARRAY_FOREACH(sbep, &wdata->entries)
174  {
175  if (m)
176  {
177  if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
178  {
179  wdata->opn_index = ARRAY_FOREACH_IDX;
180  wdata->hil_index = ARRAY_FOREACH_IDX;
181  break;
182  }
183  }
184  (*sbep)->is_hidden = ((*sbep)->mailbox->flags & MB_HIDDEN);
185  }
186 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
int opn_index
Current (open) mailbox.
Definition: private.h:68
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
Info about folders in the sidebar.
Definition: private.h:39
int hil_index
Highlighted mailbox.
Definition: private.h:69
#define MB_HIDDEN
Definition: mailbox.h:38
+ 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 191 of file sidebar.c.

192 {
194 
195  // Listen for dialog creation events
198 }
#define COMMANDS_REGISTER(cmds)
Definition: mutt_commands.h:82
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
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:189
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: dialog.c:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_shutdown()

void sb_shutdown ( void  )

Clean up the Sidebar.

Definition at line 203 of file sidebar.c.

204 {
205  if (AllDialogsWindow)
208 }
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: dialog.c:76
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ SidebarWhitelist

struct ListHead SidebarWhitelist = STAILQ_HEAD_INITIALIZER(SidebarWhitelist)

List of mailboxes to always display in the sidebar.

Definition at line 44 of file sidebar.c.

◆ sb_commands

const struct Command sb_commands[]
static
Initial value:
= {
{ "sidebar_whitelist", sb_parse_whitelist, 0 },
{ "unsidebar_whitelist", sb_parse_unwhitelist, 0 },
}
enum CommandResult sb_parse_whitelist(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;sidebar_whitelist&#39; command - Implements Command::parse() -.
Definition: commands.c:42
enum CommandResult sb_parse_unwhitelist(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unsidebar_whitelist&#39; command - Implements Command::parse() -.
Definition: commands.c:61

Definition at line 46 of file sidebar.c.