Skip to content

Commit

Permalink
Merge pull request #41 from danwalmsley/netstandard1.3
Browse files Browse the repository at this point in the history
Netstandard1.3
  • Loading branch information
danwalmsley authored Aug 14, 2017
2 parents 161fdc9 + c34fac2 commit 8b9875c
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 122 deletions.
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ var nuspecNuGetBehaviors = new NuGetPackSettings()
},
Files = new []
{
new NuSpecContent { Source = "src/AvaloniaEdit/bin/" + configuration + "/netstandard1.1/AvaloniaEdit.dll", Target = "lib/netstandard1.1" },
new NuSpecContent { Source = "src/AvaloniaEdit/bin/" + configuration + "/netstandard1.3/AvaloniaEdit.dll", Target = "lib/netstandard1.3" },
},
BasePath = Directory("./"),
OutputDirectory = nugetRoot
Expand Down
32 changes: 3 additions & 29 deletions src/AvaloniaEdit/AvaloniaEdit.csproj
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.1</TargetFramework>
<TargetFramework>netstandard1.3</TargetFramework>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="Editing\TextArea.xaml" />
<EmbeddedResource Include="TextEditor.xaml" />
<EmbeddedResource Include="AvaloniaEdit.xaml" />
<EmbeddedResource Include="CodeCompletion\CompletionList.xaml" />
<EmbeddedResource Include="CodeCompletion\InsightWindow.xaml" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Highlighting\Resources\ASPX.xshd" />
<EmbeddedResource Include="Highlighting\Resources\Boo.xshd" />
<EmbeddedResource Include="Highlighting\Resources\Coco-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\CPP-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\CSharp-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\CSS-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\HTML-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\Java-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\JavaScript-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\MarkDown-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\ModeV1.xsd" />
<EmbeddedResource Include="Highlighting\Resources\ModeV2.xsd" />
<EmbeddedResource Include="Highlighting\Resources\Patch-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\PHP-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\PowerShell.xshd" />
<EmbeddedResource Include="Highlighting\Resources\Tex-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\VB-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\XML-Mode.xshd" />
<EmbeddedResource Include="Highlighting\Resources\XmlDoc.xshd" />
<EmbeddedResource Include="**\*.xshd;**\*.resx;**\*.xaml;Assets\*;**\*.paml" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.3.0" />
<PackageReference Include="Avalonia" Version="0.5.1-build3466-alpha" />
<PackageReference Include="Avalonia" Version="0.5.1-build3595-alpha" />
</ItemGroup>

</Project>
13 changes: 7 additions & 6 deletions src/AvaloniaEdit/Document/TextLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

using System;
using System.Globalization;
using OmniXaml.TypeConversion;
using System.ComponentModel;
using Portable.Xaml.ComponentModel;

namespace AvaloniaEdit.Document
{
Expand Down Expand Up @@ -167,22 +168,22 @@ public int CompareTo(TextLocation other)
/// <summary>
/// Converts strings of the form '0+[;,]0+' to a <see cref="TextLocation"/>.
/// </summary>
public class TextLocationConverter : ITypeConverter
public class TextLocationConverter : TypeConverter
{
/// <inheritdoc/>
public bool CanConvertFrom(IValueContext context, Type sourceType)
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}

/// <inheritdoc/>
public bool CanConvertTo(IValueContext context, Type destinationType)
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof(TextLocation);
}

/// <inheritdoc/>
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var s = value as string;
var parts = s?.Split(';', ',');
Expand All @@ -194,7 +195,7 @@ public object ConvertFrom(IValueContext context, CultureInfo culture, object val
}

/// <inheritdoc/>
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (value is TextLocation loc && destinationType == typeof(string))
{
Expand Down
50 changes: 40 additions & 10 deletions src/AvaloniaEdit/Editing/AbstractMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,22 @@ namespace AvaloniaEdit.Editing
/// </summary>
public abstract class AbstractMargin : Control, ITextViewConnect
{
static AbstractMargin()
private TextArea _textArea;

public AbstractMargin()
{
TextViewProperty.Changed.Subscribe(OnTextViewChanged);
this.GetObservableWithHistory(TextViewProperty).Subscribe(o =>
{
_wasAutoAddedToTextView = false;
OnTextViewChanged(o.Item1, o.Item2);
});
}

/// <summary>
/// TextView property.
/// </summary>
public static readonly AvaloniaProperty<TextView> TextViewProperty =
AvaloniaProperty.Register<AbstractMargin, TextView>("TextView");
AvaloniaProperty.Register<AbstractMargin, TextView>(nameof(TextView));

/// <summary>
/// Gets/sets the text view for which line numbers are displayed.
Expand All @@ -55,13 +61,6 @@ public TextView TextView
set => SetValue(TextViewProperty, value);
}

private static void OnTextViewChanged(AvaloniaPropertyChangedEventArgs e)
{
var margin = (AbstractMargin)e.Sender;
margin._wasAutoAddedToTextView = false;
margin.OnTextViewChanged((TextView)e.OldValue, (TextView)e.NewValue);
}

// automatically set/unset TextView property using ITextViewConnect
private bool _wasAutoAddedToTextView;

Expand Down Expand Up @@ -110,6 +109,37 @@ protected virtual void OnTextViewChanged(TextView oldTextView, TextView newTextV
}

TextViewDocumentChanged(null, null);

if (oldTextView != null)
{
oldTextView.VisualLinesChanged -= TextViewVisualLinesChanged;
}

if (newTextView != null)
{
newTextView.VisualLinesChanged += TextViewVisualLinesChanged;

// find the text area belonging to the new text view
_textArea = newTextView.GetService(typeof(TextArea)) as TextArea;
}
else
{
_textArea = null;
}
}

/// <summary>
/// Called when the attached textviews visual lines change.
/// Default behavior is to Invalidate Margins Visual.
/// </summary>
protected virtual void OnTextViewVisualLinesChanged()
{
InvalidateVisual();
}

private void TextViewVisualLinesChanged(object sender, EventArgs e)
{
OnTextViewVisualLinesChanged();
}

private void TextViewDocumentChanged(object sender, EventArgs e)
Expand Down
17 changes: 10 additions & 7 deletions src/AvaloniaEdit/Editing/EditingCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using AvaloniaEdit.Document;
using Avalonia.Input;
using AvaloniaEdit.Utils;
using System.Threading.Tasks;

namespace AvaloniaEdit.Editing
{
Expand Down Expand Up @@ -469,26 +470,26 @@ private static void CanPaste(object target, CanExecuteRoutedEventArgs args)
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
args.CanExecute = textArea.ReadOnlySectionProvider.CanInsert(textArea.Caret.Offset)
&& !string.IsNullOrEmpty(Application.Current.Clipboard.GetTextAsync()
.GetAwaiter()
.GetResult());
args.CanExecute = textArea.ReadOnlySectionProvider.CanInsert(textArea.Caret.Offset);
args.Handled = true;
}
}

private static void OnPaste(object target, ExecutedRoutedEventArgs args)
private static async void OnPaste(object target, ExecutedRoutedEventArgs args)
{
var textArea = GetTextArea(target);
if (textArea?.Document != null)
{
string text;
textArea.Document.BeginUpdate();

string text = null;
try
{
text = Application.Current.Clipboard.GetTextAsync().GetAwaiter().GetResult();
text = await Application.Current.Clipboard.GetTextAsync();
}
catch (Exception)
{
textArea.Document.EndUpdate();
return;
}

Expand All @@ -505,6 +506,8 @@ private static void OnPaste(object target, ExecutedRoutedEventArgs args)

textArea.Caret.BringCaretToView();
args.Handled = true;

textArea.Document.EndUpdate();
}
}

Expand Down
27 changes: 0 additions & 27 deletions src/AvaloniaEdit/Editing/LineNumberMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,6 @@ public override void Render(DrawingContext drawingContext)
}
}

/// <inheritdoc/>
protected override void OnTextViewChanged(TextView oldTextView, TextView newTextView)
{
if (oldTextView != null)
{
oldTextView.VisualLinesChanged -= TextViewVisualLinesChanged;
}
base.OnTextViewChanged(oldTextView, newTextView);
if (newTextView != null)
{
newTextView.VisualLinesChanged += TextViewVisualLinesChanged;

// find the text area belonging to the new text view
_textArea = newTextView.GetService(typeof(TextArea)) as TextArea;
}
else
{
_textArea = null;
}
InvalidateVisual();
}

/// <inheritdoc/>
protected override void OnDocumentChanged(TextDocument oldDocument, TextDocument newDocument)
{
Expand Down Expand Up @@ -151,11 +129,6 @@ private void OnDocumentLineCountChanged()
}
}

private void TextViewVisualLinesChanged(object sender, EventArgs e)
{
InvalidateVisual();
}

private AnchorSegment _selectionStart;
private bool _selecting;

Expand Down
17 changes: 1 addition & 16 deletions src/AvaloniaEdit/Folding/FoldingMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,9 @@ protected override Size ArrangeOverride(Size finalSize)
return base.ArrangeOverride(finalSize);
}

/// <inheritdoc/>
protected override void OnTextViewChanged(TextView oldTextView, TextView newTextView)
{
if (oldTextView != null)
{
oldTextView.VisualLinesChanged -= TextViewVisualLinesChanged;
}
base.OnTextViewChanged(oldTextView, newTextView);
if (newTextView != null)
{
newTextView.VisualLinesChanged += TextViewVisualLinesChanged;
}
TextViewVisualLinesChanged(null, null);
}

private readonly List<FoldingMarginMarker> _markers = new List<FoldingMarginMarker>();

private void TextViewVisualLinesChanged(object sender, EventArgs e)
protected override void OnTextViewVisualLinesChanged()
{
foreach (var m in _markers)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,42 @@
// DEALINGS IN THE SOFTWARE.

using System;
using System.ComponentModel;
using System.Globalization;
using OmniXaml.TypeConversion;

namespace AvaloniaEdit.Highlighting
{
/// <summary>
/// Converts between strings and <see cref="IHighlightingDefinition"/> by treating the string as the definition name
/// and calling <c>HighlightingManager.Instance.<see cref="HighlightingManager.GetDefinition">GetDefinition</see>(name)</c>.
/// </summary>
public sealed class HighlightingDefinitionTypeConverter : ITypeConverter
public sealed class HighlightingDefinitionTypeConverter : TypeConverter
{
/// <inheritdoc/>
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
/// <inheritdoc/>
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
string definitionName = value as string;
return definitionName != null ? HighlightingManager.Instance.GetDefinition(definitionName) : null;
}
/// <inheritdoc/>
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return destinationType == typeof(string);
}
/// <inheritdoc/>
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
/// <inheritdoc/>
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}

/// <inheritdoc/>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
string definitionName = value as string;
return definitionName != null ? HighlightingManager.Instance.GetDefinition(definitionName) : null;
}

/// <inheritdoc/>
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof(string);
}

/// <inheritdoc/>
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (value is IHighlightingDefinition definition && destinationType == typeof(string))
return definition.Name;
return null;
}
}
}
}
2 changes: 1 addition & 1 deletion src/AvaloniaEdit/Highlighting/IHighlightingDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// DEALINGS IN THE SOFTWARE.

using System.Collections.Generic;
using OmniXaml.TypeConversion;
using System.ComponentModel;

namespace AvaloniaEdit.Highlighting
{
Expand Down

0 comments on commit 8b9875c

Please sign in to comment.