Remove list selection

This commit is contained in:
Arun Prakash Jana 2020-01-13 23:44:19 +05:30
parent 7029656c78
commit 7bcf19189a
No known key found for this signature in database
GPG key ID: A75979F35C080412
2 changed files with 31 additions and 27 deletions

View file

@ -474,7 +474,6 @@ static char * const utils[] = {
#define MSG_BOOKMARK_KEYS 36 #define MSG_BOOKMARK_KEYS 36
#define MSG_INVALID_REG 37 #define MSG_INVALID_REG 37
#define MSG_ORDER 38 #define MSG_ORDER 38
#define MSG_EDIT_SEL 39
static const char * const messages[] = { static const char * const messages[] = {
"no traversal", "no traversal",
@ -516,7 +515,6 @@ static const char * const messages[] = {
"bookmark keys:", "bookmark keys:",
"invalid regex", "invalid regex",
"toggle 'a'u / 'd'u / 'e'xtn / 'r'everse / 's'ize / 't'ime / 'v'ersion?", "toggle 'a'u / 'd'u / 'e'xtn / 'r'everse / 's'ize / 't'ime / 'v'ersion?",
"edit sel?",
}; };
/* Supported configuration environment variables */ /* Supported configuration environment variables */
@ -994,6 +992,7 @@ static size_t seltofile(int fd, uint *pcount)
return pos; return pos;
} }
#if 0
/* List selection from selection buffer */ /* List selection from selection buffer */
static bool listselbuf() static bool listselbuf()
{ {
@ -1038,6 +1037,7 @@ static bool listselfile(void)
return TRUE; return TRUE;
} }
#endif
/* Reset selection indicators */ /* Reset selection indicators */
static void resetselind(void) static void resetselind(void)
@ -1099,6 +1099,7 @@ static int editselection(void)
int fd, lines = 0; int fd, lines = 0;
ssize_t count; ssize_t count;
struct stat sb; struct stat sb;
struct timespec mtime;
if (!selbufpos) { if (!selbufpos) {
DPRINTF_S("empty selection"); DPRINTF_S("empty selection");
@ -1114,19 +1115,34 @@ static int editselection(void)
seltofile(fd, NULL); seltofile(fd, NULL);
close(fd); close(fd);
/* Save the last modification time */
if (stat(g_tmpfpath, &sb)) {
DPRINTF_S(strerror(errno));
unlink(g_tmpfpath);
return -1;
}
mtime = sb.st_mtim;
spawn((cfg.waitedit ? enveditor : editor), g_tmpfpath, NULL, NULL, F_CLI); spawn((cfg.waitedit ? enveditor : editor), g_tmpfpath, NULL, NULL, F_CLI);
fd = open(g_tmpfpath, O_RDONLY); fd = open(g_tmpfpath, O_RDONLY);
if (fd == -1) { if (fd == -1) {
DPRINTF_S("couldn't read tmp file"); DPRINTF_S(strerror(errno));
unlink(g_tmpfpath); unlink(g_tmpfpath);
return -1; return -1;
} }
fstat(fd, &sb); fstat(fd, &sb);
if (mtime.tv_sec == sb.st_mtim.tv_sec) {
DPRINTF_S("selection is not modified");
unlink(g_tmpfpath);
return 1;
}
if (sb.st_size > selbufpos) { if (sb.st_size > selbufpos) {
DPRINTF_S("edited buffer larger than pervious"); DPRINTF_S("edited buffer larger than previous");
unlink(g_tmpfpath);
goto emptyedit; goto emptyedit;
} }
@ -3611,7 +3627,7 @@ static void show_help(const char *path)
"cP Copy sel here%-11ca Select all\n" "cP Copy sel here%-11ca Select all\n"
"cV Move sel here%-10c^V Copy/move sel as\n" "cV Move sel here%-10c^V Copy/move sel as\n"
"cX Delete sel%-13c^X Delete entry\n" "cX Delete sel%-13c^X Delete entry\n"
"9o ^T Order toggle%-11c^Y List, edit sel\n" "9o ^T Order toggle%-11c^Y Edit sel\n"
"1MISC\n" "1MISC\n"
"9; ^P Plugin%-18c= Launch app\n" "9; ^P Plugin%-18c= Launch app\n"
"9! ^] Shell%-19c] Cmd prompt\n" "9! ^] Shell%-19c] Cmd prompt\n"
@ -5223,28 +5239,16 @@ nochange:
if (cfg.x11) if (cfg.x11)
plugscript(utils[UTIL_CBCP], newpath, F_NOWAIT | F_NOTRACE); plugscript(utils[UTIL_CBCP], newpath, F_NOWAIT | F_NOTRACE);
continue; continue;
case SEL_SELLIST: case SEL_SELEDIT:
if (!listselbuf() && !listselfile()) {
printwait(messages[MSG_0_SELECTED], &presel);
goto nochange;
}
r = get_input(messages[MSG_EDIT_SEL]);
if (r != 'y' && r != 'Y') {
cfg.filtermode ? presel = FILTER : statusbar(path);
goto nochange;
}
r = editselection(); r = editselection();
if (r <= 0) { /* Cannot be equal to 0 though as listing guards */ if (r <= 0) {
printwait(messages[MSG_FAILED], &presel); r = !r ? MSG_0_SELECTED : MSG_FAILED;
goto nochange; printwait(messages[r], &presel);
} } else {
if (cfg.x11) if (cfg.x11)
plugscript(utils[UTIL_CBCP], newpath, F_NOWAIT | F_NOTRACE); plugscript(utils[UTIL_CBCP], newpath, F_NOWAIT | F_NOTRACE);
cfg.filtermode ? presel = FILTER : statusbar(path); cfg.filtermode ? presel = FILTER : statusbar(path);
}
goto nochange; goto nochange;
case SEL_CP: // fallthrough case SEL_CP: // fallthrough
case SEL_MV: // fallthrough case SEL_MV: // fallthrough

View file

@ -72,7 +72,7 @@ enum action {
SEL_SEL, SEL_SEL,
SEL_SELMUL, SEL_SELMUL,
SEL_SELALL, SEL_SELALL,
SEL_SELLIST, SEL_SELEDIT,
SEL_CP, SEL_CP,
SEL_MV, SEL_MV,
SEL_CPMVAS, SEL_CPMVAS,
@ -189,7 +189,7 @@ static struct key bindings[] = {
/* Select all files in current dir */ /* Select all files in current dir */
{ 'a', SEL_SELALL }, { 'a', SEL_SELALL },
/* List, edit selection */ /* List, edit selection */
{ CONTROL('Y'), SEL_SELLIST }, { CONTROL('Y'), SEL_SELEDIT },
/* Copy from selection buffer */ /* Copy from selection buffer */
{ 'P', SEL_CP }, { 'P', SEL_CP },
/* Move from selection buffer */ /* Move from selection buffer */