void HandleDoneCommand() { string userMessage = null; bool doCollapseBlock, doRemoveBlock = false, doMarkDone = false; //note we will save VM to persistent so we project using the correct repeats, but then we will modify the VM again VM.WriteToPersistent(); //handle repeated task projection if (VM.Persistent.Repeats != null) { var projector = new RepeatProjector(); string nextTime = projector.AdvanceTime(VM.Persistent.Box.BoxTime, VM.Persistent.Repeats); if (nextTime != null) { //reschedule but don't mark done VM.BoxTime_Date.Date = nextTime; VM.BoxTime_Time.Time = nextTime; userMessage = "Recheduled for " + DateUtil.ToReadableDate(nextTime, includeDOW: true); doCollapseBlock = true; } else { //reached the last instance of a repeated task doMarkDone = true; doCollapseBlock = true; } } else { doMarkDone = doCollapseBlock = doRemoveBlock = true; } //check if it is possible to really mark it done if (doMarkDone) { userMessage = "Task done!"; long boxId = VM.Persistent.Box.RowId; bool hasUndoneChildren = boxId > 0 && Globals.UI.CheckBoxesExist(parentRowId: boxId, filterByNotDone: true); if (hasUndoneChildren) { doMarkDone = false; doCollapseBlock = doRemoveBlock = false; userMessage = "Cannot complete task because it has child items that are not done"; } else if (VM.Importance == Constants.IMPORTANCE_HIGH) { if (!VisualUtils.Confirm("Careful: task is marked as 'keep-alive'. About to remove from calendar!")) { doMarkDone = false; doCollapseBlock = doRemoveBlock = false; userMessage = null; } } } if (doMarkDone) { VM.DoneDate = DateUtil.ToYMD(DateTime.Today); } if (doCollapseBlock) { bool saveOK = ChangeMode(Mode.ReadOnly, true); if (saveOK) { CollapseRequested(this, doRemoveBlock); } else { //edge case: save failed because it has no title, so create a title so it can be saved as done if (string.IsNullOrWhiteSpace(VM.Title)) { VM.Title = VM.IsUnclass ? "quick note" : "task"; saveOK = ChangeMode(Mode.ReadOnly, true); if (saveOK) { CollapseRequested(this, doRemoveBlock); } else { userMessage = "Saving failed, so cannot mark it as done"; } } } } if (userMessage != null) { UIGlobals.Do.ShowTimedMessge(userMessage); } }