DoxygenDB.EntitySearchResult SearchAndAddToScene( string name, int nameOption, string longName, int longNameOption, string type, string docPath, int lineNum) { searchWindow.nameEdit.Text = name; searchWindow.typeEdit.Text = type; searchWindow.fileEdit.Text = docPath; searchWindow.lineEdit.Text = lineNum.ToString(); searchWindow.resultList.Items.Clear(); var db = DBManager.Instance().GetDB(); var result = new DoxygenDB.EntitySearchResult(); if (db == null) { return(result); } var request = new DoxygenDB.EntitySearchRequest( name, nameOption, longName, longNameOption, type, docPath, lineNum); db.SearchAndFilter(request, out result); searchWindow.SetSearchResult(result); searchWindow.OnAddToScene(); return(result); }
public void OnSearch() { var searchWord = nameEdit.Text; var searchKind = typeEdit.Text; var searchFile = fileEdit.Text.Replace("\\", "/"); int searchLine = Convert.ToInt32(lineEdit.Text == "" ? "-1" : lineEdit.Text); resultList.Items.Clear(); Logger.Debug("------------------- Search -----------------------"); var db = DBManager.Instance().GetDB(); if (db == null) { return; } var request = new DoxygenDB.EntitySearchRequest(searchWord, (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD, "", 0, searchKind, searchFile, searchLine); var result = new DoxygenDB.EntitySearchResult(); db.SearchAndFilter(request, out result); SetSearchResult(result); }
public void OnShowDefinitionInAtlas(object sender, ExecutedRoutedEventArgs e) { var scene = UIManager.Instance().GetScene(); CodeElement srcElement, tarElement; Document srcDocument, tarDocument; int srcLine, tarLine; CursorNavigator.GetCursorElement(out srcDocument, out srcElement, out srcLine); Guid cmdGroup = VSConstants.GUID_VSStandardCommandSet97; var commandTarget = ((System.IServiceProvider)m_package).GetService(typeof(SUIHostCommandDispatcher)) as IOleCommandTarget; if (commandTarget != null) { int hr = commandTarget.Exec(ref cmdGroup, (uint)VSConstants.VSStd97CmdID.GotoDefn, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, System.IntPtr.Zero, System.IntPtr.Zero); } CursorNavigator.GetCursorElement(out tarDocument, out tarElement, out tarLine); if (srcElement == null || tarElement == null || srcElement == tarElement) { return; } var srcName = srcElement.Name; var srcLongName = srcElement.FullName; var srcType = CursorNavigator.VSElementTypeToString(srcElement); var srcFile = srcDocument.FullName; var tarName = tarElement.Name; var tarLongName = tarElement.FullName; var tarType = CursorNavigator.VSElementTypeToString(tarElement); var tarFile = tarDocument.FullName; var db = DBManager.Instance().GetDB(); var srcRequest = new DoxygenDB.EntitySearchRequest( srcName, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.MATCH_WORD, srcLongName, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD, srcType, srcFile, srcLine); var srcResult = new DoxygenDB.EntitySearchResult(); db.SearchAndFilter(srcRequest, out srcResult); //var tarRequest = new DoxygenDB.EntitySearchRequest( // tarName, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.MATCH_WORD, // tarLongName, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD, // tarType, tarFile, tarLine); //var tarResult = new DoxygenDB.EntitySearchResult(); //db.SearchAndFilter(tarRequest, out tarResult); var tarResult = DoShowInAtlas(); DoxygenDB.Entity srcBestEntity, tarBestEntity; srcBestEntity = srcResult.bestEntity; tarBestEntity = tarResult.bestEntity; if (srcBestEntity != null && tarBestEntity != null && srcBestEntity.m_id != tarBestEntity.m_id) { scene.AcquireLock(); scene.AddCodeItem(srcBestEntity.m_id); scene.AddCodeItem(tarBestEntity.m_id); scene.DoAddCustomEdge(srcBestEntity.m_id, tarBestEntity.m_id); scene.SelectCodeItem(tarBestEntity.m_id); scene.ReleaseLock(); } else if (tarBestEntity != null && scene.m_customEdgeSource != null && scene.m_customEdgeSource != "") { scene.AcquireLock(); scene.DoAddCustomEdge(scene.m_customEdgeSource, tarBestEntity.m_id); scene.CancelCustomEdgeMode(); scene.SelectCodeItem(tarBestEntity.m_id); scene.ReleaseLock(); } }
bool ConnectTargetToSource() { // Get code element under cursor //Document doc = null; //doc = dte.ActiveDocument; //if (doc != null) //{ // EnvDTE.TextSelection ts = doc.Selection as EnvDTE.TextSelection; // int lineNum = ts.AnchorPoint.Line; // int lineOffset = ts.AnchorPoint.LineCharOffset; // ts.MoveToLineAndOffset(lineNum, lineOffset); //} // Get symbol name CodeElement tarElement; Document tarDocument; int tarLine; CursorNavigator.GetCursorElement(out tarDocument, out tarElement, out tarLine); if (tarElement == null) { Logger.Debug(" Go to source fail. No target element."); return(false); } // Search entity var tarName = tarElement.Name; var tarLongName = tarElement.FullName; var tarType = CursorNavigator.VSElementTypeToString(tarElement); var tarFile = tarDocument.FullName; var db = DBManager.Instance().GetDB(); var tarRequest = new DoxygenDB.EntitySearchRequest( tarName, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.MATCH_WORD, tarLongName, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.WORD_CONTAINS_DB | (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD, tarType, tarFile, tarLine); var tarResult = new DoxygenDB.EntitySearchResult(); db.SearchAndFilter(tarRequest, out tarResult); if (tarResult.bestEntity == null) { tarRequest.m_longName = ""; db.SearchAndFilter(tarRequest, out tarResult); } // Connect custom edge bool res = false; if (tarResult.bestEntity != null) { var scene = UIManager.Instance().GetScene(); var targetEntity = tarResult.bestEntity; scene.AcquireLock(); scene.AddCodeItem(targetEntity.m_id); scene.AddCodeItem(m_srcUniqueName); res = scene.DoAddCustomEdge(targetEntity.m_id, m_srcUniqueName); scene.ReleaseLock(); Logger.Debug(" Add edge:" + res); } //var tarResult = DoShowInAtlas(); //if (tarResult != null && tarResult.bestEntity != null) //{ // targetEntityList.Add(tarResult.bestEntity); //} return(res); }
int CheckFiles() { var db = DBManager.Instance().GetDB(); var scene = UIManager.Instance().GetScene(); var beginTime = DateTime.Now; int count = 0; var request = new DoxygenDB.EntitySearchRequest( "", (int)DoxygenDB.SearchOption.MATCH_WORD, "", (int)DoxygenDB.SearchOption.MATCH_WORD, "file", "", 0); var result = new DoxygenDB.EntitySearchResult(); foreach (var item in m_referenceDict) { var value = item.Value; if (value.m_isCheck) { continue; } value.m_isCheck = true; string itemInfo = item.Key; int pathSplitPos = itemInfo.IndexOf("("); if (pathSplitPos == -1) { continue; } string fileName = itemInfo.Substring(0, pathSplitPos); request.m_shortName = fileName; db.SearchAndFilter(request, out result); if (result.bestEntity == null) { continue; } string path = result.bestEntity.Longname(); int commaSplitPos = itemInfo.IndexOf(", ", pathSplitPos); if (commaSplitPos == -1) { continue; } int lineStartPos = pathSplitPos + 1; string lineStr = itemInfo.Substring(lineStartPos, commaSplitPos - lineStartPos); int columnEndPos = itemInfo.IndexOf(")"); int columnStartPos = commaSplitPos + 2; string columnStr = itemInfo.Substring(columnStartPos, columnEndPos - columnStartPos); int line; int column; if (int.TryParse(lineStr, out line) && int.TryParse(columnStr, out column)) { //if (!GoToDocument(path, line, column)) // continue; //ConnectTargetToSource(); var uname = scene.GetBookmarkUniqueName(path, line, column); scene.AddBookmarkItem(path, fileName, line, column); scene.AddCodeItem(m_srcUniqueName); scene.AcquireLock(); scene.DoAddCustomEdge(uname, m_srcUniqueName); scene.ReleaseLock(); } count++; var duration = (DateTime.Now - beginTime).TotalMilliseconds; if (duration > 100) { break; } } return(count); }
void CheckFindResultWindow(bool limitTime) { //var dte = Package.GetGlobalService(typeof(DTE)) as DTE2; //var win = dte.Windows.Item(EnvDTE.Constants.vsWindowKindFindResults1); //var selection = win.Selection as EnvDTE.TextSelection; //selection.SelectAll(); //var selectionText = selection.Text; //Logger.Debug("======================="); //Logger.Debug(selectionText); var dte = Package.GetGlobalService(typeof(DTE)) as DTE2; if (dte == null || m_srcUniqueName == "") { return; } var request = new DoxygenDB.EntitySearchRequest( "", (int)DoxygenDB.SearchOption.MATCH_WORD, "", (int)DoxygenDB.SearchOption.MATCH_WORD, "file", "", 0); var result = new DoxygenDB.EntitySearchResult(); var win = dte.Windows.Item(EnvDTE.Constants.vsWindowKindFindResults1); var selection = win.Selection as EnvDTE.TextSelection; selection.SelectAll(); var selectionText = selection.Text; var scene = UIManager.Instance().GetScene(); var db = DBManager.Instance().GetDB(); Point center; scene.GetSelectedCenter(out center); var rand = new Random(m_srcUniqueName.GetHashCode()); StringReader reader = new StringReader(selectionText); string strReadline; var beginTime = DateTime.Now; for (int ithLine = 0, processedLine = 0; (strReadline = reader.ReadLine()) != null; ++ithLine) { if (ithLine == 0) { continue; } if (m_processedLine.Contains(strReadline) || m_processedLine.Count > scene.GetLRUMaxLength()) { continue; } m_processedLine.Add(strReadline); int colon1Idx = strReadline.IndexOf(':'); if (colon1Idx == -1) { continue; } int colon2Idx = strReadline.IndexOf(':', colon1Idx + 1); if (colon2Idx == -1) { continue; } var pathLineColumn = strReadline.Substring(0, colon2Idx).Trim(); int lineBegin = pathLineColumn.LastIndexOf('('); int lineEnd = pathLineColumn.LastIndexOf(')'); if (lineBegin == -1 || lineEnd == -1) { continue; } var path = pathLineColumn.Substring(0, lineBegin); path = path.Replace('\\', '/'); int fileNameBegin = path.LastIndexOf('/'); if (fileNameBegin == -1) { continue; } var fileName = path.Substring(fileNameBegin + 1); var lineStr = pathLineColumn.Substring(lineBegin + 1, lineEnd - lineBegin - 1); int line; if (!int.TryParse(lineStr, out line)) { continue; } int column = strReadline.LastIndexOf(m_srcName); if (column == -1) { column = 0; } else { column -= colon2Idx; } request.m_shortName = fileName; request.m_longName = path; db.SearchAndFilter(request, out result); //if (result.bestEntity == null) //{ // continue; //} var bookmarkPos = new Point(center.X - 150, center.Y + (rand.NextDouble() - 0.5) * 200); var filePos = new Point(center.X - 300, center.Y + (rand.NextDouble() - 0.5) * 200); var uname = scene.GetBookmarkUniqueName(path, line, column); scene.AcquireLock(); scene.AddBookmarkItem(path, fileName, line, column, new Dictionary <string, object> { { "targetPos", bookmarkPos } }); scene.AddCodeItem(m_srcUniqueName, new Dictionary <string, object> { { "targetPos", center } }); scene.DoAddCustomEdge(uname, m_srcUniqueName); if (result.bestEntity != null) { var fileUname = result.bestEntity.UniqueName(); scene.AddCodeItem(fileUname, new Dictionary <string, object> { { "targetPos", filePos } }); scene.DoAddCustomEdge(fileUname, uname); } scene.ReleaseLock(); processedLine++; double duration = (DateTime.Now - beginTime).TotalMilliseconds; if (duration > 2000 && limitTime) { break; } } reader.Close(); }