public static void VisitParents(this SolutionItemViewModel item, Action <ISolutionParentViewModel> visitor) { var parent = item.Parent; while (true) { visitor(parent); if (parent is SolutionViewModel) { return; } parent = parent.Parent; } }
public static SolutionItemViewModel Create(ISolutionParentViewModel parent, ISolutionItem item) { SolutionItemViewModel result = null; if (item is ISolutionFolder folder) { result = new SolutionFolderViewModel(parent, folder); } else if (item is IProject project) { result = new StandardProjectViewModel(parent, project); } else { throw new Exception("Unrecognised model type"); } return(result); }
public static SolutionViewModel FindRoot(this SolutionItemViewModel item) { var solution = item.Parent; while (true) { if (solution == null) { throw new InvalidOperationException("Unable to find solution"); } if (solution is SolutionViewModel solutionViewModel) { return(solutionViewModel); } solution = solution.Parent; } }
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(); }); }