/// ------------------------------------------------------------------------------------ /// <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); } }
void OpenFile(string fileName) { var filePath = fileName.Replace('/','\\'); if (m_dte.get_IsOpenFile(EnvDTE.Constants.vsViewKindCode,filePath)) { Document doc = m_dte.Documents.Item(filePath); doc.Activate(); return; } Window window = null; if (m_dte.Solution != null) { var projItem = m_dte.Solution.FindProjectItem(filePath); if (projItem != null && !projItem.IsOpen) { window = projItem.Open(); } } //foreach (Window win in m_dte.Documents.Cast<Document>() // .FirstOrDefault(s => s.FullName == filePath).Windows) // win.Close(); if (window == null) { window = m_dte.ItemOperations.OpenFile(fileName,EnvDTE.Constants.vsViewKindCode); } if (window != null) { window.Visible = true; window.Activate(); } }
public bool get_IsOpenFile(string ViewKind, string FileName) { return(_dte.get_IsOpenFile(ViewKind, FileName)); }