mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
_targets #40504_ Major refactoring for #40113 This moves a large swath of the codebase to a `.Core` project. "Core" doesn't have any explicit dependencies on "extensions", settings or the current `MainListPage`. It's just a filterable list of stuff. This should let us make this component a bit more reusable. This is half of a PR. As I did this, I noticed a particular bit of code for TopLevelVViewModels and CommandPaletteHost that was _very rough_. Solving it in this PR would make "move everything to a new project" much harder to review. So I'm submitting two PRs simultaneously, so we can see the changes separately, then merge together.
212 lines
9.9 KiB
XML
212 lines
9.9 KiB
XML
<?xml version="1.0" encoding="utf-8" ?>
|
|
<UserControl
|
|
x:Class="Microsoft.CmdPal.UI.Controls.CommandBar"
|
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
xmlns:animations="using:CommunityToolkit.WinUI.Animations"
|
|
xmlns:cmdpalUI="using:Microsoft.CmdPal.UI"
|
|
xmlns:converters="using:CommunityToolkit.WinUI.Converters"
|
|
xmlns:coreViewModels="using:Microsoft.CmdPal.Core.ViewModels"
|
|
xmlns:cpcontrols="using:Microsoft.CmdPal.UI.Controls"
|
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
xmlns:help="using:Microsoft.CmdPal.UI.Helpers"
|
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
xmlns:ui="using:CommunityToolkit.WinUI"
|
|
xmlns:viewModels="using:Microsoft.CmdPal.UI.ViewModels"
|
|
Background="Transparent"
|
|
mc:Ignorable="d">
|
|
|
|
<UserControl.Resources>
|
|
<ResourceDictionary>
|
|
<converters:StringVisibilityConverter
|
|
x:Key="StringNotEmptyToVisibilityConverter"
|
|
EmptyValue="Collapsed"
|
|
NotEmptyValue="Visible" />
|
|
<converters:BoolToVisibilityConverter
|
|
x:Key="BoolToInvertedVisibilityConverter"
|
|
FalseValue="Visible"
|
|
TrueValue="Collapsed" />
|
|
|
|
<cmdpalUI:MessageStateToSeverityConverter x:Key="MessageStateToSeverityConverter" />
|
|
|
|
<StackLayout
|
|
x:Name="VerticalStackLayout"
|
|
Orientation="Vertical"
|
|
Spacing="4" />
|
|
|
|
<Style
|
|
x:Name="ContextMenuFlyoutStyle"
|
|
BasedOn="{StaticResource DefaultFlyoutPresenterStyle}"
|
|
TargetType="FlyoutPresenter">
|
|
<Style.Setters>
|
|
<Setter Property="Margin" Value="0" />
|
|
<Setter Property="Padding" Value="0" />
|
|
</Style.Setters>
|
|
</Style>
|
|
|
|
<Flyout
|
|
x:Name="ContextMenuFlyout"
|
|
FlyoutPresenterStyle="{StaticResource ContextMenuFlyoutStyle}"
|
|
Opened="ContextMenuFlyout_Opened">
|
|
<cpcontrols:ContextMenu x:Name="ContextControl" />
|
|
</Flyout>
|
|
|
|
<Style x:Key="HotkeyStyle" TargetType="Border">
|
|
<Style.Setters>
|
|
<Setter Property="Padding" Value="4" />
|
|
<Setter Property="VerticalAlignment" Value="Center" />
|
|
<Setter Property="Background" Value="{ThemeResource ControlFillColorSecondaryBrush}" />
|
|
<Setter Property="BorderBrush" Value="{ThemeResource DividerStrokeColorDefaultBrush}" />
|
|
<Setter Property="BorderThickness" Value="1" />
|
|
<Setter Property="CornerRadius" Value="6" />
|
|
</Style.Setters>
|
|
</Style>
|
|
</ResourceDictionary>
|
|
</UserControl.Resources>
|
|
|
|
<Grid
|
|
MinHeight="40"
|
|
Padding="4"
|
|
ColumnSpacing="8">
|
|
<Grid.ColumnDefinitions>
|
|
<ColumnDefinition Width="Auto" />
|
|
<ColumnDefinition Width="*" />
|
|
<ColumnDefinition Width="Auto" />
|
|
</Grid.ColumnDefinitions>
|
|
|
|
<Grid
|
|
x:Name="IconRoot"
|
|
Margin="8,0,0,0"
|
|
Tapped="PageIcon_Tapped"
|
|
Visibility="{x:Bind CurrentPageViewModel.IsNested, Mode=OneWay}">
|
|
<InfoBadge Visibility="{x:Bind CurrentPageViewModel.HasStatusMessage, Mode=OneWay}" Value="{x:Bind CurrentPageViewModel.StatusMessages.Count, Mode=OneWay}" />
|
|
<Grid.ContextFlyout>
|
|
<Flyout x:Name="StatusMessagesFlyout" Placement="TopEdgeAlignedLeft">
|
|
<ItemsRepeater
|
|
x:Name="MessagesDropdown"
|
|
Margin="-8"
|
|
ItemsSource="{x:Bind CurrentPageViewModel.StatusMessages, Mode=OneWay}"
|
|
Layout="{StaticResource VerticalStackLayout}">
|
|
<ItemsRepeater.ItemTemplate>
|
|
<DataTemplate x:DataType="coreViewModels:StatusMessageViewModel">
|
|
<StackPanel
|
|
Grid.Row="0"
|
|
Margin="0"
|
|
HorizontalAlignment="Stretch"
|
|
VerticalAlignment="Bottom"
|
|
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
|
|
CornerRadius="0">
|
|
<InfoBar
|
|
CornerRadius="{ThemeResource ControlCornerRadius}"
|
|
IsClosable="False"
|
|
IsOpen="True"
|
|
Message="{x:Bind Message, Mode=OneWay}"
|
|
Severity="{x:Bind State, Mode=OneWay, Converter={StaticResource MessageStateToSeverityConverter}}" />
|
|
</StackPanel>
|
|
</DataTemplate>
|
|
</ItemsRepeater.ItemTemplate>
|
|
</ItemsRepeater>
|
|
</Flyout>
|
|
</Grid.ContextFlyout>
|
|
</Grid>
|
|
<Button
|
|
x:Name="SettingsIconButton"
|
|
x:Uid="SettingsButton"
|
|
Style="{StaticResource SubtleButtonStyle}"
|
|
Tapped="SettingsIcon_Tapped"
|
|
Visibility="{x:Bind CurrentPageViewModel.IsNested, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}">
|
|
<StackPanel Orientation="Horizontal" Spacing="8">
|
|
<FontIcon
|
|
VerticalAlignment="Center"
|
|
FontSize="16"
|
|
Glyph="" />
|
|
<TextBlock
|
|
VerticalAlignment="Center"
|
|
Style="{StaticResource CaptionTextBlockStyle}"
|
|
Text="Settings" />
|
|
</StackPanel>
|
|
</Button>
|
|
<TextBlock
|
|
Grid.Column="1"
|
|
VerticalAlignment="Center"
|
|
Style="{StaticResource CaptionTextBlockStyle}"
|
|
Text="{x:Bind CurrentPageViewModel.Title, Mode=OneWay}"
|
|
TextTrimming="CharacterEllipsis"
|
|
TextWrapping="NoWrap"
|
|
Visibility="{x:Bind CurrentPageViewModel.IsNested, Mode=OneWay}" />
|
|
<StackPanel
|
|
Grid.Column="2"
|
|
Padding="0,0,4,0"
|
|
HorizontalAlignment="Right"
|
|
Orientation="Horizontal"
|
|
Spacing="4">
|
|
<Button
|
|
x:Name="PrimaryButton"
|
|
Padding="6,4,4,4"
|
|
x:Load="{x:Bind IsLoaded, Mode=OneWay}"
|
|
AutomationProperties.Name="{x:Bind ViewModel.PrimaryCommand.Name, Mode=OneWay}"
|
|
Background="Transparent"
|
|
Style="{StaticResource SubtleButtonStyle}"
|
|
Tapped="PrimaryButton_Tapped"
|
|
Visibility="{x:Bind ViewModel.HasPrimaryCommand, Mode=OneWay}">
|
|
<StackPanel Orientation="Horizontal" Spacing="8">
|
|
<TextBlock
|
|
VerticalAlignment="Center"
|
|
Style="{StaticResource CaptionTextBlockStyle}"
|
|
Text="{x:Bind ViewModel.PrimaryCommand.Name, Mode=OneWay}" />
|
|
<Border Style="{StaticResource HotkeyStyle}">
|
|
<FontIcon
|
|
HorizontalAlignment="Left"
|
|
VerticalAlignment="Center"
|
|
FontSize="10"
|
|
Foreground="{ThemeResource TextFillColorPrimaryBrush}"
|
|
Glyph="" />
|
|
</Border>
|
|
</StackPanel>
|
|
</Button>
|
|
<Button
|
|
x:Name="SecondaryButton"
|
|
Padding="6,4,4,4"
|
|
x:Load="{x:Bind IsLoaded, Mode=OneWay}"
|
|
AutomationProperties.Name="{x:Bind ViewModel.SecondaryCommand.Name, Mode=OneWay}"
|
|
Style="{StaticResource SubtleButtonStyle}"
|
|
Tapped="SecondaryButton_Tapped"
|
|
Visibility="{x:Bind ViewModel.HasSecondaryCommand, Mode=OneWay}">
|
|
<StackPanel Orientation="Horizontal" Spacing="8">
|
|
<TextBlock
|
|
VerticalAlignment="Center"
|
|
Style="{StaticResource CaptionTextBlockStyle}"
|
|
Text="{x:Bind ViewModel.SecondaryCommand.Name, Mode=OneWay}" />
|
|
<StackPanel Orientation="Horizontal" Spacing="4">
|
|
<Border Padding="4,2,4,2" Style="{StaticResource HotkeyStyle}">
|
|
<TextBlock
|
|
CharacterSpacing="4"
|
|
FontSize="10"
|
|
Foreground="{ThemeResource TextFillColorPrimaryBrush}"
|
|
Text="Ctrl" />
|
|
</Border>
|
|
<Border Style="{StaticResource HotkeyStyle}">
|
|
<FontIcon
|
|
HorizontalAlignment="Left"
|
|
VerticalAlignment="Center"
|
|
FontSize="10"
|
|
Foreground="{ThemeResource TextFillColorPrimaryBrush}"
|
|
Glyph="" />
|
|
</Border>
|
|
</StackPanel>
|
|
</StackPanel>
|
|
</Button>
|
|
<Button
|
|
x:Name="MoreCommandsButton"
|
|
x:Uid="MoreCommandsButton"
|
|
Padding="4"
|
|
Content="{ui:FontIcon Glyph=,
|
|
FontSize=16}"
|
|
Style="{StaticResource SubtleButtonStyle}"
|
|
Tapped="MoreCommandsButton_Tapped"
|
|
ToolTipService.ToolTip="Ctrl+K"
|
|
Visibility="{x:Bind ViewModel.ShouldShowContextMenu, Mode=OneWay}" />
|
|
</StackPanel>
|
|
</Grid>
|
|
</UserControl>
|