public override int IndexOf(int currentIndex, ITableEntriesSnapshot newerSnapshot)
        {
            // This and TranslateTo() are used to map errors from one snapshot to a different one (that way the error list can do things like maintain the selection on an error
            // even when the snapshot containing the error is replaced by a new one).
            //
            // You only need to implement Identity() or TranslateTo() and, of the two, TranslateTo() is more efficient for the error list to use.

            // Map currentIndex to the corresponding index in newerSnapshot (and keep doing it until either
            // we run out of snapshots, we reach newerSnapshot, or the index can no longer be mapped forward).

            /*var currentSnapshot = this;
             * do
             * {
             *  Debug.Assert(currentIndex >= 0);
             *  Debug.Assert(currentIndex < currentSnapshot.Count);
             *
             *  currentIndex = currentSnapshot.Diagnostics[currentIndex].NextIndex;
             *
             *  currentSnapshot = currentSnapshot.NextSnapshot;
             * }
             * while ((currentSnapshot != null) && (currentSnapshot != newerSnapshot) && (currentIndex >= 0));
             *
             * return currentIndex;*/
            return(currentIndex);
        }
        /// <inheritdoc />
        public void AddSnapshot(ITableEntriesSnapshot newSnapshot, bool removeAllSnapshots = false)
        {
            if (removeAllSnapshots)
            {
                RemoveAllSnapshots();
            }

            Snapshots.Add(newSnapshot);
        }
Exemple #3
0
        private static T GetValue <T>(ITableEntriesSnapshot snapshot, string columnName)
        {
            object content;

            snapshot.TryGetValue(0, columnName, out content).Should().BeTrue();

            content.Should().BeOfType <T>();
            return((T)content);
        }
        /// <inheritdoc />
        public void ReplaceSnapshot(ITableEntriesSnapshot oldSnapshot, ITableEntriesSnapshot newSnapshot)
        {
            var index = Snapshots.IndexOf(oldSnapshot);

            if (index != -1)
            {
                Snapshots[index] = newSnapshot;
            }
        }
Exemple #5
0
        public int IndexOf(int index, ITableEntriesSnapshot newerSnapshot)
        {
            var data = GetItem(index);

            if (data == null)
            {
                return(-1);
            }

            var item = data.Primary;

            if (item == null)
            {
                return(-1);
            }

            var ourSnapshot = newerSnapshot as AbstractTableEntriesSnapshot <TData>;

            if (ourSnapshot == null || ourSnapshot.Count == 0)
            {
                // not ours, we don't know how to track index
                return(-1);
            }

            // quick path - this will deal with a case where we update data without any actual change
            if (this.Count == ourSnapshot.Count)
            {
                var newData = ourSnapshot.GetItem(index);
                if (newData != null)
                {
                    var newItem = newData.Primary;
                    if (newItem != null && newItem.Equals(item))
                    {
                        return(index);
                    }
                }
            }

            // slow path.
            var bestMatch = Tuple.Create(-1, int.MaxValue);

            for (var i = 0; i < ourSnapshot.Count; i++)
            {
                var newData = ourSnapshot.GetItem(i);
                if (newData != null)
                {
                    var newItem = newData.Primary;
                    if (IsEquivalent(item, newItem))
                    {
                        return(i);
                    }
                }
            }

            // no similar item exist. table control itself will try to maintain selection
            return(-1);
        }
        public override int IndexOf(int currentIndex, ITableEntriesSnapshot newerSnapshot)
        {
            var currentSnapshot = this;

            do
            {
                currentIndex    = currentSnapshot.Messages[currentIndex].NextIndex;
                currentSnapshot = currentSnapshot.NextSnapshot;
            }while ((currentSnapshot != null) && (currentSnapshot != newerSnapshot) && (currentIndex >= 0));
            return(currentIndex);
        }
Exemple #7
0
 public override int IndexOf(int currentIndex, ITableEntriesSnapshot newSnapshot)
 {
     // Called when a new snapshot has been created and the Error List is trying to
     // map from a selected item in the previous snapshot to the corresponding item
     // in the new snapshot.
     // We can only do this if the snapshots represent the same set of issues i.e.
     // the AnalysisRunIds are the same.
     // The Error List will still raise two "selection changed" events - firstly to
     // "null", then to the corresponding issue in the new snapshot.
     if (newSnapshot is IssuesSnapshot newIssuesSnapshot &&
         newIssuesSnapshot.AnalysisRunId == AnalysisRunId)
     {
         return(currentIndex);
     }
     return(base.IndexOf(currentIndex, newSnapshot));
 }
 public override int IndexOf(int currentIndex, ITableEntriesSnapshot newSnapshot)
 {
     // Called when a new snapshot has been created and the Error List is trying to
     // map from a selected item in the previous snapshot to the corresponding item
     // in the new snapshot.
     // We can only do this if the snapshots represent the same set of issues i.e.
     // the AnalysisRunIds are the same.
     // The Error List will still raise two "selection changed" events - firstly to
     // "null", then to the corresponding issue in the new snapshot.
     if (newSnapshot is IssuesSnapshot newIssuesSnapshot &&
         newIssuesSnapshot.AnalysisRunId == AnalysisRunId &&
         currentIndex >= 0 && currentIndex < issues.Count && // defensive - shouldn't happen unless VS passes an invalid index
         !ShouldHideIssue(issues[currentIndex])              // don't map hidden issues: see #2351
         )
     {
         return(currentIndex);
     }
     return(base.IndexOf(currentIndex, newSnapshot));
 }
Exemple #9
0
        public int IndexOf(int index, ITableEntriesSnapshot newerSnapshot)
        {
            var item = GetItem(index);

            if (item == null)
            {
                return(-1);
            }

            if (newerSnapshot is not AbstractTableEntriesSnapshot <TItem> ourSnapshot || ourSnapshot.Count == 0)
            {
                // not ours, we don't know how to track index
                return(-1);
            }

            // quick path - this will deal with a case where we update data without any actual change
            if (Count == ourSnapshot.Count)
            {
                var newItem = ourSnapshot.GetItem(index);
                if (newItem != null && newItem.Equals(item))
                {
                    return(index);
                }
            }

            // slow path.
            for (var i = 0; i < ourSnapshot.Count; i++)
            {
                var newItem = ourSnapshot.GetItem(i);

                // GetItem only returns null for index out of range
                RoslynDebug.AssertNotNull(newItem);

                if (item.EqualsIgnoringLocation(newItem))
                {
                    return(i);
                }
            }

            // no similar item exist. table control itself will try to maintain selection
            return(-1);
        }
 public override int IndexOf(int currentIndex, ITableEntriesSnapshot newSnapshot)
 {
     // We only add items to the end of our list, and we never reorder.
     // As such, any index in us will map to the same index in any newer snapshot.
     return currentIndex;
 }
Exemple #11
0
 /// <inheritdoc />
 public void ReplaceSnapshot(ITableEntriesSnapshot oldSnapshot, ITableEntriesSnapshot newSnapshot)
 {
     return;
 }
Exemple #12
0
 /// <inheritdoc />
 public void RemoveSnapshot(ITableEntriesSnapshot oldSnapshot)
 {
     return;
 }
Exemple #13
0
 /// <inheritdoc />
 public void AddSnapshot(ITableEntriesSnapshot newSnapshot, bool removeAllSnapshots = false)
 {
     return;
 }
Exemple #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SnapshotEntryWrapper"/> class.
 /// </summary>
 /// <param name="snapshot">The <see cref="ITableEntriesSnapshot"/>.</param>
 /// <param name="index">The index of the <see cref="ITableEntry"/> in the <see cref="ITableEntriesSnapshot"/>.</param>
 public SnapshotEntryWrapper(ITableEntriesSnapshot snapshot, int index)
 {
     _snapshot = snapshot ?? throw new ArgumentNullException(nameof(snapshot));
     _index    = index;
 }
Exemple #15
0
 public override int IndexOf(int currentIndex, ITableEntriesSnapshot newerSnapshot)
 {
     return(currentIndex = -1);
 }
Exemple #16
0
 private static Guid GetProjectGuid(ITableEntriesSnapshot snapshot) =>
 GetValue <Guid>(snapshot, StandardTableKeyNames.ProjectGuid);
 private void DeselectItems(ITableEntriesSnapshot snapshot)
 {
     // TODO
 }
 private bool TryGetLastSnapshot(int version, out ITableEntriesSnapshot lastSnapshot)
 {
     return(_lastSnapshotWeakReference.TryGetTarget(out lastSnapshot) &&
            lastSnapshot.VersionNumber == version);
 }
Exemple #19
0
 private static string GetFilePath(ITableEntriesSnapshot snapshot) =>
 GetValue <string>(snapshot, StandardTableKeyNames.DocumentName);
Exemple #20
0
 private static string GetProjectName(ITableEntriesSnapshot snapshot) =>
 GetValue <string>(snapshot, StandardTableKeyNames.ProjectName);
Exemple #21
0
 public int IndexOf(int currentIndex, ITableEntriesSnapshot newSnapshot) => throw new NotImplementedException();
Exemple #22
0
 public override int IndexOf(int currentIndex, ITableEntriesSnapshot newSnapshot)
 {
     // We only add items to the end of our list, and we never reorder.
     // As such, any index in us will map to the same index in any newer snapshot.
     return(currentIndex);
 }
 public override int IndexOf(int currentIndex, ITableEntriesSnapshot newSnapshot)
 {
     // TODO
     return(base.IndexOf(currentIndex, newSnapshot));
 }
 /// <inheritdoc />
 public void RemoveSnapshot(ITableEntriesSnapshot oldSnapshot)
 {
     Snapshots.Remove(oldSnapshot);
 }
Exemple #25
0
 // We only add items to the end of our list, and we never reorder.
 // As such, any index in us will map to the same index in any newer snapshot.
 public override int IndexOf(int currentIndex, ITableEntriesSnapshot newSnapshot) => currentIndex;
 public int IndexOf(int currentIndex, ITableEntriesSnapshot newSnapshot)
 {
     return(currentIndex);
 }