/// <summary> /// Open a URL within Visual Studio using the <see cref="IVsWebBrowsingService"/> service /// </summary> /// <param name="url">The URL to display</param> public static void OpenUrl(string url) { ThreadHelper.ThrowIfNotOnUIThread(); bool useExternalBrowser = false; if (String.IsNullOrEmpty(url)) { return; } var options = SandcastleBuilderPackage.Instance.GeneralOptions; if (options != null) { useExternalBrowser = options.UseExternalWebBrowser; } if (!useExternalBrowser && MsVsShellPackage.GetGlobalService(typeof(SVsWebBrowsingService)) is IVsWebBrowsingService webBrowsingService) { ErrorHandler.ThrowOnFailure(webBrowsingService.Navigate(url, 0, out IVsWindowFrame frame)); if (frame != null) { frame.Show(); } } else { System.Diagnostics.Process.Start(url); } }
private void Init() { ThreadHelper.ThrowIfNotOnUIThread(); dte = Package.GetGlobalService(typeof(DTE)) as DTE2; if (dte != null) { events = dte.Events as Events2; if (events != null) { dteEvents = events.DTEEvents; solutionEvents = events.SolutionEvents; dteEvents.OnBeginShutdown += ShutDown; solutionEvents.Opened += () => SwitchStartupDir("\n====== Solution opening Detected ======\n"); } } terminalController.SetShell(OptionMgr.Shell); bool createSuccess = terminalController.Init(GetProjectPath()); if (!createSuccess) { VsShellUtilities.ShowMessageBox( ServiceProvider.GlobalProvider, "Can not create console process, check your configuration and reopen this window", "Can not create process", OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } terminalController.InvokeCmd("\n[Global Init Script ...]\n", OptionMgr.GetGlobalScript()); }
/// <summary> /// Initializes a new instance of the <see cref="MainWindow"/> class. /// </summary> public MainWindow() : base(null) { this.Caption = "AskTheCode: Control Panel"; var dte2 = ShellPackageAlias.GetGlobalService(typeof(SDTE)) as EnvDTE80.DTE2; var highlightService = ShellPackageAlias.GetGlobalService(typeof(SHighlightService)) as IHighlightService; var componentModel = ShellPackageAlias.GetGlobalService(typeof(SComponentModel)) as IComponentModel; // TODO: Avoid throwing InvalidCastException if the user has the LanguageServices library of version 1.1.0.0 // (It corresponds to Visual Studio Update 1) var workspace = componentModel?.GetService <VisualStudioWorkspace>(); Contract.Assert(dte2 != null); Contract.Assert(highlightService != null); Contract.Assert(workspace != null); var ideServices = new VisualStudioIdeServices(dte2, highlightService, workspace); this.ViewModel = new ToolView(ideServices); // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable, // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on // the object returned by the Content property. this.Content = new ToolPanel() { DataContext = this.ViewModel }; }
public VsUIServices(ICoreShell coreShell) { ProgressDialog = new VsProgressDialog(coreShell.Services); FileDialog = new VsFileDialog(coreShell); _coreShell = coreShell; _vsShell = VsPackage.GetGlobalService(typeof(SVsShell)) as IVsShell; _vsShell.AdviseBroadcastMessages(this, out _vsShellBroadcastEventsCookie); _uiShell = VsPackage.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell; }
public WpfToolWindowPane() : base(null) { GlobalServiceProvider = (IServiceProvider)VsPackage.GetGlobalService(typeof(IServiceProvider)); if (GlobalServiceProvider == null) { GlobalServiceProvider = new ServiceProvider((IOleServiceProvider)VsPackage.GetGlobalService(typeof(IOleServiceProvider))); } this._toolWindowControl = CreateToolWindowControl(); }
/// <summary> /// Retrieves Visual Studio global service from global VS service provider. /// This method is not thread safe and should not be called from async methods. /// </summary> /// <typeparam name="T">Service interface type such as IVsUiShell</typeparam> /// <param name="type">Service type if different from T, such as typeof(SVSUiShell)</param> /// <returns>Service instance of null if not found.</returns> public T GetGlobalService <T>(Type type = null) where T : class { this.AssertIsOnMainThread(); if (IsUnitTestEnvironment) { System.IServiceProvider sp = RPackage.Current; return(sp.GetService(type ?? typeof(T)) as T); } return(VsPackage.GetGlobalService(type ?? typeof(T)) as T); }
private void Initialize() { _vsShell = (IVsShell)VsPackage.GetGlobalService(typeof(SVsShell)); VsWpfOverrides.Apply(); var oleCm = (IOleComponentManager)VsPackage.GetGlobalService(typeof(SOleComponentManager)); ConfigureIdleSource(oleCm); ConfigurePackageServices(); CheckVsStarted(); }
//===================================================================== /// <summary> /// Get a service from the Sandcastle Help File Builder package /// </summary> /// <param name="throwOnError">True to throw an exception if the service cannot be obtained, /// false to return null.</param> /// <typeparam name="TInterface">The interface to obtain</typeparam> /// <typeparam name="TService">The service used to get the interface</typeparam> /// <returns>The service or null if it could not be obtained</returns> public static TInterface GetServiceFromPackage <TInterface, TService>(bool throwOnError) where TInterface : class where TService : class { TInterface service = MsVsShellPackage.GetGlobalService(typeof(TService)) as TInterface; if (service == null && throwOnError) { throw new InvalidOperationException("Unable to obtain service of type " + typeof(TService).Name); } return(service); }
private static VsAppShell GetInstance() { if (_instance != null) { return(_instance); } var componentModel = (IComponentModel)VsPackage.GetGlobalService(typeof(SComponentModel)); var instance = (VsAppShell)componentModel.DefaultExportProvider.GetExportedValue <IApplicationShell>(); instance.CompositionService = componentModel.DefaultCompositionService; instance.ExportProvider = componentModel.DefaultExportProvider; return(Interlocked.CompareExchange(ref _instance, instance, null) ?? instance); }
public static IVsPackage EnsurePackageLoaded(Guid guidPackage) { var shell = (IVsShell)VsPackage.GetGlobalService(typeof(IVsShell)); var guid = guidPackage; IVsPackage package; int hr = ErrorHandler.ThrowOnFailure(shell.IsPackageLoaded(ref guid, out package), VSConstants.E_FAIL); guid = guidPackage; if (hr != VSConstants.S_OK) { ErrorHandler.ThrowOnFailure(shell.LoadPackage(ref guid, out package), VSConstants.E_FAIL); } return(package); }
private static VsAppShell GetInstance() { if (_instance != null) { return(_instance); } ThreadHelper.ThrowIfNotOnUIThread(); var componentModel = (IComponentModel)VsPackage.GetGlobalService(typeof(SComponentModel)); var instance = (VsAppShell)componentModel.DefaultExportProvider.GetExportedValue <ICoreShell>(); return(Interlocked.CompareExchange(ref _instance, instance, null) ?? instance); }
private void CheckVsStarted() { _vsShell = (IVsShell)VsPackage.GetGlobalService(typeof(SVsShell)); _vsShell.GetProperty((int)__VSSPROPID4.VSSPROPID_ShellInitialized, out var value); if (value is bool) { if ((bool)value) { _application.FireStarted(); } else { _vsShell.AdviseShellPropertyChanges(this, out _vsShellEventsCookie); } } }
private void CheckVsStarted() { _vsShell = (IVsShell)VsPackage.GetGlobalService(typeof(SVsShell)); object value; _vsShell.GetProperty((int)__VSSPROPID4.VSSPROPID_ShellInitialized, out value); if (value is bool) { if ((bool)value) { Started?.Invoke(this, EventArgs.Empty); } else { _vsShell.AdviseShellPropertyChanges(this, out _vsShellEventsCookie); } } }
/// <summary> /// This displays a formatted message using the <see cref="IVsUIShell"/> service /// </summary> /// <param name="icon">The icon to show in the message box</param> /// <param name="message">The message format string</param> /// <param name="parameters">An optional list of parameters for the message format string</param> public static void ShowMessageBox(OLEMSGICON icon, string message, params object[] parameters) { ThreadHelper.ThrowIfNotOnUIThread(); Guid clsid = Guid.Empty; if (message == null) { throw new ArgumentNullException(nameof(message)); } if (MsVsShellPackage.GetGlobalService(typeof(SVsUIShell)) is IVsUIShell uiShell) { ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(0, ref clsid, Resources.PackageTitle, String.Format(CultureInfo.CurrentCulture, message, parameters), String.Empty, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, icon, 0, out _)); } }
private void Initialize() { MainThread = Thread.CurrentThread; MainThreadDispatcher = Dispatcher.FromThread(MainThread); var componentModel = (IComponentModel)VsPackage.GetGlobalService(typeof(SComponentModel)); _compositionService = componentModel.DefaultCompositionService; _exportProvider = componentModel.DefaultExportProvider; CheckVsStarted(); _settings = _exportProvider.GetExportedValue <IRSettings>(); _settings.LoadSettings(); ConfigureIdleSource(); ConfigureServices(); EditorShell.Current = this; }
public static TServiceImpl GetService <TService, TServiceImpl>() { return((TServiceImpl)VSPackage.GetGlobalService(typeof(TService))); }
public static TServiceInterface GetService <TService, TServiceInterface>() { return((TServiceInterface)Package.GetGlobalService(typeof(TService))); }