Reformat presel handling

This commit is contained in:
Arun Prakash Jana 2018-11-10 00:56:21 +05:30
parent 17f54456b1
commit 5879f361b3
No known key found for this signature in database
GPG key ID: A75979F35C080412

55
nnn.c
View file

@ -205,6 +205,7 @@ disabledbg()
#define settimeout() timeout(1000) #define settimeout() timeout(1000)
#define cleartimeout() timeout(-1) #define cleartimeout() timeout(-1)
#define errexit() printerr(__LINE__) #define errexit() printerr(__LINE__)
#define setdirwatch() (cfg.filtermode ? (presel = FILTER) : (dir_changed = TRUE))
#ifdef LINUX_INOTIFY #ifdef LINUX_INOTIFY
#define EVENT_SIZE (sizeof(struct inotify_event)) #define EVENT_SIZE (sizeof(struct inotify_event))
@ -990,20 +991,19 @@ static int nextsel(char **run, char **env, int *presel)
if (c == 0) if (c == 0)
c = getch(); c = getch();
else { else {
*presel = 0;
/* Unwatch dir if we are still in a filtered view */ /* Unwatch dir if we are still in a filtered view */
#ifdef LINUX_INOTIFY #ifdef LINUX_INOTIFY
if (inotify_wd >= 0) { if (*presel == FILTER && inotify_wd >= 0) {
inotify_rm_watch(inotify_fd, inotify_wd); inotify_rm_watch(inotify_fd, inotify_wd);
inotify_wd = -1; inotify_wd = -1;
} }
#elif defined(BSD_KQUEUE) #elif defined(BSD_KQUEUE)
if (event_fd >= 0) { if (*presel == FILTER && event_fd >= 0) {
close(event_fd); close(event_fd);
event_fd = -1; event_fd = -1;
} }
#endif #endif
*presel = 0;
} }
if (c == -1) { if (c == -1) {
@ -2511,13 +2511,13 @@ static void browse(char *ipath)
begin: begin:
#ifdef LINUX_INOTIFY #ifdef LINUX_INOTIFY
if (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);
inotify_wd = -1; inotify_wd = -1;
dir_changed = FALSE; dir_changed = FALSE;
} }
#elif defined(BSD_KQUEUE) #elif defined(BSD_KQUEUE)
if (dir_changed && event_fd >= 0) { if ((presel == FILTER || dir_changed) && event_fd >= 0) {
close(event_fd); close(event_fd);
event_fd = -1; event_fd = -1;
dir_changed = FALSE; dir_changed = FALSE;
@ -2560,7 +2560,6 @@ nochange:
/* Continue in navigate-as-you-type mode, if enabled */ /* Continue in navigate-as-you-type mode, if enabled */
if (cfg.filtermode) if (cfg.filtermode)
presel = FILTER; presel = FILTER;
goto nochange; goto nochange;
} }
@ -2575,11 +2574,10 @@ nochange:
/* Save last working directory */ /* Save last working directory */
xstrlcpy(lastdir, path, PATH_MAX); xstrlcpy(lastdir, path, PATH_MAX);
dir_changed = TRUE;
xstrlcpy(path, dir, PATH_MAX); xstrlcpy(path, dir, PATH_MAX);
if (cfg.filtermode)
presel = FILTER; setdirwatch();
goto begin; goto begin;
case SEL_GOIN: case SEL_GOIN:
/* Cannot descend in empty directories */ /* Cannot descend in empty directories */
@ -2612,12 +2610,10 @@ nochange:
/* Save last working directory */ /* Save last working directory */
xstrlcpy(lastdir, path, PATH_MAX); xstrlcpy(lastdir, path, PATH_MAX);
dir_changed = TRUE;
xstrlcpy(path, newpath, PATH_MAX); xstrlcpy(path, newpath, PATH_MAX);
lastname[0] = '\0'; lastname[0] = '\0';
if (cfg.filtermode) setdirwatch();
presel = FILTER;
goto begin; goto begin;
case S_IFREG: case S_IFREG:
{ {
@ -2696,13 +2692,11 @@ nochange:
/* Save last working directory */ /* Save last working directory */
xstrlcpy(lastdir, path, PATH_MAX); xstrlcpy(lastdir, path, PATH_MAX);
dir_changed = TRUE;
xstrlcpy(path, dir, PATH_MAX); xstrlcpy(path, dir, PATH_MAX);
lastname[0] = '\0'; lastname[0] = '\0';
DPRINTF_S(path); DPRINTF_S(path);
if (cfg.filtermode) setdirwatch();
presel = FILTER;
goto begin; goto begin;
case SEL_CDLAST: // fallthrough case SEL_CDLAST: // fallthrough
case SEL_VISIT: case SEL_VISIT:
@ -2724,12 +2718,10 @@ nochange:
xstrlcpy(newpath, tmp, PATH_MAX); xstrlcpy(newpath, tmp, PATH_MAX);
xstrlcpy(lastdir, path, PATH_MAX); xstrlcpy(lastdir, path, PATH_MAX);
dir_changed = TRUE;
xstrlcpy(path, newpath, PATH_MAX); xstrlcpy(path, newpath, PATH_MAX);
lastname[0] = '\0'; lastname[0] = '\0';
DPRINTF_S(path); DPRINTF_S(path);
if (cfg.filtermode) setdirwatch();
presel = FILTER;
goto begin; goto begin;
case SEL_CDBM: case SEL_CDBM:
tmp = xreadline(NULL, "key: ", cfg.char_key); tmp = xreadline(NULL, "key: ", cfg.char_key);
@ -2739,11 +2731,12 @@ nochange:
/* Interpret ~, - and & keys */ /* Interpret ~, - and & keys */
if (tmp[1] == '\0') { if (tmp[1] == '\0') {
switch (tmp[0]) { switch (tmp[0]) {
case 'q':
case '~': //fallthrough case '~': //fallthrough
case '-': //fallthrough case '-': //fallthrough
case '&': case '&':
presel = tmp[0]; presel = tmp[0];
goto begin; goto nochange;
case '>': case '>':
case '.': case '.':
case '<': case '<':
@ -2792,12 +2785,8 @@ nochange:
hfltr = g_ctx[r].c_fltr; hfltr = g_ctx[r].c_fltr;
cfg.curctx = r; cfg.curctx = r;
if (cfg.filtermode) setdirwatch();
presel = FILTER;
goto begin; goto begin;
case 'q':
presel = 'q';
goto nochange;
} }
} }
@ -2816,14 +2805,12 @@ nochange:
/* Save last working directory */ /* Save last working directory */
xstrlcpy(lastdir, path, PATH_MAX); xstrlcpy(lastdir, path, PATH_MAX);
dir_changed = TRUE;
/* Save the newly opted dir in path */ /* Save the newly opted dir in path */
xstrlcpy(path, newpath, PATH_MAX); xstrlcpy(path, newpath, PATH_MAX);
DPRINTF_S(path); DPRINTF_S(path);
if (cfg.filtermode) setdirwatch();
presel = FILTER;
goto begin; goto begin;
case SEL_PIN: case SEL_PIN:
xstrlcpy(mark, path, PATH_MAX); xstrlcpy(mark, path, PATH_MAX);
@ -2837,17 +2824,18 @@ nochange:
goto nochange; goto nochange;
case SEL_MFLTR: case SEL_MFLTR:
cfg.filtermode ^= 1; cfg.filtermode ^= 1;
if (cfg.filtermode) if (cfg.filtermode) {
presel = FILTER; presel = FILTER;
else { goto nochange;
}
/* Save current */ /* Save current */
if (ndents) if (ndents)
copycurname(); copycurname();
dir_changed = TRUE;
/* Start watching the directory */ /* Start watching the directory */
goto begin; goto begin;
}
goto nochange;
case SEL_TOGGLEDOT: case SEL_TOGGLEDOT:
cfg.showhidden ^= 1; cfg.showhidden ^= 1;
initfilter(cfg.showhidden, hfltr); initfilter(cfg.showhidden, hfltr);
@ -3314,8 +3302,7 @@ nochange:
hfltr = g_ctx[r].c_fltr; hfltr = g_ctx[r].c_fltr;
cfg.curctx = r; cfg.curctx = r;
if (cfg.filtermode) setdirwatch();
presel = FILTER;
goto begin; goto begin;
} }