Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Changes to TextEditor (Border, MVVM-friendly), add SQL to Highlighting resources #681

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ internal static void RegisterBuiltInHighlightings(HighlightingManager.DefaultHig
hlm.RegisterHighlighting("Java", new[] { ".java" }, "Java-Mode.xshd");
hlm.RegisterHighlighting("Patch", new[] { ".patch", ".diff" }, "Patch-Mode.xshd");
hlm.RegisterHighlighting("PowerShell", new[] { ".ps1", ".psm1", ".psd1" }, "PowerShell.xshd");
hlm.RegisterHighlighting("PHP", new[] { ".php" }, "PHP-Mode.xshd");
hlm.RegisterHighlighting("TeX", new[] { ".tex" }, "Tex-Mode.xshd");
hlm.RegisterHighlighting("PHP", new[] { ".php" }, "PHP-Mode.xshd");
hlm.RegisterHighlighting("SQL", new[] { ".sql" }, "SQL.xshd");
hlm.RegisterHighlighting("TeX", new[] { ".tex" }, "Tex-Mode.xshd");
hlm.RegisterHighlighting("VB", new[] { ".vb" }, "VB-Mode.xshd");
hlm.RegisterHighlighting("XML", (".xml;.xsl;.xslt;.xsd;.manifest;.config;.addin;" +
".xshd;.wxs;.wxi;.wxl;.proj;.csproj;.vbproj;.ilproj;" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
<?xml version="1.0"?>
<SyntaxDefinition name="sql" extensions=".sql"
xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="String" foreground="Olive" exampleText="string text = &quot;Hello, World!&quot;"/>
<Color name="String2" foreground="#993" exampleText="string text = &quot;Hello, World!&quot;"/>
<Color name="Comment" foreground="Green" exampleText="string text = &quot;Hello, World!&quot;"/>
<Color name="Punctuation" foreground="Red" exampleText="string text = &quot;Hello, World!&quot;"/>
<RuleSet ignoreCase="true">
<Span color="String" multiline="true" >
<Begin>'</Begin>
<End>'</End>

</Span>

<Span color="String2" multiline="true" >
<Begin>"</Begin>
<End>"</End>
</Span>
<!-- span for escape sequences -->
<Span color="Comment" begin="--" end="\n"/>
<Span color="Comment" multiline="true">
<Begin>/\*</Begin>
<End>\*/</End>
</Span>

<Keywords fontWeight="bold" foreground="Blue" >
<Word>ABORT</Word>
<Word>BETWEEN</Word>
<Word>CRASH</Word>
<Word>DIGITS</Word>
<Word>ACCEPT</Word>
<Word>BINARY_INTEGER</Word>
<Word>CREATE</Word>
<Word>DISPOSE</Word>
<Word>ACCESS</Word>
<Word>BODY</Word>
<Word>CURRENT</Word>
<Word>DISTINCT</Word>
<Word>ADD</Word>
<Word>BOOLEAN</Word>
<Word>CURRVAL</Word>
<Word>DO</Word>
<Word>ALL</Word>
<Word>BY</Word>
<Word>CURSOR</Word>
<Word>DROP</Word>
<Word>ALTER</Word>
<Word>CASE</Word>
<Word>DATABASE</Word>
<Word>ELSE</Word>
<Word>AND</Word>
<Word>CHAR</Word>
<Word>DATA_BASE</Word>
<Word>ELSIF</Word>
<Word>ANY</Word>
<Word>CHAR_BASE</Word>
<Word>DATE</Word>
<Word>END</Word>
<Word>ARRAY</Word>
<Word>CHECK</Word>
<Word>DBA</Word>
<Word>ENTRY</Word>
<Word>ARRAYLEN</Word>
<Word>CLOSE</Word>
<Word>DEBUGOFF</Word>
<Word>EXCEPTION</Word>
<Word>AS</Word>
<Word>CLUSTER</Word>
<Word>DEBUGON</Word>
<Word>EXCEPTION_INIT</Word>
<Word>ASC</Word>
<Word>CLUSTERS</Word>
<Word>DECLARE</Word>
<Word>EXISTS</Word>
<Word>ASSERT</Word>
<Word>COLAUTH</Word>
<Word>DECIMAL</Word>
<Word>EXIT</Word>
<Word>ASSIGN</Word>
<Word>COLUMNS</Word>
<Word>DEFAULT</Word>
<Word>FALSE</Word>
<Word>AT</Word>
<Word>COMMIT</Word>
<Word>DEFINITION</Word>
<Word>FETCH</Word>
<Word>AUTHORIZATION</Word>
<Word>COMPRESS</Word>
<Word>DELAY</Word>
<Word>FLOAT</Word>
<Word>AVG</Word>
<Word>CONNECT</Word>
<Word>DELETE</Word>
<Word>FOR</Word>
<Word>BASE_TABLE</Word>
<Word>CONSTANT</Word>
<Word>DELTA</Word>
<Word>FORM</Word>
<Word>BEGIN</Word>
<Word>COUNT</Word>
<Word>DESC</Word>
<Word>FROM</Word>
<Word>FUNCTION</Word>
<Word>NEW</Word>
<Word>RELEASE</Word>
<Word>SUM</Word>
<Word>GENERIC</Word>
<Word>NEXTVAL</Word>
<Word>REMR</Word>
<Word>TABAUTH</Word>
<Word>GOTO</Word>
<Word>NOCOMPRESS</Word>
<Word>RENAME</Word>
<Word>TABLE</Word>
<Word>GRANT</Word>
<Word>NOT</Word>
<Word>RESOURCE</Word>
<Word>TABLES</Word>
<Word>GROUP</Word>
<Word>NULL</Word>
<Word>RETURN</Word>
<Word>TASK</Word>
<Word>HAVING</Word>
<Word>NUMBER</Word>
<Word>REVERSE</Word>
<Word>TERMINATE</Word>
<Word>IDENTIFIED</Word>
<Word>NUMBER_BASE</Word>
<Word>REVOKE</Word>
<Word>THEN</Word>
<Word>IF</Word>
<Word>OF</Word>
<Word>ROLLBACK</Word>
<Word>TO</Word>
<Word>IN</Word>
<Word>ON</Word>
<Word>ROWID</Word>
<Word>TRUE</Word>
<Word>INDEX</Word>
<Word>OPEN</Word>
<Word>ROWLABEL</Word>
<Word>TYPE</Word>
<Word>INDEXES</Word>
<Word>OPTION</Word>
<Word>ROWNUM</Word>
<Word>UNION</Word>
<Word>INDICATOR</Word>
<Word>OR</Word>
<Word>ROWTYPE</Word>
<Word>UNIQUE</Word>
<Word>INSERT</Word>
<Word>ORDER</Word>
<Word>RUN</Word>
<Word>UPDATE</Word>
<Word>INTEGER</Word>
<Word>OTHERS</Word>
<Word>SAVEPOINT</Word>
<Word>USE</Word>
<Word>INTERSECT</Word>
<Word>OUT</Word>
<Word>SCHEMA</Word>
<Word>VALUES</Word>
<Word>INTO</Word>
<Word>PACKAGE</Word>
<Word>SELECT</Word>
<Word>VARCHAR</Word>
<Word>IS</Word>
<Word>PARTITION</Word>
<Word>SEPARATE</Word>
<Word>VARCHAR2</Word>
<Word>LEVEL</Word>
<Word>PCTFREE</Word>
<Word>SET</Word>
<Word>VARIANCE</Word>
<Word>LIKE</Word>
<Word>POSITIVE</Word>
<Word>SIZE</Word>
<Word>VIEW</Word>
<Word>LIMITED</Word>
<Word>PRAGMA</Word>
<Word>SMALLINT</Word>
<Word>VIEWS</Word>
<Word>LOOP</Word>
<Word>PRIOR</Word>
<Word>SPACE</Word>
<Word>WHEN</Word>
<Word>MAX</Word>
<Word>PRIVATE</Word>
<Word>SQL</Word>
<Word>WHERE</Word>
<Word>MIN</Word>
<Word>PROCEDURE</Word>
<Word>SQLCODE</Word>
<Word>WHILE</Word>
<Word>MINUS</Word>
<Word>PUBLIC</Word>
<Word>SQLERRM</Word>
<Word>WITH</Word>
<Word>MLSLABEL</Word>
<Word>RAISE</Word>
<Word>START</Word>
<Word>WORK</Word>
<Word>MOD</Word>
<Word>RANGE</Word>
<Word>STATEMENT</Word>
<Word>XOR</Word>
<Word>MODE</Word>
<Word>REAL</Word>
<Word>STDDEV</Word>
<Word>NATURAL</Word>
<Word>RECORD</Word>
<Word>SUBTYPE</Word>
</Keywords>
<Rule color="Punctuation">
[?,.;()\[\]{}+\-/%*&lt;&gt;^+~!|&amp;]+
</Rule>

</RuleSet>

</SyntaxDefinition>
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,7 @@
<ItemGroup>
<EmbeddedResource Include="Highlighting\Resources\MarkDown-Mode.xshd" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Highlighting\Resources\SQL.xshd" />
</ItemGroup>
</Project>
57 changes: 51 additions & 6 deletions src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,62 @@ protected TextEditor(TextArea textArea)

SetCurrentValue(OptionsProperty, textArea.Options);
SetCurrentValue(DocumentProperty, new TextDocument());

TextChanged += TextEditor_TextChanged;
}

#if !DOTNET4

#region Make TextEditor MVVM-friendly

/// <summary>
/// Occurs when the text has changed.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void TextEditor_TextChanged(object sender, EventArgs e)
{
DocumentText = Text;
}

/// <summary>
/// Gets or sets the DocumentText (set a Binding to this Property to support MVVM)
/// </summary>
public string DocumentText
{
get { return (string)GetValue(DocumentTextProperty); }
set { SetValue(DocumentTextProperty, value); }
}

/// <summary>
/// The dependency propety of the Document Text.
/// </summary>
public static readonly DependencyProperty DocumentTextProperty =
DependencyProperty.Register("DocumentText", typeof(string), typeof(TextEditor),
new PropertyMetadata(new PropertyChangedCallback(OnDocumentTextChanged)));

/// <summary>
/// Is called when the Text property has changed.
/// </summary>
/// <param name="d"></param>
/// <param name="e"></param>
private static void OnDocumentTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
TextEditor textEditor = d as TextEditor;
string documentText = e.NewValue as string;
if (textEditor.Text != documentText)
textEditor.Text = documentText;
}

#endregion

#if !DOTNET4
void SetCurrentValue(DependencyProperty property, object value)
{
SetValue(property, value);
}
#endif
#endregion
/// <inheritdoc/>
#endif
#endregion

/// <inheritdoc/>
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
return new TextEditorAutomationPeer(this);
Expand Down
17 changes: 10 additions & 7 deletions src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
xmlns:AvalonEdit="clr-namespace:ICSharpCode.AvalonEdit"
xmlns:editing="clr-namespace:ICSharpCode.AvalonEdit.Editing"
>
<Style TargetType="{x:Type AvalonEdit:TextEditor}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter Property="FlowDirection" Value="LeftToRight"/> <!-- AvalonEdit does not support RTL, so ensure we use LTR by default -->
<Style TargetType="{x:Type AvalonEdit:TextEditor}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter Property="FlowDirection" Value="LeftToRight"/> <!-- AvalonEdit does not support RTL, so ensure we use LTR by default -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type AvalonEdit:TextEditor}">
<ScrollViewer
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Focusable="False">
<ScrollViewer
Focusable="False"
Name="PART_ScrollViewer"
CanContentScroll="True"
Expand All @@ -21,9 +24,9 @@
HorizontalContentAlignment="Left"
Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
BorderThickness="0"
/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="WordWrap"
Value="True">
Expand Down