-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
554 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<string> 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.