Browse Source

Merge branch 'ViewStatePreservingFix' of https://github.com/arturek/ILSpy

pull/194/merge
Daniel Grunwald 14 years ago
parent
commit
65423df7e7
  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. 12
      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 @@ -93,7 +93,7 @@ namespace ICSharpCode.ILSpy
output.AddVisualLineElementGenerator(new MyLinkElementGenerator("SharpDevelop", "http://www.icsharpcode.net/opensource/sd/"));
output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt"));
output.AddVisualLineElementGenerator(new MyLinkElementGenerator("LGPL", "resource:LGPL.txt"));
textView.Show(output);
textView.ShowText(output);
}
sealed class MyLinkElementGenerator : LinkElementGenerator
@ -130,7 +130,7 @@ namespace ICSharpCode.ILSpy @@ -130,7 +130,7 @@ namespace ICSharpCode.ILSpy
} catch (Exception ex) {
AvalonEditTextOutput exceptionOutput = new AvalonEditTextOutput();
exceptionOutput.WriteLine(ex.ToString());
textView.Show(exceptionOutput);
textView.ShowText(exceptionOutput);
}
}, TaskScheduler.FromCurrentSynchronizationContext());
};

2
ILSpy/App.xaml.cs

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

2
ILSpy/BamlDecompiler.cs

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

2
ILSpy/Commands.cs

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

15
ILSpy/MainWindow.xaml.cs

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

12
ILSpy/NavigationHistory.cs

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

10
ILSpy/NavigationState.cs

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

21
ILSpy/TextView/DecompilerTextView.cs

@ -61,6 +61,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -61,6 +61,7 @@ namespace ICSharpCode.ILSpy.TextView
readonly UIElementGenerator uiElementGenerator;
List<VisualLineElementGenerator> activeCustomElementGenerators = new List<VisualLineElementGenerator>();
FoldingManager foldingManager;
ILSpyTreeNode[] decompiledNodes;
DefinitionLookup definitionLookup;
CancellationTokenSource currentCancellationTokenSource;
@ -211,11 +212,21 @@ namespace ICSharpCode.ILSpy.TextView @@ -211,11 +212,21 @@ namespace ICSharpCode.ILSpy.TextView
#endregion
#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>
/// Shows the given output in the text view.
/// Cancels any currently running decompilation tasks.
/// </summary>
public void Show(AvalonEditTextOutput textOutput, IHighlightingDefinition highlighting = null)
public void ShowNodes(AvalonEditTextOutput textOutput, ILSpyTreeNode[] nodes, IHighlightingDefinition highlighting = null)
{
// Cancel the decompilation task:
if (currentCancellationTokenSource != null) {
@ -224,6 +235,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -224,6 +235,7 @@ namespace ICSharpCode.ILSpy.TextView
}
this.nextDecompilationRun = null; // remove scheduled decompilation run
ShowOutput(textOutput, highlighting);
decompiledNodes = nodes;
}
/// <summary>
@ -344,6 +356,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -344,6 +356,7 @@ namespace ICSharpCode.ILSpy.TextView
}
ShowOutput(output);
}
decompiledNodes = context.TreeNodes;
});
}
@ -517,6 +530,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -517,6 +530,7 @@ namespace ICSharpCode.ILSpy.TextView
output.WriteLine(ex.ToString());
ShowOutput(output);
}
decompiledNodes = context.TreeNodes;
});
}
@ -579,11 +593,15 @@ namespace ICSharpCode.ILSpy.TextView @@ -579,11 +593,15 @@ namespace ICSharpCode.ILSpy.TextView
public DecompilerTextViewState GetState()
{
if (decompiledNodes == null)
return null;
var state = new DecompilerTextViewState();
if (foldingManager != null)
state.SaveFoldingsState(foldingManager.AllFoldings);
state.VerticalOffset = textEditor.VerticalOffset;
state.HorizontalOffset = textEditor.HorizontalOffset;
state.DecompiledNodes = decompiledNodes;
return state;
}
}
@ -594,6 +612,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -594,6 +612,7 @@ namespace ICSharpCode.ILSpy.TextView
private int FoldingsChecksum;
public double VerticalOffset;
public double HorizontalOffset;
public ILSpyTreeNode[] DecompiledNodes;
public void SaveFoldingsState(IEnumerable<FoldingSection> foldings)
{

2
ILSpy/TreeNodes/ResourceEntryNode.cs

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

2
ILSpy/TreeNodes/ResourceTreeNode.cs

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

2
ILSpy/TreeNodes/XamlResourceNode.cs

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

Loading…
Cancel
Save