Reduce presel usage

This commit is contained in:
Arun Prakash Jana 2020-03-29 20:22:43 +05:30
parent d2e83b2cfe
commit 267dc04f6c
No known key found for this signature in database
GPG key ID: A75979F35C080412
2 changed files with 51 additions and 48 deletions

View file

@ -516,8 +516,9 @@ static char * const utils[] = {
#define MSG_IGNORED 39 #define MSG_IGNORED 39
#define MSG_RM_TMP 40 #define MSG_RM_TMP 40
#define MSG_NOCHNAGE 41 #define MSG_NOCHNAGE 41
#define MSG_CANCEL 42
#ifndef DIR_LIMITED_SELECTION #ifndef DIR_LIMITED_SELECTION
#define MSG_DIR_CHANGED 42 /* Must be the last entry */ #define MSG_DIR_CHANGED 43 /* Must be the last entry */
#endif #endif
static const char * const messages[] = { static const char * const messages[] = {
@ -563,6 +564,7 @@ static const char * const messages[] = {
"ignoring invalid paths...", "ignoring invalid paths...",
"remove tmp file?", "remove tmp file?",
"unchanged", "unchanged",
"cancelled",
#ifndef DIR_LIMITED_SELECTION #ifndef DIR_LIMITED_SELECTION
"dir changed, range sel off", /* Must be the last entry */ "dir changed, range sel off", /* Must be the last entry */
#endif #endif
@ -1848,14 +1850,12 @@ finish:
return ret; return ret;
} }
static bool cpmvrm_selection(enum action sel, char *path, int *presel) static bool cpmvrm_selection(enum action sel, char *path)
{ {
int r; int r;
if (!selsafe()) { if (!selsafe())
*presel = MSGWAIT;
return FALSE; return FALSE;
}
switch (sel) { switch (sel) {
case SEL_CP: case SEL_CP:
@ -1867,12 +1867,12 @@ static bool cpmvrm_selection(enum action sel, char *path, int *presel)
case SEL_CPMVAS: case SEL_CPMVAS:
r = get_input(messages[MSG_CP_MV_AS]); r = get_input(messages[MSG_CP_MV_AS]);
if (r != 'c' && r != 'm') { if (r != 'c' && r != 'm') {
printwait(messages[MSG_INVALID_KEY], presel); printmsg(messages[MSG_INVALID_KEY]);
return FALSE; return FALSE;
} }
if (!cpmv_rename(r, path)) { if (!cpmv_rename(r, path)) {
printwait(messages[MSG_FAILED], presel); printmsg(messages[MSG_FAILED]);
return FALSE; return FALSE;
} }
break; break;
@ -1888,9 +1888,6 @@ static bool cpmvrm_selection(enum action sel, char *path, int *presel)
if (sel != SEL_CP) if (sel != SEL_CP)
clearselection(); clearselection();
if (cfg.filtermode)
*presel = FILTER;
return TRUE; return TRUE;
} }
@ -3837,19 +3834,20 @@ next:
return TRUE; return TRUE;
} }
static bool archive_mount(char *name, char *path, char *newpath, int *presel) static bool archive_mount(char *path, char *newpath)
{ {
char *dir, *cmd = utils[UTIL_ARCHIVEMOUNT]; char *dir, *cmd = utils[UTIL_ARCHIVEMOUNT];
char *name = dents[cur].name;
size_t len; size_t len;
if (!getutil(cmd)) { if (!getutil(cmd)) {
printwait(messages[MSG_UTIL_MISSING], presel); printmsg(messages[MSG_UTIL_MISSING]);
return FALSE; return FALSE;
} }
dir = strdup(name); dir = strdup(name);
if (!dir) { if (!dir) {
printwait(messages[MSG_FAILED], presel); printmsg(messages[MSG_FAILED]);
return FALSE; return FALSE;
} }
@ -3868,7 +3866,7 @@ static bool archive_mount(char *name, char *path, char *newpath, int *presel)
free(dir); free(dir);
if (!xmktree(newpath, TRUE)) { if (!xmktree(newpath, TRUE)) {
printwarn(presel); printwarn(NULL);
return FALSE; return FALSE;
} }
@ -3876,14 +3874,14 @@ static bool archive_mount(char *name, char *path, char *newpath, int *presel)
DPRINTF_S(name); DPRINTF_S(name);
DPRINTF_S(newpath); DPRINTF_S(newpath);
if (spawn(cmd, name, newpath, path, F_NORMAL)) { if (spawn(cmd, name, newpath, path, F_NORMAL)) {
printwait(messages[MSG_FAILED], presel); printmsg(messages[MSG_FAILED]);
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
static bool remote_mount(char *newpath, int *presel) static bool remote_mount(char *newpath)
{ {
uchar flag = F_CLI; uchar flag = F_CLI;
int opt; int opt;
@ -3893,8 +3891,10 @@ static bool remote_mount(char *newpath, int *presel)
r = getutil(utils[UTIL_RCLONE]); r = getutil(utils[UTIL_RCLONE]);
s = getutil(utils[UTIL_SSHFS]); s = getutil(utils[UTIL_SSHFS]);
if (!(r || s)) if (!(r || s)) {
printmsg(messages[MSG_UTIL_MISSING]);
return FALSE; return FALSE;
}
if (r && s) if (r && s)
opt = get_input(messages[MSG_REMOTE_OPTS]); opt = get_input(messages[MSG_REMOTE_OPTS]);
@ -3909,23 +3909,20 @@ static bool remote_mount(char *newpath, int *presel)
cmd = utils[UTIL_RCLONE]; cmd = utils[UTIL_RCLONE];
env = xgetenv("NNN_RCLONE", "rclone mount"); env = xgetenv("NNN_RCLONE", "rclone mount");
} else { } else {
printwait(messages[MSG_INVALID_KEY], presel); printmsg(messages[MSG_INVALID_KEY]);
return FALSE;
}
if (!getutil(cmd)) {
printwait(messages[MSG_UTIL_MISSING], presel);
return FALSE; return FALSE;
} }
tmp = xreadline(NULL, messages[MSG_HOSTNAME]); tmp = xreadline(NULL, messages[MSG_HOSTNAME]);
if (!tmp[0]) if (!tmp[0]) {
printmsg(messages[MSG_CANCEL]);
return FALSE; return FALSE;
}
/* Create the mount point */ /* Create the mount point */
mkpath(cfgdir, tmp, newpath); mkpath(cfgdir, tmp, newpath);
if (!xmktree(newpath, TRUE)) { if (!xmktree(newpath, TRUE)) {
printwarn(presel); printwarn(NULL);
return FALSE; return FALSE;
} }
@ -3940,7 +3937,7 @@ static bool remote_mount(char *newpath, int *presel)
/* Connect to remote */ /* Connect to remote */
if (opt == 's') { if (opt == 's') {
if (spawn(env, tmp, newpath, NULL, flag)) { if (spawn(env, tmp, newpath, NULL, flag)) {
printwait(messages[MSG_FAILED], presel); printmsg(messages[MSG_FAILED]);
return FALSE; return FALSE;
} }
} else { } else {
@ -5471,14 +5468,14 @@ nochange:
} }
if (r == 'm') { if (r == 'm') {
if (archive_mount(dents[cur].name, if (!archive_mount(path, newpath)) {
path, newpath, &presel)) { presel = MSGWAIT;
cdprep(lastdir, lastname, path, newpath) goto nochange;
? (presel = FILTER) : (watch = TRUE);
goto begin;
} }
goto nochange; cdprep(lastdir, lastname, path, newpath)
? (presel = FILTER) : (watch = TRUE);
goto begin;
} }
if (r != 'd') { if (r != 'd') {
@ -5560,8 +5557,10 @@ nochange:
break; break;
} // fallthrough } // fallthrough
case SEL_REMOTE: case SEL_REMOTE:
if (sel == SEL_REMOTE && !remote_mount(newpath, &presel)) if (sel == SEL_REMOTE && !remote_mount(newpath)) {
presel = MSGWAIT;
goto nochange; goto nochange;
}
cdprep(lastdir, lastname, path, newpath) ? (presel = FILTER) : (watch = TRUE); cdprep(lastdir, lastname, path, newpath) ? (presel = FILTER) : (watch = TRUE);
goto begin; goto begin;
@ -5897,9 +5896,13 @@ nochange:
endselection(); endselection();
if (!cpmvrm_selection(sel, path, &presel)) if (!cpmvrm_selection(sel, path)) {
presel = MSGWAIT;
goto nochange; goto nochange;
}
if (cfg.filtermode)
presel = FILTER;
clearfilter(); clearfilter();
/* Show notification on operation complete */ /* Show notification on operation complete */
@ -6244,6 +6247,14 @@ nochange:
statusbar(path); statusbar(path);
goto nochange; goto nochange;
case SEL_EXPORT:
export_file_list();
cfg.filtermode ? presel = FILTER : statusbar(path);
goto nochange;
case SEL_TIMETYPE:
if (!set_time_type(&presel))
goto nochange;
goto begin;
case SEL_QUITCTX: // fallthrough case SEL_QUITCTX: // fallthrough
case SEL_QUITCD: // fallthrough case SEL_QUITCD: // fallthrough
case SEL_QUIT: case SEL_QUIT:
@ -6297,14 +6308,6 @@ nochange:
cfg.picker ? selbufpos = 0 : write_lastdir(path); cfg.picker ? selbufpos = 0 : write_lastdir(path);
free(mark); free(mark);
return sel == SEL_QUITFAIL ? _FAILURE : _SUCCESS; return sel == SEL_QUITFAIL ? _FAILURE : _SUCCESS;
case SEL_EXPORT:
export_file_list();
cfg.filtermode ? presel = FILTER : statusbar(path);
goto nochange;
case SEL_TIMETYPE:
if (!set_time_type(&presel))
goto nochange;
goto begin;
default: default:
r = FALSE; r = FALSE;
if (xlines != LINES || xcols != COLS) { if (xlines != LINES || xcols != COLS) {

View file

@ -92,12 +92,12 @@ enum action {
SEL_RUNCMD, SEL_RUNCMD,
SEL_LOCK, SEL_LOCK,
SEL_SESSIONS, SEL_SESSIONS,
SEL_EXPORT,
SEL_TIMETYPE,
SEL_QUITCTX, SEL_QUITCTX,
SEL_QUITCD, SEL_QUITCD,
SEL_QUIT, SEL_QUIT,
SEL_QUITFAIL, SEL_QUITFAIL,
SEL_EXPORT,
SEL_TIMETYPE,
#ifndef NOMOUSE #ifndef NOMOUSE
SEL_CLICK, SEL_CLICK,
#endif #endif
@ -241,6 +241,10 @@ static struct key bindings[] = {
{ '0', SEL_LOCK }, { '0', SEL_LOCK },
/* Manage sessions */ /* Manage sessions */
{ 's', SEL_SESSIONS }, { 's', SEL_SESSIONS },
/* Export list */
{ '>', SEL_EXPORT },
/* Set time type */
{ 'T', SEL_TIMETYPE },
/* Quit a context */ /* Quit a context */
{ 'q', SEL_QUITCTX }, { 'q', SEL_QUITCTX },
/* Change dir on quit */ /* Change dir on quit */
@ -249,10 +253,6 @@ static struct key bindings[] = {
{ CONTROL('Q'), SEL_QUIT }, { CONTROL('Q'), SEL_QUIT },
/* Quit with an error code */ /* Quit with an error code */
{ 'Q', SEL_QUITFAIL }, { 'Q', SEL_QUITFAIL },
/* Export list */
{ '>', SEL_EXPORT },
/* Set time type */
{ 'T', SEL_TIMETYPE },
#ifndef NOMOUSE #ifndef NOMOUSE
{ KEY_MOUSE, SEL_CLICK }, { KEY_MOUSE, SEL_CLICK },
#endif #endif