NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
dlghistory.c
Go to the documentation of this file.
1 
60 #include "config.h"
61 #include <stdbool.h>
62 #include <stdint.h>
63 #include <stdio.h>
64 #include "mutt/lib.h"
65 #include "gui/lib.h"
66 #include "lib.h"
67 #include "menu/lib.h"
68 #include "format_flags.h"
69 #include "muttlib.h"
70 #include "opcodes.h"
71 
73 static const struct Mapping HistoryHelp[] = {
74  // clang-format off
75  { N_("Exit"), OP_EXIT },
76  { N_("Select"), OP_GENERIC_SELECT_ENTRY },
77  { N_("Search"), OP_SEARCH },
78  { N_("Help"), OP_HELP },
79  { NULL, 0 },
80  // clang-format on
81 };
82 
90 static const char *history_format_str(char *buf, size_t buflen, size_t col, int cols,
91  char op, const char *src, const char *prec,
92  const char *if_str, const char *else_str,
93  intptr_t data, MuttFormatFlags flags)
94 {
95  char *match = (char *) data;
96 
97  switch (op)
98  {
99  case 's':
100  mutt_format_s(buf, buflen, prec, match);
101  break;
102  }
103 
104  return src;
105 }
106 
110 static void history_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
111 {
112  char *entry = ((char **) menu->mdata)[line];
113 
114  mutt_expando_format(buf, buflen, 0, menu->win->state.cols, "%s", history_format_str,
115  (intptr_t) entry, MUTT_FORMAT_ARROWCURSOR);
116 }
117 
125 void dlg_select_history(char *buf, size_t buflen, char **matches, int match_count)
126 {
127  struct MuttWindow *dlg = simple_dialog_new(MENU_GENERIC, WT_DLG_HISTORY, HistoryHelp);
128 
129  struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
130  char title[256];
131  snprintf(title, sizeof(title), _("History '%s'"), buf);
132  sbar_set_title(sbar, title);
133 
134  struct Menu *menu = dlg->wdata;
136  menu->max = match_count;
137  menu->mdata = matches;
138 
139  bool done = false;
140  while (!done)
141  {
142  switch (menu_loop(menu))
143  {
144  case OP_GENERIC_SELECT_ENTRY:
145  {
146  const int index = menu_get_index(menu);
147  mutt_str_copy(buf, matches[index], buflen);
148  done = true;
149  break;
150  }
151 
152  case OP_EXIT:
153  done = true;
154  break;
155  }
156  }
157 
158  simple_dialog_free(&dlg);
159 }
Convenience wrapper for the gui headers.
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:550
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:780
uint8_t MuttFormatFlags
Flags for mutt_expando_format(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: format_flags.h:29
History Dialog, dlg_select_history()
Definition: mutt_window.h:85
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:165
Definition: lib.h:67
Generic selection list.
Definition: type.h:45
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
#define _(a)
Definition: message.h:28
Flags to control mutt_expando_format()
All user-callable functions.
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:105
Some miscellaneous functions.
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
void * mdata
Private data.
Definition: lib.h:155
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:221
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:110
int max
Number of entries in the menu.
Definition: lib.h:71
void mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s)
Format a simple string.
Definition: curs_lib.c:867
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:749
Mapping between user-readable string and a constant.
Definition: mapping.h:31
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:128
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 -Expando Description %s History match ...
Definition: dlghistory.c:90
Convenience wrapper for the library headers.
void * wdata
Private data.
Definition: mutt_window.h:145
#define N_(a)
Definition: message.h:32
void dlg_select_history(char *buf, size_t buflen, char **matches, int match_count)
Select an item from a history list.
Definition: dlghistory.c:125