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;
		}
        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));
        }
        static NavigationHistoryService()
        {
            IdeApp.Workspace.LastWorkspaceItemClosed += delegate {
                history.Clear();
                OnHistoryChanged();
                closedHistory.Clear();
                OnClosedHistoryChanged();
            };

            IdeApp.Workbench.DocumentOpened += delegate(object sender, DocumentEventArgs e) {
                closedHistory.RemoveAll(np => (np.Item1 as DocumentNavigationPoint)?.FileName == e.Document.FileName);
                OnClosedHistoryChanged();
            };

            IdeApp.Workbench.DocumentClosing += delegate(object sender, DocumentEventArgs e) {
                NavigationPoint point = GetNavPointForDoc(e.Document, true) as DocumentNavigationPoint;
                if (point == null)
                {
                    return;
                }

                closedHistory.Add(new Tuple <NavigationPoint, int> (point, IdeApp.Workbench.Documents.IndexOf(e.Document)));
                OnClosedHistoryChanged();
            };

            //keep nav points up to date
            TextEditorService.LineCountChanged          += LineCountChanged;
            TextEditorService.LineCountChangesCommitted += CommitCountChanges;
            TextEditorService.LineCountChangesReset     += ResetCountChanges;
            IdeApp.Workspace.FileRenamedInProject       += FileRenamed;

            IdeApp.Workbench.ActiveDocumentChanged += ActiveDocChanged;
        }
Ejemplo n.º 4
0
        public override bool ShouldReplace(NavigationPoint oldPoint)
        {
            var tf = oldPoint as TextFileNavigationPoint;

            if (tf == null)
            {
                return(false);
            }
            var line1 = this.line;

            if (this.offset is SnapshotPoint sp1)
            {
                var currentSnapshot   = sp1.Snapshot.TextBuffer.CurrentSnapshot;
                var translatedOffset1 = sp1.TranslateTo(currentSnapshot, PointTrackingMode.Positive);
                line1 = currentSnapshot.GetLineNumberFromPosition(translatedOffset1);
            }
            var line2 = tf.line;

            if (tf.offset is SnapshotPoint sp2)
            {
                var currentSnapshot   = sp2.Snapshot.TextBuffer.CurrentSnapshot;
                var translatedOffset2 = sp2.TranslateTo(currentSnapshot, PointTrackingMode.Positive);
                line2 = currentSnapshot.GetLineNumberFromPosition(translatedOffset2);
            }
            return(base.Equals(tf) && Math.Abs(line1 - line2) < 5);
        }
Ejemplo n.º 5
0
 public void Show()
 {
     if (!NavigationHistoryService.IsCurrent(this))
     {
         NavigationHistoryService.MoveTo(this);
     }
     NavigationPoint.Show();
 }
Ejemplo n.º 6
0
        public void LogNavigationPoint(NavigationPoint point, bool transient = false)
        {
            if (point == null)
            {
                throw new ArgumentNullException(nameof(point));
            }

            var item = new NavigationHistoryItem(point);

            //if the current node's transient but has been around for a while, consider making it permanent
            if (Current == null ||
                (currentIsTransient && DateTime.Now.Subtract(Current.Created).TotalMilliseconds > TRANSIENT_TIMEOUT))
            {
                currentIsTransient = false;
            }

            //if the current point's transient, always replace it
            if (currentIsTransient)
            {
                //collapse down possible extra point in history
                var backOne = history[-1];
                if (backOne != null && point.ShouldReplace(backOne.NavigationPoint))
                {
                    // The new node is the same as the last permanent, so we can discard it
                    history.RemoveCurrent();
                    currentIsTransient = false;
                    item.Dispose();
                }
                else
                {
                    currentIsTransient = transient;
                    history.ReplaceCurrent(item);
                }
            }
            //if the new point wants to replace the old one, let it
            else if (Current != null && !transient && point.ShouldReplace(Current.NavigationPoint))
            {
                history.ReplaceCurrent(item);

                //but in this case, the point should not be transient -- unless the old point was,
                //but that's handled earlier
                currentIsTransient = false;
            }
            //final choice: append the the node
            //BUT only if the existing current node would not want to replace the new node
            else if (Current == null || !Current.NavigationPoint.ShouldReplace(point))
            {
                history.AddPoint(item);
                currentIsTransient = transient;
            }
            else
            {
                item.Dispose();
            }

            OnHistoryChanged();
        }
        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);
        }
 public void Show()
 {
     if (NavigationPoint is DocumentNavigationPoint)
     {
         if (!NavigationHistoryService.IsCurrent(this))
         {
             NavigationHistoryService.MoveTo(this);
         }
     }
     NavigationPoint.ShowDocument();
 }
Ejemplo n.º 9
0
        Task DocumentManager_DocumentClosing(object sender, DocumentCloseEventArgs e)
        {
            NavigationPoint point = GetNavPointForDoc(e.Document, true) as DocumentNavigationPoint;

            if (point == null)
            {
                return(Task.CompletedTask);
            }

            closedHistory.Add(new Tuple <NavigationPoint, int> (point, documentManager.Documents.IndexOf(e.Document)));
            OnClosedHistoryChanged();
            return(Task.CompletedTask);
        }
Ejemplo n.º 10
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));
        }
Ejemplo n.º 11
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);
                }
            }

            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));
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
		// used for fuzzy matching to decide whether to replace an existing nav point
		// e.g if user just moves around a little, we don't want to add too many points
		public virtual bool ShouldReplace (NavigationPoint oldPoint)
		{
			return this.Equals (oldPoint);
		}
		internal NavigationHistoryItem (NavigationPoint navPoint)
		{
			this.navPoint = navPoint;
			navPoint.ParentItem = this;
		}
Ejemplo n.º 15
0
 // used for fuzzy matching to decide whether to replace an existing nav point
 // e.g if user just moves around a little, we don't want to add too many points
 public virtual bool ShouldReplace(NavigationPoint oldPoint)
 {
     return(this.Equals(oldPoint));
 }
 internal NavigationHistoryItem(NavigationPoint navPoint)
 {
     this.navPoint       = navPoint;
     navPoint.ParentItem = this;
 }