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); }
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); } }
/// <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"); }
//true on success static bool CopyTemplateDatabaseTo(string fileName) { try { string fromPath = Path.Combine(Globals.UI.GetExeDirectory(), "template.sqlite"); File.Copy(fromPath, fileName); return(true); } catch (Exception ex) { VisualUtils.ShowMessageDialog("Error copying template database to the selected location: " + ex.Message); return(false); } }
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 HandleCreateFileCommand() { //if no template folder or if it's empty, explain to user how to use the command and abort bool found = false; string[] templateNames = null; string templatePath = Path.Combine(Globals.UI.GetExeDirectory(), "templates"); if (Directory.Exists(templatePath)) { var fullNames = Directory.GetFiles(templatePath); if (fullNames.Any()) { found = true; templateNames = fullNames.Select(s => Path.GetFileName(s)).ToArray(); } } if (!found) { VisualUtils.ShowMessageDialog("To use this feature, create a folder called 'Templates' in the application folder, and manually copy your templates into that folder."); return; } //get user choice, or if just 1, use that string templateName = templateNames[0]; //without path if (templateNames.Length > 1) { int idx = SelectDialog.SelectFromList(templateNames.ToList()); if (idx < 0) { return; } templateName = templateNames[idx]; } //find default starting path for target file string defaultPath = GetDefaultFolderPath(); //choose destination folder and name var saveDlg = new SaveFileDialog(); if (defaultPath != null) { saveDlg.InitialDirectory = defaultPath; } string ext = Path.GetExtension(templateName); saveDlg.Filter = ext + "|" + ext; if (saveDlg.ShowDialog(App.Current.MainWindow) != true) { return; } string targetName = saveDlg.FileName; //with path //copy file then open it File.Copy(Path.Combine(templatePath, templateName), targetName); VisualUtils.OpenWithWithDefaultApp(targetName); VM.NotifyVisibilityDetails(); }
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.Box.RowId); CollapseRequested(this, VM.Persistent.Box.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) { bool saveOK = ChangeMode(Mode.ReadOnly, true); if (!VM.IsUnclass && saveOK) { CollapseRequested(this, false); } return(true); } if (command == Globals.Commands.NEWLINKEDBOX) { //if not saved, save to get parent id if (VM.Persistent.Box.RowId == 0) { if (!ChangeMode(Mode.Edit, true)) { return(true); } } UIGlobals.Deferred.OnNewBox = new DeferredBehaviors.NewBoxBehavior { ParentId = VM.Persistent.Box.RowId }; UIGlobals.Do.HandleGlobalCommand(Globals.Commands.NEWITEM); } if (command == Globals.Commands.EDITLINKS) { UIGlobals.RecordLinkController.ActivateFor(this); } if (command == Globals.Commands.CLASSIFY) { HandleClassifyCommand(); return(true); } if (command == Globals.Commands.RESCHEDULE) { string newDate = RescheduleDialog.ShowDialog(VM.BoxTime_Date.Date); if (newDate != null) { VM.BoxTime_Date.Date = newDate; UIGlobals.Do.ShowTimedMessge("Rescheduled for " + DateUtil.ToReadableDate(newDate, includeDOW: true)); ChangeMode(Mode.ReadOnly, true); CollapseRequested(this, false); } return(true); } if (command == Globals.Commands.DONE) { HandleDoneCommand(); return(true); } if (command == Globals.Commands.IMPORTEXPORT) { var childIds = VM.Links.Items.Where(r => r.Link == LinkType.FromBoxToChildBox).Select(r => r.OtherId).ToArray(); if (childIds.Length == 0) { return(false); } ExportHtmlDialog.ShowExportDialog(childIds, null); return(true); } if (command == Globals.Commands.SELECTFOLDER) { var initialPath = GetDefaultFolderPath(); var dlg = new Ookii.Dialogs.Wpf.VistaFolderBrowserDialog(); if (initialPath != null) { dlg.SelectedPath = initialPath; } if (dlg.ShowDialog(App.Current.MainWindow) != true) { return(true); } VM.RefDir = dlg.SelectedPath; VM.NotifyVisibilityDetails(); return(true); } if (command == Globals.Commands.SELECTFILE) { var initialPath = GetDefaultFolderPath(); var dlg = new OpenFileDialog(); if (initialPath != null) { dlg.InitialDirectory = initialPath; } if (dlg.ShowDialog(App.Current.MainWindow) != true) { return(true); } VM.RefFile = dlg.FileName; VM.NotifyVisibilityDetails(); return(true); } if (command == Globals.Commands.OPENFOLDER) { if (!string.IsNullOrEmpty(VM.RefDir)) { VisualUtils.OpenWithWithDefaultApp(VM.RefDir); } return(true); } if (command == Globals.Commands.OPENFILE) { if (!string.IsNullOrEmpty(VM.RefFile)) { VisualUtils.OpenWithWithDefaultApp(VM.RefFile); } return(true); } if (command == Globals.Commands.CREATEFILE) { HandleCreateFileCommand(); return(true); } if (command == Globals.Commands.CAPTUREEMAIL) { string s = Clipboard.GetText(); if (string.IsNullOrEmpty(s)) { VisualUtils.ShowMessageDialog("No text found on clipboard. (From Thunderbird, use Ctrl-UAC to copy it."); return(true); } VM.RawEmail.Value = s; VM.NotifyVisibilityDetails(); UIGlobals.Do.ShowTimedMessge("Email captured"); return(true); } if (command == Globals.Commands.CLEAREMAIL) { VM.RawEmail.Value = null; VM.NotifyVisibilityDetails(); UIGlobals.Do.ShowTimedMessge("Email cleared"); return(true); } if (command == Globals.Commands.VIEWEMAIL) { //string s = Clipboard.GetText(); if (!VM.RawEmail.HasValue) { VisualUtils.ShowMessageDialog("No email was captured into this task."); return(true); } string filename = Path.Combine(Path.GetTempPath(), "systematizer.eml"); File.WriteAllText(filename, VM.RawEmail.Value); VisualUtils.OpenWithWithDefaultApp(filename); return(true); } if (command == Globals.Commands.NEWLINKEDPERSON) { if (VM.Persistent.Box.RowId == 0) { return(true); } UIGlobals.Deferred.OnNewPerson = new DeferredBehaviors.NewPersonBehavior { LinkedBoxId = VM.Persistent.Box.RowId }; UIGlobals.Do.HandleGlobalCommand(Globals.Commands.NEWPERSON); return(true); } return(false); }