Skip to content

Commit 4673c1c

Browse files
Copilotniels9001
andcommitted
Convert TextBlock filename to DropDownButton with copy path menu
Co-authored-by: niels9001 <[email protected]>
1 parent 4bfaa04 commit 4673c1c

File tree

3 files changed

+78
-57
lines changed

3 files changed

+78
-57
lines changed

src/modules/peek/Peek.UI/PeekXAML/Views/TitleBar.xaml

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<ColumnDefinition x:Name="SystemLeftPaddingColumn" Width="0" />
1515
<ColumnDefinition x:Name="DraggableColumn" Width="*" />
1616
<ColumnDefinition x:Name="LaunchAppButtonColumn" Width="Auto" />
17-
<ColumnDefinition x:Name="CopyPathButtonColumn" Width="Auto" />
1817
<ColumnDefinition x:Name="AppRightPaddingColumn" Width="8" />
1918
<ColumnDefinition x:Name="PinButtonColumn" Width="Auto" />
2019
<ColumnDefinition x:Name="SystemRightPaddingColumn" Width="180" />
@@ -56,12 +55,38 @@
5655
Text="{x:Bind FileCountText, Mode=OneWay}"
5756
Visibility="{x:Bind IsMultiSelection, Mode=OneWay}" />
5857

59-
<TextBlock
58+
<DropDownButton
6059
x:Name="AppTitle_FileName"
6160
Grid.Column="1"
62-
Style="{StaticResource CaptionTextBlockStyle}"
63-
Text="{x:Bind FileName, Mode=OneWay}"
64-
TextWrapping="NoWrap" />
61+
HorizontalAlignment="Left"
62+
VerticalAlignment="Center"
63+
AutomationProperties.AutomationId="AppTitle_FileName"
64+
Background="Transparent"
65+
BorderThickness="0"
66+
Content="{x:Bind FileName, Mode=OneWay}"
67+
Style="{StaticResource SubtleButtonStyle}">
68+
<DropDownButton.Flyout>
69+
<MenuFlyout>
70+
<MenuFlyoutItem
71+
x:Name="CopyPathMenuItem"
72+
AutomationProperties.AutomationId="CopyPathMenuItem"
73+
Command="{x:Bind CopyPathButtonCommand, Mode=OneWay}"
74+
Text="{x:Bind CopyPathButtonText, Mode=OneWay}">
75+
<MenuFlyoutItem.Icon>
76+
<FontIcon Glyph="&#xE8C8;" />
77+
</MenuFlyoutItem.Icon>
78+
</MenuFlyoutItem>
79+
</MenuFlyout>
80+
</DropDownButton.Flyout>
81+
<DropDownButton.ContentTemplate>
82+
<DataTemplate>
83+
<TextBlock
84+
Style="{StaticResource CaptionTextBlockStyle}"
85+
Text="{Binding}"
86+
TextWrapping="NoWrap" />
87+
</DataTemplate>
88+
</DropDownButton.ContentTemplate>
89+
</DropDownButton>
6590
</Grid>
6691
</Grid>
6792

@@ -89,32 +114,9 @@
89114
</Button.KeyboardAccelerators>
90115
</Button>
91116

92-
<Button
93-
x:Name="CopyPathButton"
94-
Grid.Column="3"
95-
VerticalAlignment="Center"
96-
AutomationProperties.AutomationId="CopyPathButton"
97-
Command="{x:Bind CopyPathButtonCommand, Mode=OneWay}"
98-
Style="{StaticResource SubtleButtonStyle}"
99-
ToolTipService.ToolTip="{x:Bind CopyPathButtonToolTip, Mode=OneWay}">
100-
<Button.Content>
101-
<StackPanel Orientation="Horizontal" Spacing="4">
102-
<FontIcon
103-
x:Name="CopyPathButton_Icon"
104-
FontSize="16"
105-
Glyph="&#xE8C8;" />
106-
<TextBlock
107-
x:Name="CopyPathButton_Text"
108-
AutomationProperties.AutomationId="CopyPathButton_Text"
109-
Style="{StaticResource CaptionTextBlockStyle}"
110-
Text="{x:Bind CopyPathButtonText, Mode=OneWay}" />
111-
</StackPanel>
112-
</Button.Content>
113-
</Button>
114-
115117
<Button
116118
x:Name="PinButton"
117-
Grid.Column="5"
119+
Grid.Column="4"
118120
VerticalAlignment="Center"
119121
Command="{x:Bind PinCommand, Mode=OneWay}"
120122
Style="{StaticResource SubtleButtonStyle}"
@@ -135,7 +137,6 @@
135137
</VisualState.StateTriggers>
136138
<VisualState.Setters>
137139
<Setter Target="LaunchAppButton_Text.Visibility" Value="Visible" />
138-
<Setter Target="CopyPathButton_Text.Visibility" Value="Visible" />
139140
</VisualState.Setters>
140141
</VisualState>
141142
<VisualState x:Name="MediumLayout">
@@ -144,7 +145,6 @@
144145
</VisualState.StateTriggers>
145146
<VisualState.Setters>
146147
<Setter Target="LaunchAppButton_Text.Visibility" Value="Collapsed" />
147-
<Setter Target="CopyPathButton_Text.Visibility" Value="Collapsed" />
148148
</VisualState.Setters>
149149
</VisualState>
150150
<VisualState x:Name="MinimumLayout">
@@ -154,8 +154,6 @@
154154
<VisualState.Setters>
155155
<Setter Target="LaunchAppButton_Text.Visibility" Value="Collapsed" />
156156
<Setter Target="LaunchAppButton.Visibility" Value="Collapsed" />
157-
<Setter Target="CopyPathButton_Text.Visibility" Value="Collapsed" />
158-
<Setter Target="CopyPathButton.Visibility" Value="Collapsed" />
159157
</VisualState.Setters>
160158
</VisualState>
161159
</VisualStateGroup>

src/modules/peek/Peek.UI/PeekXAML/Views/TitleBar.xaml.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ public sealed partial class TitleBar : UserControl
7878
[ObservableProperty]
7979
private string copyPathButtonText = ResourceLoaderInstance.ResourceLoader.GetString("CopyPathButton_Text");
8080

81-
[ObservableProperty]
82-
private string copyPathButtonToolTip = ResourceLoaderInstance.ResourceLoader.GetString("CopyPathButton_ToolTip");
83-
8481
public TitleBar()
8582
{
8683
InitializeComponent();
@@ -232,7 +229,7 @@ private void UpdateDragRegion()
232229
dragRectangleLeft.Width = (int)(DraggableColumn.ActualWidth * scale);
233230
dragRectangleLeft.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
234231

235-
dragRectangleRight.X = (int)((SystemLeftPaddingColumn.ActualWidth + DraggableColumn.ActualWidth + LaunchAppButtonColumn.ActualWidth + CopyPathButtonColumn.ActualWidth) * scale);
232+
dragRectangleRight.X = (int)((SystemLeftPaddingColumn.ActualWidth + DraggableColumn.ActualWidth + LaunchAppButtonColumn.ActualWidth) * scale);
236233
dragRectangleRight.Y = 0;
237234
dragRectangleRight.Width = (int)(AppRightPaddingColumn.ActualWidth * scale);
238235
dragRectangleRight.Height = (int)(TitleBarRootContainer.ActualHeight * scale);

src/modules/peek/Peek.UITests/PeekFilePreviewTests.cs

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -333,29 +333,39 @@ public void TestOpenWithDefaultProgramByButton()
333333
}
334334

335335
/// <summary>
336-
/// Test copying file path to clipboard by clicking the copy path button
336+
/// Test copying file path to clipboard by clicking the copy path menu item from filename dropdown
337337
/// </summary>
338-
[TestMethod("Peek.CopyPath.ClickButton")]
338+
[TestMethod("Peek.CopyPath.ClickMenuItem")]
339339
[TestCategory("Copy Path")]
340-
public void TestCopyPathByButton()
340+
public void TestCopyPathByMenuItem()
341341
{
342342
string zipPath = Path.GetFullPath(@".\TestAssets\7.zip");
343343

344344
// Open zip file with Peek
345345
var peekWindow = OpenPeekWindow(zipPath);
346346

347-
// Find and click the "Copy path" button
348-
var copyPathButton = FindCopyPathButton();
349-
Assert.IsNotNull(copyPathButton, "Copy path button should be found");
347+
// Find the filename dropdown button
348+
var filenameDropdown = FindFilenameDropdown();
349+
Assert.IsNotNull(filenameDropdown, "Filename dropdown button should be found");
350350

351-
// Click the button to copy path to clipboard
352-
copyPathButton.Click();
351+
// Click the dropdown to open the menu
352+
filenameDropdown.Click();
353+
354+
// Wait a moment for the menu to appear
355+
Thread.Sleep(500);
356+
357+
// Find and click the "Copy path" menu item
358+
var copyPathMenuItem = FindCopyPathMenuItem();
359+
Assert.IsNotNull(copyPathMenuItem, "Copy path menu item should be found");
360+
361+
// Click the menu item to copy path to clipboard
362+
copyPathMenuItem.Click();
353363

354364
// Wait a moment for the clipboard operation to complete
355365
Thread.Sleep(500);
356366

357367
// Note: We can't directly test clipboard contents in UI tests due to security restrictions
358-
// The test verifies that the button exists and can be clicked without exceptions
368+
// The test verifies that the menu item exists and can be clicked without exceptions
359369
// The actual clipboard functionality is tested through the underlying ClipboardHelper
360370

361371
ClosePeekAndExplorer();
@@ -893,29 +903,45 @@ private Element FindPeekWindow(string filePath, int timeout = 5000)
893903
}
894904

895905
/// <summary>
896-
/// Helper method to find the copy path button with different AccessibilityIds depending on window size
906+
/// Helper method to find the filename dropdown button
897907
/// </summary>
898-
/// <returns>The copy path button element</returns>
899-
private Element? FindCopyPathButton()
908+
/// <returns>The filename dropdown button element</returns>
909+
private Element? FindFilenameDropdown()
900910
{
901911
try
902912
{
903-
// Try to find button with ID for larger window first
904-
var button = Find(By.AccessibilityId("CopyPathButton_Text"), 1000);
905-
if (button != null)
913+
var dropdown = Find(By.AccessibilityId("AppTitle_FileName"), 1000);
914+
if (dropdown != null)
906915
{
907-
return button;
916+
return dropdown;
908917
}
909918
}
910919
catch
911920
{
912-
// Try to find button with ID for smaller window
913-
var button = Find(By.AccessibilityId("CopyPathButton"), 1000);
914-
if (button != null)
921+
// Could not find dropdown
922+
}
923+
924+
return null;
925+
}
926+
927+
/// <summary>
928+
/// Helper method to find the copy path menu item
929+
/// </summary>
930+
/// <returns>The copy path menu item element</returns>
931+
private Element? FindCopyPathMenuItem()
932+
{
933+
try
934+
{
935+
var menuItem = Find(By.AccessibilityId("CopyPathMenuItem"), 1000);
936+
if (menuItem != null)
915937
{
916-
return button;
938+
return menuItem;
917939
}
918940
}
941+
catch
942+
{
943+
// Could not find menu item
944+
}
919945

920946
return null;
921947
}

0 commit comments

Comments
 (0)