NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
tagging.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stdbool.h>
31#include <stddef.h>
32#include "mutt/lib.h"
33#include "config/lib.h"
34#include "core/lib.h"
35#include "gui/lib.h"
36#include "lib.h"
37#include "color/lib.h"
38#include "key/lib.h"
39
44static void menu_set_prefix(struct Menu *menu)
45{
46 const bool c_auto_tag = cs_subset_bool(menu->sub, "auto_tag");
47 if ((menu->num_tagged != 0) && c_auto_tag)
48 menu->tag_prefix = true;
49
50 mutt_debug(LL_DEBUG1, "tag_prefix = %d\n", menu->tag_prefix);
51
52 // Don't overwrite error messages
53 const char *msg_text = msgwin_get_text(NULL);
54 if (msg_text && (msg_text[0] != '\0') && !mutt_str_equal(msg_text, "tag-"))
55 return;
56
57 if (menu->tag_prefix)
58 {
59 msgwin_set_text(NULL, "tag-", MT_COLOR_NORMAL);
60 }
61 else
62 {
64 }
65}
66
73static int op_end_cond(struct Menu *menu, int op)
74{
75 menu->tag_prefix = false;
76 menu_set_prefix(menu);
77 return FR_SUCCESS;
78}
79
87static int op_tag(struct Menu *menu, int op, int count)
88{
89 const bool c_auto_tag = cs_subset_bool(menu->sub, "auto_tag");
90 int rc = FR_SUCCESS;
91
92 if ((menu->num_tagged != 0) && c_auto_tag)
93 menu->tag_prefix = true;
94
95 if (!menu->tag)
96 {
97 mutt_error(_("Tagging is not supported"));
98 return FR_ERROR;
99 }
100
101 if (menu->tag_prefix && !c_auto_tag)
102 {
103 for (int i = 0; i < menu->max; i++)
104 menu->num_tagged += menu->tag(menu, i, 0);
105
106 menu->redraw |= MENU_REDRAW_INDEX;
107 }
108 else if (menu->max != 0)
109 {
110 int tag_count = MAX(count, 1);
111 for (int i = 0; (i < tag_count) && ((menu->current + i) < menu->max); i++)
112 {
113 int num = menu->tag(menu, menu->current + i, -1);
114 menu->num_tagged += num;
115 }
116
117 const bool c_resolve = cs_subset_bool(menu->sub, "resolve");
118 if (c_resolve)
119 {
120 int next_index = menu->current + tag_count;
121 if (next_index >= menu->max)
122 next_index = menu->max - 1;
123 menu_set_index(menu, next_index);
124 menu->redraw |= MENU_REDRAW_INDEX;
125 }
126 else
127 {
128 menu->redraw |= MENU_REDRAW_INDEX;
129 }
130 }
131 else
132 {
133 mutt_error(_("No entries"));
134 rc = FR_ERROR;
135 }
136
137 menu->tag_prefix = ((menu->num_tagged != 0) && c_auto_tag);
138
139 /* give visual indication that the next command is a tag- command */
140 if (menu->tag_prefix)
141 {
142 msgwin_set_text(NULL, "tag-", MT_COLOR_NORMAL);
143 }
144
145 menu->win->actions |= WA_REPAINT;
146 return rc;
147}
148
155static int op_tag_prefix(struct Menu *menu, int op)
156{
157 if (menu->tag_prefix)
158 {
159 menu->tag_prefix = false;
160 menu_set_prefix(menu);
161 }
162 else if (menu->num_tagged == 0)
163 {
164 mutt_warning(_("No tagged entries"));
165 }
166 else
167 {
168 menu->tag_prefix = true;
169 menu_set_prefix(menu);
170 }
171
172 return FR_SUCCESS;
173}
174
181static int op_tag_prefix_cond(struct Menu *menu, int op)
182{
183 if (menu->tag_prefix)
184 {
185 menu->tag_prefix = false;
186 }
187 else if (menu->num_tagged == 0)
188 {
190 mutt_debug(LL_DEBUG1, "nothing to do\n");
191 }
192 else
193 {
194 menu->tag_prefix = true;
195 }
196
197 menu_set_prefix(menu);
198 return FR_SUCCESS;
199}
200
206static int menu_abort(struct Menu *menu)
207{
208 menu->tag_prefix = false;
209 menu_set_prefix(menu);
210 return FR_SUCCESS;
211}
212
218static int menu_timeout(struct Menu *menu)
219{
220 menu_set_prefix(menu);
221 return FR_SUCCESS;
222}
223
229static int menu_other(struct Menu *menu)
230{
231 menu->tag_prefix = false;
232 menu_set_prefix(menu);
233 return FR_SUCCESS;
234}
235
239int menu_tagging_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
240{
241 if (!win || !win->wdata || !event)
242 {
244 return FR_ERROR;
245 }
246
247 struct Menu *menu = win->wdata;
248 const int op = event->op;
249 int rc = FR_UNKNOWN;
250
251 switch (op)
252 {
253 case OP_END_COND:
254 rc = op_end_cond(menu, op);
255 break;
256 case OP_TAG:
257 rc = op_tag(menu, op, event->count);
258 break;
259 case OP_TAG_PREFIX:
260 rc = op_tag_prefix(menu, op);
261 break;
262 case OP_TAG_PREFIX_COND:
263 rc = op_tag_prefix_cond(menu, op);
264 break;
265 case OP_ABORT:
266 rc = menu_abort(menu);
267 break;
268 case OP_TIMEOUT:
269 rc = menu_timeout(menu);
270 break;
271 default:
272 rc = menu_other(menu);
273 break;
274 }
275
277 return rc;
278}
Color and attribute parsing.
@ MT_COLOR_NORMAL
Plain text.
Definition color.h:53
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
void dispatcher_flush_on_error(int rv)
Flush pending keys after a dispatch error.
Definition dispatcher.c:65
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
@ FR_UNKNOWN
Unknown function.
Definition dispatcher.h:34
@ FR_ERROR
Valid function - error occurred.
Definition dispatcher.h:39
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition get.c:185
int menu_tagging_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition tagging.c:239
#define mutt_warning(...)
Definition logging2.h:92
#define mutt_error(...)
Definition logging2.h:94
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
Convenience wrapper for the gui headers.
Manage keymappings.
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
#define MAX(a, b)
Return the maximum of two values.
Definition memory.h:38
GUI present the user with a selectable list.
@ MENU_REDRAW_INDEX
Redraw the index.
Definition lib.h:61
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition menu.c:169
void msgwin_clear_text(struct MuttWindow *win)
Clear the text in the Message Window.
Definition msgwin.c:554
void msgwin_set_text(struct MuttWindow *win, const char *text, enum ColorId color)
Set the text for the Message Window.
Definition msgwin.c:500
const char * msgwin_get_text(struct MuttWindow *win)
Get the text from the Message Window.
Definition msgwin.c:413
Convenience wrapper for the library headers.
#define _(a)
Definition message.h:28
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
@ WA_REPAINT
Redraw the contents of the Window.
#define OP_TIMEOUT
1 second with no events
Definition opcodes.h:35
#define OP_ABORT
$abort_key pressed (Ctrl-G)
Definition opcodes.h:36
An event such as a keypress.
Definition get.h:75
int count
Optional count prefix, e.g. 3 for 3j
Definition get.h:78
Definition lib.h:86
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:94
int current
Current entry.
Definition lib.h:87
int num_tagged
Number of tagged entries.
Definition lib.h:101
MenuRedrawFlags redraw
When to redraw the screen.
Definition lib.h:89
int(* tag)(struct Menu *menu, int sel, int act)
Definition lib.h:139
struct ConfigSubset * sub
Inherited config items.
Definition lib.h:95
bool tag_prefix
User has pressed <tag-prefix>
Definition lib.h:92
int max
Number of entries in the menu.
Definition lib.h:88
void * wdata
Private data.
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
static int menu_other(struct Menu *menu)
Some non-tagging operation occurred.
Definition tagging.c:229
static int menu_abort(struct Menu *menu)
User aborted an operation.
Definition tagging.c:206
static int op_end_cond(struct Menu *menu, int op)
End of conditional execution (noop)
Definition tagging.c:73
static void menu_set_prefix(struct Menu *menu)
Set tag_prefix on $auto_tag.
Definition tagging.c:44
static int op_tag_prefix_cond(struct Menu *menu, int op)
Apply next function ONLY to tagged messages.
Definition tagging.c:181
static int op_tag(struct Menu *menu, int op, int count)
Tag the current entry.
Definition tagging.c:87
static int op_tag_prefix(struct Menu *menu, int op)
Apply next function to tagged messages.
Definition tagging.c:155
static int menu_timeout(struct Menu *menu)
Timeout waiting for a keypress.
Definition tagging.c:218