コード例 #1
0
 void OnSchemeChanged(CodeUIItem currentItem, string prevItem)
 {
     if (currentItem != null)
     {
         nameEdit.Text = currentItem.GetUniqueName();
     }
 }
コード例 #2
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);
        }
コード例 #3
0
        public bool ShowItemDefinition(CodeUIItem codeItem,string fileName)
        {
            if (File.Exists(fileName))
            {
                OpenFile(fileName);

                var document    = m_dte.ActiveDocument;
                var codeElement = GetCodeElement(codeItem,document);

                if (codeElement != null)
                {
                    try
                    {
                        UpdateBodyCode(codeItem,codeElement);

                        var startPnt = codeElement.StartPoint;
                        var endPnt   = codeElement.EndPoint;

                        TextSelection ts = document.Selection as TextSelection;
                        if (ts != null && ts.TopPoint.GreaterThan(startPnt) && ts.BottomPoint.LessThan(endPnt))
                        {
                            startPnt = ts.TopPoint;
                        }
                        if (CheckAndMoveTo(startPnt,document))
                        {
                            return(true);
                        }

                        // In c++, both a function's declaration and definition should be checked
                        var vcCodeElement = codeElement as VCCodeElement;
                        if (vcCodeElement != null)
                        {
                            List <vsCMWhere> whereList = new List <vsCMWhere>
                            {
                                vsCMWhere.vsCMWhereDeclaration,
                                vsCMWhere.vsCMWhereDefinition,
                                vsCMWhere.vsCMWhereDefault
                            };

                            foreach (var where in whereList)
                            {
                                startPnt = vcCodeElement.get_StartPointOf(vsCMPart.vsCMPartWholeWithAttributes,where);

                                if (CheckAndMoveTo(startPnt,document))
                                {
                                    return(true);
                                }
                            }
                        }
                        return(false);
                    }
                    catch (Exception e)
                    {
                        var msg = e.Message;
                    }
                }
            }
            return(false);
        }
コード例 #4
0
        public static Color NameToColor(string name)
        {
            uint hashVal = (uint)name.GetHashCode();

            hashVal = ((hashVal) & 0xff) ^ ((hashVal >> 8) & 0xff) ^ ((hashVal >> 16) & 0xff) ^ ((hashVal >> 24) & 0xff);
            var h = ((hashVal) & 0xffff) / 255.0;

            return(CodeUIItem.HSLToRGB(h, 0.8, 0.8));
        }
コード例 #5
0
        public static Color NameToColor(string name)
        {
            uint hashVal = (uint)name.GetHashCode();
            var  h       = ((hashVal) & 0xffff) / 65535.0;
            var  s       = ((hashVal >> 16) & 0xff) / 255.0;
            var  l       = ((hashVal >> 24) & 0xff) / 255.0;

            return(CodeUIItem.HSLToRGB(h, 0.7 + s * 0.2, 0.75 + l * 0.15));
        }
コード例 #6
0
        string UpdateBodyCode(CodeUIItem item,CodeElement codeElement)
        {
            if (codeElement == null || item == null || !item.IsFunction())
            {
                return("");
            }
            var    funcStart   = codeElement.GetStartPoint(vsCMPart.vsCMPartBody);
            var    funcEnd     = codeElement.GetEndPoint(vsCMPart.vsCMPartBody);
            var    funcEditPnt = funcStart.CreateEditPoint();
            string funcText    = funcEditPnt.GetText(funcEnd).Replace("\r\n","\n");

            item.m_bodyCode = funcText;
            return(funcText);
        }
コード例 #7
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);
        }