Support deselection

This commit is contained in:
Arun Prakash Jana 2019-11-28 23:12:49 +05:30
parent 1bf49c80e7
commit 20ac9da988
2 changed files with 35 additions and 30 deletions

View file

@ -580,6 +580,7 @@ static int (*nftw_fn)(const char *fpath, const struct stat *sb, int typeflag, st
static int dentfind(const char *fname, int n); static int dentfind(const char *fname, int n);
static void move_cursor(int target, int ignore_scrolloff); static void move_cursor(int target, int ignore_scrolloff);
static inline bool getutil(char *util); static inline bool getutil(char *util);
static size_t mkpath(const char *dir, const char *name, char *out);
/* Functions */ /* Functions */
@ -992,13 +993,26 @@ static void startselection(void)
} }
} }
static void updateselbuf(const char *path, char *newpath)
{
int i = 0;
size_t r;
for (; i < ndents; ++i)
if (dents[i].flags & FILE_SELECTED) {
r = mkpath(path, dents[i].name, newpath);
appendfpath(newpath, r);
}
}
/* Finish selection procedure before an operation */ /* Finish selection procedure before an operation */
static void endselection(void) static void endselection(const char *path, char *newpath)
{ {
if (cfg.selmode) { if (cfg.selmode) {
cfg.selmode = 0; cfg.selmode = 0;
updateselbuf(path, newpath);
if (selbufpos) { /* File path(s) written to the buffer */ if (selbufpos) { /* File path(s) written to the buffer */
writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */ writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */
spawn(copier, NULL, NULL, NULL, F_NOTRACE); spawn(copier, NULL, NULL, NULL, F_NOTRACE);
@ -1444,8 +1458,6 @@ static bool cpmvrm_selection(enum action sel, char *path, int *presel)
{ {
int r; int r;
endselection();
if (!selsafe()) { if (!selsafe()) {
*presel = MSGWAIT; *presel = MSGWAIT;
return FALSE; return FALSE;
@ -1576,7 +1588,7 @@ static void get_archive_cmd(char *cmd, char *archive)
xstrlcpy(cmd, "tar -acvf", ARCHIVE_CMD_LEN); xstrlcpy(cmd, "tar -acvf", ARCHIVE_CMD_LEN);
} }
static void MSG_ARCHIVE_SELection(const char *cmd, const char *archive, const char *curpath) static void archive_selection(const char *cmd, const char *archive, const char *curpath)
{ {
char *buf = (char *)malloc(CMD_LEN_MAX * sizeof(char)); char *buf = (char *)malloc(CMD_LEN_MAX * sizeof(char));
@ -2338,8 +2350,6 @@ static int xlink(char *suffix, char *path, char *buf, int *presel, int type)
return -1; return -1;
} }
endselection();
if (type == 's') /* symbolic link */ if (type == 's') /* symbolic link */
link_fn = &symlink; link_fn = &symlink;
else /* hard link */ else /* hard link */
@ -4134,6 +4144,9 @@ static void browse(char *ipath, const char *session)
errexit(); errexit();
begin: begin:
if (cfg.selmode && nselected)
updateselbuf(lastdir, newpath);
#ifdef LINUX_INOTIFY #ifdef LINUX_INOTIFY
if ((presel == FILTER || dir_changed) && inotify_wd >= 0) { if ((presel == FILTER || dir_changed) && inotify_wd >= 0) {
inotify_rm_watch(inotify_fd, inotify_wd); inotify_rm_watch(inotify_fd, inotify_wd);
@ -4720,7 +4733,7 @@ nochange:
refresh = TRUE; refresh = TRUE;
break; break;
case SEL_RENAMEMUL: case SEL_RENAMEMUL:
endselection(); endselection(path, newpath);
if (!batch_rename(path)) { if (!batch_rename(path)) {
printwait(messages[MSG_FAILED], &presel); printwait(messages[MSG_FAILED], &presel);
@ -4763,13 +4776,8 @@ nochange:
if (rangesel) if (rangesel)
rangesel = FALSE; rangesel = FALSE;
/* Do not select if already selected */ dents[cur].flags ^= FILE_SELECTED;
if (!(dents[cur].flags & FILE_SELECTED)) { dents[cur].flags ? ++nselected : --nselected;
appendfpath(newpath, mkpath(path, dents[cur].name, newpath));
++nselected;
dents[cur].flags |= FILE_SELECTED;
}
/* move cursor to the next entry if this is not the last entry */ /* move cursor to the next entry if this is not the last entry */
if (!cfg.picker && cur != ndents - 1) if (!cfg.picker && cur != ndents - 1)
@ -4828,29 +4836,22 @@ nochange:
for (r = selstartid; r <= selendid; ++r) for (r = selstartid; r <= selendid; ++r)
if (!(dents[r].flags & FILE_SELECTED)) { if (!(dents[r].flags & FILE_SELECTED)) {
appendfpath(newpath, mkpath(path, dents[r].name, newpath));
dents[r].flags |= FILE_SELECTED; dents[r].flags |= FILE_SELECTED;
++nselected; ++nselected;
} }
/* Show the range count */
//r = selendid - selstartid + 1;
//mvprintw(xlines - 1, 0, "+%d\n", r);
//xdelay(XDELAY_INTERVAL_MS);
//writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */
//spawn(copier, NULL, NULL, NULL, F_NOTRACE);
continue; continue;
case SEL_SELLST: case SEL_SELLIST:
if (listselbuf() || listselfile()) { if (listselbuf() || listselfile()) {
if (cfg.filtermode) if (cfg.filtermode)
presel = FILTER; presel = FILTER;
break; break;
} }
printwait(messages[MSG_0_SELECTED], &presel);
goto nochange; goto nochange;
case SEL_SELEDIT: case SEL_SELEDIT:
if (nselected)
updateselbuf(path, newpath);
if (!editselection()) { if (!editselection()) {
printwait(messages[MSG_FAILED], &presel); printwait(messages[MSG_FAILED], &presel);
goto nochange; goto nochange;
@ -4861,6 +4862,8 @@ nochange:
case SEL_CPMVAS: // fallthrough case SEL_CPMVAS: // fallthrough
case SEL_RMMUL: case SEL_RMMUL:
{ {
endselection(path, newpath);
if (!cpmvrm_selection(sel, path, &presel)) if (!cpmvrm_selection(sel, path, &presel))
goto nochange; goto nochange;
@ -4899,7 +4902,7 @@ nochange:
case SEL_ARCHIVE: case SEL_ARCHIVE:
r = get_input(messages[MSG_ARCHIVE_SEL]); r = get_input(messages[MSG_ARCHIVE_SEL]);
if (r == 'y' || r == 'Y') { if (r == 'y' || r == 'Y') {
endselection(); endselection(path, newpath);
if (!selsafe()) { if (!selsafe()) {
presel = MSGWAIT; presel = MSGWAIT;
@ -4962,7 +4965,7 @@ nochange:
get_archive_cmd(cmd, tmp); get_archive_cmd(cmd, tmp);
(r == 'y' || r == 'Y') ? MSG_ARCHIVE_SELection(cmd, tmp, path) (r == 'y' || r == 'Y') ? archive_selection(cmd, tmp, path)
: spawn(cmd, tmp, dents[cur].name, : spawn(cmd, tmp, dents[cur].name,
path, F_NORMAL | F_MULTI); path, F_NORMAL | F_MULTI);
break; break;
@ -5044,6 +5047,8 @@ nochange:
mkpath(path, tmp, newpath); mkpath(path, tmp, newpath);
r = xmktree(newpath, TRUE); r = xmktree(newpath, TRUE);
} else if (r == 's' || r == 'h') { } else if (r == 's' || r == 'h') {
endselection(path, newpath);
if (tmp[0] == '@' && tmp[1] == '\0') if (tmp[0] == '@' && tmp[1] == '\0')
tmp[0] = '\0'; tmp[0] = '\0';
r = xlink(tmp, path, newpath, &presel, r); r = xlink(tmp, path, newpath, &presel, r);
@ -5080,7 +5085,7 @@ nochange:
case SEL_PLUGIN: // fallthrough case SEL_PLUGIN: // fallthrough
case SEL_LAUNCH: // fallthrough case SEL_LAUNCH: // fallthrough
case SEL_RUNCMD: case SEL_RUNCMD:
endselection(); endselection(path, newpath);
switch (sel) { switch (sel) {
case SEL_EXEC: case SEL_EXEC:

View file

@ -78,7 +78,7 @@ enum action {
SEL_SEL, SEL_SEL,
SEL_SELMUL, SEL_SELMUL,
SEL_SELALL, SEL_SELALL,
SEL_SELLST, SEL_SELLIST,
SEL_SELEDIT, SEL_SELEDIT,
SEL_CP, SEL_CP,
SEL_MV, SEL_MV,
@ -212,7 +212,7 @@ static struct key bindings[] = {
/* Select all files in current dir */ /* Select all files in current dir */
{ 'a', SEL_SELALL }, { 'a', SEL_SELALL },
/* Show list of copied files */ /* Show list of copied files */
{ 'M', SEL_SELLST }, { 'M', SEL_SELLIST },
/* Edit selection buffer */ /* Edit selection buffer */
{ 'K', SEL_SELEDIT }, { 'K', SEL_SELEDIT },
/* Copy from selection buffer */ /* Copy from selection buffer */