Refactor cur or sel confirmation

This commit is contained in:
Arun Prakash Jana 2019-12-26 20:33:01 +05:30
parent c43dce6926
commit b455abf944
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 36 additions and 27 deletions

View File

@ -705,6 +705,22 @@ static int get_input(const char *prompt)
return r; return r;
} }
static int get_cur_or_sel()
{
if (selbufpos && ndents) {
int choice = get_input(messages[MSG_CUR_SEL_OPTS]);
return ((choice == 'c' || choice == 's') ? choice : 0);
}
if (selbufpos)
return 's';
if (ndents)
return 'c';
return 0;
}
static void xdelay(useconds_t delay) static void xdelay(useconds_t delay)
{ {
refresh(); refresh();
@ -1535,20 +1551,15 @@ static bool batch_rename(const char *path)
char foriginal[TMP_LEN_MAX] = {0}; char foriginal[TMP_LEN_MAX] = {0};
char buf[sizeof(batchrenamecmd) + (PATH_MAX << 1)]; char buf[sizeof(batchrenamecmd) + (PATH_MAX << 1)];
if (selbufpos) { i = get_cur_or_sel();
if (ndents) { if (!i)
i = get_input(messages[MSG_CUR_SEL_OPTS]);
if (i == 'c') {
selbufpos = 0; /* Clear the selection */
dir = TRUE;
} else if (i != 's')
return ret;
}
} else if (ndents)
dir = TRUE; /* Rename entries in dir */
else
return ret; return ret;
if (i == 'c') { /* Rename entries in current dir */
selbufpos = 0;
dir = TRUE;
}
fd1 = create_tmp_file(); fd1 = create_tmp_file();
if (fd1 == -1) if (fd1 == -1)
return ret; return ret;
@ -2357,20 +2368,13 @@ static size_t mkpath(const char *dir, const char *name, char *out)
*/ */
static int xlink(char *suffix, char *path, char *curfname, char *buf, int *presel, int type) static int xlink(char *suffix, char *path, char *curfname, char *buf, int *presel, int type)
{ {
int count = 0, choice = 's'; int count = 0, choice;
char *pbuf = pselbuf, *fname; char *pbuf = pselbuf, *fname;
size_t pos = 0, len, r; size_t pos = 0, len, r;
int (*link_fn)(const char *, const char *) = NULL; int (*link_fn)(const char *, const char *) = NULL;
if (selbufpos) { choice = get_cur_or_sel();
if (ndents) { if (!choice)
choice = get_input(messages[MSG_CUR_SEL_OPTS]);
if (choice != 'c' && choice != 's')
return -1;
}
} else if (ndents)
choice = 'c';
else
return -1; return -1;
if (type == 's') /* symbolic link */ if (type == 's') /* symbolic link */
@ -4763,7 +4767,8 @@ nochange:
break; break;
case SEL_TOGGLEDOT: case SEL_TOGGLEDOT:
cfg.showhidden ^= 1; cfg.showhidden ^= 1;
setdirwatch(); if (cfg.filtermode)
presel = FILTER;
break; break;
case SEL_DETAIL: case SEL_DETAIL:
cfg.showdetail ^= 1; cfg.showdetail ^= 1;
@ -4818,6 +4823,7 @@ nochange:
break; break;
} }
clearfilter();
endselection(); endselection();
/* Save current */ /* Save current */
@ -5052,7 +5058,12 @@ nochange:
switch (sel) { switch (sel) {
case SEL_ARCHIVE: case SEL_ARCHIVE:
r = get_input(messages[MSG_CUR_SEL_OPTS]); r = get_cur_or_sel();
if (!r) {
clearprompt();
goto nochange;
}
if (r == 's') { if (r == 's') {
if (!selsafe()) { if (!selsafe()) {
presel = MSGWAIT; presel = MSGWAIT;
@ -5060,11 +5071,9 @@ nochange:
} }
tmp = NULL; tmp = NULL;
} else if (r != 'c' || !ndents) {
clearprompt();
goto nochange;
} else } else
tmp = dents[cur].name; tmp = dents[cur].name;
tmp = xreadline(tmp, messages[MSG_ARCHIVE_NAME]); tmp = xreadline(tmp, messages[MSG_ARCHIVE_NAME]);
break; break;
case SEL_OPENWITH: case SEL_OPENWITH: