Browse Source

- Alters the navigation history to have a more consistent behavior, by recording all navigation events, and keeping track of the "current" state instead of the "previous" state

pull/132/head
Alex Lyman 14 years ago
parent
commit
49ed553f31
  1. 17
      ILSpy/MainWindow.xaml.cs
  2. 37
      ILSpy/NavigationHistory.cs

17
ILSpy/MainWindow.xaml.cs

@ -382,12 +382,9 @@ namespace ICSharpCode.ILSpy
} }
#region Node Selection #region Node Selection
internal void SelectNode(SharpTreeNode obj, bool recordNavigationInHistory = true) internal void SelectNode(SharpTreeNode obj)
{ {
if (obj != null) { if (obj != null) {
SharpTreeNode oldNode = treeView.SelectedItem as SharpTreeNode;
if (oldNode != null && recordNavigationInHistory)
history.Record(Tuple.Create(treeView.SelectedItems.OfType<SharpTreeNode>().ToList(), decompilerTextView.GetState()));
// Set both the selection and focus to ensure that keyboard navigation works as expected. // Set both the selection and focus to ensure that keyboard navigation works as expected.
treeView.FocusNode(obj); treeView.FocusNode(obj);
treeView.SelectedItem = obj; treeView.SelectedItem = obj;
@ -507,11 +504,14 @@ namespace ICSharpCode.ILSpy
private bool ignoreDecompilationRequests; private bool ignoreDecompilationRequests;
private void DecompileSelectedNodes(DecompilerTextViewState state = null) private void DecompileSelectedNodes(DecompilerTextViewState state = null, bool recordHistory = true)
{ {
if (ignoreDecompilationRequests) if (ignoreDecompilationRequests)
return; return;
if (recordHistory)
history.Record(Tuple.Create(treeView.SelectedItems.OfType<SharpTreeNode>().ToList(), decompilerTextView.GetState()));
if (treeView.SelectedItems.Count == 1) { if (treeView.SelectedItems.Count == 1) {
ILSpyTreeNode node = treeView.SelectedItem as ILSpyTreeNode; ILSpyTreeNode node = treeView.SelectedItem as ILSpyTreeNode;
if (node != null && node.View(decompilerTextView)) if (node != null && node.View(decompilerTextView))
@ -587,7 +587,8 @@ namespace ICSharpCode.ILSpy
var currentSelection = treeView.SelectedItems.OfType<SharpTreeNode>().ToList(); var currentSelection = treeView.SelectedItems.OfType<SharpTreeNode>().ToList();
var state = decompilerTextView.GetState(); var state = decompilerTextView.GetState();
var combinedState = Tuple.Create(currentSelection, state); var combinedState = Tuple.Create(currentSelection, state);
var newState = forward ? history.GoForward(combinedState) : history.GoBack(combinedState); history.Replace(combinedState);
var newState = forward ? history.GoForward() : history.GoBack();
ignoreDecompilationRequests = true; ignoreDecompilationRequests = true;
treeView.SelectedItems.Clear(); treeView.SelectedItems.Clear();
@ -598,7 +599,7 @@ namespace ICSharpCode.ILSpy
if (newState.Item1.Count > 0) if (newState.Item1.Count > 0)
treeView.FocusNode(newState.Item1[0]); treeView.FocusNode(newState.Item1[0]);
ignoreDecompilationRequests = false; ignoreDecompilationRequests = false;
DecompileSelectedNodes(newState.Item2); DecompileSelectedNodes(newState.Item2, false);
} }
#endregion #endregion
@ -655,4 +656,4 @@ namespace ICSharpCode.ILSpy
analyzerRow.Height = new GridLength(0); analyzerRow.Height = new GridLength(0);
} }
} }
} }

37
ILSpy/NavigationHistory.cs

@ -4,14 +4,17 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ICSharpCode.TreeView; using ICSharpCode.TreeView;
using System.Diagnostics;
namespace ICSharpCode.ILSpy namespace ICSharpCode.ILSpy
{ {
/// <summary> /// <summary>
/// Stores the navigation history. /// Stores the navigation history.
/// </summary> /// </summary>
sealed class NavigationHistory<T> internal sealed class NavigationHistory<T>
where T : class
{ {
T current;
List<T> back = new List<T>(); List<T> back = new List<T>();
List<T> forward = new List<T>(); List<T> forward = new List<T>();
@ -23,26 +26,22 @@ namespace ICSharpCode.ILSpy
get { return forward.Count > 0; } get { return forward.Count > 0; }
} }
public T GoBack(T oldNode) public T GoBack()
{ {
if (oldNode != null) forward.Add(current);
forward.Add(oldNode); current = back[back.Count - 1];
T node = back[back.Count - 1];
back.RemoveAt(back.Count - 1); back.RemoveAt(back.Count - 1);
return node; return current;
} }
public T GoForward(T oldNode) public T GoForward()
{ {
if (oldNode != null) back.Add(current);
back.Add(oldNode); current = forward[forward.Count - 1];
T node = forward[forward.Count - 1];
forward.RemoveAt(forward.Count - 1); forward.RemoveAt(forward.Count - 1);
return node; return current;
} }
public void RemoveAll(Predicate<T> predicate) public void RemoveAll(Predicate<T> predicate)
{ {
back.RemoveAll(predicate); back.RemoveAll(predicate);
@ -55,10 +54,18 @@ namespace ICSharpCode.ILSpy
forward.Clear(); forward.Clear();
} }
public void Replace(T node)
{
current = node;
}
public void Record(T node) public void Record(T node)
{ {
if (current != null)
back.Add(current);
forward.Clear(); forward.Clear();
back.Add(node); current = node;
} }
} }
} }

Loading…
Cancel
Save