NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
dialog.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <stddef.h>
31 #include <stdbool.h>
32 #include "mutt/lib.h"
33 #include "config/lib.h"
34 #include "core/lib.h"
35 #include "debug/lib.h"
36 #include "lib.h"
37 #include "mutt_menu.h"
38 
46 struct MuttWindow *dialog_find(struct MuttWindow *win)
47 {
48  for (; win && win->parent; win = win->parent)
49  {
50  if (win->parent->type == WT_ALL_DIALOGS)
51  return win;
52  }
53 
54  return NULL;
55 }
56 
66 void dialog_push(struct MuttWindow *dlg)
67 {
68  if (!dlg || !AllDialogsWindow)
69  return;
70 
71  struct MuttWindow *last = TAILQ_LAST(&AllDialogsWindow->children, MuttWindowList);
72  if (last)
73  last->state.visible = false;
74 
77 
78  // Notify the world, allowing plugins to integrate
79  struct EventWindow ev_w = { dlg, WN_VISIBLE };
81 
82  dlg->state.visible = true;
83  dlg->parent = AllDialogsWindow;
85  window_set_focus(dlg);
86 
87 #ifdef USE_DEBUG_WINDOW
89 #endif
90 }
91 
98 void dialog_pop(void)
99 {
100  if (!AllDialogsWindow)
101  return;
102 
103  struct MuttWindow *last = TAILQ_LAST(&AllDialogsWindow->children, MuttWindowList);
104  if (!last)
105  return;
106 
107  // Notify the world, allowing plugins to clean up
108  struct EventWindow ev_w = { last, WN_HIDDEN };
110 
111  last->state.visible = false;
112  last->parent = NULL;
113  TAILQ_REMOVE(&AllDialogsWindow->children, last, entries);
114 
115  last = TAILQ_LAST(&AllDialogsWindow->children, MuttWindowList);
116  if (last)
117  {
118  last->state.visible = true;
120  }
121  window_set_focus(last);
123 #ifdef USE_DEBUG_WINDOW
124  debug_win_dump();
125 #endif
126 }
127 
132 {
133  if (!nc->event_data || !nc->global_data)
134  return -1;
135  if (nc->event_type != NT_CONFIG)
136  return 0;
137 
138  struct EventConfig *ec = nc->event_data;
139  struct MuttWindow *dlg = nc->global_data;
140 
141  if (!mutt_str_equal(ec->name, "status_on_top"))
142  return 0;
143 
144  struct MuttWindow *win_first = TAILQ_FIRST(&dlg->children);
145 
146  const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
147  if ((c_status_on_top && (win_first->type == WT_INDEX)) ||
148  (!c_status_on_top && (win_first->type != WT_INDEX)))
149  {
150  // Swap the Index and the IndexBar Windows
151  TAILQ_REMOVE(&dlg->children, win_first, entries);
152  TAILQ_INSERT_TAIL(&dlg->children, win_first, entries);
153  }
154 
155  mutt_window_reflow(dlg);
156  return 0;
157 }
158 
166 {
167  if (!menu)
168  return NULL;
169 
170  struct MuttWindow *dlg =
173 
174  struct MuttWindow *index =
177  dlg->focus = index;
178 
179  struct MuttWindow *ibar =
182 
183  const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
184  if (c_status_on_top)
185  {
186  mutt_window_add_child(dlg, ibar);
187  mutt_window_add_child(dlg, index);
188  }
189  else
190  {
191  mutt_window_add_child(dlg, index);
192  mutt_window_add_child(dlg, ibar);
193  }
194 
195  menu->pagelen = index->state.rows;
196  menu->win_index = index;
197  menu->win_ibar = ibar;
198 
200  dialog_push(dlg);
201 
202  return dlg;
203 }
204 
210 {
211  if (!ptr || !*ptr)
212  return;
213 
214  struct MuttWindow *dlg = *ptr;
215 
216  dialog_pop();
218  mutt_window_free(ptr);
219 }
dialog_pop
void dialog_pop(void)
Hide a Window from the user.
Definition: dialog.c:98
dialog_create_simple_index
struct MuttWindow * dialog_create_simple_index(struct Menu *menu, enum WindowType type)
Create a simple index Dialog.
Definition: dialog.c:165
NotifyCallback
Data passed to a notification function.
Definition: observer.h:39
NT_CONFIG
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:37
window_set_focus
void window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:763
WindowType
WindowType
Type of Window.
Definition: mutt_window.h:66
dialog_push
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: dialog.c:66
dialog_find
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition: dialog.c:46
NeoMutt::notify
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
MuttWindow
A division of the screen.
Definition: mutt_window.h:115
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
AllDialogsWindow
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: mutt_window.c:46
WindowState::visible
bool visible
Window is visible.
Definition: mutt_window.h:56
TAILQ_INSERT_TAIL
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:802
NT_WINDOW_DIALOG
@ NT_WINDOW_DIALOG
A new Dialog Window has been created, e.g. WT_DLG_INDEX.
Definition: mutt_window.h:184
lib.h
WN_HIDDEN
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:172
MUTT_WIN_SIZE_MAXIMISE
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:45
Menu::win_ibar
struct MuttWindow * win_ibar
Definition: mutt_menu.h:64
notify_send
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:152
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
lib.h
TAILQ_REMOVE
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
TAILQ_FIRST
#define TAILQ_FIRST(head)
Definition: queue.h:716
MuttWindow::focus
struct MuttWindow * focus
Focussed Window.
Definition: mutt_window.h:133
MuttWindow::notify
struct Notify * notify
Notifications system.
Definition: mutt_window.h:131
debug_win_dump
void debug_win_dump(void)
Definition: window.c:88
MUTT_WIN_ORIENT_VERTICAL
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:35
lib.h
mutt_menu_set_current_redraw
void mutt_menu_set_current_redraw(MuttRedrawFlags redraw)
Set redraw flags on the current menu.
Definition: menu.c:1062
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
mutt_menu.h
REDRAW_FULL
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
lib.h
mutt_window_new
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:166
NotifyCallback::global_data
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Menu::pagelen
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
WN_VISIBLE
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:171
MUTT_WIN_SIZE_UNLIMITED
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:49
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
WindowState::rows
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:58
MuttWindow::parent
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:128
EventConfig
A config-change event.
Definition: subset.h:70
NotifyCallback::event_data
void * event_data
Data from notify_send()
Definition: observer.h:44
MuttWindow::state
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
WT_INDEX
@ WT_INDEX
An Index Window containing a selection list.
Definition: mutt_window.h:94
WT_ALL_DIALOGS
@ WT_ALL_DIALOGS
Container for All Dialogs (nested Windows)
Definition: mutt_window.h:71
WT_INDEX_BAR
@ WT_INDEX_BAR
Index Bar containing status info about the Index.
Definition: mutt_window.h:95
EventConfig::name
const char * name
Name of config item that changed.
Definition: subset.h:73
NeoMutt
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow::type
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:137
MUTT_WIN_SIZE_FIXED
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:44
NeoMutt::sub
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
notify_set_parent
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
dialog_destroy_simple_index
void dialog_destroy_simple_index(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: dialog.c:209
NotifyCallback::event_type
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
mutt_window_add_child
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:565
MuttWindow::children
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:129
dialog_config_observer
static int dialog_config_observer(struct NotifyCallback *nc)
Listen for config changes affecting a Dialog - Implements observer_t.
Definition: dialog.c:131
Menu::win_index
struct MuttWindow * win_index
Definition: mutt_menu.h:63
Menu
GUI selectable list of items.
Definition: mutt_menu.h:52
EventWindow
An Event that happened to a Window.
Definition: mutt_window.h:191
mutt_window_free
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:186
mutt_window_reflow
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:433
TAILQ_LAST
#define TAILQ_LAST(head, headname)
Definition: queue.h:812