public override void ShowAlert(View view, DialogScope dialogScope, DialogMode dialogMode) { var viewHost = GetNewDialogWindow(); // prepare host view and viewmodel viewHost.HostedView = view; viewHost.HostedViewModel = view.ViewModel; view.ViewModel.InteractionCompleting += viewModel_modalInteractionCompleting; PrepareViewForDisplay(viewHost, view); viewHost.ShowDialog(); }
public abstract void ShowAlert(View view, DialogScope dialogScope, DialogMode dialogMode);
/// <summary> /// Displays a dialog window to the user. /// </summary> /// <param name="viewModel"></param> /// <param name="dialogScope"></param> public abstract void ShowDialog( View view, DialogScope dialogScope, DialogMode dialogMode, bool showActivated = true, Func<ViewHostWindow> getWindow = null);
public override void ShowDialog(View view, DialogScope dialogScope, DialogMode dialogMode, bool showActivated = true, Func<ViewHostWindow> getWindow = null) { var viewModel = view.ViewModel; ViewHostWindow viewHost = null; // prepare host view and viewmodel if (getWindow == null) { viewHost = GetNewDialogWindow(); } else { viewHost = getWindow(); if (viewHost is Window) OnAfterWindowCreated(viewHost as Window); } viewHost.Owner = Application.Current.MainWindow; viewHost.HostedViewModel = viewModel; viewHost.HostedView = view; viewHost.Closed += (sender, e) => { if (viewModel.InteractionOutcome == UserInteractionOutcome.Unset) viewModel.CompleteInteraction(UserInteractionOutcome.Cancelled); }; if (dialogMode == DialogMode.Modal) { viewModel.InteractionCompleting += viewModel_modalInteractionCompleting; } else { viewModel.InteractionCompleting += viewModel_nonModalInteractionCompleting; } if (dialogScope == DialogScope.Global) { if (viewHost != Application.Current.MainWindow) // this may happen when Visual Studio is closing down viewHost.Owner = Application.Current.MainWindow; } viewHost.ShowActivated = showActivated; PrepareViewForDisplay(viewHost, view); if (!UIDispatcher.HasShutdownStarted && !UIDispatcher.HasShutdownFinished) { if (dialogMode == DialogMode.Modal) { viewHost.ShowDialog(); } else { viewHost.Show(); } } }
protected override void Execute() { SolutionOptions options = new SolutionOptions(); Solution.GetProperty((int)__VSPROPID.VSPROPID_SolutionDirectory, out object solutionDirectoryRaw); Solution.GetProperty((int)__VSPROPID.VSPROPID_SolutionBaseName, out object solutionNameRaw); string solutionName = solutionNameRaw.ToString(); string solutionDirectory = solutionDirectoryRaw.ToString(); options.SolutionName = solutionName; options.SolutionDirectory = solutionDirectory; options.RepositoryDirectory = new DirectoryInfo(solutionDirectory).Parent.FullName; IEnumerable <Project> projects = DTE.Solution.GetAllProjects(); using (DialogScope progress2 = new DialogScope()) { progress2.Update("Synchronizing project file properties with solution. Please wait..."); foreach (Project project in projects) { progress2.Update( "Synchronizing project file properties with solution. Please wait...", $"Processing Project '{project.Name}'" ); // =========================== // Flow // =========================== // // 1) Snapshot project file full path. // 2) Open Project File with filePath and snapshot its ProjectRootElement. // 3) Retrieve Project GUID of the project snapshotted in step 1 // 4) Unload project as if user manually unloaded it, and then close it // // 5) Walk property elements, stop at chosen property Name // 5.1) Get the parent of the property element (should be a ProjectPropertyGroupElement) // 5.2) Remove the property element, which will be an immediate child of the parent you just got in 5.1 // 6) Save the ProjectRootElement // 7) Reload the project. This is where the GUID from step 3 comes in handy. // 8) For good measure, save the project via the hierarchy. // 9) You are done, Son! // // string projectFilePath = project.FullName; Solution.GetProjectOfUniqueName(project.UniqueName, out IVsHierarchy ppHierarchy); Solution.GetGuidOfProject(ppHierarchy, out Guid projectGuid); Solution4.UnloadProject(ref projectGuid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser); Solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, ppHierarchy, VSConstants.VSITEMID_NIL); ProjectRootElement root = ProjectLoader.LoadProject(projectFilePath).Xml; foreach (ProjectPropertyElement propertyElement in root.Properties) { // Check for the most common property names for // output paths. The names checked below are // non-exhaustive. Technically, OutputPath should // be sufficient; however, OutDir is used as // well, but not very often. if (propertyElement.Name.Equals("OutputPath") || propertyElement.Name.Equals("OutDir")) { propertyElement.Parent.RemoveChild(propertyElement); root.Save(projectFilePath); } } // This has to come after the properties are removed. Otherwise you get some error // saing The SDK '' could not be found. ProjectXmlService.SetExplicitSdkImportsIfNecessaryAsync(projectFilePath); Solution4.ReloadProject(ref projectGuid); Solution4.EnsureProjectIsLoaded(ref projectGuid, 0); Solution.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave, ppHierarchy, VSConstants.VSITEMID_NIL); } } DirectoryBuildPropsWriter.WriteDirectoryBuildProps(options); Project solutionItems = DTE.Solution.GetOrCreateSolutionFolder("Solution Items"); solutionItems.ProjectItems.AddFromFile(options.DirectoryBuildPropsPath); DTE.Collapse(); }