NeoMutt  2024-04-25-85-g27bab4
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
tagging.c
Go to the documentation of this file.
1
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 && !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
86static int op_tag(struct Menu *menu, int op)
87{
88 const bool c_auto_tag = cs_subset_bool(menu->sub, "auto_tag");
89 int rc = FR_SUCCESS;
90
91 if ((menu->num_tagged != 0) && c_auto_tag)
92 menu->tag_prefix = true;
93
94 if (!menu->tag)
95 {
96 mutt_error(_("Tagging is not supported"));
97 return FR_ERROR;
98 }
99
100 if (menu->tag_prefix && !c_auto_tag)
101 {
102 for (int i = 0; i < menu->max; i++)
103 menu->num_tagged += menu->tag(menu, i, 0);
104
105 menu->redraw |= MENU_REDRAW_INDEX;
106 }
107 else if (menu->max != 0)
108 {
109 int num = menu->tag(menu, menu->current, -1);
110 menu->num_tagged += num;
111
112 const bool c_resolve = cs_subset_bool(menu->sub, "resolve");
113 if ((num != 0) && c_resolve && (menu->current < (menu->max - 1)))
114 {
115 menu_set_index(menu, menu->current + 1);
116 }
117 else
118 {
120 }
121 }
122 else
123 {
124 mutt_error(_("No entries"));
125 rc = FR_ERROR;
126 }
127
128 menu->tag_prefix = ((menu->num_tagged != 0) && c_auto_tag);
129
130 /* give visual indication that the next command is a tag- command */
131 if (menu->tag_prefix)
132 {
133 msgwin_set_text(NULL, "tag-", MT_COLOR_NORMAL);
134 }
135
136 menu->win->actions |= WA_REPAINT;
137 return rc;
138}
139
146static int op_tag_prefix(struct Menu *menu, int op)
147{
148 if (menu->tag_prefix)
149 {
150 menu->tag_prefix = false;
151 menu_set_prefix(menu);
152 }
153 else if (menu->num_tagged == 0)
154 {
155 mutt_warning(_("No tagged entries"));
156 }
157 else
158 {
159 menu->tag_prefix = true;
160 menu_set_prefix(menu);
161 }
162
163 return FR_SUCCESS;
164}
165
172static int op_tag_prefix_cond(struct Menu *menu, int op)
173{
174 if (menu->tag_prefix)
175 {
176 menu->tag_prefix = false;
177 }
178 else if (menu->num_tagged == 0)
179 {
181 mutt_debug(LL_DEBUG1, "nothing to do\n");
182 }
183 else
184 {
185 menu->tag_prefix = true;
186 }
187
188 menu_set_prefix(menu);
189 return FR_SUCCESS;
190}
191
197static int menu_abort(struct Menu *menu)
198{
199 menu->tag_prefix = false;
200 menu_set_prefix(menu);
201 return FR_SUCCESS;
202}
203
209static int menu_timeout(struct Menu *menu)
210{
211 menu_set_prefix(menu);
212 return FR_SUCCESS;
213}
214
220static int menu_other(struct Menu *menu)
221{
222 menu->tag_prefix = false;
223 menu_set_prefix(menu);
224 return FR_SUCCESS;
225}
226
231{
232 struct Menu *menu = win->wdata;
233
234 switch (op)
235 {
236 case OP_END_COND:
237 return op_end_cond(menu, op);
238 case OP_TAG:
239 return op_tag(menu, op);
240 case OP_TAG_PREFIX:
241 return op_tag_prefix(menu, op);
242 case OP_TAG_PREFIX_COND:
243 return op_tag_prefix_cond(menu, op);
244 case OP_ABORT:
245 return menu_abort(menu);
246 case OP_TIMEOUT:
247 return menu_timeout(menu);
248 default:
249 return menu_other(menu);
250 }
251}
Color and attribute parsing.
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:59
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.
@ FR_SUCCESS
Valid function - successfully performed.
Definition: dispatcher.h:39
@ FR_ERROR
Valid function - error occurred.
Definition: dispatcher.h:38
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition: get.c:166
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:230
#define mutt_warning(...)
Definition: logging2.h:90
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
Convenience wrapper for the gui headers.
Manage keymappings.
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
#define MENU_REDRAW_INDEX
Redraw the index.
Definition: lib.h:56
#define MENU_REDRAW_CURRENT
Redraw the current line of the menu.
Definition: lib.h:58
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:174
void msgwin_clear_text(struct MuttWindow *win)
Clear the text in the Message Window.
Definition: msgwin.c:519
void msgwin_set_text(struct MuttWindow *win, const char *text, enum ColorId color)
Set the text for the Message Window.
Definition: msgwin.c:484
const char * msgwin_get_text(struct MuttWindow *win)
Get the text from the Message Window.
Definition: msgwin.c:401
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:660
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
#define OP_TIMEOUT
1 second with no events
Definition: opcodes.h:36
#define OP_ABORT
$abort_key pressed (Ctrl-G)
Definition: opcodes.h:37
Key value store.
Definition: lib.h:79
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:86
int current
Current entry.
Definition: lib.h:80
int num_tagged
Number of tagged entries.
Definition: lib.h:93
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:82
int(* tag)(struct Menu *menu, int sel, int act)
Definition: lib.h:131
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:87
bool tag_prefix
User has pressed <tag-prefix>
Definition: lib.h:85
int max
Number of entries in the menu.
Definition: lib.h:81
void * wdata
Private data.
Definition: mutt_window.h:145
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
static int menu_other(struct Menu *menu)
Some non-tagging operation occurred.
Definition: tagging.c:220
static int menu_abort(struct Menu *menu)
User aborted an operation.
Definition: tagging.c:197
static int op_tag(struct Menu *menu, int op)
Tag the current entry.
Definition: tagging.c:86
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:172
static int op_tag_prefix(struct Menu *menu, int op)
Apply next function to tagged messages.
Definition: tagging.c:146
static int menu_timeout(struct Menu *menu)
Timeout waiting for a keypress.
Definition: tagging.c:209