/// <summary> /// Open dialog for user to pick which sections of the settings to do something with. /// </summary> private static bool OpenSelectionsDialog(out SettingsSelectionViewModel selectionViewModel, SettingsSelectionViewModel dataContext, Window window) { dataContext.Selections = dataContext.Selections.OrderByDescending(s => s.IsEnabled).ToList(); window.Owner = UILoader.ConfigWindow; window.WindowStartupLocation = WindowStartupLocation.CenterOwner; dataContext.PropertyChanged += (sender, args) => { if (args.PropertyName == nameof(dataContext.IsWindowOpen) && !dataContext.IsWindowOpen) { window.Close(); } }; window.ContentRendered += (o, args) => dataContext.IsWindowOpen = true; window.Closed += (o, args) => dataContext.IsWindowOpen = false; window.ShowDialog(); selectionViewModel = dataContext; return(selectionViewModel.DialogResult == DialogResult.OK); }
/// <summary> /// Try to get user to pick settings sections for export. /// </summary> public static bool TryGetExportSelections(out SettingsSelectionViewModel selectionViewModel) { var dataContext = new SettingsSelectionViewModel { Title = "Sections to Export", Description = "Only the sections selected below will be exported.", OkButtonText = "Export", }; EnableSections(SettingsSelectionViewModel.GetDefaultSelections(), dataContext); var window = UILoader.CreateNonModalWindow( "Modals\\SettingsSelection.xaml", "Export Settings", dataContext, 350, 225 ); return(OpenSelectionsDialog(out selectionViewModel, dataContext, window)); }
/// <summary> /// Try to get user to pick settings sections for import. /// </summary> public static bool TryGetImportSelections(HashSet <SettingsSelectionItem> importedParts, out SettingsSelectionViewModel selectionViewModel) { var dataContext = new SettingsSelectionViewModel { Title = "Sections to Import", Description = "Only the sections selected below will be imported.", OkButtonText = "Import", }; EnableSections(importedParts, dataContext); var window = UILoader.CreateNonModalWindow( "Modals\\SettingsSelection.xaml", "Import Settings", dataContext, 350, 225 ); return(OpenSelectionsDialog(out selectionViewModel, dataContext, window)); }
/// <summary> /// Make checkboxes on the selections dialog enabled and clickable. (they default to disabled). /// </summary> private static void EnableSections(ICollection <SettingsSelectionItem> validSections, SettingsSelectionViewModel selectionViewModel) { foreach (var item in selectionViewModel.Selections) { if (validSections.Any(s => s.SectionName == item.SectionName)) { item.IsEnabled = true; item.IsSelected = true; } } }
/// <summary> /// Clear the specified parts of a TrinitySetting object so that they have no data. /// </summary> public static void UpdateSections(string actionDescripter, TrinityStorage storages, SettingsSelectionViewModel selectionsViewModel) { foreach (var sectionEntry in selectionsViewModel.Selections) { if (sectionEntry.IsSelected) { if (!string.IsNullOrEmpty(actionDescripter)) { Core.Logger.Log($"{actionDescripter} Section: {sectionEntry}"); } continue; } ClearSection(storages, sectionEntry); } }