shithub: patch

Download patch

ref: 70d650eb94605d73027a80a37c94362f635dc98a
parent: 06dffbcd89b0d8698efb4da4b4d1c18d27824f0f
author: qwx <qwx@sciops.net>
date: Sun May 8 12:13:15 EDT 2022

vdir-tweaks: update for latest

--- a/vdir-tweaks
+++ b/vdir-tweaks
@@ -1,29 +1,7 @@
-diff 8154ecb3fc6c1265e0d5c0ab4288ad514463924d uncommitted
+diff 663d1a8c4432f3cef70466c04699fb6ebaafbc22 uncommitted
 --- a/vdir.c
 +++ b/vdir.c
-@@ -29,10 +29,10 @@
- 
- enum
- {
--	Mdelete,
- 	Mrename,
-+	Mdelete,
- };
--char *menu2str[] = { "delete", "rename", nil };
-+char *menu2str[] = { "rename", "delete", nil };
- Menu menu2 = { menu2str };
- 
- const char ellipsis[] = "…";
-@@ -252,7 +252,7 @@
- {
- 	char cmd[300];
- 
--	snprint(cmd, sizeof cmd, "rm -r %s/%s", path, name);
-+	snprint(cmd, sizeof cmd, "rm %s/%s", path, name);
- 	if(doexec(cmd) < 0)
- 		showerrstr("Cannot remove file/directory");
- 	else
-@@ -272,7 +272,7 @@
+@@ -273,7 +273,7 @@
  }
  
  int
@@ -32,7 +10,7 @@
  {
  	char *f;
  	int e;
-@@ -279,9 +279,12 @@
+@@ -280,9 +280,12 @@
  
  	f = smprint("%s/%s", path, name);
  	e = access(f, 0)==0;
@@ -48,103 +26,106 @@
  		alert("Error", "File does not exist anymore", nil, mctl, kctl);
  		loaddirs();
  		redraw();
-@@ -587,17 +590,51 @@
+@@ -588,40 +591,10 @@
  	else if(m.buttons == 0)
  		scrolling = 0;
  
 -	if(m.buttons&1){
+-		if(scrolling){
+-			dy = 1+nlines*((double)(m.xy.y - scrollr.min.y)/Dy(scrollr));
+-			scrollup(dy);
+-		}
+-	}else if(m.buttons&2){
+-		if(ptinrect(m.xy, viewr)){
+-			n = indexat(m.xy);
+-			if(n==-1)
+-				return;
+-			d = dirs[offset+n];
+-			switch(menuhit(2, mctl, &menu2, nil)){
+-			case Mdelete:
+-				rm(d.name);
+-				redraw();
+-				break;
+-			case Mrename:
+-				snprint(buf, sizeof buf, "%s", d.name);
+-				if(enter("Rename to", buf, sizeof buf, mctl, kctl, nil)>0){
+-					mv(d.name, buf);
+-					redraw();
+-				}
+-				break;
+-			}
+-		}else if(scrolling){
+-			if(nlines<ndirs){
+-				offset = scrollclamp((m.xy.y - scrollr.min.y) * ndirs/Dy(scrollr));
+-				redraw();
+-			}
+-		}
+-	}if((m.buttons&4) && oldbuttons == 0){
+-		if(scrolling){
+-			dy = 1+nlines*((double)(m.xy.y - scrollr.min.y)/Dy(scrollr));
+-			scrolldown(dy);
 +	if(m.buttons&1 && oldbuttons == 0){
- 		if(scrolling){
- 			dy = 1+nlines*((double)(m.xy.y - scrollr.min.y)/Dy(scrollr));
- 			scrollup(dy);
-+		}else if(ptinrect(m.xy, homer)){
-+			cd(nil);
-+			redraw();
-+		}else if(ptinrect(m.xy, upr)){
-+			up();
-+			redraw();
-+		}else if(ptinrect(m.xy, cdr)){
-+			m.xy = cept("Go to directory");
-+			if(enter("Go to directory", buf, sizeof buf, mctl, kctl, nil)>0){
-+				cd(buf);
++ 		if(scrolling){
++ 			dy = 1+nlines*((double)(m.xy.y - scrollr.min.y)/Dy(scrollr));
++ 			scrollup(dy);
+ 		}else if(ptinrect(m.xy, homer)){
+ 			cd(nil);
+ 			redraw();
+@@ -634,8 +607,6 @@
+ 				cd(buf);
+ 				redraw();
+ 			}
+-		}else if(ptinrect(m.xy, pathr)){
+-			plumbsendtext(plumbfd, "vdir", nil, nil, path);
+ 		}else if(ptinrect(m.xy, newdirr)){
+ 			m.xy = cept("Create directory");
+ 			if(enter("Create directory", buf, sizeof buf, mctl, kctl, nil)>0){
+@@ -656,10 +627,47 @@
+ 			if(d.qid.type & QTDIR){
+ 				cd(d.name);
+ 				redraw();
+-			}else{
+-				if(plumbfile(path, d.name))
+-					flash(n);
+ 			}
++ 		}
++	}else if(m.buttons&2 && oldbuttons == 0){
++ 		if(ptinrect(m.xy, viewr)){
++ 			n = indexat(m.xy);
++ 			if(n==-1)
++ 				return;
++ 			d = dirs[offset+n];
++			menu2.lasthit = 0;
++ 			switch(menuhit(2, mctl, &menu2, nil)){
++ 			case Mdelete:
++				rm(d.name);
 +				redraw();
++				break;
++			case Mrename:
++				snprint(buf, sizeof buf, "%s", d.name);
++				if(enter("Rename to", buf, sizeof buf, mctl, kctl, nil)>0){
++					mv(d.name, buf);
++					redraw();
++				}
++				break;
 +			}
-+		}else if(ptinrect(m.xy, newdirr)){
-+			m.xy = cept("Create directory");
-+			if(enter("Create directory", buf, sizeof buf, mctl, kctl, nil)>0){
-+				mkdir(buf);
++		}else if(scrolling){
++			if(nlines<ndirs){
++				offset = scrollclamp((m.xy.y - scrollr.min.y) * ndirs/Dy(scrollr));
 +				redraw();
 +			}
-+		}else if(ptinrect(m.xy, newfiler)){
-+			m.xy = cept("Create file");
-+			if(enter("Create file", buf, sizeof buf, mctl, kctl, nil)>0){
-+				touch(buf);
-+				redraw();
-+			}
++		}
++	}if((m.buttons&4) && oldbuttons == 0){
++		if(scrolling){
++			dy = 1+nlines*((double)(m.xy.y - scrollr.min.y)/Dy(scrollr));
++			scrolldown(dy);
++		}else if(ptinrect(m.xy, pathr)){
++			plumbsendtext(plumbfd, "vdirw", nil, nil, path);
 +		}else if(ptinrect(m.xy, viewr)){
 +			n = indexat(m.xy);
 +			if(n==-1)
 +				return;
 +			d = dirs[offset+n];
-+			if(d.qid.type & QTDIR){
-+				cd(d.name);
-+				redraw();
-+			}
- 		}
--	}else if(m.buttons&2){
-+	}else if(m.buttons&2 && oldbuttons == 0){
- 		if(ptinrect(m.xy, viewr)){
- 			n = indexat(m.xy);
- 			if(n==-1)
- 				return;
- 			d = dirs[offset+n];
-+			menu2.lasthit = 0;
- 			switch(menuhit(2, mctl, &menu2, nil)){
- 			case Mdelete:
- 				rm(d.name);
-@@ -620,44 +657,15 @@
- 		if(scrolling){
- 			dy = 1+nlines*((double)(m.xy.y - scrollr.min.y)/Dy(scrollr));
- 			scrolldown(dy);
--		}else if(ptinrect(m.xy, homer)){
--			cd(nil);
--			redraw();
--		}else if(ptinrect(m.xy, upr)){
--			up();
--			redraw();
--		}else if(ptinrect(m.xy, cdr)){
--			m.xy = cept("Go to directory");
--			if(enter("Go to directory", buf, sizeof buf, mctl, kctl, nil)>0){
--				cd(buf);
--				redraw();
--			}
- 		}else if(ptinrect(m.xy, pathr)){
--			plumbsendtext(plumbfd, "vdir", nil, nil, path);
--		}else if(ptinrect(m.xy, newdirr)){
--			m.xy = cept("Create directory");
--			if(enter("Create directory", buf, sizeof buf, mctl, kctl, nil)>0){
--				mkdir(buf);
--				redraw();
--			}
--		}else if(ptinrect(m.xy, newfiler)){
--			m.xy = cept("Create file");
--			if(enter("Create file", buf, sizeof buf, mctl, kctl, nil)>0){
--				touch(buf);
--				redraw();
--			}
-+			plumbsendtext(plumbfd, "vdirw", nil, nil, path);
- 		}else if(ptinrect(m.xy, viewr)){
- 			n = indexat(m.xy);
- 			if(n==-1)
- 				return;
- 			d = dirs[offset+n];
--			if(d.qid.type & QTDIR){
--				cd(d.name);
--				redraw();
--			}else{
--				if(plumbfile(path, d.name))
--					flash(n);
--			}
 +			if(plumbfile(path, d.name, d.qid.type & QTDIR))
 +				flash(n);
  		}