コード例 #1
0
        void TraceCursor()
        {
            var scene  = UIManager.Instance().GetScene();
            var mainUI = UIManager.Instance().GetMainUI();

            mainUI.Dispatcher.BeginInvoke((ThreadStart) delegate
            {
                string curPath;
                int curLine, curCol;
                CursorNavigator.GetCursorPosition(out curPath, out curLine, out curCol);
                if (curPath != m_curDocPath || curLine != m_curDocline)
                {
                    if (scene.m_traceCursorUpdate != SyncToEditorType.SYNC_NONE)
                    {
                        if (Math.Abs(curLine - m_curDocline) > 1)
                        {
                            mainUI.DoShowInAtlas(false);
                            if (scene.m_traceCursorUpdate == SyncToEditorType.SYNC_CURSOR_CALLER_CALLEE)
                            {
                                mainUI.OnFindCallers(null, null);
                                mainUI.OnFindCallees(null, null);
                            }
                        }
                    }
                }

                if (curPath != m_curDocPath || curLine != m_curDocline || System.Environment.TickCount - m_lastTraceTickCount > 30 * 1000)
                {
                    scene.UpdateFileList(curPath);
                    m_curDocPath         = curPath;
                    m_curDocline         = curLine;
                    m_lastTraceTickCount = System.Environment.TickCount;
                }
            }, DispatcherPriority.Loaded);
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        public DoxygenDB.EntitySearchResult DoShowInAtlas(bool showCodePosition = true)
        {
            if (!GetCommandActive())
            {
                return(null);
            }

            var      dte = Package.GetGlobalService(typeof(DTE)) as DTE2;
            Document doc = null;

            if (dte != null)
            {
                doc = dte.ActiveDocument;
            }
            if (doc == null)
            {
                return(null);
            }
            string token    = null;
            string longName = null;
            int    lineNum  = 0;

            EnvDTE.TextSelection         ts     = doc.Selection as EnvDTE.TextSelection;
            DoxygenDB.EntitySearchResult result = new DoxygenDB.EntitySearchResult();

            // Create code position
            if (showCodePosition)
            {
                bool isWholeLine = ts.AnchorPoint.AtEndOfLine && ts.ActivePoint.AtStartOfLine && ts.AnchorPoint.Line == ts.ActivePoint.Line;
                int  activeLine  = ts.ActivePoint.Line;
                if (isWholeLine && ts.Text.Length > 0)
                {
                    var    scene    = UIManager.Instance().GetScene();
                    string docPath  = doc.FullName;
                    string fileName = doc.Name;
                    int    column   = 0;
                    var    uname    = scene.GetBookmarkUniqueName(docPath, activeLine, column);
                    scene.AddBookmarkItem(docPath, fileName, activeLine, column);
                    scene.SelectCodeItem(uname);
                    var entity = new DoxygenDB.Entity(uname, docPath, fileName, "page", new Dictionary <string, DoxygenDB.Variant>());
                    result.candidateList.Add(entity);
                    result.bestEntity = entity;
                    return(result);
                }
            }

            // Search the whole document
            if (ts.AnchorPoint.AtStartOfDocument && ts.ActivePoint.AtEndOfDocument)
            {
                var fileName = doc.Name;
                var fullPath = doc.FullName.Replace("\\", "/");
                result = SearchAndAddToScene(fileName, (int)DoxygenDB.SearchOption.MATCH_WORD,
                                             fileName, (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD,
                                             "file", fullPath, 0);
                return(result);
            }

            CursorNavigator.GetCursorWord(ts, out token, out longName, out lineNum);
            var searched = false;

            if (token != null)
            {
                // Search token under cursor
                string docPath = doc.FullName;
                result = SearchAndAddToScene(token, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.MATCH_WORD,
                                             longName, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD,
                                             "", docPath, lineNum);
                searched = result.candidateList.Count != 0;

                if (!searched)
                {
                    result = SearchAndAddToScene(token, (int)DoxygenDB.SearchOption.MATCH_WORD,
                                                 longName, (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD,
                                                 "", docPath, lineNum);
                    searched = result.candidateList.Count != 0;
                }
            }
            else
            {
                // Search parent scope
                Document    cursorDoc;
                CodeElement element;
                int         line;
                CursorNavigator.GetCursorElement(out cursorDoc, out element, out line);
                if (element != null && cursorDoc != null)
                {
                    var kind = CursorNavigator.VSElementTypeToString(element);
                    result = SearchAndAddToScene(
                        element.Name, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.MATCH_WORD,
                        element.FullName, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD,
                        kind, cursorDoc.FullName, lineNum);
                    searched = result.candidateList.Count != 0;
                }
            }
            // Search the whole document
            if (!searched && token == null)
            {
                var fileName = doc.Name;
                var fullPath = doc.FullName.Replace("\\", "/");
                result = SearchAndAddToScene(fileName, (int)DoxygenDB.SearchOption.MATCH_WORD,
                                             fileName, (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD,
                                             "file", fullPath, 0);
            }


            // Create code position
            //bool isWholeLine = ts.AnchorPoint.AtEndOfLine && ts.ActivePoint.AtStartOfLine && ts.AnchorPoint.Line == ts.ActivePoint.Line;
            //bool isResultEmpty = (result.bestEntity == null) && (result.candidateList.Count == 0);
            //if (showCodePosition && (isWholeLine || isResultEmpty))
            //{
            //    DataDict dataDict = new DataDict();
            //    if (token != null)
            //    {
            //        dataDict["displayName"] = token;
            //    }

            //    int activeLine = ts.ActivePoint.Line;
            //    var scene = UIManager.Instance().GetScene();
            //    string docPath = doc.FullName;
            //    string fileName = doc.Name;
            //    int column = 0;
            //    var uname = scene.GetBookmarkUniqueName(docPath, activeLine, column);
            //    scene.AddBookmarkItem(docPath, fileName, activeLine, column, dataDict);
            //    scene.SelectCodeItem(uname);
            //    var entity = new DoxygenDB.Entity(uname, docPath, fileName, "page", new Dictionary<string, DoxygenDB.Variant>());
            //    result.candidateList.Add(entity);
            //    result.bestEntity = entity;
            //    return result;
            //}
            return(result);
        }
コード例 #4
0
        public void OnShowInAtlas(object sender, ExecutedRoutedEventArgs e)
        {
            if (!GetCommandActive())
            {
                return;
            }

            var      dte = Package.GetGlobalService(typeof(DTE)) as DTE2;
            Document doc = null;

            if (dte != null)
            {
                doc = dte.ActiveDocument;
            }
            if (doc == null)
            {
                return;
            }
            string token    = null;
            string longName = null;
            int    lineNum  = 0;

            EnvDTE.TextSelection ts = doc.Selection as EnvDTE.TextSelection;
            GetCursorWord(ts, out token, out longName, out lineNum);

            var searched = false;

            if (token != null)
            {
                // Search token under cursor
                string docPath = doc.FullName;
                searched = SearchAndAddToScene(token, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.MATCH_WORD,
                                               longName, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD,
                                               "", docPath, lineNum);
                if (!searched)
                {
                    searched = SearchAndAddToScene(token, (int)DoxygenDB.SearchOption.MATCH_WORD,
                                                   longName, (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD,
                                                   "", docPath, lineNum);
                }
            }
            else
            {
                // Search parent scope
                var         navigator = new CursorNavigator();
                Document    cursorDoc;
                CodeElement element;
                int         line;
                navigator.GetCursorElement(out cursorDoc, out element, out line);
                if (element != null && cursorDoc != null)
                {
                    var kind = VSElementTypeToString(element);
                    searched = SearchAndAddToScene(
                        element.Name, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.MATCH_WORD,
                        element.FullName, (int)DoxygenDB.SearchOption.MATCH_CASE | (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD,
                        kind, cursorDoc.FullName, lineNum);
                }
            }
            // Search the whole document
            if (!searched && token == null)
            {
                var fileName = doc.Name;
                var fullPath = doc.FullName.Replace("\\", "/");
                SearchAndAddToScene(fileName, (int)DoxygenDB.SearchOption.MATCH_WORD,
                                    fileName, (int)DoxygenDB.SearchOption.DB_CONTAINS_WORD,
                                    "file", fullPath, 0);
            }
        }
コード例 #5
0
        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);
        }