Skip to content

Commit

Permalink
Merge branch 'main' into pr2
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitism authored Jan 16, 2025
2 parents 87060da + 8651ae3 commit 67abe93
Show file tree
Hide file tree
Showing 10 changed files with 554 additions and 3 deletions.
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
83 changes: 83 additions & 0 deletions src/Ursa.Themes.Semi/Controls/PathPicker.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ursa="https://irihi.tech/ursa">
<ControlTheme x:Key="{x:Type ursa:PathPicker}" TargetType="ursa:PathPicker">
<Setter Property="Template">
<ControlTemplate>
<DockPanel HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Button Name="PART_Button"
DockPanel.Dock="Right"
Content="{TemplateBinding Title}"
Margin="1,0,0,0">
</Button>
<TextBox Name="PART_TextBox"
DockPanel.Dock="Left"
AcceptsReturn="{TemplateBinding AllowMultiple}"
Text="{TemplateBinding SelectedPathsText,Mode=TwoWay}">
</TextBox>
</DockPanel>
</ControlTemplate>
</Setter>

<Style Selector="^[AllowMultiple=False]">
<Style Selector="^ /template/ Button#PART_Button">
<Setter Property="DockPanel.Dock" Value="Right"></Setter>
</Style>
<Style Selector="^ /template/ TextBox#PART_TextBox">
<Setter Property="DockPanel.Dock" Value="Left"></Setter>
</Style>
</Style>
<Style Selector="^[AllowMultiple=True]">
<Style Selector="^ /template/ Button#PART_Button">
<Setter Property="DockPanel.Dock" Value="Top"></Setter>
</Style>
<Style Selector="^ /template/ TextBox#PART_TextBox">
<Setter Property="DockPanel.Dock" Value="Bottom"></Setter>
</Style>
</Style>
</ControlTheme>


<ControlTheme x:Key="PathPickerOnlyButton" TargetType="ursa:PathPicker">
<Setter Property="Template">
<ControlTemplate>
<Button Name="PART_Button"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
Content="{TemplateBinding Title}">
</Button>
</ControlTemplate>
</Setter>
</ControlTheme>

<ControlTheme x:Key="PathPickerForListView" TargetType="ursa:PathPicker">
<Setter Property="Template">
<ControlTemplate>
<Expander HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Expander.Header>
<Button Name="PART_Button"
HorizontalAlignment="Stretch"
Content="{TemplateBinding Title}">
<Button.Theme>
<ControlTheme TargetType="Button">
<Setter Property="Template">
<ControlTemplate>
<TextPresenter Text="{TemplateBinding Content}"
Background="Transparent"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
</TextPresenter>
</ControlTemplate>
</Setter>
</ControlTheme>
</Button.Theme>
</Button>
</Expander.Header>
<ListBox ItemsSource="{TemplateBinding SelectedPaths}"></ListBox>
</Expander>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>
1 change: 1 addition & 0 deletions src/Ursa.Themes.Semi/Controls/_index.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@
<ResourceInclude Source="UrsaView.axaml" />
<ResourceInclude Source="UrsaWindow.axaml"/>
<ResourceInclude Source="PinCode.axaml" />
<ResourceInclude Source="PathPicker.axaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Loading

0 comments on commit 67abe93

Please sign in to comment.