NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
sidebar.c File Reference
#include "config.h"
#include <stdio.h>
#include "private.h"
#include "mutt/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "context.h"
#include "mutt_globals.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 56 of file sidebar.c.

57 {
58  const bool c_sidebar_visible =
59  cs_subset_bool(NeoMutt->sub, "sidebar_visible");
60  if (!c_sidebar_visible)
61  return NULL;
62 
63  struct SidebarWindowData *wdata = sb_wdata_get(win);
64  if (wdata->hil_index < 0)
65  return NULL;
66 
67  struct SbEntry **sbep = ARRAY_GET(&wdata->entries, wdata->hil_index);
68  if (!sbep)
69  return NULL;
70 
71  return (*sbep)->mailbox;
72 }
+ 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 82 of file sidebar.c.

83 {
84  if (!m)
85  return;
86 
87  /* Any new/deleted mailboxes will cause a refresh. As long as
88  * they're valid, our pointers will be updated in prepare_sidebar() */
89 
90  struct SbEntry *entry = mutt_mem_calloc(1, sizeof(struct SbEntry));
91  entry->mailbox = m;
92 
93  if (wdata->top_index < 0)
94  wdata->top_index = ARRAY_SIZE(&wdata->entries);
95  if (wdata->bot_index < 0)
96  wdata->bot_index = ARRAY_SIZE(&wdata->entries);
97  if ((wdata->opn_index < 0) && Context &&
99  {
100  wdata->opn_index = ARRAY_SIZE(&wdata->entries);
101  }
102 
103  ARRAY_ADD(&wdata->entries, entry);
104 }
+ 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 111 of file sidebar.c.

112 {
113  struct SbEntry **sbep = NULL;
114  ARRAY_FOREACH(sbep, &wdata->entries)
115  {
116  if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
117  {
118  struct SbEntry *sbe_remove = *sbep;
119  ARRAY_REMOVE(&wdata->entries, sbep);
120  FREE(&sbe_remove);
121 
122  if (wdata->opn_index == ARRAY_FOREACH_IDX)
123  {
124  // Open item was deleted
125  wdata->opn_index = -1;
126  }
127  else if ((wdata->opn_index > 0) && (wdata->opn_index > ARRAY_FOREACH_IDX))
128  {
129  // Open item is still visible, so adjust the index
130  wdata->opn_index--;
131  }
132 
133  if (wdata->hil_index == ARRAY_FOREACH_IDX)
134  {
135  // If possible, keep the highlight where it is
136  struct SbEntry **sbep_cur = ARRAY_GET(&wdata->entries, ARRAY_FOREACH_IDX);
137  if (!sbep_cur)
138  {
139  // The last entry was deleted, so backtrack
140  select_prev(wdata);
141  }
142  else if ((*sbep)->is_hidden)
143  {
144  // Find the next unhidden entry, or the previous
145  if (!select_next(wdata))
146  if (!select_prev(wdata))
147  wdata->hil_index = -1;
148  }
149  }
150  else if ((wdata->hil_index > 0) && (wdata->hil_index > ARRAY_FOREACH_IDX))
151  {
152  // Highlighted item is still visible, so adjust the index
153  wdata->hil_index--;
154  }
155  break;
156  }
157  }
158 }
+ 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 165 of file sidebar.c.

166 {
167  wdata->opn_index = -1;
168 
169  struct SbEntry **sbep = NULL;
170  ARRAY_FOREACH(sbep, &wdata->entries)
171  {
172  if (m)
173  {
174  if (mutt_str_equal((*sbep)->mailbox->realpath, m->realpath))
175  {
176  wdata->opn_index = ARRAY_FOREACH_IDX;
177  wdata->hil_index = ARRAY_FOREACH_IDX;
178  break;
179  }
180  }
181  (*sbep)->is_hidden = ((*sbep)->mailbox->flags & MB_HIDDEN);
182  }
183 }
+ 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 188 of file sidebar.c.

189 {
191 
192  // Listen for dialog creation events
194 }
+ 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 199 of file sidebar.c.

+ 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 42 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 },
}

Definition at line 44 of file sidebar.c.

sb_parse_whitelist
enum CommandResult sb_parse_whitelist(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'sidebar_whitelist' command - Implements Command::parse()
Definition: commands.c:42
mutt_mem_calloc
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
ARRAY_ADD
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:152
cs_subset_bool
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:69
sb_wdata_get
struct SidebarWindowData * sb_wdata_get(struct MuttWindow *win)
Get the Sidebar data for this window.
Definition: wdata.c:70
AllDialogsWindow
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: mutt_window.c:46
Context
The "current" mailbox.
Definition: context.h:38
FREE
#define FREE(x)
Definition: memory.h:40
select_next
bool select_next(struct SidebarWindowData *wdata)
Selects the next unhidden mailbox.
Definition: functions.c:44
SidebarWindowData
Sidebar private Window data -.
Definition: private.h:61
ARRAY_SIZE
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83
SidebarWhitelist
struct ListHead SidebarWhitelist
List of mailboxes to always display in the sidebar.
Definition: sidebar.c:42
ARRAY_GET
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
select_prev
bool select_prev(struct SidebarWindowData *wdata)
Selects the previous unhidden mailbox.
Definition: functions.c:112
NT_WINDOW
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:43
mutt_str_equal
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
SidebarWindowData::top_index
int top_index
First mailbox visible in sidebar.
Definition: private.h:65
MB_HIDDEN
#define MB_HIDDEN
Definition: mailbox.h:38
sb_commands
static const struct Command sb_commands[]
Definition: sidebar.c:44
ARRAY_REMOVE
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition: array.h:261
MuttWindow::notify
struct Notify * notify
Notifications system.
Definition: mutt_window.h:131
ARRAY_FOREACH
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
notify_observer_remove
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:207
Context::mailbox
struct Mailbox * mailbox
Definition: context.h:50
notify_observer_add
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:169
Mailbox::realpath
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
SidebarWindowData::opn_index
int opn_index
Current (open) mailbox.
Definition: private.h:66
sb_parse_unwhitelist
enum CommandResult sb_parse_unwhitelist(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unsidebar_whitelist' command - Implements Command::parse()
Definition: commands.c:61
NeoMutt
Container for Accounts, Notifications.
Definition: neomutt.h:36
SidebarWindowData::hil_index
int hil_index
Highlighted mailbox.
Definition: private.h:67
SbEntry::mailbox
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:43
SbEntry
Info about folders in the sidebar.
Definition: private.h:38
NeoMutt::sub
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
SidebarWindowData::bot_index
int bot_index
Last mailbox visible in sidebar.
Definition: private.h:68
sb_insertion_observer
int sb_insertion_observer(struct NotifyCallback *nc)
Listen for new Dialogs - Implements observer_t.
Definition: observer.c:442
mutt_list_free
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
COMMANDS_REGISTER
#define COMMANDS_REGISTER(cmds)
Definition: mutt_commands.h:77
MuttWindow::wdata
void * wdata
Private data.
Definition: mutt_window.h:138