/// <summary> /// Initializes a new instance of the <see cref="QtMainMenu"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> private QtMainMenu(Package package) { if (package == null) { throw new ArgumentNullException("package"); } m_package = package; var commandService = VsServiceProvider .GetService <IMenuCommandService, OleMenuCommandService>(); if (commandService == null) { return; } foreach (var id in Enum.GetValues(typeof(CommandId))) { var command = new OleMenuCommand(execHandler, new CommandID(MainMenuGuid, (int)id)); command.BeforeQueryStatus += beforeQueryStatus; commandService.AddCommand(command); } }
static WaitDialog Create() { if (factory == null) { factory = VsServiceProvider .GetService <SVsThreadedWaitDialogFactory, IVsThreadedWaitDialogFactory>(); if (factory == null) { return(null); } } IVsThreadedWaitDialog2 vsWaitDialog = null; factory.CreateInstance(out vsWaitDialog); if (vsWaitDialog == null) { return(null); } return(new WaitDialog { VsWaitDialog = vsWaitDialog, Running = true, }); }
public override void ResetSettings() { ThreadHelper.ThrowIfNotOnUIThread(); QtMsBuildPath = ""; QmlDebuggerEnabled = true; QmlDebuggerTimeout = (Timeout)60000; HelpPreference = QtHelp.SourcePreference.Online; TryQtHelpOnF1Pressed = true; DesignerDetached = LinguistDetached = ResourceEditorDetached = false; BuildRunQtTools = ProjectTracking = true; BuildDebugInformation = false; BuildLoggerVerbosity = LoggerVerbosity.Quiet; //////// // Get Qt Help keyboard shortcut // var dte = VsServiceProvider.GetService <SDTE, DTE>(); var f1QtHelpBindings = dte.Commands.Item("QtVSTools.F1QtHelp")?.Bindings as Array; var binding = f1QtHelpBindings.Cast <string>() .Select(x => x.Split(new[] { "::" }, StringSplitOptions.None)) .Select(x => new { Scope = x.FirstOrDefault(), Shortcut = x.LastOrDefault() }) .FirstOrDefault(); if (binding != null) { QtHelpKeyBinding = string.Format("[{0}] {1}", binding.Scope, binding.Shortcut); } else { QtHelpKeyBinding = ""; } }
public void CollectActiveProjectItem() { try { DTE dte = (DTE)VsServiceProvider.GetService(typeof(DTE)); Document activeDocument = dte.ActiveDocument; if (activeDocument == null) { return; } IItem item = null; var projectName = activeDocument.ProjectItem.ContainingProject.FullName; if (SolutionInfo.IsOpenFolderModeActive()) { item = new CurrentDocument(activeDocument); Items.Add(item); } else if (string.IsNullOrWhiteSpace(projectName) == false) { item = new CurrentProjectItem(activeDocument.ProjectItem); Items.Add(item); } } catch (Exception e) { throw new Exception(e.Message); } }
/// <summary> /// Initializes a new instance of the <see cref="QtMainMenu"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> private QtSolutionContextMenu(Package package) { if (package == null) { throw new ArgumentNullException("package"); } m_package = package; var commandService = VsServiceProvider .GetService <IMenuCommandService, OleMenuCommandService>(); if (commandService == null) { return; } commandService.AddCommand(new OleMenuCommand(execHandler, new CommandID(SolutionContextMenuGuid, lUpdateOnSolutionId))); commandService.AddCommand(new OleMenuCommand(execHandler, new CommandID(SolutionContextMenuGuid, lReleaseOnSolutionId))); commandService.AddCommand(new OleMenuCommand(execHandler, new CommandID(SolutionContextMenuGuid, ChangeSolutionQtVersionId))); commandService.AddCommand(new OleMenuCommand(execHandler, new CommandID(SolutionContextMenuGuid, SolutionConvertToQtMsBuild))); }
public ItemsCollector(List <string> aExtensions = null) { mAcceptedFileExtensions = aExtensions; var dte2 = (DTE2)VsServiceProvider.GetService(typeof(DTE)); selectedItems = dte2.ToolWindows.SolutionExplorer.SelectedItems as Array; }
// TODO : Refactor this method. Generics can be a solution. public void CollectActiveProjectItem() { try { DTE dte = (DTE)VsServiceProvider.GetService(typeof(DTE)); Document activeDocument = dte.ActiveDocument; if (activeDocument == null) { return; } IItem item = null; if (SolutionInfo.IsOpenFolderModeActive()) { item = new CurrentDocument(activeDocument); } else { item = new CurrentProjectItem(activeDocument.ProjectItem); } Items.Add(item); } catch (Exception e) { throw new Exception(e.Message); } }
static WaitDialog Create(IVsThreadedWaitDialogFactory dialogFactory) { ThreadHelper.ThrowIfNotOnUIThread(); if (factory == null) { factory = dialogFactory ?? VsServiceProvider .GetService <SVsThreadedWaitDialogFactory, IVsThreadedWaitDialogFactory>(); if (factory == null) { return(null); } } factory.CreateInstance(out IVsThreadedWaitDialog2 vsWaitDialog); if (vsWaitDialog == null) { return(null); } return(new WaitDialog { VsWaitDialog = vsWaitDialog, Running = true, }); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { if (value is string) { var dte = VsServiceProvider.GetService <SDTE, DTE>(); if (dte == null) { return(ValidationResult.ValidResult); } var project = HelperFunctions.GetSelectedProject(dte); if (project == null) { return(ValidationResult.ValidResult); } var files = HelperFunctions.GetProjectFiles(project, Filter); if (files.Count == 0) { return(ValidationResult.ValidResult); } var fileName = (value as string).ToUpperInvariant(); if (files.FirstOrDefault(x => x.ToUpperInvariant() == fileName) != null) { return(new ValidationResult(false, @"File already exists.")); } return(ValidationResult.ValidResult); } return(new ValidationResult(false, @"Invalid file name.")); }
public static void Initialize() { Instance = new Launcher(); Instance.debugger = VsServiceProvider.GetService <IVsDebugger>(); Instance.debugger4 = VsServiceProvider.GetService <IVsDebugger, IVsDebugger4>(); if (Instance.debugger != null && Instance.debugger4 != null) { Instance.debugger.AdviseDebugEventCallback(Instance); } var outputWindow = VsServiceProvider.GetService <SVsOutputWindow, IVsOutputWindow>(); if (outputWindow != null) { var debugOutputGuid = VSConstants.OutputWindowPaneGuid.DebugPane_guid; var result = outputWindow.GetPane(ref debugOutputGuid, out Instance.debugOutput); if (result != VSConstants.S_OK || Instance.debugOutput == null) { Messages.PaneMessageSafe(Vsix.Instance.Dte, "Unable to get reference to output window debug pane.", 5000); } } else { Messages.PaneMessageSafe(Vsix.Instance.Dte, "Unable to get reference to output window.", 5000); } }
/// <summary> /// Initializes a new instance of the <see cref="QtMainMenu"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> private QtItemContextMenu(Package package) { if (package == null) { throw new ArgumentNullException("package"); } m_package = package; var commandService = VsServiceProvider .GetService <IMenuCommandService, OleMenuCommandService>(); if (commandService == null) { return; } var command = new OleMenuCommand(execHandler, new CommandID(ItemContextMenuGuid, lUpdateOnItemId)); command.BeforeQueryStatus += beforeQueryStatus; commandService.AddCommand(command); command = new OleMenuCommand(execHandler, new CommandID(ItemContextMenuGuid, lReleaseOnItemId)); command.BeforeQueryStatus += beforeQueryStatus; commandService.AddCommand(command); }
QtHelpMenu(Package pkg) { if (pkg == null) { throw new ArgumentNullException("package"); } package = pkg; var commandService = VsServiceProvider .GetService <IMenuCommandService, OleMenuCommandService>(); if (commandService == null) { return; } var menuCommandID = new CommandID(HelpMenuGroupGuid, F1QtHelpId); commandService.AddCommand(new MenuCommand(F1QtHelpCallback, menuCommandID)); menuCommandID = new CommandID(HelpMenuGroupGuid, ViewQtHelpId); commandService.AddCommand(new MenuCommand(ViewQtHelpCallback, menuCommandID)); var command = new OleMenuCommand(ExecHandler, new CommandID(HelpMenuGroupGuid, OfflineDocumentationId)); command.BeforeQueryStatus += BeforeQueryStatus; commandService.AddCommand(command); command = new OleMenuCommand(ExecHandler, new CommandID(HelpMenuGroupGuid, OnlineDocumentationId)); command.BeforeQueryStatus += BeforeQueryStatus; commandService.AddCommand(command); }
private void OnBrowseButtonClick(object sender, RoutedEventArgs e) { var block = System.IntPtr.Zero; try { var dte = VsServiceProvider.GetService <DTE>(); var serviceProvider = new ServiceProvider(dte as IServiceProvider); var iVsUIShell = VsServiceProvider.GetService <SVsUIShell, IVsUIShell>(); System.IntPtr owner; iVsUIShell.GetDialogOwnerHwnd(out owner); var browseInfo = new VSBROWSEINFOW[1]; browseInfo[0].lStructSize = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW)); browseInfo[0].pwzInitialDir = Location; browseInfo[0].pwzDlgTitle = @"Location"; browseInfo[0].hwndOwner = owner; browseInfo[0].nMaxDirName = 260; block = Marshal.AllocCoTaskMem(520); browseInfo[0].pwzDirName = block; var result = iVsUIShell.GetDirectoryViaBrowseDlg(browseInfo); if (result == Microsoft.VisualStudio.VSConstants.S_OK) { Location = Marshal.PtrToStringAuto(browseInfo[0].pwzDirName); LocationComboBox.Text = Marshal.PtrToStringAuto(browseInfo[0].pwzDirName); } } finally { if (block != System.IntPtr.Zero) { Marshal.FreeCoTaskMem(block); } } }
public async Task RunClangTidyAsync(int aCommandId, CommandUILocation commandUILocation, Document document = null) { await PrepareCommmandAsync(commandUILocation); await Task.Run(() => { lock (mutex) { try { using var silentFileController = new SilentFileChangerController(); using var fileChangerWatcher = new FileChangerWatcher(); var tidySettings = SettingsProvider.TidySettingsModel; if (CommandIds.kTidyFixId == aCommandId || tidySettings.TidyOnSave) { fileChangerWatcher.OnChanged += FileOpener.Open; var dte2 = VsServiceProvider.GetService(typeof(DTE)) as DTE2; string solutionFolderPath = SolutionInfo.IsOpenFolderModeActive() ? dte2.Solution.FullName : dte2.Solution.FullName .Substring(0, dte2.Solution.FullName.LastIndexOf('\\')); fileChangerWatcher.Run(solutionFolderPath); FilePathCollector fileCollector = new FilePathCollector(); var filesPath = fileCollector.Collect(mItemsCollector.Items).ToList(); silentFileController.SilentFiles(filesPath); silentFileController.SilentFiles(dte2.Documents); } if (tidySettings.DetectClangTidyFile && !mItemsCollector.IsEmpty) { // Check for .clang-tidy congif file if (FileSystem.SearchAllTopDirectories(mItemsCollector.Items[0].GetPath(), FileSystem.ConfigClangTidyFileName)) { tidySettings.UseChecksFrom = ClangTidyUseChecksFrom.TidyFile; } else { tidySettings.UseChecksFrom = ClangTidyUseChecksFrom.PredefinedChecks; } var settingsHandlder = new SettingsHandler(); settingsHandlder.SaveSettings(); } RunScript(aCommandId, false); } catch (Exception exception) { VsShellUtilities.ShowMessageBox(AsyncPackage, exception.Message, "Error", OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } } }); }
/// <summary> /// Check if VS runs in Open Folder Mode /// </summary> /// <returns>True if VS runs in Open Folder Mode. False otherwise.</returns> public static bool IsOpenFolderModeActive() { var solution = (IVsSolution)VsServiceProvider.GetService(typeof(SVsSolution)); solution.GetProperty((int)__VSPROPID7.VSPROPID_IsInOpenFolderMode, out object folderMode); OpenFolderModeActive = (bool)folderMode; return(OpenFolderModeActive); }
protected VCLanguageManagerValidationRule() { ValidatesOnTargetUpdated = true; var dte = VsServiceProvider.GetService <DTE>(); Vclm = dte.GetObject("VCLanguageManager") as VCLanguageManager; }
/// <summary> /// Check if any VS Solution is open /// </summary> /// <returns>True if any VS Solution is open. False otherwise.</returns> public static bool IsSolutionOpen() { var solution = (IVsSolution)VsServiceProvider.GetService(typeof(SVsSolution)); solution.GetProperty((int)__VSPROPID.VSPROPID_IsSolutionOpen, out object open); SolutionOpen = (bool)open; return(SolutionOpen); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // Switches to the UI thread in order to consume some services used in command initialization await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); await RegisterVsServicesAsync(); TaskErrorViewModel.Errors.Clear(); SquiggleViewModel.Squiggles.Clear(); mCommandController = new CommandController(this); CommandTestUtility.CommandController = mCommandController; var vsOutputWindow = VsServiceProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow; mOutputWindowController = new OutputWindowController(); mOutputWindowController.Initialize(this, vsOutputWindow); mRunningDocTableEvents = new RunningDocTableEvents(this); mErrorWindowController = new ErrorWindowController(this); #region Get Pointer to IVsSolutionEvents if (VsServiceProvider.TryGetService(typeof(SVsSolution), out object vsSolutionService)) { var vsSolution = vsSolutionService as IVsSolution; UnadviseSolutionEvents(vsSolution); AdviseSolutionEvents(vsSolution); } #endregion // Get the build and command events from DTE if (VsServiceProvider.TryGetService(typeof(DTE), out object dte)) { var dte2 = dte as DTE2; mBuildEvents = dte2.Events.BuildEvents; mCommandEvents = dte2.Events.CommandEvents; mDteEvents = dte2.Events.DTEEvents; } mSettingsHandler = new SettingsHandler(); mSettingsHandler.InitializeSettings(); await mCommandController.InitializeCommandsAsync(this); mSettingsProvider = new SettingsProvider(); RegisterToEvents(); LicenseController mLicenseController = new LicenseController(); await mLicenseController.CheckLicenseAsync(); await base.InitializeAsync(cancellationToken, progress); }
protected VCLanguageManagerValidationRule() { ThreadHelper.ThrowIfNotOnUIThread(); ValidatesOnTargetUpdated = true; var dte = VsServiceProvider.GetService <DTE>(); Vclm = dte.GetObject("VCLanguageManager") as VCLanguageManager; }
public bool SaveVersion(string versionName, string path, bool checkPath = true) { var verName = versionName?.Trim().Replace(@"\", "_"); if (string.IsNullOrEmpty(verName)) { return(false); } var dir = string.Empty; if (verName != "$(QTDIR)") { DirectoryInfo di; try { di = new DirectoryInfo(path); } catch { di = null; } if (di?.Exists == true) { dir = di.FullName; } else if (!checkPath) { dir = path; } else { return(false); } } string rootKeyPath = "SOFTWARE\\" + Resources.registryRootPath; string versionKeyPath = strVersionKey + "\\" + verName; using (var key = Registry.CurrentUser.CreateSubKey(rootKeyPath)) { if (key == null) { Messages.PaneMessageSafe(VsServiceProvider.GetService <DTE>(), "ERROR: root registry key creation failed", timeout: 5000); return(false); } using (var versionKey = key.CreateSubKey(versionKeyPath)) { if (versionKey == null) { Messages.PaneMessageSafe(VsServiceProvider.GetService <DTE>(), "ERROR: version registry key creation failed", timeout: 5000); return(false); } versionKey.SetValue("InstallDir", dir); } } RefreshVersionNames(); return(true); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // Switches to the UI thread in order to consume some services used in command initialization await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); await RegisterVsServicesAsync(); mCommandController = new CommandController(this); CommandTestUtility.CommandController = mCommandController; var vsOutputWindow = VsServiceProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow; mOutputWindowController = new OutputWindowController(); mOutputWindowController.Initialize(this, vsOutputWindow); mRunningDocTableEvents = new RunningDocTableEvents(this); mErrorWindowController = new ErrorWindowController(this); #region Get Pointer to IVsSolutionEvents if (VsServiceProvider.TryGetService(typeof(SVsSolution), out object vsSolutionService)) { var vsSolution = vsSolutionService as IVsSolution; UnadviseSolutionEvents(vsSolution); AdviseSolutionEvents(vsSolution); } #endregion // Get-Set the build and command events from DTE if (VsServiceProvider.TryGetService(typeof(DTE), out object dte)) { var dte2 = dte as DTE2; mBuildEvents = dte2.Events.BuildEvents; mCommandEvents = dte2.Events.CommandEvents; mDteEvents = dte2.Events.DTEEvents; windowEvents = dte2.Events.WindowEvents; } var settingsHandler = new SettingsHandler(); settingsHandler.InitializeSettings(); await settingsHandler.InitializeAccountSettingsAsync(); string version = SettingsProvider.GeneralSettingsModel.Version; ShowToolbar(version); UpdateVersion(version); //.SafeFireAndForget(); await mCommandController.InitializeCommandsAsync(this); RegisterToEvents(); await base.InitializeAsync(cancellationToken, progress); }
public static bool ContainsCppProject() { DTE2 dte = (DTE2)VsServiceProvider.GetService(typeof(DTE)); Solution solution = dte.Solution; if (solution == null) { return(false); } return(AnyCppProject(solution)); }
public static void Initialize() { ThreadHelper.ThrowIfNotOnUIThread(); Instance = new Launcher(); Instance.debugger = VsServiceProvider.GetService <IVsDebugger>(); Instance.debugger4 = VsServiceProvider.GetService <IVsDebugger, IVsDebugger4>(); if (Instance.debugger != null && Instance.debugger4 != null) { Instance.debugger.AdviseDebugEventCallback(Instance); } }
/// <summary> /// Collect all selected items in the Solution explorer for commands /// </summary> public void CollectSelectedFiles(ProjectItem aProjectItem, bool aClangFormatFlag = false) { try { var dte2 = VsServiceProvider.GetService(typeof(DTE)) as DTE2; Array selectedItems = dte2.ToolWindows.SolutionExplorer.SelectedItems as Array; if (selectedItems == null || selectedItems.Length == 0) { return; } foreach (UIHierarchyItem item in selectedItems) { if (item.Object is Solution) { var solution = item.Object as Solution; if (aClangFormatFlag) { GetProjectItem(solution); } else { GetProjectsFromSolution(solution); } } else if (item.Object is Project) { var project = item.Object as Project; if (aClangFormatFlag) { GetProjectItem(project); } else { AddProject(project); } } else if (item.Object is ProjectItem) { GetProjectItem(item.Object as ProjectItem); } } } catch (Exception e) { throw new Exception(e.Message); } }
private QtHelp() { var commandService = VsServiceProvider .GetService <IMenuCommandService, OleMenuCommandService>(); if (commandService == null) { return; } var menuCommandID = new CommandID(MainMenuGuid, F1QtHelpId); commandService.AddCommand(new MenuCommand(F1QtHelpEventHandler, menuCommandID)); }
void RefreshVersionNames() { var rootKeyPath = "SOFTWARE\\" + Resources.registryRootPath; try { using (var rootKey = Registry.CurrentUser.OpenSubKey(rootKeyPath, true)) using (var versionsKey = rootKey.OpenSubKey(strVersionKey, true)) { versionsKey.SetValue("VersionNames", string.Join(";", GetVersions())); } } catch (Exception e) { Messages.PaneMessageSafe(VsServiceProvider.GetService <DTE>(), e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace, 5000); } }
private void GetVisualStudioInfo(out string edition, out string version, out IItem item, bool onFile) { ThreadHelper.ThrowIfNotOnUIThread(); var dte = (DTE2)VsServiceProvider.GetService(typeof(DTE)); edition = dte.Edition; mVsVersions.TryGetValue(dte.Version, out string vsVersion); version = vsVersion; item = onFile ? (IItem) new CurrentProjectItem(dte.Solution.Projects.Item(1).ProjectItems.Item(4)) : (IItem) new CurrentProject(dte.Solution.Projects.Item(2)); }
private bool Initialize( QmlEngine engine, IDebugProcess2 nativeProc, string execPath, string execArgs) { Engine = engine; NativeProc = nativeProc; var nativeProcId = new AD_PROCESS_ID[1]; nativeProc.GetPhysicalProcessId(nativeProcId); NativeProcId = nativeProcId[0].dwProcessId; ExecPath = execPath; ExecArgs = execArgs; Debugger = QmlDebugger.Create(this, execPath, execArgs); if (Debugger == null) { return(false); } VsDebugger = VsServiceProvider.GetService <IVsDebugger>(); if (VsDebugger != null) { ThreadHelper.JoinableTaskFactory.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); VsDebugger.AdviseDebugEventCallback(this); }); } vsDebuggerThreadDispatcher = Dispatcher.CurrentDispatcher; ProcessId = Guid.NewGuid(); CurrentFrames = new List <StackFrame>(); lock (criticalSectionGlobal) { if (runningPrograms == 0) { originalBreakAllProcesses = BreakAllProcesses; } runningPrograms++; } return(true); }
public List <string> GetProjectsToIgnore() { List <string> projectsToIgnore = new List <string>(); DTE2 dte2 = VsServiceProvider.GetService(typeof(DTE)) as DTE2; Array selectedItems = dte2.ToolWindows.SolutionExplorer.SelectedItems as Array; foreach (UIHierarchyItem item in selectedItems) { if (item.Object is Project) { var project = item.Object as Project; projectsToIgnore.Add(project.Name); } } return(projectsToIgnore); }
private bool Initialize(ITextView textView, ITextBuffer buffer) { this.textView = textView; this.buffer = buffer; debugger = VsServiceProvider.GetService <IVsDebugger>(); if (debugger == null) { return(false); } var componentModel = VsServiceProvider .GetService <SComponentModel, IComponentModel>(); if (componentModel == null) { return(false); } var editorFactory = componentModel.GetService <IVsEditorAdaptersFactoryService>(); if (editorFactory == null) { return(false); } vsTextView = editorFactory.GetViewAdapter(textView); if (vsTextView == null) { return(false); } if (vsTextView.GetBuffer(out textLines) != VSConstants.S_OK) { return(false); } if (vsTextView.AddCommandFilter(this, out nextTarget) != VSConstants.S_OK) { return(false); } textView.Closed += TextView_Closed; return(true); }