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 @@ -382,12 +382,9 @@ namespace ICSharpCode.ILSpy
}
#region Node Selection
internal void SelectNode(SharpTreeNode obj, bool recordNavigationInHistory = true)
internal void SelectNode(SharpTreeNode obj)
{
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.
treeView.FocusNode(obj);
treeView.SelectedItem = obj;
@ -507,11 +504,14 @@ namespace ICSharpCode.ILSpy @@ -507,11 +504,14 @@ namespace ICSharpCode.ILSpy
private bool ignoreDecompilationRequests;
private void DecompileSelectedNodes(DecompilerTextViewState state = null)
private void DecompileSelectedNodes(DecompilerTextViewState state = null, bool recordHistory = true)
{
if (ignoreDecompilationRequests)
return;
if (recordHistory)
history.Record(Tuple.Create(treeView.SelectedItems.OfType<SharpTreeNode>().ToList(), decompilerTextView.GetState()));
if (treeView.SelectedItems.Count == 1) {
ILSpyTreeNode node = treeView.SelectedItem as ILSpyTreeNode;
if (node != null && node.View(decompilerTextView))
@ -587,7 +587,8 @@ namespace ICSharpCode.ILSpy @@ -587,7 +587,8 @@ namespace ICSharpCode.ILSpy
var currentSelection = treeView.SelectedItems.OfType<SharpTreeNode>().ToList();
var state = decompilerTextView.GetState();
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;
treeView.SelectedItems.Clear();
@ -598,7 +599,7 @@ namespace ICSharpCode.ILSpy @@ -598,7 +599,7 @@ namespace ICSharpCode.ILSpy
if (newState.Item1.Count > 0)
treeView.FocusNode(newState.Item1[0]);
ignoreDecompilationRequests = false;
DecompileSelectedNodes(newState.Item2);
DecompileSelectedNodes(newState.Item2, false);
}
#endregion
@ -655,4 +656,4 @@ namespace ICSharpCode.ILSpy @@ -655,4 +656,4 @@ namespace ICSharpCode.ILSpy
analyzerRow.Height = new GridLength(0);
}
}
}
}

37
ILSpy/NavigationHistory.cs

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

Loading…
Cancel
Save