Skip to content

Commit

Permalink
提高文件夹打开速度!界面优化;修复视图bug;侧边栏支持一键收起全部
Browse files Browse the repository at this point in the history
  • Loading branch information
DearVa committed Sep 8, 2022
1 parent ca7b5e0 commit 42da5b8
Show file tree
Hide file tree
Showing 40 changed files with 1,923 additions and 1,366 deletions.
12 changes: 7 additions & 5 deletions ExplorerEx/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
Expand Down Expand Up @@ -46,8 +47,8 @@ public partial class App {
Current.Shutdown();
return;
}
if (Args.RequireDebugger && Debugger.Launch()) {
Debugger.Break();
if (Args.RequireDebugger) {
Debugger.Launch();
}

mutex = new Mutex(true, "ExplorerExMut", out var createdNew);
Expand All @@ -67,9 +68,7 @@ public partial class App {

isRunning = true;
notifyMmf = new NotifyMemoryMappedFile("ExplorerExIPC", 1024, true);
new Thread(IPCWork) {
IsBackground = true
}.Start();
_ = Task.Factory.StartNew(IPCWork, TaskCreationOptions.LongRunning);

ProcessorCount = Environment.ProcessorCount;
IconHelper.Initialize();
Expand Down Expand Up @@ -159,6 +158,9 @@ public partial class App {
case "Open":
Dispatcher.Invoke(() => View.MainWindow.OpenPath(msg.Length == 2 ? msg[1] : null));
break;
// case "Select":
// Dispatcher.Invoke(() => View.MainWindow.OpenPath(msg.Length == 2 ? msg[1] : null));
// break;
}
}
}
Expand Down
24 changes: 20 additions & 4 deletions ExplorerEx/Assets/Geometries.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1204,13 +1204,13 @@
<DrawingImage.Drawing>
<DrawingGroup ClipGeometry="M0,0 V20 H17.75 V0 H0 Z">
<DrawingGroup Transform="1,0,0,1,-2.75,-2">
<GeometryDrawing Brush="{DynamicResource PrimaryTextBrush}" Geometry="F1 M17.75,20z M0,0z M19.75,18L10.75,18A0.75,0.75,0,0,0,10.75,19.5L19.75,19.5A0.75,0.75,0,0,0,19.75,18z" />
<GeometryDrawing Brush="{DynamicResource SecondaryTextBrush}" Geometry="F1 M17.75,20z M0,0z M19.75,18L10.75,18A0.75,0.75,0,0,0,10.75,19.5L19.75,19.5A0.75,0.75,0,0,0,19.75,18z" />
</DrawingGroup>
<DrawingGroup Transform="1,0,0,1,-2.75,-2">
<GeometryDrawing Brush="{DynamicResource PrimaryTextBrush}" Geometry="F1 M17.75,20z M0,0z M19.75,11.49L10.75,11.49A0.75,0.75,0,0,0,10.75,12.99L19.75,12.99A0.75,0.75,0,0,0,19.75,11.49z" />
<GeometryDrawing Brush="{DynamicResource SecondaryTextBrush}" Geometry="F1 M17.75,20z M0,0z M19.75,11.49L10.75,11.49A0.75,0.75,0,0,0,10.75,12.99L19.75,12.99A0.75,0.75,0,0,0,19.75,11.49z" />
</DrawingGroup>
<DrawingGroup Transform="1,0,0,1,-2.75,-2">
<GeometryDrawing Brush="{DynamicResource PrimaryTextBrush}" Geometry="F1 M17.75,20z M0,0z M10.75,6.5L19.75,6.5A0.75,0.75,0,0,0,19.75,5L10.75,5A0.75,0.75,0,0,0,10.75,6.5z" />
<GeometryDrawing Brush="{DynamicResource SecondaryTextBrush}" Geometry="F1 M17.75,20z M0,0z M10.75,6.5L19.75,6.5A0.75,0.75,0,0,0,19.75,5L10.75,5A0.75,0.75,0,0,0,10.75,6.5z" />
</DrawingGroup>
<DrawingGroup Transform="1,0,0,1,-2.75,-2">
<GeometryDrawing Brush="{DynamicResource PrimaryBrush}" Geometry="F1 M17.75,20z M0,0z M4.15,5.14L4.5,4.89 4.5,7.25A0.75,0.75,0,0,0,6,7.25L6,2.75A0.75,0.75,0,0,0,5.41,2A0.74,0.74,0,0,0,4.57,2.42L4.57,2.42 4.57,2.42 4.57,2.53A3.54,3.54,0,0,1,4.26,3A3.12,3.12,0,0,1,3.35,3.9A0.75,0.75,0,0,0,4.15,5.18z" />
Expand All @@ -1222,7 +1222,7 @@
<GeometryDrawing Brush="{DynamicResource PrimaryBrush}" Geometry="F1 M17.75,20z M0,0z M7.2,17.9A1.75,1.75,0,0,0,6.6,16.54A2.35,2.35,0,0,0,5,16A3.25,3.25,0,0,0,3.54,16.33A2.62,2.62,0,0,0,3.14,16.57L3,16.66 3,16.66 3,16.66A0.75,0.75,0,0,0,4,17.73L4,17.73 4.17,17.63A1.75,1.75,0,0,1,5,17.5A0.94,0.94,0,0,1,5.61,17.66A0.26,0.26,0,0,1,5.7,17.85A0.37,0.37,0,0,1,5.57,18.08A0.83,0.83,0,0,1,5,18.25A0.75,0.75,0,0,0,5,19.75A0.83,0.83,0,0,1,5.57,19.92A0.37,0.37,0,0,1,5.7,20.15A0.24,0.24,0,0,1,5.61,20.34A0.94,0.94,0,0,1,5,20.5A1.75,1.75,0,0,1,4.21,20.33L4,20.23 4,20.23A0.75,0.75,0,0,0,3,21.3L3,21.3 3,21.3 3.11,21.39A2.62,2.62,0,0,0,3.51,21.63A3.25,3.25,0,0,0,5,22A2.35,2.35,0,0,0,6.6,21.46A1.75,1.75,0,0,0,7.2,20.1A1.81,1.81,0,0,0,6.77,19A1.81,1.81,0,0,0,7.2,17.9z" />
</DrawingGroup>
<DrawingGroup Transform="1,0,0,1,-2.75,-2">
<GeometryDrawing Brush="{DynamicResource PrimaryTextBrush}" Geometry="F1 M17.75,20z M0,0z M3,16.72z" />
<GeometryDrawing Brush="{DynamicResource SecondaryTextBrush}" Geometry="F1 M17.75,20z M0,0z M3,16.72z" />
</DrawingGroup>
</DrawingGroup>
</DrawingImage.Drawing>
Expand All @@ -1244,6 +1244,22 @@
</DrawingImage.Drawing>
</DrawingImage>

<DrawingImage x:Key="CollapseAllDrawingImage">
<DrawingImage.Drawing>
<DrawingGroup ClipGeometry="M0,0 V15.5 H20 V0 H0 Z">
<DrawingGroup Transform="1,0,0,1,-2,-4">
<GeometryDrawing Brush="{DynamicResource PrimaryBrush}" Geometry="F1 M20,15.5z M0,0z M6.22,8.22A0.75,0.75,0,0,1,7.28,8.22L10.28,11.22A0.75,0.75,0,0,1,9.22,12.28L7.5,10.56 7.5,18.75A0.75,0.75,0,0,1,6,18.75L6,10.56 4.28,12.28A0.75,0.75,0,0,1,3.22,11.22z" />
</DrawingGroup>
<DrawingGroup Transform="1,0,0,1,-2,-4">
<GeometryDrawing Brush="{DynamicResource SecondaryTextBrush}" Geometry="F1 M20,15.5z M0,0z M22,4.75A0.76,0.76,0,0,0,21.25,4L2.75,4A0.75,0.75,0,0,0,2.75,5.5L21.25,5.5A0.76,0.76,0,0,0,22,4.75z" />
</DrawingGroup>
<DrawingGroup Transform="1,0,0,1,-2,-4">
<GeometryDrawing Brush="{DynamicResource SecondaryTextBrush}" Geometry="F1 M20,15.5z M0,0z M21.25,8L12.25,8A0.75,0.75,0,0,0,12.25,9.5L21.25,9.5A0.75,0.75,0,0,0,21.25,8z" />
</DrawingGroup>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>

<Geometry x:Key="LeftArrowGeometry" o:Freeze="True">M 955.1 433.2 H 301.3 c -17.7 0 -25.6 -21.7 -13.8 -33.5 l 189 -189 c 11.8 -11.8 11.8 -29.5 0 -41.4 L 433.2 126 c -11.8 -11.8 -29.5 -11.8 -41.4 0 L 47.3 470.6 c -11.8 11.8 -11.8 29.5 0 41.4 l 344.6 344.6 c 11.8 11.8 29.5 11.8 41.4 0 l 41.4 -41.4 c 11.8 -11.8 11.8 -29.5 0 -41.4 l -189 -189 c -11.8 -11.8 -3.9 -33.5 13.8 -33.5 h 653.8 c 15.8 0 29.5 -13.8 29.5 -29.5 v -59.1 c 2 -15.8 -11.8 -29.5 -27.6 -29.5 z</Geometry>
<Geometry x:Key="RightArrowGeometry" o:Freeze="True">M -955.1 433.2 H -301.3 c 17.7 0 25.6 -21.7 13.8 -33.5 l -189 -189 c -11.8 -11.8 -11.8 -29.5 0 -41.4 L -433.2 126 c 11.8 -11.8 29.5 -11.8 41.4 0 L -47.3 470.6 c 11.8 11.8 11.8 29.5 0 41.4 l -344.6 344.6 c -11.8 11.8 -29.5 11.8 -41.4 0 l -41.4 -41.4 c -11.8 -11.8 -11.8 -29.5 0 -41.4 l 189 -189 c 11.8 -11.8 3.9 -33.5 -13.8 -33.5 h -653.8 c -15.8 0 -29.5 -13.8 -29.5 -29.5 v -59.1 c -2 -15.8 11.8 -29.5 27.6 -29.5 z</Geometry>
<Geometry x:Key="UpArrowGeometry" o:Freeze="True">M 414 809.7 V 155.9 c 0 -17.7 -21.7 -25.6 -33.5 -13.8 l -189 189 c -11.8 11.8 -29.5 11.8 -41.4 0 l -43.3 -43.3 c -11.8 -11.8 -11.8 -29.5 0 -41.4 l 344.6 -344.5 c 11.8 -11.8 29.5 -11.8 41.4 0 l 344.6 344.6 c 11.8 11.8 11.8 29.5 0 41.4 L 796 329.3 c -11.8 11.8 -29.5 11.8 -41.4 0 l -189 -189 c -11.8 -11.8 -33.5 -3.9 -33.5 13.8 v 653.8 c 0 15.8 -13.8 29.5 -29.5 29.5 h -59.1 c -15.8 2 -29.5 -11.8 -29.5 -27.6 Z</Geometry>
Expand Down
1 change: 1 addition & 0 deletions ExplorerEx/Assets/Svg/CollapseAll.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions ExplorerEx/Command/FileItemCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ public class FileItemCommand : ICommand {
case "Cut": {
var items = Items;
if (items.Count > 0) {
var isCut = !Folder.IsReadonly && str == "Cut";
var data = new DataObject(DataFormats.FileDrop, items.Where(item => item is FileSystemItem or DiskDriveItem).Select(item => item.FullPath).ToArray());
data.SetData("IsCut", !Folder.IsReadonly && str == "Cut");
data.SetData("IsCut", isCut);
Clipboard.SetDataObject(data);
foreach (var item in items) {
item.Opacity = 0.3d;
}
}
break;
}
Expand Down Expand Up @@ -339,7 +343,7 @@ public class FileItemCommand : ICommand {
hc.MessageBox.Error(e.Message, "FailedToOpenFile".L());
}
}

public event EventHandler? CanExecuteChanged;
}

Expand Down
2 changes: 1 addition & 1 deletion ExplorerEx/Converter/FileGridListBoxTemplateConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class FileGridListBoxTemplateConverter {
public DataTemplate? TileHomeTemplate { get; set; }

public DataTemplate? Convert() {
return FileListView!.FileView!.FileViewType switch {
return FileListView!.FileView.FileViewType switch {
FileViewType.Icons => IconTemplate,
FileViewType.List => ListTemplate,
FileViewType.Tiles when FileListView.FileView.PathType == PathType.Home => TileHomeTemplate,
Expand Down
27 changes: 16 additions & 11 deletions ExplorerEx/Model/FileListViewItem/DiskDriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ public sealed class DiskDriveItem : FolderItem {

public long TotalSpace { get; private set; }

public double FreeSpaceRatio => TotalSpace == -1 ? 0 : (double)(TotalSpace - FreeSpace) / TotalSpace;
/// <summary>
/// 使用占比
/// </summary>
public double PercentFull => TotalSpace == -1 ? 0 : (double)(TotalSpace - FreeSpace) / TotalSpace;

public Brush ProgressBarBackground => FreeSpaceRatio > 0.8d ? new SolidColorBrush(GradientColor.Eval((FreeSpaceRatio - 0.5d) * 2d)) : NormalProgressBrush;
public Brush ProgressBarBackground => PercentFull > 0.8d ? new SolidColorBrush(GradientColor.Eval((PercentFull - 0.8d) * 10d)) : NormalProgressBrush;

public string SpaceOverviewString => $"{"Available: ".L()}{FileUtils.FormatByteSize(FreeSpace)}{", ".L()}{"Total: ".L()}{FileUtils.FormatByteSize(TotalSpace)}";

private static readonly SolidColorBrush NormalProgressBrush = new(Colors.ForestGreen);

private static readonly Gradient GradientColor = new(Colors.ForestGreen, Colors.Orange, Colors.Red);
private static readonly Gradient GradientColor = new(Colors.ForestGreen, Colors.OrangeRed, Colors.Red);

public DiskDriveItem(DriveInfo drive) : base(new DirectoryInfo(drive.Name), LoadDetailsOptions.Default) {
Drive = drive;
Expand All @@ -51,7 +54,7 @@ public sealed class DiskDriveItem : FolderItem {
}
OnPropertyChanged(nameof(FreeSpace));
OnPropertyChanged(nameof(TotalSpace));
OnPropertyChanged(nameof(FreeSpaceRatio));
OnPropertyChanged(nameof(PercentFull));
OnPropertyChanged(nameof(ProgressBarBackground));
OnPropertyChanged(nameof(SpaceOverviewString));
}
Expand Down Expand Up @@ -79,7 +82,6 @@ public sealed class DiskDriveItem : FolderItem {
private class Gradient {
private readonly int segmentLength;
private readonly HSVColor[] colors;
private readonly Color endColor;

public Gradient(params Color[] colors) {
Debug.Assert(colors is { Length: > 1 });
Expand All @@ -88,16 +90,19 @@ private class Gradient {
this.colors[i] = new HSVColor(colors[i]);
}
segmentLength = colors.Length - 1;
endColor = colors[segmentLength];
}

public Color Eval(double v) {
if (v >= 1f) {
return endColor;
switch (v) {
case <= 0d:
return colors[0].ToRGB();
case >= 1d:
return colors[^1].ToRGB();
default:
var j = v * segmentLength;
var i = (int)j;
return HSVColor.Lerp(colors[i], colors[i + 1], j - i);
}
var j = v * segmentLength;
var i = (int)j;
return HSVColor.Lerp(colors[i], colors[i + 1], j - i);
}
}
}
22 changes: 14 additions & 8 deletions ExplorerEx/Model/FileListViewItem/FileListViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class FileListViewItem : INotifyPropertyChanged {
This = this;
}

protected FileListViewItem(ImageSource defaultIcon, LoadDetailsOptions options) {
protected FileListViewItem(ImageSource? defaultIcon, LoadDetailsOptions options) {
this.defaultIcon = defaultIcon;
Options = options;
This = this;
Expand All @@ -34,7 +34,7 @@ public abstract class FileListViewItem : INotifyPropertyChanged {
This = this;
}

protected FileListViewItem(string fullPath, string name, ImageSource defaultIcon, LoadDetailsOptions options) {
protected FileListViewItem(string fullPath, string name, ImageSource? defaultIcon, LoadDetailsOptions options) {
FullPath = fullPath;
Name = name;
this.defaultIcon = defaultIcon;
Expand All @@ -50,10 +50,7 @@ public abstract class FileListViewItem : INotifyPropertyChanged {
if (icon != null) {
return icon;
}
Task.Run(() => {
LoadIcon();
LoadAttributes();
}); // TODO
LazyLoad();
return defaultIcon;
}
protected set {
Expand All @@ -66,9 +63,18 @@ public abstract class FileListViewItem : INotifyPropertyChanged {

private ImageSource? icon;

protected readonly ImageSource defaultIcon;
protected readonly ImageSource? defaultIcon;

/// <summary>
/// 当get_Icon的时候运行
/// </summary>
protected virtual void LazyLoad() {
Task.Run(() => {
LoadIcon();
LoadAttributes();
}); // TODO
}


public double Opacity {
get => opacity;
set {
Expand Down
11 changes: 6 additions & 5 deletions ExplorerEx/Model/FileListViewItem/FileSystemItem.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System;
using System.IO;
using System.Windows.Media;
using ExplorerEx.Shell32;
using ExplorerEx.Utils;
using ExplorerEx.View.Controls;
using File = System.IO.File;

namespace ExplorerEx.Model;

public abstract class FileSystemItem : FileListViewItem {
protected FileSystemInfo? FileSystemInfo { get; }
protected FileSystemInfo? FileSystemInfo { get; init; }

/// <summary>
/// 自动更新UI
Expand Down Expand Up @@ -41,7 +40,7 @@ public abstract class FileSystemItem : FileListViewItem {

private DateTime dateCreated = DateTime.MaxValue;

public override string GetRenameName() {
public override string? GetRenameName() {
return Name;
}

Expand Down Expand Up @@ -72,15 +71,17 @@ public abstract class FileSystemItem : FileListViewItem {
/// <param name="isFolder"></param>
protected FileSystemItem(bool isFolder) : base(isFolder, LoadDetailsOptions.Default) { }

protected FileSystemItem(ImageSource? defaultIcon) : base(defaultIcon, LoadDetailsOptions.Default) { }

protected FileSystemItem(string fullPath, string name, bool isFolder, LoadDetailsOptions options) : base(fullPath, name, isFolder, options) { }

protected FileSystemItem(string fullPath, string name, ImageSource defaultIcon, LoadDetailsOptions options) : base(fullPath, name, defaultIcon, options) { }
protected FileSystemItem(string fullPath, string name, ImageSource? defaultIcon, LoadDetailsOptions options) : base(fullPath, name, defaultIcon, options) { }

protected FileSystemItem(FileSystemInfo fileSystemInfo, bool isFolder, LoadDetailsOptions options) : base(fileSystemInfo.FullName, fileSystemInfo.Name, isFolder, options) {
FileSystemInfo = fileSystemInfo;
}

protected FileSystemItem(FileSystemInfo fileSystemInfo, ImageSource defaultIcon, LoadDetailsOptions options) : base(fileSystemInfo.FullName, fileSystemInfo.Name, defaultIcon, options) {
protected FileSystemItem(FileSystemInfo fileSystemInfo, ImageSource? defaultIcon, LoadDetailsOptions options) : base(fileSystemInfo.FullName, fileSystemInfo.Name, defaultIcon, options) {
FileSystemInfo = fileSystemInfo;
}
}
2 changes: 2 additions & 0 deletions ExplorerEx/Model/FileListViewItem/FolderItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class FolderItem : FileSystemItem {

protected FolderItem() : base(true) { }

protected FolderItem(ImageSource? defaultIcon) : base(defaultIcon) { }

public FolderItem(DirectoryInfo directoryInfo, LoadDetailsOptions options) : base(directoryInfo, InitializeIsEmptyFolder(directoryInfo.FullName), options) {
IsFolder = true;
FileSize = -1;
Expand Down

0 comments on commit 42da5b8

Please sign in to comment.