Browse Source

Use AvalonEdit in definition view.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5654 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 15 years ago
parent
commit
090bf516bb
  1. 0
      AddIns/ICSharpCode.SharpDevelop.addin
  2. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.addin
  3. 1
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  4. 42
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs
  5. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DocumentPrinter.cs
  6. 85
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopTextEditor.cs
  7. 12
      src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditTextEditorAdapter.cs
  8. 5
      src/Main/Base/Project/Src/Gui/Pads/AbstractConsolePad.cs
  9. 53
      src/Main/Base/Project/Src/Gui/Pads/DefinitionViewPad.cs
  10. 8
      src/Main/Base/Project/Src/Services/LanguageBinding/AggregatedLanguageBinding.cs

0
AddIns/ICSharpCode.SharpDevelop.addin

4
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.addin

@ -28,6 +28,10 @@ @@ -28,6 +28,10 @@
<Include id="DefaultEditor" path="/SharpDevelop/ViewContent/TextEditor/ContextMenu"/>
</Path>
<Path name = "/SharpDevelop/ViewContent/AvalonEdit/TextEditorInstance">
<Class id="CodeEditorView" class="ICSharpCode.AvalonEdit.AddIn.SharpDevelopTextEditor"/>
</Path>
<Path name = "/SharpDevelop/ViewContent/TextEditor/ContextMenu">
<Condition name = "WindowActive" activewindow="ICSharpCode.AvalonEdit.AddIn.ICodeEditorProvider">
<MenuItem id = "SaveWithEncoding"

1
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

@ -87,6 +87,7 @@ @@ -87,6 +87,7 @@
<Compile Include="Src\CodeEditor.cs" />
<Compile Include="Src\CodeEditorAdapter.cs" />
<Compile Include="Src\CodeEditorView.cs" />
<Compile Include="Src\SharpDevelopTextEditor.cs" />
<Compile Include="Src\Commands\FoldingCommands.cs" />
<Compile Include="Src\Commands\RunIncrementalSearch.cs" />
<Compile Include="Src\Commands\SaveFileWithEncoding.cs" />

42
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs

@ -36,23 +36,15 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -36,23 +36,15 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// There can be two CodeEditorView instances in a single CodeEditor if split-view
/// is enabled.
/// </summary>
public class CodeEditorView : TextEditor
public class CodeEditorView : SharpDevelopTextEditor
{
public ITextEditor Adapter { get; set; }
CodeEditorOptions options;
BracketHighlightRenderer bracketRenderer;
public CodeEditorView()
{
AvalonEditDisplayBinding.RegisterAddInHighlightingDefinitions();
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Help, OnHelpExecuted));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Print, OnPrint));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.PrintPreview, OnPrintPreview));
options = ICSharpCode.AvalonEdit.AddIn.Options.CodeEditorOptions.Instance;
options.BindToTextEditor(this);
UpdateCustomizedHighlighting();
@ -71,6 +63,10 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -71,6 +63,10 @@ namespace ICSharpCode.AvalonEdit.AddIn
this.TextArea.DefaultInputHandler.Editing.InputBindings.Add(newTabBinding);
}
protected override string FileName {
get { return this.Adapter.FileName; }
}
protected override void OnOptionChanged(PropertyChangedEventArgs e)
{
base.OnOptionChanged(e);
@ -386,33 +382,6 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -386,33 +382,6 @@ namespace ICSharpCode.AvalonEdit.AddIn
}
#endregion
#region Printing
void OnPrint(object sender, ExecutedRoutedEventArgs e)
{
PrintDialog printDialog = PrintPreviewViewContent.PrintDialog;
if (printDialog.ShowDialog() == true) {
FlowDocument fd = DocumentPrinter.CreateFlowDocumentForEditor(this);
fd.ColumnGap = 0;
fd.ColumnWidth = printDialog.PrintableAreaWidth;
fd.PageHeight = printDialog.PrintableAreaHeight;
fd.PageWidth = printDialog.PrintableAreaWidth;
IDocumentPaginatorSource doc = fd;
printDialog.PrintDocument(doc.DocumentPaginator, Path.GetFileName(this.Adapter.FileName));
}
}
void OnPrintPreview(object sender, ExecutedRoutedEventArgs e)
{
PrintDialog printDialog = PrintPreviewViewContent.PrintDialog;
FlowDocument fd = DocumentPrinter.CreateFlowDocumentForEditor(this);
fd.ColumnGap = 0;
fd.ColumnWidth = printDialog.PrintableAreaWidth;
fd.PageHeight = printDialog.PrintableAreaHeight;
fd.PageWidth = printDialog.PrintableAreaWidth;
PrintPreviewViewContent.ShowDocument(fd, Path.GetFileName(this.Adapter.FileName));
}
#endregion
protected override IVisualLineTransformer CreateColorizer(IHighlightingDefinition highlightingDefinition)
{
return new CustomizableHighlightingColorizer(
@ -420,6 +389,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -420,6 +389,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
FetchCustomizations(highlightingDefinition.Name));
}
// TODO: move this into SharpDevelopTextEditor
public void UpdateCustomizedHighlighting()
{
string language = this.SyntaxHighlighting != null ? this.SyntaxHighlighting.Name : null;

4
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DocumentPrinter.cs

@ -55,9 +55,9 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -55,9 +55,9 @@ namespace ICSharpCode.AvalonEdit.AddIn
return p;
}
public static FlowDocument CreateFlowDocumentForEditor(CodeEditorView editor)
public static FlowDocument CreateFlowDocumentForEditor(TextEditor editor)
{
IHighlighter highlighter = editor.Adapter.GetService(typeof(IHighlighter)) as IHighlighter;
IHighlighter highlighter = editor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;
FlowDocument doc = new FlowDocument(ConvertTextDocumentToBlock(editor.Document, highlighter));
doc.FontFamily = editor.FontFamily;
doc.FontSize = editor.FontSize;

85
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopTextEditor.cs

@ -0,0 +1,85 @@ @@ -0,0 +1,85 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Input;
using ICSharpCode.AvalonEdit.AddIn.Options;
using ICSharpCode.AvalonEdit.AddIn.Snippets;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
using ICSharpCode.SharpDevelop.Editor.Commands;
namespace ICSharpCode.AvalonEdit.AddIn
{
/// <summary>
/// The text editor used in SharpDevelop.
/// Serves both as base class for CodeEditorView and as text editor control
/// for editors used in other parts of SharpDevelop (e.g. all ConsolePad-based controls)
/// </summary>
public class SharpDevelopTextEditor : TextEditor
{
protected readonly CodeEditorOptions options;
public SharpDevelopTextEditor()
{
AvalonEditDisplayBinding.RegisterAddInHighlightingDefinitions();
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Print, OnPrint));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.PrintPreview, OnPrintPreview));
options = ICSharpCode.AvalonEdit.AddIn.Options.CodeEditorOptions.Instance;
options.BindToTextEditor(this);
}
protected virtual string FileName {
get { return "untitled"; }
}
#region Printing
void OnPrint(object sender, ExecutedRoutedEventArgs e)
{
PrintDialog printDialog = PrintPreviewViewContent.PrintDialog;
if (printDialog.ShowDialog() == true) {
FlowDocument fd = DocumentPrinter.CreateFlowDocumentForEditor(this);
fd.ColumnGap = 0;
fd.ColumnWidth = printDialog.PrintableAreaWidth;
fd.PageHeight = printDialog.PrintableAreaHeight;
fd.PageWidth = printDialog.PrintableAreaWidth;
IDocumentPaginatorSource doc = fd;
printDialog.PrintDocument(doc.DocumentPaginator, Path.GetFileName(this.FileName));
}
}
void OnPrintPreview(object sender, ExecutedRoutedEventArgs e)
{
PrintDialog printDialog = PrintPreviewViewContent.PrintDialog;
FlowDocument fd = DocumentPrinter.CreateFlowDocumentForEditor(this);
fd.ColumnGap = 0;
fd.ColumnWidth = printDialog.PrintableAreaWidth;
fd.PageHeight = printDialog.PrintableAreaHeight;
fd.PageWidth = printDialog.PrintableAreaWidth;
PrintPreviewViewContent.ShowDocument(fd, Path.GetFileName(this.FileName));
}
#endregion
}
}

12
src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditTextEditorAdapter.cs

@ -45,6 +45,16 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit @@ -45,6 +45,16 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit
OnDocumentChanged();
}
public static TextEditor CreateAvalonEditInstance()
{
var node = Core.AddInTree.GetTreeNode("/SharpDevelop/ViewContent/AvalonEdit/TextEditorInstance", false);
if (node != null && node.Codons.Count > 0) {
return (TextEditor)node.Codons[0].BuildItem(null, null);
} else {
return new TextEditor();
}
}
protected virtual bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
{
if (managerType == typeof(TextEditorWeakEventManager.DocumentChanged)) {
@ -75,7 +85,7 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit @@ -75,7 +85,7 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit
public virtual ITextEditorOptions Options { get; private set; }
public virtual ILanguageBinding Language {
get { throw new NotSupportedException(); }
get { return AggregatedLanguageBinding.NullLanguageBinding; }
}
sealed class CaretAdapter : ITextEditorCaret

5
src/Main/Base/Project/Src/Gui/Pads/AbstractConsolePad.cs

@ -264,13 +264,10 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -264,13 +264,10 @@ namespace ICSharpCode.SharpDevelop.Gui
this.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
this.editor = new ICSharpCode.AvalonEdit.TextEditor();
this.editor = Editor.AvalonEdit.AvalonEditTextEditorAdapter.CreateAvalonEditInstance();
this.editor.SetValue(Grid.ColumnProperty, 0);
this.editor.SetValue(Grid.RowProperty, 0);
this.editor.Background = Brushes.White;
this.editor.FontFamily = new FontFamily("Consolas");
this.editor.FontSize = 13;
this.Children.Add(editor);
editor.TextArea.ReadOnlySectionProvider = readOnlyRegion = new BeginReadOnlySectionProvider();

53
src/Main/Base/Project/Src/Gui/Pads/DefinitionViewPad.cs

@ -5,14 +5,16 @@ @@ -5,14 +5,16 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Editor;
using System;
using System.IO;
using System.Windows;
using System.Windows.Forms;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.SharpDevelop.Gui
{
@ -21,10 +23,10 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -21,10 +23,10 @@ namespace ICSharpCode.SharpDevelop.Gui
/// </summary>
public class DefinitionViewPad : AbstractPadContent
{
TextEditorControl ctl;
AvalonEdit.TextEditor ctl;
/// <summary>
/// The <see cref="System.Windows.Forms.Control"/> representing the pad
/// The control representing the pad
/// </summary>
public override object Control {
get {
@ -37,12 +39,11 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -37,12 +39,11 @@ namespace ICSharpCode.SharpDevelop.Gui
/// </summary>
public DefinitionViewPad()
{
ctl = new TextEditorControl();
ctl.Document.ReadOnly = true;
ctl.TextEditorProperties = SharpDevelopTextEditorProperties.Instance;
ctl.ActiveTextAreaControl.TextArea.DoubleClick += OnDoubleClick;
ctl = Editor.AvalonEdit.AvalonEditTextEditorAdapter.CreateAvalonEditInstance();
ctl.IsReadOnly = true;
ctl.MouseDoubleClick += OnDoubleClick;
ParserService.ParserUpdateStepFinished += OnParserUpdateStep;
ctl.VisibleChanged += delegate { UpdateTick(null); };
//this.IsVisibleChanged += delegate { UpdateTick(null); };
}
/// <summary>
@ -51,16 +52,16 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -51,16 +52,16 @@ namespace ICSharpCode.SharpDevelop.Gui
public override void Dispose()
{
ParserService.ParserUpdateStepFinished -= OnParserUpdateStep;
ctl.Dispose();
ctl.Document = null;
base.Dispose();
}
void OnDoubleClick(object sender, EventArgs e)
{
string fileName = ctl.FileName;
string fileName = currentFileName;
if (fileName != null) {
Caret caret = ctl.ActiveTextAreaControl.Caret;
FileService.JumpToFilePosition(fileName, caret.Line + 1, caret.Column + 1);
var caret = ctl.TextArea.Caret;
FileService.JumpToFilePosition(fileName, caret.Line, caret.Column);
// refresh DefinitionView to show the definition of the expression that was double-clicked
UpdateTick(null);
@ -69,7 +70,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -69,7 +70,7 @@ namespace ICSharpCode.SharpDevelop.Gui
void OnParserUpdateStep(object sender, ParserUpdateStepEventArgs e)
{
WorkbenchSingleton.SafeThreadAsyncCall(UpdateTick, e);
UpdateTick(e);
}
void UpdateTick(ParserUpdateStepEventArgs e)
@ -114,24 +115,25 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -114,24 +115,25 @@ namespace ICSharpCode.SharpDevelop.Gui
return ParserService.Resolve(expr, caret.Line, caret.Column, editor.FileName, content);
} catch (Exception ex) {
disableDefinitionView = true;
ctl.Visible = false;
ctl.Visibility = Visibility.Collapsed;
MessageService.ShowException(ex, "Error resolving at " + caret.Line + "/" + caret.Column
+ ". DefinitionViewPad is disabled until you restart SharpDevelop.");
+ ". DefinitionViewPad is disabled until you restart SharpDevelop.");
return null;
}
}
FilePosition oldPosition;
string currentFileName;
void OpenFile(FilePosition pos)
{
if (pos.Equals(oldPosition)) return;
oldPosition = pos;
if (pos.FileName != ctl.FileName)
if (pos.FileName != currentFileName)
LoadFile(pos.FileName);
ctl.ActiveTextAreaControl.ScrollTo(int.MaxValue); // scroll completely down
ctl.ActiveTextAreaControl.Caret.Line = pos.Line - 1;
ctl.ActiveTextAreaControl.ScrollToCaret(); // scroll up to search position
ctl.ScrollToEnd(); // scroll completely down
ctl.TextArea.Caret.Line = pos.Line;
ctl.TextArea.Caret.BringCaretToView(); // scroll up to search position
}
/// <summary>
@ -149,12 +151,13 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -149,12 +151,13 @@ namespace ICSharpCode.SharpDevelop.Gui
// Load the text into the definition view's text editor.
if (openTextEditor != null) {
ctl.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategyForFile(fileName);
// AvalonEdit.TextEditor aeEditor = openTextEditor.GetService(
ctl.Text = openTextEditor.Document.Text;
ctl.FileName = fileName;
currentFileName = fileName;
} else {
ctl.LoadFile(fileName, true, true); // TODO: get AutoDetectEncoding from settings
ctl.Load(fileName);
}
ctl.SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName));
}
}
}

8
src/Main/Base/Project/Src/Services/LanguageBinding/AggregatedLanguageBinding.cs

@ -16,12 +16,16 @@ namespace ICSharpCode.SharpDevelop @@ -16,12 +16,16 @@ namespace ICSharpCode.SharpDevelop
/// Aggregates multiple ILanguageBinding instances to allow more
/// than one language binding for a filename extension.
/// </summary>
class AggregatedLanguageBinding : ILanguageBinding
sealed class AggregatedLanguageBinding : ILanguageBinding
{
IEnumerable<ILanguageBinding> allBindings;
public static readonly AggregatedLanguageBinding NullLanguageBinding = new AggregatedLanguageBinding(System.Linq.Enumerable.Empty<ILanguageBinding>());
readonly IEnumerable<ILanguageBinding> allBindings;
public AggregatedLanguageBinding(IEnumerable<ILanguageBinding> bindings)
{
if (bindings == null)
throw new ArgumentNullException("bindings");
this.allBindings = bindings;
}

Loading…
Cancel
Save