diff --git a/OPS.NOTMUCH b/OPS.NOTMUCH index c69691c..a50c453 100644 --- a/OPS.NOTMUCH +++ b/OPS.NOTMUCH @@ -2,3 +2,4 @@ OP_MAIN_CHANGE_VFOLDER "open a different virtual folder" OP_MAIN_VFOLDER_FROM_QUERY "generate virtual folder from query" OP_MAIN_MODIFY_LABELS "modify (notmuch) tags" OP_MAIN_MODIFY_LABELS_THEN_HIDE "modify labeld and then hide message" +OP_MAIN_BROWSE_LABELS "browse (notmuch) tags" diff --git a/browser.c b/browser.c index 39b839c..f36c570 100644 --- a/browser.c +++ b/browser.c @@ -493,6 +493,16 @@ static int examine_vfolders (MUTTMENU *menu, struct browser_state *state) browser_sort (state); return 0; } + +static int examine_tags (MUTTMENU *menu, struct browser_state *state, char ***fnames, int *count) +{ + mutt_buffy_check (0); + + init_state (state, menu); + nm_add_tags(menu, state, add_folder); + browser_sort (state); + return 0; +} #endif static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state) @@ -707,7 +717,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num #endif } #ifdef USE_NOTMUCH - else if (!(flags & M_SEL_VFOLDER)) + else if (!(flags & (M_SEL_VFOLDER|M_SEL_NOTMUCH_TAGS) )) #else else #endif @@ -742,6 +752,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num if (flags & M_SEL_VFOLDER) { if (examine_vfolders (NULL, &state) == -1) goto bail; + } else if (flags & M_SEL_NOTMUCH_TAGS) { + examine_tags (NULL, &state, files, numfiles); } else #endif if (buffy) diff --git a/curs_main.c b/curs_main.c index 153eedf..bd28ac8 100644 --- a/curs_main.c +++ b/curs_main.c @@ -1253,6 +1253,7 @@ int mutt_index_menu (void) break; case OP_MAIN_CHANGE_VFOLDER: + case OP_MAIN_BROWSE_LABELS: #endif case OP_SIDEBAR_OPEN: case OP_MAIN_CHANGE_FOLDER: @@ -1270,6 +1271,8 @@ int mutt_index_menu (void) #ifdef USE_NOTMUCH else if (op == OP_MAIN_CHANGE_VFOLDER) cp = _("Open virtual folder"); + else if (op == OP_MAIN_BROWSE_LABELS) + cp = _("Edit available labels"); #endif else cp = _("Open mailbox"); @@ -1290,9 +1293,41 @@ int mutt_index_menu (void) { mutt_buffy (buf, sizeof (buf)); #ifdef USE_NOTMUCH +/* XXXXXXXXXXXXXXXXXXXX */ + // printf ("curs_main 1 '%s'\n\r", buf); if (op == OP_MAIN_CHANGE_VFOLDER) mutt_enter_vfolder (cp, buf, sizeof (buf), &menu->redraw, 1); - else + else if (op == OP_MAIN_BROWSE_LABELS) { + // printf ("curs_main 2\n\r"); + + /* + const char *prompt, char *buf, size_t blen, + int *redraw, int buffy, int multiple, + char ***files, int *numfiles, int flags + */ + nm_browse_tags_init(Context); + + if (tag && !option (OPTAUTOTAG)) + { + // printf ("Count: %d\n\r", Context->vcount); + for (j = 0; j < Context->vcount; j++) { + if (Context->hdrs[Context->v2r[j]]->tagged) { + nm_browse_tags (Context->hdrs[Context->v2r[j]]); + // printf ("...\n\r"); + } + } + } + else + { + nm_browse_tags (CURHDR); + } + _mutt_enter_fname( + cp,buf,sizeof(buf), + &menu->redraw,1,0, + NULL,NULL,M_SEL_NOTMUCH_TAGS|M_SEL_MULTI); + + nm_browse_tags_finish(Context); + } else #endif if ( op == OP_SIDEBAR_OPEN ) { diff --git a/functions.h b/functions.h index c27d9f1..7e6d46f 100644 --- a/functions.h +++ b/functions.h @@ -171,8 +171,9 @@ const struct binding_t OpMain[] = { /* map: index */ #ifdef USE_NOTMUCH { "change-vfolder", OP_MAIN_CHANGE_VFOLDER, "X" }, { "vfolder-from-query", OP_MAIN_VFOLDER_FROM_QUERY, "\033X" }, - { "modify-labels", OP_MAIN_MODIFY_LABELS, "`" }, + { "modify-labels", OP_MAIN_MODIFY_LABELS, NULL }, { "modify-labels-then-hide", OP_MAIN_MODIFY_LABELS_THEN_HIDE, NULL }, + { "browse-labels", OP_MAIN_BROWSE_LABELS, "`" }, #endif { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL }, { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL }, @@ -287,8 +288,9 @@ const struct binding_t OpPager[] = { /* map: pager */ #ifdef USE_NOTMUCH { "change-vfolder", OP_MAIN_CHANGE_VFOLDER, "X" }, { "vfolder-from-query", OP_MAIN_VFOLDER_FROM_QUERY, "\033X" }, - { "modify-labels", OP_MAIN_MODIFY_LABELS, "`" }, + { "modify-labels", OP_MAIN_MODIFY_LABELS, NULL }, { "modify-labels-then-hide", OP_MAIN_MODIFY_LABELS_THEN_HIDE, NULL }, + { "browse-labels", OP_MAIN_BROWSE_LABELS, "`" }, #endif { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL }, { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL }, diff --git a/mutt.h b/mutt.h index e94e228..29d14d2 100644 --- a/mutt.h +++ b/mutt.h @@ -304,6 +304,7 @@ enum #define M_SEL_MULTI (1<<1) #define M_SEL_FOLDER (1<<2) #define M_SEL_VFOLDER (1<<3) +#define M_SEL_NOTMUCH_TAGS (1<<4) /* flags for parse_spam_list */ #define M_SPAM 1 diff --git a/mutt_notmuch.c b/mutt_notmuch.c index 9ede705..243a30d 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -1536,3 +1536,110 @@ done: ctx->msgcount > oldmsgcount ? M_NEW_MAIL : new_flags ? M_FLAGS : 0; } + +struct browse_tags { + notmuch_database_t *db; + HASH *hash; + char **tags; + int ntags, tags_size; +} browse_tags; + + +int +nm_browse_tags_init (CONTEXT *ctx) +{ + struct nm_ctxdata *data; + + if ( ! (data = get_ctxdata(ctx)) ) { + // printf ("error, no data?\n\r"); + return -1; + } + browse_tags.db = NULL; + + // printf ("browse 1\n\r"); + if ( ! (browse_tags.db = get_db(data, TRUE)) ) { + // printf ("error, no db\n\r"); + return -1; + } + browse_tags.hash = hash_create(50, 0); + browse_tags.ntags = 0; + browse_tags.tags_size = 0; + browse_tags.tags = NULL; + // printf ("browse 2\n\r"); + return 0; +} + +int +nm_add_tags (MUTTMENU *menu, struct browser_state *state, void(*add_folder)(MUTTMENU *, struct browser_state *, const char *, const char *, const struct stat *, unsigned int, unsigned int all)) +{ + int i; + + // printf ("browse 3\n\r"); + for (i=0; i