- created DefaultSnippetElementProvider for standard SnippetElements
- introduced SnippetInfo and changed signature of ISnippetElementProvider - added SnippetAnchorElement - refactored InsertCtor to insert ctor body at the same time as the dialog
This commit is contained in:
Родитель
dccd628866
Коммит
b7263a90a9
|
@ -286,6 +286,7 @@
|
||||||
<DependentUpon>VisualLine.cs</DependentUpon>
|
<DependentUpon>VisualLine.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Snippets\IActiveElement.cs" />
|
<Compile Include="Snippets\IActiveElement.cs" />
|
||||||
|
<Compile Include="Snippets\SnippetAnchorElement.cs" />
|
||||||
<Compile Include="Snippets\SnippetEventArgs.cs" />
|
<Compile Include="Snippets\SnippetEventArgs.cs" />
|
||||||
<Compile Include="Snippets\SnippetInputHandler.cs" />
|
<Compile Include="Snippets\SnippetInputHandler.cs" />
|
||||||
<Compile Include="Snippets\Snippet.cs" />
|
<Compile Include="Snippets\Snippet.cs" />
|
||||||
|
|
|
@ -92,6 +92,15 @@ namespace ICSharpCode.AvalonEdit.Snippets
|
||||||
AnchorSegment wholeSnippetAnchor;
|
AnchorSegment wholeSnippetAnchor;
|
||||||
bool deactivateIfSnippetEmpty;
|
bool deactivateIfSnippetEmpty;
|
||||||
|
|
||||||
|
public int StartPosition {
|
||||||
|
get {
|
||||||
|
if (wholeSnippetAnchor != null)
|
||||||
|
return wholeSnippetAnchor.Offset;
|
||||||
|
else
|
||||||
|
return startPosition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Inserts text at the insertion position and advances the insertion position.
|
/// Inserts text at the insertion position and advances the insertion position.
|
||||||
/// This method will add the current indentation to every line in <paramref name="text"/> and will
|
/// This method will add the current indentation to every line in <paramref name="text"/> and will
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <author name="Siegfried Pammer"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using ICSharpCode.AvalonEdit.Document;
|
||||||
|
|
||||||
|
namespace ICSharpCode.AvalonEdit.Snippets
|
||||||
|
{
|
||||||
|
public sealed class SnippetAnchorElement : SnippetElement
|
||||||
|
{
|
||||||
|
string textToInsert = "";
|
||||||
|
|
||||||
|
public string Name { get; private set; }
|
||||||
|
|
||||||
|
public SnippetAnchorElement(string name)
|
||||||
|
{
|
||||||
|
this.Name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Insert(InsertionContext context)
|
||||||
|
{
|
||||||
|
int start = context.InsertionPosition;
|
||||||
|
context.InsertText("");
|
||||||
|
int end = context.InsertionPosition;
|
||||||
|
AnchorSegment segment = new AnchorSegment(context.Document, start, end - start);
|
||||||
|
context.RegisterActiveElement(this, new AnchorSnippetElement(segment, "", Name, context));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class AnchorSnippetElement : IActiveElement
|
||||||
|
{
|
||||||
|
public bool IsEditable {
|
||||||
|
get { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
AnchorSegment segment;
|
||||||
|
InsertionContext context;
|
||||||
|
|
||||||
|
public ISegment Segment {
|
||||||
|
get { return segment; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public AnchorSnippetElement(AnchorSegment segment, string text, string name, InsertionContext context)
|
||||||
|
{
|
||||||
|
this.segment = segment;
|
||||||
|
this.context = context;
|
||||||
|
this.Text = text;
|
||||||
|
this.Name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Text {
|
||||||
|
get { return context.Document.GetText(segment); }
|
||||||
|
set {
|
||||||
|
int offset = segment.Offset;
|
||||||
|
int length = segment.Length;
|
||||||
|
context.Document.Replace(offset, length, value);
|
||||||
|
if (length == 0) {
|
||||||
|
// replacing an empty anchor segment with text won't enlarge it, so we have to recreate it
|
||||||
|
segment = new AnchorSegment(context.Document, offset, value.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name { get; private set; }
|
||||||
|
|
||||||
|
public void OnInsertionCompleted()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deactivate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -107,7 +107,6 @@ namespace ICSharpCode.AvalonEdit.Snippets
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool IsEditable {
|
public bool IsEditable {
|
||||||
get { return false; }
|
get { return false; }
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче