Skip to content

Commit

Permalink
Merge pull request #782 from filipnavara/avalonia-aot
Browse files Browse the repository at this point in the history
Update Avalonia to latest version, enable basic PublishAot scenario
  • Loading branch information
KirillOsenkov authored Aug 18, 2024
2 parents 21f0d96 + 9c1997e commit 8b9f902
Show file tree
Hide file tree
Showing 23 changed files with 282 additions and 196 deletions.
12 changes: 10 additions & 2 deletions PublishNativeAOT.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#!/bin/sh
dotnet publish -c Release -r linux-x64 -p:PublishNativeAot=True src/StructuredLogViewer.Avalonia/StructuredLogViewer.Avalonia.csproj
strip bin/StructuredLogViewer.Avalonia/Release/net7.0/linux-x64/publish/StructuredLogViewer.Avalonia
unameOut="$(uname -s)"
case "${unameOut}" in
Darwin*) rid=osx-arm64;;
Linux*) rid=linux-x64;;
*)
echo "Unknown OS"
exit 1
;;
esac
dotnet publish -c Release -r ${rid} -p:PublishNativeAot=True src/StructuredLogViewer.Avalonia/StructuredLogViewer.Avalonia.csproj
18 changes: 9 additions & 9 deletions src/StructuredLogViewer.Avalonia/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
xmlns:l="clr-namespace:Microsoft.Build.Logging.StructuredLogger;assembly=StructuredLogger"
xmlns:common="clr-namespace:Microsoft.Build.Logging.StructuredLogger;assembly=StructuredLogViewer.Core"
xmlns:s="clr-namespace:StructuredLogViewer.Avalonia.Controls;assembly=StructuredLogViewer.Avalonia"
x:Class="StructuredLogViewer.Avalonia.App">
x:Class="StructuredLogViewer.Avalonia.App"
RequestedThemeVariant="Light">

<Application.Resources>
<ResourceDictionary>
Expand All @@ -18,9 +19,8 @@
</Application.Resources>

<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml" />
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
<StyleInclude Source="avares://AvaloniaEdit/AvaloniaEdit.xaml" />
<FluentTheme />
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
<StyleInclude Source="/Styles.xaml" />

<Style Selector="Rectangle.nodeIcon">
Expand Down Expand Up @@ -434,7 +434,7 @@
<ContentPresenter Content="{Binding Converter={StaticResource ProxyNodeIconConverter}}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
<ItemsControl Items="{Binding Highlights}"
<ItemsControl ItemsSource="{Binding Highlights}"
Focusable="False">
<ItemsControl.DataTemplates>
<DataTemplate DataType="{x:Type l:HighlightedText}">
Expand All @@ -443,7 +443,7 @@
Background="Yellow"
Text="{Binding Text}" />
</DataTemplate>
<DataTemplate>
<DataTemplate DataType="x:Object">
<TextBlock Classes="nodeBeforeText"
Text="{Binding .}" />
</DataTemplate>
Expand Down Expand Up @@ -568,7 +568,7 @@
<Expander IsExpanded="True"
Header="Recent projects and solutions"
Margin="10">
<ListBox Items="{Binding RecentProjects}"
<ListBox ItemsSource="{Binding RecentProjects}"
Margin="10"
SelectedItem="{Binding SelectedProject, Mode=OneWayToSource}"
Background="Transparent"
Expand All @@ -582,7 +582,7 @@
<Expander IsExpanded="True"
Header="Recent logs"
Margin="10">
<ListBox Items="{Binding RecentLogs}"
<ListBox ItemsSource="{Binding RecentLogs}"
Margin="10"
SelectedItem="{Binding SelectedLog, Mode=OneWayToSource}"
Background="Transparent"
Expand Down Expand Up @@ -620,7 +620,7 @@
<TextBlock Text="Specify custom MSBuild command line arguments:"
Margin="4" />
<WrapPanel Orientation="Horizontal">
<ComboBox Items="{Binding MSBuildLocations}"
<ComboBox ItemsSource="{Binding MSBuildLocations}"
SelectedItem="{Binding MSBuildLocation}"
ToolTip.Tip="Select MSBuild toolset to use for building"
Height="28"
Expand Down
44 changes: 0 additions & 44 deletions src/StructuredLogViewer.Avalonia/Avalonia.rd.xml

This file was deleted.

12 changes: 2 additions & 10 deletions src/StructuredLogViewer.Avalonia/AvaloniaExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Avalonia.Controls;
using System.Collections;
using System.Linq;
using System.Threading.Tasks;

namespace StructuredLogViewer.Avalonia
{
Expand All @@ -22,16 +20,10 @@ public static void ClearItems(this ItemsControl itemsControl)
(itemsControl.Items as IList)?.Clear();
}

public static void RegisterControl<TControl>(this IControl parent, out TControl control, string name)
where TControl : class, IControl
public static void RegisterControl<TControl>(this Control parent, out TControl control, string name)
where TControl : Control
{
control = parent.FindControl<TControl>(name);
}

public static async Task<string> ShowAndGetFileAsync(this OpenFileDialog dialog, Window window = null)
{
var result = await dialog.ShowAsync(window);
return result?.FirstOrDefault();
}
}
}
11 changes: 5 additions & 6 deletions src/StructuredLogViewer.Avalonia/Controls/BuildControl.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:StructuredLogViewer.Avalonia.Controls;assembly=StructuredLogViewer.Avalonia"
x:Class="StructuredLogViewer.Avalonia.Controls.BuildControl">
xmlns:structuredLogger="clr-namespace:Microsoft.Build.Logging.StructuredLogger;assembly=StructuredLogger"
x:Class="StructuredLogViewer.Avalonia.Controls.BuildControl"
x:DataType="structuredLogger:Build">

<local:SplitterPanel Orientation="Vertical" FirstChildRelativeSize="*" SecondChildRelativeSize="50">

Expand Down Expand Up @@ -55,7 +57,7 @@
BorderThickness="0"
Classes="searchable"
AutoScrollToSelectedItem="True"
Items="{Binding Children}"/>
ItemsSource="{Binding Children}"/>
</TabItem>

<!--<TabItem Name="timelineTab"
Expand Down Expand Up @@ -90,11 +92,8 @@
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}"
Margin="{TemplateBinding Padding}"
VirtualizationMode="{TemplateBinding VirtualizationMode}" />
Margin="{TemplateBinding Padding}" />
</Border>
</ControlTemplate>
</ListBox.Template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ private void PopulateFilesTab()
CompressTree(subFolder);
}

filesTree.Items = root.Children;
filesTree.ItemsSource = root.Children;
filesTree.GotFocus += (s, a) => ActiveTreeView = filesTree;
filesTree.ContextMenu = sharedTreeContextMenu;
}
Expand Down Expand Up @@ -814,7 +814,7 @@ public void UpdateBreadcrumb(object item)
chain = IntersperseWithSeparators(chain).ToArray();
}

breadCrumb.Items = chain;
breadCrumb.ItemsSource = chain;
breadCrumb.SelectedIndex = -1;
}

Expand Down Expand Up @@ -1070,9 +1070,9 @@ private void CopyPaths(TreeView tree = null)
CopyToClipboard(sb.ToString());
}

private static void CopyToClipboard(string text)
private void CopyToClipboard(string text)
{
Application.Current.Clipboard.SetTextAsync(text);
TopLevel.GetTopLevel(this).Clipboard.SetTextAsync(text);
}

public void CopyName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<local:DocumentWell />
</Design.DataContext>
<Grid>
<TabControl Name="tabControl" Items="{Binding #documentWell.Tabs}">
<TabControl Name="tabControl" ItemsSource="{Binding #documentWell.Tabs}">
<TabControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:SourceFileTab}">
<StackPanel Orientation="Horizontal">
Expand Down
10 changes: 6 additions & 4 deletions src/StructuredLogViewer.Avalonia/Controls/DocumentWell.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Avalonia.Controls;
using System;
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using Avalonia.Interactivity;
using Avalonia.VisualTree;

namespace StructuredLogViewer.Avalonia.Controls
{
Expand Down Expand Up @@ -108,7 +110,7 @@ private void TabControlOnPointerPressed(object sender, PointerPressedEventArgs e
if (e.Handled)
return;

var current = e.Source;
var current = e.Source as Visual;

while (current != null)
{
Expand All @@ -118,7 +120,7 @@ private void TabControlOnPointerPressed(object sender, PointerPressedEventArgs e
break;
}

current = current.InteractiveParent;
current = current.GetVisualParent();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
using Avalonia.Controls.Primitives.PopupPositioning;
using Avalonia.Input;
using Avalonia.Media;
using Avalonia.Media.TextFormatting;
using AvaloniaEdit;
using AvaloniaEdit.Document;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Text;
using Microsoft.Build.Logging.StructuredLogger;
using FontStyle = Avalonia.Media.FontStyle;

Expand Down Expand Up @@ -130,7 +130,7 @@ public ImportLinkElement(ImportLinkGenerator generator, VisualLine parentVisualL

public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructionContext context)
{
TextRunProperties.Underline = true;
TextRunProperties.SetTextDecorations(TextDecorations.Underline);
return base.CreateTextRun(startVisualColumn, context);
}

Expand Down Expand Up @@ -216,7 +216,7 @@ private void OpenMenu()
var topLeft = ParentVisualLine.GetVisualPosition(VisualColumn, VisualYPosition.LineTop);
var bottomRight = ParentVisualLine.GetVisualPosition(VisualColumn + VisualLength, VisualYPosition.LineBottom);

menu.PlacementMode = PlacementMode.AnchorAndGravity;
menu.Placement = PlacementMode.AnchorAndGravity;
menu.PlacementAnchor = PopupAnchor.BottomLeft;
menu.PlacementGravity = PopupGravity.BottomRight;
menu.PlacementTarget = generator.TextView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private DrawingGroup GetIcon(string resourceName)
{
if (!icons.TryGetValue(resourceName, out var icon))
{
if (!Application.Current.Resources.TryGetResource(resourceName, out var resource))
if (!Application.Current.Resources.TryGetResource(resourceName, null, out var resource))
resource = null;

icon = resource as DrawingGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private object GetResource(string resourceName)

if (!resources.TryGetValue(resourceName, out var resource))
{
if (!Application.Current.Resources.TryGetResource(resourceName, out resource))
if (!Application.Current.Resources.TryGetResource(resourceName, null, out resource))
resource = null;

resources[resourceName] = resource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<ContentPresenter Name="watermark"
Margin="40"
HorizontalAlignment="Center"
Content="{Binding WatermarkText}"
Content="WatermarkText"
VerticalAlignment="Center">
<ContentPresenter.Styles>
<Style Selector="TextBlock">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void DisplayItems(IEnumerable content)
watermarkScrollViewer.IsVisible = false;
}

resultsList.Items = content;
resultsList.ItemsSource = content;
}

public object WatermarkContent
Expand Down
22 changes: 12 additions & 10 deletions src/StructuredLogViewer.Avalonia/Controls/TextViewerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using AvaloniaEdit.Highlighting.Xshd;
using System.Text;
using Avalonia.VisualTree;
using Avalonia.Platform.Storage;

namespace StructuredLogViewer.Avalonia.Controls
{
Expand Down Expand Up @@ -185,7 +186,7 @@ public void DisplaySource(int lineNumber, int column)

private async void save_Click(object sender, RoutedEventArgs e)
{
if (this.FindAncestorOfType<Window>() is not Window window)
if (TopLevel.GetTopLevel(this) is not TopLevel topLevel)
{
return;
}
Expand All @@ -199,18 +200,19 @@ private async void save_Click(object sender, RoutedEventArgs e)
filePath += extension;
}

var saveFileDialog = new SaveFileDialog
using var result = await topLevel.StorageProvider.SaveFilePickerAsync(new()
{
Title = "Save file as...",
DefaultExtension = $"{extension.Substring(1)} files|*{extension}|All Files|*.*",
InitialFileName = Path.GetFileName(filePath)
};
DefaultExtension = extension,
SuggestedFileName = Path.GetFileName(filePath),
FileTypeChoices = new[] { FilePickerFileTypes.All, FilePickerFileTypes.TextPlain }
});

var result = await saveFileDialog.ShowAsync(window);

if (!string.IsNullOrWhiteSpace(result))
if (result is not null)
{
await File.WriteAllTextAsync(result, Text, Encoding.UTF8, default);
await using var stream = await result.OpenWriteAsync();
await using var writer = new StreamWriter(stream, Encoding.UTF8);
await writer.WriteAsync(Text);
}
}

Expand All @@ -228,7 +230,7 @@ private void openInExternalEditor_Click(object sender, RoutedEventArgs e)

private void copyFullPath_Click(object sender, RoutedEventArgs e)
{
Application.Current.Clipboard.SetTextAsync(FilePath);
TopLevel.GetTopLevel(this).Clipboard.SetTextAsync(FilePath);
}

private void preprocess_Click(object sender, RoutedEventArgs e)
Expand Down
Loading

0 comments on commit 8b9f902

Please sign in to comment.