/// <summary> /// Command callback. /// Called to navigate to a category. /// </summary> /// <param name="selectedCategory">Value selected.</param> private async void OnCategorySelection(SettingsCategoryEnum selectedCategory) { if (selectedCategory == _currentCategory) { return; } if (ContentViewModel.IsChangePending) { var result = await MessageBoxManager.GetMessageBoxStandardWindow(new MessageBoxStandardParams { ContentTitle = "Pending changes", ContentMessage = $"Some changes were not saved{Environment.NewLine}Do you want to save them?", ButtonDefinitions = ButtonEnum.YesNoCancel, Icon = Icon.Info, }).ShowDialog(NavigationActor.Instance.MainWindow); switch (result) { case ButtonResult.Yes: OnSaveSettings(); break; case ButtonResult.Cancel: return; // Do not navigate on cancel. } } Navigate(selectedCategory); }
/// <summary> /// Command callback. /// Called to navigate to a category. /// </summary> /// <param name="selectedCategory">Value selected.</param> private void OnCategorySelection(SettingsCategoryEnum selectedCategory) { if (selectedCategory == _currentCategory) { return; } if (ContentViewModel.IsChangePending) { MessageBoxResult choice = MessageBox.Show(NavigationActor.Instance.ActiveWindow, string.Format("Some changes were not saved.{0}Do you want to save them?", Environment.NewLine), "Pending changes", System.Windows.MessageBoxButton.YesNoCancel, System.Windows.MessageBoxImage.Information, MessageBoxResult.Cancel); switch (choice) { case MessageBoxResult.Yes: OnSaveSettings(); break; case MessageBoxResult.Cancel: return; // Do not navigate on cancel. } } Navigate(selectedCategory); }
/// <summary> /// Navigates to the settings page, and performs an intra-navigation /// to the specified settings page. /// </summary> /// <param name="page">Page to navigate to.</param> public void NavigateToSettings(SettingsCategoryEnum page) { lock (_mainWindowLock) { RequireMainWindow(); CurrentPage = NavigationPageEnum.Settings; SettingsVm.Navigate(page); } }
/// <summary> /// Navigates to the given settings category, if it is not already the /// current category. /// </summary> /// <param name="targetCategory">Category to attain.</param> public void Navigate(SettingsCategoryEnum targetCategory, bool force = false) { if (CurrentCategory != targetCategory || force) { _currentCategory = targetCategory; if (_contentViewModel != null) { _contentViewModel.Dispose(); } _contentViewModel = GetViewModelByCategory(targetCategory); // Raise a property changed on the whole view model. // Doing so will prevent a temporary mismatch between the // current category and the content view model. RaisePropertyChanged(null); } }
/// <summary> /// Gets a new settings view model built according to the given /// settings category. /// </summary> /// <param name="c">Category to match.</param> /// <returns></returns> private SettingsPageViewModel GetViewModelByCategory(SettingsCategoryEnum c) { switch (c) { case SettingsCategoryEnum.Application: return(new ApplicationSettingsViewModel()); case SettingsCategoryEnum.Kanji: return(new KanjiSettingsViewModel()); case SettingsCategoryEnum.Vocab: return(new VocabSettingsViewModel()); case SettingsCategoryEnum.Srs: return(new SrsSettingsViewModel()); default: throw new ArgumentException( string.Format("Unknown category: {0}.", c)); } }
/// <summary> /// Command callback. /// Called to navigate to a category. /// </summary> /// <param name="selectedCategory">Value selected.</param> private void OnCategorySelection(SettingsCategoryEnum selectedCategory) { if (selectedCategory == _currentCategory) { return; } if (ContentViewModel.IsChangePending) { MessageBoxResult choice = MessageBox.Show(NavigationActor.Instance.ActiveWindow, string.Format("Some changes were not saved.{0}Do you want to save them?", Environment.NewLine), "Pending changes", System.Windows.MessageBoxButton.YesNoCancel, System.Windows.MessageBoxImage.Information, MessageBoxResult.Cancel); switch (choice) { case MessageBoxResult.Yes: OnSaveSettings(); break; case MessageBoxResult.Cancel: return; // Do not navigate on cancel. } } Navigate(selectedCategory); }
/// <summary> /// Gets a new settings view model built according to the given /// settings category. /// </summary> /// <param name="c">Category to match.</param> /// <returns></returns> private SettingsPageViewModel GetViewModelByCategory(SettingsCategoryEnum c) { switch (c) { case SettingsCategoryEnum.Application: return new ApplicationSettingsViewModel(); case SettingsCategoryEnum.Kanji: return new KanjiSettingsViewModel(); case SettingsCategoryEnum.Vocab: return new VocabSettingsViewModel(); case SettingsCategoryEnum.Srs: return new SrsSettingsViewModel(); default: throw new ArgumentException( string.Format("Unknown category: {0}.", c)); } }
/// <summary> /// Navigates to the given settings category, if it is not already the /// current category. /// </summary> /// <param name="targetCategory">Category to attain.</param> public void Navigate(SettingsCategoryEnum targetCategory, bool force = false) { if (CurrentCategory != targetCategory || force) { _currentCategory = targetCategory; if (_contentViewModel != null) { _contentViewModel.Dispose(); } _contentViewModel = GetViewModelByCategory(targetCategory); // Raise a property changed on the whole view model. // Doing so will prevent a temporary mismatch between the // current category and the content view model. RaisePropertyChanged(null); } }
/// <summary> /// Navigates to the settings page, and performs an intra-navigation /// to the specified settings page. /// </summary> /// <param name="page">Page to navigate to.</param> public void NavigateToSettings(SettingsCategoryEnum page) { lock (_mainWindowLock) { RequireMainWindow(); CurrentPage = NavigationPageEnum.Settings; SettingsVm.Navigate(page); } }