NeoMutt  2024-02-01-35-geee02f
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 "type.h"
38
39struct ConfigSubset;
40
43
47static const 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 struct Buffer *buf = buf_pool_get();
58
59 menu->make_entry(menu, line, buf);
60 int rc = regexec(rx, buf->data, 0, NULL, 0);
61 buf_pool_release(&buf);
62
63 return rc;
64}
65
69void menu_cleanup(void)
70{
71 for (int i = 0; i < MENU_MAX; i++)
73}
74
78void menu_init(void)
79{
80 for (int i = 0; i < MENU_MAX; i++)
81 SearchBuffers[i] = NULL;
82}
83
89{
90 struct MuttWindow *win = window_get_focus();
91
92 // This should only happen before the first window is created
93 if (!win)
94 return MENU_INDEX;
95
96 if ((win->type == WT_CUSTOM) && (win->parent->type == WT_PAGER))
97 return MENU_PAGER;
98
99 if (win->type != WT_MENU)
100 return MENU_GENERIC;
101
102 struct Menu *menu = win->wdata;
103 if (!menu)
104 return MENU_GENERIC;
105
106 return menu->type;
107}
108
113void menu_free(struct Menu **ptr)
114{
115 if (!ptr || !*ptr)
116 return;
117
118 struct Menu *menu = *ptr;
119
120 notify_free(&menu->notify);
121
122 if (menu->mdata_free && menu->mdata)
123 menu->mdata_free(menu, &menu->mdata); // Custom function to free private data
124
125 FREE(ptr);
126}
127
135struct Menu *menu_new(enum MenuType type, struct MuttWindow *win, struct ConfigSubset *sub)
136{
137 struct Menu *menu = mutt_mem_calloc(1, sizeof(struct Menu));
138
139 menu->type = type;
140 menu->redraw = MENU_REDRAW_FULL;
141 menu->color = default_color;
142 menu->search = generic_search;
143 menu->notify = notify_new();
144 menu->win = win;
145 menu->page_len = win->state.rows;
146 menu->sub = sub;
147
149 menu_add_observers(menu);
150
151 return menu;
152}
153
159int menu_get_index(struct Menu *menu)
160{
161 if (!menu)
162 return -1;
163
164 return menu->current;
165}
166
173MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
174{
175 return menu_move_selection(menu, index);
176}
177
184{
185 if (!menu)
186 return;
187
188 menu->redraw |= redraw;
189 menu->win->actions |= WA_RECALC;
190}
Color and attribute parsing.
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition: simple.c:88
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:59
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: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:45
#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:88
void menu_init(void)
Initialise all the Menus.
Definition: menu.c:78
void menu_cleanup(void)
Free the saved Menu searches.
Definition: menu.c:69
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:183
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:159
void menu_free(struct Menu **ptr)
Free a Menu.
Definition: menu.c:113
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:135
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:173
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:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
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:69
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
int current
Current entry.
Definition: lib.h:70
const struct AttrColor *(* color)(struct Menu *menu, int line)
Definition: lib.h:131
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:72
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:149
int(* search)(struct Menu *menu, regex_t *rx, int line)
Definition: lib.h:107
enum MenuType type
Menu definition for keymap entries.
Definition: lib.h:73
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:77
struct Notify * notify
Notifications.
Definition: lib.h:133
void * mdata
Private data.
Definition: lib.h:135
void(* make_entry)(struct Menu *menu, int line, struct Buffer *buf)
Definition: lib.h:94
int page_len
Number of entries per screen.
Definition: lib.h:74
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:61
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:55
@ MENU_MAX
Definition: type.h:60