Пример #1
0
        private void перейтиККодуToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (tvAspects.SelectedNode == null)
                {
                    return;
                }
                PointOfInterest pt = Adapter.GetPointByNode(tvAspects.SelectedNode);
                if ((pt?.Context?.Count ?? 0) == 0)
                {
                    return;
                }
                string           fileName = Manager.GetFullFilePath(pt.FileName);
                PointOfInterest  Tree     = ide.IsDocumentOpen(fileName) ? treeManager.GetTree(fileName, ide.GetDocument(fileName)) : treeManager.GetTree(fileName);
                TreeSearchResult Search   = TreeSearchEngine.FindPointInTree2(Tree, pt, treeManager.GetText(fileName));
                if (Search.Count == 0)
                {
                    SetStatus(string.Format(Strings.CannotFindPoint, pt.Title));
                }
                else if (Search.Singular && (ModifierKeys != Keys.Control))
                {
                    //update point anchor if similarity != 1
                    string path = Manager.GetFullFilePath(pt.FileName);
                    ide.NavigateToFileAndPosition(path, Search[0].Location.StartLine, Search[0].Location.StartColumn);
                    SetStatus("");
                }
                else
                {
                    if (Search.Count >= 2)
                    {
                        int d1 = TreeSearchOptions.Equility - Search.GetTotalMatch(0);
                        int d2 = TreeSearchOptions.Equility - Search.GetTotalMatch(1);
                        //float near = Math.Max(pt.NearG, pt.NearL);
                        //float threshold = ((near + 4) / 5 + 1) / 2; //hardcoded
                        //if (Search._result[0].TotalMatch > threshold*TreeSearchOptions.Equility && Search._result[1].TotalMatch < threshold * TreeSearchOptions.Equility)
                        if (d2 != 0 && d2 >= d1 * 2 && (ModifierKeys != Keys.Control))
                        {
                            string path = Manager.GetFullFilePath(pt.FileName);
                            ide.NavigateToFileAndPosition(path, Search[0].Location.StartLine, Search[0].Location.StartColumn);
                            SetStatus("");
                            return;
                        }
                    }

                    fmSelectPoint.Launch(Search, pt);
                    SetStatus("");
                }
            }
            catch (Exception exc)
            {
                ExceptionInfoHelper.ShowInfo(exc);
            }
        }
        /// <summary>
        /// Вычисляет место для вставки узла при перетаскивании
        /// </summary>
        /// <param name="tv">Дерево</param>
        /// <param name="x">Экранные координаты курсора</param>
        /// <param name="y">Экранные координаты курсора</param>
        /// <param name="NewParent">Узел, являющийся новым родителем</param>
        /// <param name="NewPos">Позиция среди подузлов этого родителя</param>
        public static void GetPositionToInsert(TreeView tv, TreeViewAdapter tva, int x, int y, out TreeNode NewParent, out int NewPos)
        {
            Point pt = tv.PointToClient(new Point(x, y));
            TreeNode DestinationNode = tv.GetNodeAt(pt);
            if (DestinationNode == null)
            {
                NewParent = null;
                NewPos = tv.Nodes.Count;
                return;
            }
            int kind;
            PointOfInterest pti = tva.GetPointByNode(DestinationNode);
            bool NestingAllowed = pti != null;
            int border = DestinationNode.Bounds.Height / 4;

            if (pt.Y <= (DestinationNode.Bounds.Top + border))
                kind = -1;  //верхняя четверть - перед узлом
            else if (pt.Y >= (DestinationNode.Bounds.Bottom - border))
            {
                if (!DestinationNode.IsExpanded)
                    kind = 1;   //нижняя четверть неразвернутого узла - после узла
                else
                    kind = 0;   //нижняя четверть развернутого узла - внутрь
            }
            else
                kind = 0;       //Иначе - внутрь

            if (kind == 0 && ! NestingAllowed)
                if (pt.Y <= (DestinationNode.Bounds.Top + 2*border))
                    kind = -1;  //если внутрь нельзя и верхняя половина - перед узлом
                else
                    kind = 1;   //Внутрь нельзя и нижняя половина - после узла

            if (kind == -1)
            {
                //Перед узлом
                NewParent = DestinationNode.Parent;
                if (NewParent == null)
                    NewPos = tv.Nodes.IndexOf(DestinationNode);
                else
                    NewPos = DestinationNode.Parent.Nodes.IndexOf(DestinationNode);
            }
            else if (kind == 1)
            {
                //После узла
                NewParent = DestinationNode.Parent;
                if (NewParent == null)
                    NewPos = tv.Nodes.IndexOf(DestinationNode) + 1;
                else
                    NewPos = DestinationNode.Parent.Nodes.IndexOf(DestinationNode) + 1;
            }
            else
            {
                //Внутрь узла
                NewParent = DestinationNode;
                NewPos = DestinationNode.Nodes.Count;
            }

        }
Пример #3
0
        /// <summary>
        /// Вычисляет место для вставки узла при перетаскивании
        /// </summary>
        /// <param name="tv">Дерево</param>
        /// <param name="x">Экранные координаты курсора</param>
        /// <param name="y">Экранные координаты курсора</param>
        /// <param name="NewParent">Узел, являющийся новым родителем</param>
        /// <param name="NewPos">Позиция среди подузлов этого родителя</param>
        public static void GetPositionToInsert(TreeView tv, TreeViewAdapter tva, int x, int y, out TreeNode NewParent, out int NewPos)
        {
            Point    pt = tv.PointToClient(new Point(x, y));
            TreeNode DestinationNode = tv.GetNodeAt(pt);

            if (DestinationNode == null)
            {
                NewParent = null;
                NewPos    = tv.Nodes.Count;
                return;
            }
            int             kind;
            PointOfInterest pti            = tva.GetPointByNode(DestinationNode);
            bool            NestingAllowed = pti != null;
            int             border         = DestinationNode.Bounds.Height / 4;

            if (pt.Y <= (DestinationNode.Bounds.Top + border))
            {
                kind = -1;  //верхняя четверть - перед узлом
            }
            else if (pt.Y >= (DestinationNode.Bounds.Bottom - border))
            {
                if (!DestinationNode.IsExpanded)
                {
                    kind = 1;   //нижняя четверть неразвернутого узла - после узла
                }
                else
                {
                    kind = 0;   //нижняя четверть развернутого узла - внутрь
                }
            }
            else
            {
                kind = 0;       //Иначе - внутрь
            }
            if (kind == 0 && !NestingAllowed)
            {
                if (pt.Y <= (DestinationNode.Bounds.Top + 2 * border))
                {
                    kind = -1;  //если внутрь нельзя и верхняя половина - перед узлом
                }
                else
                {
                    kind = 1;   //Внутрь нельзя и нижняя половина - после узла
                }
            }
            if (kind == -1)
            {
                //Перед узлом
                NewParent = DestinationNode.Parent;
                if (NewParent == null)
                {
                    NewPos = tv.Nodes.IndexOf(DestinationNode);
                }
                else
                {
                    NewPos = DestinationNode.Parent.Nodes.IndexOf(DestinationNode);
                }
            }
            else if (kind == 1)
            {
                //После узла
                NewParent = DestinationNode.Parent;
                if (NewParent == null)
                {
                    NewPos = tv.Nodes.IndexOf(DestinationNode) + 1;
                }
                else
                {
                    NewPos = DestinationNode.Parent.Nodes.IndexOf(DestinationNode) + 1;
                }
            }
            else
            {
                //Внутрь узла
                NewParent = DestinationNode;
                NewPos    = DestinationNode.Nodes.Count;
            }
        }
Пример #4
0
        public static void EditPointAnchor(IDEInterop ide, TreeManager treeManager, AspectManager Manager, TreeViewAdapter Adapter, TreeNode Node, Action Callback)
        {
            if (ide.GetCurrentDocumentFileName() == "")
                return;

            string Text = ide.GetCurrentLine().Trim();
            if (Text == "")
                return;

            List<PointOfInterest> points = FindPointUnderCursor(ide, treeManager);
            PointOfInterest OriginalPoint = Adapter.GetPointByNode(Node);
            if (points != null)
                foreach (PointOfInterest pt in points)
                {
                    pt.FileName = Manager.GetRelativePath(pt.FileName);
                    pt.Title = OriginalPoint.Title;
                    pt.Note = OriginalPoint.Note;
                    pt.Text = Text;
                }

            ShowPointDialog(Adapter, points, Node, false, Callback);
        }