NeoMutt  2021-10-29-33-g41675a
Teaching an old dog new tricks
DOXYGEN
dlgpattern.c File Reference

Pattern Selection Dialog. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "menu/lib.h"
#include "format_flags.h"
#include "muttlib.h"
#include "opcodes.h"
+ Include dependency graph for dlgpattern.c:

Go to the source code of this file.

Data Structures

struct  PatternEntry
 A line in the Pattern Completion menu. More...
 

Functions

static const char * pattern_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 pattern completion menu - Implements format_t -. More...
 
static void make_pattern_entry (struct Menu *menu, char *buf, size_t buflen, int num)
 Create a line for the Pattern Completion menu - Implements Menu::make_entry() -. More...
 
static void free_pattern_menu (struct Menu *menu, void **ptr)
 Free the Pattern Completion menu - Implements Menu::mdata_free() -. More...
 
static struct Menucreate_pattern_menu (struct MuttWindow *dlg)
 Create the Pattern Completion menu. More...
 
static int pattern_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -. More...
 
static int pattern_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -. More...
 
bool dlg_select_pattern (char *buf, size_t buflen)
 Show menu to select a Pattern. More...
 

Variables

static const struct Mapping PatternHelp []
 Help Bar for the Pattern selection dialog. More...
 

Detailed Description

Pattern Selection Dialog.

Authors
  • Michael R. Elkins
  • Pietro Cerutti

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

Function Documentation

◆ create_pattern_menu()

static struct Menu* create_pattern_menu ( struct MuttWindow dlg)
static

Create the Pattern Completion menu.

Parameters
dlgDialog holding the Menu
Return values
ptrNew Menu

Definition at line 177 of file dlgpattern.c.

178 {
179  int num_entries = 0, i = 0;
180  struct Buffer *entrybuf = NULL;
181 
182  while (Flags[num_entries].tag)
183  num_entries++;
184  /* Add three more hard-coded entries */
185  num_entries += 3;
186  struct PatternEntry *entries =
187  mutt_mem_calloc(num_entries, sizeof(struct PatternEntry));
188 
189  struct Menu *menu = dlg->wdata;
191  menu->mdata = entries;
193  menu->max = num_entries;
194 
195  struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
196  // L10N: Pattern completion menu title
197  sbar_set_title(sbar, _("Patterns"));
198 
199  entrybuf = mutt_buffer_pool_get();
200  while (Flags[i].tag)
201  {
202  entries[i].num = i + 1;
203 
204  mutt_buffer_printf(entrybuf, "~%c", (char) Flags[i].tag);
205  entries[i].tag = mutt_str_dup(mutt_buffer_string(entrybuf));
206 
207  switch (Flags[i].eat_arg)
208  {
209  case EAT_REGEX:
210  /* L10N:
211  Pattern Completion Menu argument type: a regular expression
212  */
213  mutt_buffer_add_printf(entrybuf, " %s", _("EXPR"));
214  break;
215  case EAT_RANGE:
216  case EAT_MESSAGE_RANGE:
217  /* L10N:
218  Pattern Completion Menu argument type: a numeric range.
219  Used by ~m, ~n, ~X, ~z.
220  */
221  mutt_buffer_add_printf(entrybuf, " %s", _("RANGE"));
222  break;
223  case EAT_DATE:
224  /* L10N:
225  Pattern Completion Menu argument type: a date range
226  Used by ~d, ~r.
227  */
228  mutt_buffer_add_printf(entrybuf, " %s", _("DATERANGE"));
229  break;
230  case EAT_QUERY:
231  /* L10N:
232  Pattern Completion Menu argument type: a query
233  Used by ~I.
234  */
235  mutt_buffer_add_printf(entrybuf, " %s", _("QUERY"));
236  break;
237  default:
238  break;
239  }
240  entries[i].expr = mutt_str_dup(mutt_buffer_string(entrybuf));
241  entries[i].desc = mutt_str_dup(_(Flags[i].desc));
242 
243  i++;
244  }
245 
246  /* Add struct MuttThread patterns manually.
247  * Note we allocated 3 extra slots for these above. */
248 
249  /* L10N:
250  Pattern Completion Menu argument type: a nested pattern.
251  Used by ~(), ~<(), ~>().
252  */
253  const char *patternstr = _("PATTERN");
254 
255  entries[i].num = i + 1;
256  entries[i].tag = mutt_str_dup("~()");
257  mutt_buffer_printf(entrybuf, "~(%s)", patternstr);
258  entries[i].expr = mutt_str_dup(mutt_buffer_string(entrybuf));
259  // L10N: Pattern Completion Menu description for ~()
260  entries[i].desc = mutt_str_dup(
261  _("messages in threads containing messages matching PATTERN"));
262  i++;
263 
264  entries[i].num = i + 1;
265  entries[i].tag = mutt_str_dup("~<()");
266  mutt_buffer_printf(entrybuf, "~<(%s)", patternstr);
267  entries[i].expr = mutt_str_dup(mutt_buffer_string(entrybuf));
268  // L10N: Pattern Completion Menu description for ~<()
269  entries[i].desc =
270  mutt_str_dup(_("messages whose immediate parent matches PATTERN"));
271  i++;
272 
273  entries[i].num = i + 1;
274  entries[i].tag = mutt_str_dup("~>()");
275  mutt_buffer_printf(entrybuf, "~>(%s)", patternstr);
276  entries[i].expr = mutt_str_dup(mutt_buffer_string(entrybuf));
277  // L10N: Pattern Completion Menu description for ~>()
278  entries[i].desc =
279  mutt_str_dup(_("messages having an immediate child matching PATTERN"));
280 
281  mutt_buffer_pool_release(&entrybuf);
282 
283  return menu;
284 }
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:203
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
static void make_pattern_entry(struct Menu *menu, char *buf, size_t buflen, int num)
Create a line for the Pattern Completion menu - Implements Menu::make_entry() -.
Definition: dlgpattern.c:145
static void free_pattern_menu(struct Menu *menu, void **ptr)
Free the Pattern Completion menu - Implements Menu::mdata_free() -.
Definition: dlgpattern.c:158
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define _(a)
Definition: message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:181
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:520
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
const struct PatternFlags Flags[]
Lookup table for all patterns.
Definition: flags.c:40
@ EAT_RANGE
Process a number (range)
Definition: private.h:41
@ EAT_MESSAGE_RANGE
Process a message number (range)
Definition: private.h:42
@ EAT_DATE
Process a date (range)
Definition: private.h:40
@ EAT_QUERY
Process a query string.
Definition: private.h:43
@ EAT_REGEX
Process a regex.
Definition: private.h:39
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:219
String manipulation buffer.
Definition: buffer.h:34
Definition: lib.h:67
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:103
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:168
void * mdata
Private data.
Definition: lib.h:153
int max
Number of entries in the menu.
Definition: lib.h:69
void * wdata
Private data.
Definition: mutt_window.h:145
A line in the Pattern Completion menu.
Definition: dlgpattern.c:89
const char * desc
Description of pattern.
Definition: dlgpattern.c:93
const char * tag
Copied to buffer if selected.
Definition: dlgpattern.c:91
int num
Index number.
Definition: dlgpattern.c:90
const char * expr
Displayed in the menu.
Definition: dlgpattern.c:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dlg_select_pattern()

bool dlg_select_pattern ( char *  buf,
size_t  buflen 
)

Show menu to select a Pattern.

Parameters
bufBuffer for the selected Pattern
buflenLength of buffer
Return values
trueA selection was made

Definition at line 343 of file dlgpattern.c.

344 {
346  struct Menu *menu = create_pattern_menu(dlg);
347 
348  struct MuttWindow *win_menu = menu->win;
349 
350  // NT_COLOR is handled by the SimpleDialog
353 
354  bool rc = false;
355  bool done = false;
356  while (!done)
357  {
358  switch (menu_loop(menu))
359  {
360  case OP_GENERIC_SELECT_ENTRY:
361  {
362  const int index = menu_get_index(menu);
363  struct PatternEntry *entry = ((struct PatternEntry *) menu->mdata) + index;
364  mutt_str_copy(buf, entry->tag, buflen);
365  rc = true;
366  done = true;
367  break;
368  }
369 
370  case OP_EXIT:
371  done = true;
372  break;
373  }
374  }
375 
376  simple_dialog_free(&dlg);
377  return rc;
378 }
static struct Menu * create_pattern_menu(struct MuttWindow *dlg)
Create the Pattern Completion menu.
Definition: dlgpattern.c:177
static const struct Mapping PatternHelp[]
Help Bar for the Pattern selection dialog.
Definition: dlgpattern.c:97
static int pattern_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: dlgpattern.c:315
static int pattern_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: dlgpattern.c:291
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:126
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:163
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:608
int menu_loop(struct Menu *menu)
Menu event loop.
Definition: menu.c:283
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:189
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:560
@ WT_DLG_PATTERN
Pattern Dialog, create_pattern_menu()
Definition: mutt_window.h:87
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:74
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
@ MENU_GENERIC
Generic selection list.
Definition: type.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ PatternHelp

const struct Mapping PatternHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Select"), OP_GENERIC_SELECT_ENTRY },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
}
#define N_(a)
Definition: message.h:32

Help Bar for the Pattern selection dialog.

Definition at line 1 of file dlgpattern.c.