shithub: spread

Download patch

ref: f5d1631b91dd7a70c50b84912411465ad94ff2e6
parent: f397463f79e2b99db0b7a29d6c61396b88433717
author: sirjofri <[email protected]>
date: Thu Jul 4 11:21:24 EDT 2024

adds click to edit (RMB), don't save empty cells

--- a/engine.c
+++ b/engine.c
@@ -397,6 +397,8 @@
 		Bprint(b, "%s=%s\n", ptoa(c->p), c->value);
 		break;
 	case STRING:
+		if (!c->value || !c->value[0])
+			break;
 		Bprint(b, "%s;%s\n", ptoa(c->p), c->value);
 		break;
 	}
--- a/spread.c
+++ b/spread.c
@@ -340,6 +340,39 @@
 	return 0;
 }
 
+P clicktop(Point xy)
+{
+	P p;
+	p.x = 0;
+	p.y = 0;
+	
+	if (!ptinrect(xy, dstate.r)) {
+		return p;
+	}
+	
+	xy = subpt(xy, dstate.r.min);
+	
+	p.x = xy.x / dstate.dcolwidth;
+	p.y = xy.y / font->height;
+	
+	p.x += dstate.firstcell.x;
+	p.y += dstate.firstcell.y;
+	return p;
+}
+
+static void
+processclick(Event ev)
+{
+	P cell;
+	
+	if (ev.mouse.buttons & 4) {
+		/* right click to edit */
+		cell = clicktop(ev.mouse.xy);
+		edit(cell);
+		return;
+	}
+}
+
 void
 main(int argc, char **argv)
 {
@@ -391,6 +424,7 @@
 		
 		switch (e) {
 		case Emouse:
+			processclick(ev);
 			break;
 		case Ekeyboard:
 			if (processkbd(ev))