public void ProcessTest() { Agent.EnsureSolutionOpen(); DTE2 DTE = Agent.GetDTE(); BatchInlineCommand target = Agent.BatchInlineCommand; var window = DTE.OpenFile(null, Agent.VBReferencesTestFile1); window.Activate(); target.Process(true); Assert.IsTrue(VLDocumentViewsManager.IsFileLocked(Agent.VBReferencesTestFile1)); ValidateResults(GetExpectedResultsFor(Agent.VBReferencesTestFile1), target.Results); Assert.IsTrue(VLDocumentViewsManager.IsFileLocked(Agent.VBReferencesTestFile1)); VLDocumentViewsManager.SetFileReadonly(Agent.VBReferencesTestFile1, false); Assert.IsFalse(VLDocumentViewsManager.IsFileLocked(Agent.VBReferencesTestFile1)); window.Detach(); window.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Toggle the H and CPP file /// </summary> /// <returns></returns> /// ------------------------------------------------------------------------------------ public void ToggleHAndCpp() { string newFile; if (Path.GetExtension(m_applicationObject.ActiveDocument.FullName) == ".cpp") { newFile = Path.ChangeExtension(m_applicationObject.ActiveDocument.FullName, ".h"); } else if (Path.GetExtension(m_applicationObject.ActiveDocument.FullName) == ".h") { newFile = Path.ChangeExtension(m_applicationObject.ActiveDocument.FullName, ".cpp"); } else { return; } // Try to activate the file if it is already open, otherwise open it. if (m_applicationObject.get_IsOpenFile(null, newFile)) { Document doc = m_applicationObject.Documents.Item(Path.GetFileName(newFile)); doc.Activate(); } else { m_applicationObject.OpenFile(null, newFile); } }
public void ProcessTest1() { Agent.EnsureSolutionOpen(); DTE2 DTE = Agent.GetDTE(); BatchMoveCommand target = Agent.BatchMoveCommand; for (int i = 0; i < 3; i++) { var window = DTE.OpenFile(null, Agent.VBStringsTestFile1); window.Activate(); target.Process(true); Assert.IsTrue(VLDocumentViewsManager.IsFileLocked(Agent.VBStringsTestFile1)); ValidateResults(GetExpectedResultsFor(Agent.VBStringsTestFile1), target.Results); window.Detach(); window.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo); Assert.IsTrue(VLDocumentViewsManager.IsFileLocked(Agent.VBStringsTestFile1)); VLDocumentViewsManager.ReleaseLocks(); Assert.IsFalse(VLDocumentViewsManager.IsFileLocked(Agent.VBStringsTestFile1)); } }
private void SelectGo() { if (m_lvCandidate.SelectedItems.Count > 0) { string fullpath = m_lvCandidate.SelectedItems[0].SubItems[1].Text; if (false == System.IO.File.Exists(fullpath)) { System.Diagnostics.Debug.Print(fullpath + " does not exist"); } else { try { Window w = m_app.OpenFile(EnvDTE.Constants.vsViewKindPrimary, fullpath); if (w != null) { w.SetFocus(); w.Activate(); Close(); } } catch (System.Runtime.InteropServices.COMException ex) { MessageBox.Show(this.Owner, "Cannot open the file"); } } } else { System.Diagnostics.Debug.Print("There is no selected item"); } }
private bool setBreakpointFromStacktrace(CacheTestMessage test, ref string targetFramework) { // pull test name from full name var vsTestName = test.Test.Name.Replace("+", "."); var testName = vsTestName.Substring(vsTestName.LastIndexOf('.') + 1, vsTestName.Length - (vsTestName.LastIndexOf('.') + 1)); AutoTest.Core.DebugLog.Debug.WriteDebug("Attempting to set breakpoint through call stack for " + testName); foreach (var line in test.Test.StackTrace) { if (!File.Exists(line.File)) { continue; } AutoTest.Core.DebugLog.Debug.WriteDebug(string.Format("Locating file {0}", line.File)); var window = _application.OpenFile(EnvDTE.Constants.vsViewKindCode, line.File); if (breakOnFunctionElement(line.File, window.ProjectItem.FileCodeModel.CodeElements, testName)) { AutoTest.Core.DebugLog.Debug.WriteDebug("Found code file containing test and set breakpoint"); targetFramework = window.Project.Properties.Item("TargetFrameworkMoniker").Value.ToString(); AutoTest.Core.DebugLog.Debug.WriteDebug(string.Format("Target framework is {0}", targetFramework)); return(true); } } return(false); }
/// <summary> /// Invokes the editor for the specified Gallio test. /// </summary> /// <param name="uiBlob">Identifies the Project/Item blob to be displayed.</param> /// <param name="test">The test that the editor is being invoked for.</param> public void InvokeEditor(UIBlob uiBlob, ITestElement test) { if (!TipShellExtension.IsInitialized) { return; } GallioTestElement gallioTest = test as GallioTestElement; if (gallioTest != null) { if (gallioTest.Path == null) { ErrorDialog.Show(NativeWindow.FromHandle((IntPtr)dte.MainWindow.HWnd), Properties.Resources.UnknownTestCodeLocationCaption, Properties.Resources.UnknownTestCodeLocation, ""); } else { Window window = dte.OpenFile(EnvDTE.Constants.vsViewKindCode, gallioTest.Path); TextSelection selection = window.Selection as TextSelection; if (gallioTest.Line != 0) { if (selection != null) { selection.MoveToLineAndOffset(gallioTest.Line, Math.Max(1, gallioTest.Column), false); } } window.Activate(); } } }
//hack for embedded constants. private static void goTo(DTE2 dte, Position item) { var window = dte.OpenFile(vsViewKindCode, item.Filename); window.Activate(); var selection = (TextSelection)dte.ActiveDocument.Selection; selection.MoveToDisplayColumn(item.LineNumber, 0); return; }
private void runFeedback_GoToReference(object sender, UI.GoToReferenceArgs e) { try { var window = _application.OpenFile(EnvDTE.Constants.vsViewKindCode, e.Position.File); window.Activate(); var selection = (TextSelection)_application.ActiveDocument.Selection; selection.MoveToDisplayColumn(e.Position.LineNumber, e.Position.Column, false); } catch { } }
private void goToReference(string file, int lineNumber) { try { var window = _application.OpenFile(EnvDTE.Constants.vsViewKindCode, file); window.Activate(); var selection = (TextSelection)_application.ActiveDocument.Selection; selection.GotoLine(lineNumber, false); } catch (Exception ex) { var messag = ex.Message; } }
private void goToReference(string file, int lineNumber, int column) { try { var window = _application.OpenFile(EnvDTE.Constants.vsViewKindCode, file); window.Activate(); var selection = (TextSelection)_application.ActiveDocument.Selection; selection.MoveToDisplayColumn(lineNumber, column, false); } catch (Exception ex) { Logger.Write(ex); } }
public static void GotoTypeByFullName(DTE2 dte, string name) { try { var ProjectItem = GetProjectItemFromFullName(dte, name); var window = dte.OpenFile(vsViewKindCode, ProjectItem.FileNames[0]); window.Activate(); } catch (Exception ex) { Core.DebugLog.Debug.WriteDebug("error going to type " + name); Core.DebugLog.Debug.WriteException(ex); } }
internal static void OpenCorrespondingFile(DTE2 _applicationObject) { if (_applicationObject.ActiveDocument != null) { string filename = System.IO.Path.GetFullPath(_applicationObject.ActiveDocument.FullName); string[] extChain = new string[] { ".h", ".hpp", ".cpp", ".c" }; for ( int i=0; i<extChain.Length; ++i ) { if (filename.ToLower().EndsWith(extChain[i])) { int nextIndex = i; for (int j = 0; j < extChain.Length; ++j) { nextIndex = (nextIndex + 1) % extChain.Length; string nextExt = extChain[nextIndex]; string newfilename = System.IO.Path.GetDirectoryName(filename) + "\\" + System.IO.Path.GetFileNameWithoutExtension(filename); newfilename += nextExt; if (File.Exists(newfilename)) { Window w = _applicationObject.OpenFile(EnvDTE.Constants.vsViewKindPrimary, newfilename); if (w != null) { w.Activate(); break; } } else { System.Diagnostics.Debug.Print("There is no file : " + newfilename); } } break; } } } else { System.Diagnostics.Debug.Print("ActiveDocument is null"); } }
internal static void OpenCorrespondingFile(DTE2 _applicationObject) { if (_applicationObject.ActiveDocument != null) { string filename = System.IO.Path.GetFullPath(_applicationObject.ActiveDocument.FullName); string[] extChain = new string[] { ".h", ".hpp", ".cpp", ".c" }; for (int i = 0; i < extChain.Length; ++i) { if (filename.ToLower().EndsWith(extChain[i])) { int nextIndex = i; for (int j = 0; j < extChain.Length; ++j) { nextIndex = (nextIndex + 1) % extChain.Length; string nextExt = extChain[nextIndex]; string newfilename = System.IO.Path.GetDirectoryName(filename) + "\\" + System.IO.Path.GetFileNameWithoutExtension(filename); newfilename += nextExt; if (File.Exists(newfilename)) { Window w = _applicationObject.OpenFile(EnvDTE.Constants.vsViewKindPrimary, newfilename); if (w != null) { w.Activate(); break; } } else { System.Diagnostics.Debug.Print("There is no file : " + newfilename); } } break; } } } else { System.Diagnostics.Debug.Print("ActiveDocument is null"); } }
public void ProcessEmptySelectionTest() { Agent.EnsureSolutionOpen(); DTE2 DTE = Agent.GetDTE(); BatchInlineCommand_Accessor target = Agent.BatchInlineCommand_Accessor; Window window = DTE.OpenFile(null, Agent.VBReferencesTestFile1); IVsTextView view = VLDocumentViewsManager.GetTextViewForFile(Agent.VBReferencesTestFile1, false, true); view.SetSelection(28, 4, 35, 31); List <AbstractResultItem> emptyList = new List <AbstractResultItem>(); target.ProcessSelection(true); ValidateResults(emptyList, target.Results); Assert.IsFalse(VLDocumentViewsManager.IsFileLocked(Agent.VBReferencesTestFile1)); window.Detach(); window.Close(vsSaveChanges.vsSaveChangesNo); }
public void Run(DTE2 _applicationObject) { List<FileDetails> fileDetails = new List<FileDetails>(); /* * Create a list of all projects and files in the solution, so * that we can display them later on to the user. This is done * prior to showing the dialog. */ Projects projects = _applicationObject.Solution.Projects; int projCount = _applicationObject.Solution.Projects.Count; for (int i = 1; i <= projects.Count; i++ ) { Project project = projects.Item(i); CreateFileList(project.Name, project.ProjectItems, ref fileDetails); } /* * formIncrementalOpen is the dialog in which the user filters * the list of files. */ formIncrementalOpen openDlg = new formIncrementalOpen(); FileDetails resultFile = openDlg.Show(fileDetails); if (resultFile != null) { string fullPath = Path.Combine(resultFile.Path, resultFile.FileName); Window win = _applicationObject.OpenFile(EnvDTE.Constants.vsViewKindCode, fullPath); win.Visible = true; win.SetFocus(); } }
public Window OpenFile(string ViewKind, string FileName) { return(_dte.OpenFile(ViewKind, FileName)); }
private void Open(string filename) { var window = _application.OpenFile(EnvDTE.Constants.vsViewKindDesigner, filename); window.Activate(); }
/// <summary> /// /// </summary> /// <param name="projectItem"></param> private void ProcessProjectItem(ProjectItem projectItem) { if (projectItem == null) { return; } if (IsNotNeedProcess(projectItem)) { return; } var fileName = projectItem.FileNames[1]; WriteLog($"Doing: {fileName}"); var window = _dte.OpenFile("{7651A703-06E5-11D1-8EBD-00A0C90F26EA}", fileName); window.Activate(); #region 执行命令 try { switch (_selectedMenu) { case PkgCmdIdList.CmdidRemoveUnusedUsings: _dte.ExecuteCommand("Edit.RemoveUnusedUsings"); break; case PkgCmdIdList.CmdidSortUsings: _dte.ExecuteCommand("Edit.SortUsings"); break; case PkgCmdIdList.CmdidRemoveAndSortUsings: _dte.ExecuteCommand("Edit.RemoveAndSort"); break; case PkgCmdIdList.CmdidFormatDocument: _dte.ExecuteCommand("Edit.FormatDocument"); break; case PkgCmdIdList.CmdidSortUsingsAndFormatDocument: _dte.ExecuteCommand("Edit.SortUsings"); _dte.ExecuteCommand("Edit.FormatDocument"); break; case PkgCmdIdList.CmdidRemoveAndSortUsingsAndFormatDocument: _dte.ExecuteCommand("Edit.RemoveAndSort"); _dte.ExecuteCommand("Edit.FormatDocument"); break; case PkgCmdIdList.Null: break; default: throw new ArgumentOutOfRangeException(); } } catch (COMException) { } #endregion if (_lstAlreadyOpenFiles.Exists(file => file.Equals(fileName, StringComparison.OrdinalIgnoreCase))) { _dte.ActiveDocument.Save(fileName); } else { window.Close(vsSaveChanges.vsSaveChangesYes); } }
private void ProcessProjectItem(ProjectItem projectItem) { string fileName; if (projectItem != null) { fileName = projectItem.FileNames[1]; if (IsNotNeedProcess(projectItem)) { return; } WriteLog("Doing :" + fileName); Window window = dte.OpenFile("{7651A703-06E5-11D1-8EBD-00A0C90F26EA}", fileName); window.Activate(); #region 执行命令 try { switch (selectedMenu) { case PkgCmdIDList.cmdidRemoveUnusedUsings: dte.ExecuteCommand("Edit.RemoveUnusedUsings"); break; case PkgCmdIDList.cmdidSortUsings: dte.ExecuteCommand("Edit.SortUsings"); break; case PkgCmdIDList.cmdidRemoveAndSortUsings: dte.ExecuteCommand("Edit.RemoveAndSort"); break; case PkgCmdIDList.cmdidFormatDocument: dte.ExecuteCommand("Edit.FormatDocument"); break; case PkgCmdIDList.cmdidSortUsingsAndFormatDocument: dte.ExecuteCommand("Edit.SortUsings"); dte.ExecuteCommand("Edit.FormatDocument"); break; case PkgCmdIDList.cmdidRemoveAndSortUsingsAndFormatDocument: dte.ExecuteCommand("Edit.RemoveAndSort"); dte.ExecuteCommand("Edit.FormatDocument"); break; default: break; } } catch (COMException) { } #endregion if (lstAlreadyOpenFiles.Exists(file => file.Equals(fileName, StringComparison.OrdinalIgnoreCase))) { dte.ActiveDocument.Save(fileName); } else { window.Close(vsSaveChanges.vsSaveChangesYes); } } }
public ShellWindow OpenFile(string ViewKind, string FileName) { return(new ShellWindow(_dte.OpenFile(ViewKind, FileName) as Window2)); }
public static void GotoTypeByFullName(DTE2 dte, string name) { try { var ProjectItem = GetProjectItemFromFullName(dte, name); var window = dte.OpenFile(vsViewKindCode, ProjectItem.FileNames[0]); window.Activate(); } catch(Exception ex) { Core.DebugLog.Debug.WriteDebug("error going to type " + name); Core.DebugLog.Debug.WriteException(ex); } }