Merge branch 'main' into pr2

This commit is contained in:
Dong Bin
2025-01-16 22:15:10 +08:00
committed by GitHub
10 changed files with 554 additions and 3 deletions

View File

@@ -0,0 +1,114 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:u="https://irihi.tech/ursa"
xmlns:vm="using:Ursa.Demo.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Ursa.Demo.Pages.PathPickerDemo"
x:DataType="vm:PathPickerDemoViewModel">
<Grid ColumnDefinitions="*,*"
RowDefinitions="7*,3*">
<ScrollViewer Grid.Column="0" Grid.Row="0">
<StackPanel>
<HeaderedContentControl Theme="{DynamicResource GroupBox}"
Header="Functionality and Usage"
Content="PathPicker aggregates a file selector and provides a Command property. The Command is triggered solely after opening the file selector and selecting a file, whereupon the Command receives an IReadOnlyList&lt;string&gt; parameter.">
</HeaderedContentControl>
<u:Form LabelAlignment="Left" LabelPosition="Left" LabelWidth="*" HorizontalAlignment="Stretch">
<TextBox Name="Title" u:FormItem.Label="Title"></TextBox>
<TextBox Name="SuggestedFileName" u:FormItem.Label="SuggestedFileName"
Watermark="filename(not have file extension)">
</TextBox>
<TextBox Name="SuggestedStartPath" u:FormItem.Label="SuggestedStartPath"
Watermark="D:\Win7 Help\win-x64">
</TextBox>
<TextBox Name="FileFilter" u:FormItem.Label="FileFilter"
Watermark="[Name,Pattern] like this [123,*.exe,*.pdb] or [All][ImageAll][11,*.txt]">
</TextBox>
<TextBox Name="DefaultFileExtension" u:FormItem.Label="DefaultFileExtension"
Watermark="json">
</TextBox>
<ToggleButton Name="AllowMultiple" Content="AllowMultiple" u:FormItem.NoLabel="True"
HorizontalAlignment="Stretch">
</ToggleButton>
<ToggleButton Name="IsOmitCommandOnCancel" Content="Do not trigger the command after unselecting."
u:FormItem.NoLabel="True"
HorizontalAlignment="Stretch">
</ToggleButton>
<ToggleButton Name="IsClearSelectionOnCancel" Content="Clear the selection when unselecting."
u:FormItem.NoLabel="True"
HorizontalAlignment="Stretch">
</ToggleButton>
<u:EnumSelector Name="UsePickerType" EnumType="u:UsePickerTypes" u:FormItem.Label="UsePickerType"></u:EnumSelector>
</u:Form>
</StackPanel>
</ScrollViewer>
<ScrollViewer Grid.Column="0" Grid.Row="1">
<StackPanel Spacing="2">
<HeaderedContentControl Header="Default">
<u:PathPicker Title="{Binding #Title.Text}"
SuggestedFileName="{Binding #SuggestedFileName.Text}"
SuggestedStartPath="{Binding #SuggestedStartPath.Text}"
FileFilter="{Binding #FileFilter.Text}"
DefaultFileExtension="{Binding #DefaultFileExtension.Text}"
AllowMultiple="{Binding #AllowMultiple.IsChecked}"
UsePickerType="{Binding #UsePickerType.Value}"
SelectedPathsText="{Binding Path,Mode=OneWayToSource}"
SelectedPaths="{Binding Paths,Mode=OneWayToSource}"
Command="{Binding SelectedCommand}"
IsOmitCommandOnCancel="{Binding #IsOmitCommandOnCancel.IsChecked}"
IsClearSelectionOnCancel="{Binding #IsClearSelectionOnCancel.IsChecked}">
</u:PathPicker>
</HeaderedContentControl>
<HeaderedContentControl Header="PathPickerOnlyButton">
<u:PathPicker Theme="{DynamicResource PathPickerOnlyButton}"
Title="{Binding #Title.Text}"
SuggestedFileName="{Binding #SuggestedFileName.Text}"
SuggestedStartPath="{Binding #SuggestedStartPath.Text}"
FileFilter="{Binding #FileFilter.Text}"
DefaultFileExtension="{Binding #DefaultFileExtension.Text}"
AllowMultiple="{Binding #AllowMultiple.IsChecked}"
UsePickerType="{Binding #UsePickerType.Value}"
SelectedPathsText="{Binding Path,Mode=OneWayToSource}"
SelectedPaths="{Binding Paths,Mode=OneWayToSource}"
Command="{Binding SelectedCommand}"
IsOmitCommandOnCancel="{Binding #IsOmitCommandOnCancel.IsChecked}"
IsClearSelectionOnCancel="{Binding #IsClearSelectionOnCancel.IsChecked}">
</u:PathPicker>
</HeaderedContentControl>
<HeaderedContentControl Header="PathPickerForListView">
<u:PathPicker Theme="{DynamicResource PathPickerForListView}"
Title="{Binding #Title.Text}"
SuggestedFileName="{Binding #SuggestedFileName.Text}"
SuggestedStartPath="{Binding #SuggestedStartPath.Text}"
FileFilter="{Binding #FileFilter.Text}"
DefaultFileExtension="{Binding #DefaultFileExtension.Text}"
AllowMultiple="{Binding #AllowMultiple.IsChecked}"
UsePickerType="{Binding #UsePickerType.Value}"
SelectedPathsText="{Binding Path,Mode=OneWayToSource}"
SelectedPaths="{Binding Paths,Mode=OneWayToSource}"
Command="{Binding SelectedCommand}"
IsOmitCommandOnCancel="{Binding #IsOmitCommandOnCancel.IsChecked}"
IsClearSelectionOnCancel="{Binding #IsClearSelectionOnCancel.IsChecked}">
</u:PathPicker>
</HeaderedContentControl>
</StackPanel>
</ScrollViewer>
<ScrollViewer Grid.Column="1" Grid.Row="0" Grid.RowSpan="2">
<StackPanel Spacing="1">
<TextBlock Text="{Binding CommandTriggerCount,StringFormat='Command Trigger Count:{0}'}"></TextBlock>
<HeaderedContentControl Header="SelectedPathsText">
<TextBox Name="SelectedPath" u:FormItem.Label="SelectedPath" IsReadOnly="True"
Text="{Binding Path}">
</TextBox>
</HeaderedContentControl>
<HeaderedContentControl Header="SelectedPaths">
<ListBox Name="SelectedPaths"
ItemsSource="{Binding Paths}">
</ListBox>
</HeaderedContentControl>
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>

View File

@@ -0,0 +1,13 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Ursa.Demo.Pages;
public partial class PathPickerDemo : UserControl
{
public PathPickerDemo()
{
InitializeComponent();
}
}

View File

@@ -4,6 +4,7 @@ using Avalonia;
using Avalonia.Styling;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using Ursa.Controls;
using Ursa.Themes.Semi;
namespace Ursa.Demo.ViewModels;
@@ -79,6 +80,7 @@ public partial class MainViewViewModel : ViewModelBase
MenuKeys.MenuKeyTreeComboBox => new TreeComboBoxDemoViewModel(),
MenuKeys.MenuKeyTwoTonePathIcon => new TwoTonePathIconDemoViewModel(),
MenuKeys.AspectRatioLayout => new AspectRatioLayoutDemoViewModel(),
MenuKeys.PathPicker => new PathPickerDemoViewModel(),
_ => throw new ArgumentOutOfRangeException(nameof(s), s, null)
};
}

View File

@@ -59,7 +59,8 @@ public class MenuViewModel : ViewModelBase
new() { MenuHeader = "ToolBar", Key = MenuKeys.MenuKeyToolBar },
new() { MenuHeader = "TreeComboBox", Key = MenuKeys.MenuKeyTreeComboBox },
new() { MenuHeader = "TwoTonePathIcon", Key = MenuKeys.MenuKeyTwoTonePathIcon },
new() { MenuHeader = "AspectRatioLayout", Key = MenuKeys.AspectRatioLayout ,Status = "WIP"},
new() { MenuHeader = "AspectRatioLayout", Key = MenuKeys.AspectRatioLayout, Status = "New" },
new() { MenuHeader = "PathPicker", Key = MenuKeys.PathPicker, Status = "WIP" },
};
}
}
@@ -115,4 +116,5 @@ public static class MenuKeys
public const string MenuKeyTreeComboBox = "TreeComboBox";
public const string MenuKeyTwoTonePathIcon = "TwoTonePathIcon";
public const string AspectRatioLayout = "AspectRatioLayout";
public const string PathPicker = "PathPicker";
}

View File

@@ -0,0 +1,18 @@
using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace Ursa.Demo.ViewModels;
public partial class PathPickerDemoViewModel : ViewModelBase
{
[ObservableProperty] private string? _path;
[ObservableProperty] private IReadOnlyList<string>? _paths;
[ObservableProperty] private int _commandTriggerCount = 0;
[RelayCommand]
private void Selected(IReadOnlyList<string> paths)
{
CommandTriggerCount++;
}
}