I broke it

This commit is contained in:
Niels Laute
2025-12-04 21:01:39 +01:00
parent 42ed7f4cda
commit 3ecdb45eea
6 changed files with 122 additions and 91 deletions

View File

@@ -5,6 +5,7 @@
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.CmdPal.Core.ViewModels; using Microsoft.CmdPal.Core.ViewModels;
using Microsoft.CmdPal.UI.ViewModels.Settings; using Microsoft.CmdPal.UI.ViewModels.Settings;
@@ -84,6 +85,12 @@ public partial class DockBandSettingsViewModel : ObservableObject
set => ShowLabels = (ShowLabelsOption)value; set => ShowLabels = (ShowLabelsOption)value;
} }
[RelayCommand]
private void Unpin()
{
PinSideIndex = 0;
}
private DockPinSide PinSide private DockPinSide PinSide
{ {
get => _pinSide; get => _pinSide;

View File

@@ -3,6 +3,8 @@
x:Class="Microsoft.CmdPal.UI.Controls.DockEditor" x:Class="Microsoft.CmdPal.UI.Controls.DockEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dockVm="using:Microsoft.CmdPal.UI.ViewModels.Dock" xmlns:dockVm="using:Microsoft.CmdPal.UI.ViewModels.Dock"
xmlns:helpers="using:Microsoft.CmdPal.UI.Helpers" xmlns:helpers="using:Microsoft.CmdPal.UI.Helpers"
@@ -81,8 +83,7 @@
BorderThickness="1" BorderThickness="1"
CornerRadius="4" CornerRadius="4"
ToolTipService.ToolTip="{x:Bind Title}"> ToolTipService.ToolTip="{x:Bind Title}">
<Button Style="{StaticResource SubtleButtonStyle}"> <FlyoutBase.AttachedFlyout>
<Button.Flyout>
<Flyout Placement="Bottom"> <Flyout Placement="Bottom">
<Grid Width="280"> <Grid Width="280">
<Grid.RowDefinitions> <Grid.RowDefinitions>
@@ -133,10 +134,16 @@
Grid.Row="3" Grid.Row="3"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
Click="UnpinButton_Click" Click="UnpinButton_Click"
Command="{x:Bind UnpinCommand}"
Content="Unpin from dock" /> Content="Unpin from dock" />
</Grid> </Grid>
</Flyout> </Flyout>
</Button.Flyout> </FlyoutBase.AttachedFlyout>
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="Tapped">
<helpers:OpenFlyoutAction />
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
<local:IconBox <local:IconBox
Width="24" Width="24"
Height="24" Height="24"
@@ -144,7 +151,6 @@
VerticalAlignment="Center" VerticalAlignment="Center"
SourceKey="{x:Bind Icon, Mode=OneWay}" SourceKey="{x:Bind Icon, Mode=OneWay}"
SourceRequested="{x:Bind helpers:IconCacheProvider.SourceRequested}" /> SourceRequested="{x:Bind helpers:IconCacheProvider.SourceRequested}" />
</Button>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
@@ -296,7 +302,7 @@
DragItemsCompleted="ListView_DragItemsCompleted" DragItemsCompleted="ListView_DragItemsCompleted"
DragItemsStarting="ListView_DragItemsStarting" DragItemsStarting="ListView_DragItemsStarting"
DragOver="ListView_DragOver" DragOver="ListView_DragOver"
Drop="EndListView_Drop" Drop="StartListView_Drop"
IsItemClickEnabled="False" IsItemClickEnabled="False"
ItemContainerStyle="{StaticResource DockEditorListViewItemStyle}" ItemContainerStyle="{StaticResource DockEditorListViewItemStyle}"
ItemTemplate="{StaticResource DockBandItemTemplate}" ItemTemplate="{StaticResource DockBandItemTemplate}"

View File

@@ -18,7 +18,6 @@ public sealed partial class DockEditor : UserControl
private DockBandSettingsViewModel? _draggedItem; private DockBandSettingsViewModel? _draggedItem;
private ObservableCollection<DockBandSettingsViewModel>? _sourceCollection; private ObservableCollection<DockBandSettingsViewModel>? _sourceCollection;
private DockEditorPinArea _targetArea; private DockEditorPinArea _targetArea;
private DockBandSettingsViewModel? _currentContextItem;
public Orientation Orientation public Orientation Orientation
{ {
@@ -206,31 +205,19 @@ public sealed partial class DockEditor : UserControl
private void UnpinButton_Click(object sender, RoutedEventArgs e) private void UnpinButton_Click(object sender, RoutedEventArgs e)
{ {
if (_currentContextItem == null) if (sender is Button btn && btn.DataContext is DockBandSettingsViewModel contextItem)
{ {
return;
}
// Remove from all UI collections // Remove from all UI collections
StartItems.Remove(_currentContextItem); StartItems.Remove(contextItem);
CenterItems.Remove(_currentContextItem); CenterItems.Remove(contextItem);
EndItems.Remove(_currentContextItem); EndItems.Remove(contextItem);
// Set pin side to None
_currentContextItem.PinSideIndex = 0;
// Refresh available items // Refresh available items
RefreshAvailableItems(); RefreshAvailableItems();
_currentContextItem = null;
// Close the flyout // Close the flyout
CloseFlyoutFromSender(sender); CloseFlyoutFromSender(sender);
} }
private void DockItemOptionsFlyout_Closed(object sender, object e)
{
_currentContextItem = null;
} }
private void ListView_DragItemsStarting(object sender, DragItemsStartingEventArgs e) private void ListView_DragItemsStarting(object sender, DragItemsStartingEventArgs e)

View File

@@ -41,14 +41,12 @@
Style="{StaticResource TaskBarButtonStyle}" Style="{StaticResource TaskBarButtonStyle}"
Tapped="BandItem_Tapped" Tapped="BandItem_Tapped"
ToolTipService.ToolTip="{x:Bind Tooltip, Mode=OneWay}"> ToolTipService.ToolTip="{x:Bind Tooltip, Mode=OneWay}">
<Grid AutomationProperties.Name="{x:Bind Title, Mode=OneWay}" Background="Transparent"> <Grid AutomationProperties.Name="{x:Bind Title, Mode=OneWay}" Background="Transparent">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel <StackPanel
Grid.Column="0" Grid.Column="0"
VerticalAlignment="Center" VerticalAlignment="Center"

View File

@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.Xaml.Interactivity;
namespace Microsoft.CmdPal.UI.Helpers;
public class OpenFlyoutAction : DependencyObject, IAction
{
public object? Execute(object sender, object parameter)
{
FlyoutBase.ShowAttachedFlyout(TargetObject ?? (FrameworkElement)sender);
return null;
}
public Control TargetObject
{
get { return (Control)GetValue(TargetObjectProperty); }
set { SetValue(TargetObjectProperty, value); }
}
public static readonly DependencyProperty TargetObjectProperty =
DependencyProperty.Register(nameof(TargetObject), typeof(Control), typeof(OpenFlyoutAction), new PropertyMetadata(null));
}

View File

@@ -112,7 +112,7 @@
<!-- Bands Section --> <!-- Bands Section -->
<TextBlock x:Uid="DockBandsSettingsHeader" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" /> <TextBlock x:Uid="DockBandsSettingsHeader" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />
<Grid BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" BorderThickness="1"> <Grid BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" BorderThickness="1">
<cpControls:DockEditor Height="148" DockItems="{x:Bind AllDockBandItems, Mode=OneWay}" /> <cpControls:DockEditor Height="56" DockItems="{x:Bind AllDockBandItems, Mode=OneWay}" />
</Grid> </Grid>
<!--<ItemsRepeater ItemsSource="{x:Bind AllDockBandItems, Mode=OneWay}"> <!--<ItemsRepeater ItemsSource="{x:Bind AllDockBandItems, Mode=OneWay}">