public override bool ChangeMode(Mode mode, bool saveChanges) { VisualUtils.LoseRegainFocus(); bool failedSave = false; if (saveChanges && VM.IsDirty) { VM.WriteToPersistent(); try { Globals.UI.SavePerson(VM.Persistent); if (BoxToLinkOnSave != null) { Globals.UI.WritePersonLink(new LinkInstruction { Link = LinkType.FromBoxToPerson, FromId = BoxToLinkOnSave.Value, ToId = VM.Persistent.Person.RowId }); BoxToLinkOnSave = null; } } catch (Exception ex) { failedSave = true; UIGlobals.Do.ShowTimedMessge("Cannot save: " + ex.Message); } VM.IsDirty = false; } VM.IsEditMode = mode == Mode.Edit || failedSave; return(!failedSave); }
public void SearchRequested() { VisualUtils.LoseRegainFocus(); var persons = Globals.UI.LoadFilteredPersons(VM.TermCri, VM.IncludeDetailsCri, VM.CatIdCri, false); VM.Results.Clear(); if (persons == null) { return; } foreach (var p in persons) { VM.Results.Add(new PersonSearchVM.ResultItem { PersonId = p.RowId, Name = p.Name }); } var searchBtn = VM.GetPreResultsControl?.Invoke(); if (searchBtn != null && persons.Length > 0) { VisualUtils.DelayThen(20, () => { searchBtn.Focus(); searchBtn.MoveFocus(new System.Windows.Input.TraversalRequest(System.Windows.Input.FocusNavigationDirection.Next)); }); } }
public override bool HandleCommand(CommandCenter.Item command) { if (command == Globals.Commands.OPEN) { if (LastFocusedBoxId < 0) { return(false); } var ebox = Globals.UI.LoadBoxForEditing(LastFocusedBoxId); if (ebox == null) { UIGlobals.Do.ShowTimedMessge("Cannot find task"); return(true); } UIGlobals.Do.AddBoxToEditStack(ebox); return(true); } if (command == Globals.Commands.CLOSE) { VisualUtils.LoseRegainFocus(); SaveChunks(); return(false); //caller can handle collapse } if (command == Globals.Commands.NEWLINKEDBOX) { NewTaskNearSelection(); } return(false); }
public void SearchRequested() { VisualUtils.LoseRegainFocus(); string doneSince = null; if (VM.DoneMode) { doneSince = VM.DoneSinceCri.Date; if (doneSince == null) { return; //must have done date in done mode } } var cachedBoxes = Globals.UI.LoadBoxesByKeyword(VM.TermCri, VM.IncludeDetailsCri, doneSince); VM.Results.Clear(); if (cachedBoxes == null) { return; } foreach (var cb in cachedBoxes) { VM.Results.Add(new BoxPreviewVM(new AgendaEntry { Box = cb, Time = cb.BoxTime }, null, ItemGotFocus)); } foreach (var vm in VM.Results) { vm.TimeClicked = HandleTimeClicked; } var searchBtn = VM.GetPreResultsControl?.Invoke(); if (searchBtn != null && cachedBoxes.Length > 0) { VisualUtils.DelayThen(20, () => { searchBtn.Focus(); searchBtn.MoveFocus(new System.Windows.Input.TraversalRequest(System.Windows.Input.FocusNavigationDirection.Next)); }); } }
public override bool HandleCommand(CommandCenter.Item command) { if (command == Globals.Commands.OPEN) { VM.IsEditMode = true; return(true); } if (command == Globals.Commands.ABANDON) { Globals.UI.AbandonBox(VM.Persistent.Person.RowId); CollapseRequested(this, VM.Persistent.Person.RowId == 0); UIGlobals.Do.ShowTimedMessge("Edits rolled back"); return(true); } if (command == Globals.Commands.ENDEDITS) { if (VM.IsEditMode) { ChangeMode(Mode.ReadOnly, true); return(true); } return(false); //ancestor will collapse block } if (command == Globals.Commands.CLOSE) { VisualUtils.LoseRegainFocus(); if (ChangeMode(Mode.ReadOnly, true)) { CollapseRequested(this, false); } return(true); } if (command == Globals.Commands.NEWLINKEDBOX) { //if not saved, save to get parent id if (VM.Persistent.Person.RowId == 0) { if (!ChangeMode(Mode.Edit, true)) { return(true); } } UIGlobals.Deferred.OnNewBox = new DeferredBehaviors.NewBoxBehavior { LinkedPersonId = VM.Persistent.Person.RowId }; UIGlobals.Do.HandleGlobalCommand(Globals.Commands.NEWITEM); return(true); } if (command == Globals.Commands.EDITLINKS) { UIGlobals.RecordLinkController.ActivateFor(this); return(true); } if (command == Globals.Commands.EDITCATEGORIES) { ChangeMode(Mode.Edit, false); if (CatMultiselectDialog.SelectCats(VM.Persistent)) { VM.IsDirty = true; VM.InitializeCatsFromPersistent(); } return(true); } if (command == Globals.Commands.SENDEMAIL) { if (!string.IsNullOrEmpty(VM.MainEmail)) { VisualUtils.ComposeEmailTo(VM.MainEmail); } return(true); } if (command == Globals.Commands.DELETEPERSON) { if (VM.Persistent.Person.RowId == 0) { UIGlobals.Do.HandleGlobalCommand(Globals.Commands.ABANDON); } else { if (MessageBox.Show(App.Current.MainWindow, $"Really permanently delete person ({VM.Name})?", "Systematizer", MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) { CollapseRequested(this, true); Globals.UI.DeletePerson(VM.Persistent.Person.RowId); } } return(true); } return(false); }