From 27fd8910ae7a41a53a53c531e216f414ad7a2ed4 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 14 Aug 2015 17:20:16 -0400 Subject: [PATCH] TW-1655: Inform "No changes made." when quitting early due to signal - Thanks to Daniel Shahaf. --- ChangeLog | 2 ++ src/l10n/deu-DEU.h | 1 + src/l10n/eng-USA.h | 2 ++ src/l10n/epo-RUS.h | 1 + src/l10n/esp-ESP.h | 1 + src/l10n/fra-FRA.h | 1 + src/l10n/ita-ITA.h | 1 + src/l10n/jpn-JPN.h | 1 + src/l10n/pol-POL.h | 1 + src/l10n/por-PRT.h | 1 + src/util.cpp | 18 ++++++++++++++++++ 11 files changed, 30 insertions(+) diff --git a/ChangeLog b/ChangeLog index d032351be..147074ff9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -123,6 +123,8 @@ - TW-1652 task rm misparsed (thanks to Daniel Shahaf). - TW-1653 info report regression; shouldn't be context sensitive (thanks to David Patrick). +- TW-1655 Inform "No changes made." when quitting early due to signal (thanks + to Daniel Shahaf). - Prevent potential task duplication during import for non-pending tasks. - Show the active context in "context list", if any is active. - Fix "task edit" dropping annotation text after newlines. diff --git a/src/l10n/deu-DEU.h b/src/l10n/deu-DEU.h index b4932ecbf..0acecf91b 100644 --- a/src/l10n/deu-DEU.h +++ b/src/l10n/deu-DEU.h @@ -752,6 +752,7 @@ #define STRING_ERROR_DETAILS "Die Option 'calendar.details.report' muss einen einzelnen Report-Namen enthalten." #define STRING_ERROR_NO_FILTER "Command line filters are not supported by this command." #define STRING_ERROR_NO_MODS "Command line modifications are not supported by this command." +#define STRING_ERROR_CONFIRM_SIGINT "Interrupted: No changes made." // Feedback #define STRING_FEEDBACK_NO_TASKS "Keine Aufgaben." diff --git a/src/l10n/eng-USA.h b/src/l10n/eng-USA.h index c2824d841..f10532bcb 100644 --- a/src/l10n/eng-USA.h +++ b/src/l10n/eng-USA.h @@ -384,6 +384,7 @@ #define STRING_CMD_DELETE_1 "Deleted {1} task." #define STRING_CMD_DELETE_N "Deleted {1} tasks." + #define STRING_CMD_DUPLICATE_USAGE "Duplicates the specified tasks" #define STRING_CMD_DUPLICATE_REC "Note: task {1} was a parent recurring task. The duplicated task is too." #define STRING_CMD_DUPLICATE_NON_REC "Note: task {1} was a recurring task. The duplicated task is not." @@ -749,6 +750,7 @@ #define STRING_ERROR_DETAILS "The setting 'calendar.details.report' must contain a single report name." #define STRING_ERROR_NO_FILTER "Command line filters are not supported by this command." #define STRING_ERROR_NO_MODS "Command line modifications are not supported by this command." +#define STRING_ERROR_CONFIRM_SIGINT "Interrupted: No changes made." // Feedback #define STRING_FEEDBACK_NO_TASKS "No tasks." diff --git a/src/l10n/epo-RUS.h b/src/l10n/epo-RUS.h index 1caecc0b0..821fc50cf 100644 --- a/src/l10n/epo-RUS.h +++ b/src/l10n/epo-RUS.h @@ -752,6 +752,7 @@ #define STRING_ERROR_DETAILS "Agordo 'calendar.details.report' devas enhavi sole unu raportnomon." #define STRING_ERROR_NO_FILTER "Command line filters are not supported by this command." #define STRING_ERROR_NO_MODS "Command line modifications are not supported by this command." +#define STRING_ERROR_CONFIRM_SIGINT "Interrupted: No changes made." // Feedback #define STRING_FEEDBACK_NO_TASKS "Nenia tasko." diff --git a/src/l10n/esp-ESP.h b/src/l10n/esp-ESP.h index 05e9c3400..a4ff0ed7f 100644 --- a/src/l10n/esp-ESP.h +++ b/src/l10n/esp-ESP.h @@ -764,6 +764,7 @@ #define STRING_ERROR_DETAILS "El ajuste 'calendar.details.report' debe contener un único nombre de informe." #define STRING_ERROR_NO_FILTER "Command line filters are not supported by this command." #define STRING_ERROR_NO_MODS "Command line modifications are not supported by this command." +#define STRING_ERROR_CONFIRM_SIGINT "Interrupted: No changes made." // Feedback #define STRING_FEEDBACK_NO_TASKS "Ninguna tarea." diff --git a/src/l10n/fra-FRA.h b/src/l10n/fra-FRA.h index 3b79db0e1..c7dfab0bf 100644 --- a/src/l10n/fra-FRA.h +++ b/src/l10n/fra-FRA.h @@ -752,6 +752,7 @@ #define STRING_ERROR_DETAILS "The setting 'calendar.details.report' must contain a single report name." #define STRING_ERROR_NO_FILTER "Command line filters are not supported by this command." #define STRING_ERROR_NO_MODS "Command line modifications are not supported by this command." +#define STRING_ERROR_CONFIRM_SIGINT "Interrupted: No changes made." // Feedback #define STRING_FEEDBACK_NO_TASKS "No tasks." diff --git a/src/l10n/ita-ITA.h b/src/l10n/ita-ITA.h index ddda8974a..687af0f57 100644 --- a/src/l10n/ita-ITA.h +++ b/src/l10n/ita-ITA.h @@ -751,6 +751,7 @@ #define STRING_ERROR_DETAILS "The setting 'calendar.details.report' must contain a single report name." #define STRING_ERROR_NO_FILTER "Command line filters are not supported by this command." #define STRING_ERROR_NO_MODS "Command line modifications are not supported by this command." +#define STRING_ERROR_CONFIRM_SIGINT "Interrupted: No changes made." // Feedback #define STRING_FEEDBACK_NO_TASKS "Nessun task." diff --git a/src/l10n/jpn-JPN.h b/src/l10n/jpn-JPN.h index 90abee88d..21ad4fff8 100644 --- a/src/l10n/jpn-JPN.h +++ b/src/l10n/jpn-JPN.h @@ -752,6 +752,7 @@ #define STRING_ERROR_DETAILS "The setting 'calendar.details.report' must contain a single report name." #define STRING_ERROR_NO_FILTER "Command line filters are not supported by this command." #define STRING_ERROR_NO_MODS "Command line modifications are not supported by this command." +#define STRING_ERROR_CONFIRM_SIGINT "Interrupted: No changes made." // Feedback #define STRING_FEEDBACK_NO_TASKS "タスクがない。" diff --git a/src/l10n/pol-POL.h b/src/l10n/pol-POL.h index f7a705979..52a42152e 100644 --- a/src/l10n/pol-POL.h +++ b/src/l10n/pol-POL.h @@ -752,6 +752,7 @@ #define STRING_ERROR_DETAILS "Zmienna 'calendar.details.report' musi zawierać nazwę raportu." #define STRING_ERROR_NO_FILTER "Command line filters are not supported by this command." #define STRING_ERROR_NO_MODS "Command line modifications are not supported by this command." +#define STRING_ERROR_CONFIRM_SIGINT "Interrupted: No changes made." // Feedback #define STRING_FEEDBACK_NO_TASKS "Brak zadań." diff --git a/src/l10n/por-PRT.h b/src/l10n/por-PRT.h index a1c500103..1fe1f5eea 100644 --- a/src/l10n/por-PRT.h +++ b/src/l10n/por-PRT.h @@ -752,6 +752,7 @@ #define STRING_ERROR_DETAILS "A definição 'calendar.details.report' pode apenas indicar um nome de relatório." #define STRING_ERROR_NO_FILTER "Command line filters are not supported by this command." #define STRING_ERROR_NO_MODS "Command line modifications are not supported by this command." +#define STRING_ERROR_CONFIRM_SIGINT "Interrupted: No changes made." // Feedback #define STRING_FEEDBACK_NO_TASKS "Nenhuma tarefa." diff --git a/src/util.cpp b/src/util.cpp index 1f4e583db..ea8b973d8 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,16 @@ extern Context context; +//////////////////////////////////////////////////////////////////////////////// +static void signal_handler (int s) +{ + if (s == SIGINT) + { + std::cout << "\n\n" << STRING_ERROR_CONFIRM_SIGINT << "\n"; + exit (1); + } +} + //////////////////////////////////////////////////////////////////////////////// // Uses std::getline, because std::cin eats leading whitespace, and that means // that if a newline is entered, std::cin eats it and never returns from the @@ -69,6 +80,8 @@ bool confirm (const std::string& question) STRING_UTIL_CONFIRM_NO}; std::vector matches; + signal (SIGINT, signal_handler); + do { std::cout << question @@ -83,6 +96,7 @@ bool confirm (const std::string& question) } while (! std::cin.eof () && matches.size () != 1); + signal (SIGINT, SIG_DFL); return matches.size () == 1 && matches[0] == STRING_UTIL_CONFIRM_YES ? true : false; } @@ -101,6 +115,8 @@ int confirm4 (const std::string& question) STRING_UTIL_CONFIRM_QUIT}; std::vector matches; + signal (SIGINT, signal_handler); + do { std::cout << question @@ -119,6 +135,8 @@ int confirm4 (const std::string& question) } while (! std::cin.eof () && matches.size () != 1); + signal (SIGINT, SIG_DFL); + if (matches.size () == 1) { if (matches[0] == STRING_UTIL_CONFIRM_YES_U) return 1;