Browse Source

Fixed split view crash when folding is enabled.

Added GridSplitter to split view.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5052 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
ac6d4f66a0
  1. 1
      samples/AvalonEdit.Sample/article.html
  2. 36
      samples/AvalonEdit.Sample/rendering.html
  3. 33
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
  4. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/CaretNavigationCommandHandler.cs

1
samples/AvalonEdit.Sample/article.html

@ -162,7 +162,6 @@ You can change the <code>Document</code> property to bind the editor to another @@ -162,7 +162,6 @@ You can change the <code>Document</code> property to bind the editor to another
public UndoStack UndoStack { get; }
}</pre>
<h3>Offsets and Lines</h3>
In AvalonEdit, an index into the document is called an <b>offset</b>.
<p>Offsets usually represent the position between two characters.

36
samples/AvalonEdit.Sample/rendering.html

@ -248,42 +248,6 @@ AvalonEdit also internally uses this geometry builder to create the selection wi @@ -248,42 +248,6 @@ AvalonEdit also internally uses this geometry builder to create the selection wi
Inside SharpDevelop, the first option (getting list of rectangles) is used to render the squiggly red line that for compiler errors,
while the second option is used to produce nice-looking breakpoint markers.
<h2>Editing</h2>
The <code>TextArea</code> class is handling user input and executing the appropriate actions.
Both the caret and the selection are controlled by the <code>TextArea</code>.
<p>
You can customize the text area by modifying the <code>TextArea.DefaultInputHandler</code> by adding new or replacing existing
WPF input bindings in it. You can also set <code>TextArea.ActiveInputHandler</code> to something different than the default
to switch the text area into another mode. You could use this to implement an "incremental search" feature, or even a VI emulator.
<p>
The text area has the useful <code>LeftMargins</code> property - use it to add controls to the left of the text view that look like
they're inside the scroll viewer, but don't actually scroll. The <code>AbstractMargin</code> base class contains some useful code
to detect when the margin is attached/detaching from a text view; or when the active document changes. However, you're not forced to use it;
any <code>UIElement</code> can be used as margin.
<h2>Folding</h2>
Folding (code collapsing) could be implemented as an extension to the editor without having to modify the AvalonEdit code.
A <code>VisualLineElementGenerator</code> takes care of the collapsed sections in the text document; and a custom margin draws the plus and minus
buttons.
<p>
That's exactly how folding is implemented in AvalonEdit. However, to make it a bit easier to use; the static <code>FoldingManager.Install</code>
method will create and register the necessary parts automatically.
<p>
All that's left for you is to regularly call <code>FoldingManager.UpdateFoldings</code> with the list of foldings you want to provide.
<p>
Here is the full code required to enable folding:
<pre lang="cs">foldingManager = FoldingManager.Install(textEditor.TextArea);
foldingStrategy = new XmlFoldingStrategy();
foldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);</pre>
If you want the folding markers to update when the text is changed, you have to repeat the <code>foldingStrategy.UpdateFoldings</code> call regularly.
<p>
The sample application to this article also contains the <code>BraceFoldingStrategy</code> that folds using { and }.
However, it is a very simple implementation and does not handle { and } inside strings or comments correctly.
<h2>Syntax highlighting</h2>
TODO: write this section
<h2>Points of Interest</h2>
<p>Did you learn anything interesting/fun/annoying while writing the code? Did you

33
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs

@ -49,6 +49,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -49,6 +49,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
readonly CodeEditorAdapter primaryTextEditorAdapter;
CodeEditorView secondaryTextEditor;
CodeEditorAdapter secondaryTextEditorAdapter;
GridSplitter gridSplitter;
readonly IconBarManager iconBarManager;
readonly TextMarkerService textMarkerService;
ErrorPainter errorPainter;
@ -136,6 +137,8 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -136,6 +137,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
}
}
const double minRowHeight = 40;
public CodeEditor()
{
this.CommandBindings.Add(new CommandBinding(SharpDevelopRoutedCommands.SplitView, OnSplitView));
@ -155,8 +158,9 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -155,8 +158,9 @@ namespace ICSharpCode.AvalonEdit.AddIn
this.Document = primaryTextEditor.Document;
primaryTextEditor.SetBinding(TextEditor.DocumentProperty, new Binding("Document") { Source = this });
this.ColumnDefinitions.Add(new ColumnDefinition());
this.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star), MinHeight = minRowHeight });
SetRow(primaryTextEditor, 1);
this.Children.Add(primaryTextEditor);
@ -188,8 +192,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -188,8 +192,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
textView.Services.AddService(typeof(IBookmarkMargin), iconBarManager);
textEditor.TextArea.LeftMargins.Insert(0, new IconBarMargin(iconBarManager));
textView.Services.AddService(typeof(ParserFoldingStrategy), new ParserFoldingStrategy(textEditor.TextArea));
textView.Services.AddService(typeof(ISyntaxHighlighter), new AvalonEditSyntaxHighlighterAdapter(textView));
textEditor.TextArea.TextView.MouseRightButtonDown += TextViewMouseRightButtonDown;
@ -244,7 +246,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -244,7 +246,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
{
if (secondaryTextEditor == null) {
// create secondary editor
this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star), MinHeight = minRowHeight });
secondaryTextEditor = CreateTextEditor();
secondaryTextEditorAdapter = (CodeEditorAdapter)secondaryTextEditor.TextArea.GetService(typeof(ITextEditor));
Debug.Assert(primaryTextEditorAdapter != null);
@ -254,19 +256,31 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -254,19 +256,31 @@ namespace ICSharpCode.AvalonEdit.AddIn
secondaryTextEditor.SyntaxHighlighting = primaryTextEditor.SyntaxHighlighting;
secondaryTextEditor.Options = primaryTextEditor.Options;
gridSplitter = new GridSplitter {
Height = 4,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Top
};
SetRow(gridSplitter, 2);
this.Children.Add(gridSplitter);
secondaryTextEditor.Margin = new Thickness(0, 4, 0, 0);
SetRow(secondaryTextEditor, 2);
this.Children.Add(secondaryTextEditor);
this.secondaryBracketRenderer = new BracketHighlightRenderer(secondaryTextEditor.TextArea.TextView);
secondaryTextEditorAdapter.FileNameChanged();
FetchParseInformation();
} else {
// remove secondary editor
this.Children.Remove(secondaryTextEditor);
this.Children.Remove(gridSplitter);
DisposeTextEditor(secondaryTextEditor);
secondaryTextEditor = null;
secondaryTextEditorAdapter.Language.Detach();
secondaryTextEditorAdapter = null;
gridSplitter = null;
this.secondaryBracketRenderer = null;
this.RowDefinitions.RemoveAt(this.RowDefinitions.Count - 1);
}
@ -527,19 +541,18 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -527,19 +541,18 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (editor != null) {
IServiceContainer container = editor.GetService(typeof(IServiceContainer)) as IServiceContainer;
ParserFoldingStrategy folding = container.GetService(typeof(ParserFoldingStrategy)) as ParserFoldingStrategy;
if (folding != null) {
if (parseInfo == null) {
if (parseInfo == null) {
if (folding != null) {
folding.Dispose();
container.RemoveService(typeof(ParserFoldingStrategy));
} else {
folding.UpdateFoldings(parseInfo);
}
} else {
TextArea textArea = editor.GetService(typeof(TextArea)) as TextArea;
if (parseInfo != null) {
if (folding == null) {
TextArea textArea = editor.GetService(typeof(TextArea)) as TextArea;
folding = new ParserFoldingStrategy(textArea);
container.AddService(typeof(ParserFoldingStrategy), folding);
}
folding.UpdateFoldings(parseInfo);
}
}
}

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/CaretNavigationCommandHandler.cs

@ -86,7 +86,6 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -86,7 +86,6 @@ namespace ICSharpCode.AvalonEdit.Editing
args.Handled = true;
textArea.Caret.Offset = textArea.Document.TextLength;
textArea.Selection = new SimpleSelection(0, textArea.Document.TextLength);
textArea.Caret.BringCaretToView();
}
}

Loading…
Cancel
Save