NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 "lib.h"
36#include "color/lib.h"
37#include "expando/lib.h" // IWYU pragma: keep
38#include "type.h"
39
40struct ConfigSubset;
41
44
48static const struct AttrColor *default_color(struct Menu *menu, int line)
49{
51}
52
56static int generic_search(struct Menu *menu, regex_t *rx, int line)
57{
58 struct Buffer *buf = buf_pool_get();
59
60 menu->make_entry(menu, line, -1, buf);
61 int rc = regexec(rx, buf->data, 0, NULL, 0);
62 buf_pool_release(&buf);
63
64 return rc;
65}
66
70void menu_cleanup(void)
71{
72 for (int i = 0; i < MENU_MAX; i++)
74}
75
79void menu_init(void)
80{
81 for (int i = 0; i < MENU_MAX; i++)
82 SearchBuffers[i] = NULL;
83}
84
90{
91 struct MuttWindow *win = window_get_focus();
92
93 // This should only happen before the first window is created
94 if (!win)
95 return MENU_INDEX;
96
97 if ((win->type == WT_CUSTOM) && (win->parent->type == WT_PAGER))
98 return MENU_PAGER;
99
100 if (win->type != WT_MENU)
101 return MENU_GENERIC;
102
103 struct Menu *menu = win->wdata;
104 if (!menu)
105 return MENU_GENERIC;
106
107 return menu->type;
108}
109
114void menu_free(struct Menu **ptr)
115{
116 if (!ptr || !*ptr)
117 return;
118
119 struct Menu *menu = *ptr;
120
121 notify_free(&menu->notify);
122
123 if (menu->mdata_free && menu->mdata)
124 menu->mdata_free(menu, &menu->mdata); // Custom function to free private data
125
126 FREE(ptr);
127}
128
136struct Menu *menu_new(enum MenuType type, struct MuttWindow *win, struct ConfigSubset *sub)
137{
138 struct Menu *menu = MUTT_MEM_CALLOC(1, struct Menu);
139
140 menu->type = type;
141 menu->redraw = MENU_REDRAW_FULL;
142 menu->color = default_color;
143 menu->search = generic_search;
144 menu->notify = notify_new();
145 menu->win = win;
146 menu->page_len = win->state.rows;
147 menu->sub = sub;
148
150 menu_add_observers(menu);
151
152 return menu;
153}
154
160int menu_get_index(struct Menu *menu)
161{
162 if (!menu)
163 return -1;
164
165 return menu->current;
166}
167
174MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
175{
176 return menu_move_selection(menu, index);
177}
178
185{
186 if (!menu)
187 return;
188
189 menu->redraw |= redraw;
190 menu->win->actions |= WA_RECALC;
191}
Color and attribute parsing.
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition: simple.c:95
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:55
Parse Expando string.
static const 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:48
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:56
Convenience wrapper for the gui headers.
#define FREE(x)
Definition: memory.h:55
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:59
uint8_t MenuRedrawFlags
Flags, e.g. MENU_REDRAW_INDEX.
Definition: lib.h:54
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:134
enum MenuType menu_get_current_type(void)
Get the type of the current Window.
Definition: menu.c:89
void menu_init(void)
Initialise all the Menus.
Definition: menu.c:79
void menu_cleanup(void)
Free the saved Menu searches.
Definition: menu.c:70
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:184
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:160
void menu_free(struct Menu **ptr)
Free a Menu.
Definition: menu.c:114
char * SearchBuffers[MENU_MAX]
Previous search string, one for each MenuType.
Definition: menu.c:43
struct Menu * menu_new(enum MenuType type, struct MuttWindow *win, struct ConfigSubset *sub)
Create a new Menu.
Definition: menu.c:136
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:174
Convenience wrapper for the library headers.
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:62
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:95
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:75
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
Definition: mutt_window.c:668
#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
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
GUI display the mailboxes in a side panel.
Key value store.
A curses colour and its attributes.
Definition: attr.h:66
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
A set of inherited config items.
Definition: subset.h:47
Definition: lib.h:79
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:86
int current
Current entry.
Definition: lib.h:80
const struct AttrColor *(* color)(struct Menu *menu, int line)
Definition: lib.h:143
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:82
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:161
int(* search)(struct Menu *menu, regex_t *rx, int line)
Definition: lib.h:119
enum MenuType type
Menu definition for keymap entries.
Definition: lib.h:83
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition: lib.h:106
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:87
struct Notify * notify
Notifications.
Definition: lib.h:145
void * mdata
Private data.
Definition: lib.h:147
int page_len
Number of entries per screen.
Definition: lib.h:84
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
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:62
Menu types.
MenuType
Types of GUI selections.
Definition: type.h:36
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:51
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:52
@ MENU_MAX
Definition: type.h:57