Browse Source

Adapt folding commands from SharpDevelop

pull/345/head
Ronny Klier 13 years ago
parent
commit
e68c9c907f
  1. 12
      ILSpy/ContextMenuEntry.cs
  2. 11
      ILSpy/TextView/DecompilerTextView.cs
  3. 22
      ILSpy/TextView/FoldingCommands.cs

12
ILSpy/ContextMenuEntry.cs

@ -21,6 +21,8 @@ using System.ComponentModel.Composition; @@ -21,6 +21,8 @@ using System.ComponentModel.Composition;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using ICSharpCode.AvalonEdit;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.TreeView;
@ -59,15 +61,23 @@ namespace ICSharpCode.ILSpy @@ -59,15 +61,23 @@ namespace ICSharpCode.ILSpy
/// </summary>
public ReferenceSegment Reference { get; private set; }
/// <summary>
/// Returns the position in TextView the mouse cursor is currently hovering above.
/// Returns null, if TextView returns null;
/// </summary>
public TextViewPosition? Position { get; private set; }
public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null)
{
var reference = textView != null ? textView.GetReferenceSegmentAtMousePosition() : null;
var position = textView != null ? textView.GetPositionFromMousePosition() : null;
var selectedTreeNodes = treeView != null ? treeView.GetTopLevelSelection().ToArray() : null;
return new TextViewContext {
TreeView = treeView,
SelectedTreeNodes = selectedTreeNodes,
TextView = textView,
Reference = reference
Reference = reference,
Position = position
};
}
}

11
ILSpy/TextView/DecompilerTextView.cs

@ -763,19 +763,18 @@ namespace ICSharpCode.ILSpy.TextView @@ -763,19 +763,18 @@ namespace ICSharpCode.ILSpy.TextView
internal ReferenceSegment GetReferenceSegmentAtMousePosition()
{
TextViewPosition? position = textEditor.TextArea.TextView.GetPosition(Mouse.GetPosition(textEditor.TextArea.TextView) + textEditor.TextArea.TextView.ScrollOffset);
TextViewPosition? position = GetPositionFromMousePosition();
if (position == null)
return null;
int offset = textEditor.Document.GetOffset(position.Value.Location);
return referenceElementGenerator.References.FindSegmentsContaining(offset).FirstOrDefault();
}
public int CurrentOffset {
get {
return textEditor.CaretOffset;
}
internal TextViewPosition? GetPositionFromMousePosition()
{
return textEditor.TextArea.TextView.GetPosition(Mouse.GetPosition(textEditor.TextArea.TextView) + textEditor.TextArea.TextView.ScrollOffset);
}
public DecompilerTextViewState GetState()
{
if (decompiledNodes == null)

22
ILSpy/TextView/FoldingCommands.cs

@ -10,6 +10,7 @@ using System; @@ -10,6 +10,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Folding;
namespace ICSharpCode.ILSpy.TextView
@ -62,16 +63,23 @@ namespace ICSharpCode.ILSpy.TextView @@ -62,16 +63,23 @@ namespace ICSharpCode.ILSpy.TextView
public void Execute(TextViewContext context)
{
if (null == context.TextView)
return;
var textView = context.TextView;
if (null == textView)
return;
var editor = textView.textEditor;
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();
// TODO: or use Caret if position is not given?
var posBox = context.Position;
if (null == posBox)
return;
TextViewPosition pos = posBox.Value;
// look for folding on this line:
FoldingSection folding = foldingManager.GetNextFolding(editor.Document.GetOffset(pos.Line, 1));
if (folding == null || editor.Document.GetLineByOffset(folding.StartOffset).LineNumber != pos.Line) {
// no folding found on current line: find innermost folding containing the mouse position
folding = foldingManager.GetFoldingsContaining(editor.Document.GetOffset(pos.Line, pos.Column)).LastOrDefault();
}
if (folding != null) {
folding.IsFolded = !folding.IsFolded;

Loading…
Cancel
Save