private void AddSection(bool rename = true) { if (SelectedNotebook == null) { AddNotebook(); return; } NotebookSection section = new NotebookSection(); section.NotebookID = SelectedNotebook.ID; section.Title = "New Section"; section.LastModified = DateTime.UtcNow; section.Color = NotesFunctions.GenerateSectionColor(); NoteDatabase.Add(section); AddSection(section, true); AddPage(); sectionTabs.UpdateLayout(); if (rename) { RenameActiveSection(); } }
private void NewNote(Notebook nb = null, NotebookSection ns = null, NotebookPage page = null) { if (page == null) { page = new NotebookPage(); page.Created = page.LastModified = DateTime.UtcNow; } if (nb == null) { string nbID = Settings.LastOpenedNotebook; if (nbID != null) { nb = NoteDatabase.GetNotebook(nbID); } if (nb == null) { nb = NoteDatabase.FirstNotebook(); } } if (nb == null) { nb = new Notebook(); nb.Title = "My Notebook"; nb.Color = NotesFunctions.GenerateNotebookColor(); NoteDatabase.Add(nb); } if (ns == null) { ns = NoteDatabase.GetSection(nb.LastSelectedSectionID); } if (ns == null) { ns = new NotebookSection(); ns.Title = "Quick Notes"; ns.NotebookID = nb.ID; ns.Color = NotesFunctions.GenerateSectionColor(); NoteDatabase.Add(ns); } page.SectionID = ns.ID; SelectedPage = page; SelectedSection = ns; SelectedNotebook = nb; }
private void AddNotebook() { Notebook notebook = new Notebook(); notebook.Title = "New Notebook"; notebook.LastModified = DateTime.UtcNow; notebook.Color = NotesFunctions.GenerateNotebookColor(); NoteDatabase.Add(notebook); AddNotebook(notebook, true); AddSection(false); RenameActiveNotebook(); }
private void createButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(titleTextBox.Text) && contentTextBox.Document.Blocks.Count == 0) { TaskDialog td = new TaskDialog( Application.Current.MainWindow, "Empty Note", "You are about to create a note with no title and no body.", MessageType.Information, true ); if (td.ShowDialog() != true) { return; } } NotebookPage page = new NotebookPage(); page.Title = titleTextBox.Text; page.DetailsDocument = contentTextBox.Document; page.Created = page.LastModified = DateTime.UtcNow; if (NotesView.LastUsedNotesView == null) { string nbID = Settings.LastOpenedNotebook; Notebook nb = null; if (nbID != null) { nb = NoteDatabase.GetNotebook(nbID); } if (nb == null) { nb = NoteDatabase.FirstNotebook(); } if (nb == null) { nb = new Notebook(); nb.Title = "My Notebook"; nb.Color = NotesFunctions.GenerateNotebookColor(); NoteDatabase.Add(nb); } NotebookSection ns = NoteDatabase.GetSection(nb.LastSelectedSectionID); if (ns == null) { ns = new NotebookSection(); ns.Title = "Quick Notes"; ns.NotebookID = nb.ID; ns.Color = NotesFunctions.GenerateSectionColor(); NoteDatabase.Add(ns); } page.SectionID = ns.ID; } else { Notebook nb = NotesView.LastUsedNotesView.SelectedNotebook; if (nb == null) { nb = new Notebook(); nb.Title = "My Notebook"; nb.Color = NotesFunctions.GenerateNotebookColor(); NoteDatabase.Add(nb); } NotebookSection ns = NotesView.LastUsedNotesView.SelectedSection; if (ns == null) { ns = new NotebookSection(); ns.Title = "Quick Notes"; ns.NotebookID = nb.ID; ns.Color = NotesFunctions.GenerateSectionColor(); NoteDatabase.Add(ns); } page.SectionID = ns.ID; } NoteDatabase.Add(page); titleTextBox.Clear(); contentTextBox.Document.Blocks.Clear(); if (NotesView.LastUsedNotesView != null) { NewNoteCommand.Execute(page, NotesView.LastUsedNotesView); } }