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

Feat: add a new control PathPicker, add PathPickerDemo #533

Merged
merged 6 commits into from
Jan 15, 2025
Merged
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
87 changes: 72 additions & 15 deletions demo/Sandbox/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,84 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Sandbox.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
xmlns:sys="using:System"
Icon="/Assets/avalonia-logo.ico"
Title="Sandbox">

<Design.DataContext>
<!-- This only sets the DataContext for the previewer in an IDE,
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:MainWindowViewModel/>
<vm:MainWindowViewModel />
</Design.DataContext>

<Grid>
<u:Form>
<u:FormItem Label="_Numeric">
<u:NumericIntUpDown/>
</u:FormItem>
<u:FormItem Label="_AnotherNumeric">
<u:NumericIntUpDown/>
</u:FormItem>
<u:FormItem Label="_TextBox">
<TextBox/>
</u:FormItem>
</u:Form>
</Grid>

</Window>
<Grid ColumnDefinitions="*,*"
RowDefinitions="7*,3*">
<ScrollViewer Grid.Column="0" Grid.Row="0">
<u:Form LabelAlignment="Left" LabelPosition="Left" LabelWidth="*" HorizontalAlignment="Stretch">
<TextBox Name="Title" u:FormItem.Label="Title"></TextBox>
<TextBox Name="SuggestedFileName" u:FormItem.Label="SuggestedFileName"></TextBox>
<TextBox Name="SuggestedStartPath" u:FormItem.Label="SuggestedStartPath"></TextBox>
<TextBox Name="FileFilter" u:FormItem.Label="FileFilter"></TextBox>
<TextBox Name="DefaultFileExtension" u:FormItem.Label="DefaultFileExtension"></TextBox>
<ToggleButton Name="AllowMultiple" Content="AllowMultiple" u:FormItem.NoLabel="True"
HorizontalAlignment="Stretch">
</ToggleButton>
<u:EnumSelector Name="UsePickerType" EnumType="u:UsePickerTypes" u:FormItem.Label="UsePickerType"></u:EnumSelector>
</u:Form>
</ScrollViewer>
<ScrollViewer Grid.Column="0" Grid.Row="1">
<StackPanel Spacing="2">
<HeaderedContentControl Header="Default">
<u:PathPicker Name="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}">
</u:PathPicker>
</HeaderedContentControl>
<HeaderedContentControl Header="PathPickerOnlyButton">
<u:PathPicker Name="PathPicker1"
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}">
</u:PathPicker>
</HeaderedContentControl>
<HeaderedContentControl Header="PathPickerForList">
<u:PathPicker Name="PathPicker2"
Theme="{DynamicResource PathPickerForList}"
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}">
</u:PathPicker>
</HeaderedContentControl>
</StackPanel>
</ScrollViewer>
<ScrollViewer Grid.Column="1" Grid.Row="0" Grid.RowSpan="2">
<StackPanel Spacing="1">
<HeaderedContentControl Header="SelectedPath">
<TextBox Name="SelectedPath" u:FormItem.Label="SelectedPath" IsReadOnly="True"
Text="{Binding #PathPicker.SelectedPath}">
</TextBox>
</HeaderedContentControl>
<HeaderedContentControl Header="SelectedPaths">
<ListBox Name="SelectedPaths"
ItemsSource="{Binding #PathPicker.SelectedPaths}">
</ListBox>
</HeaderedContentControl>
</StackPanel>
</ScrollViewer>
</Grid>
</Window>
114 changes: 114 additions & 0 deletions demo/Ursa.Demo/Pages/PathPickerDemo.axaml
Original file line number Diff line number Diff line change
@@ -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>
13 changes: 13 additions & 0 deletions demo/Ursa.Demo/Pages/PathPickerDemo.axaml.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
2 changes: 2 additions & 0 deletions demo/Ursa.Demo/ViewModels/MainViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Avalonia.Styling;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using Ursa.Controls;
using Ursa.Themes.Semi;

namespace Ursa.Demo.ViewModels;
Expand Down Expand Up @@ -79,6 +80,7 @@ private void OnNavigation(MainViewViewModel vm, string s)
MenuKeys.MenuKeyTreeComboBox => new TreeComboBoxDemoViewModel(),
MenuKeys.MenuKeyTwoTonePathIcon => new TwoTonePathIconDemoViewModel(),
MenuKeys.AspectRatioLayout => new AspectRatioLayoutDemoViewModel(),
MenuKeys.PathPicker => new PathPickerDemoViewModel(),
_ => throw new ArgumentOutOfRangeException(nameof(s), s, null)
};
}
Expand Down
4 changes: 3 additions & 1 deletion demo/Ursa.Demo/ViewModels/MenuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public MenuViewModel()
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" },
};
}
}
Expand Down Expand Up @@ -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";
}
18 changes: 18 additions & 0 deletions demo/Ursa.Demo/ViewModels/PathPickerDemoViewModel.cs
Original file line number Diff line number Diff line change
@@ -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++;
}
}
4 changes: 2 additions & 2 deletions src/Ursa.ReactiveUIExtension/Ursa.ReactiveUIExtension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

这个是一个Ursa拓展包。这个包整合并互相兼容了UrsaWindow和UrsaView与Avalonia.ReactiveUI的功能。【Avalonia.ReactiveUI参见:https://docs.avaloniaui.net/docs/concepts/reactiveui/】
</Description>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<RepositoryUrl>https://github.com/irihitech/Ursa.Avalonia</RepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.1"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)"/>
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading