#include "color.h"
#include "context.h"
#include "globals.h"
-#include "keymap.h"
#include "mutt_commands.h"
#include "mutt_curses.h"
-#include "mutt_menu.h"
#include "options.h"
#include "pattern.h"
#ifdef USE_SLANG_CURSES
colors_clear(c);
defs_free(c);
quotes_free(c);
+ notify_free(&c->notify);
FREE(ptr);
}
struct Colors *mutt_colors_new(void)
{
struct Colors *c = mutt_mem_calloc(1, sizeof(*c));
+ c->notify = notify_new(c, NT_COLOR);
quotes_init(c);
defs_init(c);
start_color();
#endif
+ notify_set_parent(c->notify, NeoMutt->notify);
return c;
}
if (mutt_str_strcmp(buf->data, "*") == 0)
{
colors_clear(c);
+ struct EventColor ec = { false }; // Color reset/removed
+ notify_send(c->notify, NT_COLOR, MT_COLOR_MAX, (intptr_t) &ec);
return MUTT_CMD_SUCCESS;
}
// Simple colours
c->defs[object] = A_NORMAL;
+ struct EventColor ec = { false }; // Color reset/removed
+ notify_send(c->notify, NT_COLOR, object, (intptr_t) &ec);
return MUTT_CMD_SUCCESS;
}
else if (object == MT_COLOR_STATUS)
changed |= do_uncolor(c, buf, s, &c->status_list, uncolor);
- bool is_index = ((object == MT_COLOR_INDEX) || (object == MT_COLOR_INDEX_AUTHOR) ||
- (object == MT_COLOR_INDEX_FLAGS) || (object == MT_COLOR_INDEX_SUBJECT) ||
- (object == MT_COLOR_INDEX_TAG));
-
- if (changed && is_index && !OptNoCurses)
+ if (changed)
{
- mutt_menu_set_redraw_full(MENU_MAIN);
- /* force re-caching of index colors */
- for (int i = 0; Context && i < Context->mailbox->msg_count; i++)
- Context->mailbox->emails[i]->pair = 0;
+ struct EventColor ec = { false }; // Color reset/removed
+ notify_send(c->notify, NT_COLOR, object, (intptr_t) &ec);
}
return MUTT_CMD_SUCCESS;
else if (object == MT_COLOR_INDEX)
{
rc = add_pattern(c, &c->index_list, buf->data, true, fg, bg, attr, err, true, match);
- mutt_menu_set_redraw_full(MENU_MAIN);
}
else if (object == MT_COLOR_INDEX_AUTHOR)
{
rc = add_pattern(c, &c->index_author_list, buf->data, true, fg, bg, attr, err, true, match);
- mutt_menu_set_redraw_full(MENU_MAIN);
}
else if (object == MT_COLOR_INDEX_FLAGS)
{
rc = add_pattern(c, &c->index_flags_list, buf->data, true, fg, bg, attr, err, true, match);
- mutt_menu_set_redraw_full(MENU_MAIN);
}
else if (object == MT_COLOR_INDEX_SUBJECT)
{
rc = add_pattern(c, &c->index_subject_list, buf->data, true, fg, bg, attr, err, true, match);
- mutt_menu_set_redraw_full(MENU_MAIN);
}
else if (object == MT_COLOR_INDEX_TAG)
{
rc = add_pattern(c, &c->index_tag_list, buf->data, true, fg, bg, attr, err, true, match);
- mutt_menu_set_redraw_full(MENU_MAIN);
}
else if (object == MT_COLOR_QUOTED)
{
else
{
c->defs[object] = fgbgattr_to_color(c, fg, bg, attr);
- if (object > MT_COLOR_INDEX_AUTHOR)
- mutt_menu_set_redraw_full(MENU_MAIN);
rc = MUTT_CMD_SUCCESS;
}
+ if (rc == MUTT_CMD_SUCCESS)
+ {
+ struct EventColor ec = { true }; // Color set/added
+ notify_send(c->notify, NT_COLOR, object, (intptr_t) &ec);
+ }
+
return rc;
}
notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_hist_observer, 0);
notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_log_observer, 0);
- notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_menu_observer, 0);
+ notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_menu_config_observer, 0);
notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_reply_observer, 0);
+ notify_observer_add(Colors->notify, NT_COLOR, 0, mutt_menu_color_observer, 0);
if (sendflags & SEND_POSTPONED)
{
}
/**
- * mutt_menu_observer - Listen for config changes affecting the menu - Implements ::observer_t()
+ * mutt_menu_color_observer - Listen for colour changes affecting the menu - Implements ::observer_t()
*/
-int mutt_menu_observer(struct NotifyCallback *nc)
+int mutt_menu_color_observer(struct NotifyCallback *nc)
+{
+ if ((!nc) || (nc->event_type != NT_COLOR))
+ return -1;
+
+ int s = nc->event_subtype;
+
+ bool simple = (s == MT_COLOR_INDEX_COLLAPSED) || (s == MT_COLOR_INDEX_DATE) ||
+ (s == MT_COLOR_INDEX_LABEL) || (s == MT_COLOR_INDEX_NUMBER) ||
+ (s == MT_COLOR_INDEX_SIZE) || (s == MT_COLOR_INDEX_TAGS);
+ bool lists = (s == MT_COLOR_ATTACH_HEADERS) || (s == MT_COLOR_BODY) ||
+ (s == MT_COLOR_HEADER) || (s == MT_COLOR_INDEX) ||
+ (s == MT_COLOR_INDEX_AUTHOR) || (s == MT_COLOR_INDEX_FLAGS) ||
+ (s == MT_COLOR_INDEX_SUBJECT) || (s == MT_COLOR_INDEX_TAG);
+
+ // The changes aren't relevant to the index menu
+ if (!simple && !lists)
+ return 0;
+
+ struct EventColor *ec = (struct EventColor *) nc->event;
+
+ // Colour deleted from a list
+ if (!ec->set && lists && Context && Context->mailbox)
+ {
+ // Force re-caching of index colors
+ for (int i = 0; i < Context->mailbox->msg_count; i++)
+ Context->mailbox->emails[i]->pair = 0;
+ }
+
+ mutt_menu_set_redraw_full(MENU_MAIN);
+ return 0;
+}
+
+/**
+ * mutt_menu_config_observer - Listen for config changes affecting the menu - Implements ::observer_t()
+ */
+int mutt_menu_config_observer(struct NotifyCallback *nc)
{
if (!nc)
return -1;