private void OnProjectBuildFinished(string project, string projectConfig, string platform, string solutionConfig, bool success) { if (!_canExecute || success || !Enabled || !Active) { return; } _canExecute = false; _dte.ExecuteCommand(CancelBuildCommand); var pane = _dte.ToolWindows.OutputWindow.OutputWindowPanes .Cast <OutputWindowPane>() .FirstOrDefault(x => x.Guid == BuildPaneGuid); if (pane != null) { var path = Path.GetFileNameWithoutExtension(project); var message = string.Format("StopOnFirstBuildError: Build cancelled because project \"{0}\" failed to build.{1}", path, Environment.NewLine); pane.OutputString(message); } if (ShowErrorList) { _dte.ExecuteCommand(ViewErrorListCommand); } }
private static void ResetZoom(DTE2 dte, IWpfTextView view) { ThreadHelper.ThrowIfNotOnUIThread(); view.ZoomLevel = Options.Instance.DefaultZoomLevel; dte.ExecuteCommand("View.ZoomOut"); dte.ExecuteCommand("View.ZoomIn"); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { DTE2 dte = GetDTE(); try { Document activeDoc = dte.ActiveDocument; if (activeDoc != null && activeDoc.ProjectItem != null && activeDoc.ProjectItem.ContainingProject != null) { TextDocument objTextDoc = activeDoc.Object("TextDocument") as TextDocument; EditPoint2 startPoint = objTextDoc.StartPoint.CreateEditPoint() as EditPoint2; EditPoint2 endPoint = objTextDoc.EndPoint.CreateEditPoint() as EditPoint2; string wholeWindowText = startPoint.GetText(endPoint); wholeWindowText = Regex.Replace(wholeWindowText, @"^\s+${2,}", string.Empty, RegexOptions.Multiline); wholeWindowText = Regex.Replace(wholeWindowText, @"\r\n\n\s*\}\r\n\s*$", "\r\n}\r\n", RegexOptions.Multiline); wholeWindowText = Regex.Replace(wholeWindowText, @"\r\n\n\s*\}", "\r\n}", RegexOptions.Multiline); wholeWindowText = Regex.Replace(wholeWindowText, @"\{\r\n\n", "{\r\n", RegexOptions.Multiline); startPoint.ReplaceText(endPoint, wholeWindowText, 3); startPoint.SmartFormat(endPoint); dte.ActiveDocument.Activate(); dte.ExecuteCommand("Edit.FormatDocument"); dte.ExecuteCommand("Edit.SortUsings"); } } catch (Exception ex) { System.Diagnostics.Debug.Write(ex); } }
public void slnExplUIHierarchyExample(object sender, EventArgs e) { //UIHierarchyItem UIH = dte.ToolWindows.SolutionExplorer.UIHierarchyItems.Item(1); //string fileName = dte.ActiveDocument.FullName; //bool found = false; //EnumUIHierarchyItems(UIH.UIHierarchyItems // , (item) => // { // if (item.Object is ProjectItem) // { // ProjectItem pItem = item.Object as ProjectItem; // if (pItem.Properties != null) // { // object FullPath = pItem.Properties.Item("FullPath").Value; // if (FullPath != null && FullPath.ToString().Equals(fileName)) // { // WriteOutput(string.Format("FullName:{0},Kind:{1},{2}", pItem.Document.FullName, pItem.Kind, Environment.NewLine)); // return true; // } // } // } // return false; // } //, ref found); WriteOutput("Location Ready"); dte.ExecuteCommand("View.TrackActivityinSolutionExplorer", "true"); dte.ExecuteCommand("View.TrackActivityinSolutionExplorer", "false"); WriteOutput("Location Success"); }
private void AddCommandToFile(object sender, EventArgs e) { OleMenuCommand button = (OleMenuCommand)sender; var item = ProjectHelpers.GetSelectedItems().FirstOrDefault(); if (item == null || item.FileCount == 0) { return; } string file = item.FileNames[1]; bool isSolution; string configPath = GetConfigPath(item, out isSolution); bool configExist = File.Exists(configPath); JObject json = CommandHelpers.GetJsonContent(configPath, file); ProjectHelpers.CheckFileOutOfSourceControl(configPath); File.WriteAllText(configPath, json.ToString(), new UTF8Encoding(false)); if (!configExist) { AddFileToProject(item, isSolution, configPath); _dte.ItemOperations.OpenFile(configPath); _dte.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument"); _dte.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument"); } OpenTaskRunnerExplorer(); _dte.StatusBar.Text = $"File successfully added to {Constants.FILENAME}"; }
private static void RunFunctionalTests(DTE2 dte2) { Console.WriteLine("Wait for 10 seconds before executing the command so that VS can be activated"); Thread.Sleep(TimeSpan.FromSeconds(10)); Console.WriteLine("For testing, open output window"); dte2.ExecuteCommand("View.Output"); Console.WriteLine("Executing View.PackageManagerConsole menu on VS via DTE..."); // Launch Powershell Console by executing View.PackageManagerConsole menu dte2.ExecuteCommand(CommandNameForPMC); Console.WriteLine("Wait for 5 secs for the powershell host to initialize before executing the next command"); Thread.Sleep(TimeSpan.FromSeconds(5)); Console.WriteLine("Import the NuGet.Tests powershell module so that 'Run-Test' can be executed"); dte2.ExecuteCommand(CommandNameForPMC, @"Import-Module " + Path.Combine(TestPath, "nuget.Tests.psm1")); Thread.Sleep(TimeSpan.FromSeconds(2)); Console.WriteLine("Import the API.Test.dll module so that 'Run-Test' can be executed"); dte2.ExecuteCommand(CommandNameForPMC, @"Import-Module " + Path.Combine(TestPath, "API.Test.dll")); Thread.Sleep(TimeSpan.FromSeconds(2)); // Execute the main command now that the necessary modules have been imported dte2.ExecuteCommand(CommandNameForPMC, Command); Console.WriteLine("Started running functional tests..."); }
private int ReadErrorsAndWarnings(DTE dte) { int numberOfErrors = 0; DTE2 dte2 = (DTE2)dte; dte2.ExecuteCommand("View.ErrorList", " "); EnvDTE80.ErrorList errors = dte2.ToolWindows.ErrorList; errors.Parent.Activate(); errors.ShowWarnings = true; errors.ShowErrors = true; errors.ShowMessages = true; errors.Parent.Activate(); dte2.ExecuteCommand("View.ErrorList", " "); for (int i = 1; i <= errors.ErrorItems.Count; i++) { try { TestContext.WriteLine(errors.ErrorItems.Item(i).Description); if (!IgnoreWarning(errors.ErrorItems.Item(i).Description.ToString())) { numberOfErrors++; TestContext.WriteLine("BuildError: " + errors.ErrorItems.Item(i).Description.ToString() + " in " + errors.ErrorItems.Item(i).FileName); } } catch { } } return(numberOfErrors); }
void RemoveAndSort() { try { Dte.ExecuteCommand("Edit.RemoveAndSort", string.Empty); } catch (COMException) { } }
private async System.Threading.Tasks.Task CreateFile(string inputCamel, string folder, object selectedItem, Project project, TemplateType templateType) { var file = CreateFileInfo(inputCamel, folder, templateType); PackageUtilities.EnsureOutputPath(folder); if (!file.Exists) { int position = await WriteFileAsync(project, file.FullName, inputCamel, templateType); try { ProjectItem projectItem = null; if (selectedItem is ProjectItem projItem) { if ("{6BB5F8F0-4483-11D3-8BCF-00C04F8EC28C}" == projItem.Kind) // Constants.vsProjectItemKindVirtualFolder { projectItem = projItem.ProjectItems.AddFromFile(file.FullName); } } if (projectItem == null) { projectItem = project.AddFileToProject(file); } if (file.FullName.EndsWith("__dummy__")) { projectItem?.Delete(); return; } VsShellUtilities.OpenDocument(this, file.FullName); // Move cursor into position if (position > 0) { Microsoft.VisualStudio.Text.Editor.IWpfTextView view = ProjectHelpers.GetCurentTextView(); view?.Caret.MoveTo(new SnapshotPoint(view.TextBuffer.CurrentSnapshot, position)); } _dte.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument"); _dte.ActiveDocument.Activate(); } catch (Exception ex) { Logger.Log(ex); } } else { System.Windows.Forms.MessageBox.Show("The file '" + file + "' already exist."); } }
public static void ReloadProject(Project project) { var solutionName = Path.GetFileNameWithoutExtension(dte.Solution.FullName); var projectName = project.Name; DTE.Windows.Item(EnvDTEConstants.vsWindowKindSolutionExplorer).Activate(); ((DTE2)dte).ToolWindows.SolutionExplorer.GetItem(solutionName + @"\" + projectName).Select(vsUISelectionType.vsUISelectionTypeSelect); dte.ExecuteCommand("Project.UnloadProject"); dte.ExecuteCommand("Project.ReloadProject"); }
void InsertXaml(String xaml) { if (_hasBeenApplied) { _dte2.ExecuteCommand("Edit.Undo"); _dte2.ExecuteCommand("Edit.Undo"); } var ts = (TextSelection)_dte2.ActiveDocument.Selection; ts.Insert(xaml); _dte2.ExecuteCommand("Edit.FormatDocument"); }
void InsertXaml(String xaml) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); if (_hasBeenApplied) { _dte2.ExecuteCommand("Edit.Undo"); _dte2.ExecuteCommand("Edit.Undo"); } var ts = (TextSelection)_dte2.ActiveDocument.Selection; ts.Insert(xaml); _dte2.ExecuteCommand("Edit.FormatDocument"); }
/// <summary> /// 注册别名. /// </summary> /// <param name="cCmd">完整命令</param> /// <param name="cAlias">别名</param> /// <param name="bDelete">是删除还是注册.T.删除.</param> /// <remarks></remarks> public static void RegAlias(string cCmd, string cAlias, bool bDelete) { try { chDTE.ExecuteCommand("Tools.Alias ", cAlias + " " + (bDelete ? " /delete" : cCmd).ToString()); ShowInfo((bDelete ? "删除" : "注册").ToString() + "别名'" + cAlias + "'成功!"); } catch (Exception) { ShowInfo((bDelete ? "删除" : "注册").ToString() + "别名" + cAlias + "失败!"); } }
private void ReloadProject(DTE2 dte2, Project currentProject) { // we need to unload and reload the project dte2.ExecuteCommand("File.SaveAll"); string solutionName = System.IO.Path.GetFileNameWithoutExtension(dte2.Solution.FullName); string projectName = currentProject.Name; dte2.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Activate(); ((DTE2)dte2).ToolWindows.SolutionExplorer.GetItem(solutionName + @"\" + projectName).Select(vsUISelectionType.vsUISelectionTypeSelect); dte2.ExecuteCommand("Project.UnloadProject"); System.Threading.Thread.Sleep(500); dte2.ExecuteCommand("Project.ReloadProject"); }
void OpenZebbleFile(string value, string projectPath) { var zebbleFile = FindZebbleModuleInAppUI(value, projectPath); if (!File.Exists(zebbleFile)) { App.StatusBar.Text = "Cannot find " + value; } else { App.ExecuteCommand("File.OpenFile", zebbleFile.WrapInQuatation()); App.StatusBar.Text = "Ready"; } }
public static bool ExecuteCommandIfExists(string command, DTE2 dte) { if (dte.Commands.Cast <Command>().Any(dtecommand => dtecommand.Name == command)) { try { dte.ExecuteCommand(command); OutputWindowHandler.WriteMessage("Command executed"); } catch (COMException e) { if (command == "ReSharper_Suspend") { OutputWindowHandler.WriteMessage("Excecution of '" + command + "' failed. Maybe ReSharper is already suspended? \n " + e.ToString()); } else { //Command may be found but cannot be executed OutputWindowHandler.WriteMessage("Excecution of '" + command + "' failed. \n " + e.ToString()); } return(false); } return(true); } return(false); }
///////////////////////////////////////////////////////// #region IIde Member public void OpenSolution(string path) { if (path != null) { _dte.ExecuteCommand("File.OpenProject", String.Format("\"{0}\"", path)); } }
private OutputWindowPane PrepareOutputWindowPane() { dte.ExecuteCommand("View.Output"); OutputWindow outputWindow = dte.ToolWindows.OutputWindow; OutputWindowPane outputWindowPane = null; foreach (OutputWindowPane pane in outputWindow.OutputWindowPanes) { if (pane.Name == "MonoTools") { outputWindowPane = pane; break; } } if (outputWindowPane == null) { outputWindowPane = outputWindow.OutputWindowPanes.Add("MonoTools"); } outputWindowPane.Activate(); outputWindowPane.Clear(); outputWindowPane.OutputString($"MonoTools {App.Version} © johnshope.com 2016\r\n"); return(outputWindowPane); }
public static bool ExecuteCommandIfExists(string command, DTE2 dte) { if (dte.Commands.Cast<Command>().Any(dtecommand => dtecommand.Name == command)) { try { dte.ExecuteCommand(command); OutputWindowHandler.WriteMessage("Command executed"); } catch (COMException e) { if(command == "ReSharper_Suspend") { OutputWindowHandler.WriteMessage("Excecution of '" + command + "' failed. Maybe ReSharper is already suspended? \n " + e.ToString()); } else { //Command may be found but cannot be executed OutputWindowHandler.WriteMessage("Excecution of '" + command + "' failed. \n " + e.ToString()); } return false; } return true; } return false; }
public ErrorHighlighter(IWpfTextView view, ITextDocument document, IVsTaskList tasks, DTE2 dte) { _view = view; _document = document; _text = new Adornment(); _tasks = tasks; _dispatcher = Dispatcher.CurrentDispatcher; _adornmentLayer = view.GetAdornmentLayer(ErrorHighlighterFactory.LayerName); _view.ViewportHeightChanged += SetAdornmentLocation; _view.ViewportWidthChanged += SetAdornmentLocation; _text.MouseUp += (s, e) => { dte.ExecuteCommand("View.ErrorList"); }; _timer = new Timer(750); _timer.Elapsed += (s, e) => { _timer.Stop(); Task.Run(() => { _dispatcher.Invoke(new Action(() => { Update(false); }), DispatcherPriority.ApplicationIdle, null); }); }; _timer.Start(); }
public override void Run(DTE2 app) { try { if (app.ActiveDocument == null) { app.StatusBar.Text = "No Active Document"; return; } var sisterFile = app.ActiveDocument.FullName.FindSisterFile(); if (sisterFile.HasValue() && File.Exists(sisterFile)) { sisterFile = sisterFile.WrapInQuatation(); // handle white spaces in the path app.ExecuteCommand("File.OpenFile", sisterFile); app.StatusBar.Text = "Ready"; } else { app.StatusBar.Text = "File Not found: " + sisterFile; } } catch (Exception err) { ErrorNotification.EmailError(err); } }
public RoslynCodeAnalysisHelper(IWpfTextView view, ITextDocument document, IVsTaskList tasks, DTE2 dte, SVsServiceProvider serviceProvider, IVsActivityLog log) { _view = view; _document = document; _text = new Adornment(); _tasks = tasks; _serviceProvider = serviceProvider; _log = log; _dispatcher = Dispatcher.CurrentDispatcher; _adornmentLayer = view.GetAdornmentLayer(RoslynCodeAnalysisFactory.LayerName); _view.ViewportHeightChanged += SetAdornmentLocation; _view.ViewportWidthChanged += SetAdornmentLocation; _text.MouseUp += (s, e) => dte.ExecuteCommand("View.ErrorList"); _timer = new Timer(750); _timer.Elapsed += (s, e) => { _timer.Stop(); System.Threading.Tasks.Task.Run(() => { _dispatcher.Invoke(new Action(() => Update(false)), DispatcherPriority.ApplicationIdle, null); }); }; _timer.Start(); }
private void CompareFiles(DTE2 dte, string mutantCodePath, string originalCodePath) { if (!string.IsNullOrEmpty(mutantCodePath) && !string.IsNullOrEmpty(originalCodePath)) { dte.ExecuteCommand("Tools.DiffFiles", $"\"{mutantCodePath}\" \"{originalCodePath}\""); } }
void IIde.OpenSolution(string path) { if (path != null) { _dte.ExecuteCommand("File.OpenProject", $"\"{path}\""); } }
private void MenuItemCallback(object sender, EventArgs e) { var menuCommand = (MenuCommand)sender; var debugging = menuCommand.CommandID.ID == PkgCmdIDList.CmdStartDebugging; var selectedItemCount = _dte.SelectedItems.Count; if (selectedItemCount > 1) //Multiple projects selected? { var projects = new List <EnvDTE.Project>(); for (int k = 0; k < selectedItemCount; k++) { var selectedProject = _dte.SelectedItems.Item(k + 1).Project; projects.Add(selectedProject); } var sb = _dte.Solution.SolutionBuild; var newStartups = projects.Select(t => t.FullName).ToArray <object>(); sb.StartupProjects = newStartups; } else //Single project selected { var startupProjectProperty = _dte.Solution.Properties.Item("StartupProject"); startupProjectProperty.Value = _dte.SelectedItems.Item(1).Project.Name; } _dte.ExecuteCommand(debugging ? "Debug.Start" : "Debug.StartWithoutDebugging"); }
/// <summary> /// Tries to execute a Visual Studio command. /// </summary> /// <param name="command">The text identifying the command that should be executed.</param> /// <param name="dte"> /// The <see cref="DTE2" /> that is used to execute the command identified by <paramref name="command" /> /// . /// </param> /// <returns>Returns <see langword="true" /> if the command was executed successfully, otherwise <see langword="false" />.</returns> public static bool TryExecuteCommand(string command, DTE2 dte) { if (dte.Commands.Cast <Command>().All( dteCommand => { ThreadHelper.ThrowIfNotOnUIThread(); return(dteCommand.Name != command); })) { return(false); } try { dte.ExecuteCommand(command); s_log.Info($"Command '{command}' successfully executed."); } catch (COMException ex) { s_log.Error(command == "ReSharper_Suspend" ? $"Command '{command}' failed. Maybe ReSharper is already suspended?" : $"Command '{command}' failed.", ex); return(false); } return(true); }
public ErrorHighlighter(IWpfTextView view, ITextDocument document, IVsTaskList tasks, DTE2 dte, SVsServiceProvider serviceProvider) { _view = view; _document = document; _text = new Adornment(); _tasks = tasks; _serviceProvider = serviceProvider; _dispatcher = Dispatcher.CurrentDispatcher; _adornmentLayer = view.GetAdornmentLayer(ErrorHighlighterFactory.LayerName); _view.ViewportHeightChanged += SetAdornmentLocation; _view.ViewportWidthChanged += SetAdornmentLocation; _text.MouseUp += (s, e) => { dte.ExecuteCommand("View.ErrorList"); }; _timer = new Timer(750); _timer.Elapsed += (s, e) => { _timer.Stop(); System.Threading.Tasks.Task.Run(() => { _dispatcher.Invoke(new Action(() => { Update(false); }), DispatcherPriority.ApplicationIdle, null); }); }; _timer.Start(); }
public static void DockToolWindows(DTE2 dte) { ThreadHelper.ThrowIfNotOnUIThread(); dte.ExecuteCommand("Window.AutoHideAll"); ToolWindows toolWindows = dte.ToolWindows; GeneralOptions options = GeneralOptions.Instance; Dock(toolWindows.CommandWindow.Parent, options.ShowCommandWindow); Dock(toolWindows.ErrorList.Parent, options.ShowErrorList); Dock(toolWindows.OutputWindow.Parent, options.ShowOutputWindow); Dock(toolWindows.SolutionExplorer.Parent, options.ShowSolutionExplorer); Dock(toolWindows.TaskList.Parent, options.ShowTaskList); Dock(toolWindows.ToolBox.Parent, options.ShowToolbox); var customWindowCaptions = options.CustomWindowCaptionList.Split(';').ToHashSet(); Windows windows = dte.Windows; foreach (Window window in windows) { if (customWindowCaptions.Contains(window.Caption)) { Dock(window, true); } } }
private void buildEvents_OnBuildProjConfigBegin( string Project, string ProjectConfig, string Platform, string SolutionConfig) { Options currentOptions = OptionsProviderRegistry.CurrentOptions; if (_buildAction == vsBuildAction.vsBuildActionClean || !currentOptions.Enabled || !currentOptions.RunOnBuild) { return; } var proj = _dte2.Solution.AllProjects().Single(p => p.UniqueName == Project); ResetErrorCount(); SuspendErrorList(); bool reachedTreshold; AnalyzeProjectItems(proj.ProjectItems, out reachedTreshold); ResumeErrorList(); UpdateStatusBar(reachedTreshold); if (_errorCount > 0 && currentOptions.CancelBuildOnError) { WriteToErrorList("Build cancelled due to JSLint validation errors."); _dte2.ExecuteCommand("Build.Cancel"); } }
internal static string ShowProjectCreationWizard() { CloseSolution(); mInstance.ExecuteCommand("File.NewProject", ""); string toReturn = ""; if (mInstance.Solution.IsOpen) { EnvDTE.Project newProject = null; foreach (EnvDTE.Project project in mInstance.Solution.Projects) { if (!project.FileName.Contains(".Web")) { newProject = project; } } toReturn = newProject.FileName; } CloseSolution(); return(toReturn); }
private UploadSolution ListupTargetFiles(DTE2 dte, OutputWindowPane pane) { ThreadHelper.ThrowIfNotOnUIThread(); var currCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; // ソリューションアイテムへのアクセスはCOMベースになるため、UIスレッドで行うことにした(同期じゃないと面倒なため) var solution = dte.Solution; var solutionPath = solution.FullName; if (solution == null || solution.Count == 0 || string.IsNullOrWhiteSpace(solutionPath) || !File.Exists(solutionPath) || solution.Projects.Kind != EnvDTE.Constants.vsProjectsKindSolution) { pane.WriteLine($"ソリューションを開いていません。dte.Solution.FullName=\"{solutionPath}\""); return(null); } pane.WriteLine("すべてのファイルを保存しています。"); // すべて保存のコマンドを発行することで保存を行う dte.ExecuteCommand("File.SaveAll", ""); // ソリューションファイルを含むすべてのコピー対象アイテムをリストアップ var uploadSln = new UploadSolution(dte, pane); uploadSln.ListupUploadFiles(); Cursor.Current = currCursor; return(uploadSln); }
/// <summary> /// Checks the error list for compiler errors. /// </summary> /// <returns>True if there's something in the list.</returns> private bool IsCompilerErrorInErrorList() { ErrorList myErrors; applicationObject.ExecuteCommand("View.ErrorList", " "); myErrors = applicationObject.ToolWindows.ErrorList; for (int i = 1; i <= myErrors.ErrorItems.Count; i++) { if (myErrors.ErrorItems.Item(i).ErrorLevel == vsBuildErrorLevel.vsBuildErrorLevelHigh) { return(true); } } return(false); }
private static OutputWindowPane PrepareOutputWindowPane(DTE2 dte) { dte.ExecuteCommand("View.Output"); OutputWindow outputWindow = dte.ToolWindows.OutputWindow; OutputWindowPane outputWindowPane = null; foreach (OutputWindowPane pane in outputWindow.OutputWindowPanes) { if (pane.Name == "MonoHelper") { outputWindowPane = pane; break; } } if (outputWindowPane == null) { outputWindowPane = outputWindow.OutputWindowPanes.Add("MonoHelper"); } outputWindowPane.Activate(); outputWindowPane.Clear(); outputWindowPane.OutputString("MonoHelper, Version 1.2\r\n"); outputWindowPane.OutputString("Copyright (C) Christopher Dresel 2015\r\n"); outputWindowPane.OutputString("\r\n"); return(outputWindowPane); }
public static void ExecuteCommand(DTE2 dte, string commandName) { var command = dte.Commands.Item(commandName); if (command.IsAvailable) { dte.ExecuteCommand(command.Name); } }
private static void LoadTheme(Theme theme, DTE2 application, Config config) { application.ExecuteCommand( "Tools.ImportandExportSettings", string.Format("/import:\"{0}\"", theme.FilePath)); config.CurrentThemeName = theme.Name; ConfigManager.SaveConfig(config); }
public override void OnCommand(DTE2 application, OutputWindowPane pane) { ThreadPool.QueueUserWorkItem( o => { string file = GitCommands.RunGitExWait("searchfile", application.Solution.FullName); if (file == null || string.IsNullOrEmpty(file.Trim())) return; application.ExecuteCommand("File.OpenFile", file); }); }
public ErrorListScanner(DTE2 dte) { _dte = dte; var errorItems = dte.ToolWindows.ErrorList.ErrorItems; dte.ExecuteCommand("View.ErrorList", " "); //Yup these iterator count from 1.. for (int i = 1; i <= errorItems.Count; i++) { var item = errorItems.Item(i); var symbol = GetUnresolvedSymbol(item); //Check if this is an unresolved external symbol error if (symbol == null) continue; var project = GetProject(item); AddUnresolvedSymbol(project, symbol); } }
public static void ExecuteCommand(string command, DTE2 dte) { dte.ExecuteCommand(command); }
private void ReloadProject(DTE2 dte2, Project currentProject) { // we need to unload and reload the project dte2.ExecuteCommand("File.SaveAll"); string solutionName = System.IO.Path.GetFileNameWithoutExtension(dte2.Solution.FullName); string projectName = currentProject.Name; dte2.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Activate(); ((DTE2)dte2).ToolWindows.SolutionExplorer.GetItem(solutionName + @"\" + projectName).Select(vsUISelectionType.vsUISelectionTypeSelect); dte2.ExecuteCommand("Project.UnloadProject"); System.Threading.Thread.Sleep(500); dte2.ExecuteCommand("Project.ReloadProject"); }
/// <summary> /// Test body /// </summary> /// <param name="DTE">The environment application object</param> public static void RunTest(DTE2 DTE) { DTE.ItemOperations.OpenFile(Environment.GetEnvironmentVariable("ORMFile", EnvironmentVariableTarget.Process), ""); // The test file has three binary facts in it. FactType1, FactType2, FactType3, and an entity type EntityType1. EntityType1 is connected // the first role of the three facts. FactType1 and FactType2 are mandatory and unique on the first role. // Standard test handling ORMTestHooks hooks = new ORMTestHooks(DTE); ORMTestWindow testWindow = hooks.FindORMTestWindow(null); using (StreamWriter writer = File.AppendText(Environment.GetEnvironmentVariable("TestLog", EnvironmentVariableTarget.Process))) { // Grab accessible objects for the diagram and the 4 roles we'll be connecting to AccessibleObject accDiagram = CommonTestHooks.FindAccessibleObject( testWindow.AccessibleObject, new AccessiblePathNode[]{ new AccessiblePathNode("ORMDiagram")}); AccessibleObject accRole1_1 = CommonTestHooks.FindAccessibleObject( accDiagram, new AccessiblePathNode[]{ new AccessiblePathNode("FactType", "EntityType1A"), new AccessiblePathNode("Roles"), new AccessiblePathNode("Role", 0)}); AccessibleObject accRole2_1 = CommonTestHooks.FindAccessibleObject( accDiagram, new AccessiblePathNode[]{ new AccessiblePathNode("FactType", "EntityType1B"), new AccessiblePathNode("Roles"), new AccessiblePathNode("Role", 0)}); AccessibleObject accRole3_1 = CommonTestHooks.FindAccessibleObject( accDiagram, new AccessiblePathNode[]{ new AccessiblePathNode("FactType", "EntityType1C"), new AccessiblePathNode("Roles"), new AccessiblePathNode("Role", 0)}); AccessibleObject accRole3_2 = CommonTestHooks.FindAccessibleObject( accDiagram, new AccessiblePathNode[]{ new AccessiblePathNode("FactType", "EntityType1C"), new AccessiblePathNode("Roles"), new AccessiblePathNode("Role", 1)}); // Add the equality constraint and get its accessible object testWindow.ActivateToolboxItem("Equality Constraint"); testWindow.ClickAccessibleObject(accDiagram, 1, ClickLocation.UpperLeft, 50, 50); AccessibleObject accEquality = testWindow.GetSelectedAccessibleObjects()[0]; EqualityConstraint equalityConstraint = (EqualityConstraint)testWindow.TranslateAccessibleObject(accEquality, false); bool scenarioPassed; // Scenario 1: Attach the two mandatory roles testWindow.ClickAccessibleObject(accRole1_1, 2); testWindow.ClickAccessibleObject(accRole2_1, 2); SendKeys.SendWait("{ESC}"); scenarioPassed = null != equalityConstraint.EqualityImpliedByMandatoryError; writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError exists when all roles are mandatory"); // Scenario 2: Remove the mandatory constraint from the second role testWindow.ClickAccessibleObject(accRole2_1); DTE.ExecuteCommand("OtherContextMenus.ORMDesignerContextMenu.IsMandatory", ""); scenarioPassed = null == equalityConstraint.EqualityImpliedByMandatoryError; writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError does not exist when some roles are not mandatory"); // Scenario 3: Delete the non-mandatory role SendKeys.SendWait("^{DEL}"); scenarioPassed = null != equalityConstraint.EqualityImpliedByMandatoryError; writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError exists when the last non-mandatory role is deleted"); // Scenario 4: Delete the role sequence DTE.ExecuteCommand("Edit.Undo", ""); testWindow.ClickAccessibleObject(accEquality); testWindow.ClickAccessibleObject(accRole2_1); DTE.ExecuteCommand("OtherContextMenus.ORMDesignerContextMenu.DeleteRoleSequence", ""); scenarioPassed = null != equalityConstraint.EqualityImpliedByMandatoryError; writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError exists when a role sequence with the last non-mandatory role is deleted"); // Scenario 5: Delete the associated fact DTE.ExecuteCommand("Edit.Undo", ""); testWindow.ClickAccessibleObject(accRole2_1.Parent, 1, ClickLocation.UpperLeft, 1, 1); SendKeys.SendWait("^{DEL}"); scenarioPassed = null != equalityConstraint.EqualityImpliedByMandatoryError; writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError exists when the fact with the last non-mandatory role is deleted"); // Scenario 6: Add an additional role sequence to a non-mandatory role DTE.ExecuteCommand("Edit.Undo", ""); DTE.ExecuteCommand("Edit.Undo", ""); testWindow.ClickAccessibleObject(accEquality, 2); testWindow.ClickAccessibleObject(accRole3_1, 2); SendKeys.SendWait("{ESC}"); scenarioPassed = null == equalityConstraint.EqualityImpliedByMandatoryError; writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError does not exist a role sequence with a single non-mandatory role is added"); // Scenario 7: Add a mandatory constraint to the non-mandatory role testWindow.ClickAccessibleObject(accRole3_1); DTE.ExecuteCommand("OtherContextMenus.ORMDesignerContextMenu.IsMandatory", ""); scenarioPassed = null != equalityConstraint.EqualityImpliedByMandatoryError; writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError exists when the last non-mandatory role is change to a mandatory role"); // Scenario 8: Add a second role to the third role sequence testWindow.ClickAccessibleObject(accRole3_1, 2); testWindow.ClickAccessibleObject(accRole3_2, 2); scenarioPassed = null == equalityConstraint.EqualityImpliedByMandatoryError; writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError does not exist if a role is added to make more than one column in at least one role sequence"); // Scenario 9: Remove the second role from the third role sequence testWindow.ClickAccessibleObject(accEquality, 1); testWindow.ClickAccessibleObject(accRole3_2, 2); testWindow.KeyDown(Keys.ControlKey); testWindow.ClickAccessibleObject(accRole3_2, 2); testWindow.KeyUp(Keys.ControlKey); scenarioPassed = null != equalityConstraint.EqualityImpliedByMandatoryError; writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError exist if a role is removed from a role sequence, leaving a single-column in all role sequences with all mandatory roles"); } }
/// <summary> /// Activate an item in the toolbox /// </summary> /// <param name="DTE">DTE object</param> /// <param name="tabName">The toolbox tab name</param> /// <param name="itemName">The item name in that tab</param> /// <returns>true if the item has been activated</returns> public static bool ActivateToolboxItem(DTE2 DTE, string tabName, string itemName) { DTE.ExecuteCommand("View.Toolbox", ""); ToolBox toolbox = DTE.ToolWindows.ToolBox; ToolBoxTab tab = toolbox.ToolBoxTabs.Item(tabName); if (tab != null) { tab.Activate(); ToolBoxItem foundItem = null; int foundItemIndex = -1; int selectedItemIndex = -1; ToolBoxItems items = tab.ToolBoxItems; ToolBoxItem selectedItem = items.SelectedItem; foreach (ToolBoxItem currentItem in items) { if (foundItem == null) { ++foundItemIndex; if (currentItem.Name == itemName) { foundItem = currentItem; if (selectedItem == null) { break; } } } if (selectedItem != null) { ++selectedItemIndex; if (selectedItem == currentItem) { selectedItem = null; if (foundItem != null) { break; } } } } if (foundItem != null) { int distance = foundItemIndex - selectedItemIndex; if (distance != 0) { SendKeys.Flush(); if (distance > 0) { SendKeys.SendWait(string.Format("{{DOWN {0}}}", distance)); } else { SendKeys.SendWait(string.Format("{{UP {0}}}", -distance)); } } return true; } } return false; }
public static void XBuild(DTE2 dte, bool rebuild = false) { OutputWindowPane outputWindowPane = PrepareOutputWindowPane(dte); if (!rebuild) { outputWindowPane.OutputString("MonoHelper: XBuild Solution Start\r\n\r\n"); } else { outputWindowPane.OutputString("MonoHelper: XRebuild Solution Start\r\n\r\n"); } outputWindowPane.OutputString(string.Format("MonoHelper: Saving Documents\r\n")); dte.ExecuteCommand("File.SaveAll"); string monoPath = DetermineMonoPath(dte); // Get current configuration string configurationName = dte.Solution.SolutionBuild.ActiveConfiguration.Name; string platformName = ((SolutionConfiguration2)dte.Solution.SolutionBuild.ActiveConfiguration).PlatformName; string fileName = string.Format(@"{0}\bin\xbuild.bat", monoPath); string arguments = string.Format(@"""{0}"" /p:Configuration=""{1}"" /p:Platform=""{2}"" {3}", dte.Solution.FileName, configurationName, platformName, rebuild ? " /t:Rebuild" : string.Empty); // Run XBuild and show in output System.Diagnostics.Process proc = new System.Diagnostics.Process { StartInfo = new ProcessStartInfo { FileName = fileName, Arguments = arguments, UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true } }; outputWindowPane.OutputString(string.Format("MonoHelper: Running {0} {1}\r\n\r\n", fileName, arguments)); proc.Start(); while (!proc.StandardOutput.EndOfStream) { string line = proc.StandardOutput.ReadLine(); outputWindowPane.OutputString(line); outputWindowPane.OutputString("\r\n"); } // XBuild returned with error, stop processing XBuild Command if (proc.ExitCode != 0) { if (!rebuild) { outputWindowPane.OutputString("\r\n\r\nMonoHelper: XBuild Solution End"); } else { outputWindowPane.OutputString("\r\n\r\nMonoHelper: XRebuild Solution End"); } return; } foreach (Project project in dte.Solution.Projects) { if (project.ConfigurationManager == null || project.ConfigurationManager.ActiveConfiguration == null) { continue; } Property debugSymbolsProperty = GetProperty(project.ConfigurationManager.ActiveConfiguration.Properties, "DebugSymbols"); // If DebugSymbols is true, generate pdb symbols for all assemblies in output folder if (debugSymbolsProperty != null && debugSymbolsProperty.Value is bool && (bool)debugSymbolsProperty.Value) { outputWindowPane.OutputString( string.Format("\r\nMonoHelper: Generating DebugSymbols and injecting DebuggableAttributes for project {0}\r\n", project.Name)); // Determine Outputpath, see http://www.mztools.com/articles/2009/MZ2009015.aspx string absoluteOutputPath = GetAbsoluteOutputPath(project); GenerateDebugSymbols(absoluteOutputPath, outputWindowPane); } } if (!rebuild) { outputWindowPane.OutputString("\r\nMonoHelper: XBuild Solution End"); } else { outputWindowPane.OutputString("\r\nMonoHelper: XRebuild Solution End"); } }
private static OutputWindowPane PrepareOutputWindowPane(DTE2 dte) { dte.ExecuteCommand("View.Output"); OutputWindow outputWindow = dte.ToolWindows.OutputWindow; OutputWindowPane outputWindowPane = null; foreach (OutputWindowPane pane in outputWindow.OutputWindowPanes) { if (pane.Name == "MonoHelper") { outputWindowPane = pane; break; } } if (outputWindowPane == null) { outputWindowPane = outputWindow.OutputWindowPanes.Add("MonoHelper"); } outputWindowPane.Activate(); outputWindowPane.Clear(); outputWindowPane.OutputString("MonoHelper, Version 1.2\r\n"); outputWindowPane.OutputString("Copyright (C) Christopher Dresel 2015\r\n"); outputWindowPane.OutputString("\r\n"); return outputWindowPane; }