shithub: mongrel

Download patch

ref: 608e406ec0d81e33bb6965c0ab6d25d5d12753cf
parent: 76d2ed0cda44c790a068ca9b8bce5bee2fce5334
author: phil9 <telephil9@gmail.com>
date: Fri Feb 4 15:52:14 EST 2022

add middle click menu in pager

	this menu allows (for the time being) to:
	- send the selected message to the plumber
	- delete the selected message

--- a/README.md
+++ b/README.md
@@ -15,13 +15,17 @@
 ## Usage
 mongrel has two components:
 - the index which shows the list of messages
-- the pager which shows an individual mail
+- the pager which shows the content of the mail currently selected in the index.
 
-Navigation in the index is done using the mouse, the arrow keys, page up/down, home and end. A left click on a given message will select it. Right-clicking or pressing `enter` will display the message content (in this case the pager will open if not displayed already).
-Scrolling in the pager can be achieved with either the mouse or with a combination of pressing `alt` and the arrow keys or page up/down.  
-The pager displays any attachments the message may have below the message headers. Right-clicking an individual attachment will send it to the plumber.  
-`q` will hide the pager if it is open or quit mongrel if in the index.  
-`Del` exit mongrel.
+In the index, navigation is done using either the scrollbar or the mouse wheel. Selection can be changed using the arrow keys, page up, page down, home and end. A left click on a message will select it and display its content if the pager is open while a right click (or pressing `Enter`) will open the pager first and then display the message content. A middle click will open a menu with additional actions:
+- plumb sends the message to the plumber which by default opens the message in nedmail (useful for answering/forwarding the message).
+- delete deletes the message
+
+In the pager, navigation is done using either the scrollbar or the mouse wheel. It is also possible to use keyboard navigation by pressing `Alt` in addition to the arrow keys, page up, page down, home and end.
+
+Other shortcuts:
+- `q` will hide the pager if it is open or quit mongrel if in the index.  
+- `Del` exit mongrel.
 
 ## License
 MIT
--- a/a.h
+++ b/a.h
@@ -78,7 +78,7 @@
 Message* mldel(Mlist*, usize);
 
 /* index */
-void indexinit(Channel*, Channel*, Theme*);
+void indexinit(Mousectl*, Channel*, Channel*, Theme*);
 Rectangle indexresize(Rectangle, int);
 void indexdraw(void);
 void indexmouse(Mouse);
--- a/index.c
+++ b/index.c
@@ -4,6 +4,7 @@
 #include <mouse.h>
 #include <keyboard.h>
 #include <thread.h>
+#include <plumb.h>
 #include "theme.h"
 #include "a.h"
 
@@ -27,17 +28,13 @@
 
 enum
 {
-	Mreply,
-	Mreplyall,
-	Mforward,
+	Mplumb,
 	Mdelete,
 };
 
 char *menustr[] =
 {
-	"reply",
-	"reply all",
-	"forward",
+	"plumb",
 	"delete",
 	nil
 };
@@ -47,6 +44,7 @@
 	menustr
 };
 
+Mousectl *mctl;
 Channel *showc;
 Channel *selc;
 Mailbox *mbox;
@@ -220,12 +218,13 @@
 }
 
 void
-indexinit(Channel *c0, Channel *c1, Theme *theme)
+indexinit(Mousectl *mc, Channel *c0, Channel *c1, Theme *theme)
 {
 	Rectangle r;
 
 	sel = 0;
 	offset = 0;
+	mctl = mc;
 	showc = c0;
 	selc = c1;
 	if(theme != nil){
@@ -297,7 +296,39 @@
 	return offset + (p.y-listr.min.y)/lineh;
 }
 
+static
 void
+plumbmsg(Message *m)
+{
+	int fd;
+
+	fd = plumbopen("send", OWRITE|OCEXEC);
+	if(fd<0)
+		return;
+	plumbsendtext(fd, "mongrel", nil, nil, m->path);
+	close(fd);	
+}
+
+static
+void
+menu2hit(Mouse m)
+{
+	int n;
+
+	n = menuhit(2, mctl, &menu, nil);
+	switch(n){
+	case Mplumb:
+		select(indexat(m.xy), selc);
+		plumbmsg(messageat(sel));
+		break;
+	case Mdelete:
+		select(indexat(m.xy), selc);
+		mesgdel(mbox, messageat(sel));
+		break;
+	}
+}
+
+void
 indexmouse(Mouse m)
 {
 	int n;
@@ -308,7 +339,7 @@
 		if(m.buttons & 1){
 			select(indexat(m.xy), selc);
 		}else if(m.buttons & 2){
-			/* TODO: menu */
+			menu2hit(m);
 		}else if(m.buttons & 4){
 			n = indexat(m.xy);
 			if(n != sel)
--- a/main.c
+++ b/main.c
@@ -181,7 +181,7 @@
 		cols[BORD] = allocimage(display, r, screen->chan, 1, 0x98971AFF);
 		*/
 	}
-	indexinit(showc, selc, theme);
+	indexinit(mctl, showc, selc, theme);
 	pagerinit(mctl, theme);
 }