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); }
void ImportPeopleCSV_Click(object sender, RoutedEventArgs e) { //category to auto-apply long?autocCatId = CatSelectDialog.SelectCat("Choose category to apply to each imported person, or cancel to skip")?.RowId; string filename = AskForImportFileName(false); if (filename == null) { return; } var cvt = new CsvConverter(); try { using var rdr = new StreamReader(filename); var persons = cvt.PersonFromCsv(rdr).ToArray(); foreach (var person in persons) { var eperson = new ExtPerson(person, null, null); if (autocCatId != null) { eperson.SelectedCatIds = new long[] { autocCatId.Value } } ; Globals.UI.SavePerson(eperson); } VisualUtils.ShowMessageDialog($"Imported {persons.Length} record(s)"); } catch (Exception ex) { VisualUtils.ShowMessageDialog("Importing failed: " + ex.Message); } }
void ImportBoxesCSV_Click(object sender, RoutedEventArgs e) { string filename = AskForImportFileName(false); if (filename == null) { return; } var cvt = new CsvConverter(); try { using var rdr = new StreamReader(filename); var boxes = cvt.BoxFromCsv(rdr).ToArray(); foreach (var box in boxes) { Globals.UI.SaveBox(new ExtBox(box, null), false); } VisualUtils.ShowMessageDialog($"Imported {boxes.Length} record(s)"); } catch (Exception ex) { VisualUtils.ShowMessageDialog("Importing failed: " + ex.Message); } UIGlobals.Do.RebuildViews(BoxEditingPool.CreateUniversalChangeItem(), false); }
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)); }); } }
void Time_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var ctrl = (FrameworkElement)sender; var rowIdx = VisualUtils.IndexOfControlInItemsControl(Rows, ctrl); VM.MouseOpenRequested?.Invoke(ctrl, VM.Rows[rowIdx]); }
void RemoveEntry_Click(object sender, RoutedEventArgs e) { int itemIdx = VisualUtils.IndexOfControlInItemsControl(eEntries, (Button)sender); if (itemIdx >= 0) { VM.Entries.RemoveAt(itemIdx); } }
void Title_GotFocus(object sender, RoutedEventArgs e) { var rowIdx = VisualUtils.IndexOfControlInItemsControl(Rows, (DependencyObject)sender); if (rowIdx >= 0) { VM.ItemGotFocus?.Invoke(rowIdx); } ((TextBox)sender).SelectAll(); }
/// <summary> /// Write all lines to file and inform user /// </summary> static void WriteLinesTo(string writeToPath, IEnumerable <string> lines) { using (var stream = new StreamWriter(writeToPath)) { foreach (var line in lines) { stream.WriteLine(line); } stream.Flush(); } VisualUtils.ShowMessageDialog("Export completed"); }
void EditEntry_Click(object sender, RoutedEventArgs e) { int itemIdx = VisualUtils.IndexOfControlInItemsControl(eEntries, (Button)sender); if (itemIdx >= 0) { var entry = RepeatPatternDialog.ShowDialog(VM.Entries[itemIdx].Entry); if (entry != null) { VM.Entries.RemoveAt(itemIdx); VM.Entries.Insert(itemIdx, new RepeatInfoVM.EntryVM(entry)); } } }
public ExtBoxView() { InitializeComponent(); DataContextChanged += (s, e) => { if (VM == null) { return; } VM.GetMainControl = () => { return(VisualUtils.GetByUid(this, "eTitle") as TextBox); }; }; }
public TodayController(bool isToday, Action <BlockController> blockGotFocusHandler, Action <BlockController, bool> collapseRequested) : base(blockGotFocusHandler, collapseRequested) { IsToday = isToday; DateTime dt = DateTime.Now; if (!isToday) { dt = dt.AddDays(1); } string dateS = DateUtil.ToYMD(dt); Date = dateS; VM = new TodayVM(isToday, dateS, VMGotFocus); //hook up VM events VM.ChunkGotFocus = idx => { LastFocusedChunk = VM.Chunks[idx]; }; VM.RequestAddChunk = () => { VM.Chunks.Add(new TodayVM.ChunkVM(VM, UserRemovedChunk) { Title = VM.NewChunkTitle, IsDirty = true }); VM.NewChunkTitle = ""; }; VM.DropOnChunkRequested = (BoxDragInfo di, TodayVM.ChunkVM chunkVM) => { MoveBoxToChunk(di.Box, chunkVM, true); }; VM.FocusBarClicked = () => { VisualUtils.DelayThen(30, () => { VM.GetMainControl?.Invoke()?.Focus(); }); }; Refresh(null); }
void ExportHtml_Click(object sender, RoutedEventArgs e) { //what to export bool inclAllPersons = eIncludeAllPeople.IsChecked == true, inclCatPersons = eIncludeCatPeople.IsChecked == true, inclTasks = eIncludeSchedule.IsChecked == true, inclNotes = eIncludeNotes.IsChecked == true, inclPasswords = eIncludePasswords.IsChecked == true; //abort if not rational string message = null; if (inclCatPersons && CatId == null) { message = "Select a category before exporting"; } if (inclAllPersons && inclCatPersons) { message = "Choose one type of person export, not both"; } if (!inclAllPersons && !inclCatPersons && !inclTasks && !inclNotes) { message = "Select something to export"; } if (message != null) { VisualUtils.ShowMessageDialog(message); return; } //get filename string filename = AskForExportFileName(true); if (filename == null) { return; } //export HtmlExporter.ExportHtml(filename, inclAllPersons, inclCatPersons ? CatId : null, inclTasks, inclNotes, inclPasswords); VisualUtils.ShowMessageDialog("Export complete"); }
void FinishConstructor(ExtBox ebox, bool editMode) { VM = new ExtBoxVM(ebox, VMGotFocus, HandleCommand); if (editMode) { VM.IsEditMode = true; } //hook up VM events VM.FocusBarClicked = () => { ChangeMode(Mode.Edit, false); VisualUtils.DelayThen(10, () => { VM.GetMainControl?.Invoke()?.Focus(); }); }; VM.LinkClicked = linkItemVM => { UIGlobals.Do.OpenBlockFromLink(linkItemVM.Link, linkItemVM.OtherId); }; //handle deferred behaviors if (UIGlobals.Deferred.OnNewBox != null) { VM.ParentId = UIGlobals.Deferred.OnNewBox.ParentId; LinkToPersonIdOnSave = UIGlobals.Deferred.OnNewBox.LinkedPersonId; UIGlobals.Deferred.OnNewBox = null; } if (UIGlobals.Deferred.OnOpenBox != null) { if (UIGlobals.Deferred.OnOpenBox.MakeUndone) { VM.DoneDate = null; } UIGlobals.Deferred.OnOpenBox = null; } }
VM = new ExtPersonVM(ep, VMGotFocus) { CustomLabel1 = customLabel(0), CustomLabel2 = customLabel(1), CustomLabel3 = customLabel(2), CustomLabel4 = customLabel(3), CustomLabel5 = customLabel(4) }; if (editMode) { VM.IsEditMode = true; } //hook up VM events VM.FocusBarClicked = () => { ChangeMode(Mode.Edit, false); VisualUtils.DelayThen(10, () => { VM.GetMainControl?.Invoke()?.Focus(); }); }; VM.LinkClicked = linkItemVM => { UIGlobals.Do.OpenBlockFromLink(linkItemVM.Link, linkItemVM.OtherId); }; //handle deferred behaviors if (UIGlobals.Deferred.OnNewPerson != null) { BoxToLinkOnSave = UIGlobals.Deferred.OnNewPerson.LinkedBoxId; UIGlobals.Deferred.OnNewPerson = null; } //edit mode only for new record VM.IsEditMode = editMode || ep.Person.RowId == 0; }
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); }
void FocusNotes() { var ctrl = VisualUtils.GetByUid(this, "eNotes") as RichTextView; VisualUtils.DelayThen(20, () => ctrl?.FocusMainControl()); }
void FocusDate() { var ctrl = VisualUtils.GetByUid(this, "eDate") as DateView; VisualUtils.DelayThen(20, () => ctrl?.FocusMainControl()); }
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); } }