Skip to content

Commit ec5f21e

Browse files
committed
修复了当没有任何类时,在显示全部文件时右键菜单会崩溃的BUG;新增支持删除物理文件功能
1 parent 0f3619c commit ec5f21e

12 files changed

Lines changed: 165 additions & 19 deletions

File tree

ChangeLog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,4 +565,10 @@ UIFileDisplay部分属性将延迟初始化,几乎解决了文件及将显示
565565

566566
## 20200816
567567

568-
再次修改了任务队列的方式,提高了效率、防止了任务队列执行时卡死UI
568+
再次修改了任务队列的方式,提高了效率、防止了任务队列执行时卡死UI
569+
570+
## 20200824
571+
572+
修复了当没有任何类时,在显示全部文件时右键菜单会崩溃的BUG
573+
574+
新增支持删除物理文件功能

ClassifyFiles.WPFCore/ClassifyFiles.WPFCore.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
</ItemGroup>
6666

6767
<ItemGroup>
68+
<Page Update="UI\Dialog\DeleteFilesDialog.xaml">
69+
<SubType>Designer</SubType>
70+
</Page>
6871
<Page Update="UI\Dialog\FileMetadataDialog.xaml">
6972
<SubType>Designer</SubType>
7073
</Page>

ClassifyFiles.WPFCore/Config.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ public static bool SmoothScroll
216216
set => Set(ref smoothScroll, value, nameof(SmoothScroll));
217217
}
218218

219+
private static int? autoDeleteFiles = null;
220+
221+
public static int AutoDeleteFiles
222+
{
223+
get => Get(ref autoDeleteFiles, GetInt, 0, nameof(AutoDeleteFiles));
224+
set => Set(ref autoDeleteFiles, value, nameof(AutoDeleteFiles));
225+
}
226+
219227
private static T Get<T>(ref T? field, Func<string, T, T> dbGet, T defultValue, string key) where T : struct
220228
{
221229
if (field == null)

ClassifyFiles.WPFCore/UI/Converter/Converters.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace ClassifyFiles.UI.Converter
1212
{
13-
public class Bool2intConverter : IValueConverter
13+
public class Bool2IntConverter : IValueConverter
1414
{
1515
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1616
{
@@ -28,6 +28,23 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
2828
}
2929
}
3030

31+
public class NotZero2BoolConverter : IValueConverter
32+
{
33+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
34+
{
35+
return ((int)value) > 0;
36+
}
37+
38+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
39+
{
40+
if ((bool)value == false)
41+
{
42+
return 0;
43+
}
44+
throw new Exception();
45+
}
46+
}
47+
3148
public class Null2ZeroConverter : IValueConverter
3249
{
3350
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<dialog:ContentDialogBase
2+
x:Class="ClassifyFiles.UI.DeleteFilesDialog"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:dialog="clr-namespace:ClassifyFiles.UI.Dialog"
7+
xmlns:local="clr-namespace:ClassifyFiles.UI"
8+
xmlns:m="http://schemas.modernwpf.com/2019"
9+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10+
xmlns:root="clr-namespace:ClassifyFiles"
11+
Title="删除文件"
12+
CloseButtonStyle="{DynamicResource btn}"
13+
CloseButtonText="取消"
14+
PrimaryButtonStyle="{DynamicResource btn}"
15+
PrimaryButtonText="仅删除记录"
16+
SecondaryButtonStyle="{DynamicResource btn}"
17+
SecondaryButtonText="删除记录和物理文件"
18+
mc:Ignorable="d">
19+
<ContentControl.Resources>
20+
<Style
21+
x:Key="btn"
22+
BasedOn="{StaticResource DefaultButtonStyle}"
23+
TargetType="{x:Type Button}">
24+
<Setter Property="Width" Value="144" />
25+
</Style>
26+
</ContentControl.Resources>
27+
<m:SimpleStackPanel Spacing="12">
28+
<TextBlock Text="{Binding Message}" />
29+
<CheckBox x:Name="chkRemember" Content="记住选择" />
30+
</m:SimpleStackPanel>
31+
</dialog:ContentDialogBase>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using ClassifyFiles.UI.Dialog;
2+
using FzLib.Extension;
3+
4+
using ModernWpf.Controls;
5+
using System.Threading.Tasks;
6+
7+
namespace ClassifyFiles.UI
8+
{
9+
/// <summary>
10+
/// Dialog.xaml 的交互逻辑
11+
/// </summary>
12+
public partial class DeleteFilesDialog : ContentDialogBase
13+
{
14+
public DeleteFilesDialog()
15+
{
16+
InitializeComponent();
17+
}
18+
19+
private string message;
20+
21+
public string Message
22+
{
23+
get => message;
24+
set
25+
{
26+
message = value;
27+
this.Notify(nameof(Message));
28+
}
29+
}
30+
31+
public async Task<int> ShowAsync(int fileCount)
32+
{
33+
Message = $"是否删除{fileCount}个文件?";
34+
int result = (int)await ShowAsync();
35+
if (chkRemember.IsChecked.Value)
36+
{
37+
Configs.AutoDeleteFiles = result;
38+
}
39+
return result;
40+
}
41+
}
42+
}

ClassifyFiles.WPFCore/UI/Dialog/ErrorDialog.xaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ public string Detail
5151
await base.ShowAsync();
5252
}
5353

54-
public async new Task ShowAsync(string message, string title)
54+
public async new Task ShowAsync(string message, string title, string detail = null)
5555
{
5656
Message = message;
5757
Title = title;
58+
if (detail != null)
59+
{
60+
Detail = detail;
61+
}
5862
await base.ShowAsync();
5963
}
6064

ClassifyFiles.WPFCore/UI/Panel/FIlesViewer.xaml.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,9 @@ private async void Viewer_PreviewMouseDoubleClick(object sender, MouseButtonEven
712712
/// <param name="e"></param>
713713
private void ListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
714714
{
715-
if (Keyboard.IsKeyDown(Key.LeftCtrl) )
715+
if (Keyboard.IsKeyDown(Key.LeftCtrl))
716716
{
717-
if (CurrentFileView == FileView.Detail || CurrentFileView==FileView.Tree && Configs.TreeSimpleTemplate)
717+
if (CurrentFileView == FileView.Detail || CurrentFileView == FileView.Tree && Configs.TreeSimpleTemplate)
718718
{
719719
return;
720720
}
@@ -947,7 +947,7 @@ private void ContextMenu_Opened(object sender, RoutedEventArgs e)
947947

948948
if (!IsSingleWindow)
949949
{
950-
MenuItem menuDelete = new MenuItem() { Header = "删除文件", ToolTip = "这不会删除磁盘上的文件,仅仅删除记录" };
950+
MenuItem menuDelete = new MenuItem() { Header = "删除文件" };
951951
menuDelete.Click += MenuDelete_Click;
952952
menu.Items.Add(menuDelete);
953953

@@ -972,7 +972,7 @@ private void ContextMenu_Opened(object sender, RoutedEventArgs e)
972972
menu.Items.Add(menuShowProperties);
973973
}
974974
var classesMenus = new List<CheckBox>();
975-
if (!IsSingleWindow)
975+
if (!IsSingleWindow && Project.Classes != null && Project.Classes.Count > 0)
976976
{
977977
menu.Items.Add(new Separator());
978978

@@ -1051,7 +1051,7 @@ private async void MenuRecover_Click(object sender, RoutedEventArgs e)
10511051
async Task Do()
10521052
{
10531053
await Task.Run(() =>
1054-
FileUtility.DeleteFilesRecord(files.Select(p => p.File)));
1054+
FileUtility.RecoverFiles(files.Select(p => p.File)));
10551055
foreach (var file in files)
10561056
{
10571057
Files.Remove(file);
@@ -1066,11 +1066,24 @@ await Task.Run(() =>
10661066
private async void MenuDelete_Click(object sender, RoutedEventArgs e)
10671067
{
10681068
var files = GetSelectedFiles();
1069-
await MainWindow.Current.DoProcessAsync(Do());
1070-
async Task Do()
1069+
int mode = Configs.AutoDeleteFiles > 0 ?
1070+
Configs.AutoDeleteFiles :
1071+
await new DeleteFilesDialog().ShowAsync(files.Count);
1072+
IReadOnlyCollection<string> faileds = null;
1073+
if (mode > 0)
1074+
{
1075+
await MainWindow.Current.DoProcessAsync(DeleteRecordsOnly());
1076+
if (faileds != null && faileds.Count > 0)
1077+
{
1078+
await new ErrorDialog().ShowAsync("某一些物理文件可能由于某些原因,无法删除。",
1079+
"部分文件删除失败",
1080+
string.Join(Environment.NewLine, faileds));
1081+
}
1082+
}
1083+
async Task DeleteRecordsOnly()
10711084
{
10721085
await Task.Run(() =>
1073-
FileUtility.DeleteFilesRecord(files.Select(p => p.File)));
1086+
FileUtility.DeleteFiles(files.Select(p => p.File), mode == 2, out faileds));
10741087
foreach (var file in files)
10751088
{
10761089
Files.Remove(file);

ClassifyFiles.WPFCore/UI/Panel/FilesViewer.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<c:IsNotNull2BoolConverter x:Key="nn2b" />
2727
<c:IsNotNull2VisibilityConverter x:Key="nn2v" />
2828
<c:Null2ZeroConverter x:Key="n2z" />
29-
<c:Bool2intConverter x:Key="b2i" />
29+
<c:Bool2IntConverter x:Key="b2i" />
3030

3131
<sys:Double x:Key="iconViewMinWidth">72</sys:Double>
3232
<VirtualizationCacheLength x:Key="virtualizingPanelCacheLength">100</VirtualizationCacheLength>

ClassifyFiles.WPFCore/UI/Window/SettingWindow.xaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
xmlns:panel="clr-namespace:ClassifyFiles.UI.Panel"
1111
xmlns:root="clr-namespace:ClassifyFiles"
1212
xmlns:sys="clr-namespace:System;assembly=System.Runtime"
13-
xmlns:sys2="clr-namespace:System;assembly=System.Runtime.Extensions"
13+
xmlns:sys2="clr-namespace:System;assembly=System.Runtime.Extensions" xmlns:converter="clr-namespace:ClassifyFiles.UI.Converter"
1414
Title="设置" Width="600"
1515
Height="400"
1616
m:TitleBar.ExtendViewIntoTitleBar="True"
@@ -20,7 +20,9 @@
2020
ResizeMode="NoResize" WindowStyle="ToolWindow"
2121
WindowStartupLocation="CenterScreen"
2222
mc:Ignorable="d">
23-
<local:WindowBase.Resources />
23+
<local:WindowBase.Resources>
24+
<converter:NotZero2BoolConverter x:Key="nz2b" />
25+
</local:WindowBase.Resources>
2426
<Grid>
2527
<Grid.RowDefinitions>
2628
<RowDefinition Height="*" />
@@ -142,7 +144,7 @@
142144
Width="128" VerticalAlignment="Center"
143145
Maximum="48" Minimum="1" IsSnapToTickEnabled="True"
144146
TickFrequency="1" LargeChange="8" SmallChange="2"
145-
AutoToolTipPlacement="TopLeft"
147+
AutoToolTipPlacement="TopLeft"
146148
Value="{Binding Path=(root:Configs.RefreshThreadCount)}" />
147149
<Button Click="Button_Click_1">立即应用</Button>
148150
<TextBlock VerticalAlignment="Center" Foreground="{DynamicResource SystemControlBackgroundBaseMediumBrush}">
@@ -168,7 +170,6 @@
168170
<Button Click="Button_Click">打开缓存目录</Button>
169171
<Button Click="DeleteThumbnailButton_Click">删除所有缩略图</Button>
170172

171-
172173
<m:SimpleStackPanel Orientation="Horizontal" Spacing="12">
173174
<Button Background="Red" Foreground="White">
174175
<m:SimpleStackPanel Orientation="Horizontal" Spacing="4">
@@ -196,8 +197,12 @@
196197

197198
<Button
198199
Click="ResetAutoAddFilesButton_Click"
199-
Content="取消自动添加文件"
200+
Content="取消记忆添加文件选项"
200201
IsEnabled="{Binding Path=(root:Configs.AutoAddFiles)}" />
202+
<Button
203+
Click="ResetAutoDeleteFilesButton_Click"
204+
Content="取消记忆删除文件选项"
205+
IsEnabled="{Binding Path=(root:Configs.AutoDeleteFiles),Converter={StaticResource nz2b}}" />
201206
</m:SimpleStackPanel>
202207
</TabItem>
203208

0 commit comments

Comments
 (0)