NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_pattern.c File Reference

Pattern Selection Dialog. More...

#include "config.h"
#include <stdbool.h>
#include <stddef.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "expando/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "functions.h"
#include "mutt_logging.h"
+ Include dependency graph for dlg_pattern.c:

Go to the source code of this file.

Functions

void pattern_d (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
 Pattern: pattern description - Implements ExpandoRenderData::get_string() -.
 
void pattern_e (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
 Pattern: pattern expression - Implements ExpandoRenderData::get_string() -.
 
long pattern_n_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Pattern: Index number - Implements ExpandoRenderData::get_number() -.
 
static int pattern_make_entry (struct Menu *menu, int line, int max_cols, struct Buffer *buf)
 Create a Pattern for the Menu - Implements Menu::make_entry() -.
 
static void free_pattern_menu (struct Menu *menu, void **ptr)
 Free the Pattern Completion menu - Implements Menu::mdata_free() -.
 
static struct Menucreate_pattern_menu (struct MuttWindow *dlg)
 Create the Pattern Completion menu.
 
static int pattern_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -.
 
static int pattern_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -.
 
bool dlg_pattern (char *buf, size_t buflen)
 Show menu to select a Pattern -.
 

Variables

const struct ExpandoRenderData PatternRenderData []
 Callbacks for Pattern Expandos.
 
static const struct Mapping PatternHelp []
 Help Bar for the Pattern selection dialog.
 

Detailed Description

Pattern Selection Dialog.

Authors
  • Pietro Cerutti
  • Richard Russon
  • Tóth János

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 dlg_pattern.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 174 of file dlg_pattern.c.

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

Variable Documentation

◆ PatternRenderData

const struct ExpandoRenderData PatternRenderData
Initial value:
= {
{ -1, -1, NULL, NULL },
}
@ ED_PATTERN
Pattern ED_PAT_ ExpandoDataPattern.
Definition: domain.h:50
long pattern_n_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Pattern: Index number - Implements ExpandoRenderData::get_number() -.
Definition: dlg_pattern.c:124
void pattern_e(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Pattern: pattern expression - Implements ExpandoRenderData::get_string() -.
Definition: dlg_pattern.c:112
void pattern_d(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Pattern: pattern description - Implements ExpandoRenderData::get_string() -.
Definition: dlg_pattern.c:100
@ ED_PAT_DESCRIPTION
PatternEntry.desc.
Definition: private.h:51
@ ED_PAT_EXPRESION
PatternEntry.expr.
Definition: private.h:52
@ ED_PAT_NUMBER
PatternEntry.num.
Definition: private.h:53

Callbacks for Pattern Expandos.

See also
PatternFormatDef, ExpandoDataGlobal, ExpandoDataPattern

Definition at line 85 of file dlg_pattern.c.

◆ 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 88 of file dlg_pattern.c.