NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
observer.c File Reference

Sidebar observers. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.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 observer.c:

Go to the source code of this file.

Functions

void sb_win_remove_observers (struct MuttWindow *win)
 Remove Observers from the Sidebar Window. More...
 
static bool calc_divider (struct SidebarWindowData *wdata)
 Decide what actions are required for the divider. More...
 
static struct MuttWindowsb_win_init (struct MuttWindow *dlg)
 Initialise and insert the Sidebar Window. More...
 
static void sb_init_data (struct MuttWindow *win)
 Initialise the Sidebar data. More...
 
static int sb_account_observer (struct NotifyCallback *nc)
 Notification that an Account has changed - Implements observer_t. More...
 
static int sb_color_observer (struct NotifyCallback *nc)
 Notification that a Color has changed - Implements observer_t. More...
 
static int sb_command_observer (struct NotifyCallback *nc)
 Notification that a Command has occurred - Implements observer_t. More...
 
static int sb_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t. More...
 
static int sb_index_observer (struct NotifyCallback *nc)
 Notification that the Index has changed - Implements observer_t. More...
 
static int sb_mailbox_observer (struct NotifyCallback *nc)
 Notification that a Mailbox has changed - Implements observer_t. More...
 
static int sb_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t. More...
 
void sb_win_add_observers (struct MuttWindow *win)
 Add Observers to the Sidebar Window. More...
 
int sb_insertion_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t. More...
 

Detailed Description

Sidebar observers.

Authors
  • Richard Russon

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 observer.c.

Function Documentation

◆ sb_win_remove_observers()

void sb_win_remove_observers ( struct MuttWindow win)

Remove Observers from the Sidebar Window.

Parameters
winSidebar Window

Definition at line 453 of file observer.c.

454 {
455  if (!win || !NeoMutt)
456  return;
457 
465 }
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
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:

◆ calc_divider()

static bool calc_divider ( struct SidebarWindowData wdata)
static

Decide what actions are required for the divider.

Parameters
wdataSidebar data
Return values
trueThe width has changed

If the divider changes width, then Window will need to be reflowed.

Definition at line 50 of file observer.c.

51 {
52  enum DivType type = SB_DIV_USER;
53  const char *const c_sidebar_divider_char =
54  cs_subset_string(NeoMutt->sub, "sidebar_divider_char");
55 
56  // Calculate the width of the delimiter in screen cells
57  int width = mutt_strwidth(c_sidebar_divider_char);
58 
59  const bool c_ascii_chars = cs_subset_bool(NeoMutt->sub, "ascii_chars");
60  if (c_ascii_chars)
61  {
62  if (width < 1) // empty or bad
63  {
64  type = SB_DIV_ASCII;
65  width = 1;
66  }
67  else
68  {
69  for (size_t i = 0; i < width; i++)
70  {
71  if (c_sidebar_divider_char[i] & ~0x7F) // high-bit is set
72  {
73  type = SB_DIV_ASCII;
74  width = 1;
75  break;
76  }
77  }
78  }
79  }
80  else
81  {
82  if (width < 1) // empty or bad
83  {
84  type = SB_DIV_UTF8;
85  width = 1;
86  }
87  }
88 
89  const bool changed = (width != wdata->divider_width);
90 
91  wdata->divider_type = type;
92  wdata->divider_width = width;
93 
94  return changed;
95 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
enum DivType divider_type
Type of divider to use, e.g. SB_DIV_ASCII.
Definition: private.h:73
Container for Accounts, Notifications.
Definition: neomutt.h:36
int mutt_strwidth(const char *s)
Measure a string&#39;s width in screen cells.
Definition: curs_lib.c:983
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
short divider_width
Width of the divider in screen columns.
Definition: private.h:74
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_win_init()

static struct MuttWindow* sb_win_init ( struct MuttWindow dlg)
static

Initialise and insert the Sidebar Window.

Parameters
dlgIndex Dialog
Return values
ptrSidebar Window

Definition at line 102 of file observer.c.

103 {
105 
106  struct MuttWindow *index_panel = TAILQ_FIRST(&dlg->children);
107  mutt_window_remove_child(dlg, index_panel);
108 
109  struct MuttWindow *pager_panel = TAILQ_FIRST(&dlg->children);
110  mutt_window_remove_child(dlg, pager_panel);
111 
112  struct MuttWindow *cont_right =
115  dlg->focus = cont_right;
116 
117  mutt_window_add_child(cont_right, index_panel);
118  mutt_window_add_child(cont_right, pager_panel);
119  cont_right->focus = index_panel;
120 
121  const short c_sidebar_width = cs_subset_number(NeoMutt->sub, "sidebar_width");
122  struct MuttWindow *win_sidebar =
124  c_sidebar_width, MUTT_WIN_SIZE_UNLIMITED);
125  const bool c_sidebar_visible =
126  cs_subset_bool(NeoMutt->sub, "sidebar_visible");
127  win_sidebar->state.visible = c_sidebar_visible && (c_sidebar_width > 0);
128 
129  struct IndexSharedData *shared = dlg->wdata;
130  win_sidebar->wdata = sb_wdata_new(shared);
131  win_sidebar->wdata_free = sb_wdata_free;
132 
133  calc_divider(win_sidebar->wdata);
134 
135  win_sidebar->recalc = sb_recalc;
136  win_sidebar->repaint = sb_repaint;
137 
138  const bool c_sidebar_on_right =
139  cs_subset_bool(NeoMutt->sub, "sidebar_on_right");
140  if (c_sidebar_on_right)
141  {
142  mutt_window_add_child(dlg, cont_right);
143  mutt_window_add_child(dlg, win_sidebar);
144  }
145  else
146  {
147  mutt_window_add_child(dlg, win_sidebar);
148  mutt_window_add_child(dlg, cont_right);
149  }
150 
151  sb_win_add_observers(win_sidebar);
152 
153  return win_sidebar;
154 }
int sb_repaint(struct MuttWindow *win)
Repaint the Sidebar display - Implements MuttWindow::repaint() -.
Definition: window.c:891
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
struct MuttWindow * mutt_window_remove_child(struct MuttWindow *parent, struct MuttWindow *child)
Remove a child from a Window.
Definition: mutt_window.c:488
enum MuttWindowOrientation orient
Which direction the Window will expand.
Definition: mutt_window.h:130
#define TAILQ_FIRST(head)
Definition: queue.h:723
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:160
Window uses all available vertical space.
Definition: mutt_window.h:38
Invisible shaping container Window.
Definition: mutt_window.h:73
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct MuttWindow * focus
Focussed Window.
Definition: mutt_window.h:140
Window has a fixed size.
Definition: mutt_window.h:47
Side panel containing Accounts or groups of data.
Definition: mutt_window.h:101
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool visible
Window is visible.
Definition: mutt_window.h:59
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
int sb_recalc(struct MuttWindow *win)
Recalculate the Sidebar display - Implements MuttWindow::recalc() -.
Definition: window.c:695
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:468
void sb_wdata_free(struct MuttWindow *win, void **ptr)
Free Sidebar Window data - Implements MuttWindow::wdata_free() -.
Definition: wdata.c:52
Window uses all available horizontal space.
Definition: mutt_window.h:39
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:182
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:171
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:180
Window wants as much space as possible.
Definition: mutt_window.h:48
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_init_data()

static void sb_init_data ( struct MuttWindow win)
static

Initialise the Sidebar data.

Parameters
winSidebar Window

Definition at line 160 of file observer.c.

161 {
162  struct SidebarWindowData *wdata = sb_wdata_get(win);
163  if (!wdata)
164  return;
165 
166  if (!ARRAY_EMPTY(&wdata->entries))
167  return;
168 
169  struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
171  struct MailboxNode *np = NULL;
172  STAILQ_FOREACH(np, &ml, entries)
173  {
174  if (!(np->mailbox->flags & MB_HIDDEN))
175  sb_add_mailbox(wdata, np->mailbox);
176  }
178 }
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:141
Match any Mailbox type.
Definition: mailbox.h:45
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:164
Sidebar private Window data -.
Definition: private.h:62
Container for Accounts, Notifications.
Definition: neomutt.h:36
#define MB_HIDDEN
Definition: mailbox.h:38
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
uint8_t flags
e.g. MB_NORMAL
Definition: mailbox.h:134
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
List of Mailboxes.
Definition: mailbox.h:156
void * wdata
Private data.
Definition: mutt_window.h:145
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:158
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_account_observer()

static int sb_account_observer ( struct NotifyCallback nc)
static

Notification that an Account has changed - Implements observer_t.

Definition at line 183 of file observer.c.

184 {
185  if ((nc->event_type != NT_ACCOUNT) || !nc->global_data || !nc->event_data)
186  return -1;
187 
188  struct MuttWindow *win = nc->global_data;
189  struct SidebarWindowData *wdata = sb_wdata_get(win);
190  struct EventAccount *ev_a = nc->event_data;
191 
192  struct MailboxNode *np = NULL;
193  STAILQ_FOREACH(np, &ev_a->account->mailboxes, entries)
194  {
195  sb_add_mailbox(wdata, np->mailbox);
196  }
197 
198  win->actions |= WA_RECALC;
199  mutt_debug(LL_DEBUG5, "account done, request WA_RECALC\n");
200  return 0;
201 }
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:41
Sidebar private Window data -.
Definition: private.h:62
An Event that happened to an Account.
Definition: account.h:78
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:34
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
List of Mailboxes.
Definition: mailbox.h:156
Log at debug level 5.
Definition: logging.h:44
void * wdata
Private data.
Definition: mutt_window.h:145
struct Account * account
The Account this Event relates to.
Definition: account.h:80
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:158
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_color_observer()

static int sb_color_observer ( struct NotifyCallback nc)
static

Notification that a Color has changed - Implements observer_t.

Definition at line 206 of file observer.c.

207 {
208  if ((nc->event_type != NT_COLOR) || !nc->global_data || !nc->event_data)
209  return -1;
210 
211  struct EventColor *ev_c = nc->event_data;
212  struct MuttWindow *win = nc->global_data;
213 
214  enum ColorId color = ev_c->color;
215 
216  switch (color)
217  {
218  case MT_COLOR_INDICATOR:
219  case MT_COLOR_NORMAL:
228  case MT_COLOR_MAX: // Sent on `uncolor *`
229  win->actions |= WA_REPAINT;
230  mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
231  break;
232 
233  default:
234  break;
235  }
236  return 0;
237 }
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
An Event that happened to a Colour.
Definition: color.h:122
Mailbox with no new or flagged messages.
Definition: color.h:70
Line dividing sidebar from the index/pager.
Definition: color.h:65
Select cursor.
Definition: color.h:67
Mailbox with new mail.
Definition: color.h:69
Current open mailbox.
Definition: color.h:68
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
ColorId
List of all colored objects.
Definition: color.h:39
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Plain text.
Definition: color.h:58
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
Selected item in list.
Definition: color.h:54
enum ColorId color
Definition: color.h:124
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Mailbox with unread mail.
Definition: color.h:72
Log at debug level 5.
Definition: logging.h:44
Mailbox with flagged messages.
Definition: color.h:66
$spool_file (Spool mailbox)
Definition: color.h:71
+ Here is the caller graph for this function:

◆ sb_command_observer()

static int sb_command_observer ( struct NotifyCallback nc)
static

Notification that a Command has occurred - Implements observer_t.

Definition at line 242 of file observer.c.

243 {
244  if ((nc->event_type != NT_COMMAND) || !nc->global_data || !nc->event_data)
245  return -1;
246 
247  struct Command *cmd = nc->event_data;
248 
249  if ((cmd->parse != sb_parse_whitelist) && (cmd->parse != sb_parse_unwhitelist))
250  return 0;
251 
252  struct MuttWindow *win = nc->global_data;
253  win->actions |= WA_RECALC;
254  mutt_debug(LL_DEBUG5, "command done, request WA_RECALC\n");
255  return 0;
256 }
A Command has been executed, Command.
Definition: notify_type.h:40
enum CommandResult(* parse)(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Definition: mutt_commands.h:62
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
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
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
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
Log at debug level 5.
Definition: logging.h:44
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_config_observer()

static int sb_config_observer ( struct NotifyCallback nc)
static

Notification that a Config Variable has changed - Implements observer_t.

Definition at line 261 of file observer.c.

262 {
263  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
264  return -1;
265 
266  struct EventConfig *ev_c = nc->event_data;
267 
268  if (!mutt_strn_equal(ev_c->name, "sidebar_", 8) &&
269  !mutt_str_equal(ev_c->name, "ascii_chars") &&
270  !mutt_str_equal(ev_c->name, "folder") && !mutt_str_equal(ev_c->name, "spool_file"))
271  {
272  return 0;
273  }
274 
275  if (mutt_str_equal(ev_c->name, "sidebar_next_new_wrap"))
276  return 0; // Affects the behaviour, but not the display
277 
278  mutt_debug(LL_DEBUG5, "config: %s\n", ev_c->name);
279 
280  struct MuttWindow *win = nc->global_data;
281 
282  if (mutt_str_equal(ev_c->name, "sidebar_visible"))
283  {
284  const bool c_sidebar_visible =
285  cs_subset_bool(NeoMutt->sub, "sidebar_visible");
286  window_set_visible(win, c_sidebar_visible);
287  window_reflow(win->parent);
288  mutt_debug(LL_DEBUG5, "config done, request WA_REFLOW\n");
289  return 0;
290  }
291 
292  if (mutt_str_equal(ev_c->name, "sidebar_width"))
293  {
294  const short c_sidebar_width =
295  cs_subset_number(NeoMutt->sub, "sidebar_width");
296  win->req_cols = c_sidebar_width;
297  win->parent->actions |= WA_REFLOW;
298  mutt_debug(LL_DEBUG5, "config done, request WA_REFLOW\n");
299  return 0;
300  }
301 
302  if (mutt_str_equal(ev_c->name, "spool_file"))
303  {
304  win->actions |= WA_REPAINT;
305  mutt_debug(LL_DEBUG5, "config done, request WA_REPAINT\n");
306  return 0;
307  }
308 
309  if (mutt_str_equal(ev_c->name, "sidebar_on_right"))
310  {
311  struct MuttWindow *parent = win->parent;
312  struct MuttWindow *first = TAILQ_FIRST(&parent->children);
313  const bool c_sidebar_on_right =
314  cs_subset_bool(NeoMutt->sub, "sidebar_on_right");
315 
316  if ((c_sidebar_on_right && (first == win)) || (!c_sidebar_on_right && (first != win)))
317  {
318  // Swap the Sidebar and the Container of the Index/Pager
319  TAILQ_REMOVE(&parent->children, first, entries);
320  TAILQ_INSERT_TAIL(&parent->children, first, entries);
321  }
322 
323  win->parent->actions |= WA_REFLOW;
324  mutt_debug(LL_DEBUG5, "config done, request WA_REFLOW\n");
325  return 0;
326  }
327 
328  if (mutt_str_equal(ev_c->name, "ascii_chars") ||
329  mutt_str_equal(ev_c->name, "sidebar_divider_char"))
330  {
331  struct SidebarWindowData *wdata = sb_wdata_get(win);
332  if (calc_divider(wdata))
333  {
334  win->parent->actions |= WA_REFLOW;
335  mutt_debug(LL_DEBUG5, "config done, request WA_REFLOW\n");
336  }
337  return 0;
338  }
339 
340  // All the remaining config changes...
341  win->actions |= WA_RECALC;
342  mutt_debug(LL_DEBUG5, "config done, request WA_RECALC\n");
343  return 0;
344 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
A config-change event.
Definition: subset.h:69
Sidebar private Window data -.
Definition: private.h:62
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
Container for Accounts, Notifications.
Definition: neomutt.h:36
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition: reflow.c:222
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
Definition: string.c:593
void window_set_visible(struct MuttWindow *win, bool visible)
Set a Window visible or hidden.
Definition: mutt_window.c:163
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Log at debug level 5.
Definition: logging.h:44
void * wdata
Private data.
Definition: mutt_window.h:145
const char * name
Name of config item that changed.
Definition: subset.h:72
short req_cols
Number of columns required.
Definition: mutt_window.h:124
#define WA_REFLOW
Reflow the Window and its children.
Definition: mutt_window.h:109
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_index_observer()

static int sb_index_observer ( struct NotifyCallback nc)
static

Notification that the Index has changed - Implements observer_t.

Definition at line 349 of file observer.c.

350 {
351  if ((nc->event_type != NT_INDEX) || !nc->global_data)
352  return -1;
353 
354  struct MuttWindow *win_ibar = nc->global_data;
355  if (!win_ibar)
356  return 0;
357 
358  struct IndexSharedData *shared = nc->event_data;
359  if (!shared)
360  return 0;
361 
363  {
364  struct SidebarWindowData *wdata = sb_wdata_get(win_ibar);
365  sb_set_current_mailbox(wdata, shared->mailbox);
366 
367  win_ibar->actions |= WA_RECALC;
368  mutt_debug(LL_DEBUG5, "index done, request WA_RECALC\n");
369  }
370 
371  return 0;
372 }
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
Sidebar private Window data -.
Definition: private.h:62
#define NT_INDEX_MAILBOX
Mailbox has changed.
Definition: lib.h:64
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:47
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
Log at debug level 5.
Definition: logging.h:44
void * wdata
Private data.
Definition: mutt_window.h:145
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_mailbox_observer()

static int sb_mailbox_observer ( struct NotifyCallback nc)
static

Notification that a Mailbox has changed - Implements observer_t.

Definition at line 377 of file observer.c.

378 {
379  if ((nc->event_type != NT_MAILBOX) || !nc->global_data || !nc->event_data)
380  return -1;
381 
382  struct MuttWindow *win = nc->global_data;
383 
384  struct SidebarWindowData *wdata = sb_wdata_get(win);
385  struct EventMailbox *ev_m = nc->event_data;
386 
387  if (nc->event_subtype == NT_MAILBOX_SWITCH)
388  {
389  sb_set_current_mailbox(wdata, ev_m->mailbox);
390  }
391  else if (nc->event_subtype == NT_MAILBOX_ADD)
392  {
393  sb_add_mailbox(wdata, ev_m->mailbox);
394  }
395  else if (nc->event_subtype == NT_MAILBOX_DELETE)
396  {
397  sb_remove_mailbox(wdata, ev_m->mailbox);
398  }
399 
400  win->actions |= WA_RECALC;
401  mutt_debug(LL_DEBUG5, "mailbox done, request WA_RECALC\n");
402  return 0;
403 }
Mailbox is about to be deleted.
Definition: mailbox.h:174
struct Mailbox * mailbox
The Mailbox this Event relates to.
Definition: mailbox.h:192
Sidebar private Window data -.
Definition: private.h:62
An Event that happened to a Mailbox.
Definition: mailbox.h:190
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
Mailbox has been added.
Definition: mailbox.h:173
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Current Mailbox has changed.
Definition: mailbox.h:182
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:48
Log at debug level 5.
Definition: logging.h:44
void * wdata
Private data.
Definition: mutt_window.h:145
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_window_observer()

static int sb_window_observer ( struct NotifyCallback nc)
static

Notification that a Window has changed - Implements observer_t.

Definition at line 408 of file observer.c.

409 {
410  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
411  return -1;
412 
413  struct MuttWindow *win = nc->global_data;
414  struct EventWindow *ev_w = nc->event_data;
415  if (ev_w->win != win)
416  return 0;
417 
418  if (nc->event_subtype == NT_WINDOW_STATE)
419  {
420  win->actions |= WA_RECALC;
421  mutt_debug(LL_DEBUG5, "window state done, request WA_RECALC\n");
422  }
423  else if (nc->event_subtype == NT_WINDOW_DELETE)
424  {
425  mutt_debug(LL_DEBUG5, "window delete done\n");
427  }
428  return 0;
429 }
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
An Event that happened to a Window.
Definition: mutt_window.h:215
Window is about to be deleted.
Definition: mutt_window.h:206
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:207
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Log at debug level 5.
Definition: logging.h:44
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_win_add_observers()

void sb_win_add_observers ( struct MuttWindow win)

Add Observers to the Sidebar Window.

Parameters
winSidebar Window

Definition at line 435 of file observer.c.

436 {
437  if (!win || !NeoMutt)
438  return;
439 
447 }
A Command has been executed, Command.
Definition: notify_type.h:40
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:47
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
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:34
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_insertion_window_observer()

int sb_insertion_window_observer ( struct NotifyCallback nc)

Notification that a Window has changed - Implements observer_t.

Definition at line 470 of file observer.c.

471 {
472  if ((nc->event_type != NT_WINDOW) || !nc->event_data)
473  return -1;
474 
475  if (nc->event_subtype != NT_WINDOW_DIALOG)
476  return 0;
477 
478  struct EventWindow *ev_w = nc->event_data;
479  if (ev_w->win->type != WT_DLG_INDEX)
480  return 0;
481 
482  if (ev_w->flags & WN_VISIBLE)
483  {
484  mutt_debug(LL_DEBUG5, "insertion: visible\n");
485  struct MuttWindow *win_sidebar = sb_win_init(ev_w->win);
486  sb_init_data(win_sidebar);
487  }
488  else if (ev_w->flags & WN_HIDDEN)
489  {
490  mutt_debug(LL_DEBUG5, "insertion: hidden\n");
492  }
493 
494  return 0;
495 }
A new Dialog Window has been created, e.g. WT_DLG_INDEX.
Definition: mutt_window.h:208
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
An Event that happened to a Window.
Definition: mutt_window.h:215
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:193
WindowNotifyFlags flags
Attributes of Window that changed.
Definition: mutt_window.h:218
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:192
Index Dialog, index_pager_init()
Definition: mutt_window.h:86
Log at debug level 5.
Definition: logging.h:44
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
+ Here is the call graph for this function:
+ Here is the caller graph for this function: