From: Mehdi Abaakouk Date: Wed, 20 Sep 2017 12:43:48 +0000 (+0200) Subject: tags: move tags_editor and tags_commit to mx X-Git-Tag: neomutt-20171006~8^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=06b54b8b0113be855020f0f7f0cc83170c2a687f;p=neomutt tags: move tags_editor and tags_commit to mx This methods handles the run of dedicated methods on the mailbox, and not the tags list manipulation. It makes more sense to have it in mx.c like other methods with the same purpose. --- diff --git a/curs_main.c b/curs_main.c index d33d3ded7..9298b9e29 100644 --- a/curs_main.c +++ b/curs_main.c @@ -1857,16 +1857,16 @@ int mutt_index_menu(void) case OP_MAIN_MODIFY_TAGS: case OP_MAIN_MODIFY_TAGS_THEN_HIDE: { - if (!Context || ((Context->magic != MUTT_NOTMUCH) && (Context->magic != MUTT_IMAP))) + if (!Context || !mx_tags_is_supported(Context)) { - mutt_message(_("No virtual folder, aborting.")); + mutt_message(_("Folder doesn't support tagging, aborting.")); break; } CHECK_MSGCOUNT; CHECK_VISIBLE; CHECK_READONLY; - rc = driver_tags_editor(Context, tag ? NULL : driver_tags_get_with_hidden(CURHDR), buf, sizeof(buf)); + rc = mx_tags_editor(Context, tag ? NULL : driver_tags_get_with_hidden(CURHDR), buf, sizeof(buf)); if (rc < 0) break; else if (rc == 0) @@ -1897,7 +1897,7 @@ int mutt_index_menu(void) { if (!Context->quiet) mutt_progress_update(&progress, ++px, -1); - driver_tags_commit(Context, Context->hdrs[Context->v2r[j]], buf); + mx_tags_commit(Context, Context->hdrs[Context->v2r[j]], buf); if (op == OP_MAIN_MODIFY_TAGS_THEN_HIDE) { bool still_queried = false; @@ -1919,7 +1919,7 @@ int mutt_index_menu(void) } else { - if (driver_tags_commit(Context, CURHDR, buf)) + if (mx_tags_commit(Context, CURHDR, buf)) { mutt_message(_("Failed to modify tags, aborting.")); break; diff --git a/mutt_tags.c b/mutt_tags.c index 4fc60a047..d6957f585 100644 --- a/mutt_tags.c +++ b/mutt_tags.c @@ -22,7 +22,6 @@ #include "config.h" #include "mutt_tags.h" -#include "context.h" #include "globals.h" #include "lib/hash.h" #include "lib/string2.h" @@ -231,21 +230,3 @@ int driver_tags_replace(struct Header *h, char *tags) } return 1; } - -int driver_tags_editor(struct Context *ctx, const char *tags, char *buf, size_t buflen) -{ - if (ctx->mx_ops->edit_msg_tags) - return ctx->mx_ops->edit_msg_tags(ctx, tags, buf, buflen); - - mutt_message(_("Folder doesn't support tagging, aborting.")); - return -1; -} - -int driver_tags_commit(struct Context *ctx, struct Header *h, char *tags) -{ - if (ctx->mx_ops->commit_msg_tags) - return ctx->mx_ops->commit_msg_tags(ctx, h, tags); - - mutt_message(_("Folder doesn't support tagging, aborting.")); - return -1; -} diff --git a/mutt_tags.h b/mutt_tags.h index 708ea1a0f..717614930 100644 --- a/mutt_tags.h +++ b/mutt_tags.h @@ -24,7 +24,6 @@ #define _MUTT_TAG_H #include "header.h" -#include "context.h" /** * struct TagList - Mail Header Tags @@ -64,7 +63,5 @@ const char *driver_tags_get_transformed(struct Header *h); const char *driver_tags_get_transformed_for(char *name, struct Header *h); void driver_tags_init(struct Header *h); int driver_tags_replace(struct Header *h, char *tags); -int driver_tags_editor(struct Context *ctx, const char *tags, char *buf, size_t buflen); -int driver_tags_commit(struct Context *ctx, struct Header *h, char *tags); #endif /* _MUTT_TAG_H */ diff --git a/mx.c b/mx.c index bd21a8ea9..e04994d93 100644 --- a/mx.c +++ b/mx.c @@ -1367,3 +1367,36 @@ int mx_check_empty(const char *path) } /* not reached */ } + +/** + * mx_tags_editor - start the tag editor of the mailbox + * @retval -1 Error + */ +int mx_tags_editor(struct Context *ctx, const char *tags, char *buf, size_t buflen) +{ + if (ctx->mx_ops->edit_msg_tags) + return ctx->mx_ops->edit_msg_tags(ctx, tags, buf, buflen); + + mutt_message(_("Folder doesn't support tagging, aborting.")); + return -1; +} + +/** + * mx_tags_commit - save tags to the mailbox + */ +int mx_tags_commit(struct Context *ctx, struct Header *h, char *tags) +{ + if (ctx->mx_ops->commit_msg_tags) + return ctx->mx_ops->commit_msg_tags(ctx, h, tags); + + mutt_message(_("Folder doesn't support tagging, aborting.")); + return -1; +} + +/** + * mx_tags_is_supported - return true if mailbox support tagging + */ +int mx_tags_is_supported(struct Context *ctx) +{ + return ctx->mx_ops->commit_msg_tags && ctx->mx_ops->edit_msg_tags; +} diff --git a/mx.h b/mx.h index a4fb157f8..64f2320b0 100644 --- a/mx.h +++ b/mx.h @@ -110,6 +110,10 @@ int mh_sync_mailbox_message(struct Context *ctx, int msgno); bool mx_is_notmuch(const char *p); #endif +int mx_tags_editor(struct Context *ctx, const char *tags, char *buf, size_t buflen); +int mx_tags_commit(struct Context *ctx, struct Header *h, char *tags); +int mx_tags_is_supported(struct Context *ctx); + FILE *maildir_open_find_message(const char *folder, const char *msg, char **newname); int mbox_strict_cmp_headers(const struct Header *h1, const struct Header *h2);