private void RefreshNotebooksAndNotes() { this.Notebooks = null; var localNotebooks = new ObservableCollection <NotebookViewModel>(); // Add the default notebooks localNotebooks.Add(NotebookViewModel.CreateAllNotesNotebook()); localNotebooks.Add(NotebookViewModel.CreateUnfiledNotesNotebook()); foreach (Notebook nb in this.noteService.GetNotebooks(ref this.totalNotebooks)) { localNotebooks.Add(new NotebookViewModel() { Notebook = nb, FontWeight = "Normal", IsDragOver = false }); } this.Notebooks = localNotebooks; // Because we cannot pass a Property by reference aboves OnPropertyChanged(() => this.TotalNotebooks); // Set the default selected notebook (Setting the selected notebook, triggers a refresh of the notes.) this.SetDefaultSelectedNotebook(); // This makes sure the View is notified that the Notebooks collection has changed. // If this call is missing, the list of Notebooks is not updated in the View after // we changed its elements here. OnPropertyChanged("Notebooks") this.eventAggregator.GetEvent <NotebooksChangedEvent>().Publish(""); }
private void NewNote(object param) { bool createUnfiled = Convert.ToBoolean(param); try { string initialTitle = this.noteService.GetUniqueNoteTitle(ResourceUtils.GetString("Language_New_Note")); FlowDocument flowDoc = new FlowDocument(); Notebook theNotebook = default(Notebook); if (!createUnfiled & (this.SelectedNotebook != null && !this.SelectedNotebook.IsDefaultNotebook)) { theNotebook = this.SelectedNotebook.Notebook; } else { theNotebook = NotebookViewModel.CreateUnfiledNotesNotebook().Notebook; } NoteWindow notewin = new NoteWindow(initialTitle, "", theNotebook, this.searchService.SearchText, true, this.appearanceService, this.jumpListService, this.eventAggregator, this.noteService, this.dialogService); notewin.ActivateNow(); RefreshNotes(); } catch (Exception) { this.dialogService.ShowNotificationDialog(null, title: ResourceUtils.GetString("Language_Error"), content: ResourceUtils.GetString("Language_Problem_Creating_Note"), okText: ResourceUtils.GetString("Language_Ok"), showViewLogs: false); } }
private void SetDefaultSelectedNotebook() { try { this.SelectedNotebook = NotebookViewModel.CreateAllNotesNotebook(); } catch (Exception ex) { LogClient.Error("Could not set selected notebook. Exception: {0}", ex.Message); } }
private void NewNotebook() { this.selectedNotebook = null; string responseText = string.Empty; bool dialogResult = this.dialogService.ShowInputDialog(null, title: ResourceUtils.GetString("Language_New_Notebook"), content: ResourceUtils.GetString("Language_New_Notebook_Enter_Name"), okText: ResourceUtils.GetString("Language_Ok"), cancelText: ResourceUtils.GetString("Language_Cancel"), responeText: ref responseText); if (dialogResult) { if (!string.IsNullOrEmpty(responseText)) { Notebook newNotebook = new Notebook { Id = Guid.NewGuid().ToString(), Title = responseText, CreationDate = DateTime.Now.Ticks, IsDefaultNotebook = false }; try { if (!this.noteService.NotebookExists(newNotebook)) { this.noteService.NewNotebook(newNotebook); this.RefreshNotebooksAndNotes(); this.SelectedNotebook = new NotebookViewModel { Notebook = new Notebook { Id = newNotebook.Id, Title = newNotebook.Title, CreationDate = DateTime.Now.Ticks } }; } else { this.dialogService.ShowNotificationDialog(null, title: ResourceUtils.GetString("Language_Error"), content: ResourceUtils.GetString("Language_Already_Notebook_With_That_Name"), okText: ResourceUtils.GetString("Language_Ok"), showViewLogs: false); } } catch (Exception) { this.dialogService.ShowNotificationDialog(null, title: ResourceUtils.GetString("Language_Error"), content: ResourceUtils.GetString("Language_Problem_Creating_Notebook"), okText: ResourceUtils.GetString("Language_Ok"), showViewLogs: false); } } else { this.dialogService.ShowNotificationDialog(null, title: ResourceUtils.GetString("Language_Error"), content: ResourceUtils.GetString("Language_Notebook_Needs_Name"), okText: ResourceUtils.GetString("Language_Ok"), showViewLogs: false); } } }
private void RefreshNotes() { this.Notes = new ObservableCollection <NoteViewModel>(); string formatDate = "D"; string text = ""; if (this.searchService.SearchText != null) { text = this.searchService.SearchText.Trim(); } this.Notes.Clear(); NotebookViewModel selectedNotebook = this.SelectedNotebook != null ? this.SelectedNotebook : NotebookViewModel.CreateAllNotesNotebook(); var notes = this.noteService.GetNotes(selectedNotebook.Notebook, text, ref this.total, SettingsClient.Get <bool>("Appearance", "SortByModificationDate"), this.NoteFilter); foreach (Note note in notes) { this.Notes.Add(new NoteViewModel() { Title = note.Title, Id = note.Id, NotebookId = note.NotebookId, OpenDate = new DateTime(note.OpenDate), OpenDateText = DateUtils.DateDifference(new DateTime(note.OpenDate), DateTime.Now, formatDate, false), ModificationDate = new DateTime(note.ModificationDate), Flagged = note.Flagged == 1 ? true : false, ModificationDateText = DateUtils.DateDifference(new DateTime(note.ModificationDate), DateTime.Now, formatDate, false), ModificationDateTextSimple = DateUtils.DateDifference(new DateTime(note.ModificationDate), DateTime.Now, formatDate, !SettingsClient.Get <bool>("Notes", "UseExactDates")) }); } // Because we cannot pass Property "Total" by reference, we need to force a refresh. OnPropertyChanged <int>(() => this.Total); this.eventAggregator.GetEvent <CountNotesEvent>().Publish(""); }
private void SetDefaultSelectedNotebook() { try { // Set the backing field, this avoid unnecessary refresh of the notes. this.selectedNotebook = new NotebookViewModel { Notebook = new Notebook { Title = ResourceUtils.GetStringResource("Language_All_Notes"), Id = "0", CreationDate = DateTime.Now.Ticks, IsDefaultNotebook = true } }; OnPropertyChanged(() => this.SelectedNotebook); } catch (Exception ex) { LogClient.Error("Could not set selected notebook. Exception: {0}", ex.Message); } }