Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Delete functionality for Peek #35418

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify delete confirmation dialog. Remove workaround for focus visu…
…al issue. Ensure delete confirmation dialog is closed when the main window visibility is toggled.
daverayment committed Jan 28, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 098d912e19ef852bee22c7c61cd03323fe00565b
6 changes: 0 additions & 6 deletions src/modules/peek/Peek.UI/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -66,9 +66,6 @@ partial void OnCurrentItemChanged(IFileSystemItem? value)
WindowTitle = value != null
? ReadableStringHelper.FormatResourceString("WindowTitle", value.Name)
: _defaultWindowTitle;

DeleteConfirmationDialogMessage =
ReadableStringHelper.FormatResourceString("DeleteConfirmationDialog_Message", value?.Name ?? string.Empty);
}

[ObservableProperty]
@@ -78,9 +75,6 @@ partial void OnCurrentItemChanged(IFileSystemItem? value)
[NotifyPropertyChangedFor(nameof(DisplayItemCount))]
private NeighboringItems? _items;

[ObservableProperty]
private string _deleteConfirmationDialogMessage = string.Empty;

/// <summary>
/// The number of items selected and available to preview. Decreases as the user deletes
/// items. Displayed on the title bar.
2 changes: 1 addition & 1 deletion src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@
x:Uid="DeleteConfirmationDialog"
DefaultButton="Close">
<StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Spacing="12">
<TextBlock TextWrapping="Wrap" Text="{x:Bind ViewModel.DeleteConfirmationDialogMessage, Mode=OneWay}" />
<TextBlock x:Uid="DeleteConfirmationDialog_Message" TextWrapping="Wrap" />
<CheckBox x:Name="DeleteDontAskCheckbox" x:Uid="DeleteConfirmationDialog_DontAskCheckbox" />
</StackPanel>
</ContentDialog>
44 changes: 5 additions & 39 deletions src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -31,12 +31,6 @@ public sealed partial class MainWindow : WindowEx, IDisposable

private readonly ThemeListener? themeListener;

// Used to work around a focus visual issue when the delete confirmation dialog is
// triggered by a key event.
private readonly Thickness _zeroThickness = new(0);
private Thickness _defaultFocusPrimaryThickness = new(2);
private Thickness _defaultFocusSecondaryThickness = new(2);

/// <summary>
/// Whether the delete confirmation dialog is currently open. Used to ensure only one
/// dialog is open at a time.
@@ -75,13 +69,6 @@ private async void Content_KeyUp(object sender, KeyRoutedEventArgs e)
{
await DeleteItem();
}

// Restore the default focus visual. The Space key is excluded as that is used to toggle
// the checkbox when it has focus.
if (e.Key != Windows.System.VirtualKey.Space)
{
RestoreFocusThickness();
}
}

private async Task DeleteItem()
@@ -119,37 +106,11 @@ private async Task<ContentDialogResult> ShowDeleteConfirmationDialogAsync()
{
DeleteDontAskCheckbox.IsChecked = false;

CacheFocusThickness();

// Hide the default focus visual. This prevents its initial display when the dialog is
// opened via a keyboard event.
DeleteDontAskCheckbox.FocusVisualPrimaryThickness = _zeroThickness;
DeleteDontAskCheckbox.FocusVisualSecondaryThickness = _zeroThickness;

DeleteConfirmationDialog.XamlRoot = Content.XamlRoot;

return await DeleteConfirmationDialog.ShowAsync();
}

/// <summary>
/// Save the current focus visual thickness. This will be restored when the user interacts
/// with the dialog, e.g. by using Tab.
/// </summary>
private void CacheFocusThickness()
{
CheckBox hiddenCheckBox = new() { Visibility = Visibility.Collapsed };
MainGrid.Children.Add(hiddenCheckBox);
_defaultFocusPrimaryThickness = hiddenCheckBox.FocusVisualPrimaryThickness;
_defaultFocusSecondaryThickness = hiddenCheckBox.FocusVisualSecondaryThickness;
MainGrid.Children.Remove(hiddenCheckBox);
}

private void RestoreFocusThickness()
{
DeleteDontAskCheckbox.FocusVisualPrimaryThickness = _defaultFocusPrimaryThickness;
DeleteDontAskCheckbox.FocusVisualSecondaryThickness = _defaultFocusSecondaryThickness;
}

/// <summary>
/// Toggling the window visibility and querying files when necessary.
/// </summary>
@@ -162,6 +123,11 @@ public void Toggle(bool firstActivation, Windows.Win32.Foundation.HWND foregroun
return;
}

if (DeleteConfirmationDialog.Visibility == Visibility.Visible)
{
DeleteConfirmationDialog.Hide();
}

if (AppWindow.IsVisible)
{
if (IsNewSingleSelectedItem(foregroundWindowHandle))
10 changes: 5 additions & 5 deletions src/modules/peek/Peek.UI/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
@@ -358,18 +358,18 @@
<comment>The prefix added to all file delete failure messages. {0} is replaced with the name of the file</comment>
</data>
<data name="DeleteConfirmationDialog.Title" xml:space="preserve">
<value>Delete file</value>
<value>Delete file?</value>
</data>
<data name="DeleteConfirmationDialog.PrimaryButtonText" xml:space="preserve">
<value>Move to Recycle Bin</value>
<value>Delete</value>
</data>
<data name="DeleteConfirmationDialog.CloseButtonText" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="DeleteConfirmationDialog_Message" xml:space="preserve">
<value>Are you sure you want to move "{0}" to the Recycle Bin?</value>
<data name="DeleteConfirmationDialog_Message.Text" xml:space="preserve">
<value>Are you sure you want to delete this file?</value>
</data>
<data name="DeleteConfirmationDialog_DontAskCheckbox.Content" xml:space="preserve">
<value>Don't ask me again</value>
<value>Don't show this warning again</value>
</data>
</root>