From 7a002ec117886669ba9e1f19bed506847b730c9d Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Thu, 10 Aug 2017 18:18:20 -0700 Subject: Add helpers to add and remove actx entries. (see #3728) Use the helper in compose update_idx(), to consolidate the resize logic and simplify the code. Separate out the actx "free" routine from a routine to empty out the idx. The index regeneration routines should flush and rebuild the index without having to renerate the actx structure. --- attach.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'attach.c') diff --git a/attach.c b/attach.c index 7a512419..9b4b649e 100644 --- a/attach.c +++ b/attach.c @@ -1042,15 +1042,26 @@ int mutt_print_attachment (FILE *fp, BODY *a) } } -void mutt_free_attach_context (ATTACH_CONTEXT **pactx) +void mutt_actx_add_attach (ATTACH_CONTEXT *actx, ATTACHPTR *attach, MUTTMENU *menu) { int i; - ATTACH_CONTEXT *actx; - if (!pactx || !*pactx) - return; + if (actx->idxlen == actx->idxmax) + { + actx->idxmax += 5; + safe_realloc (&actx->idx, sizeof (ATTACHPTR *) * actx->idxmax); + for (i = actx->idxlen; i < actx->idxmax; i++) + actx->idx[i] = NULL; + if (menu) + menu->data = actx->idx; + } - actx = *pactx; + actx->idx[actx->idxlen++] = attach; +} + +void mutt_actx_free_entries (ATTACH_CONTEXT *actx) +{ + int i; for (i = 0; i < actx->idxlen; i++) { @@ -1059,7 +1070,19 @@ void mutt_free_attach_context (ATTACH_CONTEXT **pactx) FREE (&actx->idx[i]->tree); FREE (&actx->idx[i]); } - FREE (&actx->idx); + actx->idxlen = 0; +} + +void mutt_free_attach_context (ATTACH_CONTEXT **pactx) +{ + ATTACH_CONTEXT *actx; + + if (!pactx || !*pactx) + return; + + actx = *pactx; + mutt_actx_free_entries (actx); + FREE (&actx->idx); FREE (pactx); /* __FREE_CHECKED__ */ } -- cgit v1.2.3