NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
menu.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stdio.h>
32#include "private.h"
33#include "mutt/lib.h"
34#include "gui/lib.h"
35#include "color/lib.h"
36#include "menu/lib.h"
37#include "type.h"
38
39struct ConfigSubset;
40
43
47static struct AttrColor *default_color(struct Menu *menu, int line)
48{
50}
51
55static int generic_search(struct Menu *menu, regex_t *rx, int line)
56{
57 char buf[1024] = { 0 };
58
59 menu->make_entry(menu, buf, sizeof(buf), line);
60 return regexec(rx, buf, 0, NULL, 0);
61}
62
66void menu_cleanup(void)
67{
68 for (int i = 0; i < MENU_MAX; i++)
70}
71
75void menu_init(void)
76{
77 for (int i = 0; i < MENU_MAX; i++)
78 SearchBuffers[i] = NULL;
79}
80
86{
87 struct MuttWindow *win = alldialogs_get_current();
88 while (win && win->focus)
89 win = win->focus;
90
91 // This should only happen before the first window is created
92 if (!win)
93 return MENU_INDEX;
94
95 if ((win->type == WT_CUSTOM) && (win->parent->type == WT_PAGER))
96 return MENU_PAGER;
97
98 if (win->type != WT_MENU)
99 return MENU_GENERIC;
100
101 struct Menu *menu = win->wdata;
102 if (!menu)
103 return MENU_GENERIC;
104
105 return menu->type;
106}
107
112void menu_free(struct Menu **ptr)
113{
114 struct Menu *menu = *ptr;
115
116 notify_free(&menu->notify);
117
118 if (menu->mdata_free && menu->mdata)
119 menu->mdata_free(menu, &menu->mdata); // Custom function to free private data
120
121 FREE(ptr);
122}
123
131struct Menu *menu_new(enum MenuType type, struct MuttWindow *win, struct ConfigSubset *sub)
132{
133 struct Menu *menu = mutt_mem_calloc(1, sizeof(struct Menu));
134
135 menu->type = type;
136 menu->redraw = MENU_REDRAW_FULL;
137 menu->color = default_color;
138 menu->search = generic_search;
139 menu->notify = notify_new();
140 menu->win = win;
141 menu->page_len = win->state.rows;
142 menu->sub = sub;
143
145 menu_add_observers(menu);
146
147 return menu;
148}
149
155int menu_get_index(struct Menu *menu)
156{
157 if (!menu)
158 return -1;
159
160 return menu->current;
161}
162
169MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
170{
171 return menu_move_selection(menu, index);
172}
173
180{
181 if (!menu)
182 return;
183
184 menu->redraw |= redraw;
185 menu->win->actions |= WA_RECALC;
186}
Color and attribute parsing.
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition: simple.c:74
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:57
struct MuttWindow * alldialogs_get_current(void)
Get the currently active Dialog.
Definition: dialog.c:223
static struct AttrColor * default_color(struct Menu *menu, int line)
Get the default colour for a line of the menu - Implements Menu::color() -.
Definition: menu.c:47
static int generic_search(struct Menu *menu, regex_t *rx, int line)
Search a menu for a item matching a regex - Implements Menu::search() -.
Definition: menu.c:55
Convenience wrapper for the gui headers.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define FREE(x)
Definition: memory.h:43
GUI present the user with a selectable list.
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:60
uint8_t MenuRedrawFlags
Flags, e.g. MENU_REDRAW_INDEX.
Definition: lib.h:55
MenuRedrawFlags menu_move_selection(struct Menu *menu, int index)
Move the selection, keeping within between [0, menu->max].
Definition: move.c:236
void menu_add_observers(struct Menu *menu)
Add the notification observers.
Definition: observer.c:133
enum MenuType menu_get_current_type(void)
Get the type of the current Window.
Definition: menu.c:85
void menu_init(void)
Initialise all the Menus.
Definition: menu.c:75
void menu_cleanup(void)
Free the saved Menu searches.
Definition: menu.c:66
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:179
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:155
void menu_free(struct Menu **ptr)
Free a Menu.
Definition: menu.c:112
char * SearchBuffers[MENU_MAX]
Previous search string, one for each MenuType.
Definition: menu.c:42
struct Menu * menu_new(enum MenuType type, struct MuttWindow *win, struct ConfigSubset *sub)
Create a new Menu.
Definition: menu.c:131
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:169
Convenience wrapper for the library headers.
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:60
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:93
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:73
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
@ WT_CUSTOM
Window with a custom drawing function.
Definition: mutt_window.h:95
@ WT_PAGER
A panel containing the Pager Window.
Definition: mutt_window.h:100
@ WT_MENU
An Window containing a Menu.
Definition: mutt_window.h:98
GUI display the mailboxes in a side panel.
A curses colour and its attributes.
Definition: attr.h:35
A set of inherited config items.
Definition: subset.h:47
Definition: lib.h:70
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:97
int current
Current entry.
Definition: lib.h:71
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:73
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
struct AttrColor *(* color)(struct Menu *menu, int line)
Definition: lib.h:134
int(* search)(struct Menu *menu, regex_t *rx, int line)
Definition: lib.h:110
enum MenuType type
Menu definition for keymap entries.
Definition: lib.h:74
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:78
struct Notify * notify
Notifications.
Definition: lib.h:136
void * mdata
Private data.
Definition: lib.h:138
int page_len
Number of entries per screen.
Definition: lib.h:75
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
Menu types.
MenuType
Types of GUI selections.
Definition: type.h:36
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:50
@ MENU_GENERIC
Generic selection list.
Definition: type.h:45
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:54
@ MENU_MAX
Definition: type.h:59