protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); this.Note = e.Parameter as Note; var backStack = Frame.BackStack; var backStackCount = backStack.Count; if (backStackCount > 0) { var masterPageEntry = backStack[backStackCount - 1]; backStack.RemoveAt(backStackCount - 1); // Doctor the navigation parameter for the master page so it // will show the correct item in the side-by-side view. var modifiedEntry = new PageStackEntry( masterPageEntry.SourcePageType, this.Note.Name, masterPageEntry.NavigationTransitionInfo); backStack.Add(modifiedEntry); } // Register for hardware and software back request from the system SystemNavigationManager.GetForCurrentView().BackRequested += DetailPage_BackRequested; }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); bool isFolderSet = await Settings.GetStorageFolderAsync() != null; if (isFolderSet) { this.Message.Visibility = Visibility.Collapsed; await NoteManager.TryReadAllFromStorageAsync(); if (e.Parameter != null) { // Parameter is item name var name = (string)e.Parameter; this.selectedNote = this.notes.GetByName(name); } this.SelectMostAppropriateNote(); this.UpdateForVisualState(AdaptiveStates.CurrentState); VisualStateManager.GoToState(this, this.MasterState.Name, true); // Don't play a content transition for first item load. // Sometimes, this content will be animated as part of the page transition. this.DisableContentTransitions(); VisualStateManager.GoToState(this, this.MasterState.Name, true); } else { this.Message.Visibility = Visibility.Visible; VisualStateManager.GoToState(this, this.NoFolderState.Name, true); } }
private static async Task MergeFileIntoNote(StorageFile file, Note note) { note.DateCreated = file.DateCreated.LocalDateTime; BasicProperties properties = await file.GetBasicPropertiesAsync(); note.DateModified = properties.DateModified.LocalDateTime; note.Name = file.Name; note.Text = await FileIO.ReadTextAsync(file); note.MarkAsClean(); }
public static async Task WriteToStorageAsync(Note note) { if (note.IsDirty) { var save = StorageManager.SaveFileAsync(note.Name, note.Text); note.MarkAsClean(); await save; note.DateModified = DateTime.Now; } }
public static async Task RenameNoteAsync(Note note, string desiredName) { // It's possible that desiredName is null or empty. It's no big deal... just don't // do anything try { note.Name = await StorageManager.RenameFileAsync(note.Name, desiredName); ; Notes.Remove(note as Note); Notes.InsertInOrder(note as Note); } catch { } }
private void SelectMostAppropriateNote() { if (this.notes.Count > 0) { if (this.selectedNote != null && !this.MasterListView.Items.Contains(this.selectedNote)) { // If we're navigating back to this page then we reload all the notes from disk in which // case we will have new references. this.selectedNote = this.notes.Where(n => n.Name == this.selectedNote.Name).FirstOrDefault(); } if (this.selectedNote == null) { this.selectedNote = this.notes[0]; } this.MasterListView.SelectedItem = this.selectedNote; } }
public static async Task TryReadAllFromStorageAsync() { // Sometimes other saves will be going on. And we have a reasonably // aggressive reload strategy going on - so rather than deal with // serious marshalling just try it and don't worry too much try { var files = await StorageManager.LoadFilesAsync(); // Ensure all files are in notes and up to date foreach (var file in files) { var note = Notes.GetByName(file.Name); if (note == null) { note = new Note { Name = file.Name }; Notes.InsertInOrder(note); } await MergeFileIntoNote(file, note); } // Now ensure that any notes NOT in a file is removed for (int index = 0; index < Notes.Count; index++) { var note = Notes[index]; var file = files.Where(f => f.Name == note.Name).FirstOrDefault(); if (file == null) { Notes.RemoveAt(index); index--; } } } catch { } }
public static async Task DeleteNoteAsync(Note note) { await StorageManager.DeleteFileAsync(note.Name); Notes.Remove(note as Note); }
public static async Task RenameNoteAsync(Note note, string desiredName) { note.Name = await StorageManager.RenameFileAsync(note.Name, desiredName);; Notes.Remove(note as Note); Notes.InsertInOrder(note as Note); }
public static async Task<Note> CreateNoteAsync() { string name = CreateNewUniqueName(); var note = new Note { DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = name, Text = string.Empty }; Notes.InsertInOrder(note); await StorageManager.CreateFileAsync(note.Name, note.Text); return note; }
private async void Add_Click(object sender, RoutedEventArgs e) { this.selectedNote = await NoteManager.CreateNoteAsync(); this.MasterListView.SelectedItem = this.selectedNote; this.MasterListView.ScrollIntoView(this.selectedNote); }
private async Task EditAsync(Note note) { this.selectedNote = note; // Force a reload of the files in case they've changed in the background await NoteManager.TryReadAllFromStorageAsync(); // Check the file still exists if (!this.notes.Contains(this.selectedNote)) { var dialog = new MessageDialog(Data.Constants.FileNotFoundException); await dialog.ShowAsync(); this.SelectMostAppropriateNote(); return; } // We can only edit if there's only one selected if (this.MasterListView.SelectedItems.Count == 1) { if (AdaptiveStates.CurrentState == NarrowState) { // Use "drill in" transition for navigating from master list to detail view Frame.Navigate(typeof(DetailPage), this.selectedNote, new DrillInNavigationTransitionInfo()); } else { // Play a refresh animation when the user switches detail items. EnableContentTransitions(); } } }