shithub: orca

Download patch

ref: c98d73fc2318481eeb16d90144c697e87544bf46
parent: 46544df18a733fdcc2e43dde43b396e719f1a0b1
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Feb 12 16:18:35 EST 2020

plan9: load/save and display the filename

--- a/plan9.c
+++ b/plan9.c
@@ -31,6 +31,7 @@
 static Field field;
 static Mbuf_reusable mbuf;
 static Oevent_list events;
+static char filename[256];
 
 static char *menu3i[] = {
 	"load",
@@ -242,6 +243,10 @@
 	runesprint(linebuf, "%d", bpm);
 	runestring(screen, p, display->white, ZP, font, linebuf);
 
+	/* filename */
+	p.y += font->height;
+	string(screen, p, display->white, ZP, font, filename);
+
 	/* cursor bg */
 	p = top;
 	p.x += curx*stringwidth(font, " ");
@@ -266,6 +271,18 @@
 	return 0;
 }
 
+static int
+fieldsave(char *path)
+{
+	FILE *f;
+
+	if ((f = fopen(path, "w")) == nil)
+		return -1;
+	field_fput(&field, f);
+	fclose(f);
+	return 0;
+}
+
 static void
 fieldset(Rune key)
 {
@@ -295,7 +312,7 @@
 	Rune key;
 	Mouse m;
 	char tmp[256];
-	int oldw, oldh, w, h;
+	int oldw, oldh, w, h, n;
 	Alt a[] = {
 		{ nil, &m, CHANRCV },
 		{ nil, nil, CHANRCV },
@@ -351,18 +368,18 @@
 			case 2:
 				break;
 			case 4:
-				switch (menuhit(3, mctl, &menu3, nil)) {
-				case 0:
-					tmp[0] = 0;
-					if (enter("load file:", tmp, sizeof(tmp), mctl, kctl, nil) > 0) {
-						if (fieldload(tmp) == 0) {
+				n = menuhit(3, mctl, &menu3, nil);
+				if (n == 0 || n == 1) {
+					strncpy(tmp, filename, sizeof(tmp));
+					if (enter("file path:", tmp, sizeof(tmp), mctl, kctl, nil) > 0) {
+						if (n == 0 && fieldload(tmp) == 0) {
 							w = field.width;
 							h = field.height;
-						} else {
-							/* FIXME display the error */
+							strncpy(filename, tmp, sizeof(filename));
+						} else if (n == 1 && fieldsave(tmp) == 0) {
+							strncpy(filename, tmp, sizeof(filename));
 						}
 					}
-					break;
 				}
 				break;
 			}