NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
tagging.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdbool.h>
31#include "mutt/lib.h"
32#include "config/lib.h"
33#include "core/lib.h"
34#include "gui/lib.h"
35#include "lib.h"
36#include "color/color.h"
37#include "opcodes.h"
38
43static void menu_set_prefix(struct Menu *menu)
44{
45 const bool c_auto_tag = cs_subset_bool(menu->sub, "auto_tag");
46 if ((menu->num_tagged != 0) && c_auto_tag)
47 menu->tag_prefix = true;
48
49 mutt_debug(LL_DEBUG1, "tag_prefix = %d\n", menu->tag_prefix);
50
51 // Don't overwrite error messages
52 const char *msg_text = msgwin_get_text();
53 if (msg_text && !mutt_str_equal(msg_text, "tag-"))
54 return;
55
56 if (menu->tag_prefix)
58 else
60}
61
68static int op_end_cond(struct Menu *menu, int op)
69{
70 menu->tag_prefix = false;
71 menu_set_prefix(menu);
72 return FR_SUCCESS;
73}
74
81static int op_tag(struct Menu *menu, int op)
82{
83 const bool c_auto_tag = cs_subset_bool(menu->sub, "auto_tag");
84 int rc = FR_SUCCESS;
85
86 if ((menu->num_tagged != 0) && c_auto_tag)
87 menu->tag_prefix = true;
88
89 if (!menu->tag)
90 {
91 mutt_error(_("Tagging is not supported"));
92 return FR_ERROR;
93 }
94
95 if (menu->tag_prefix && !c_auto_tag)
96 {
97 for (int i = 0; i < menu->max; i++)
98 menu->num_tagged += menu->tag(menu, i, 0);
99
100 menu->redraw |= MENU_REDRAW_INDEX;
101 }
102 else if (menu->max != 0)
103 {
104 int num = menu->tag(menu, menu->current, -1);
105 menu->num_tagged += num;
106
107 const bool c_resolve = cs_subset_bool(menu->sub, "resolve");
108 if ((num != 0) && c_resolve && (menu->current < (menu->max - 1)))
109 {
110 menu_set_index(menu, menu->current + 1);
111 }
112 else
113 {
115 }
116 }
117 else
118 {
119 mutt_error(_("No entries"));
120 rc = FR_ERROR;
121 }
122
123 menu->tag_prefix = ((menu->num_tagged != 0) && c_auto_tag);
124
125 /* give visual indication that the next command is a tag- command */
126 if (menu->tag_prefix)
128
129 menu->win->actions |= WA_REPAINT;
130 return rc;
131}
132
139static int op_tag_prefix(struct Menu *menu, int op)
140{
141 if (menu->tag_prefix)
142 {
143 menu->tag_prefix = false;
144 menu_set_prefix(menu);
145 }
146 else if (menu->num_tagged == 0)
147 {
148 mutt_warning(_("No tagged entries"));
149 }
150 else
151 {
152 menu->tag_prefix = true;
153 menu_set_prefix(menu);
154 }
155
156 return FR_SUCCESS;
157}
158
165static int op_tag_prefix_cond(struct Menu *menu, int op)
166{
167 if (menu->tag_prefix)
168 {
169 menu->tag_prefix = false;
170 }
171 else if (menu->num_tagged == 0)
172 {
174 mutt_debug(LL_DEBUG1, "nothing to do\n");
175 }
176 else
177 {
178 menu->tag_prefix = true;
179 }
180
181 menu_set_prefix(menu);
182 return FR_SUCCESS;
183}
184
190static int menu_abort(struct Menu *menu)
191{
192 menu->tag_prefix = false;
193 menu_set_prefix(menu);
194 return FR_SUCCESS;
195}
196
202static int menu_timeout(struct Menu *menu)
203{
204 menu_set_prefix(menu);
205 return FR_SUCCESS;
206}
207
213static int menu_other(struct Menu *menu)
214{
215 menu->tag_prefix = false;
216 menu_set_prefix(menu);
217 return FR_SUCCESS;
218}
219
224{
225 struct Menu *menu = win->wdata;
226
227 switch (op)
228 {
229 case OP_END_COND:
230 return op_end_cond(menu, op);
231 case OP_TAG:
232 return op_tag(menu, op);
233 case OP_TAG_PREFIX:
234 return op_tag_prefix(menu, op);
235 case OP_TAG_PREFIX_COND:
236 return op_tag_prefix_cond(menu, op);
237 case OP_ABORT:
238 return menu_abort(menu);
239 case OP_TIMEOUT:
240 return menu_timeout(menu);
241 default:
242 return menu_other(menu);
243 }
244}
Color and attribute parsing.
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:57
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition: curs_lib.c:573
@ FR_SUCCESS
Valid function - successfully performed.
Definition: dispatcher.h:39
@ FR_ERROR
Valid function - error occurred.
Definition: dispatcher.h:38
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:223
#define mutt_warning(...)
Definition: logging2.h:88
#define mutt_error(...)
Definition: logging2.h:90
#define mutt_debug(LEVEL,...)
Definition: logging2.h:87
Convenience wrapper for the gui headers.
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
#define MENU_REDRAW_INDEX
Redraw the index.
Definition: lib.h:57
#define MENU_REDRAW_CURRENT
Redraw the current line of the menu.
Definition: lib.h:59
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:169
void msgwin_set_text(enum ColorId cid, const char *text)
Set the text for the Message Window.
Definition: msgwin.c:234
const char * msgwin_get_text(void)
Get the text from the Message Window.
Definition: msgwin.c:217
void msgwin_clear_text(void)
Clear the text in the Message Window.
Definition: msgwin.c:250
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:798
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
All user-callable functions.
#define OP_TIMEOUT
Definition: opcodes.h:32
#define OP_ABORT
Definition: opcodes.h:33
Key value store.
Definition: lib.h:70
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
int current
Current entry.
Definition: lib.h:71
int num_tagged
Number of tagged entries.
Definition: lib.h:84
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:73
int(* tag)(struct Menu *menu, int sel, int act)
Definition: lib.h:122
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:78
bool tag_prefix
User has pressed <tag-prefix>
Definition: lib.h:76
int max
Number of entries in the menu.
Definition: lib.h:72
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:213
static int menu_abort(struct Menu *menu)
User aborted an operation.
Definition: tagging.c:190
static int op_tag(struct Menu *menu, int op)
Tag the current entry.
Definition: tagging.c:81
static int op_end_cond(struct Menu *menu, int op)
End of conditional execution (noop)
Definition: tagging.c:68
static void menu_set_prefix(struct Menu *menu)
Set tag_prefix on $auto_tag.
Definition: tagging.c:43
static int op_tag_prefix_cond(struct Menu *menu, int op)
Apply next function ONLY to tagged messages.
Definition: tagging.c:165
static int op_tag_prefix(struct Menu *menu, int op)
Apply next function to tagged messages.
Definition: tagging.c:139
static int menu_timeout(struct Menu *menu)
Timeout waiting for a keypress.
Definition: tagging.c:202