From 9360bd577f63e8657a0adaf19e264e99abe2bce1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 19 Jul 2015 20:23:10 -0400 Subject: [PATCH] Feature: Editing failure stops all editing of multiple tasks - Thanks to Daniel Shahaf. --- ChangeLog | 2 ++ src/commands/CmdEdit.cpp | 26 ++++++++++++++++++++------ src/commands/CmdEdit.h | 3 ++- src/l10n/deu-DEU.h | 2 +- src/l10n/eng-USA.h | 2 +- src/l10n/epo-RUS.h | 2 +- src/l10n/esp-ESP.h | 2 +- src/l10n/fra-FRA.h | 2 +- src/l10n/ita-ITA.h | 2 +- src/l10n/jpn-JPN.h | 2 +- src/l10n/pol-POL.h | 2 +- src/l10n/por-PRT.h | 2 +- 12 files changed, 33 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0444a15f7..375091edd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -84,6 +84,8 @@ - "import" can now import JSON arrays, the new default "export" output. - The '_tags' helper command now includes virtual tags (thanks to Daniel Shahaf). + -When multiple tasks are 'edit'ed, a failure causes the editing to stop (thanks + to Daniel Shahaf). ------ current release --------------------------- diff --git a/src/commands/CmdEdit.cpp b/src/commands/CmdEdit.cpp index 07362330e..12a705a28 100644 --- a/src/commands/CmdEdit.cpp +++ b/src/commands/CmdEdit.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -68,8 +69,13 @@ int CmdEdit::execute (std::string& output) // Find number of matching tasks. for (auto& task : filtered) - if (editFile (task)) + { + CmdEdit::editResult result = editFile (task); + if (result == CmdEdit::editResult::error) + break; + else if (result == CmdEdit::editResult::changes) context.tdb2.modify (task); + } return 0; } @@ -730,7 +736,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string } //////////////////////////////////////////////////////////////////////////////// -bool CmdEdit::editFile (Task& task) +CmdEdit::editResult CmdEdit::editFile (Task& task) { // Check for file permissions. Directory location (context.config.get ("data.location")); @@ -775,10 +781,16 @@ ARE_THESE_REALLY_HARMFUL: // Launch the editor. std::cout << format (STRING_EDIT_LAUNCHING, editor) << "\n"; - if (-1 == system (editor.c_str ())) - std::cout << STRING_EDIT_NO_EDITS << "\n"; - else + int exitcode = system (editor.c_str ()); + if (0 == exitcode) std::cout << STRING_EDIT_COMPLETE << "\n"; + else + { + std::cout << format (STRING_EDIT_FAILED, exitcode) << "\n"; + if (-1 == exitcode) + std::cout << std::strerror (errno) << "\n"; + return CmdEdit::editResult::error; + } // Slurp file. std::string after; @@ -826,7 +838,9 @@ ARE_THESE_REALLY_HARMFUL: // Cleanup. File::remove (file.str ()); ignored = chdir (current_dir.c_str ()); - return changes; + return changes + ? CmdEdit::editResult::changes + : CmdEdit::editResult::nochanges; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdEdit.h b/src/commands/CmdEdit.h index fccaf1790..a98dddb43 100644 --- a/src/commands/CmdEdit.h +++ b/src/commands/CmdEdit.h @@ -45,7 +45,8 @@ private: std::string formatDuration (Task&, const std::string&); std::string formatTask (Task, const std::string&); void parseTask (Task&, const std::string&, const std::string&); - bool editFile (Task&); + enum class editResult { error, changes, nochanges }; + editResult editFile (Task&); }; #endif diff --git a/src/l10n/deu-DEU.h b/src/l10n/deu-DEU.h index 6575c2957..8b33c84f5 100644 --- a/src/l10n/deu-DEU.h +++ b/src/l10n/deu-DEU.h @@ -667,7 +667,7 @@ // edit #define STRING_EDIT_NO_CHANGES "Keine Änderungen entdeckt." -#define STRING_EDIT_NO_EDITS "Keine Änderungen ausgeführt." +#define STRING_EDIT_FAILED "Editing failed with exit code {1}." #define STRING_EDIT_COMPLETE "Bearbeitung abgeschlossen." #define STRING_EDIT_LAUNCHING "Starte jetzt '{1}'..." #define STRING_EDIT_CHANGES "Änderungen entdeckt." diff --git a/src/l10n/eng-USA.h b/src/l10n/eng-USA.h index adbd42eb8..b08da5afa 100644 --- a/src/l10n/eng-USA.h +++ b/src/l10n/eng-USA.h @@ -667,7 +667,7 @@ // edit #define STRING_EDIT_NO_CHANGES "No edits were detected." -#define STRING_EDIT_NO_EDITS "No editing performed." +#define STRING_EDIT_FAILED "Editing failed with exit code {1}." #define STRING_EDIT_COMPLETE "Editing complete." #define STRING_EDIT_LAUNCHING "Launching '{1}' now..." #define STRING_EDIT_CHANGES "Edits were detected." diff --git a/src/l10n/epo-RUS.h b/src/l10n/epo-RUS.h index c2c22553d..8c56fd683 100644 --- a/src/l10n/epo-RUS.h +++ b/src/l10n/epo-RUS.h @@ -667,7 +667,7 @@ // edit #define STRING_EDIT_NO_CHANGES "Ne detektis nenian redakton." -#define STRING_EDIT_NO_EDITS "Ne redaktis nenion." +#define STRING_EDIT_FAILED "Editing failed with exit code {1}." #define STRING_EDIT_COMPLETE "Redaktis komplete." #define STRING_EDIT_LAUNCHING "Lanĉanta nun '{1}'..." #define STRING_EDIT_CHANGES "Detektis redaktojn." diff --git a/src/l10n/esp-ESP.h b/src/l10n/esp-ESP.h index c1c18b6b9..01607cce2 100644 --- a/src/l10n/esp-ESP.h +++ b/src/l10n/esp-ESP.h @@ -679,7 +679,7 @@ // edit #define STRING_EDIT_NO_CHANGES "No se detectaron modificaciones." -#define STRING_EDIT_NO_EDITS "No se realizó edición." +#define STRING_EDIT_FAILED "Editing failed with exit code {1}." #define STRING_EDIT_COMPLETE "Edición completada." #define STRING_EDIT_LAUNCHING "Lanzando '{1}' ahora..." #define STRING_EDIT_CHANGES "Se detectaron modificaciones." diff --git a/src/l10n/fra-FRA.h b/src/l10n/fra-FRA.h index c4cb66cdc..9aff5a244 100644 --- a/src/l10n/fra-FRA.h +++ b/src/l10n/fra-FRA.h @@ -667,7 +667,7 @@ // edit #define STRING_EDIT_NO_CHANGES "Aucunes modifications détectées." -#define STRING_EDIT_NO_EDITS "Aucune modification appliquée." +#define STRING_EDIT_FAILED "Editing failed with exit code {1}." #define STRING_EDIT_COMPLETE "Édition terminée." #define STRING_EDIT_LAUNCHING "Lancement de '{1}' maintenant..." #define STRING_EDIT_CHANGES "Des modifications ont été détectées." diff --git a/src/l10n/ita-ITA.h b/src/l10n/ita-ITA.h index 3e3d8250a..5ae85a7bc 100644 --- a/src/l10n/ita-ITA.h +++ b/src/l10n/ita-ITA.h @@ -666,7 +666,7 @@ // edit #define STRING_EDIT_NO_CHANGES "Nessuna modifica riscontrata." -#define STRING_EDIT_NO_EDITS "Nessuna modifica effettuata." +#define STRING_EDIT_FAILED "Editing failed with exit code {1}." #define STRING_EDIT_COMPLETE "Modifica completa." #define STRING_EDIT_LAUNCHING "Esecuzione di '{1}' ora..." #define STRING_EDIT_CHANGES "Modifiche rilevate." diff --git a/src/l10n/jpn-JPN.h b/src/l10n/jpn-JPN.h index d34b7407f..c37dc6cda 100644 --- a/src/l10n/jpn-JPN.h +++ b/src/l10n/jpn-JPN.h @@ -667,7 +667,7 @@ // edit #define STRING_EDIT_NO_CHANGES "No edits were detected." -#define STRING_EDIT_NO_EDITS "No editing performed." +#define STRING_EDIT_FAILED "Editing failed with exit code {1}." #define STRING_EDIT_COMPLETE "Editing complete." #define STRING_EDIT_LAUNCHING "Launching '{1}' now..." #define STRING_EDIT_CHANGES "Edits were detected." diff --git a/src/l10n/pol-POL.h b/src/l10n/pol-POL.h index e2f022d7a..2c1cc4a89 100644 --- a/src/l10n/pol-POL.h +++ b/src/l10n/pol-POL.h @@ -667,7 +667,7 @@ // edit #define STRING_EDIT_NO_CHANGES "Nie znaleziono żadnych edycji." -#define STRING_EDIT_NO_EDITS "Nie wykonano żadnych edycji" +#define STRING_EDIT_FAILED "Editing failed with exit code {1}." #define STRING_EDIT_COMPLETE "Edycja zakończona." #define STRING_EDIT_LAUNCHING "Uruchamianie '{1}'..." #define STRING_EDIT_CHANGES "Zmiany wykryte." diff --git a/src/l10n/por-PRT.h b/src/l10n/por-PRT.h index 0a31fe41d..e03f1add1 100644 --- a/src/l10n/por-PRT.h +++ b/src/l10n/por-PRT.h @@ -667,7 +667,7 @@ // edit #define STRING_EDIT_NO_CHANGES "Não foram detetadas alterações." -#define STRING_EDIT_NO_EDITS "Nada editado." +#define STRING_EDIT_FAILED "Editing failed with exit code {1}." #define STRING_EDIT_COMPLETE "Edição concluída." #define STRING_EDIT_LAUNCHING "A iniciar '{1}' ..." #define STRING_EDIT_CHANGES "Alterações detetadas."