Exemple #1
0
        public bool BeginNewNormalSearch()
        {
            Clear();
            var scene         = UIManager.Instance().GetScene();
            var selectedNodes = scene.SelectedNodes();

            if (selectedNodes.Count == 0)
            {
                return(false);
            }

            CodeUIItem node = selectedNodes[0];

            m_srcUniqueName = node.GetUniqueName();
            m_srcLongName   = node.GetLongName();
            m_srcName       = node.GetName();
            bool res = LaunchNormalSearch(node.GetName());

            if (res == false)
            {
                Clear();
            }

            return(res);
        }
Exemple #2
0
        CodeElement GetCodeElement(CodeUIItem uiItem,Document document)
        {
            if (document == null)
            {
                return(null);
            }
            var t0 = DateTime.Now;

            var docModel = GetFileCodeModel(document);

            if (docModel == null)
            {
                return(null);
            }

            var t1 = DateTime.Now;

            Logger.Debug("GetCodeElement:: get file code model " + (t1 - t0).TotalMilliseconds.ToString());
            t0 = t1;

            var metric     = uiItem.GetMetric();
            int uiItemLine = -1;
            var docName    = document.Name.ToLower();

            if (metric.ContainsKey("file") && metric["file"].m_string.ToLower().Contains(docName))
            {
                uiItemLine = metric["line"].m_int;
            }
            else if (metric.ContainsKey("declFile") && metric["declFile"].m_string.ToLower().Contains(docName))
            {
                uiItemLine = metric["declLine"].m_int;
            }

            var vcDocModel = docModel as VCFileCodeModel;

            if (vcDocModel != null)
            {
                var candidates = vcDocModel.CodeElementFromFullName(uiItem.GetLongName());

                if (candidates != null)
                {
                    var candidateList = new List <Tuple <CodeElement,int> >();
                    foreach (var item in candidates)
                    {
                        var candidate = item as CodeElement;
                        if (candidate != null)
                        {
                            int lineDist  = int.MaxValue;
                            var startLine = candidate.StartPoint.Line;
                            var endLine   = candidate.EndPoint.Line;
                            if (uiItemLine != -1)
                            {
                                var startDist = Math.Abs(uiItemLine - startLine);
                                var endDist   = Math.Abs(uiItemLine - endLine);
                                lineDist = startDist + endDist;
                            }

                            candidateList.Add(new Tuple <CodeElement,int>(candidate,lineDist));
                        }
                    }

                    candidateList.Sort((x,y) => (x.Item2.CompareTo(y.Item2)));
                    if (candidateList.Count != 0)
                    {
                        return(candidateList[0].Item1);
                    }
                }
            }

            var elements = docModel.CodeElements;
            // TraverseCodeElement(elements, 1);
            var elementsList = new List <CodeElements> {
                docModel.CodeElements
            };
            var nameMatchList = new List <Tuple <CodeElement,bool,int> >();

            while (elementsList.Count > 0)
            {
                var curElements = elementsList[0];
                elementsList.RemoveAt(0);

                var elementIter = curElements.GetEnumerator();
                while (elementIter.MoveNext())
                {
                    var element = elementIter.Current as CodeElement;
                    try
                    {
                        var eleName     = element.Name;
                        var eleFullName = element.FullName;
                        var eleStart    = element.StartPoint.Line;
                        var eleEnd      = element.EndPoint.Line;
                        var lineDist    = int.MaxValue;
                        if (uiItemLine != -1)
                        {
                            var startDist = Math.Abs(uiItemLine - eleStart);
                            var endDist   = Math.Abs(uiItemLine - eleEnd);
                            lineDist = startDist + endDist;
                        }
                        //var start = element.GetStartPoint(vsCMPart.vsCMPartBody);
                        //var end = element.GetEndPoint(vsCMPart.vsCMPartBody);
                        //var vcElement = element as VCCodeElement;
                        //if (vcElement != null)
                        //{
                        //    start = vcElement.get_StartPointOf(vsCMPart.vsCMPartWholeWithAttributes, vsCMWhere.vsCMWhereDeclaration);
                        //    end = vcElement.get_EndPointOf(vsCMPart.vsCMPartWholeWithAttributes, vsCMWhere.vsCMWhereDeclaration);
                        //}
                        //var startLine = start.Line;
                        //var endLine = end.Line;
                        //string indentStr = "";
                        //var itemDoc = start.Parent.Parent;
                        //var itemPath = itemDoc.Name;
                        //var docPath = document.Name;
                        //Logger.WriteLine(indentStr + string.Format("element:{0} {1} {2}", eleName, itemPath, startLine));
                        //Logger.WriteLine("-----" + eleName);
                        if (eleFullName != null && uiItem.GetLongName().Contains(eleFullName) &&
                            IsMatchPair(uiItem.GetKind(),element.Kind))
                        {
                            nameMatchList.Add(new Tuple <CodeElement,bool,int>(element,true,lineDist));
                        }
                        else if (eleName == uiItem.GetName())
                        {
                            nameMatchList.Add(new Tuple <CodeElement,bool,int>(element,false,lineDist));
                        }

                        var children = element.Children;
                        if (children != null)
                        {
                            elementsList.Add(children);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            nameMatchList.Sort((x,y) => (
                                   (x.Item2 == y.Item2) ? (x.Item3.CompareTo(y.Item3)) : (x.Item2 == true ? -1 : 1)
                                   ));
            if (nameMatchList.Count > 0)
            {
                return(nameMatchList[0].Item1);
            }
            return(null);
        }