Add right click file selection (#482)

This commit is contained in:
lvgx 2020-03-01 08:10:35 +01:00 committed by GitHub
parent 2b11601f89
commit b2f2b78990
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1458,9 +1458,11 @@ static bool initcurses(void *oldmask)
keypad(stdscr, TRUE); keypad(stdscr, TRUE);
#ifndef NOMOUSE #ifndef NOMOUSE
#if NCURSES_MOUSE_VERSION <= 1 #if NCURSES_MOUSE_VERSION <= 1
mousemask(BUTTON1_PRESSED | BUTTON1_DOUBLE_CLICKED, (mmask_t *)oldmask); mousemask(BUTTON1_PRESSED | BUTTON1_DOUBLE_CLICKED | BUTTON3_PRESSED,
(mmask_t *)oldmask);
#else #else
mousemask(BUTTON1_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED, (mmask_t *)oldmask); mousemask(BUTTON1_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED,
(mmask_t *)oldmask);
#endif #endif
mouseinterval(0); mouseinterval(0);
#endif #endif
@ -4949,6 +4951,7 @@ static bool browse(char *ipath, const char *session)
MEVENT event; MEVENT event;
struct timespec mousetimings[2] = {{.tv_sec = 0, .tv_nsec = 0}, {.tv_sec = 0, .tv_nsec = 0} }; struct timespec mousetimings[2] = {{.tv_sec = 0, .tv_nsec = 0}, {.tv_sec = 0, .tv_nsec = 0} };
bool currentmouse = 1; bool currentmouse = 1;
bool rightclicksel = 0;
#endif #endif
#ifndef DIR_LIMITED_SELECTION #ifndef DIR_LIMITED_SELECTION
@ -5162,9 +5165,18 @@ nochange:
} }
/* Handle clicking on a file */ /* Handle clicking on a file */
if (event.y >= 2 && event.y <= ndents + 1 && event.bstate == BUTTON1_PRESSED) { if (event.y >= 2 && event.y <= ndents + 1 &&
(event.bstate == BUTTON1_PRESSED ||
event.bstate == BUTTON3_PRESSED)) {
r = curscroll + (event.y - 2); r = curscroll + (event.y - 2);
move_cursor(r, 1); move_cursor(r, 1);
/* Handle right click selection */
if (event.bstate == BUTTON3_PRESSED) {
rightclicksel = 1;
goto selection;
}
currentmouse ^= 1; currentmouse ^= 1;
clock_gettime( clock_gettime(
#if defined(CLOCK_MONOTONIC_RAW) #if defined(CLOCK_MONOTONIC_RAW)
@ -5600,6 +5612,7 @@ nochange:
/* Repopulate as directory content may have changed */ /* Repopulate as directory content may have changed */
goto begin; goto begin;
} }
selection:
case SEL_SEL: case SEL_SEL:
if (!ndents) if (!ndents)
goto nochange; goto nochange;
@ -5629,7 +5642,12 @@ nochange:
if (!nselected) if (!nselected)
unlink(g_selpath); unlink(g_selpath);
#ifndef NOMOUSE
if (rightclicksel) {
rightclicksel = 0;
break;
}
#endif
/* 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)
move_cursor((cur + 1) % ndents, 0); move_cursor((cur + 1) % ndents, 0);