From c8361dcdb426abc7d3bbac26e7289e59896fb8d4 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Tue, 21 Sep 2010 14:47:01 +0200 Subject: [PATCH] Allow expanding folding sections by double-clicking on the folded element. --- .../Folding/FoldingElementGenerator.cs | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingElementGenerator.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingElementGenerator.cs index f8e2d4ad50..40e16b52cd 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingElementGenerator.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingElementGenerator.cs @@ -3,6 +3,7 @@ using System; using System.Windows; +using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.TextFormatting; @@ -48,23 +49,24 @@ namespace ICSharpCode.AvalonEdit.Folding if (FoldingManager == null) return null; int foldedUntil = -1; - string title = null; + FoldingSection foldingSection = null; foreach (FoldingSection fs in FoldingManager.GetFoldingsAt(offset)) { if (fs.IsFolded) { if (fs.EndOffset > foldedUntil) { foldedUntil = fs.EndOffset; - title = fs.Title; + foldingSection = fs; } } } - if (foldedUntil > offset) { + if (foldedUntil > offset && foldingSection != null) { + string title = foldingSection.Title; if (string.IsNullOrEmpty(title)) title = "..."; var p = new VisualLineElementTextRunProperties(CurrentContext.GlobalTextRunProperties); p.SetForegroundBrush(Brushes.Gray); var textFormatter = TextFormatterFactory.Create(CurrentContext.TextView); var text = FormattedTextElement.PrepareText(textFormatter, title, p); - return new FoldingLineElement(text, foldedUntil - offset); + return new FoldingLineElement(foldingSection, text, foldedUntil - offset); } else { return null; } @@ -72,14 +74,27 @@ namespace ICSharpCode.AvalonEdit.Folding sealed class FoldingLineElement : FormattedTextElement { - public FoldingLineElement(TextLine text, int documentLength) : base(text, documentLength) + readonly FoldingSection fs; + + public FoldingLineElement(FoldingSection fs, TextLine text, int documentLength) : base(text, documentLength) { + this.fs = fs; } public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructionContext context) { return new FoldingLineTextRun(this, this.TextRunProperties); } + + protected internal override void OnMouseDown(MouseButtonEventArgs e) + { + if (e.ClickCount == 2 && e.ChangedButton == MouseButton.Left) { + fs.IsFolded = false; + e.Handled = true; + } else { + base.OnMouseDown(e); + } + } } sealed class FoldingLineTextRun : FormattedTextRun