Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bcfbd1726 | ||
|
|
5c910aaed7 | ||
|
|
1a3b89bdf7 | ||
|
|
972da36877 | ||
|
|
bf46dc5622 | ||
|
|
ee308d245d | ||
|
|
d0d5d9bfd5 | ||
|
|
85ff350339 | ||
|
|
0646b49a62 | ||
|
|
b449231adc | ||
|
|
6caae160a1 | ||
|
|
bbd3476670 | ||
|
|
0931cb9434 |
No files matched your search
@@ -1,4 +1,4 @@
|
||||
using FileManager_UWP.Server;
|
||||
using FileManager_UWP.Service;
|
||||
using GalaSoft.MvvmLight.Ioc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -74,7 +74,7 @@ namespace FileManager_UWP
|
||||
Window.Current.Activate();
|
||||
}
|
||||
|
||||
SimpleIoc.Default.Register<FileServer>();
|
||||
SimpleIoc.Default.Register<FileService>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -120,7 +120,14 @@
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Server\FileServer.cs" />
|
||||
<Compile Include="Model\DisplayableDisk.cs" />
|
||||
<Compile Include="Model\DisplayableFile.cs" />
|
||||
<Compile Include="Model\DisplayableFolder.cs" />
|
||||
<Compile Include="Model\DisplayableSpecial.cs" />
|
||||
<Compile Include="Model\DisplayFileFolderItem.cs" />
|
||||
<Compile Include="Model\Displayable.cs" />
|
||||
<Compile Include="Service\FileService.cs" />
|
||||
<Compile Include="Service\IconServer.cs" />
|
||||
<Compile Include="ViewModel\FileListViewModel.cs" />
|
||||
<Compile Include="ViewModel\MainPageViewModel.cs" />
|
||||
<Compile Include="View\FileListView.xaml.cs">
|
||||
@@ -172,13 +179,23 @@
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||
<Version>6.2.7</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed">
|
||||
<Version>2.0.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MvvmLight">
|
||||
<Version>5.4.1.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MvvmLightLibs">
|
||||
<Version>5.4.1.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.IO">
|
||||
<Version>4.3.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.IO.FileSystem">
|
||||
<Version>4.3.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Model\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.FileProperties;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Animation;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
||||
namespace FileManager_UWP.Model {
|
||||
/// <summary>
|
||||
/// 显示用的文件文件夹统一类, 已废弃
|
||||
/// </summary>
|
||||
class DisplayFileFolderItem {
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
public bool IsFolder { get; set; }
|
||||
public BitmapImage Icon { get; set; } = new BitmapImage();
|
||||
|
||||
public DisplayFileFolderItem(StorageFolder file) {
|
||||
Name = file.Name;
|
||||
Path = file.Path;
|
||||
IsFolder = true;
|
||||
}
|
||||
public DisplayFileFolderItem(StorageFile file) {
|
||||
Name = file.Name;
|
||||
Path = file.Path;
|
||||
IsFolder = false;
|
||||
}
|
||||
private DisplayFileFolderItem() { }
|
||||
|
||||
public static async Task<DisplayFileFolderItem> GetInstance(StorageFile file)
|
||||
{
|
||||
DisplayFileFolderItem obj = new DisplayFileFolderItem
|
||||
{
|
||||
Name = file.Name,
|
||||
Path = file.Path,
|
||||
IsFolder = false,
|
||||
};
|
||||
var thumbnail = await file.GetThumbnailAsync(ThumbnailMode.ListView, 32);
|
||||
await obj.Icon.SetSourceAsync(thumbnail).AsTask();
|
||||
|
||||
//var imgExt = new[] { "bmp", "gif", "jpeg", "jpg", "png" }.FirstOrDefault(ext => file.Path.ToLower().EndsWith(ext));
|
||||
//if (imgExt != null) {
|
||||
// var dummy = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("dummy." + imgExt, CreationCollisionOption.ReplaceExisting); //may overwrite existing
|
||||
// obj.Icon = await dummy.GetThumbnailAsync(ThumbnailMode.SingleItem, 32);
|
||||
//} else {
|
||||
// obj.Icon = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 32);
|
||||
//}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static async Task<DisplayFileFolderItem> GetInstance(StorageFolder file) {
|
||||
DisplayFileFolderItem obj = new DisplayFileFolderItem {
|
||||
Name = file.Name,
|
||||
Path = file.Path,
|
||||
IsFolder = true,
|
||||
};
|
||||
var thumbnail = await file.GetThumbnailAsync(ThumbnailMode.ListView, 32);
|
||||
await obj.Icon.SetSourceAsync(thumbnail).AsTask();
|
||||
|
||||
//var imgExt = new[] { "bmp", "gif", "jpeg", "jpg", "png" }.FirstOrDefault(ext => file.Path.ToLower().EndsWith(ext));
|
||||
//if (imgExt != null) {
|
||||
// var dummy = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("dummy." + imgExt, CreationCollisionOption.ReplaceExisting); //may overwrite existing
|
||||
// obj.Icon = await dummy.GetThumbnailAsync(ThumbnailMode.SingleItem, 32);
|
||||
//} else {
|
||||
// obj.Icon = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 32);
|
||||
//}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static async Task<DisplayFileFolderItem> parent(string current) {
|
||||
string path = current.Substring(0, current.LastIndexOf('\\'));
|
||||
if (path.Length == 2)
|
||||
path += "\\";
|
||||
StorageFolder file = await StorageFolder.GetFolderFromPathAsync(path);
|
||||
var thumbnail = await file.GetThumbnailAsync(ThumbnailMode.ListView, 32);
|
||||
DisplayFileFolderItem d = new DisplayFileFolderItem(file);
|
||||
await d.Icon.SetSourceAsync(thumbnail).AsTask();
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
||||
namespace FileManager_UWP.Model {
|
||||
public enum Type{
|
||||
File, Folder, Disk, VirtualFolder
|
||||
}
|
||||
public abstract class Displayable : IComparable {
|
||||
public abstract string Name { get; }
|
||||
public abstract string Path { get; }
|
||||
public abstract Type Type { get; }
|
||||
public abstract BitmapImage Icon { get; }
|
||||
|
||||
public int CompareTo(object obj) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.FileProperties;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
||||
namespace FileManager_UWP.Model
|
||||
{
|
||||
public class DisplayableDisk: Displayable {
|
||||
private readonly DriveInfo _drive;
|
||||
private readonly BitmapImage _icon = new BitmapImage();
|
||||
|
||||
private DisplayableDisk(DriveInfo d) {
|
||||
_drive = d;
|
||||
}
|
||||
|
||||
public static async Task<DisplayableDisk> GetInstance(DriveInfo d) {
|
||||
var obj = new DisplayableDisk(d);
|
||||
StorageFolder f = await StorageFolder.GetFolderFromPathAsync(d.Name);
|
||||
var thumbnail = await f.GetThumbnailAsync(ThumbnailMode.ListView, 32);
|
||||
await obj._icon.SetSourceAsync(thumbnail).AsTask();
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
public override string Name => _drive.Name;
|
||||
public override string Path => _drive.Name;
|
||||
public override BitmapImage Icon => _icon;
|
||||
public override Type Type => Type.Disk;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.FileProperties;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
||||
namespace FileManager_UWP.Model
|
||||
{
|
||||
public class DisplayableFile: Displayable {
|
||||
private readonly StorageFile _file;
|
||||
private readonly BitmapImage _icon;
|
||||
|
||||
private DisplayableFile(StorageFile f) {
|
||||
_file = f;
|
||||
_icon = new BitmapImage();
|
||||
}
|
||||
|
||||
public static async Task<DisplayableFile> GetInstanceAsync(StorageFile f) {
|
||||
DisplayableFile obj = new DisplayableFile(f);
|
||||
var thumbnail = await f.GetThumbnailAsync(ThumbnailMode.ListView, 32);
|
||||
await obj._icon.SetSourceAsync(thumbnail).AsTask();
|
||||
return obj;
|
||||
}
|
||||
|
||||
public override string Name => _file.Name;
|
||||
|
||||
public override string Path => _file.Path;
|
||||
|
||||
public override Type Type => Type.File;
|
||||
|
||||
public override BitmapImage Icon => _icon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.FileProperties;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
||||
namespace FileManager_UWP.Model
|
||||
{
|
||||
public class DisplayableFolder: Displayable {
|
||||
private readonly StorageFolder _folder;
|
||||
private readonly BitmapImage _icon;
|
||||
|
||||
private DisplayableFolder(StorageFolder f) {
|
||||
_folder = f;
|
||||
_icon = new BitmapImage();
|
||||
}
|
||||
|
||||
public static async Task<DisplayableFolder> GetInstanceAsync(StorageFolder f)
|
||||
{
|
||||
DisplayableFolder obj = new DisplayableFolder(f);
|
||||
var thumbnail = await f.GetThumbnailAsync(ThumbnailMode.ListView, 32);
|
||||
await obj._icon.SetSourceAsync(thumbnail).AsTask();
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static async Task<Displayable> GetParentAsync(StorageFolder f) {
|
||||
string path = System.IO.Path.GetDirectoryName(f.Path);
|
||||
BitmapImage img = new BitmapImage();
|
||||
if (path != null) {
|
||||
path = f.Path.Substring(0, f.Path.LastIndexOf('\\'));
|
||||
StorageFolder file = await StorageFolder.GetFolderFromPathAsync(path);
|
||||
var thumbnail = await file.GetThumbnailAsync(ThumbnailMode.ListView, 32);
|
||||
await img.SetSourceAsync(thumbnail).AsTask();
|
||||
return new DisplayableSpecial("..", file.Path, Model.Type.Folder, img);
|
||||
}
|
||||
else {
|
||||
var thumbnail = await f.GetThumbnailAsync(ThumbnailMode.ListView, 32);
|
||||
await img.SetSourceAsync(thumbnail).AsTask();
|
||||
return new DisplayableSpecial("..", "/", Model.Type.Folder, img);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Name => _folder.Name;
|
||||
|
||||
public override string Path => _folder.Path;
|
||||
|
||||
public override Type Type => Type.Folder;
|
||||
|
||||
public override BitmapImage Icon => _icon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
||||
namespace FileManager_UWP.Model
|
||||
{
|
||||
public class DisplayableSpecial: Displayable {
|
||||
public DisplayableSpecial(string name, string path, Type type, BitmapImage icon)
|
||||
{
|
||||
Name = name;
|
||||
Path = path;
|
||||
Type = type;
|
||||
Icon = icon;
|
||||
}
|
||||
public override string Name { get; }
|
||||
public override string Path { get; }
|
||||
public override Type Type { get; }
|
||||
public override BitmapImage Icon { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace FileManager_UWP.Server {
|
||||
/// <summary>
|
||||
/// 负责提供本地文件及文件夹访问服务
|
||||
/// </summary>
|
||||
class FileServer {
|
||||
public async Task<IReadOnlyList<StorageFile>> getFileList() {
|
||||
StorageFolder picturesFolder = KnownFolders.DocumentsLibrary;
|
||||
IReadOnlyList<StorageFile> fileList = await picturesFolder.GetFilesAsync();
|
||||
return fileList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
using FileManager_UWP.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Authentication;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Data.Json;
|
||||
using Windows.Devices.Custom;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.FileProperties;
|
||||
using Windows.Web.Http.Headers;
|
||||
using Type = FileManager_UWP.Model.Type;
|
||||
|
||||
namespace FileManager_UWP.Service {
|
||||
internal interface IFileService {
|
||||
/// <summary>
|
||||
/// 获得可显示的目录
|
||||
/// </summary>
|
||||
/// <param name="path">路径</param>
|
||||
/// <returns>文件和文件夹列表</returns>
|
||||
Task<List<Displayable>> GetDisplayFileFolderList(string path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 负责提供本地文件及文件夹访问服务
|
||||
/// </summary>
|
||||
class FileService : IFileService {
|
||||
/// <summary>
|
||||
/// 获得普通文件夹中的文件
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<List<Displayable>> GetRegularFilesAsync(string path) {
|
||||
StorageFolder folder = null;
|
||||
try {
|
||||
folder = await StorageFolder.GetFolderFromPathAsync(path);
|
||||
} catch (FileNotFoundException e) {
|
||||
Debug.WriteLine(e.Message);
|
||||
throw;
|
||||
} catch (AuthenticationException e) {
|
||||
Debug.WriteLine(e.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
// 打开文件夹
|
||||
List<Displayable> displayFileFolderItems =
|
||||
new List<Displayable> {await DisplayableFolder.GetParentAsync(folder)};
|
||||
|
||||
// 读取配置文件
|
||||
string confPath = folder.Path;
|
||||
if (confPath.EndsWith('\\'))
|
||||
confPath += ".awesomefilemanager";
|
||||
else
|
||||
confPath += "\\.awesomefilemanager";
|
||||
try
|
||||
{
|
||||
StorageFile confFile = await StorageFile.GetFileFromPathAsync(confPath);
|
||||
string jsonString = await FileIO.ReadTextAsync(confFile);
|
||||
JsonObject jsonObject = JsonObject.Parse(jsonString);
|
||||
JsonArray virtualFolders = jsonObject.GetNamedArray("virtual_folders");
|
||||
foreach (var jsonValue in virtualFolders) {
|
||||
var virtualFolder = jsonValue.GetObject();
|
||||
displayFileFolderItems.Add(new DisplayableSpecial(
|
||||
virtualFolder.GetNamedString("name"),
|
||||
"",
|
||||
Type.VirtualFolder,
|
||||
await IconServer.GetFolderIcon(ThumbnailMode.ListView, 32)));
|
||||
}
|
||||
} catch (FileNotFoundException) {
|
||||
Debug.WriteLine("no configure file in " + confPath);
|
||||
}
|
||||
|
||||
IReadOnlyList<StorageFolder> folders = await folder.GetFoldersAsync();
|
||||
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
|
||||
//displayFileFolderItems.AddRange(folders
|
||||
// .Select(async i => await DisplayFileFolderItem.GetInstance(i))
|
||||
// .Select(i => i.Result)
|
||||
//);
|
||||
//displayFileFolderItems.AddRange(files
|
||||
// .Select(async i => await DisplayFileFolderItem.GetInstance(i))
|
||||
// .Select(i => i.Result)
|
||||
//);
|
||||
|
||||
foreach (var file in folders) {
|
||||
displayFileFolderItems.Add(
|
||||
await DisplayableFolder.GetInstanceAsync(file));
|
||||
}
|
||||
|
||||
foreach (var file in files) {
|
||||
displayFileFolderItems.Add(
|
||||
await DisplayableFile.GetInstanceAsync(file));
|
||||
}
|
||||
|
||||
return displayFileFolderItems;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得磁盘驱动器列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<List<Displayable>> GetDiskDrivesAsync() {
|
||||
var drives = System.IO.DriveInfo.GetDrives();
|
||||
List<Displayable> ans = new List<Displayable>();
|
||||
foreach (var d in drives)
|
||||
{
|
||||
ans.Add(await DisplayableDisk.GetInstance(d));
|
||||
}
|
||||
|
||||
return ans;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获得可显示的目录
|
||||
/// </summary>
|
||||
/// <param name="path">路径</param>
|
||||
/// <returns>文件和文件夹列表</returns>
|
||||
public async Task<List<Displayable>> GetDisplayFileFolderList(string path) {
|
||||
if (path == "/")
|
||||
return await GetDiskDrivesAsync();
|
||||
return await GetRegularFilesAsync(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.FileProperties;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
||||
namespace FileManager_UWP.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 管理文件和文件夹图标的静态类
|
||||
/// </summary>
|
||||
public class IconServer
|
||||
{
|
||||
private IconServer() {
|
||||
}
|
||||
|
||||
public static async Task<BitmapImage> GetFolderIcon(ThumbnailMode mode, uint size) {
|
||||
StorageFolder f = await StorageFolder.GetFolderFromPathAsync("C:\\Windows");
|
||||
BitmapImage img = new BitmapImage();
|
||||
StorageItemThumbnail thumbnail = await f.GetThumbnailAsync(mode, size);
|
||||
await img.SetSourceAsync(thumbnail).AsTask();
|
||||
|
||||
return img;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
<Page
|
||||
x:Class="FileManager_UWP.View.FileListView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:FileManager_UWP.View"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:storage="using:Windows.Storage"
|
||||
xmlns:Custom="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:Custom1="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:model="using:FileManager_UWP.Model"
|
||||
x:Class="FileManager_UWP.View.FileListView"
|
||||
mc:Ignorable="d"
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
|
||||
@@ -23,56 +24,65 @@
|
||||
<Button
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Name="getFileList"
|
||||
Click="GetFileList_Click"
|
||||
Content="获得文件列表"
|
||||
Command="{Binding RefreshCommand}"
|
||||
Content="刷新文件列表"
|
||||
FontSize="20"/>
|
||||
<TextBox
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Width="Auto"
|
||||
Text="C:\"
|
||||
Name="pathText"/>
|
||||
Text="{Binding Path}"
|
||||
/>
|
||||
<ListView
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
ItemsSource="{x:Bind Files}"
|
||||
ItemsSource="{Binding DisplayFileFolderItems}"
|
||||
CanDragItems="False"
|
||||
CanReorderItems="True"
|
||||
AllowDrop="True"
|
||||
AllowDrop="False"
|
||||
SelectionMode="Single"
|
||||
IsItemClickEnabled="True"
|
||||
ItemClick="ListView_ItemClick"
|
||||
SelectedItem="{Binding ListSelectedItem, Mode=TwoWay}"
|
||||
|
||||
IsDoubleTapEnabled="True"
|
||||
IsTapEnabled="True"
|
||||
|
||||
>
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate
|
||||
x:Name="SingleLineDataTemplate"
|
||||
x:DataType="local:DisplayFileFolderItem">
|
||||
<DataTemplate>
|
||||
<StackPanel
|
||||
Orientation="Horizontal"
|
||||
Height="44"
|
||||
Padding="12"
|
||||
AutomationProperties.Name="{x:Bind Name}">
|
||||
<Image Source="Placeholder.png"
|
||||
>
|
||||
<Image Source="{Binding Icon}"
|
||||
Height="16"
|
||||
Width="16"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock
|
||||
Text="{x:Bind Name}"
|
||||
Text="{Binding Name}"
|
||||
VerticalAlignment="Center"
|
||||
Style="{ThemeResource BaseTextBlockStyle}"
|
||||
Foreground="{ThemeResource SystemControlPageTextBaseHighBrush}"
|
||||
Margin="12,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
|
||||
<Custom:Interaction.Behaviors>
|
||||
<Custom1:EventTriggerBehavior EventName="DoubleTapped">
|
||||
<Custom1:InvokeCommandAction Command="{Binding DoubleTappedCommand}"/>
|
||||
</Custom1:EventTriggerBehavior>
|
||||
</Custom:Interaction.Behaviors>
|
||||
|
||||
</ListView>
|
||||
|
||||
<TextBlock
|
||||
Name="DebugPanel"
|
||||
Grid.Row="2">
|
||||
</TextBlock>
|
||||
Text="{Binding DebugText}"
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
/>
|
||||
|
||||
</Grid>
|
||||
</Page>
|
||||
@@ -1,93 +1,16 @@
|
||||
using FileManager_UWP.Server;
|
||||
using GalaSoft.MvvmLight.Ioc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using FileManager_UWP.ViewModel;
|
||||
|
||||
namespace FileManager_UWP.View {
|
||||
public class DisplayFileFolderItem {
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
public bool IsFolder { get; set; }
|
||||
public DisplayFileFolderItem(StorageFolder f) {
|
||||
Name = f.Name;
|
||||
Path = f.Path;
|
||||
IsFolder = true;
|
||||
}
|
||||
public DisplayFileFolderItem(StorageFile f) {
|
||||
Name = f.Name;
|
||||
Path = f.Path;
|
||||
IsFolder = false;
|
||||
}
|
||||
public DisplayFileFolderItem() { }
|
||||
|
||||
public static DisplayFileFolderItem parent(string current) {
|
||||
DisplayFileFolderItem d = new DisplayFileFolderItem();
|
||||
d.Name = "..";
|
||||
d.IsFolder = true;
|
||||
d.Path = current.Substring(0, current.LastIndexOf('\\'));
|
||||
if (d.Path.Length == 2)
|
||||
d.Path += "\\";
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed partial class FileListView : Page {
|
||||
ObservableCollection<DisplayFileFolderItem> Files =
|
||||
new ObservableCollection<DisplayFileFolderItem>();
|
||||
private FileListViewModel vm;
|
||||
public FileListView() {
|
||||
this.InitializeComponent();
|
||||
vm = new FileListViewModel();
|
||||
DataContext = vm;
|
||||
vm.RefreshCommand.Execute(null);
|
||||
}
|
||||
|
||||
private async void UpdateFileList(string path) {
|
||||
StorageFolder folder = null;
|
||||
try {
|
||||
folder = await StorageFolder.GetFolderFromPathAsync(path);
|
||||
} catch (Exception ex) {
|
||||
DebugPanel.Text = ex.Message;
|
||||
}
|
||||
|
||||
if (null != folder) {
|
||||
TreeViewNode rootNode = new TreeViewNode() { Content = folder.Name };
|
||||
IReadOnlyList<StorageFolder> folders = await folder.GetFoldersAsync();
|
||||
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
|
||||
Files.Clear();
|
||||
Files.Add(DisplayFileFolderItem.parent(path));
|
||||
foreach (StorageFolder f in folders) {
|
||||
// DebugPanel.Children.Add(new TextBlock { Text = f.Name });
|
||||
Files.Add(new DisplayFileFolderItem(f));
|
||||
}
|
||||
foreach (StorageFile f in files) {
|
||||
// DebugPanel.Children.Add(new TextBlock { Text = f.Name });
|
||||
Files.Add(new DisplayFileFolderItem(f));
|
||||
// Files.Add(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GetFileList_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) {
|
||||
//StorageFolder picturesFolder = KnownFolders.DocumentsLibrary;
|
||||
//IReadOnlyList<StorageFile> fileList = await picturesFolder.GetFilesAsync();
|
||||
//foreach (StorageFile file in fileList) {
|
||||
// DebugPanel.Children.Add(new TextBlock { Text = file.Name });
|
||||
// Debug.WriteLine(file.Name);
|
||||
//}
|
||||
|
||||
string path = pathText.Text;
|
||||
UpdateFileList(path);
|
||||
}
|
||||
|
||||
private void ListView_ItemClick(object sender, ItemClickEventArgs e) {
|
||||
DisplayFileFolderItem i = e.ClickedItem as DisplayFileFolderItem;
|
||||
if (i.IsFolder) {
|
||||
pathText.Text = i.Path;
|
||||
UpdateFileList(i.Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,83 @@
|
||||
using System;
|
||||
using FileManager_UWP.Model;
|
||||
using FileManager_UWP.Service;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
using Type = FileManager_UWP.Model.Type;
|
||||
|
||||
namespace FileManager_UWP.ViewModel {
|
||||
class FileListViewModel {
|
||||
public class FileListViewModel : ViewModelBase {
|
||||
|
||||
/// <summary>
|
||||
/// 当前路径
|
||||
/// </summary>
|
||||
private string _path = "C:\\";
|
||||
public string Path {
|
||||
get => _path;
|
||||
set => Set(nameof(Path), ref _path, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件和文件夹列表
|
||||
/// </summary>
|
||||
private IEnumerable<Displayable> _displayFileFolderItems;
|
||||
public IEnumerable<Displayable> DisplayFileFolderItems {
|
||||
get => _displayFileFolderItems;
|
||||
set => Set(nameof(DisplayFileFolderItems), ref _displayFileFolderItems, value);
|
||||
}
|
||||
|
||||
private string _debugText;
|
||||
public string DebugText {
|
||||
get => _debugText;
|
||||
set => Set(nameof(DebugText), ref _debugText, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新命令
|
||||
/// </summary>
|
||||
private RelayCommand _refreshCommand;
|
||||
public RelayCommand RefreshCommand =>
|
||||
_refreshCommand ?? (_refreshCommand = new RelayCommand(async () => {
|
||||
var fileService = new FileService();
|
||||
try {
|
||||
var fileList = await fileService.GetDisplayFileFolderList(Path);
|
||||
DisplayFileFolderItems = fileList;
|
||||
} catch (Exception e) {
|
||||
Debug.WriteLine(e.Message);
|
||||
}
|
||||
}));
|
||||
|
||||
private object _listSelectedItem;
|
||||
public object ListSelectedItem {
|
||||
get => _listSelectedItem;
|
||||
set => Set(nameof(ListSelectedItem), ref _listSelectedItem, value);
|
||||
}
|
||||
|
||||
private List<object> _listSelectedItems;
|
||||
public List<object> ListSelectedItems {
|
||||
get => _listSelectedItems;
|
||||
set => Set(nameof(ListSelectedItems), ref _listSelectedItems, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新命令
|
||||
/// </summary>
|
||||
private RelayCommand _doubleTappedCommand;
|
||||
public RelayCommand DoubleTappedCommand =>
|
||||
_doubleTappedCommand ?? (_doubleTappedCommand = new RelayCommand(
|
||||
() =>
|
||||
{
|
||||
Displayable i = ListSelectedItem as Displayable;
|
||||
Debug.WriteLine("Double tapped");
|
||||
if (i != null && (i.Type == Type.Folder || i.Type == Type.Disk))
|
||||
{
|
||||
Debug.WriteLine("double tapped: " + i.Name);
|
||||
Path = i.Path;
|
||||
RefreshCommand.Execute(null);
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user