protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); DTE2 dte = await VS.GetServiceAsync <EnvDTE.DTE, DTE2>(); if (dte?.ActiveDocument == null) { return; } try { DocumentView docView = await VS.Documents.GetActiveDocumentViewAsync(); if (docView?.TextView != null) { ResetZoom(dte, docView.TextView); } } catch (Exception ex) { await ex.LogAsync(); } }
static XSharpXMLDocTools() { ThreadHelper.JoinableTaskFactory.Run(async delegate { _XMLMemberIndexService = await VS.GetServiceAsync <SVsXMLMemberIndexService, IVsXMLMemberIndexService>(); }); Assumes.Present(_XMLMemberIndexService); return; }
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) { var webservice = await VS.GetServiceAsync <SVsWebBrowsingService, IVsWebBrowsingService>(); if (webservice != null) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); string url = "https://www.xsharp.eu"; IVsWindowFrame frame = null; webservice.Navigate(url, (uint)(__VSWBNAVIGATEFLAGS.VSNWB_WebURLOnly | __VSWBNAVIGATEFLAGS.VSNWB_ForceNew), out frame); frame.Show(); } }
/// <summary> /// Force load package. /// A hack method which is called from analyzers to ensure that the package is loaded before diagnostics are executed. /// </summary> /// <returns/> public static async System.Threading.Tasks.Task ForceLoadPackageAsync() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsShell shell = await VS.GetServiceAsync <SVsShell, IVsShell>(); if (shell == null) { return; } var packageToBeLoadedGuid = new Guid(PackageGuidString); shell.LoadPackage(ref packageToBeLoadedGuid, out var _); await System.Threading.Tasks.TaskScheduler.Default; }
private void RegisterDebuggerEvents() { int hr; ThreadHelper.JoinableTaskFactory.Run(async delegate { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); m_debugger = await VS.GetServiceAsync <SVsShellDebugger, IVsDebugger>(); if (m_debugger != null) { hr = m_debugger.AdviseDebuggerEvents(this, out m_Debuggercookie); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hr); // Get initial value DBGMODE[] modeArray = new DBGMODE[1]; hr = m_debugger.GetMode(modeArray); XSettings.DebuggerMode = (DebuggerMode)modeArray[0]; } }); }
/// <summary>Adds one or more files to the project.</summary> public static async Task AddFilesToProjectAsync(this Project project, params string[] files) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (project == null || project.IsKind(ProjectTypes.ASPNET_Core, ProjectTypes.DOTNET_Core, ProjectTypes.SSDT)) { return; } DTE2?dte = await VS.GetDTEAsync(); if (project.IsKind(ProjectTypes.WEBSITE_PROJECT)) { Command command = dte.Commands.Item("SolutionExplorer.Refresh"); if (command.IsAvailable) { dte.ExecuteCommand(command.Name); } return; } IVsSolution?solutionService = await VS.GetServiceAsync <SVsSolution, IVsSolution>(); solutionService.GetProjectOfUniqueName(project.UniqueName, out IVsHierarchy? hierarchy); if (hierarchy == null) { return; } var ip = (IVsProject)hierarchy; var result = new VSADDRESULT[files.Count()]; ip.AddItem(VSConstants.VSITEMID_ROOT, VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE, string.Empty, (uint)files.Count(), files.ToArray(), IntPtr.Zero, result); }
public async Task <ICollection <string> > GetSelectedFilesAsync() { var monitorSelection = await VS.GetServiceAsync <SVsShellMonitorSelection, IVsMonitorSelection>().ConfigureAwait(true); await JoinableTaskFactory.SwitchToMainThreadAsync(); var selection = monitorSelection?.GetSelectedProjectItems(); if (selection == null) { return(Array.Empty <string>()); } var files = selection .Select(item => item.GetMkDocument()) .ExceptNullItems() .ToArray(); return(files); }
/// <summary> /// Converts an ImageMoniker to an IVsUIObject in the specified size. /// </summary> public static async Task <IVsUIObject> ToUiObjectAsync(this ImageMoniker moniker, int size) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsImageService2 imageService = await VS.GetServiceAsync <SVsImageService, IVsImageService2>(); Color backColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey); var imageAttributes = new ImageAttributes { Flags = (uint)_ImageAttributesFlags.IAF_RequiredFlags | unchecked ((uint)_ImageAttributesFlags.IAF_Background), ImageType = (uint)_UIImageType.IT_Bitmap, Format = (uint)_UIDataFormat.DF_WPF, Dpi = 96, LogicalHeight = size, LogicalWidth = size, Background = (uint)backColor.ToArgb(), StructSize = Marshal.SizeOf(typeof(ImageAttributes)) }; return(imageService.GetImage(moniker, imageAttributes)); }