[FileLocksmith]Show process files in modal dialog to fix crash (#33804)

## Summary of the Pull Request
To prevent a crash, show the individual files of a process within a
modal dialog rather than as inline text. Please see the linked issue for
more details.

## Detailed Description of the Pull Request / Additional comments
- Removed inline list of process files.
- Added "Show files" button to expander to show list of process files as
a modal dialog. This dialog has the same design as the one used to
display the list of selected folders within the same application.
- Added unhandled exception hander to application similar to our other
applications.


![image](https://github.com/user-attachments/assets/52eddfcc-5e10-40a3-94b2-68bbfb607f1d)

![image](https://github.com/user-attachments/assets/ff996e32-36f6-41a9-a9f0-6dda7a93d09a)
This commit is contained in:
Ani 2024-07-25 14:46:20 +02:00 committed by GitHub
parent 84def18ed5
commit d40367a860
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 16 deletions

View File

@ -25,6 +25,8 @@ namespace FileLocksmithUI
Logger.InitializeLogger("\\File Locksmith\\FileLocksmithUI\\Logs");
this.InitializeComponent();
UnhandledException += App_UnhandledException;
}
/// <summary>
@ -55,6 +57,11 @@ namespace FileLocksmithUI
_window.Activate();
}
private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
Logger.LogError("Unhandled exception", e.Exception);
}
private Window _window;
}
}

View File

@ -141,27 +141,16 @@
IsTextSelectionEnabled="True"
Text="{x:Bind user}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard ContentAlignment="Vertical">
<tkcontrols:SettingsCard>
<tkcontrols:SettingsCard.Header>
<TextBlock>
<Run x:Uid="Files" />
<Run Text="(" /><Run Text="{x:Bind files, Converter={StaticResource fileCountConverter}}" /><Run Text=")" />
</TextBlock>
</tkcontrols:SettingsCard.Header>
<ItemsRepeater ItemsSource="{x:Bind files}">
<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="x:String">
<TextBlock
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
IsTextSelectionEnabled="True"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{Binding}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap"
ToolTipService.ToolTip="{Binding}" />
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
<Button Click="ShowProcessFiles_Click">
<TextBlock x:Uid="ShowProcessFiles" />
</Button>
</tkcontrols:SettingsCard>
</tkcontrols:SettingsExpander.Items>
</tkcontrols:SettingsExpander>
@ -200,5 +189,13 @@
Text="{x:Bind ViewModel.PathsToString, Mode=OneWay}"
TextWrapping="Wrap" />
</ContentDialog>
<ContentDialog x:Name="ProcessFilesListDialog" x:Uid="ProcessFilesListDialog">
<ScrollViewer Padding="15" HorizontalScrollBarVisibility="Auto">
<TextBlock
x:Name="ProcessFilesListDialogTextBlock"
x:Uid="ProcessFilesListDialogTextBlock"
IsTextSelectionEnabled="True" />
</ScrollViewer>
</ContentDialog>
</Grid>
</Page>

View File

@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information.
using System;
using FileLocksmith.Interop;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using PowerToys.FileLocksmithUI.ViewModels;
@ -19,9 +21,17 @@ namespace PowerToys.FileLocksmithUI.Views
DataContext = ViewModel;
}
private async void ShowSelectedPathsButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
private async void ShowSelectedPathsButton_Click(object sender, RoutedEventArgs e)
{
await SelectedFilesListDialog.ShowAsync();
}
private async void ShowProcessFiles_Click(object sender, RoutedEventArgs e)
{
var processResult = (ProcessResult)((FrameworkElement)sender).DataContext;
ProcessFilesListDialogTextBlock.Text = string.Join(Environment.NewLine, processResult.files);
await ProcessFilesListDialog.ShowAsync();
}
}
}

View File

@ -130,6 +130,13 @@
<data name="Files.Text" xml:space="preserve">
<value>Files</value>
</data>
<data name="ProcessFilesListDialog.Title" xml:space="preserve">
<value>Files</value>
</data>
<data name="ProcessFilesListDialog.CloseButtonText" xml:space="preserve">
<value>Close</value>
<comment>As in, close a dialog prompt.</comment>
</data>
<data name="PathsTooltipDescription.Text" xml:space="preserve">
<value>Click to see the entire list of paths.</value>
<comment>Paths as in file paths that were selected for the utility to check.</comment>
@ -164,4 +171,8 @@
<value>Administrator: File Locksmith</value>
<comment>Title of the window when running as administrator.</comment>
</data>
<data name="ShowProcessFiles.Text" xml:space="preserve">
<value>Show files</value>
<comment>Show files for the selected process</comment>
</data>
</root>