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 NewProjectDialogViewModel()
            : base("New Project", true, true)
        {
            _studio          = IoC.Get <IStudio>();
            _templateManager = IoC.Get <TemplateManager>();

            _allProjectTemplates = new Lazy <IDictionary <string, IEnumerable <ITemplate> > >(_templateManager.GetProjectTemplates);

            location = Platform.ProjectDirectory;

            SelectedLanguage = Languages.FirstOrDefault();
            SelectedTemplate = ProjectTemplates.FirstOrDefault();

            BrowseLocationCommand = ReactiveCommand.Create(async() =>
            {
                var ofd = new OpenFolderDialog
                {
                    InitialDirectory = location
                };

                var result = await ofd.ShowAsync();

                if (!string.IsNullOrEmpty(result))
                {
                    Location = result;
                }
            });

            OKCommand = ReactiveCommand.Create(async() =>
            {
                Close();

                bool loadNewSolution = false;

                if (_solutionFolder == null)
                {
                    IoC.Get <IStatusBar>().SetText("Creating new Solution...");
                    loadNewSolution = true;

                    var destination = Path.Combine(location, solutionName);
                    location        = destination;
                    _solutionFolder = VisualStudioSolution.Create(destination, solutionName, false, VisualStudioSolution.Extension);
                }
                else
                {
                    IoC.Get <IStatusBar>().SetText("Creating new project...");
                }

                var templateManager = IoC.Get <TemplateManager>();

                var templateDestination = Path.Combine(Location, name);

                if (await templateManager.CreateTemplate(selectedTemplate, templateDestination, ("name", name)) == CreationResult.Success)
                {
                    var projectFiles = GetProjectFiles(templateDestination);

                    bool defaultSet = _solutionFolder.Solution.StartupProject != null;

                    foreach (var projectFile in projectFiles)
                    {
                        var projectTypeGuid = ProjectUtils.GetProjectTypeGuidForProject(projectFile);

                        if (projectTypeGuid.HasValue)
                        {
                            var project = await ProjectUtils.LoadProjectFileAsync(
                                _solutionFolder.Solution, projectTypeGuid.Value, projectFile);

                            if (project != null)
                            {
                                _solutionFolder.Solution.AddItem(project, projectTypeGuid, _solutionFolder);
                            }

                            if (!defaultSet)
                            {
                                defaultSet = true;
                                _solutionFolder.Solution.StartupProject = project;
                            }

                            if (!loadNewSolution)
                            {
                                await project.LoadFilesAsync();

                                await project.ResolveReferencesAsync();
                            }
                        }
                        else
                        {
                            IoC.Get <Utils.IConsole>().WriteLine(
                                $"The project '{projectFile}' isn't supported by any installed project type!");
                        }
                    }
                }

                _solutionFolder.Solution.Save();

                if (loadNewSolution)
                {
                    await _studio.OpenSolutionAsync(_solutionFolder.Solution.Location);
                }
                else
                {
                    await _solutionFolder.Solution.RestoreSolutionAsync();
                }

                _solutionFolder = null;

                IoC.Get <IStatusBar>().ClearText();
            },
                                               this.WhenAny(x => x.Location, x => x.SolutionName, (location, solution) => solution.Value != null && !Directory.Exists(Path.Combine(location.Value, solution.Value))));

            UpdateTemplatesCommand = ReactiveCommand.Create(async() =>
            {
                var templateManager = IoC.Get <TemplateManager>();

                await Task.Run(() =>
                {
                    templateManager.UpdateDefaultTemplates();

                    _allProjectTemplates = new Lazy <IDictionary <string, IEnumerable <ITemplate> > >(_templateManager.GetProjectTemplates);

                    SelectedLanguage = SelectedLanguage;
                });
            });
        }