Exemplo n.º 1
0
        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("");
        }
Exemplo n.º 2
0
 private void SetDefaultSelectedNotebook()
 {
     try
     {
         this.SelectedNotebook = NotebookViewModel.CreateAllNotesNotebook();
     }
     catch (Exception ex)
     {
         LogClient.Error("Could not set selected notebook. Exception: {0}", ex.Message);
     }
 }
Exemplo n.º 3
0
        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("");
        }