62 Commits
Author SHA1 Message Date
w-mj 16f4ece443 depend interface 2019-05-22 16:05:48 +08:00
w-mj b3054869c2 configure file demo 2019-05-22 14:05:35 +08:00
w-mj 52ed312582 fix preview view 2019-05-20 22:51:46 +08:00
w-mj 11a576de99 save label in db; 2019-05-20 22:46:49 +08:00
w-mj fb72350f9a command on label list control 2019-05-20 21:54:07 +08:00
w-mj 60a895a552 click and preview! 2019-05-19 23:30:21 +08:00
w-mj f25758992e Merge branch 'master' of github.com:c-my/FileManager-UWP 2019-05-19 23:21:34 +08:00
w-mj 239ebb65c8 use simple ioc for all viewmodels 2019-05-19 23:21:17 +08:00
c-my 5295123843 add scale and scroll support for pdf 2019-05-19 22:37:02 +08:00
w-mj 726263ef69 Merge branch 'master' of github.com:c-my/FileManager-UWP 2019-05-19 22:31:21 +08:00
c-my 30cc4dece2 Merge branch 'master' of https://github.com/c-my/FileManager-UWP
wtf????
2019-05-19 22:18:38 +08:00
c-my 1fa8e2031b add page turning for pdf 2019-05-19 22:18:15 +08:00
w-mj 1ffdbdc84e remove 刷新文件列表 2019-05-19 21:57:31 +08:00
w-mj 30dc52f748 Merge branch 'master' of github.com:c-my/FileManager-UWP 2019-05-19 21:54:03 +08:00
w-mj 54090083e3 fix bug of show virtual folder 2019-05-19 21:53:36 +08:00
c-my 2225c99869 add page buttons 2019-05-19 21:45:25 +08:00
c-my 8515e92656 add default pic for preview 2019-05-19 21:41:07 +08:00
c-my 5029b1100a add path param for preview command 2019-05-19 20:54:32 +08:00
c-my a34730d942 delect some using sentences 2019-05-15 23:57:08 +08:00
c-my 0692b177af add preview support for doc/docx 2019-05-15 22:09:02 +08:00
c-my e7871023fa fix error when analyzing file type 2019-05-04 23:47:00 +08:00
c-my ae77d7eb69 add command for preview 2019-05-04 21:35:47 +08:00
c-my a78a2c4e5c add preview page to main page 2019-05-04 21:15:44 +08:00
c-my e1aa98c869 merged 2019-05-04 21:10:43 +08:00
c-my 99da741a94 show picture preview 2019-05-04 21:08:06 +08:00
Mingjian W 4c2379ffac Merge pull request #2 from w-mj/master
数据绑腚,绑TM的腚"
2019-05-04 20:51:52 +08:00
w-mj c22c359e5d 数据绑腚,绑TM的腚" 2019-05-04 20:50:34 +08:00
c-my 02d75cf374 add preview models 2019-05-04 16:07:10 +08:00
w-mj 14fc8491dd drag delete 2019-04-30 16:20:28 +08:00
w-mj 3936f27fb9 drag label 2019-04-30 15:58:37 +08:00
w-mj 4f6c287dd8 trying drag & drop 2019-04-29 21:46:53 +08:00
w-mj d0beb62fc3 add new label 2019-04-29 21:24:27 +08:00
w-mj 7700bf9ea4 add button 2019-04-29 20:59:03 +08:00
w-mj f42874758f auto trunc label 2019-04-29 20:23:12 +08:00
w-mj 68be369e39 use Label item 2019-04-29 19:54:49 +08:00
w-mj ae050cb425 make background button transprant 2019-04-29 19:28:25 +08:00
w-mj e6a76ddc69 auto measure canvas's width 2019-04-29 19:09:35 +08:00
w-mj 55cb903d1b label animation 2019-04-29 16:31:19 +08:00
w-mj c9d18b31bf get customed resource 2019-04-29 14:51:47 +08:00
w-mj c80e895d4a add Element in canvas 2019-04-29 10:51:53 +08:00
w-mj f4062dc5a6 bind observable collection on labelListView 2019-04-28 21:55:02 +08:00
w-mj 2293d207c5 seperate dictionary file 2019-04-28 19:23:45 +08:00
w-mj b9988cbe4c add label in Displayable 2019-04-28 15:58:46 +08:00
w-mj d3a281e10a get ico's thumbnail in listview may return null 2019-04-28 12:12:33 +08:00
w-mj 6926e2d268 hint no permission 2019-04-26 20:27:49 +08:00
w-mj e36db2dec9 fit the bug of get parent of a virtual folder 2019-04-15 20:56:17 +08:00
w-mj 94b068ec40 use json serialization 2019-04-15 20:46:18 +08:00
w-mj c54e096162 open virtual folder 2019-04-04 22:53:33 +08:00
w-mj 6dda41d62e sort by name 2019-04-04 22:02:02 +08:00
w-mj 2bcfbd1726 show virtual floder 2019-04-04 21:54:55 +08:00
w-mj 5c910aaed7 Icon Server 2019-04-04 21:35:48 +08:00
w-mj 1a3b89bdf7 use Path.GetDirectoryName 2019-04-04 21:01:01 +08:00
w-mj 972da36877 change IDisplayable from interface to abstract class 2019-04-04 20:38:14 +08:00
w-mj bf46dc5622 go back 2019-04-04 20:10:52 +08:00
w-mj ee308d245d fix the bug of cant enter folder 2019-04-02 11:44:18 +08:00
w-mj d0d5d9bfd5 reconstruct file list with warpper 2019-04-02 11:38:04 +08:00
w-mj 85ff350339 handle double tapped event in a more elegant method 2019-04-01 19:19:39 +08:00
w-mj 0646b49a62 double click enter folder 2019-03-30 17:30:58 +08:00
w-mj b449231adc show icon 2019-03-30 15:33:34 +08:00
w-mj 6caae160a1 reconstruct filelist by mvvm 2019-03-30 13:22:06 +08:00
w-mj bbd3476670 make file list mvvm 2019-03-29 11:51:19 +08:00
w-mj 0931cb9434 double click enter 2019-03-27 14:07:45 +08:00
39 changed files with 1885 additions and 147 deletions

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
{
"VirtualFolders": [
{
"name": "PROGRAMS",
"Includes": [
"C:\\Program Files (x86)",
"C:\\Program Files",
"C:\\Users\\wming\\AppData\\Local\\Programs"
]
}
]
}
+6
View File
@@ -0,0 +1,6 @@
using System;
namespace DataAccessLibrary {
public class Class1 {
}
}
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.8" />
</ItemGroup>
</Project>
+82
View File
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Data.Sqlite;
namespace DataAccessLibrary.Service {
public class LabelService {
public static void InitializeDatabase() {
using (SqliteConnection db =
new SqliteConnection("Filename=awesomefilemanager.db")) {
db.Open();
String tableCommand = "CREATE TABLE IF NOT " +
"EXISTS Labels (id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"Path NVARCHAR(2048) NOT NULL, LABEL NVARCHAR(2048) NOT NULL)";
SqliteCommand createTable = new SqliteCommand(tableCommand, db);
createTable.ExecuteReader();
}
}
public static void AddLabel(string path, string label) {
using (SqliteConnection db =
new SqliteConnection("Filename=awesomefilemanager.db")) {
db.Open();
SqliteCommand insertCommand = new SqliteCommand();
insertCommand.Connection = db;
// Use parameterized query to prevent SQL injection attacks
insertCommand.CommandText = "INSERT INTO Labels (Path, LABEL) VALUES (@Path, @Label);";
insertCommand.Parameters.AddWithValue("@Path", path);
insertCommand.Parameters.AddWithValue("@Label", label);
insertCommand.ExecuteReader();
db.Close();
}
}
public static List<String> GetLabels(string path) {
List<String> entries = new List<string>();
using (SqliteConnection db =
new SqliteConnection("Filename=awesomefilemanager.db")) {
db.Open();
SqliteCommand selectCommand = new SqliteCommand
("SELECT LABEL from Labels where path=@Path", db);
selectCommand.Parameters.AddWithValue("@Path", path);
SqliteDataReader query = selectCommand.ExecuteReader();
while (query.Read()) {
entries.Add(query.GetString(0));
}
db.Close();
}
return entries;
}
public static void RemoveLabel(string path, string label) {
List<String> entries = new List<string>();
using (SqliteConnection db =
new SqliteConnection("Filename=awesomefilemanager.db")) {
db.Open();
SqliteCommand removeCommand = new SqliteCommand
("DELETE from Labels where path=@Path and label=@Label", db);
removeCommand.Parameters.AddWithValue("@Path", path);
removeCommand.Parameters.AddWithValue("@Label", label);
SqliteDataReader query = removeCommand.ExecuteReader();
db.Close();
}
}
}
}
+31 -2
View File
@@ -1,22 +1,30 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.489
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.202
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileManager_UWP", "FileManager_UWP\FileManager_UWP.csproj", "{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}"
ProjectSection(ProjectDependencies) = postProject
{FAA7FCD7-5380-436C-A615-8612D798224D} = {FAA7FCD7-5380-436C-A615-8612D798224D}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccessLibrary", "DataAccessLibrary\DataAccessLibrary.csproj", "{FAA7FCD7-5380-436C-A615-8612D798224D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM = Debug|ARM
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM = Release|ARM
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|Any CPU.ActiveCfg = Debug|x86
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|ARM.ActiveCfg = Debug|ARM
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|ARM.Build.0 = Debug|ARM
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|ARM.Deploy.0 = Debug|ARM
@@ -29,6 +37,7 @@ Global
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|x86.ActiveCfg = Debug|x86
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|x86.Build.0 = Debug|x86
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|x86.Deploy.0 = Debug|x86
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|Any CPU.ActiveCfg = Release|x86
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|ARM.ActiveCfg = Release|ARM
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|ARM.Build.0 = Release|ARM
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|ARM.Deploy.0 = Release|ARM
@@ -41,6 +50,26 @@ Global
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|x86.ActiveCfg = Release|x86
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|x86.Build.0 = Release|x86
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|x86.Deploy.0 = Release|x86
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|ARM.ActiveCfg = Debug|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|ARM.Build.0 = Debug|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|ARM64.Build.0 = Debug|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|x64.ActiveCfg = Debug|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|x64.Build.0 = Debug|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|x86.ActiveCfg = Debug|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|x86.Build.0 = Debug|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|Any CPU.Build.0 = Release|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|ARM.ActiveCfg = Release|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|ARM.Build.0 = Release|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|ARM64.ActiveCfg = Release|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|ARM64.Build.0 = Release|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|x64.ActiveCfg = Release|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|x64.Build.0 = Release|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|x86.ActiveCfg = Release|Any CPU
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+9 -1
View File
@@ -2,6 +2,14 @@
x:Class="FileManager_UWP.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FileManager_UWP">
xmlns:local="using:FileManager_UWP"
xmlns:viewModel="using:FileManager_UWP.ViewModel"
>
<Application.Resources>
<ResourceDictionary>
<viewModel:ViewModelLocator x:Key ="ViewModelLocator"></viewModel:ViewModelLocator>
</ResourceDictionary>
</Application.Resources>
</Application>
+5 -2
View File
@@ -1,4 +1,6 @@
using FileManager_UWP.Server;
using FileManager_UWP.Service;
using FileManager_UWP.View;
using FileManager_UWP.ViewModel;
using GalaSoft.MvvmLight.Ioc;
using System;
using System.Collections.Generic;
@@ -74,7 +76,8 @@ namespace FileManager_UWP
Window.Current.Activate();
}
SimpleIoc.Default.Register<FileServer>();
// SimpleIoc.Default.Register<FileService>();
// SimpleIoc.Default.Register<FileListViewModel>();
}
/// <summary>
@@ -0,0 +1,408 @@
using FileManager_UWP.Model;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
// The Templated Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234235
namespace FileManager_UWP.Controls {
public class LabelListChangeEvent {
public enum EventType { Add, Remove };
public LabelListControl LabelListControl;
public EventType eventType;
public LabelItem label;
}
/// <summary>
/// 一个可以自动折叠的标签菜单
/// </summary>
public class LabelListControl: ItemsControl {
// public delegate void OnLabelChanged(LabelItem item);
public RelayCommand<LabelListChangeEvent> OnAddLabel = null, OnRemoveLabel = null;
//private int _collpse_distance = 22;
//private List<int> _expanded_position = new List<int>();
private Storyboard _collpse_story_board = new Storyboard();
private Storyboard _expand_story_board = new Storyboard();
private Duration _animate_during = new Duration(TimeSpan.FromMilliseconds(200));
private Canvas labelListCanvas;
private bool _adding_new_label = false;
private bool _hovering = false, _draging = false;
private int shit_cnt = 0;
private ResourceDictionary genericResourceDictionary;
public LabelListControl() {
this.DefaultStyleKey = typeof(LabelListControl);
var uri = new Uri("ms-appx:///Controls/LabelListControl.xaml");
genericResourceDictionary = new ResourceDictionary();
Application.LoadComponent(genericResourceDictionary, uri);
Loaded += LabelListControl_Loaded;
//AllowDrop = true;
//RegisterPropertyChangedCallback(ItemsControl.ItemsSourceProperty, this.tbTagChangedCallback);
}
private void LabelListControl_Loaded(object sender, RoutedEventArgs e) {
init();
update();
}
private void tbTagChangedCallback(DependencyObject sender, DependencyProperty dp) {
if (dp == ItemsControl.ItemsSourceProperty) {
// These lines produce the same result.
Debug.WriteLine("The tag has been set to " + sender.ToString());
Debug.WriteLine("The tag has been set to " + sender.GetValue(dp));
ItemsSource = sender.GetValue(dp);
shit_cnt++;
if (shit_cnt >= 2) {
init();
update();
}
}
}
/// <summary>
/// 监听ItemSource改变
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ItemsSource_CollectionChanged(object sender,
System.Collections.Specialized.NotifyCollectionChangedEventArgs e) {
update();
}
private void SetElasticAnimate(Button b, int expanded_position) {
DoubleAnimation expand_animate = new DoubleAnimation();
expand_animate.From = null; // labelListCanvas.Children.Count * 22;
expand_animate.To = expanded_position;
expand_animate.Duration = _animate_during;
//expand_animate.Completed += Animate_Completed;
_expand_story_board.Children.Add(expand_animate);
Storyboard.SetTarget(expand_animate, b);
Storyboard.SetTargetProperty(expand_animate, "(Canvas.Left)");
DoubleAnimation collpse_animate = new DoubleAnimation();
collpse_animate.From = null; // expanded_position;
collpse_animate.To = labelListCanvas.Children.Count * 20;
collpse_animate.Duration = _animate_during;
//collpse_animate.Completed += Animate_Completed;
_collpse_story_board.Children.Add(collpse_animate);
Storyboard.SetTarget(collpse_animate, b);
Storyboard.SetTargetProperty(collpse_animate, "(Canvas.Left)");
}
private DependencyProperty LabelProperty = DependencyProperty.Register(
"LabelItem", typeof(LabelItem), typeof(Button), null);
/// <summary>
/// 当ItemsSource改变时,绘制标签,注册动画
/// </summary>
private void update() {
Debug.WriteLine("ObservableCollection update");
var itemsSource = ItemsSource as ObservableCollection<LabelItem>;
labelListCanvas.Children.Clear();
_collpse_story_board.Stop();
_collpse_story_board.Children.Clear();
_expand_story_board.Stop();
_expand_story_board.Children.Clear();
int expanded_position = 0;
foreach (LabelItem label in itemsSource) {
Button b = new Button();
b.SetValue(LabelProperty, label);
b.Content = label.tag;
b.Background = new SolidColorBrush(label.color);
b.SetValue(Canvas.LeftProperty, expanded_position);
b.Style = (Style)genericResourceDictionary["LabelButtonStyle"];
b.Click += B_Click;
//b.AddHandler(PointerPressedEvent, new PointerEventHandler(B_PointerPressed), true);
//b.AddHandler(PointerReleasedEvent, new PointerEventHandler(B_PointerReleased), true);
InitManipulationTransforms(b);
SetElasticAnimate(b, expanded_position);
expanded_position += label.tag.Count() * 14 + 15;
labelListCanvas.Children.Add(b);
}
Button add_button = new Button();
SetElasticAnimate(add_button, expanded_position);
add_button.Content = "+";
add_button.SetValue(Canvas.LeftProperty, expanded_position);
add_button.Style = (Style)genericResourceDictionary["LabelButtonStyle"];
add_button.Click += Add_Click;
DoubleAnimation appear_animate = new DoubleAnimation {
To = 100,
Duration = _animate_during
};
appear_animate.Completed += Animate_Completed;
_expand_story_board.Children.Add(appear_animate);
Storyboard.SetTarget(appear_animate, add_button);
Storyboard.SetTargetProperty(appear_animate, "Opacity");
DoubleAnimation disappear_animate = new DoubleAnimation {
Duration = _animate_during
};
// 如果没有标签,则+不自动隐藏
if (itemsSource.Count > 0)
disappear_animate.To = 0;
else
disappear_animate.To = 100;
disappear_animate.Completed += Animate_Completed;
_collpse_story_board.Children.Add(disappear_animate);
Storyboard.SetTarget(disappear_animate, add_button);
Storyboard.SetTargetProperty(disappear_animate, "Opacity");
labelListCanvas.Children.Add(add_button);
measure();
LabelListCanvas_PointerExited(null, null);
}
//private bool _pressing_label = false;
//private void B_PointerPressed(object sender, PointerRoutedEventArgs e) {
// Debug.WriteLine("label pressed");
// _pressing_label = true;
//}
//private void B_PointerReleased(object sender, PointerRoutedEventArgs e) {
// Debug.WriteLine("label release");
// _pressing_label = false;
//}
private void B_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) {
TransformGroup transforms = (sender as Button).RenderTransform as TransformGroup;
MatrixTransform previousTransform = transforms.Children[0] as MatrixTransform;
CompositeTransform deltaTransform = transforms.Children[1] as CompositeTransform;
previousTransform.Matrix = transforms.Value;
// Get center point for rotation
Point center = previousTransform.TransformPoint(new Point(e.Position.X, e.Position.Y));
deltaTransform.CenterX = center.X;
deltaTransform.CenterY = center.Y;
// Look at the Delta property of the ManipulationDeltaRoutedEventArgs to retrieve
// the rotation, scale, X, and Y changes
deltaTransform.Rotation = e.Delta.Rotation;
deltaTransform.TranslateX = e.Delta.Translation.X;
deltaTransform.TranslateY = e.Delta.Translation.Y;
}
private void InitManipulationTransforms(Button b) {
var transforms = new TransformGroup();
var previousTransform = new MatrixTransform();
previousTransform.Matrix = Matrix.Identity;
var deltaTransform = new CompositeTransform();
transforms.Children.Add(previousTransform);
transforms.Children.Add(deltaTransform);
b.RenderTransform = transforms;
b.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY;
b.ManipulationDelta += B_ManipulationDelta;
b.ManipulationStarted += B_ManipulationStarted;
b.ManipulationCompleted += B_ManipulationCompleted;
}
private Point _origin;
private void B_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) {
Debug.WriteLine("Manipulation finish");
_draging = false;
ObservableCollection<LabelItem> itemsSource = ItemsSource as ObservableCollection<LabelItem>;
var toRemove = (sender as Button).GetValue(LabelProperty) as LabelItem;
itemsSource.Remove(toRemove);
update();
OnRemoveLabel?.Execute(new LabelListChangeEvent {
label = toRemove,
LabelListControl = this,
eventType = LabelListChangeEvent.EventType.Remove
});
}
private void B_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e) {
Debug.WriteLine("Manipulation start");
_origin = e.Position;
_draging = true;
}
private void B_DragLeave(object sender, DragEventArgs e) {
var itemsSource = ItemsSource as ObservableCollection<LabelItem>;
Button b = sender as Button;
var tag = b.Content as string;
Debug.WriteLine("Drag Leave " + tag);
int index = itemsSource.ToList().FindIndex(x => x.tag == tag);
itemsSource.RemoveAt(index);
}
/// <summary>
/// 点击标签
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void B_Click(object sender, RoutedEventArgs e) {
Button b = sender as Button;
Debug.WriteLine(b.Content);
}
/// <summary>
/// 点击新建标签
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Add_Click(object sender, RoutedEventArgs e) {
Debug.WriteLine("Click Add Label");
Button b = sender as Button;
TextBox textBox = new TextBox();
textBox.Height = b.ActualHeight;
textBox.FontSize = b.FontSize;
textBox.BorderThickness = new Thickness(0);
textBox.Padding = new Thickness(4, 4, 4, 4);
textBox.Margin = new Thickness(0, 0, 0, 0);
textBox.GotFocus += TextBox_GotFocus;
textBox.LostFocus += TextBox_LostFocus;
b.Content = textBox;
}
private void TextBox_LostFocus(object sender, RoutedEventArgs e) {
_adding_new_label = false;
TextBox tb = sender as TextBox;
var NewLabel = new LabelItem(tb.Text);
if (tb.Text.Count() != 0)
(ItemsSource as ObservableCollection<LabelItem>).Add(NewLabel);
if (!_hovering)
LabelListCanvas_PointerExited(null, null);
// 调用回调函数
OnAddLabel?.Execute(new LabelListChangeEvent {
label = NewLabel,
LabelListControl = this,
eventType = LabelListChangeEvent.EventType.Add
});
}
private void TextBox_GotFocus(object sender, RoutedEventArgs e) {
_adding_new_label = true;
}
/// <summary>
/// 动画完成
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Animate_Completed(object sender, object e) {
measure();
}
/// <summary>
/// 计算控件尺寸
/// </summary>
private void measure() {
Button lb = labelListCanvas.Children.Last() as Button;
lb.Content = "+";
labelListCanvas.Height = lb.ActualHeight;
double left = (double)lb.GetValue(Canvas.LeftProperty);
labelListCanvas.Width = left + lb.ActualWidth;
}
/// <summary>
/// 鼠标离开
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelListCanvas_PointerExited(object sender, PointerRoutedEventArgs e) {
_hovering = false;
// 正在输入新标签时不折叠
if (!_adding_new_label && !_draging) {
_collpse_story_board.Begin();
for (int i = 0; i < labelListCanvas.Children.Count - 2; i++) {
Button b = labelListCanvas.Children[i] as Button;
b.Content = string.Format("{0}...", (b.Content as string)[0]);
}
}
}
/// <summary>
/// 鼠标进入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelListCanvas_PointerEntered(object sender, PointerRoutedEventArgs e) {
_hovering = true;
if (!_adding_new_label && !_draging) {
_expand_story_board.Begin();
var labels = ItemsSource as ObservableCollection<LabelItem>;
for (int i = 0; i < labels.Count - 1; i++) {
Button b = labelListCanvas.Children[i] as Button;
b.Content = labels[i].tag;
}
}
}
/// <summary>
/// 初始化控件
/// </summary>
private void init() {
Debug.WriteLine("INIT LABEL LIST CONTROL");
var itemsSource = ItemsSource as ObservableCollection<LabelItem>;
if (ItemsSource != null && itemsSource == null) {
ItemsSource = new ObservableCollection<LabelItem>(ItemsSource as IEnumerable<LabelItem>);
itemsSource = ItemsSource as ObservableCollection<LabelItem>;
}
//var itemsSource = GetValue(ItemsControl.ItemsSourceProperty) as ObservableCollection<LabelItem>;
itemsSource.CollectionChanged += ItemsSource_CollectionChanged;
Button labelListButton = (Button)GetTemplateChild("LabelListPresenter");
labelListButton.PointerEntered += LabelListCanvas_PointerEntered;
labelListButton.PointerExited += LabelListCanvas_PointerExited;
labelListCanvas = (Canvas)GetTemplateChild("LabelListCanvas");
}
/// <summary>
/// 该Control被加载时调用
/// </summary>
protected override void OnApplyTemplate() {
//shit_cnt++;
//if (shit_cnt >= 2) {
//}
}
//public new static readonly DependencyProperty ItemsSourceProperty = //Notice this is static. It's bound to an internal static hash table of some sort; I use to know exactly but forgot.
//DependencyProperty.Register(
// "ItemsSources",
// /*The name of the property to register against.
// * The static version is always the name of the property ended with Property
// * i.e. SomeValue property is SomeValueProperty dependency property */
// typeof(ObservableCollection<LabelItem>), //This is the type used to describe the property.
// typeof(LabelListControl), //This is the type the dependency property relates to.
// /* Below this is the magic. It's where we supply the property meta data and can be delivered different ways.
// * For this example I will supply only the default value and the event we want to use when the value is changed.
// * Note:
// * The event we supply is fired ONLY if the value is changed. This event is what we need to use to handle changes in the setter to cover binding operations as well. */
// new PropertyMetadata(default(ObservableCollection<LabelItem>),
// /* This is the default value the dependency property will have.
// * It can be whatever you decide but make sure it works with the same type or you'll most likely get an error. */
// /* This is the event fired when the value changes.
// * Note: Dependency properties binding and events always operate on the UI thread. Cross threading will throw exceptions. */
// new PropertyChangedCallback((s, e) => {
// var ctr = s as LabelListControl; //The sender of the callback will always be of the type it's from.
// /* The values given from the e argument for OldValue and NewValue should be of type int in this example...
// * but since we can't gaurantee the property is setup properly before here I always add a check. */
// if (e.OldValue != e.NewValue) {
// ctr.ItemsSource = e.NewValue;
// }
// //if (e.OldValue is int oldValue) { }
// //if (e.NewValue is int newValue) {
// // /* Now do what you want with the information. This is where you need to do custom work instead of using the setter.
// // * Note: If you need to work on something in the MainPage remember this is a static event and you'll need to refer to the sender or s value in this case.
// // * I've converted s to the variable mainPage for easy referencing here. */
// // ctr.ItemsSource = newValue; //Note: The custom control should bind to this as well via XAML making this pointless. I set the value here just for educational purposes.
// //}
// })));
}
}
@@ -0,0 +1,55 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FileManager_UWP.Controls"
xmlns:model="using:FileManager_UWP.Model">
<Style TargetType="Button" x:Key="LabelButtonStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="RootGrid"
CornerRadius="10"
Background="{TemplateBinding Background}"
BorderThickness="1"
BorderBrush="Blue">
<ContentPresenter
x:Name="ContentPresenter"
Padding="4 4 4 4"
/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="local:LabelListControl">
<Setter Property="ItemsSource" Value="{Binding ItemsSource}"></Setter>
<Setter Property="DataContext" Value="{Binding}"></Setter>
<!--<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate x:DataType="model:LabelItem"></DataTemplate>
</Setter.Value>
</Setter>-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:LabelListControl">
<Button Name="LabelListPresenter">
<Button.Resources>
<ResourceDictionary>
<SolidColorBrush x:Key="ButtonBackground" Color="Transparent"/>
<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="Transparent"/>
<SolidColorBrush x:Key="ButtonBackgroundPressed" Color="Transparent"/>
<SolidColorBrush x:Key="ButtonBorderBrushPressed" Color="Transparent"/>
<SolidColorBrush x:Key="ButtonBorderBrushPointerOver" Color="Transparent"/>
</ResourceDictionary>
</Button.Resources>
<Canvas Name="LabelListCanvas" AllowDrop="True"></Canvas>
</Button>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
+65 -3
View File
@@ -18,7 +18,7 @@
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>
<PackageCertificateKeyFile>FileManager_UWP_TemporaryKey.pfx</PackageCertificateKeyFile>
<PackageCertificateThumbprint>5058C24840B066026EEA46E892616A9B0CF9D282</PackageCertificateThumbprint>
<PackageCertificateThumbprint>3345EE1782F80611CAB226C70864DC55EDEBBCEE</PackageCertificateThumbprint>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
@@ -120,9 +120,23 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Server\FileServer.cs" />
<Compile Include="Controls\LabelListControl.cs" />
<Compile Include="Model\DisplayableDisk.cs" />
<Compile Include="Model\DisplayableFile.cs" />
<Compile Include="Model\DisplayableFolder.cs" />
<Compile Include="Model\DisplayableSpecial.cs" />
<Compile Include="Model\Displayable.cs" />
<Compile Include="Model\PreviewModel.cs" />
<Compile Include="Model\FolderSetting.cs" />
<Compile Include="Model\LabelItem.cs" />
<Compile Include="Model\VirtualFolder.cs" />
<Compile Include="Service\FileService.cs" />
<Compile Include="Service\IconServer.cs" />
<Compile Include="Service\PreviewService.cs" />
<Compile Include="ViewModel\FileListViewModel.cs" />
<Compile Include="ViewModel\MainPageViewModel.cs" />
<Compile Include="ViewModel\PreviewViewModel.cs" />
<Compile Include="ViewModel\ViewModelLocator.cs" />
<Compile Include="View\FileListView.xaml.cs">
<DependentUpon>FileListView.xaml</DependentUpon>
</Compile>
@@ -133,6 +147,9 @@
<Compile Include="View\PreviewView.xaml.cs">
<DependentUpon>PreviewView.xaml</DependentUpon>
</Compile>
<Compile Include="View\TestLabelView.xaml.cs">
<DependentUpon>TestLabelView.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
@@ -155,6 +172,14 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="Controls\LabelListControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Themes\Generic.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="View\FileListView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -167,17 +192,54 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="View\TestLabelView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<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="NETStandard.Library">
<Version>2.0.3</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.1</Version>
</PackageReference>
<PackageReference Include="sqlite-net-pcl">
<Version>1.5.231</Version>
</PackageReference>
<PackageReference Include="Syncfusion.DocIORenderer.NET.Core">
<Version>17.1.0.47</Version>
</PackageReference>
<PackageReference Include="Syncfusion.Presentation.UWP">
<Version>17.1.0.47</Version>
</PackageReference>
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core">
<Version>17.1.0.47</Version>
</PackageReference>
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core">
<Version>17.1.0.47</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\" />
<ProjectReference Include="..\DataAccessLibrary\DataAccessLibrary.csproj">
<Project>{faa7fcd7-5380-436c-a615-8612d798224d}</Project>
<Name>DataAccessLibrary</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
+27
View File
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using Windows.UI.Xaml.Media.Imaging;
namespace FileManager_UWP.Model {
public enum Type{
Folder = 0, VirtualFolder, Disk, File
}
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 abstract List<LabelItem> Labels { get; }
public int CompareTo(object obj) {
if (this.Type != (obj as Displayable).Type)
return this.Type - (obj as Displayable).Type;
if (obj is Displayable another) {
return Name.CompareTo(another.Name);
}
throw new NotSupportedException();
}
}
}
+41
View File
@@ -0,0 +1,41 @@
using DataAccessLibrary.Service;
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 readonly List<LabelItem> _labels;
private DisplayableDisk(DriveInfo d) {
_drive = d;
_labels = LabelService.GetLabels(d.Name).Select((x) => new LabelItem(x)).ToList();
}
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;
public override List<LabelItem> Labels => _labels;
}
}
+37
View File
@@ -0,0 +1,37 @@
using DataAccessLibrary.Service;
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 readonly List<LabelItem> _labels;
private DisplayableFile(StorageFile f) {
_file = f;
_icon = new BitmapImage();
_labels = LabelService.GetLabels(f.Path).Select((x) => new LabelItem(x)).ToList();
}
public static async Task<DisplayableFile> GetInstanceAsync(StorageFile f) {
DisplayableFile obj = new DisplayableFile(f);
var thumbnail = await f.GetThumbnailAsync(ThumbnailMode.SingleItem, 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;
public override List<LabelItem> Labels => _labels;
}
}
@@ -0,0 +1,55 @@
using DataAccessLibrary.Service;
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 readonly List<LabelItem> _labels;
private DisplayableFolder(StorageFolder f) {
_folder = f;
_icon = new BitmapImage();
_labels = LabelService.GetLabels(f.Path).Select((x) => new LabelItem(x)).ToList();
}
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;
public override List<LabelItem> Labels => _labels;
}
}
@@ -0,0 +1,26 @@
using DataAccessLibrary.Service;
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;
Labels = LabelService.GetLabels(Path).Select((x) => new LabelItem(x)).ToList();
}
public override string Name { get; }
public override string Path { get; }
public override Type Type { get; }
public override BitmapImage Icon { get; }
public override List<LabelItem> Labels { get; }
}
}
+39
View File
@@ -0,0 +1,39 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Data.Json;
using Windows.Storage;
namespace FileManager_UWP.Model
{
public class FolderSetting {
public List<VirtualFolder> VirtualFolders { get; set; }
public FolderSetting() {
VirtualFolders = new List<VirtualFolder>();
}
static public async Task<FolderSetting> GetInstance(StorageFolder folder) {
var confPath = folder.Path;
if (confPath.EndsWith('\\'))
confPath += ".awesomefilemanager";
else
confPath += "\\.awesomefilemanager";
FolderSetting folderSetting;
try {
var confFile = await StorageFile.GetFileFromPathAsync(confPath);
var jsonString = await FileIO.ReadTextAsync(confFile);
folderSetting = JsonConvert.DeserializeObject<FolderSetting>(jsonString);
} catch (FileNotFoundException) {
Debug.WriteLine("no configure file in " + confPath);
folderSetting = new FolderSetting();
}
return folderSetting;
}
}
}
+16
View File
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using Windows.UI;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileManager_UWP.Model {
public class LabelItem {
public string tag;
public Color color = Color.FromArgb(0xf0, 0xC6, 0xE2, 0xFF);
public LabelItem(string tag) {
this.tag = tag;
}
}
}
+28
View File
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileManager_UWP.Model
{
public class PreviewModel
{
public const string PNGType = "13780";
public const string JPGType = "255216";
public const string GIFType = "7173";
public const string BMPType = "6677";
public const string OfficeOldType = "208207";
public const string OfficeXType = "8075";
public const string PDFType = "3780";
public enum FileType
{
NAT = 0,//not a type
Picture,
Pdf,
Office,
}
}
}
+16
View File
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using Windows.Data.Json;
using Windows.UI.StartScreen;
namespace FileManager_UWP.Model
{
public class VirtualFolder {
public string Name { get; set; }
public List<string> Includes { get; set; }
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:wincap="https://schemas.microsoft.com/appx/manifest/foundation/windows10/windowscapabilities" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap mp rescap">
<Identity Name="c339ceaf-658a-4c74-9c4b-5b956758df7c" Publisher="CN=MingjianW" Version="1.0.0.0" />
<Identity Name="c339ceaf-658a-4c74-9c4b-5b956758df7c" Publisher="CN=wming" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="c339ceaf-658a-4c74-9c4b-5b956758df7c" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>FileManager_UWP</DisplayName>
+5 -2
View File
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -26,4 +27,6 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ComVisible(false)]
[assembly: ComVisible(false)]
[assembly: NeutralResourcesLanguage("zh")]
-20
View File
@@ -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;
}
}
}
+155
View File
@@ -0,0 +1,155 @@
using FileManager_UWP.Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.FileProperties;
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>
internal class FileService: IFileService {
private async Task<List<Displayable>> GetVirtualFolderAsync(string path) {
// var splitList = path.Split('\\');
//var virtualFolderName = path.Substring(0, path.LastIndexOf('\\'));
//path = path.Substring(path.LastIndexOf('\\'));
var directoryName = Path.GetDirectoryName(path);
var virtualFolderName = path.Substring(path.LastIndexOf('\\') + 1);
if (directoryName == null)
throw new FileNotFoundException();
StorageFolder folder;
folder = await StorageFolder.GetFolderFromPathAsync(directoryName);
FolderSetting folderSetting = await FolderSetting.GetInstance(folder);
VirtualFolder virtualFolder = folderSetting.VirtualFolders.Find(x => x.Name == virtualFolderName);
if (virtualFolder == null)
throw new FileNotFoundException();
var displayFileFolderItems = new List<Displayable>
{
new DisplayableSpecial(
"..",
directoryName,
Type.Folder,
await IconServer.GetFolderIcon(ThumbnailMode.ListView, 32)
)
};
foreach (var virtualFilderItem in virtualFolder.Includes) {
displayFileFolderItems.AddRange(
await GetRegularFilesAsync(virtualFilderItem, false)
);
}
return displayFileFolderItems;
}
/// <summary>
/// 获得普通文件夹中的文件
/// </summary>
/// <param name="path"></param>
/// <param name="withParent"></param>
/// <returns></returns>
private async Task<List<Displayable>> GetRegularFilesAsync(string path, bool withParent = true) {
StorageFolder folder = null;
try {
folder = await StorageFolder.GetFolderFromPathAsync(path);
} catch (System.UnauthorizedAccessException) {
throw;
} catch (Exception e) {
Debug.WriteLine(e.Message + " " + path + " try to get Virtual Folder");
try {
return await GetVirtualFolderAsync(path);
} catch (Exception) {
Debug.WriteLine(e.Message);
throw;
}
}
// 打开文件夹
var displayFileFolderItems = new List<Displayable>();
if (withParent)
displayFileFolderItems.Add(await DisplayableFolder.GetParentAsync(folder));
// 读取配置文件
FolderSetting folderSetting = await FolderSetting.GetInstance(folder);
foreach (var virtualFolder in folderSetting.VirtualFolders) {
displayFileFolderItems.Add(new DisplayableSpecial(
virtualFolder.Name,
folder.Path + "\\" + virtualFolder.Name,
Type.VirtualFolder,
await IconServer.GetFolderIcon(ThumbnailMode.ListView, 32)));
}
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)
//);
try {
foreach (var file in folders)
displayFileFolderItems.Add(
await DisplayableFolder.GetInstanceAsync(file));
foreach (var file in files)
displayFileFolderItems.Add(
await DisplayableFile.GetInstanceAsync(file));
} catch (Exception e) {
Debug.WriteLine("Exception at appending dispalyFileFolder " + e.Message);
}
return displayFileFolderItems;
}
/// <summary>
/// 获得磁盘驱动器列表
/// </summary>
/// <returns></returns>
private async Task<List<Displayable>> GetDiskDrivesAsync() {
var drives = DriveInfo.GetDrives();
var 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) {
try {
List<Displayable> ans;
if (path == "/")
ans = await GetDiskDrivesAsync();
else
ans = await GetRegularFilesAsync(path);
ans.Sort();
return ans;
} catch (Exception) {
throw;
}
}
}
}
+29
View File
@@ -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;
}
}
}
+204
View File
@@ -0,0 +1,204 @@
using FileManager_UWP.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Data.Pdf;
using Windows.Storage;
using Windows.Storage.Streams;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIORenderer;
namespace FileManager_UWP.Service
{
class PreviewService
{
private static string defaultPicPath = "ms-appx:///Assets/SplashScreen.scale-200.png";
private static PreviewModel.FileType currentFileType = PreviewModel.FileType.NAT;
private static uint currentPdfCount = 0;
private static uint currentPdfPage = 0;
private static string currentPdfPath = "";
public static bool IsCurrentPDF()
{
return currentFileType == PreviewModel.FileType.Pdf;
}
/// <summary>
/// 判断文件的类型(图片/PDF文档)
/// </summary>
/// <param name="path">文件路径</param>
/// <returns>文件类型</returns>
public static async Task<PreviewModel.FileType> GetFileTypeAsync(string path)
{
StorageFile file;
try
{
file = await StorageFile.GetFileFromPathAsync(path);
}
catch (Exception)
{
return PreviewModel.FileType.NAT;
}
var buffer = await Windows.Storage.FileIO.ReadBufferAsync(file);
string res = "";
using (var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(buffer))
{
var byt = dataReader.ReadByte();
res = byt.ToString();
byt = dataReader.ReadByte();
res += byt.ToString();
}
switch (res)
{
case PreviewModel.PNGType:
case PreviewModel.GIFType:
case PreviewModel.JPGType:
case PreviewModel.BMPType:
return PreviewModel.FileType.Picture;
case PreviewModel.PDFType:
return PreviewModel.FileType.Pdf;
case PreviewModel.OfficeXType:
case PreviewModel.OfficeOldType:
return PreviewModel.FileType.Office;
default:
return PreviewModel.FileType.NAT;
}
}
/// <summary>
/// 获得Word文件的预览图
/// </summary>
/// <param name="path">文件路径</param>
/// <returns>Word的预览</returns>
public static async Task<IRandomAccessStream> GetWordPreviewAsync(string path)
{
StorageFile file = await StorageFile.GetFileFromPathAsync(path);
var res = await file.OpenAsync(FileAccessMode.Read);
WordDocument wordDocument = new WordDocument();
wordDocument.Open(res.AsStream(), Syncfusion.DocIO.FormatType.Automatic);
DocIORenderer render = new DocIORenderer();
Syncfusion.Pdf.PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
render.Dispose();
wordDocument.Dispose();
InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
pdfDocument.Save(ms.AsStream());
currentFileType = PreviewModel.FileType.Office;
return await GetPDFPreviewFromStreamAsync(ms);
}
/// <summary>
/// 获得图片文件的预览图
/// </summary>
/// <param name="path">图片路径</param>
/// <returns>图片的预览</returns>
public static async Task<IRandomAccessStream> GetPicPreviewAsync(string path, bool inner = false)
{
{
StorageFile file;
if (inner == false)
{
file = await StorageFile.GetFileFromPathAsync(path);
}
else
{
file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(path));
}
var res = await file.OpenAsync(FileAccessMode.Read);
currentFileType = PreviewModel.FileType.Picture;
return res;
}
}
/// <summary>
/// 获得PDF文件的预览图
/// </summary>
/// <param name="path">文档路径</param>
/// <returns>PDF的预览</returns>
public static async Task<IRandomAccessStream> GetPDFPreviewAsync(string path, uint p = 0)
{
StorageFile pdfFile;
try
{
pdfFile = await StorageFile.GetFileFromPathAsync(path);
var pdf = await Windows.Data.Pdf.PdfDocument.LoadFromFileAsync(pdfFile);
var page = pdf.GetPage(p);
currentPdfCount = pdf.PageCount;
currentPdfPage = p;
currentPdfPath = path;
InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
await page.RenderToStreamAsync(ms);
currentFileType = PreviewModel.FileType.Pdf;
return ms;
}
catch (Exception)
{
return await GetPicPreviewAsync(defaultPicPath);
}
}
public static async Task<IRandomAccessStream> GetNextPageAsync()
{
if (currentPdfPage + 1 < currentPdfCount)
{
currentPdfPage += 1;
}
return await GetPDFPreviewAsync(currentPdfPath, currentPdfPage);
}
public static async Task<IRandomAccessStream> GetPrevPageAsync()
{
if (currentPdfPage != 0)
{
currentPdfPage -= 1;
}
return await GetPDFPreviewAsync(currentPdfPath, currentPdfPage);
}
public static async Task<IRandomAccessStream> ShowPreviewAsync(string path)
{
try
{
var t = await GetFileTypeAsync(path);
switch (t)
{
case PreviewModel.FileType.Picture:
return await GetPicPreviewAsync(path);
case PreviewModel.FileType.Pdf:
return await GetPDFPreviewAsync(path);
case PreviewModel.FileType.Office:
return await GetWordPreviewAsync(path);
default:
return await GetPicPreviewAsync(defaultPicPath, true);
}
}
catch (Exception)
{
return await GetPicPreviewAsync(defaultPicPath, true);
}
}
private static async Task<IRandomAccessStream> GetPDFPreviewFromStreamAsync(IRandomAccessStream stream, uint p = 0)
{
try
{
var pdf = await Windows.Data.Pdf.PdfDocument.LoadFromStreamAsync(stream);
var page = pdf.GetPage(p);
currentPdfCount = pdf.PageCount;
currentPdfPage = p;
InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
await page.RenderToStreamAsync(ms);
return ms;
}
catch (Exception)
{
return await GetPicPreviewAsync(defaultPicPath);
}
}
}
}
+11
View File
@@ -0,0 +1,11 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FileManager_UWP.Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Controls/LabelListControl.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
+52 -25
View File
@@ -1,11 +1,13 @@
<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"
xmlns:controls="using:FileManager_UWP.Controls"
x:Class="FileManager_UWP.View.FileListView"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
@@ -20,59 +22,84 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button
<!--<controls:LabelListControl ItemsSource="{x:Bind vm.Labels}" />-->
<!--<Button
Grid.Row="0"
Grid.Column="1"
Name="getFileList"
Click="GetFileList_Click"
Content="获得文件列表"
FontSize="20"/>
Command="{Binding RefreshCommand}"
Content="刷新文件列表"
FontSize="20"/>-->
<TextBox
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
Width="Auto"
Text="C:\"
Name="pathText"/>
Text="{Binding Path}"
/>
<ListView
Name="MicroShitList"
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
ItemsSource="{x:Bind Files}"
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">
<!--ItemsSource="{Binding DisplayFileFolderItems}"-->
<!--<ListView.ItemTemplate>
<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"/>
--><!--<controls:LabelListControl ItemsSource="{x:Bind Labels}">
<DataTemplate x:DataType="model:LabelItem"></DataTemplate>
--><!--<controls:LabelListControl.ItemTemplate>
<DataTemplate x:DataType="model:LabelItem">
</DataTemplate>
</controls:LabelListControl.ItemTemplate>--><!--
</controls:LabelListControl>--><!--
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView.ItemTemplate>-->
<Custom:Interaction.Behaviors>
<Custom1:EventTriggerBehavior EventName="DoubleTapped">
<Custom1:InvokeCommandAction Command="{Binding DoubleTappedCommand}"/>
</Custom1:EventTriggerBehavior>
<Custom1:EventTriggerBehavior EventName="Tapped">
<Custom1:InvokeCommandAction Command="{Binding TappedCommand}"/>
</Custom1:EventTriggerBehavior>
</Custom:Interaction.Behaviors>
</ListView>
<TextBlock
Name="DebugPanel"
Grid.Row="2">
</TextBlock>
Text="{Binding DebugText}"
Grid.Row="2"
Grid.Column="0"
/>
</Grid>
</Page>
+56 -78
View File
@@ -1,92 +1,70 @@
using FileManager_UWP.Server;
using GalaSoft.MvvmLight.Ioc;
using System;
using System.Collections.Generic;
using Windows.UI.Xaml.Controls;
using FileManager_UWP.ViewModel;
using System.Collections.ObjectModel;
using FileManager_UWP.Model;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI.Xaml.Controls;
using FileManager_UWP.Controls;
using GalaSoft.MvvmLight.Ioc;
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>();
//public ObservableCollection<LabelItem> Labels =
// new ObservableCollection<LabelItem>{
// new LabelItem("照片"),
// new LabelItem("土耳其摔跤"),
// new LabelItem("李若明"),
// new LabelItem("鸢晓曼"),
// new LabelItem("才明洋与吴岳江进行土耳其摔跤"),
// new LabelItem("真正的瑜伽大师")
// };
private FileListViewModel vm;
public FileListView() {
this.InitializeComponent();
vm = SimpleIoc.Default.GetInstance<FileListViewModel>();
// vm = new FileListViewModel();
DataContext = vm;
vm.RefreshCommand.Execute(null);
vm.PropertyChanged += Vm_PropertyChanged;
}
private async void UpdateFileList(string path) {
StorageFolder folder = null;
try {
folder = await StorageFolder.GetFolderFromPathAsync(path);
} catch (Exception ex) {
DebugPanel.Text = ex.Message;
}
private void Vm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
Debug.WriteLine(e.PropertyName);
if (e.PropertyName == "DisplayFileFolderItems") {
var items = (sender as FileListViewModel).DisplayFileFolderItems;
MicroShitList.Items.Clear();
foreach (var displayFileItem in items) {
StackPanel sp = new StackPanel();
sp.Height = 44;
sp.Padding = new Windows.UI.Xaml.Thickness(12);
sp.Orientation = Orientation.Horizontal;
// TODO:滥用Tag
sp.SetValue(StackPanel.TagProperty, displayFileItem);
Image Icon = new Image();
Icon.Source = displayFileItem.Icon;
Icon.Height = 16;
Icon.Width = 16;
Icon.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center;
TextBlock Name = new TextBlock();
Name.Text = displayFileItem.Name;
Name.Margin = new Windows.UI.Xaml.Thickness(12, 0, 0, 0);
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));
LabelListControl labels = new LabelListControl();
labels.ItemsSource = displayFileItem.Labels;
// labels.Padding = new Windows.UI.Xaml.Thickness(0, -50, 0, 0);
labels.SetValue(LabelListControl.TagProperty, displayFileItem.Path);
labels.OnRemoveLabel = vm.LabelRemoveCommand;
labels.OnAddLabel = vm.LabelAddCommand;
sp.Children.Add(Icon);
sp.Children.Add(Name);
sp.Children.Add(labels);
MicroShitList.Items.Add(sp);
}
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);
}
}
}
+14 -4
View File
@@ -8,13 +8,13 @@
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<NavigationView PaneDisplayMode="LeftCompact" IsBackButtonVisible="Auto"
<NavigationView PaneDisplayMode="LeftCompact" IsBackButtonVisible="Collapsed"
>
<NavigationView.Header>
<!--<NavigationView.Header>
<RelativePanel Margin="0,5,10,0">
<SearchBox Width="300" RelativePanel.AlignRightWithPanel="True"></SearchBox>
</RelativePanel>
</NavigationView.Header>
</NavigationView.Header>-->
<NavigationView.AutoSuggestBox>
<AutoSuggestBox></AutoSuggestBox>
</NavigationView.AutoSuggestBox>
@@ -24,6 +24,16 @@
<NavigationViewItem Icon="Tag"></NavigationViewItem>
</StackPanel>
</NavigationView.PaneFooter>
<Frame Name="mainFrame"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Frame Name="mainFrame" Grid.Column="0"/>
<Frame Name="previewFrame" Grid.Column="1"/>
</Grid>
<!--<StackPanel Orientation="Horizontal">
</StackPanel>-->
</NavigationView>
</Page>
+1
View File
@@ -27,6 +27,7 @@ namespace FileManager_UWP
{
this.InitializeComponent();
mainFrame.Navigate(typeof(FileListView));
previewFrame.Navigate(typeof(PreviewView));
}
}
}
+18 -2
View File
@@ -8,7 +8,23 @@
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<RelativePanel>
<ScrollViewer ZoomMode="Enabled"
HorizontalScrollBarVisibility="Auto"
RelativePanel.AlignTopWithPanel="True"
RelativePanel.AlignHorizontalCenterWithPanel="True">
<Image Width="500" Height="500"
VerticalAlignment="Center" Source="{x:Bind vm.ImgSource}">
</Image>
</ScrollViewer>
<StackPanel RelativePanel.AlignBottomWithPanel="True"
RelativePanel.AlignHorizontalCenterWithPanel="True"
Orientation="Horizontal"
Spacing="30">
<Button Command="{x:Bind vm.ShowPreviewCommand}">Do</Button>
<Button Command="{x:Bind vm.PrevPageCommand}">←</Button>
<Button Command="{x:Bind vm.NextPageCommand}">→</Button>
</StackPanel>
</Grid>
</RelativePanel>
</Page>
+12 -1
View File
@@ -1,16 +1,22 @@
using System;
using FileManager_UWP.ViewModel;
using GalaSoft.MvvmLight.Ioc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Data.Pdf;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板
@@ -22,9 +28,14 @@ namespace FileManager_UWP.View
/// </summary>
public sealed partial class PreviewView : Page
{
private PreviewViewModel vm;
public PreviewView()
{
this.InitializeComponent();
vm = SimpleIoc.Default.GetInstance<PreviewViewModel>();
// vm = new PreviewViewModel();
DataContext = vm;
}
}
}
+30
View File
@@ -0,0 +1,30 @@
<Page
x:Class="FileManager_UWP.View.TestLabelView"
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:controls="using:FileManager_UWP.Controls"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
>
<StackPanel Name="MicroshitPanel">
<TextBlock
FontSize="50"
Text="Test Label View" />
<Button FontSize="20" Content="加" Click="Button_Click"></Button>
<!--<ListView ItemsSource="{x:Bind Labels}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>-->
<!--<controls:LabelListControl ItemsSource="{x:Bind Labels}" />-->
<!--<controls:LabelListControl ItemsSource="{Binding empty}" />-->
</StackPanel>
</Page>
@@ -0,0 +1,75 @@
using FileManager_UWP.Controls;
using FileManager_UWP.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace FileManager_UWP.View {
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class TestLabelView: Page {
public ObservableCollection<LabelItem> Labels =
new ObservableCollection<LabelItem>{
new LabelItem("照片"),
new LabelItem("土耳其摔跤"),
new LabelItem("李若明"),
new LabelItem("鸢晓曼"),
new LabelItem("才明洋与吴岳江进行土耳其摔跤"),
new LabelItem("真正的瑜伽大师")
};
public ObservableCollection<LabelItem> empty =
new ObservableCollection<LabelItem>() {
new LabelItem("123")
};
public TestLabelView() {
this.InitializeComponent();
Debug.WriteLine(Labels.ToString());
// MicroshitPanel;
LabelListControl list1 = new LabelListControl();
list1.ItemsSource = Labels;
MicroshitPanel.Children.Add(list1);
}
private void Button_Click(object sender, RoutedEventArgs e) {
switch (Labels.Count) {
case 0:
Labels.Add(new LabelItem("照片"));
break;
case 1:
Labels.Add(new LabelItem("土耳其摔跤"));
break;
case 2:
Labels.Add(new LabelItem("李若明"));
break;
case 3:
Labels.Add(new LabelItem("鸢晓曼"));
break;
default:
Labels.Add(new LabelItem("才明洋与吴岳江摔跤"));
break;
}
Debug.WriteLine(Labels.Count.ToString());
}
private void LabelListControl_Tapped(object sender, TappedRoutedEventArgs e) {
Debug.WriteLine(sender);
}
}
}
+140 -5
View File
@@ -1,11 +1,146 @@
using System;
using FileManager_UWP.Controls;
using FileManager_UWP.Model;
using FileManager_UWP.Service;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Ioc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Diagnostics;
using Windows.Storage;
using Windows.UI.Xaml.Controls;
using DataAccessLibrary;
using Type = FileManager_UWP.Model.Type;
using DataAccessLibrary.Service;
namespace FileManager_UWP.ViewModel {
class FileListViewModel {
public class FileListViewModel: ViewModelBase {
public FileListViewModel() {
// SimpleIoc.Default.Register<FileService>();
}
/// <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 () => {
Debug.WriteLine("Refresh");
try {
var fileService = SimpleIoc.Default.GetInstance<IFileService>();
// var fileService = new FileService();
var fileList = await fileService.GetDisplayFileFolderList(Path);
DisplayFileFolderItems = fileList;
} catch (System.UnauthorizedAccessException) {
ContentDialog noWifiDialog = new ContentDialog {
Title = "无文件系统访问权限",
Content = "请在设置->隐私->文件系统中为FileManager_UWP开启文件系统访问权限。",
CloseButtonText = "行"
};
ContentDialogResult result = await noWifiDialog.ShowAsync();
}
}));
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(
() => {
StackPanel sp = ListSelectedItem as StackPanel;
if (sp == null)
return;
Displayable i = sp.GetValue(StackPanel.TagProperty) as Displayable;
//Displayable i = ListSelectedItem as Displayable;
Debug.WriteLine("Double tapped");
if (i != null && (i.Type != Type.File)) {
Path = i.Path;
RefreshCommand.Execute(null);
}
}));
private RelayCommand _tappedCommand;
public RelayCommand TappedCommand =>
_tappedCommand ?? (_tappedCommand = new RelayCommand(
() => {
PreviewViewModel pvm = SimpleIoc.Default.GetInstance<PreviewViewModel>();
StackPanel sp = ListSelectedItem as StackPanel;
if (sp == null)
return;
Displayable i = sp.GetValue(StackPanel.TagProperty) as Displayable;
// pvm.Path = i.Path;
pvm.ShowPreviewCommand.Execute(i.Path);
}));
private RelayCommand<LabelListChangeEvent> _labelRemoveCommand;
public RelayCommand<LabelListChangeEvent> LabelRemoveCommand =>
_labelRemoveCommand ?? (_labelRemoveCommand =
new RelayCommand<LabelListChangeEvent>(
(LabelListChangeEvent e) => {
string path = e.LabelListControl.GetValue(LabelListControl.TagProperty) as string;
LabelItem label = e.label;
Debug.WriteLine("remove " + path + " " + label.tag);
LabelService.RemoveLabel(path, label.tag);
})
);
private RelayCommand<LabelListChangeEvent> _labelAddCommand;
public RelayCommand<LabelListChangeEvent> LabelAddCommand =>
_labelAddCommand ?? (_labelAddCommand =
new RelayCommand<LabelListChangeEvent>(
(LabelListChangeEvent e) => {
string path = e.LabelListControl.GetValue(LabelListControl.TagProperty) as string;
LabelItem label = e.label;
Debug.WriteLine("add " + path + " " + label.tag);
if (path != "" && label.tag != "")
LabelService.AddLabel(path, label.tag);
})
);
}
}
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace FileManager_UWP.ViewModel
{
class MainPageViewModel
public class MainPageViewModel
{
}
}
@@ -0,0 +1,80 @@
using FileManager_UWP.Service;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media.Imaging;
namespace FileManager_UWP.ViewModel
{
public class PreviewViewModel :ViewModelBase//, INotifyPropertyChanged
{
//public event PropertyChangedEventHandler PropertyChanged = delegate { };
public PreviewViewModel()
{
_source = new BitmapImage();
Path = "C:\\Users\\CaiMY\\Downloads\\tt.doc";
}
private BitmapImage _source;
public BitmapImage ImgSource
{
get => _source;
set
{
Set(nameof(ImgSource), ref _source, value);
//this.OnPropertyChanged();
}
}
private string _path;
public string Path
{
get => _path;
set => Set(nameof(Path), ref _path, value);
}
private RelayCommand<String> _showPreviewCommand;
private RelayCommand _nextPageCommand;
private RelayCommand _prevPageCommand;
public RelayCommand<String> ShowPreviewCommand =>
_showPreviewCommand ?? (_showPreviewCommand = new RelayCommand<String>(async (String path) =>
{
if (path == null)
path = "C:\\Users\\CaiMY\\Downloads\\tt.pdf";
var preview = await PreviewService.ShowPreviewAsync(path);
ImgSource.SetSource(preview);
}));
public RelayCommand NextPageCommand =>
_nextPageCommand ?? (_nextPageCommand = new RelayCommand(async () =>
{
if (PreviewService.IsCurrentPDF())
{
var nextPage = await PreviewService.GetNextPageAsync();
ImgSource.SetSource(nextPage);
}
}));
public RelayCommand PrevPageCommand =>
_prevPageCommand ?? (_prevPageCommand = new RelayCommand(async () =>
{
if (PreviewService.IsCurrentPDF())
{
var prevPage = await PreviewService.GetPrevPageAsync();
ImgSource.SetSource(prevPage);
}
}));
}
}
@@ -0,0 +1,30 @@
using CommonServiceLocator;
using DataAccessLibrary.Service;
using FileManager_UWP.Service;
using GalaSoft.MvvmLight.Ioc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileManager_UWP.ViewModel {
public class ViewModelLocator {
public FileListViewModel FileListViewModel => ServiceLocator.Current.GetInstance<FileListViewModel>();
public MainPageViewModel MainPageViewModel => ServiceLocator.Current.GetInstance<MainPageViewModel>();
public PreviewViewModel PreviewViewModel => ServiceLocator.Current.GetInstance<PreviewViewModel>();
// public LabelService LabelService => ServiceLocator.Current.GetInstance<LabelService>();
public ViewModelLocator() {
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
LabelService.InitializeDatabase();
SimpleIoc.Default.Register<FileListViewModel>();
SimpleIoc.Default.Register<MainPageViewModel>();
SimpleIoc.Default.Register<PreviewViewModel>();
SimpleIoc.Default.Register<IFileService, FileService>();
}
}
}
+1
View File
@@ -2,3 +2,4 @@
A file manager for humans.
## Dependencies