From c516dad82665724b2eed7b00970f6cb7b231b3ff Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 29 Aug 2023 19:54:22 +1000 Subject: [PATCH] notmuch: place a context menu on all from: addresses The menu on From: addresses allow the address to be added to any query in the special "from-list" query. We don't act on the menu selection yet - that comes later. Signed-off-by: NeilBrown --- python/module-notmuch.py | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/python/module-notmuch.py b/python/module-notmuch.py index 148bee60..05a327e2 100644 --- a/python/module-notmuch.py +++ b/python/module-notmuch.py @@ -26,6 +26,8 @@ # in the "search list" together with a count of 'current' and 'current/new' messages. # "query.misc-list" is a subset of current-list for which query:current should not # be assumed. +# "query.from-list" is a list of other queries for which it is meaningful +# to add "from:address" clauses for some address. import edlib @@ -763,6 +765,12 @@ class notmuch_main(edlib.Doc): self.searches.slist["-ad hoc-"] = "" return 1 + def handle_get_query(self, key, focus, str1, comm2, **a): + "handle:doc:notmuch:get-query" + if str1 and str1 in self.searches.slist: + comm2("cb", focus, self.searches.slist[str1]) + return 1 + def tick(self, key, **a): if not self.updating: self.searches.load(False) @@ -3115,6 +3123,8 @@ class notmuch_message_view(edlib.Pane): self.prev_point = None self.have_prev = False self.call("doc:request:mark:moving") + self.menu = None + self.addr = None self['word-wrap'] = '1' # Should this be different in different parts? @@ -3462,6 +3472,13 @@ class notmuch_message_view(edlib.Pane): comm2("attr:callback", focus, 0, mark, "wrap-tail: ,wrap-head: ", 121) return 1 + if str == "render:rfc822header-addr": + w=str2.split(",") + if "From" in w: + comm2("attr:callback", focus, int(w[0]), mark, + "underline,action-menu:notmuch-addr-menu,addr-tag:"+w[1], + 200) + return 1 if str == "render:rfc822header-wrap": comm2("attr:callback", focus, int(str2), mark, "wrap", 120) return 1 @@ -3519,6 +3536,45 @@ class notmuch_message_view(edlib.Pane): comm2("cb", focus, mark, 0, "bg:"+bg, 102) return edlib.Efallthrough + def handle_menu(self, key, focus, mark, xy, str1, **a): + "handle:notmuch-addr-menu" + if self.menu: + self.menu.call("Cancel") + for at in str1.split(','): + if at.startswith("addr-tag:"): + t = at[9:] + addr = focus.call("doc:get-attr", 0, mark, "addr-"+t, ret='str') + if not addr: + return 1 + focus.call("Message", "Menu for address %s" % addr) + mp = self.call("attach-menu", "", "notmuch-addr-choice", xy, ret='pane') + mp.call("menu-add", "C", "Compose") + q = focus.call("doc:notmuch:get-query", "from-list", ret='str') + if q: + for t in q.split(): + if t.startswith("query:"): + t = t[6:] + mp.call("menu-add", t, 'Add to "%s"' % t) + mp.call("doc:file", -1) + self.menu = mp + self.addr = addr + self.add_notify(mp, "Notify:Close") + return 1 + + def handle_notify_close(self, key, focus, **a): + "handle:Notify:Close" + if focus == self.menu: + self.menu = None + return 1 + return edlib.Efallthrough + + def handle_addr_choice(self, key, focus, mark, str1, **a): + "handle:notmuch-addr-choice" + if not str1 or not self.addr: + return None + edlib.LOG("Addr menu Chose", str1, "for", self.addr) + return 1 + def handle_render_line(self, key, focus, num, mark, mark2, comm2, **a): "handle:doc:render-line" # If between active quote marks, render a simple marker -- 2.39.5