private static void ExecutedNewNoteCommand(object sender, ExecutedRoutedEventArgs e) { NotesView notesView = (NotesView)sender; NotebookPage page = (NotebookPage)e.Parameter; NotebookSection section = NoteDatabase.GetSection(page.SectionID); Notebook notebook = NoteDatabase.GetNotebook(section.NotebookID); if (notesView.SelectedNotebook == null) { notesView.AddNotebook(notebook, true); return; } if (notesView.SelectedSection == null) { notesView.AddSection(section, true); return; } if (notesView.SelectedPage == null) { notesView.AddPage(page, true); } else { notesView.AddPage(page); } }
public FlowDocument GetFlowDocument() { FlowDocument doc = (FlowDocument)Application.LoadComponent( new Uri("/Daytimer.DatabaseHelpers;component/Templates/NoteTemplate.xaml", UriKind.Relative)); NotebookSection section = NoteDatabase.GetSection(_page.SectionID); Notebook notebook = NoteDatabase.GetNotebook(section.NotebookID); ((Paragraph)doc.FindName("Title")).Inlines.Add(_page.Title); ((Paragraph)doc.FindName("Created")).Inlines.Add(FormatHelpers.FormatDate(_page.Created.Date) + " " + RandomFunctions.FormatTime(_page.Created.TimeOfDay)); ((Paragraph)doc.FindName("Notebook")).Inlines.Add(notebook.Title); ((Paragraph)doc.FindName("Section")).Inlines.Add(section.Title); Section details = (Section)doc.FindName("Details"); FlowDocument detailsDoc = _page.DetailsDocument; if (detailsDoc != null) { BlockCollection blocks = _page.DetailsDocument.Copy().Blocks; while (blocks.Count > 0) { details.Blocks.Add(blocks.FirstBlock); } } return(doc); }
private async void pageTabs_SelectionChanged(object sender, RoutedEventArgs e) { if (_ignorePageTabsChanged) { _ignorePageTabsChanged = false; return; } NotebookPage selectedPage = SelectedPage; NotebookSection selectedSection = SelectedSection; Notebook selectedNotebook = SelectedNotebook; FlowDocument doc = document.HasContentChanged ? document.Document.Copy() : null; FrameworkElement _sender = (FrameworkElement)sender; NotebookPage page = (NotebookPage)_sender.Tag; // If the Notes app bar is open to this note, close it. if (NotesAppBar.LastUsedNotesAppBar != null && NotesAppBar.LastUsedNotesAppBar.SelectedPage.ID == page.ID) { NotesAppBar.LastUsedNotesAppBar.Close(); } SelectedPage = page; document.Document.Blocks.Clear(); document.Document = await page.GetDetailsDocumentAsync(); pageTabsScroller.UpdateLayout(); pageTabsScroller.ScrollToVerticalPixel(_sender.TranslatePoint(new Point(0, 0), pageTabs).Y); await Save(selectedPage, selectedSection, selectedNotebook, doc); }
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 async Task Save(NotebookPage page, NotebookSection section, Notebook notebook, FlowDocument document) { if (page != null) { if (document != null) { await page.SetDetailsDocumentAsync(document); } await Task.Factory.StartNew(() => { page.LastModified = DateTime.UtcNow; NoteDatabase.UpdatePage(page); section.LastSelectedPageID = page.ID; section.LastModified = DateTime.UtcNow; NoteDatabase.UpdateSection(section); notebook.LastSelectedSectionID = section.ID; notebook.LastModified = DateTime.UtcNow; NoteDatabase.UpdateNotebook(notebook); Settings.LastOpenedNotebook = notebook.ID; }); } else { await Task.Factory.StartNew(() => { if (section != null) { section.LastSelectedPageID = ""; section.LastModified = DateTime.UtcNow; NoteDatabase.UpdateSection(section); } if (notebook != null) { if (section != null) { notebook.LastSelectedSectionID = section.ID; } else { notebook.LastSelectedSectionID = ""; } notebook.LastModified = DateTime.UtcNow; NoteDatabase.UpdateNotebook(notebook); Settings.LastOpenedNotebook = notebook.ID; } else { Settings.LastOpenedNotebook = ""; } }); } }
public string[] GetTextDocument() { NotebookSection section = NoteDatabase.GetSection(_page.SectionID); Notebook notebook = NoteDatabase.GetNotebook(section.NotebookID); return(new string[] { "Title:\t" + _page.Title, "Created:\t" + FormatHelpers.FormatDate(_page.Created.Date) + " " + RandomFunctions.FormatTime(_page.Created.TimeOfDay), "Notebook:\t" + notebook.Title, "Section:\t" + section.Title, "Details:\t" + _page.Details }); }
private async void notebookTabs_SelectionChanged(object sender, RoutedEventArgs e) { NotebookPage selectedPage = SelectedPage; NotebookSection selectedSection = SelectedSection; Notebook selectedNotebook = SelectedNotebook; FlowDocument doc = document.HasContentChanged ? document.Document.Copy() : null; _selectedNotebookTab = sender; LoadNotebook((Notebook)((FrameworkElement)sender).Tag); await Save(selectedPage, selectedSection, selectedNotebook, doc); }
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 async void sectionTabs_SelectionChanged(object sender, RoutedEventArgs e) { NotebookPage selectedPage = SelectedPage; NotebookSection selectedSection = SelectedSection; Notebook selectedNotebook = SelectedNotebook; FlowDocument doc = document.HasContentChanged ? document.Document.Copy() : null; _selectedSectionTab = sender; NotebookSection section = (NotebookSection)((FrameworkElement)sender).Tag; SelectedSection = section; pageTabs.Items.Clear(); IEnumerable <NotebookPage> pages = section.Pages; if (pages.GetEnumerator().MoveNext()) { _ignorePageTabsChanged = false; string selectedID = section.LastSelectedPageID; bool found = false; foreach (NotebookPage page in pages) { if (page.ID != selectedID) { AddPage(page); } else { AddPage(page, _createOnLoad ? false : true); found = true; } } if (!found) { ((ToggleButton)pageTabs.Items[0]).IsChecked = true; } } else { SelectedPage = null; ShowEmptySectionMessage(); } await Save(selectedPage, selectedSection, selectedNotebook, doc); }
/// <summary> /// Delete existing section /// </summary> /// <param name="section">The section to delete.</param> public static void Delete(NotebookSection section) { if (section != null) { List <NotebookPage> pages = new List <NotebookPage>(section.Pages); foreach (NotebookPage each in pages) { Delete(each); } Delete(section.ID); } }
private void flyout_Navigate(object sender, RoutedEventArgs e) { NotebookSection section = ((HiddenTabsFlyout)sender).SelectedSection; foreach (object each in sectionTabs.Items) { ToggleButton tb = each as ToggleButton; if (tb != null && tb.Tag == section) { tb.IsChecked = true; break; } } }
private void SectionDelete_Click(object sender, RoutedEventArgs e) { NotebookSection selectedSection = SelectedSection; NoteDatabase.Delete(selectedSection); SelectedSection = null; SelectedPage = null; foreach (object each in sectionTabs.Items) { RadioButton rb = each as RadioButton; if (rb != null && rb.Tag == selectedSection) { int index = sectionTabs.Items.IndexOf(each); sectionTabs.Items.Remove(each); if (sectionTabs.Items.Count > 2) { if (index > 0) { ((ToggleButton)sectionTabs.Items[index - 1]).IsChecked = true; } else { ((ToggleButton)sectionTabs.Items[0]).IsChecked = true; } } else { SelectedSection = null; SelectedPage = null; ShowEmptyNotebookMessage(); } break; } } if (NotesAppBar.LastUsedNotesAppBar != null && NotesAppBar.LastUsedNotesAppBar.SelectedSection.ID == selectedSection.ID) { NotesAppBar.LastUsedNotesAppBar.SelectedNotebook = null; NotesAppBar.LastUsedNotesAppBar.SelectedSection = null; NotesAppBar.LastUsedNotesAppBar.SelectedPage = null; NotesAppBar.LastUsedNotesAppBar.Close(); } }
/// <summary> /// Update the values on an existing section. /// </summary> /// <param name="section"></param> public static void UpdateSection(NotebookSection section) { if (section != null) { XmlElement elem = db.Doc.GetElementById(section.ID); if (elem != null) { elem.SetAttribute(TitleAttribute, section.Title); elem.SetAttribute(ColorAttribute, section.Color.ToString()); elem.SetAttribute(ReadOnlyAttribute, FormatHelpers.BoolToString(section.ReadOnly)); elem.SetAttribute(PrivateAttribute, FormatHelpers.BoolToString(section.Private)); elem.SetAttribute(LastModifiedAttribute, FormatHelpers.DateTimeToString(section.LastModified)); elem.SetAttribute(LastSelectedAttribute, section.LastSelectedPageID); } else { Add(section); } } }
public static NotebookSection GetSection(XmlNode node) { if (node == null) { return(null); } XmlAttributeCollection attribs = node.Attributes; NotebookSection section = new NotebookSection(false); section.ID = attribs[XmlDatabase.IdAttribute].Value; section.NotebookID = node.ParentNode.Attributes[XmlDatabase.IdAttribute].Value; section.Title = attribs[TitleAttribute].Value; section.Color = (Color)ColorConverter.ConvertFromString(attribs[ColorAttribute].Value); section.ReadOnly = FormatHelpers.ParseBool(attribs[ReadOnlyAttribute].Value); section.Private = FormatHelpers.ParseBool(attribs[PrivateAttribute].Value); section.LastModified = FormatHelpers.ParseDateTime(attribs[LastModifiedAttribute].Value); section.LastSelectedPageID = attribs[LastSelectedAttribute].Value; return(section); }
private void AddSection(NotebookSection section, bool openEdit = false) { RadioButton sec = new RadioButton(); Binding titleBinding = new Binding("Title"); titleBinding.Source = section; sec.SetBinding(ContentControl.ContentProperty, titleBinding); Binding colorBinding = new Binding("Color"); colorBinding.Source = section; colorBinding.Converter = new ColorToBrushConverter(); sec.SetBinding(BackgroundProperty, colorBinding); sec.Tag = section; sectionTabs.Items.Insert(sectionTabs.Items.Count - 2, sec); if (openEdit) { sec.IsChecked = true; } }
/// <summary> /// Add a new notebook. /// </summary> /// <param name="section"></param> /// <returns></returns> public static XmlElement Add(NotebookSection section) { if (!SectionExists(section)) { // // <n /> // XmlElement nt = db.Doc.CreateElement(SectionTag); nt.SetAttribute(XmlDatabase.IdAttribute, section.ID); nt.SetAttribute(TitleAttribute, section.Title); nt.SetAttribute(ColorAttribute, section.Color.ToString()); nt.SetAttribute(ReadOnlyAttribute, FormatHelpers.BoolToString(section.ReadOnly)); nt.SetAttribute(PrivateAttribute, FormatHelpers.BoolToString(section.Private)); nt.SetAttribute(LastModifiedAttribute, FormatHelpers.DateTimeToString(section.LastModified)); nt.SetAttribute(LastSelectedAttribute, section.LastSelectedPageID); db.Doc.GetElementById(section.NotebookID).AppendChild(nt); return(nt); } return(null); }
public void ScrollToNote(string id) { if (IsLoaded) { _scrollToNoteId = null; NotebookPage page = NoteDatabase.GetPage(id); NotebookSection section = NoteDatabase.GetSection(page.SectionID); Notebook notebook = NoteDatabase.GetNotebook(section.NotebookID); // // Step 1: Select notebook. // if (SelectedNotebook != notebook) { foreach (ToggleButton each in notebookTabs.Items) { if (((DatabaseObject)each.Tag).ID == notebook.ID) { each.IsChecked = true; break; } } } // // Step 2: Select section. // if (SelectedSection != section) { foreach (object each in sectionTabs.Items) { RadioButton rb = each as RadioButton; if (rb != null && ((DatabaseObject)rb.Tag).ID == section.ID) { rb.IsChecked = true; break; } } } // // Step 3: Select page. // if (SelectedPage != page) { foreach (ToggleButton each in pageTabs.Items) { if (((DatabaseObject)each.Tag).ID == page.ID) { each.IsChecked = true; break; } } } } else { _scrollToNoteId = id; } }
/// <summary> /// Gets if a specified section exists in the database. /// </summary> /// <param name="section"></param> /// <returns></returns> public static bool SectionExists(NotebookSection section) { return(db.Doc.GetElementById(section.ID) != null); }
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); } }