NeoMutt  2024-02-01-23-g345d7b
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_pattern.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 "key/lib.h"
#include "menu/lib.h"
#include "format_flags.h"
#include "functions.h"
#include "mutt_logging.h"
#include "muttlib.h"
+ Include dependency graph for dlg_pattern.c:

Go to the source code of this file.

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 -.
 
static void make_pattern_entry (struct Menu *menu, int line, 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

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

Detailed Description

Pattern Selection Dialog.

Authors
  • Pietro Cerutti
  • Richard Russon

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

171{
172 int num_entries = 0, i = 0;
173 struct Buffer *entrybuf = NULL;
174
175 while (Flags[num_entries].tag)
176 num_entries++;
177 /* Add three more hard-coded entries */
178 num_entries += 3;
179 struct PatternEntry *entries = mutt_mem_calloc(num_entries, sizeof(struct PatternEntry));
180
181 struct Menu *menu = dlg->wdata;
183 menu->mdata = entries;
185 menu->max = num_entries;
186
187 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
188 // L10N: Pattern completion menu title
189 sbar_set_title(sbar, _("Patterns"));
190
191 entrybuf = buf_pool_get();
192 while (Flags[i].tag)
193 {
194 entries[i].num = i + 1;
195
196 buf_printf(entrybuf, "~%c", (char) Flags[i].tag);
197 entries[i].tag = mutt_str_dup(buf_string(entrybuf));
198
199 switch (Flags[i].eat_arg)
200 {
201 case EAT_REGEX:
202 /* L10N:
203 Pattern Completion Menu argument type: a regular expression
204 */
205 buf_add_printf(entrybuf, " %s", _("EXPR"));
206 break;
207 case EAT_RANGE:
209 /* L10N:
210 Pattern Completion Menu argument type: a numeric range.
211 Used by ~m, ~n, ~X, ~z.
212 */
213 buf_add_printf(entrybuf, " %s", _("RANGE"));
214 break;
215 case EAT_DATE:
216 /* L10N:
217 Pattern Completion Menu argument type: a date range
218 Used by ~d, ~r.
219 */
220 buf_add_printf(entrybuf, " %s", _("DATERANGE"));
221 break;
222 case EAT_QUERY:
223 /* L10N:
224 Pattern Completion Menu argument type: a query
225 Used by ~I.
226 */
227 buf_add_printf(entrybuf, " %s", _("QUERY"));
228 break;
229 default:
230 break;
231 }
232 entries[i].expr = mutt_str_dup(buf_string(entrybuf));
233 entries[i].desc = mutt_str_dup(_(Flags[i].desc));
234
235 i++;
236 }
237
238 /* Add struct MuttThread patterns manually.
239 * Note we allocated 3 extra slots for these above. */
240
241 /* L10N:
242 Pattern Completion Menu argument type: a nested pattern.
243 Used by ~(), ~<(), ~>().
244 */
245 const char *patternstr = _("PATTERN");
246
247 entries[i].num = i + 1;
248 entries[i].tag = mutt_str_dup("~()");
249 buf_printf(entrybuf, "~(%s)", patternstr);
250 entries[i].expr = mutt_str_dup(buf_string(entrybuf));
251 // L10N: Pattern Completion Menu description for ~()
252 entries[i].desc = mutt_str_dup(_("messages in threads containing messages matching PATTERN"));
253 i++;
254
255 entries[i].num = i + 1;
256 entries[i].tag = mutt_str_dup("~<()");
257 buf_printf(entrybuf, "~<(%s)", patternstr);
258 entries[i].expr = mutt_str_dup(buf_string(entrybuf));
259 // L10N: Pattern Completion Menu description for ~<()
260 entries[i].desc = mutt_str_dup(_("messages whose immediate parent matches PATTERN"));
261 i++;
262
263 entries[i].num = i + 1;
264 entries[i].tag = mutt_str_dup("~>()");
265 buf_printf(entrybuf, "~>(%s)", patternstr);
266 entries[i].expr = mutt_str_dup(buf_string(entrybuf));
267 // L10N: Pattern Completion Menu description for ~>()
268 entries[i].desc = mutt_str_dup(_("messages having an immediate child matching PATTERN"));
269
270 buf_pool_release(&entrybuf);
271
272 return menu;
273}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:178
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:221
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:97
static void make_pattern_entry(struct Menu *menu, int line, struct Buffer *buf)
Create a Pattern for the Menu - Implements Menu::make_entry() -.
Definition: dlg_pattern.c:138
static void free_pattern_menu(struct Menu *menu, void **ptr)
Free the Pattern Completion menu - Implements Menu::mdata_free() -.
Definition: dlg_pattern.c:151
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: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:533
@ 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:54
@ EAT_MESSAGE_RANGE
Process a message number (range)
Definition: private.h:55
@ EAT_DATE
Process a date (range)
Definition: private.h:53
@ EAT_QUERY
Process a query string.
Definition: private.h:56
@ EAT_REGEX
Process a regex.
Definition: private.h:52
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:69
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:149
void * mdata
Private data.
Definition: lib.h:135
void(* make_entry)(struct Menu *menu, int line, struct Buffer *buf)
Definition: lib.h:94
int max
Number of entries in the menu.
Definition: lib.h:71
void * wdata
Private data.
Definition: mutt_window.h:145
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

◆ 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.