Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trimmability #302

Open
wants to merge 5 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
5 changes: 3 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors>nullable</WarningsAsErrors>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>9</LangVersion>
<LangVersion>11</LangVersion>
<!-- https://github.com/dotnet/msbuild/issues/2661 -->
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>
<MSBuildEnableWorkloadResolver>false</MSBuildEnableWorkloadResolver>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>
<PropertyGroup>
<AvaloniaVersion>11.0.0</AvaloniaVersion>
<AvaloniaSamplesVersion>11.1.3</AvaloniaSamplesVersion>
</PropertyGroup>
</Project>
7 changes: 4 additions & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"sdk": {
"version": "7.0.101",
"rollForward": "latestFeature"
"version": "8.0.0",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}
}
5 changes: 3 additions & 2 deletions samples/TreeDataGridDemo/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
xmlns:vm="using:TreeDataGridDemo.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="TreeDataGridDemo.MainWindow"
Title="TreeDataGridDemo">
Title="TreeDataGridDemo"
x:DataType="vm:MainWindowViewModel">
<TabControl Name="tabs">
<TabItem Header="Countries">
<DockPanel>
Expand Down Expand Up @@ -125,7 +126,7 @@
<TextBlock Classes="realized-count" DockPanel.Dock="Bottom"/>
<TreeDataGrid Name="wikipedia" Source="{Binding Wikipedia.Source}">
<TreeDataGrid.Resources>
<DataTemplate x:Key="WikipediaImageCell">
<DataTemplate x:Key="WikipediaImageCell" x:DataType="m:OnThisDayArticle">
<Image Source="{Binding Image}"/>
</DataTemplate>
</TreeDataGrid.Resources>
Expand Down
6 changes: 0 additions & 6 deletions samples/TreeDataGridDemo/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
this.AttachDevTools();
DataContext = new MainWindowViewModel();

_tabs = this.FindControl<TabControl>("tabs");
Expand Down Expand Up @@ -75,11 +74,6 @@ public void AddCountryClick(object sender, RoutedEventArgs e)
countries.TryGetRow(index)?.Focus();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}

private void MainWindow_Activated(object? sender, EventArgs e)
{
Program.Stopwatch!.Stop();
Expand Down
8 changes: 4 additions & 4 deletions samples/TreeDataGridDemo/Models/DragDropItem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using ReactiveUI;
using CommunityToolkit.Mvvm.ComponentModel;

namespace TreeDataGridDemo.Models
{
public class DragDropItem : ReactiveObject
public class DragDropItem : ObservableObject
{
private static Random _random = new Random(0);
private ObservableCollection<DragDropItem>? _children;
Expand All @@ -18,13 +18,13 @@ public class DragDropItem : ReactiveObject
public bool AllowDrag
{
get => _allowDrag;
set => this.RaiseAndSetIfChanged(ref _allowDrag, value);
set => SetProperty(ref _allowDrag, value);
}

public bool AllowDrop
{
get => _allowDrop;
set => this.RaiseAndSetIfChanged(ref _allowDrop, value);
set => SetProperty(ref _allowDrop, value);
}

public ObservableCollection<DragDropItem> Children => _children ??= CreateRandomItems();
Expand Down
16 changes: 8 additions & 8 deletions samples/TreeDataGridDemo/Models/FileTreeNodeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using System.ComponentModel;
using System.IO;
using Avalonia.Threading;
using ReactiveUI;
using CommunityToolkit.Mvvm.ComponentModel;

namespace TreeDataGridDemo.Models
{
public class FileTreeNodeModel : ReactiveObject, IEditableObject
public class FileTreeNodeModel : ObservableObject, IEditableObject
{
private string _path;
private string _name;
Expand Down Expand Up @@ -42,37 +42,37 @@ public FileTreeNodeModel(
public string Path
{
get => _path;
private set => this.RaiseAndSetIfChanged(ref _path, value);
private set => SetProperty(ref _path, value);
}

public string Name
{
get => _name;
private set => this.RaiseAndSetIfChanged(ref _name, value);
private set => SetProperty(ref _name, value);
}

public long? Size
{
get => _size;
private set => this.RaiseAndSetIfChanged(ref _size, value);
private set => SetProperty(ref _size, value);
}

public DateTimeOffset? Modified
{
get => _modified;
private set => this.RaiseAndSetIfChanged(ref _modified, value);
private set => SetProperty(ref _modified, value);
}

public bool HasChildren
{
get => _hasChildren;
private set => this.RaiseAndSetIfChanged(ref _hasChildren, value);
private set => SetProperty(ref _hasChildren, value);
}

public bool IsExpanded
{
get => _isExpanded;
set => this.RaiseAndSetIfChanged(ref _isExpanded, value);
set => SetProperty(ref _isExpanded, value);
}

public bool IsChecked { get; set; }
Expand Down
2 changes: 0 additions & 2 deletions samples/TreeDataGridDemo/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics;
using Avalonia;
using Avalonia.ReactiveUI;

namespace TreeDataGridDemo
{
Expand All @@ -21,7 +20,6 @@ public static void Main(string[] args)
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.UseReactiveUI()
.LogToTrace();
}
}
15 changes: 8 additions & 7 deletions samples/TreeDataGridDemo/TreeDataGridDemo.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>False</IsPackable>
<OutputType>WinExe</OutputType>
<PublishAot Condition="'$(Configuration)' == 'Release'">true</PublishAot>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**" />
Expand All @@ -12,12 +13,12 @@
<None Remove="Assets\folder.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia" Version="$(AvaloniaSamplesVersion)" />
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaSamplesVersion)" />
<PackageReference Include="Avalonia.Diagnostics" Version="$(AvaloniaSamplesVersion)" Condition="'$(Configuration)' != 'Release'" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaSamplesVersion)" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="$(AvaloniaSamplesVersion)" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Bogus" Version="34.0.2" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions samples/TreeDataGridDemo/ViewModels/CountriesPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
using Avalonia.Controls;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Selection;
using ReactiveUI;
using CommunityToolkit.Mvvm.ComponentModel;
using TreeDataGridDemo.Models;

namespace TreeDataGridDemo.ViewModels
{
internal class CountriesPageViewModel : ReactiveObject
internal class CountriesPageViewModel : ObservableObject
{
private readonly ObservableCollection<Country> _data;
private bool _cellSelection;
Expand Down Expand Up @@ -50,7 +50,7 @@ public bool CellSelection
Source.Selection = new TreeDataGridCellSelectionModel<Country>(Source) { SingleSelect = false };
else
Source.Selection = new TreeDataGridRowSelectionModel<Country>(Source) { SingleSelect = false };
this.RaisePropertyChanged();
OnPropertyChanged();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions samples/TreeDataGridDemo/ViewModels/DragDropPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Collections.ObjectModel;
using Avalonia.Controls;
using Avalonia.Controls.Models.TreeDataGrid;
using ReactiveUI;
using CommunityToolkit.Mvvm.ComponentModel;
using TreeDataGridDemo.Models;

namespace TreeDataGridDemo.ViewModels
{
internal class DragDropPageViewModel : ReactiveObject
internal class DragDropPageViewModel : ObservableObject
{
private ObservableCollection<DragDropItem> _data;

Expand Down
37 changes: 22 additions & 15 deletions samples/TreeDataGridDemo/ViewModels/FilesPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Runtime.InteropServices;
using Avalonia.Controls;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Selection;
using Avalonia.Data.Converters;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using ReactiveUI;
using CommunityToolkit.Mvvm.ComponentModel;
using TreeDataGridDemo.Models;

namespace TreeDataGridDemo.ViewModels
{
public class FilesPageViewModel : ReactiveObject
public class FilesPageViewModel : ObservableObject
{
private static IconConverter? s_iconConverter;
private readonly HierarchicalTreeDataGridSource<FileTreeNodeModel>? _treeSource;
Expand All @@ -42,16 +41,24 @@ public FilesPageViewModel()

_source = _treeSource = CreateTreeSource();

this.WhenAnyValue(x => x.SelectedDrive)
.Subscribe(x =>
UpdateRoot();
PropertyChanged += (sender, args) =>
{
if (args.PropertyName == nameof(SelectedDrive))
{
_root = new FileTreeNodeModel(_selectedDrive, isDirectory: true, isRoot: true);
UpdateRoot();
}
};

if (_treeSource is not null)
_treeSource.Items = new[] { _root };
else if (_flatSource is not null)
_flatSource.Items = _root.Children;
});
void UpdateRoot()
{
_root = new FileTreeNodeModel(SelectedDrive, isDirectory: true, isRoot: true);

if (_treeSource is not null)
_treeSource.Items = new[] { _root };
else if (_flatSource is not null)
_flatSource.Items = _root.Children;
}
}

public bool CellSelection
Expand All @@ -66,7 +73,7 @@ public bool CellSelection
Source.Selection = new TreeDataGridCellSelectionModel<FileTreeNodeModel>(Source) { SingleSelect = false };
else
Source.Selection = new TreeDataGridRowSelectionModel<FileTreeNodeModel>(Source) { SingleSelect = false };
this.RaisePropertyChanged();
OnPropertyChanged();
}
}
}
Expand All @@ -86,7 +93,7 @@ public bool FlatList
public string SelectedDrive
{
get => _selectedDrive;
set => this.RaiseAndSetIfChanged(ref _selectedDrive, value);
set => SetProperty(ref _selectedDrive, value);
}

public string? SelectedPath
Expand All @@ -98,7 +105,7 @@ public string? SelectedPath
public ITreeDataGridSource<FileTreeNodeModel> Source
{
get => _source;
private set => this.RaiseAndSetIfChanged(ref _source, value);
private set => SetProperty(ref _source, value);
}

public static IMultiValueConverter FileIconConverter
Expand Down Expand Up @@ -292,7 +299,7 @@ private ITreeDataGridRowSelectionModel<FileTreeNodeModel> GetRowSelection(ITreeD
private void SelectionChanged(object? sender, TreeSelectionModelSelectionChangedEventArgs<FileTreeNodeModel> e)
{
var selectedPath = GetRowSelection(Source).SelectedItem?.Path;
this.RaiseAndSetIfChanged(ref _selectedPath, selectedPath, nameof(SelectedPath));
SetProperty(ref _selectedPath, selectedPath, nameof(SelectedPath));

foreach (var i in e.DeselectedItems)
System.Diagnostics.Trace.WriteLine($"Deselected '{i?.Path}'");
Expand Down
15 changes: 10 additions & 5 deletions samples/TreeDataGridDemo/ViewModels/WikipediaPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Avalonia.Collections;
using Avalonia.Controls;
Expand All @@ -11,7 +12,7 @@

namespace TreeDataGridDemo.ViewModels
{
internal class WikipediaPageViewModel
internal partial class WikipediaPageViewModel
{
private readonly AvaloniaList<OnThisDayArticle> _data = new();

Expand Down Expand Up @@ -47,15 +48,19 @@ private async Task LoadContent()
var m = DateTimeOffset.Now.Month;
var uri = $"https://api.wikimedia.org/feed/v1/wikipedia/en/onthisday/all/{m}/{d}";
var s = await client.GetStringAsync(uri);
var data = JsonSerializer.Deserialize<OnThisDay>(s, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
});
var data = (OnThisDay)JsonSerializer.Deserialize(s, typeof(OnThisDay), SerializationContext.Default)!;

if (data?.Selected is not null)
_data.AddRange(data.Selected.SelectMany(x => x.Pages!));
}
catch { }
}

[JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true)]
[JsonSerializable(typeof(OnThisDay))]
internal partial class SerializationContext : JsonSerializerContext
{

}
}
}
Loading
Loading