private void AddButton_Click(object sender, RoutedEventArgs e) { var dir = new OpenDirectoryDialog().OpenDirectory(); if (string.IsNullOrWhiteSpace(dir) == false) { var reader = new FolderSettingsFileReader(); var settings = reader.ReadFileAsync(dir).Result; if (settings == null) { var vm = AddDirectoryDialog.Show(dir); if (vm == null) { return; } settings = new FolderSettings((uint)vm.DaysBeforeRemoval, (DirectoriesDeleteBehaviour)vm.BehaviourID); var writer = new FolderSettingsFileSaver(); writer.SaveAsync(settings, dir).Wait(); } var specificSettings = new SpecificFolderSetting(dir, settings); App.Oldi.AddSettings(specificSettings); vm.FolderSettingItems.Add(new FolderSettingItemViewModel(specificSettings)); } }
public static AddDirectoryDialogViewModel Show(string directoryPath) { var dir = new AddDirectoryDialog(directoryPath); bool saved = false; dir.OnSave += (_a, _b) => { saved = true; }; dir.ShowDialog(); if (saved) { return(dir.vm); } else { return(null); } }