public void Removing_Solution_Folder_Removes_Children() { var solution = VisualStudioSolution.Create(@"c:\TestProject\Test.sln", "Test", false); solution.SaveEnabled = false; var startupProject = new TestProject("c:\\TestProject\\Project1\\Project.csproj"); solution.AddItem(startupProject); solution.StartupProject = startupProject; var folder = solution.AddItem(SolutionFolder.Create("SubFolder")); solution.AddItem(new TestProject("c:\\TestProject\\Project1\\Project1.csproj"), folder); solution.AddItem(new TestProject("c:\\TestProject\\Project1\\Project2.csproj"), folder); Assert.Equal(3, solution.Projects.Count()); Assert.Equal(4, solution.Model.Projects.Count); solution.RemoveItem(folder); Assert.Equal(1, solution.Projects.Count()); Assert.Equal(1, solution.Model.Projects.Count); Assert.Equal(startupProject, solution.Projects.FirstOrDefault()); }
public SolutionParentViewModel(ISolutionParentViewModel parent, T model) : base(parent, model) { Items = new ObservableCollection <SolutionItemViewModel>(); Items.BindCollections(Model.Items, p => { return(SolutionItemViewModel.Create(this, p)); }, (pvm, p) => pvm.Model == p); AddNewFolderCommand = ReactiveCommand.Create(() => { Model.Solution.AddItem(SolutionFolder.Create("New Folder"), null, Model); Model.Solution.Save(); }); AddExistingProjectCommand = ReactiveCommand.Create(async() => { var dlg = new OpenFileDialog(); dlg.Title = "Open Project"; var shell = IoC.Get <IShell>(); foreach (var projectType in shell.ProjectTypes) { var projectTypeMetadata = projectType.Metadata; var extensions = new List <string>(); extensions.Add(projectTypeMetadata.DefaultExtension); extensions.AddRange(projectTypeMetadata.PossibleExtensions); dlg.Filters.Add(new FileDialogFilter() { Name = projectTypeMetadata.Description, Extensions = extensions }); } dlg.InitialDirectory = Model.Solution.CurrentDirectory; dlg.AllowMultiple = false; var result = await dlg.ShowAsync(); if (result != null && !string.IsNullOrEmpty(result.FirstOrDefault())) { var projectTypeGuid = ProjectUtils.GetProjectTypeGuidForProject(result[0]); if (projectTypeGuid.HasValue) { var proj = await ProjectUtils.LoadProjectFileAsync(Model.Solution, projectTypeGuid.Value, result[0]); if (proj != null) { Model.Solution.AddItem(proj, projectTypeGuid, Model); Model.Solution.Save(); } } else { IoC.Get <Utils.IConsole>().WriteLine( $"The project '{result[0]}' isn't supported by any installed project type!"); } } }); AddNewProjectCommand = ReactiveCommand.Create(() => { var shell = IoC.Get <IShell>(); shell.ModalDialog = new NewProjectDialogViewModel(Model); shell.ModalDialog.ShowDialog(); }); RemoveCommand = ReactiveCommand.Create(() => { Model.Solution.RemoveItem(Model); Model.Solution.Save(); }); }
public SolutionParentViewModel(ISolutionParentViewModel parent, T model) : base(parent, model) { Items = new ObservableCollection <SolutionItemViewModel>(); Items.BindCollections(Model.Items, p => { return(SolutionItemViewModel.Create(this, p)); }, (pvm, p) => pvm.Model == p); AddNewFolderCommand = ReactiveCommand.Create(() => { Model.Solution.AddItem(SolutionFolder.Create("New Folder"), Model); Model.Solution.Save(); }); AddExistingProjectCommand = ReactiveCommand.Create(async() => { var dlg = new OpenFileDialog(); dlg.Title = "Open Project"; var extensions = new List <string>(); var shell = IoC.Get <IShell>(); foreach (var projectType in shell.ProjectTypes) { extensions.AddRange(projectType.Extensions); } dlg.Filters.Add(new FileDialogFilter { Name = "AvalonStudio Project", Extensions = extensions }); dlg.InitialDirectory = Model.Solution.CurrentDirectory; dlg.AllowMultiple = false; var result = await dlg.ShowAsync(); if (result != null && !string.IsNullOrEmpty(result.FirstOrDefault())) { var proj = await Project.LoadProjectFileAsync(Model.Solution, result[0]); if (proj != null) { Model.Solution.AddItem(proj, Model); Model.Solution.Save(); } } }); AddNewProjectCommand = ReactiveCommand.Create(() => { var shell = IoC.Get <IShell>(); shell.ModalDialog = new NewProjectDialogViewModel(Model); shell.ModalDialog.ShowDialog(); }); RemoveCommand = ReactiveCommand.Create(() => { Model.Solution.RemoveItem(Model); Model.Solution.Save(); }); }