Skip to content

Commit

Permalink
修复内容视图不显示
Browse files Browse the repository at this point in the history
  • Loading branch information
DearVa committed Aug 8, 2022
1 parent ad623d9 commit 8c762f3
Show file tree
Hide file tree
Showing 18 changed files with 267 additions and 127 deletions.
16 changes: 8 additions & 8 deletions ExplorerEx/Converter/FileGridListBoxTemplateConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
namespace ExplorerEx.Converter;

internal class FileGridListBoxTemplateConverter {
public FileListView FileListView { get; set; }
public FileListView? FileListView { get; set; }
/// <summary>
/// 图标模式
/// </summary>
public DataTemplate IconTemplate { get; set; }
public DataTemplate? IconTemplate { get; set; }
/// <summary>
/// 列表模式
/// </summary>
public DataTemplate ListTemplate { get; set; }
public DataTemplate? ListTemplate { get; set; }
/// <summary>
/// 平铺模式
/// </summary>
public DataTemplate TileTemplate { get; set; }
public DataTemplate? TileTemplate { get; set; }
/// <summary>
/// 内容模式
/// </summary>
public DataTemplate ContentTemplate { get; set; }
public DataTemplate? ContentTemplate { get; set; }
/// <summary>
/// Home的平铺模板
/// </summary>
public DataTemplate TileHomeTemplate { get; set; }
public DataTemplate? TileHomeTemplate { get; set; }

public DataTemplate Convert() {
return FileListView.FileView.FileViewType switch {
public DataTemplate? Convert() {
return FileListView!.FileView!.FileViewType switch {
FileViewType.Icons => IconTemplate,
FileViewType.List => ListTemplate,
FileViewType.Tiles when FileListView.FileView.PathType == PathType.Home => TileHomeTemplate,
Expand Down
48 changes: 48 additions & 0 deletions ExplorerEx/Converter/FileViewItemDetailsConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Globalization;
using System.Windows.Data;
using ExplorerEx.Model;
using ExplorerEx.Utils;
using HandyControl.Tools.Converter;

namespace ExplorerEx.Converter;

internal class FileListViewItemDetails0Converter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
switch (value) {
case DiskDriveItem ddi:
if (ddi.Drive.IsReady) {
return ddi.Drive.DriveFormat;
}
return string.Empty;
case FileSystemItem fsi:
return "DateModified".L() + ":".L() + fsi.DateModified;
default:
return string.Empty;
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotImplementedException();
}
}

internal class FileListViewItemDetails1Converter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
switch (value) {
case DiskDriveItem ddi:
if (ddi.Drive.IsReady) {
return string.Format("...FreeOf...".L(), Long2FileSizeConverter.StaticConvert(ddi.FreeSpace), Long2FileSizeConverter.StaticConvert(ddi.TotalSpace));
}
return string.Empty;
case FileListViewItem flv:
return flv.FileSize == -1 ? string.Empty : "FileSize".L() + ":".L() + Long2FileSizeConverter.StaticConvert(flv.FileSize);
default:
return string.Empty;
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotImplementedException();
}
}
4 changes: 2 additions & 2 deletions ExplorerEx/Model/CreateFileItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class CreateFileItem : NotifyPropertyChangedBase {
if (createIcon) {
Task.Run(() => {
Icon = GetSmallIcon(extension, true);
UpdateUI(nameof(Icon));
OnPropertyChanged(nameof(Icon));
Description = FileUtils.GetFileTypeDescription(extension);
UpdateUI(nameof(Description));
OnPropertyChanged(nameof(Description));
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions ExplorerEx/Model/FileItem/Bookmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class BookmarkCategory : NotifyPropertyChangedBase {
set {
if (isExpanded != value) {
isExpanded = value;
UpdateUI();
OnPropertyChanged();
}
}
}
Expand All @@ -51,8 +51,8 @@ public class BookmarkCategory : NotifyPropertyChangedBase {
public void AddBookmark(BookmarkItem item) {
Children ??= new ObservableCollection<BookmarkItem>();
Children.Add(item);
UpdateUI(nameof(Children));
UpdateUI(nameof(Icon));
OnPropertyChanged(nameof(Children));
OnPropertyChanged(nameof(Icon));
}

public override string ToString() {
Expand Down
10 changes: 5 additions & 5 deletions ExplorerEx/Model/FileItem/DiskDriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public sealed class DiskDriveItem : FolderItem {
} else {
TotalSpace = -1;
}
UpdateUI(nameof(FreeSpace));
UpdateUI(nameof(TotalSpace));
UpdateUI(nameof(FreeSpaceRatio));
UpdateUI(nameof(ProgressBarBackground));
UpdateUI(nameof(SpaceOverviewString));
OnPropertyChanged(nameof(FreeSpace));
OnPropertyChanged(nameof(TotalSpace));
OnPropertyChanged(nameof(FreeSpaceRatio));
OnPropertyChanged(nameof(ProgressBarBackground));
OnPropertyChanged(nameof(SpaceOverviewString));
}

public override void LoadIcon(LoadDetailsOptions options) {
Expand Down
27 changes: 21 additions & 6 deletions ExplorerEx/Model/FileItem/FileListViewItem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Threading;
using System.Windows;
Expand All @@ -16,10 +18,11 @@ namespace ExplorerEx.Model;
/// <summary>
/// 所有可以显示在<see cref="FileListView"/>中的项目的基类
/// </summary>
public abstract class FileListViewItem : NotifyPropertyChangedBase {
public abstract class FileListViewItem : INotifyPropertyChanged {
protected FileListViewItem(string fullPath, string name) {
FullPath = fullPath;
Name = name;
This = this;
}

/// <summary>
Expand All @@ -31,7 +34,7 @@ public abstract class FileListViewItem : NotifyPropertyChangedBase {
protected set {
if (icon != value) {
icon = value;
UpdateUI();
OnPropertyChanged();
}
}
}
Expand All @@ -54,7 +57,7 @@ public abstract class FileListViewItem : NotifyPropertyChangedBase {
protected set {
if (type != value) {
type = value;
UpdateUI();
OnPropertyChanged();
}
}
}
Expand All @@ -67,7 +70,7 @@ public abstract class FileListViewItem : NotifyPropertyChangedBase {
protected set {
if (fileSize != value) {
fileSize = value;
UpdateUI();
OnPropertyChanged();
}
}
}
Expand All @@ -85,7 +88,7 @@ public abstract class FileListViewItem : NotifyPropertyChangedBase {
set {
if (isSelected != value) {
isSelected = value;
UpdateUI();
OnPropertyChanged();
}
}
}
Expand Down Expand Up @@ -120,7 +123,7 @@ public abstract class FileListViewItem : NotifyPropertyChangedBase {
if (!FileUtils.IsProhibitedFileName(newName)) {
if (newName != Name && InternalRename(newName)) {
Name = newName;
UpdateUI(nameof(Name));
OnPropertyChanged(nameof(Name));
return true;
}
}
Expand Down Expand Up @@ -186,6 +189,18 @@ public class LoadDetailsOptions {

public bool UseLargeIcon { get; set; }
}

/// <summary>
/// 用于更新绑定到自身的东西
/// </summary>
public FileListViewItem This { get; }

public event PropertyChangedEventHandler? PropertyChanged;

public void OnPropertyChanged([CallerMemberName] string? propertyName = null) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(This)));
}
}

public class FileItemAttach {
Expand Down
6 changes: 3 additions & 3 deletions ExplorerEx/Model/FileItem/FileSystemItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class FileSystemItem : FileListViewItem {
protected set {
if (dateModified != value) {
dateModified = value;
UpdateUI();
OnPropertyChanged();
}
}
}
Expand All @@ -34,7 +34,7 @@ public abstract class FileSystemItem : FileListViewItem {
protected set {
if (dateCreated != value) {
dateCreated = value;
UpdateUI();
OnPropertyChanged();
}
}
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public abstract class FileSystemItem : FileListViewItem {
if (!IsFolder) {
LoadIcon(options);
}
UpdateUI(nameof(Icon));
OnPropertyChanged(nameof(Icon));
LoadAttributes(options);
}

Expand Down
4 changes: 2 additions & 2 deletions ExplorerEx/Model/FileItem/FolderOnlyItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ internal sealed class FolderOnlyItem : FileListViewItem {
// ReSharper disable once PossibleUnintendedReferenceComparison
if (children != value) {
children = value;
UpdateUI();
OnPropertyChanged();
}
}
}
Expand All @@ -160,7 +160,7 @@ internal sealed class FolderOnlyItem : FileListViewItem {
set {
if (isExpanded != value) {
isExpanded = value;
UpdateUI();
OnPropertyChanged();
if (value) {
if (this == Home) {
UpdateDriveChildren();
Expand Down
2 changes: 1 addition & 1 deletion ExplorerEx/NotifyPropertyChangedBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract class NotifyPropertyChangedBase : INotifyPropertyChanged {
public event PropertyChangedEventHandler? PropertyChanged;

[NotifyPropertyChangedInvocator]
public void UpdateUI([CallerMemberName] string? propertyName = null) {
public void OnPropertyChanged([CallerMemberName] string? propertyName = null) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

0 comments on commit 8c762f3

Please sign in to comment.