Skip to content

Commit

Permalink
Downgrade source generator TFM to netstandard2.0 to bypass the VS bul…
Browse files Browse the repository at this point in the history
…lshit
  • Loading branch information
SKProCH committed Apr 26, 2024
1 parent 53c1c0c commit f99a807
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 29 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ name: CI Build
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
BUILD_VERSION: 1.5.0
BUILD_VERSION: 1.5.1
PACKAGE_RELEASE_NOTES: |
Updates the tfm and packages
Disable IsEditable when IsDynamicCodeSupported false
Add exception handlers to TextMate loading
Downgrade source generator TFM to netstandard2.0 to bypass the VS bullshit
# NOTE: Instead of , use %2c

on:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>preview</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeBuildOutput>false</IncludeBuildOutput>
Expand Down
2 changes: 1 addition & 1 deletion ShowMeTheXaml.Avalonia/ShowMeTheXaml.Avalonia.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand All @@ -14,6 +13,7 @@
<RepositoryType>Git</RepositoryType>
<PackageTags>avalonia avaloniaui</PackageTags>
<RootNamespace>ShowMeTheXaml</RootNamespace>
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
71 changes: 48 additions & 23 deletions ShowMeTheXaml.Avalonia/XamlDisplay.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using Avalonia.Metadata;

// ReSharper disable once CheckNamespace
namespace ShowMeTheXaml {
public class XamlDisplay : TemplatedControl {
namespace ShowMeTheXaml
{
public class XamlDisplay : TemplatedControl
{
public static readonly StyledProperty<string?> XamlTextProperty =
AvaloniaProperty.Register<XamlDisplay, string?>(nameof(XamlText));

Expand All @@ -22,7 +24,7 @@ public class XamlDisplay : TemplatedControl {
public static readonly StyledProperty<AlignmentY> XamlButtonAlignmentProperty =
AvaloniaProperty.Register<XamlDisplay, AlignmentY>(nameof(XamlButtonAlignment), AlignmentY.Bottom);

public static readonly StyledProperty<bool> IsEditableProperty =
public static readonly StyledProperty<bool> IsEditableProperty =
AvaloniaProperty.Register<XamlDisplay, bool>("IsEditable", true);

private IDisposable? _buttonClickHandler;
Expand All @@ -31,63 +33,82 @@ public class XamlDisplay : TemplatedControl {

public XamlDisplay()
{
#if NETSTANDARD2_1_OR_GREATER
IsEditable = RuntimeFeature.IsDynamicCodeSupported;
#else
IsEditable = false;
#endif
}

public bool IsEditable {
public bool IsEditable
{
get => GetValue(IsEditableProperty);
set => SetValue(IsEditableProperty, value);
}

public string UniqueId {
public string UniqueId
{
get => _uniqueId;
set {
set
{
_uniqueId = value;
Reset();
}
}

public string? XamlText {
public string? XamlText
{
get => GetValue(XamlTextProperty);
set => SetValue(XamlTextProperty, value);
}

[Content]
public object? Content {
public object? Content
{
get => GetValue(ContentProperty);
set {
set
{
if (GetValue(ContentProperty) is ILogical oldLogical) LogicalChildren.Remove(oldLogical);
SetValue(ContentProperty, value);
if (value is ILogical newLogical) LogicalChildren.Add(newLogical);
}
}

public AlignmentY XamlButtonAlignment {
public AlignmentY XamlButtonAlignment
{
get => GetValue(XamlButtonAlignmentProperty);
set => SetValue(XamlButtonAlignmentProperty, value);
}

public Dictionary<string, string> CurrentFileNamespaceAliases =>
XamlFilesNamespaceAliases[DisplayContent[UniqueId].FileName];

private void SourceXamlButtonOnPointerPressed(object sender, PointerPressedEventArgs e) {
if (_popup != null) {
private void SourceXamlButtonOnPointerPressed(object sender, PointerPressedEventArgs e)
{
if (_popup != null)
{
_popup.IsOpen = !_popup.IsOpen;
}
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e) {
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_buttonClickHandler?.Dispose();
_popup = e.NameScope.Find<Popup>("XamlPopup");
_buttonClickHandler = e.NameScope.Find<Control>("SourceXamlButton").AddDisposableHandler(PointerPressedEvent, SourceXamlButtonOnPointerPressed);
_buttonClickHandler = e.NameScope.Find<Control>("SourceXamlButton")

Check warning on line 99 in ShowMeTheXaml.Avalonia/XamlDisplay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'o' in 'IDisposable InteractiveExtensions.AddDisposableHandler<PointerPressedEventArgs>(Interactive o, RoutedEvent<PointerPressedEventArgs> routedEvent, EventHandler<PointerPressedEventArgs> handler, RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble, bool handledEventsToo = false)'.
.AddDisposableHandler(PointerPressedEvent, SourceXamlButtonOnPointerPressed);
}

public void Reset() {
public void Reset()
{
if (!DisplayContent.TryGetValue(UniqueId, out var xamlDisplayInstanceData)) return;
if (!string.IsNullOrEmpty(XamlText)) {
Content = AvaloniaRuntimeXamlLoaderHelper.Parse(xamlDisplayInstanceData.Data, CurrentFileNamespaceAliases);
if (!string.IsNullOrEmpty(XamlText))
{
Content = AvaloniaRuntimeXamlLoaderHelper.Parse(xamlDisplayInstanceData.Data,
CurrentFileNamespaceAliases);
}

XamlText = xamlDisplayInstanceData.Data;
}

Expand All @@ -96,17 +117,21 @@ public void Reset() {
private static Dictionary<string, XamlDisplayInstanceData>? _displayContent;
private static Dictionary<string, Dictionary<string, string>>? _xamlFilesNamespaceAliases;

public static Dictionary<string, XamlDisplayInstanceData> DisplayContent {
public static Dictionary<string, XamlDisplayInstanceData> DisplayContent
{
get => _displayContent
?? throw new NullReferenceException("Install ShowMeTheXaml.Avalonia.Generator and call XamlDisplayInternalData.RegisterXamlDisplayData" +
"Also check \"Getting started\" on our Github");
?? throw new NullReferenceException(
"Install ShowMeTheXaml.Avalonia.Generator and call XamlDisplayInternalData.RegisterXamlDisplayData" +
"Also check \"Getting started\" on our Github");
set => _displayContent = value;
}

public static Dictionary<string, Dictionary<string, string>> XamlFilesNamespaceAliases {
public static Dictionary<string, Dictionary<string, string>> XamlFilesNamespaceAliases
{
get => _xamlFilesNamespaceAliases
?? throw new NullReferenceException("Install ShowMeTheXaml.Avalonia.Generator and call XamlDisplayInternalData.RegisterXamlDisplayData" +
"Also check \"Getting started\" on our Github");
?? throw new NullReferenceException(
"Install ShowMeTheXaml.Avalonia.Generator and call XamlDisplayInternalData.RegisterXamlDisplayData" +
"Also check \"Getting started\" on our Github");
set => _xamlFilesNamespaceAliases = value;
}

Expand Down

0 comments on commit f99a807

Please sign in to comment.