NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
menu.c File Reference

GUI present the user with a selectable list. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "private.h"
#include "mutt/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "color/lib.h"
#include "expando/lib.h"
#include "key/lib.h"
#include "module_data.h"
#include "type.h"
+ Include dependency graph for menu.c:

Go to the source code of this file.

Functions

static const struct AttrColordefault_color (struct Menu *menu, int line)
 Get the default colour for a line of the menu - Implements Menu::color() -.
 
static int generic_search (struct Menu *menu, regex_t *rx, int line)
 Search a menu for a item matching a regex - Implements Menu::search() -.
 
void menu_init2 (char **search_buffers)
 Initialise all the Menus.
 
enum MenuType menu_get_current_type (void)
 Get the type of the current Window.
 
void menu_free (struct Menu **ptr)
 Free a Menu.
 
struct Menumenu_new (const struct MenuDefinition *md, struct MuttWindow *win, struct ConfigSubset *sub)
 Create a new Menu.
 
int menu_get_index (struct Menu *menu)
 Get the current selection in the Menu.
 
MenuRedrawFlags menu_set_index (struct Menu *menu, int index)
 Set the current selection in the Menu.
 
void menu_queue_redraw (struct Menu *menu, MenuRedrawFlags redraw)
 Queue a request for a redraw.
 

Detailed Description

GUI present the user with a selectable list.

Authors
  • Richard Russon
  • R Primus

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

Function Documentation

◆ menu_init2()

void menu_init2 ( char ** search_buffers)

Initialise all the Menus.

Parameters
search_buffersArray of search buffer pointers to initialise

Definition at line 72 of file menu.c.

73{
74 for (int i = 0; i < MENU_MAX; i++)
75 search_buffers[i] = NULL;
76}
@ MENU_MAX
Definition type.h:52
+ Here is the caller graph for this function:

◆ menu_get_current_type()

enum MenuType menu_get_current_type ( void )

Get the type of the current Window.

Return values
enumMenu Type, e.g. MENU_PAGER

Definition at line 82 of file menu.c.

83{
84 struct MuttWindow *win = window_get_focus();
85
86 // This should only happen before the first window is created
87 if (!win)
88 return MENU_INDEX;
89
90 if ((win->type == WT_CUSTOM) && (win->parent->type == WT_PAGER))
91 return MENU_PAGER;
92
93 if (win->type != WT_MENU)
94 return MENU_GENERIC;
95
96 struct Menu *menu = win->wdata;
97 if (!menu)
98 return MENU_GENERIC;
99
100 return menu->md->id;
101}
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
@ WT_CUSTOM
Window with a custom drawing function.
Definition mutt_window.h:95
@ WT_PAGER
A panel containing the Pager Window.
@ WT_MENU
An Window containing a Menu.
Definition mutt_window.h:98
int id
Menu ID, e.g. MENU_ALIAS.
Definition menu.h:78
Definition lib.h:86
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:94
const struct MenuDefinition * md
Menu definition for keymap entries.
Definition lib.h:90
void * wdata
Private data.
struct MuttWindow * parent
Parent Window.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
@ MENU_INDEX
Index panel (list of emails)
Definition type.h:44
@ MENU_GENERIC
Generic selection list.
Definition type.h:43
@ MENU_PAGER
Pager pager (email viewer)
Definition type.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_free()

void menu_free ( struct Menu ** ptr)

Free a Menu.

Parameters
ptrMenu to free

Definition at line 107 of file menu.c.

108{
109 if (!ptr || !*ptr)
110 return;
111
112 struct Menu *menu = *ptr;
113
114 notify_free(&menu->notify);
115
116 if (menu->mdata_free && menu->mdata)
117 menu->mdata_free(menu, &menu->mdata); // Custom function to free private data
118
119 FREE(ptr);
120}
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition notify.c:75
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition lib.h:169
struct Notify * notify
Notifications.
Definition lib.h:153
void * mdata
Private data.
Definition lib.h:155
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_new()

struct Menu * menu_new ( const struct MenuDefinition * md,
struct MuttWindow * win,
struct ConfigSubset * sub )

Create a new Menu.

Parameters
mdMenu Definition
winParent Window
subConfig items
Return values
ptrNew Menu

Definition at line 129 of file menu.c.

131{
132 struct Menu *menu = MUTT_MEM_CALLOC(1, struct Menu);
133
134 menu->md = md;
135 menu->redraw = MENU_REDRAW_FULL;
136 menu->color = default_color;
137 menu->search = generic_search;
138 menu->notify = notify_new();
139 menu->win = win;
140 menu->page_len = win->state.rows;
141 menu->sub = sub;
142 menu->show_indicator = true;
143
145 menu_add_observers(menu);
146
147 return menu;
148}
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:49
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:57
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
@ MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:64
void menu_add_observers(struct Menu *menu)
Add the notification observers.
Definition observer.c:137
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
const struct AttrColor *(* color)(struct Menu *menu, int line)
Definition lib.h:151
MenuRedrawFlags redraw
When to redraw the screen.
Definition lib.h:89
bool show_indicator
Show the Indicator colour.
Definition lib.h:93
int(* search)(struct Menu *menu, regex_t *rx, int line)
Definition lib.h:127
struct ConfigSubset * sub
Inherited config items.
Definition lib.h:95
int page_len
Number of entries per screen.
Definition lib.h:91
struct WindowState state
Current state of the Window.
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition mutt_window.h:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_get_index()

int menu_get_index ( struct Menu * menu)

Get the current selection in the Menu.

Parameters
menuMenu
Return values
numIndex of selection

Definition at line 155 of file menu.c.

156{
157 if (!menu)
158 return -1;
159
160 return menu->current;
161}
int current
Current entry.
Definition lib.h:87

◆ menu_set_index()

MenuRedrawFlags menu_set_index ( struct Menu * menu,
int index )

Set the current selection in the Menu.

Parameters
menuMenu
indexItem to select
Return values
enumMenuRedrawFlags, e.g. MENU_REDRAW_INDEX

Definition at line 169 of file menu.c.

170{
171 return menu_move_selection(menu, index);
172}
MenuRedrawFlags menu_move_selection(struct Menu *menu, int index)
Move the selection, keeping within between [0, menu->max].
Definition move.c:236
+ Here is the call graph for this function:

◆ menu_queue_redraw()

void menu_queue_redraw ( struct Menu * menu,
MenuRedrawFlags redraw )

Queue a request for a redraw.

Parameters
menuMenu
redrawItem to redraw, e.g. MENU_REDRAW_CURRENT

Definition at line 179 of file menu.c.

180{
181 if (!menu)
182 return;
183
184 menu->redraw |= redraw;
185 menu->win->actions |= WA_RECALC;
186}
@ WA_RECALC
Recalculate the contents of the Window.
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.