NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
dialog.c File Reference
#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "debug/lib.h"
#include "lib.h"
#include "mutt_menu.h"
+ Include dependency graph for dialog.c:

Go to the source code of this file.

Functions

struct MuttWindowdialog_find (struct MuttWindow *win)
 Find the parent Dialog of a Window. More...
 
void dialog_push (struct MuttWindow *dlg)
 Display a Window to the user. More...
 
void dialog_pop (void)
 Hide a Window from the user. More...
 
static int dialog_config_observer (struct NotifyCallback *nc)
 Listen for config changes affecting a Dialog - Implements observer_t. More...
 
struct MuttWindowdialog_create_simple_index (struct Menu *menu, enum WindowType type)
 Create a simple index Dialog. More...
 
void dialog_destroy_simple_index (struct MuttWindow **ptr)
 Destroy a simple index Dialog. More...
 

Detailed Description

Dialog Windows

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

Function Documentation

◆ dialog_find()

struct MuttWindow* dialog_find ( struct MuttWindow win)

Find the parent Dialog of a Window.

Parameters
winWindow
Return values
ptrDialog

Dialog Windows will be owned by a MuttWindow of type WT_ALL_DIALOGS.

Definition at line 46 of file dialog.c.

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 }
+ Here is the caller graph for this function:

◆ dialog_push()

void dialog_push ( struct MuttWindow dlg)

Display a Window to the user.

Parameters
dlgWindow to display

The Dialog Windows are kept in a stack. The topmost is visible to the user, whilst the others are hidden.

When a Window is pushed, the old Window is marked as not visible.

Definition at line 66 of file dialog.c.

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 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dialog_pop()

void dialog_pop ( void  )

Hide a Window from the user.

The topmost (visible) Window is removed from the stack and the next Window is marked as visible.

Definition at line 98 of file dialog.c.

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 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dialog_config_observer()

static int dialog_config_observer ( struct NotifyCallback nc)
static

Listen for config changes affecting a Dialog - Implements observer_t.

Definition at line 131 of file dialog.c.

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 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dialog_create_simple_index()

struct MuttWindow* dialog_create_simple_index ( struct Menu menu,
enum WindowType  type 
)

Create a simple index Dialog.

Parameters
menuMenu to use
typeDialog type, e.g. WT_DLG_ALIAS
Return values
ptrNew Dialog Window

Definition at line 165 of file dialog.c.

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 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dialog_destroy_simple_index()

void dialog_destroy_simple_index ( struct MuttWindow **  ptr)

Destroy a simple index Dialog.

Parameters
ptrDialog Window to destroy

Definition at line 209 of file dialog.c.

210 {
211  if (!ptr || !*ptr)
212  return;
213 
214  struct MuttWindow *dlg = *ptr;
215 
216  dialog_pop();
218  mutt_window_free(ptr);
219 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:
dialog_pop
void dialog_pop(void)
Hide a Window from the user.
Definition: dialog.c:98
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
dialog_push
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: dialog.c:66
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
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
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
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
REDRAW_FULL
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
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
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
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