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();
            });
        }
Ejemplo n.º 2
0
        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();
            });
        }