From e96cc36d568a91f0fc36612d77dac60d58597648 Mon Sep 17 00:00:00 2001 From: piyo <piyo@users.noreply.github.com> Date: Fri, 18 Sep 2015 16:43:37 +0900 Subject: [PATCH] Confirm quit action with a cancellable dialog. --- Makefile.am | 2 ++ src/browser.c | 2 +- src/global.h | 2 ++ src/main.c | 2 ++ src/quit.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/quit.h | 37 ++++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/quit.c create mode 100644 src/quit.h diff --git a/Makefile.am b/Makefile.am index 41cd6ec..28e19e7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,6 +13,7 @@ ncdu_SOURCES=\ src/exclude.c\ src/help.c\ src/shell.c\ + src/quit.c\ src/main.c\ src/path.c\ src/util.c @@ -28,6 +29,7 @@ noinst_HEADERS=\ src/global.h\ src/help.h\ src/shell.h\ + src/quit.h\ src/path.h\ src/util.h diff --git a/src/browser.c b/src/browser.c index c49720e..d1adb4b 100644 --- a/src/browser.c +++ b/src/browser.c @@ -397,7 +397,7 @@ int browse_key(int ch) { if(info_show) info_show = 0; else - return 1; + quit_init(); break; case 'g': if(++graph > 3) diff --git a/src/global.h b/src/global.h index 9ba22ba..17f192d 100644 --- a/src/global.h +++ b/src/global.h @@ -56,6 +56,7 @@ #define ST_DEL 2 #define ST_HELP 3 #define ST_SHELL 4 +#define ST_QUIT 5 /* structure representing a file or directory */ @@ -104,5 +105,6 @@ int input_handle(int); #include "path.h" #include "util.h" #include "shell.h" +#include "quit.h" #endif diff --git a/src/main.c b/src/main.c index 206c3b7..6eeca0c 100644 --- a/src/main.c +++ b/src/main.c @@ -54,6 +54,7 @@ static void screen_draw() { case ST_HELP: help_draw(); break; case ST_SHELL: shell_draw(); break; case ST_DEL: delete_draw(); break; + case ST_QUIT: quit_draw(); break; } } @@ -97,6 +98,7 @@ int input_handle(int wait) { case ST_BROWSE: return browse_key(ch); case ST_HELP: return help_key(ch); case ST_DEL: return delete_key(ch); + case ST_QUIT: return quit_key(ch); } screen_draw(); } diff --git a/src/quit.c b/src/quit.c new file mode 100644 index 0000000..6594ded --- /dev/null +++ b/src/quit.c @@ -0,0 +1,55 @@ +/* ncdu - NCurses Disk Usage + + Copyright (c) 2015 Yoran Heling + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +#include "global.h" + +#include <ncurses.h> + +/* extern? */ int page, start; + +int quit_key(int ch) { + switch(ch) { + case 'y': + case 'Y': + return 1; + break; + default: + pstate = ST_BROWSE; + } + return 0; +} + +void quit_draw() { + browse_draw(); + + nccreate(4,30, "ncdu confirm quit"); + ncaddstr(2,2, "Really quit? (y/N)"); +} + +void quit_init() { + page = 1; + start = 0; + pstate = ST_QUIT; +} diff --git a/src/quit.h b/src/quit.h new file mode 100644 index 0000000..54b03d8 --- /dev/null +++ b/src/quit.h @@ -0,0 +1,37 @@ +/* ncdu - NCurses Disk Usage + + Copyright (c) 2015 Yoran Heling + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +#ifndef _quit_h +#define _quit_h + +#include "global.h" + +int quit_key(int); +void quit_draw(void); +void quit_init(void); + + +#endif + -- GitLab