Browse Source

Fixed navigation to preserve state of decompiler's text view.

pull/172/head
Artur Zgodziński 16 years ago
parent
commit
54d777f833
  1. 4
      ILSpy/AboutPage.cs
  2. 2
      ILSpy/App.xaml.cs
  3. 2
      ILSpy/BamlDecompiler.cs
  4. 2
      ILSpy/Commands.cs
  5. 15
      ILSpy/MainWindow.xaml.cs
  6. 10
      ILSpy/NavigationHistory.cs
  7. 10
      ILSpy/NavigationState.cs
  8. 21
      ILSpy/TextView/DecompilerTextView.cs
  9. 2
      ILSpy/TreeNodes/ResourceEntryNode.cs
  10. 2
      ILSpy/TreeNodes/ResourceTreeNode.cs
  11. 2
      ILSpy/TreeNodes/XamlResourceNode.cs

4
ILSpy/AboutPage.cs

@ -93,7 +93,7 @@ namespace ICSharpCode.ILSpy
output.AddVisualLineElementGenerator(new MyLinkElementGenerator("SharpDevelop", "http://www.icsharpcode.net/opensource/sd/")); output.AddVisualLineElementGenerator(new MyLinkElementGenerator("SharpDevelop", "http://www.icsharpcode.net/opensource/sd/"));
output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt")); output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt"));
output.AddVisualLineElementGenerator(new MyLinkElementGenerator("LGPL", "resource:LGPL.txt")); output.AddVisualLineElementGenerator(new MyLinkElementGenerator("LGPL", "resource:LGPL.txt"));
textView.Show(output); textView.ShowText(output);
} }
sealed class MyLinkElementGenerator : LinkElementGenerator sealed class MyLinkElementGenerator : LinkElementGenerator
@ -130,7 +130,7 @@ namespace ICSharpCode.ILSpy
} catch (Exception ex) { } catch (Exception ex) {
AvalonEditTextOutput exceptionOutput = new AvalonEditTextOutput(); AvalonEditTextOutput exceptionOutput = new AvalonEditTextOutput();
exceptionOutput.WriteLine(ex.ToString()); exceptionOutput.WriteLine(ex.ToString());
textView.Show(exceptionOutput); textView.ShowText(exceptionOutput);
} }
}, TaskScheduler.FromCurrentSynchronizationContext()); }, TaskScheduler.FromCurrentSynchronizationContext());
}; };

2
ILSpy/App.xaml.cs

@ -165,7 +165,7 @@ namespace ICSharpCode.ILSpy
} }
} }
} }
ILSpy.MainWindow.Instance.TextView.Show(output); ILSpy.MainWindow.Instance.TextView.ShowText(output);
} else { } else {
Process.Start(e.Uri.ToString()); Process.Start(e.Uri.ToString());
} }

2
ILSpy/BamlDecompiler.cs

@ -401,7 +401,7 @@ namespace ICSharpCode.ILSpy.Baml
} }
return output; return output;
}), }),
t => textView.Show(t.Result, highlighting) t => textView.ShowNode(t.Result, this, highlighting)
); );
return true; return true;
} }

2
ILSpy/Commands.cs

@ -122,7 +122,7 @@ namespace ICSharpCode.ILSpy
return output; return output;
} }
), ),
task => MainWindow.Instance.TextView.Show(task.Result)); task => MainWindow.Instance.TextView.ShowText(task.Result));
} }
} }
#endif #endif

15
ILSpy/MainWindow.xaml.cs

@ -242,7 +242,7 @@ namespace ICSharpCode.ILSpy
if (!found) { if (!found) {
AvalonEditTextOutput output = new AvalonEditTextOutput(); AvalonEditTextOutput output = new AvalonEditTextOutput();
output.Write("Cannot find " + args.NavigateTo); output.Write("Cannot find " + args.NavigateTo);
decompilerTextView.Show(output); decompilerTextView.ShowText(output);
} }
} }
commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore
@ -511,8 +511,12 @@ namespace ICSharpCode.ILSpy
if (ignoreDecompilationRequests) if (ignoreDecompilationRequests)
return; return;
if (recordHistory) if (recordHistory) {
history.Record(new NavigationState(treeView.SelectedItems.OfType<SharpTreeNode>(), decompilerTextView.GetState())); var dtState = decompilerTextView.GetState();
if(dtState != null)
history.UpdateCurrent(new NavigationState(dtState));
history.Record(new NavigationState(treeView.SelectedItems.OfType<SharpTreeNode>()));
}
if (treeView.SelectedItems.Count == 1) { if (treeView.SelectedItems.Count == 1) {
ILSpyTreeNode node = treeView.SelectedItem as ILSpyTreeNode; ILSpyTreeNode node = treeView.SelectedItem as ILSpyTreeNode;
@ -586,8 +590,9 @@ namespace ICSharpCode.ILSpy
void NavigateHistory(bool forward) void NavigateHistory(bool forward)
{ {
var combinedState = new NavigationState(treeView.SelectedItems.OfType<SharpTreeNode>(), decompilerTextView.GetState()); var dtState = decompilerTextView.GetState();
history.Record(combinedState, replace: true, clearForward: false); if(dtState != null)
history.UpdateCurrent(new NavigationState(dtState));
var newState = forward ? history.GoForward() : history.GoBack(); var newState = forward ? history.GoForward() : history.GoBack();
ignoreDecompilationRequests = true; ignoreDecompilationRequests = true;

10
ILSpy/NavigationHistory.cs

@ -72,12 +72,17 @@ namespace ICSharpCode.ILSpy
forward.Clear(); forward.Clear();
} }
public void Record(T node, bool replace = false, bool clearForward = true) public void UpdateCurrent(T node)
{
current = node;
}
public void Record(T node)
{ {
var navigationTime = DateTime.Now; var navigationTime = DateTime.Now;
var period = navigationTime - lastNavigationTime; var period = navigationTime - lastNavigationTime;
if (period.TotalSeconds < NavigationSecondsBeforeNewEntry || replace) { if (period.TotalSeconds < NavigationSecondsBeforeNewEntry) {
current = node; current = node;
} else { } else {
if (current != null) if (current != null)
@ -88,7 +93,6 @@ namespace ICSharpCode.ILSpy
current = node; current = node;
} }
if (clearForward)
forward.Clear(); forward.Clear();
lastNavigationTime = navigationTime; lastNavigationTime = navigationTime;

10
ILSpy/NavigationState.cs

@ -32,12 +32,18 @@ namespace ICSharpCode.ILSpy
public IEnumerable<SharpTreeNode> TreeNodes { get { return treeNodes; } } public IEnumerable<SharpTreeNode> TreeNodes { get { return treeNodes; } }
public DecompilerTextViewState ViewState { get; private set; } public DecompilerTextViewState ViewState { get; private set; }
public NavigationState(IEnumerable<SharpTreeNode> treeNodes, DecompilerTextViewState viewState) public NavigationState(DecompilerTextViewState viewState)
{ {
this.treeNodes = new HashSet<SharpTreeNode>(treeNodes); this.treeNodes = new HashSet<SharpTreeNode>(viewState.DecompiledNodes);
ViewState = viewState; ViewState = viewState;
} }
public NavigationState(IEnumerable<SharpTreeNode> treeNodes)
{
this.treeNodes = new HashSet<SharpTreeNode>(treeNodes);
}
public bool Equals(NavigationState other) public bool Equals(NavigationState other)
{ {
// TODO: should this care about the view state as well? // TODO: should this care about the view state as well?

21
ILSpy/TextView/DecompilerTextView.cs

@ -60,6 +60,7 @@ namespace ICSharpCode.ILSpy.TextView
readonly UIElementGenerator uiElementGenerator; readonly UIElementGenerator uiElementGenerator;
List<VisualLineElementGenerator> activeCustomElementGenerators = new List<VisualLineElementGenerator>(); List<VisualLineElementGenerator> activeCustomElementGenerators = new List<VisualLineElementGenerator>();
FoldingManager foldingManager; FoldingManager foldingManager;
ILSpyTreeNode[] decompiledNodes;
DefinitionLookup definitionLookup; DefinitionLookup definitionLookup;
CancellationTokenSource currentCancellationTokenSource; CancellationTokenSource currentCancellationTokenSource;
@ -207,11 +208,21 @@ namespace ICSharpCode.ILSpy.TextView
#endregion #endregion
#region ShowOutput #region ShowOutput
public void ShowText(AvalonEditTextOutput textOutput)
{
ShowNodes(textOutput, null);
}
public void ShowNode(AvalonEditTextOutput textOutput, ILSpyTreeNode node, IHighlightingDefinition highlighting = null)
{
ShowNodes(textOutput, new[] { node }, highlighting);
}
/// <summary> /// <summary>
/// Shows the given output in the text view. /// Shows the given output in the text view.
/// Cancels any currently running decompilation tasks. /// Cancels any currently running decompilation tasks.
/// </summary> /// </summary>
public void Show(AvalonEditTextOutput textOutput, IHighlightingDefinition highlighting = null) public void ShowNodes(AvalonEditTextOutput textOutput, ILSpyTreeNode[] nodes, IHighlightingDefinition highlighting = null)
{ {
// Cancel the decompilation task: // Cancel the decompilation task:
if (currentCancellationTokenSource != null) { if (currentCancellationTokenSource != null) {
@ -220,6 +231,7 @@ namespace ICSharpCode.ILSpy.TextView
} }
this.nextDecompilationRun = null; // remove scheduled decompilation run this.nextDecompilationRun = null; // remove scheduled decompilation run
ShowOutput(textOutput, highlighting); ShowOutput(textOutput, highlighting);
decompiledNodes = nodes;
} }
/// <summary> /// <summary>
@ -340,6 +352,7 @@ namespace ICSharpCode.ILSpy.TextView
} }
ShowOutput(output); ShowOutput(output);
} }
decompiledNodes = context.TreeNodes;
}); });
} }
@ -513,6 +526,7 @@ namespace ICSharpCode.ILSpy.TextView
output.WriteLine(ex.ToString()); output.WriteLine(ex.ToString());
ShowOutput(output); ShowOutput(output);
} }
decompiledNodes = context.TreeNodes;
}); });
} }
@ -575,11 +589,15 @@ namespace ICSharpCode.ILSpy.TextView
public DecompilerTextViewState GetState() public DecompilerTextViewState GetState()
{ {
if (decompiledNodes == null)
return null;
var state = new DecompilerTextViewState(); var state = new DecompilerTextViewState();
if (foldingManager != null) if (foldingManager != null)
state.SaveFoldingsState(foldingManager.AllFoldings); state.SaveFoldingsState(foldingManager.AllFoldings);
state.VerticalOffset = textEditor.VerticalOffset; state.VerticalOffset = textEditor.VerticalOffset;
state.HorizontalOffset = textEditor.HorizontalOffset; state.HorizontalOffset = textEditor.HorizontalOffset;
state.DecompiledNodes = decompiledNodes;
return state; return state;
} }
} }
@ -590,6 +608,7 @@ namespace ICSharpCode.ILSpy.TextView
private int FoldingsChecksum; private int FoldingsChecksum;
public double VerticalOffset; public double VerticalOffset;
public double HorizontalOffset; public double HorizontalOffset;
public ILSpyTreeNode[] DecompiledNodes;
public void SaveFoldingsState(IEnumerable<FoldingSection> foldings) public void SaveFoldingsState(IEnumerable<FoldingSection> foldings)
{ {

2
ILSpy/TreeNodes/ResourceEntryNode.cs

@ -144,7 +144,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
output.AddUIElement(() => new Image { Source = image }); output.AddUIElement(() => new Image { Source = image });
output.WriteLine(); output.WriteLine();
output.AddButton(Images.Save, "Save", delegate { Save(null); }); output.AddButton(Images.Save, "Save", delegate { Save(null); });
textView.Show(output, null); textView.ShowNode(output, this, null);
return true; return true;
} }
catch (Exception) { catch (Exception) {

2
ILSpy/TreeNodes/ResourceTreeNode.cs

@ -95,7 +95,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
ext = ".xml"; ext = ".xml";
else else
ext = Path.GetExtension(DecompilerTextView.CleanUpName(er.Name)); ext = Path.GetExtension(DecompilerTextView.CleanUpName(er.Name));
textView.Show(output, HighlightingManager.Instance.GetDefinitionByExtension(ext)); textView.ShowNode(output, this, HighlightingManager.Instance.GetDefinitionByExtension(ext));
return true; return true;
} }
} }

2
ILSpy/TreeNodes/XamlResourceNode.cs

@ -74,7 +74,7 @@ namespace ICSharpCode.ILSpy.Xaml
} }
return output; return output;
}), }),
t => textView.Show(t.Result, highlighting) t => textView.ShowNode(t.Result, this, highlighting)
); );
return true; return true;
} }

Loading…
Cancel
Save