NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
dlghistory.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <stdbool.h>
31 #include <stdint.h>
32 #include <stdio.h>
33 #include "mutt/lib.h"
34 #include "gui/lib.h"
35 #include "mutt.h"
36 #include "history/lib.h"
37 #include "format_flags.h"
38 #include "keymap.h"
39 #include "mutt_menu.h"
40 #include "muttlib.h"
41 #include "opcodes.h"
42 
44 static const struct Mapping HistoryHelp[] = {
45  // clang-format off
46  { N_("Exit"), OP_EXIT },
47  { N_("Select"), OP_GENERIC_SELECT_ENTRY },
48  { N_("Search"), OP_SEARCH },
49  { N_("Help"), OP_HELP },
50  { NULL, 0 },
51  // clang-format on
52 };
53 
61 static const char *history_format_str(char *buf, size_t buflen, size_t col, int cols,
62  char op, const char *src, const char *prec,
63  const char *if_str, const char *else_str,
64  intptr_t data, MuttFormatFlags flags)
65 {
66  char *match = (char *) data;
67 
68  switch (op)
69  {
70  case 's':
71  mutt_format_s(buf, buflen, prec, match);
72  break;
73  }
74 
75  return src;
76 }
77 
81 static void history_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
82 {
83  char *entry = ((char **) menu->mdata)[line];
84 
85  mutt_expando_format(buf, buflen, 0, menu->win_index->state.cols, "%s",
86  history_format_str, (intptr_t) entry, MUTT_FORMAT_ARROWCURSOR);
87 }
88 
96 void dlg_select_history(char *buf, size_t buflen, char **matches, int match_count)
97 {
98  bool done = false;
99  char title[256];
100 
101  snprintf(title, sizeof(title), _("History '%s'"), buf);
102 
103  struct Menu *menu = mutt_menu_new(MENU_GENERIC);
105  dlg->help_data = HistoryHelp;
106  dlg->help_menu = MENU_GENERIC;
107 
109  menu->title = title;
111 
112  menu->max = match_count;
113  menu->mdata = matches;
114 
115  while (!done)
116  {
117  switch (mutt_menu_loop(menu))
118  {
119  case OP_GENERIC_SELECT_ENTRY:
120  mutt_str_copy(buf, matches[menu->current], buflen);
121  /* fall through */
122 
123  case OP_EXIT:
124  done = true;
125  break;
126  }
127  }
128 
129  mutt_menu_pop_current(menu);
130  mutt_menu_free(&menu);
132 }
MENU_GENERIC
@ MENU_GENERIC
Generic selection list.
Definition: keymap.h:79
dialog_create_simple_index
struct MuttWindow * dialog_create_simple_index(struct Menu *menu, enum WindowType type)
Create a simple index Dialog.
Definition: dialog.c:165
HistoryHelp
static const struct Mapping HistoryHelp[]
Help Bar for the History Selection dialog.
Definition: dlghistory.c:44
_
#define _(a)
Definition: message.h:28
format_flags.h
history_make_entry
static void history_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format a menu item for the history list - Implements Menu::make_entry()
Definition: dlghistory.c:81
MUTT_FORMAT_ARROWCURSOR
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
MuttWindow
A division of the screen.
Definition: mutt_window.h:115
mutt_menu_new
struct Menu * mutt_menu_new(enum MenuType type)
Create a new Menu.
Definition: menu.c:956
MuttWindow::help_menu
int help_menu
Menu for key bindings, e.g. MENU_PAGER.
Definition: mutt_window.h:134
Menu::make_entry
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Format a item for a menu.
Definition: mutt_menu.h:88
Mapping
Mapping between user-readable string and a constant.
Definition: mapping.h:31
mutt_menu_push_current
void mutt_menu_push_current(struct Menu *menu)
Add a new Menu to the stack.
Definition: menu.c:1015
keymap.h
lib.h
muttlib.h
dlg_select_history
void dlg_select_history(char *buf, size_t buflen, char **matches, int match_count)
Select an item from a history list.
Definition: dlghistory.c:96
mutt_menu.h
Menu::title
const char * title
Title of this menu.
Definition: mutt_menu.h:54
MuttWindow::help_data
const struct Mapping * help_data
Data for the Help Bar.
Definition: mutt_window.h:135
mutt_format_s
void mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s)
Format a simple string.
Definition: curs_lib.c:1248
mutt_menu_loop
int mutt_menu_loop(struct Menu *menu)
Menu event loop.
Definition: menu.c:1309
MuttWindow::state
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
mutt_menu_pop_current
void mutt_menu_pop_current(struct Menu *menu)
Remove a Menu from the stack.
Definition: menu.c:1027
Menu::mdata
void * mdata
Extra data for the current menu.
Definition: mutt_menu.h:55
mutt_expando_format
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:774
Menu::max
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
mutt.h
WindowState::cols
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:57
dialog_destroy_simple_index
void dialog_destroy_simple_index(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: dialog.c:209
Menu::current
int current
Current entry.
Definition: mutt_menu.h:56
opcodes.h
WT_DLG_HISTORY
@ WT_DLG_HISTORY
History Dialog, dlg_select_history()
Definition: mutt_window.h:82
lib.h
Menu::win_index
struct MuttWindow * win_index
Definition: mutt_menu.h:63
Menu
GUI selectable list of items.
Definition: mutt_menu.h:52
N_
#define N_(a)
Definition: message.h:32
lib.h
history_format_str
static const char * history_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Format a string for the history list - Implements format_t.
Definition: dlghistory.c:61
MuttFormatFlags
uint8_t MuttFormatFlags
Flags for mutt_expando_format(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: format_flags.h:29
mutt_menu_free
void mutt_menu_free(struct Menu **ptr)
Destroy a menu.
Definition: menu.c:972
mutt_str_copy
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:716