/// <inheritdoc /> /// <summary> /// Initializes a new instance of the <see cref="T:Jfevia.ProductivityShell.Vsix.Shell.PackageBase" /> class. /// </summary> /// <param name="commandSet">The command set.</param> public PackageBase(Guid commandSet) { CommandSet = commandSet; _shell3 = this.GetGlobalService <SVsShell, IVsShell3>(); _shell4 = this.GetGlobalService <SVsShell, IVsShell4>(); }
private void Execute(object sender, EventArgs e) { string message = "This will reset Web Extension Pack and restart Visual Studio.\r\n\r\nDo you wish to continue?"; var answer = VsShellUtilities.ShowMessageBox( ServiceProvider, message, Vsix.Name, OLEMSGICON.OLEMSGICON_QUERY, OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); if (answer == (int)MessageBoxResult.OK) { var store = new DataStore(); if (store.Reset()) { IVsShell4 shell = (IVsShell4)ServiceProvider.GetService(typeof(SVsShell)); shell.Restart((uint)__VSRESTARTTYPE.RESTART_Normal); } else { var dte = (DTE2)ServiceProvider.GetService(typeof(DTE)); dte.StatusBar.Text = "An error occured. Please see output window for details."; } } }
public ConsoleContainer(IVsShell4 shell) { InitializeComponent(); ThreadHelper.JoinableTaskFactory.StartOnIdle( async() => { await System.Threading.Tasks.Task.Run( async() => { var solutionManager = ServiceLocator.GetInstance <ISolutionManager>(); var productUpdateService = ServiceLocator.GetInstance <IProductUpdateService>(); var packageRestoreManager = ServiceLocator.GetInstance <IPackageRestoreManager>(); var deleteOnRestartManager = ServiceLocator.GetInstance <IDeleteOnRestartManager>(); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); RootLayout.Children.Add(new ProductUpdateBar(productUpdateService)); RootLayout.Children.Add(new PackageRestoreBar(solutionManager, packageRestoreManager)); RootLayout.Children.Add(new RestartRequestBar(deleteOnRestartManager, shell)); }); }, VsTaskRunContext.UIThreadIdlePriority); // Set DynamicResource binding in code // The reason we can't set it in XAML is that the VsBrushes class come from either // Microsoft.VisualStudio.Shell.10 or Microsoft.VisualStudio.Shell.11 assembly, // depending on whether NuGet runs inside VS10 or VS11. InitializeText.SetResourceReference(TextBlock.ForegroundProperty, VsBrushes.WindowTextKey); }
private PackageManagerWindow(Project project, DTE dte, IVsPackageManagerFactory packageManagerFactory, IPackageRepositoryFactory repositoryFactory, IPackageSourceProvider packageSourceProvider, IHttpClientEvents httpClientEvents, IProductUpdateService productUpdateService, IPackageRestoreManager packageRestoreManager, ISolutionManager solutionManager, IOptionsPageActivator optionPageActivator, IDeleteOnRestartManager deleteOnRestartManager, IVsShell4 vsRestarter, string dialogParameters) : base(F1Keyword) { InitializeComponent(); #if !VS10 // set unique search guid for VS11 explorer.SearchCategory = new Guid("{85566D5F-E585-411F-B299-5BF006E9F11E}"); #endif _httpClientEvents = httpClientEvents; if (_httpClientEvents != null) { _httpClientEvents.SendingRequest += OnSendingRequest; } _productUpdateService = productUpdateService; _optionsPageActivator = optionPageActivator; _activeProject = project; // replace the ConsoleOutputProvider with SmartOutputConsoleProvider so that we can clear // the console the first time an entry is written to it var providerServices = new ProviderServices(); _smartOutputConsoleProvider = new SmartOutputConsoleProvider(providerServices.OutputConsoleProvider); providerServices.OutputConsoleProvider = _smartOutputConsoleProvider; _providerSettings = providerServices.ProviderSettings; AddUpdateBar(productUpdateService); AddRestoreBar(packageRestoreManager); var restartRequestBar = AddRestartRequestBar(deleteOnRestartManager, vsRestarter); InsertDisclaimerElement(); AdjustSortComboBoxWidth(); PreparePrereleaseComboBox(); SetupProviders( project, dte, packageManagerFactory, repositoryFactory, packageSourceProvider, providerServices, httpClientEvents, solutionManager, packageRestoreManager, restartRequestBar); ProcessDialogParameters(dialogParameters); }
public static async Task InitializeAsync(AsyncPackage package) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); _shell = await package.GetServiceAsync <SVsShell, IVsShell4>(); _dte = await package.GetServiceAsync <DTE, DTE2>(); _events = _dte.Events.DTEEvents; _events.OnBeginShutdown += OnBeginShutdown; IMenuCommandService commandService = await package.GetServiceAsync <IMenuCommandService, IMenuCommandService>(); Assumes.Present(commandService); var cmdNormalId = new CommandID(PackageGuids.guidCommands, PackageIds.RestartNormal); var cmdNormal = new OleMenuCommand((s, e) => Execute(RestartType.Normal), cmdNormalId); commandService.AddCommand(cmdNormal); var cmdElevatedId = new CommandID(PackageGuids.guidCommands, PackageIds.RestartElevated); var cmdElevated = new OleMenuCommand((s, e) => Execute(RestartType.Elevated), cmdElevatedId); commandService.AddCommand(cmdElevated); var cmdSafemodeId = new CommandID(PackageGuids.guidCommands, PackageIds.RestartSafemode); var cmdSafemode = new OleMenuCommand((s, e) => Execute(RestartType.Safemode), cmdSafemodeId); commandService.AddCommand(cmdSafemode); }
private void AddRestartRequestBar(IVsShell4 vsRestarter) { if (Model.Context.PackageManager.DeleteOnRestartManager != null && vsRestarter != null) { _restartBar = new RestartRequestBar(Model.Context.PackageManager.DeleteOnRestartManager, vsRestarter); DockPanel.SetDock(_restartBar, Dock.Top); _root.Children.Insert(0, _restartBar); } }
private void PromptForRestart() { string prompt = "You must restart Visual Studio for the extensions to be loaded.\r\rRestart now?"; var result = MessageBox.Show(prompt, Vsix.Name, MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { IVsShell4 shell = (IVsShell4)_serviceProvider.GetService(typeof(SVsShell)); shell.Restart((uint)__VSRESTARTTYPE.RESTART_Normal); } }
protected override async Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); Dte = GetService <_DTE, DTE2>(); CommandService = GetService <IMenuCommandService, OleMenuCommandService>(); SelectionService = GetService <SVsShellMonitorSelection, IVsMonitorSelection>(); VsShell = GetService <SVsShell, IVsShell4>(); VisualStudioVersion = Dte.Version; }
private void PromptForRestart(IEnumerable <string> extensions) { string list = string.Join(Environment.NewLine, extensions); string prompt = $"The following extensions were installed:\r\r{list}\r\rDo you want to restart Visual Studio now?"; var answer = VsShellUtilities.ShowMessageBox(this, prompt, Vsix.Name, OLEMSGICON.OLEMSGICON_QUERY, OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND); if (answer == (int)MessageBoxResult.OK) { IVsShell4 shell = (IVsShell4)GetService(typeof(SVsShell)); shell.Restart((uint)__VSRESTARTTYPE.RESTART_Normal); } }
/// <summary> /// Restarts Visual Studio. /// </summary> public static async Task <bool> RestartAsync() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsShell4 shell = await GetRequiredServiceAsync <SVsShell, IVsShell4>(); ((IVsShell3)shell).IsRunningElevated(out bool elevated); __VSRESTARTTYPE type = elevated ? __VSRESTARTTYPE.RESTART_Elevated : __VSRESTARTTYPE.RESTART_Normal; int hr = shell.Restart((uint)type); return(ErrorHandler.Succeeded(hr)); }
//Restart Visual Studio public static async System.Threading.Tasks.Task RestartAsync() { if (!ThreadHelper.CheckAccess()) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); } IVsShell4 shell = await Instance.ServiceProvider.GetServiceAsync(typeof(SVsShell)) as IVsShell4; Assumes.Present(shell); shell.Restart((uint)__VSRESTARTTYPE.RESTART_Normal); }
private static void Execute(bool forceElevated, IVsShell4 shell) { ThreadHelper.ThrowIfNotOnUIThread(); if (forceElevated) { shell.Restart((uint)__VSRESTARTTYPE.RESTART_Elevated); } else { ((IVsShell3)shell).IsRunningElevated(out var elevated); __VSRESTARTTYPE type = elevated ? __VSRESTARTTYPE.RESTART_Elevated : __VSRESTARTTYPE.RESTART_Normal; shell.Restart((uint)type); } }
/// <summary> /// Restarts the IDE. /// </summary> /// <param name="forceElevated">Forces the IDE to start back up elevated. /// If <see langword="false"/>, it restarts in the same mode it is currently running in. /// </param> public async Task RestartAsync(bool forceElevated = false) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsShell4 shell = (IVsShell4)await VS.Services.GetShellAsync(); if (forceElevated) { shell.Restart((uint)__VSRESTARTTYPE.RESTART_Elevated); } else { ((IVsShell3)shell).IsRunningElevated(out bool elevated); __VSRESTARTTYPE type = elevated ? __VSRESTARTTYPE.RESTART_Elevated : __VSRESTARTTYPE.RESTART_Normal; shell.Restart((uint)type); } }
private void DeleteCacheFolder(object sender, EventArgs e) { if (!UserWantsToProceed()) { return; } string folder = GetFolderPath(); if (!string.IsNullOrEmpty(folder) && Directory.Exists(folder)) { IVsShell4 shell = (IVsShell4)ServiceProvider.GetService(typeof(SVsShell)); shell.Restart((uint)__VSRESTARTTYPE.RESTART_Normal); Directory.Delete(folder, true); } }
public static void PromptForRestart() { string prompt = $"Extensions have been installed. Visual Studio must be restarted for the changes to take effect.\r\rDo you want to restart Visual Studio now?"; int answer = VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, prompt, Vsix.Name, OLEMSGICON.OLEMSGICON_QUERY, OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND); if (answer == (int)MessageBoxResult.OK) { IVsShell4 shell = (IVsShell4)Package.GetGlobalService(typeof(SVsShell)); shell.Restart((uint)__VSRESTARTTYPE.RESTART_Normal); } }
public ConsoleContainer( ISolutionManager solutionManager, IProductUpdateService productUpdateService, IPackageRestoreManager packageRestoreManager, IDeleteOnRestartManager deleteOnRestartManager, IVsShell4 shell) { InitializeComponent(); RootLayout.Children.Add(new ProductUpdateBar(productUpdateService)); RootLayout.Children.Add(new PackageRestoreBar(solutionManager, packageRestoreManager)); RootLayout.Children.Add(new RestartRequestBar(deleteOnRestartManager, shell)); // Set DynamicResource binding in code // The reason we can't set it in XAML is that the VsBrushes class come from either // Microsoft.VisualStudio.Shell.10 or Microsoft.VisualStudio.Shell.11 assembly, // depending on whether NuGet runs inside VS10 or VS11. InitializeText.SetResourceReference(TextBlock.ForegroundProperty, VsBrushes.WindowTextKey); }
public static async Task InitializeAsync(AsyncPackage package) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); IVsShell4 shell = await package.GetServiceAsync <SVsShell, IVsShell4>(); Assumes.Present(shell); IMenuCommandService commandService = await package.GetServiceAsync <IMenuCommandService, IMenuCommandService>(); Assumes.Present(commandService); var cmdNormalId = new CommandID(PackageGuids.guidCommands, PackageIds.RestartNormal); var cmdNormal = new OleMenuCommand((s, e) => Execute(false, shell), cmdNormalId); commandService.AddCommand(cmdNormal); var cmdElevatedId = new CommandID(PackageGuids.guidCommands, PackageIds.RestartElevated); var cmdElevated = new OleMenuCommand((s, e) => Execute(true, shell), cmdElevatedId); commandService.AddCommand(cmdElevated); }
public RestartRequestBar(IDeleteOnRestartManager deleteOnRestartManager, IVsShell4 vsRestarter) { InitializeComponent(); _deleteOnRestartManager = deleteOnRestartManager; _vsRestarter = vsRestarter; // Since the DeleteonRestartManager is guranteed to be a singleton, we can rely on it for firing the events // both in package management ui and the powershell console. _deleteOnRestartManager.PackagesMarkedForDeletionFound += OnPackagesMarkedForDeletionFound; // Since Loaded event is not reliable, we do it at construction time initially, this is only for // the case when this needs to show up in package manager window (since package manager ui gets recreated, // the check can happen here). For powershell, it depends on the event handlers firigng up either via // package manager ui or the powershell commands like uninstall package. _deleteOnRestartManager.CheckAndRaisePackageDirectoriesMarkedForDeletion(); // Set DynamicResource binding in code // The reason we can't set it in XAML is that the VsBrushes class come from either // Microsoft.VisualStudio.Shell.12 or Microsoft.VisualStudio.Shell.14 assembly, // depending on whether NuGet runs inside VS12 or VS14. RequestRestartMessage.SetResourceReference(TextBlock.ForegroundProperty, VsBrushes.InfoTextKey); RestartBar.SetResourceReference(Border.BackgroundProperty, VsBrushes.InfoBackgroundKey); RestartBar.SetResourceReference(Border.BorderBrushProperty, VsBrushes.ActiveBorderKey); }
void RestartVS() { IVsShell4 shell = GetService <IVsShell4, SVsShell>(); shell.Restart((uint)__VSRESTARTTYPE.RESTART_Normal); }
public RestartRequestBar(IDeleteOnRestartManager deleteOnRestartManager, IVsShell4 vsRestarter) { InitializeComponent(); _deleteOnRestartManager = deleteOnRestartManager; _vsRestarter = vsRestarter; }
private RestartRequestBar AddRestartRequestBar(IDeleteOnRestartManager deleteOnRestartManager, IVsShell4 vsRestarter) { var restartRequestBar = new RestartRequestBar(deleteOnRestartManager, vsRestarter); Grid.SetColumn(restartRequestBar, 1); BottomBar.Children.Insert(1, restartRequestBar); return(restartRequestBar); }
private PackageManagerWindow(Project project, DTE dte, IVsPackageManagerFactory packageManagerFactory, IPackageRepositoryFactory repositoryFactory, IPackageSourceProvider packageSourceProvider, IHttpClientEvents httpClientEvents, IProductUpdateService productUpdateService, IPackageRestoreManager packageRestoreManager, ISolutionManager solutionManager, IOptionsPageActivator optionPageActivator, IDeleteOnRestartManager deleteOnRestartManager, IVsShell4 vsRestarter, string dialogParameters) : base(F1Keyword) { InitializeComponent(); #if !VS10 // set unique search guid for VS11 explorer.SearchCategory = new Guid("{85566D5F-E585-411F-B299-5BF006E9F11E}"); #endif _httpClientEvents = httpClientEvents; if (_httpClientEvents != null) { _httpClientEvents.SendingRequest += OnSendingRequest; } _productUpdateService = productUpdateService; _optionsPageActivator = optionPageActivator; _activeProject = project; // replace the ConsoleOutputProvider with SmartOutputConsoleProvider so that we can clear // the console the first time an entry is written to it var providerServices = new ProviderServices(); _smartOutputConsoleProvider = new SmartOutputConsoleProvider(providerServices.OutputConsoleProvider); providerServices.OutputConsoleProvider = _smartOutputConsoleProvider; _providerSettings = providerServices.ProviderSettings; _updateAllUIService = providerServices.UpdateAllUIService; providerServices.ProgressWindow.UpgradeNuGetRequested += (_, __) => { Close(); productUpdateService.Update(); }; AddUpdateBar(productUpdateService); AddRestoreBar(packageRestoreManager); var restartRequestBar = AddRestartRequestBar(deleteOnRestartManager, vsRestarter); InsertDisclaimerElement(); AdjustSortComboBoxWidth(); PreparePrereleaseComboBox(); InsertUpdateAllButton(providerServices.UpdateAllUIService); SetupProviders( project, dte, packageManagerFactory, repositoryFactory, packageSourceProvider, providerServices, httpClientEvents, solutionManager, packageRestoreManager, restartRequestBar); ProcessDialogParameters(dialogParameters); }
private RestartRequestBar AddRestartRequestBar(IDeleteOnRestartManager deleteOnRestartManager, IVsShell4 vsRestarter) { var restartRequestBar = new RestartRequestBar(deleteOnRestartManager, vsRestarter); Grid.SetColumn(restartRequestBar, 1); BottomBar.Children.Insert(1, restartRequestBar); return restartRequestBar; }
public PackageManagerControl( PackageManagerModel model, Configuration.ISettings nugetSettings, IVsWindowSearchHostFactory searchFactory, IVsShell4 vsShell, INuGetUILogger uiLogger = null) { _uiDispatcher = Dispatcher.CurrentDispatcher; _uiLogger = uiLogger; Model = model; Settings = nugetSettings; if (!Model.IsSolution) { _detailModel = new PackageDetailControlModel(Model.Context.SolutionManager, Model.Context.Projects); } else { _detailModel = new PackageSolutionDetailControlModel( Model.Context.SolutionManager, Model.Context.Projects, Model.Context.PackageManagerProviders); } InitializeComponent(); _windowSearchHostFactory = searchFactory; if (_windowSearchHostFactory != null) { _windowSearchHost = _windowSearchHostFactory.CreateWindowSearchHost( _topPanel.SearchControlParent); _windowSearchHost.SetupSearch(this); _windowSearchHost.IsVisible = true; } AddRestoreBar(); AddRestartRequestBar(vsShell); AddPackagesErrorBar(); _packageDetail.Control = this; _packageDetail.Visibility = Visibility.Hidden; SetTitle(); _topPanel.IsSolution = Model.IsSolution; var settings = LoadSettings(); InitializeFilterList(settings); InitSourceRepoList(settings); ApplySettings(settings, nugetSettings); _initialized = true; // UI is initialized. Start the first search _packageList.CheckBoxesEnabled = _topPanel.Filter == ItemFilter.UpdatesAvailable; _packageList.IsSolution = this.Model.IsSolution; Loaded += (_, __) => { SearchPackagesAndRefreshUpdateCount(_windowSearchHost.SearchQuery.SearchString, useCache: false); RefreshConsolidatablePackagesCount(); }; // register with the UI controller var controller = model.UIController as NuGetUI; if (controller != null) { controller.PackageManagerControl = this; } var solutionManager = Model.Context.SolutionManager; solutionManager.NuGetProjectAdded += SolutionManager_ProjectsChanged; solutionManager.NuGetProjectRemoved += SolutionManager_ProjectsChanged; solutionManager.NuGetProjectUpdated += SolutionManager_ProjectsUpdated; solutionManager.NuGetProjectRenamed += SolutionManager_ProjectRenamed; solutionManager.ActionsExecuted += SolutionManager_ActionsExecuted; solutionManager.AfterNuGetCacheUpdated += SolutionManager_CacheUpdated; Model.Context.SourceProvider.PackageSourceProvider.PackageSourcesChanged += Sources_PackageSourcesChanged; if (IsUILegalDisclaimerSuppressed()) { _legalDisclaimer.Visibility = Visibility.Collapsed; } _missingPackageStatus = false; }
private RestartRequestBar AddRestartRequestBar(IDeleteOnRestartManager deleteOnRestartManager, IVsShell4 vsRestarter) { var restartRequestBar = new RestartRequestBar(deleteOnRestartManager, vsRestarter); Grid.SetColumn(restartRequestBar, 1); BottomBar.Children.Insert(1, restartRequestBar); Loaded += restartRequestBar.NotifyOnUnsuccessfulUninstall; return(restartRequestBar); }
void RestartVS() { IVsShell4 shell = (IVsShell4)ServiceProvider.GetService(typeof(SVsShell)); shell.Restart((uint)__VSRESTARTTYPE.RESTART_Normal); }