Browse Source

Add context menu entries for folding

pull/345/head
Ronny Klier 13 years ago
parent
commit
07fbe290d5
  1. 1
      ILSpy/ILSpy.csproj
  2. 13
      ILSpy/TextView/DecompilerTextView.cs
  3. 82
      ILSpy/TextView/FoldingCommands.cs

1
ILSpy/ILSpy.csproj

@ -177,6 +177,7 @@ @@ -177,6 +177,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Commands\SimpleCommand.cs" />
<Compile Include="TextView\FoldingCommands.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzeContextMenuEntry.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedAssemblyTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedAttributeAppliedToTreeNode.cs" />

13
ILSpy/TextView/DecompilerTextView.cs

@ -769,6 +769,12 @@ namespace ICSharpCode.ILSpy.TextView @@ -769,6 +769,12 @@ namespace ICSharpCode.ILSpy.TextView
int offset = textEditor.Document.GetOffset(position.Value.Location);
return referenceElementGenerator.References.FindSegmentsContaining(offset).FirstOrDefault();
}
public int CurrentOffset {
get {
return textEditor.CaretOffset;
}
}
public DecompilerTextViewState GetState()
{
@ -809,6 +815,13 @@ namespace ICSharpCode.ILSpy.TextView @@ -809,6 +815,13 @@ namespace ICSharpCode.ILSpy.TextView
// scroll to
textEditor.ScrollTo(lineNumber, 0);
}
public FoldingManager FoldingManager
{
get {
return foldingManager;
}
}
#endregion
}

82
ILSpy/TextView/FoldingCommands.cs

@ -0,0 +1,82 @@ @@ -0,0 +1,82 @@
/*
* Created by SharpDevelop.
* User: Ronny Klier
* Date: 24.05.2012
* Time: 23:44
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.AvalonEdit.Folding;
namespace ICSharpCode.ILSpy.TextView
{
[ExportContextMenuEntryAttribute(Header = "Toggle All Folding", Category = "Folding")]
internal sealed class ToggleAllContextMenuEntry : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
{
return context.TextView != null;
}
public bool IsEnabled(TextViewContext context)
{
return context.TextView != null && context.TextView.FoldingManager != null;
}
public void Execute(TextViewContext context)
{
if (null == context.TextView)
return;
FoldingManager foldingManager = context.TextView.FoldingManager;
if (null == foldingManager)
return;
bool doFold = true;
foreach (FoldingSection fm in foldingManager.AllFoldings) {
if (fm.IsFolded) {
doFold = false;
break;
}
}
foreach (FoldingSection fm in foldingManager.AllFoldings) {
fm.IsFolded = doFold;
}
}
}
[ExportContextMenuEntryAttribute(Header = "Toggle Folding", Category = "Folding")]
internal sealed class ToggleContextMenuEntry : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
{
return context.TextView != null;
}
public bool IsEnabled(TextViewContext context)
{
return context.TextView != null && context.TextView.FoldingManager != null;
}
public void Execute(TextViewContext context)
{
if (null == context.TextView)
return;
FoldingManager foldingManager = context.TextView.FoldingManager;
if (null == foldingManager)
return;
int offset = context.TextView.CurrentOffset;
FoldingSection folding = foldingManager.GetNextFolding(offset);
if (folding == null || folding.StartOffset != offset) {
// no folding found on current line: find innermost folding containing the caret
folding = foldingManager.GetFoldingsContaining(offset).LastOrDefault();
}
if (folding != null) {
folding.IsFolded = !folding.IsFolded;
}
}
}
}
Loading…
Cancel
Save