static NavigationPoint GetNavPointForDoc(Document doc)
        {
            if (doc == null)
            {
                return(null);
            }

            NavigationPoint point = null;

            INavigable navigable = doc.GetContent <INavigable> ();

            if (navigable != null)
            {
                point = navigable.BuildNavigationPoint();
                if (point != null)
                {
                    return(point);
                }
            }

            IEditableTextBuffer editBuf = doc.GetContent <IEditableTextBuffer> ();

            if (editBuf != null)
            {
                point = new TextFileNavigationPoint(doc, editBuf);
                if (point != null)
                {
                    return(point);
                }
            }

            return(new DocumentNavigationPoint(doc));
        }
        public override bool ShouldReplace(NavigationPoint oldPoint)
        {
            TextFileNavigationPoint tf = oldPoint as TextFileNavigationPoint;

            if (tf == null)
            {
                return(false);
            }
            return(base.Equals(tf) && Math.Abs(line - tf.line) < 5);
        }
Ejemplo n.º 3
0
        NavigationPoint GetNavPointForDoc(Document doc, bool forClosedHistory)
        {
            if (doc == null)
            {
                return(null);
            }

            NavigationPoint point = null;

            INavigable navigable = doc.GetContent <INavigable> (true);

            if (navigable != null)
            {
                point = navigable.BuildNavigationPoint();
                if (point != null)
                {
                    return(point);
                }
            }

                        #pragma warning disable CS0618, CS0612 // Type or member is obsolete
            var editBuf = doc.Editor;
            if (editBuf != null)
            {
                if (forClosedHistory)
                {
                    point = new TextFileNavigationPoint(doc.FileName, editBuf.CaretLine, editBuf.CaretColumn);
                }
                else
                {
                    point = new TextFileNavigationPoint(doc, editBuf);
                }
                if (point != null)
                {
                    return(point);
                }
            }
                        #pragma warning restore CS0618, CS0612 // Type or member is obsolete

            return(new DocumentNavigationPoint(doc));
        }
        NavigationPoint GetNavPointForDoc(Document doc, bool forClosedHistory)
        {
            if (doc == null)
            {
                return(null);
            }

            NavigationPoint point = null;

            INavigable navigable = doc.GetContent <INavigable> (true);

            if (navigable != null)
            {
                point = navigable.BuildNavigationPoint();
                if (point != null)
                {
                    return(point);
                }
            }

            if (doc.GetContent <ITextView> (forActiveView: true) is ITextView textView)
            {
                if (forClosedHistory)
                {
                    var caretPosition = textView.Caret.Position.BufferPosition;
                    var line          = textView.TextBuffer.CurrentSnapshot.GetLineFromPosition(caretPosition);
                    var column        = caretPosition.Position - line.Start.Position;
                    point = new TextFileNavigationPoint(doc.FileName, line.LineNumber, column);
                }
                else
                {
                    point = new TextFileNavigationPoint(doc, textView);
                }
                if (point != null)
                {
                    return(point);
                }
            }

            return(new DocumentNavigationPoint(doc));
        }
        static NavigationPoint GetNavPointForDoc(Document doc, bool forClosedHistory)
        {
            if (doc == null)
            {
                return(null);
            }

            NavigationPoint point = null;

            INavigable navigable = doc.GetContent <INavigable> ();

            if (navigable != null)
            {
                point = navigable.BuildNavigationPoint();
                if (point != null)
                {
                    return(point);
                }
            }

            var editBuf = doc.Editor;

            if (editBuf != null)
            {
                if (forClosedHistory)
                {
                    point = new TextFileNavigationPoint(doc.FileName, editBuf.CaretLine, editBuf.CaretColumn);
                }
                else
                {
                    point = new TextFileNavigationPoint(doc, editBuf);
                }
                if (point != null)
                {
                    return(point);
                }
            }

            return(new DocumentNavigationPoint(doc));
        }
        /*
         *
         * //FIXME: this currently isn't hooked up to any GUI. In addition, it should be done lazily, since it's expensive
         * // and the nav menus are shown much less frequently than nav points are created.
         *
         * public override string Tooltip {
         *      get { return snippet; }
         * }
         *
         * public void UpdateLine (int line, MonoDevelop.Ide.Gui.Content.IEditableTextBuffer buffer)
         * {
         *      this.line = line;
         *      UpdateSnippet (buffer);
         * }
         *
         * //gets a snippet for the tooltip
         * void UpdateSnippet (MonoDevelop.Ide.Gui.Content.IEditableTextBuffer buffer)
         * {
         *      //get some lines from the file
         *      int startPos = buffer.GetPositionFromLineColumn (Math.Max (Line - 1, 1), 1);
         *      int endPos = buffer.GetPositionFromLineColumn (Line + 2, 1);
         *      if (endPos < 0)
         *              endPos = buffer.Length;
         *
         *      string [] lines = buffer.GetText (startPos, endPos).Split ('\n', '\r');
         *      System.Text.StringBuilder fragment = new System.Text.StringBuilder ();
         *
         *      //calculate the minimum indent of any of these lines, using an approximation that tab == 4 spaces
         *      int minIndentLength = int.MaxValue;
         *      foreach (string line in lines) {
         *              if (line.Length == 0)
         *                      continue;
         *              int indentLength = GetIndentLength (line);
         *              if (indentLength < minIndentLength)
         *                      minIndentLength = indentLength;
         *      }
         *
         *      //strip off the indents and truncate the length
         *      const int MAX_LINE_LENGTH = 40;
         *      foreach (string line in lines) {
         *              if (line.Length == 0)
         *                      continue;
         *
         *              int length = Math.Min (MAX_LINE_LENGTH, line.Length) - minIndentLength;
         *              if (length > 0)
         *                      fragment.AppendLine (line.Substring (minIndentLength, length));
         *              else
         *                      fragment.AppendLine ();
         *      }
         *
         *      snippet = fragment.ToString ();
         * }
         *
         * int GetIndentLength (string line)
         * {
         *      int indent = 0;
         *      for (int i = 0; i < line.Length; i++) {
         *              if (line[i] == ' ')
         *                      indent++;
         *              else if (line[i] == '\t')
         *                      indent += 4;
         *              else
         *                      break;
         *      }
         *      return indent;
         * }*/

        public override bool Equals(object o)
        {
            TextFileNavigationPoint other = o as TextFileNavigationPoint;

            return(other != null && other.line == line && base.Equals(other));
        }
		static NavigationPoint GetNavPointForDoc (Document doc)
		{
			if (doc == null)
				return null;
			
			NavigationPoint point = null;
			
			INavigable navigable = doc.GetContent<INavigable> ();
			if (navigable != null) {
				point = navigable.BuildNavigationPoint ();
				if (point != null)
					return point;
			}
			
			IEditableTextBuffer editBuf = doc.GetContent<IEditableTextBuffer> ();
			if (editBuf != null) {
				point = new TextFileNavigationPoint (doc, editBuf);
				if (point != null)
					return point;
			}
			
			return new DocumentNavigationPoint (doc);
		}