diff --git a/src/Cmd.cpp b/src/Cmd.cpp index ee6a1760c..560babffa 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -107,13 +107,11 @@ void Cmd::loadCommands () { if (commands.size () == 0) { - commands.push_back (context.stringtable.get (CMD_ACTIVE, "active")); commands.push_back (context.stringtable.get (CMD_ADD, "add")); commands.push_back (context.stringtable.get (CMD_APPEND, "append")); commands.push_back (context.stringtable.get (CMD_ANNOTATE, "annotate")); commands.push_back (context.stringtable.get (CMD_CALENDAR, "calendar")); commands.push_back (context.stringtable.get (CMD_COLORS, "colors")); - commands.push_back (context.stringtable.get (CMD_COMPLETED, "completed")); commands.push_back (context.stringtable.get (CMD_DELETE, "delete")); commands.push_back (context.stringtable.get (CMD_DONE, "done")); commands.push_back (context.stringtable.get (CMD_DUPLICATE, "duplicate")); @@ -125,7 +123,6 @@ void Cmd::loadCommands () commands.push_back (context.stringtable.get (CMD_IMPORT, "import")); commands.push_back (context.stringtable.get (CMD_INFO, "info")); commands.push_back (context.stringtable.get (CMD_NEXT, "next")); - commands.push_back (context.stringtable.get (CMD_OVERDUE, "overdue")); commands.push_back (context.stringtable.get (CMD_PROJECTS, "projects")); commands.push_back (context.stringtable.get (CMD_START, "start")); commands.push_back (context.stringtable.get (CMD_STATS, "stats")); @@ -176,23 +173,21 @@ void Cmd::allCustomReports (std::vector & all) const // Commands that do not directly modify the data files. bool Cmd::isReadOnlyCommand () { - if (command == context.stringtable.get (CMD_ACTIVE, "active") || // R - command == context.stringtable.get (CMD_CALENDAR, "calendar") || // R - command == context.stringtable.get (CMD_COLORS, "colors") || // R - command == context.stringtable.get (CMD_COMPLETED, "completed") || // R - command == context.stringtable.get (CMD_EXPORT, "export") || // R - command == context.stringtable.get (CMD_HELP, "help") || // R - command == context.stringtable.get (CMD_HISTORY, "history") || // R - command == context.stringtable.get (CMD_GHISTORY, "ghistory") || // R - command == context.stringtable.get (CMD_INFO, "info") || // R - command == context.stringtable.get (CMD_NEXT, "next") || // R - command == context.stringtable.get (CMD_OVERDUE, "overdue") || // R - command == context.stringtable.get (CMD_PROJECTS, "projects") || // R - command == context.stringtable.get (CMD_STATS, "stats") || // R - command == context.stringtable.get (CMD_SUMMARY, "summary") || // R - command == context.stringtable.get (CMD_TAGS, "tags") || // R - command == context.stringtable.get (CMD_TIMESHEET, "timesheet") || // R - command == context.stringtable.get (CMD_VERSION, "version")) // R + if (command == context.stringtable.get (CMD_CALENDAR, "calendar") || + command == context.stringtable.get (CMD_COLORS, "colors") || + command == context.stringtable.get (CMD_EXPORT, "export") || + command == context.stringtable.get (CMD_HELP, "help") || + command == context.stringtable.get (CMD_HISTORY, "history") || + command == context.stringtable.get (CMD_GHISTORY, "ghistory") || + command == context.stringtable.get (CMD_INFO, "info") || + command == context.stringtable.get (CMD_NEXT, "next") || + command == context.stringtable.get (CMD_PROJECTS, "projects") || + command == context.stringtable.get (CMD_STATS, "stats") || + command == context.stringtable.get (CMD_SUMMARY, "summary") || + command == context.stringtable.get (CMD_TAGS, "tags") || + command == context.stringtable.get (CMD_TIMESHEET, "timesheet") || + command == context.stringtable.get (CMD_VERSION, "version") || + validCustom (command)) return true; return false; @@ -202,18 +197,18 @@ bool Cmd::isReadOnlyCommand () // Commands that directly modify the data files. bool Cmd::isWriteCommand () { - if (command == context.stringtable.get (CMD_ADD, "add") || // W - command == context.stringtable.get (CMD_APPEND, "append") || // W - command == context.stringtable.get (CMD_ANNOTATE, "annotate") || // W - command == context.stringtable.get (CMD_DELETE, "delete") || // W - command == context.stringtable.get (CMD_DONE, "done") || // W - command == context.stringtable.get (CMD_DUPLICATE, "duplicate") || // W - command == context.stringtable.get (CMD_EDIT, "edit") || // W - command == context.stringtable.get (CMD_IMPORT, "import") || // W - command == context.stringtable.get (CMD_START, "start") || // W - command == context.stringtable.get (CMD_STOP, "stop") || // W - command == context.stringtable.get (CMD_UNDELETE, "undelete") || // W - command == context.stringtable.get (CMD_UNDO, "undo")) // W + if (command == context.stringtable.get (CMD_ADD, "add") || + command == context.stringtable.get (CMD_APPEND, "append") || + command == context.stringtable.get (CMD_ANNOTATE, "annotate") || + command == context.stringtable.get (CMD_DELETE, "delete") || + command == context.stringtable.get (CMD_DONE, "done") || + command == context.stringtable.get (CMD_DUPLICATE, "duplicate") || + command == context.stringtable.get (CMD_EDIT, "edit") || + command == context.stringtable.get (CMD_IMPORT, "import") || + command == context.stringtable.get (CMD_START, "start") || + command == context.stringtable.get (CMD_STOP, "stop") || + command == context.stringtable.get (CMD_UNDELETE, "undelete") || + command == context.stringtable.get (CMD_UNDO, "undo")) return true; return false; diff --git a/src/Context.cpp b/src/Context.cpp index 39cb46338..6bb4ee418 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -49,6 +49,7 @@ Context::Context () , stringtable () , program ("") , cmd () +, inShadow (false) { // Set up randomness. #ifdef HAVE_SRANDOM @@ -158,61 +159,57 @@ int Context::run () //////////////////////////////////////////////////////////////////////////////// std::string Context::dispatch () { - bool gc = true; // TODO Should be false for shadow file updates. - - bool gcMod = false; // Change occurred by way of gc. - bool cmdMod = false; // Change occurred by way of command type. + int gcMod = 0; // Change occurred by way of gc. std::string out; -/* // Read-only commands with no side effects. - if (command == "export") { out = handleExport (); } +/* + if (cmd.command == "export") { out = handleExport (); } */ - if (cmd.command == "projects") { out = handleProjects (); } - else if (cmd.command == "tags") { out = handleTags (); } - else if (cmd.command == "colors") { out = handleColor (); } - else if (cmd.command == "version") { out = handleVersion (); } - else if (cmd.command == "help") { out = longUsage (); } + if (cmd.command == "projects") { out = handleProjects (); } + else if (cmd.command == "tags") { out = handleTags (); } + else if (cmd.command == "colors") { out = handleColor (); } + else if (cmd.command == "version") { out = handleVersion (); } + else if (cmd.command == "help") { out = longUsage (); } else if (cmd.command == "stats") { out = handleReportStats (); } /* - else if (command == "info") { out = handleInfo (); } - else if (command == "history") { out = handleReportHistory (); } - else if (command == "ghistory") { out = handleReportGHistory (); } - else if (command == "calendar") { out = handleReportCalendar (); } - else if (command == "summary") { out = handleReportSummary (); } - else if (command == "timesheet") { out = handleReportTimesheet (); } + else if (cmd.command == "info") { out = handleInfo (); } + else if (cmd.command == "history") { out = handleReportHistory (); } + else if (cmd.command == "ghistory") { out = handleReportGHistory (); } + else if (cmd.command == "calendar") { out = handleReportCalendar (); } + else if (cmd.command == "summary") { out = handleReportSummary (); } + else if (cmd.command == "timesheet") { out = handleReportTimesheet (); } */ // Commands that cause updates. - else if (cmd.command == "add") { cmdMod = true; out = handleAdd (); } + else if (cmd.command == "add") { out = handleAdd (); } /* - else if (command == "" && task.getId ()) { cmdMod = true; out = handleModify (); } - else if (command == "append") { cmdMod = true; out = handleAppend (); } - else if (command == "annotate") { cmdMod = true; out = handleAnnotate (); } - else if (command == "done") { cmdMod = true; out = handleDone (); } - else if (command == "undelete") { cmdMod = true; out = handleUndelete (); } - else if (command == "delete") { cmdMod = true; out = handleDelete (); } - else if (command == "start") { cmdMod = true; out = handleStart (); } - else if (command == "stop") { cmdMod = true; out = handleStop (); } - else if (command == "undo") { cmdMod = true; out = handleUndo (); } - else if (command == "import") { cmdMod = true; out = handleImport (); } - else if (command == "duplicate") { cmdMod = true; out = handleDuplicate (); } - else if (command == "edit") { cmdMod = true; out = handleEdit (); } + else if (command == "" && task.getId ()) { out = handleModify (); } + else if (command == "append") { out = handleAppend (); } + else if (command == "annotate") { out = handleAnnotate (); } + else if (command == "done") { out = handleDone (); } + else if (command == "undelete") { out = handleUndelete (); } + else if (command == "delete") { out = handleDelete (); } + else if (command == "start") { out = handleStart (); } + else if (command == "stop") { out = handleStop (); } + else if (command == "undo") { out = handleUndo (); } + else if (command == "import") { out = handleImport (); } + else if (command == "duplicate") { out = handleDuplicate (); } + else if (command == "edit") { out = handleEdit (); } */ // Command that display IDs and therefore need TDB::gc first. /* - else if (command == "next") { if (gc) gcMod = tdb.gc (); out = handleReportNext (); } + else if (command == "next") { if (!inShadow) gcMod = tdb.gc (); out = handleReportNext (); } */ - else if (cmd.validCustom (cmd.command)) { if (gc) gcMod = tdb.gc (); out = handleCustomReport (cmd.command); } + else if (cmd.validCustom (cmd.command)) { if (!inShadow) gcMod = tdb.gc (); out = handleCustomReport (cmd.command); } // If the command is not recognized, display usage. else { out = shortUsage (); } // Only update the shadow file if such an update was not suppressed (shadow), - // and if an actual change occurred (gcMod || cmdMod). // TODO -// if (shadow && (gcMod || cmdMod)) +// if (cmd.isWriteCommand (cmd.command) && !inShadow)) // shadow (); return out; @@ -225,6 +222,8 @@ void Context::shadow () std::string shadowFile = expandPath (config.get ("shadow.file")); if (shadowFile != "") { + inShadow = true; // Prevents recursion in case shadow command writes. + // TODO Reinstate these checks. /* // Check for silly shadow file settings. @@ -267,6 +266,8 @@ void Context::shadow () // Optionally display a notification that the shadow file was updated. if (config.get (std::string ("shadow.notify"), false)) footnote (std::string ("[Shadow file '") + shadowFile + "' updated]"); + + inShadow = false; } } diff --git a/src/Context.h b/src/Context.h index 422cd210d..b63669482 100644 --- a/src/Context.h +++ b/src/Context.h @@ -78,6 +78,7 @@ public: private: std::vector messages; std::vector footnotes; + bool inShadow; }; #endif