Esempio n. 1
0
        protected void RequestToolTip(Point mousePos)
        {
            if (toolTipRectangle.Contains(mousePos))
            {
                if (!toolTipActive)
                {
                    ResetMouseEventArgs();
                }
                return;
            }

            //Console.WriteLine("Request tooltip for " + mousePos);

            toolTipRectangle = new Rectangle(mousePos.X - 4, mousePos.Y - 4, 8, 8);

            TextLocation logicPos = textView.GetLogicalPosition(mousePos.X - textView.DrawingPosition.Left,
                                                                mousePos.Y - textView.DrawingPosition.Top);
            bool inDocument = textView.DrawingPosition.Contains(mousePos) &&
                              logicPos.Y >= 0 && logicPos.Y < Document.TotalNumberOfLines;
            ToolTipRequestEventArgs args = new ToolTipRequestEventArgs(mousePos, logicPos, inDocument);

            OnToolTipRequest(args);
            if (args.ToolTipShown)
            {
                //Console.WriteLine("Set tooltip to " + args.toolTipText);
                toolTipActive = true;
                SetToolTip(args.toolTipText, inDocument ? logicPos.Y + 1 : -1);
            }
            else
            {
                CloseToolTip();
            }
        }
Esempio n. 2
0
 protected virtual void OnToolTipRequest(ToolTipRequestEventArgs e)
 {
     if (ToolTipRequest != null)
     {
         ToolTipRequest(this, e);
     }
 }
        void OnToolTipRequest(object sender, ToolTipRequestEventArgs e)
        {
            if (e.ToolTipShown)
            {
                return;
            }
            Point      mousepos = e.MousePosition;
            FoldMarker marker   = textArea.TextView.GetFoldMarkerFromPosition(mousepos.X - textArea.TextView.DrawingPosition.X,
                                                                              mousepos.Y - textArea.TextView.DrawingPosition.Y);

            if (marker != null && marker.IsFolded)
            {
                StringBuilder sb = new StringBuilder(marker.InnerText);

                // max 10 lines
                int endLines = 0;
                for (int i = 0; i < sb.Length; ++i)
                {
                    if (sb[i] == '\n')
                    {
                        ++endLines;
                        if (endLines >= 10)
                        {
                            sb.Remove(i + 1, sb.Length - i - 1);
                            sb.Append(Environment.NewLine);
                            sb.Append("...");
                            break;
                        }
                    }
                }
                sb.Replace("\t", "    ");
                e.ShowToolTip(sb.ToString());
                return;
            }

            List <TextMarker> markers = textArea.Document.MarkerStrategy.GetMarkers(e.LogicalPosition);

            foreach (TextMarker tm in markers)
            {
                if (tm.ToolTip != null)
                {
                    e.ShowToolTip(tm.ToolTip.Replace("\t", "    "));
                    return;
                }
            }
        }