NeoMutt  2022-04-29-178-g3b62e6
Teaching an old dog new tricks
DOXYGEN
menu.c File Reference

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

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

Go to the source code of this file.

Functions

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

Variables

char * SearchBuffers [MENU_MAX]
 

Detailed Description

GUI present the user with a selectable list.

Authors
  • Michael R. Elkins
  • 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_cleanup()

void menu_cleanup ( void  )

Free the saved Menu searches.

Definition at line 65 of file menu.c.

66{
67 for (int i = 0; i < MENU_MAX; i++)
69}
#define FREE(x)
Definition: memory.h:43
char * SearchBuffers[MENU_MAX]
Definition: menu.c:41
@ MENU_MAX
Definition: type.h:59
+ Here is the caller graph for this function:

◆ menu_init()

void menu_init ( void  )

Initialise all the Menus.

Definition at line 74 of file menu.c.

75{
76 for (int i = 0; i < MENU_MAX; i++)
77 SearchBuffers[i] = NULL;
78}
+ 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 84 of file menu.c.

85{
86 struct MuttWindow *win = alldialogs_get_current();
87 while (win && win->focus)
88 win = win->focus;
89
90 // This should only happen before the first window is created
91 if (!win)
92 return MENU_INDEX;
93
94 if ((win->type == WT_CUSTOM) && (win->parent->type == WT_PAGER))
95 return MENU_PAGER;
96
97 if (win->type != WT_MENU)
98 return MENU_GENERIC;
99
100 struct Menu *menu = win->wdata;
101 if (!menu)
102 return MENU_GENERIC;
103
104 return menu->type;
105}
struct MuttWindow * alldialogs_get_current(void)
Get the currently active Dialog.
Definition: dialog.c:223
@ 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
Definition: lib.h:69
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
enum MenuType type
Menu definition for keymap entries.
Definition: lib.h:73
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
void * wdata
Private data.
Definition: mutt_window.h:145
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
@ 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
+ 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 111 of file menu.c.

112{
113 struct Menu *menu = *ptr;
114
115 notify_free(&menu->notify);
116
117 if (menu->mdata_free && menu->mdata)
118 menu->mdata_free(menu, &menu->mdata); // Custom function to free private data
119
120 FREE(ptr);
121}
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:73
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
struct Notify * notify
Notifications.
Definition: lib.h:135
void * mdata
Private data.
Definition: lib.h:137
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_new()

struct Menu * menu_new ( enum MenuType  type,
struct MuttWindow win,
struct ConfigSubset sub 
)

Create a new Menu.

Parameters
typeMenu type, e.g. MENU_ALIAS
winParent Window
subConfig items
Return values
ptrNew Menu

Definition at line 130 of file menu.c.

131{
132 struct Menu *menu = mutt_mem_calloc(1, sizeof(struct Menu));
133
134 menu->type = type;
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
144 menu_add_observers(menu);
145
146 return menu;
147}
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:46
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:54
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:59
void menu_add_observers(struct Menu *menu)
Add the notification observers.
Definition: observer.c:133
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
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:72
struct AttrColor *(* color)(struct Menu *menu, int line)
Definition: lib.h:133
int(* search)(struct Menu *menu, regex_t *rx, int line)
Definition: lib.h:109
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:77
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
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
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 154 of file menu.c.

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

◆ 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
numMenuRedrawFlags, e.g. MENU_REDRAW_INDEX

Definition at line 168 of file menu.c.

169{
170 return menu_move_selection(menu, index);
171}
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:
+ Here is the caller 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 178 of file menu.c.

179{
180 if (!menu)
181 return;
182
183 menu->redraw |= redraw;
184 menu->win->actions |= WA_RECALC;
185}
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132

Variable Documentation

◆ SearchBuffers

char* SearchBuffers[MENU_MAX]

Definition at line 41 of file menu.c.