From bfff5762e0df868d13f835a417085cd871bbed8a Mon Sep 17 00:00:00 2001 From: piyo <piyo@users.noreply.github.com> Date: Wed, 23 Sep 2015 15:23:17 +0900 Subject: [PATCH] Confirm quit action during scan (reuse existing scan dialog). --- src/dir_common.c | 19 ++++++++++++++++--- src/dir_scan.c | 3 +++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/dir_common.c b/src/dir_common.c index 6ab12ab..46ebb75 100644 --- a/src/dir_common.c +++ b/src/dir_common.c @@ -35,6 +35,7 @@ char *dir_curpath; /* Full path of the last seen item. */ struct dir_output dir_output; char *dir_fatalerr; /* Error message on a fatal error. (NULL if there was no fatal error) */ int dir_ui; /* User interface to use */ +int confirm_quit_while_scanning_stage_1_passed; /* Additional check before quitting */ static char *lasterr; /* Path where the last error occured. */ static int curpathl; /* Allocated length of dir_curpath */ static int lasterrl; /* ^ of lasterr */ @@ -134,7 +135,10 @@ static void draw_progress() { if(dir_output.size) ncprint(2, 23, "size: %s", formatsize(dir_output.size)); ncprint(3, 2, "Current item: %s", cropstr(dir_curpath, width-18)); - ncaddstr(8, width-18, "Press q to abort"); + if (confirm_quit_while_scanning_stage_1_passed) + ncaddstr(8, width-26, "Press y to confirm abort"); + else + ncaddstr(8, width-18, "Press q to abort"); /* show warning if we couldn't open a dir */ if(lasterr) { @@ -207,7 +211,16 @@ void dir_draw() { int dir_key(int ch) { if(dir_fatalerr) return 1; - if(ch == 'q') - return 1; + if(confirm_quit_while_scanning_stage_1_passed) { + if (ch == 'y'|| ch == 'Y') { + return 1; + } else { + confirm_quit_while_scanning_stage_1_passed = 0; + return 0; + } + } else if(ch == 'q') { + confirm_quit_while_scanning_stage_1_passed = 1; + return 0; + } return 0; } diff --git a/src/dir_scan.c b/src/dir_scan.c index 6c38eeb..ab140a6 100644 --- a/src/dir_scan.c +++ b/src/dir_scan.c @@ -291,10 +291,13 @@ static int process() { } +extern int confirm_quit_while_scanning_stage_1_passed; + void dir_scan_init(const char *path) { dir_curpath_set(path); dir_setlasterr(NULL); dir_seterr(NULL); dir_process = process; pstate = ST_CALC; + confirm_quit_while_scanning_stage_1_passed = 0; } -- GitLab