Compare commits
34
Commits
label_list_dev
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16f4ece443 | ||
|
|
b3054869c2 | ||
|
|
52ed312582 | ||
|
|
11a576de99 | ||
|
|
fb72350f9a | ||
|
|
60a895a552 | ||
|
|
f25758992e | ||
|
|
239ebb65c8 | ||
|
|
5295123843 | ||
|
|
726263ef69 | ||
|
|
30cc4dece2 | ||
|
|
1fa8e2031b | ||
|
|
1ffdbdc84e | ||
|
|
30dc52f748 | ||
|
|
54090083e3 | ||
|
|
2225c99869 | ||
|
|
8515e92656 | ||
|
|
5029b1100a | ||
|
|
a34730d942 | ||
|
|
0692b177af | ||
|
|
e7871023fa | ||
|
|
ae77d7eb69 | ||
|
|
a78a2c4e5c | ||
|
|
e1aa98c869 | ||
|
|
99da741a94 | ||
|
|
4c2379ffac | ||
|
|
c22c359e5d | ||
|
|
02d75cf374 | ||
|
|
14fc8491dd | ||
|
|
3936f27fb9 | ||
|
|
4f6c287dd8 | ||
|
|
d0beb62fc3 | ||
|
|
7700bf9ea4 | ||
|
|
f42874758f |
No files matched your search
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"VirtualFolders": [
|
||||
{
|
||||
"name": "PROGRAMS",
|
||||
"Includes": [
|
||||
"C:\\Program Files (x86)",
|
||||
"C:\\Program Files",
|
||||
"C:\\Users\\wming\\AppData\\Local\\Programs"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -2,7 +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>
|
||||
@@ -1,5 +1,6 @@
|
||||
using FileManager_UWP.Service;
|
||||
using FileManager_UWP.View;
|
||||
using FileManager_UWP.ViewModel;
|
||||
using GalaSoft.MvvmLight.Ioc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -69,13 +70,14 @@ namespace FileManager_UWP
|
||||
// 当导航堆栈尚未还原时,导航到第一页,
|
||||
// 并通过将所需信息作为导航参数传入来配置
|
||||
// 参数
|
||||
rootFrame.Navigate(typeof(TestLabelView), e.Arguments);
|
||||
rootFrame.Navigate(typeof(MainPage), e.Arguments);
|
||||
}
|
||||
// 确保当前窗口处于活动状态
|
||||
Window.Current.Activate();
|
||||
}
|
||||
|
||||
SimpleIoc.Default.Register<FileService>();
|
||||
// SimpleIoc.Default.Register<FileService>();
|
||||
// SimpleIoc.Default.Register<FileListViewModel>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
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;
|
||||
@@ -17,18 +19,31 @@ 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(500));
|
||||
private int _status = 0; // 0 展开, 1 动画, 2 折叠
|
||||
private double _width, _height;
|
||||
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() {
|
||||
@@ -36,21 +51,70 @@ namespace FileManager_UWP.Controls {
|
||||
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 ItemsSource_CollectionChanged(object sender,
|
||||
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() {
|
||||
//TextBlock textBlock = (TextBlock)GetTemplateChild("LabelTextBlock");
|
||||
//textBlock.Text = "测试自定义控件\n";
|
||||
//listView.ItemsSource = ItemsSource;
|
||||
Debug.WriteLine("ObservableCollection update");
|
||||
var itemsSource = ItemsSource as ObservableCollection<LabelItem>;
|
||||
//textBlock.Text += itemsSource.Count().ToString();
|
||||
|
||||
//labelListCanvas.Children.Count;
|
||||
labelListCanvas.Children.Clear();
|
||||
_collpse_story_board.Stop();
|
||||
_collpse_story_board.Children.Clear();
|
||||
@@ -59,76 +123,286 @@ namespace FileManager_UWP.Controls {
|
||||
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;
|
||||
|
||||
DoubleAnimation collpse_animate = new DoubleAnimation();
|
||||
collpse_animate.From = null; // labelListCanvas.Children.Count * 22;
|
||||
collpse_animate.To = expanded_position;
|
||||
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)");
|
||||
|
||||
DoubleAnimation expand_animate = new DoubleAnimation();
|
||||
expand_animate.From = null; // expanded_position;
|
||||
expand_animate.To = labelListCanvas.Children.Count * 22;
|
||||
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)");
|
||||
|
||||
expanded_position += label.tag.Count() * 14 + 20;
|
||||
//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.ActualHeight;
|
||||
labelListCanvas.Width = left + lb.ActualWidth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鼠标离开
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LabelListCanvas_PointerExited(object sender, PointerRoutedEventArgs e) {
|
||||
_expand_story_board.Begin();
|
||||
_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) {
|
||||
_collpse_story_board.Begin();
|
||||
_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");
|
||||
|
||||
//TextBlock textBlock = (TextBlock)GetTemplateChild("LabelTextBlock");
|
||||
//textBlock.Text = "测试自定义控件\nINIT";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 该Control被加载时调用
|
||||
/// </summary>
|
||||
protected override void OnApplyTemplate() {
|
||||
init();
|
||||
update();
|
||||
//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.
|
||||
// //}
|
||||
// })));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
<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:local="using:FileManager_UWP.Controls"
|
||||
xmlns:model="using:FileManager_UWP.Model">
|
||||
|
||||
<Style TargetType="Button" x:Key="LabelButtonStyle">
|
||||
<Setter Property="Template">
|
||||
@@ -23,6 +24,14 @@
|
||||
</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">
|
||||
@@ -31,10 +40,12 @@
|
||||
<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"></Canvas>
|
||||
<Canvas Name="LabelListCanvas" AllowDrop="True"></Canvas>
|
||||
</Button>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
|
||||
@@ -126,13 +126,17 @@
|
||||
<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>
|
||||
@@ -203,8 +207,8 @@
|
||||
<PackageReference Include="MvvmLight">
|
||||
<Version>5.4.1.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MvvmLightLibs">
|
||||
<Version>5.4.1.1</Version>
|
||||
<PackageReference Include="NETStandard.Library">
|
||||
<Version>2.0.3</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json">
|
||||
<Version>12.0.1</Version>
|
||||
@@ -212,6 +216,18 @@
|
||||
<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>
|
||||
@@ -219,7 +235,12 @@
|
||||
<Version>4.3.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DataAccessLibrary\DataAccessLibrary.csproj">
|
||||
<Project>{faa7fcd7-5380-436c-a615-8612d798224d}</Project>
|
||||
<Name>DataAccessLibrary</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace FileManager_UWP.Model {
|
||||
public abstract string Path { get; }
|
||||
public abstract Type Type { get; }
|
||||
public abstract BitmapImage Icon { get; }
|
||||
public abstract List<String> Labels { get; }
|
||||
public abstract List<LabelItem> Labels { get; }
|
||||
|
||||
public int CompareTo(object obj) {
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using DataAccessLibrary.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -14,10 +15,12 @@ namespace FileManager_UWP.Model
|
||||
public class DisplayableDisk: Displayable {
|
||||
private readonly DriveInfo _drive;
|
||||
private readonly BitmapImage _icon = new BitmapImage();
|
||||
private readonly List<String> _labels = new List<String>();
|
||||
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) {
|
||||
@@ -33,6 +36,6 @@ namespace FileManager_UWP.Model
|
||||
public override string Path => _drive.Name;
|
||||
public override BitmapImage Icon => _icon;
|
||||
public override Type Type => Type.Disk;
|
||||
public override List<String> Labels => _labels;
|
||||
public override List<LabelItem> Labels => _labels;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using DataAccessLibrary.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -12,12 +13,12 @@ namespace FileManager_UWP.Model
|
||||
public class DisplayableFile: Displayable {
|
||||
private readonly StorageFile _file;
|
||||
private readonly BitmapImage _icon;
|
||||
private readonly List<String> _labels;
|
||||
private readonly List<LabelItem> _labels;
|
||||
|
||||
private DisplayableFile(StorageFile f) {
|
||||
_file = f;
|
||||
_icon = new BitmapImage();
|
||||
_labels = new List<string> { "喵喵喵" };
|
||||
_labels = LabelService.GetLabels(f.Path).Select((x) => new LabelItem(x)).ToList();
|
||||
}
|
||||
|
||||
public static async Task<DisplayableFile> GetInstanceAsync(StorageFile f) {
|
||||
@@ -31,6 +32,6 @@ namespace FileManager_UWP.Model
|
||||
public override string Path => _file.Path;
|
||||
public override Type Type => Type.File;
|
||||
public override BitmapImage Icon => _icon;
|
||||
public override List<String> Labels => _labels;
|
||||
public override List<LabelItem> Labels => _labels;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using DataAccessLibrary.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -12,12 +13,12 @@ namespace FileManager_UWP.Model
|
||||
public class DisplayableFolder: Displayable {
|
||||
private readonly StorageFolder _folder;
|
||||
private readonly BitmapImage _icon;
|
||||
private readonly List<String> _labels;
|
||||
private readonly List<LabelItem> _labels;
|
||||
|
||||
private DisplayableFolder(StorageFolder f) {
|
||||
_folder = f;
|
||||
_icon = new BitmapImage();
|
||||
_labels = new List<string>();
|
||||
_labels = LabelService.GetLabels(f.Path).Select((x) => new LabelItem(x)).ToList();
|
||||
}
|
||||
|
||||
public static async Task<DisplayableFolder> GetInstanceAsync(StorageFolder f)
|
||||
@@ -49,6 +50,6 @@ namespace FileManager_UWP.Model
|
||||
public override string Path => _folder.Path;
|
||||
public override Type Type => Type.Folder;
|
||||
public override BitmapImage Icon => _icon;
|
||||
public override List<String> Labels => _labels;
|
||||
public override List<LabelItem> Labels => _labels;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using DataAccessLibrary.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -14,12 +15,12 @@ namespace FileManager_UWP.Model
|
||||
Path = path;
|
||||
Type = type;
|
||||
Icon = icon;
|
||||
Labels = new List<String>();
|
||||
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<String> Labels { get; }
|
||||
public override List<LabelItem> Labels { get; }
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,9 @@ 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 Newtonsoft.Json;
|
||||
using Type = FileManager_UWP.Model.Type;
|
||||
|
||||
namespace FileManager_UWP.Service {
|
||||
@@ -34,7 +27,7 @@ namespace FileManager_UWP.Service {
|
||||
//var virtualFolderName = path.Substring(0, path.LastIndexOf('\\'));
|
||||
//path = path.Substring(path.LastIndexOf('\\'));
|
||||
var directoryName = Path.GetDirectoryName(path);
|
||||
var virtualFolderName = path.Substring(path.LastIndexOf('\\'));
|
||||
var virtualFolderName = path.Substring(path.LastIndexOf('\\') + 1);
|
||||
|
||||
if (directoryName == null)
|
||||
throw new FileNotFoundException();
|
||||
@@ -97,7 +90,7 @@ namespace FileManager_UWP.Service {
|
||||
foreach (var virtualFolder in folderSetting.VirtualFolders) {
|
||||
displayFileFolderItems.Add(new DisplayableSpecial(
|
||||
virtualFolder.Name,
|
||||
folder.Path + "//" + virtualFolder.Name,
|
||||
folder.Path + "\\" + virtualFolder.Name,
|
||||
Type.VirtualFolder,
|
||||
await IconServer.GetFolderIcon(ThumbnailMode.ListView, 32)));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
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}">
|
||||
@@ -21,34 +22,38 @@
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Button
|
||||
<!--<controls:LabelListControl ItemsSource="{x:Bind vm.Labels}" />-->
|
||||
|
||||
|
||||
<!--<Button
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Command="{Binding RefreshCommand}"
|
||||
Content="刷新文件列表"
|
||||
FontSize="20"/>
|
||||
FontSize="20"/>-->
|
||||
<TextBox
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
Width="Auto"
|
||||
Text="{Binding Path}"
|
||||
/>
|
||||
<ListView
|
||||
Name="MicroShitList"
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
ItemsSource="{Binding DisplayFileFolderItems}"
|
||||
CanDragItems="False"
|
||||
CanReorderItems="True"
|
||||
AllowDrop="False"
|
||||
SelectionMode="Single"
|
||||
SelectedItem="{Binding ListSelectedItem, Mode=TwoWay}"
|
||||
|
||||
IsDoubleTapEnabled="True"
|
||||
IsTapEnabled="True"
|
||||
|
||||
>
|
||||
<ListView.ItemTemplate>
|
||||
<!--ItemsSource="{Binding DisplayFileFolderItems}"-->
|
||||
|
||||
<!--<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel
|
||||
Orientation="Horizontal"
|
||||
@@ -65,28 +70,27 @@
|
||||
Style="{ThemeResource BaseTextBlockStyle}"
|
||||
Foreground="{ThemeResource SystemControlPageTextBaseHighBrush}"
|
||||
Margin="12,0,0,0"/>
|
||||
<ListView
|
||||
ScrollViewer.VerticalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
||||
ScrollViewer.HorizontalScrollMode="Enabled"
|
||||
ScrollViewer.VerticalScrollMode="Disabled"
|
||||
ItemsSource="{Binding Labels}">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding}"></TextBlock>
|
||||
</Grid>
|
||||
--><!--<controls:LabelListControl ItemsSource="{x:Bind Labels}">
|
||||
<DataTemplate x:DataType="model:LabelItem"></DataTemplate>
|
||||
--><!--<controls:LabelListControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="model:LabelItem">
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</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>
|
||||
|
||||
@@ -1,15 +1,71 @@
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using FileManager_UWP.ViewModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using FileManager_UWP.Model;
|
||||
using System.Diagnostics;
|
||||
using FileManager_UWP.Controls;
|
||||
using GalaSoft.MvvmLight.Ioc;
|
||||
|
||||
namespace FileManager_UWP.View {
|
||||
|
||||
public sealed partial class FileListView : Page {
|
||||
|
||||
//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 = new FileListViewModel();
|
||||
vm = SimpleIoc.Default.GetInstance<FileListViewModel>();
|
||||
// vm = new FileListViewModel();
|
||||
DataContext = vm;
|
||||
vm.RefreshCommand.Execute(null);
|
||||
vm.PropertyChanged += Vm_PropertyChanged;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,11 @@
|
||||
|
||||
<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>
|
||||
@@ -27,6 +27,7 @@ namespace FileManager_UWP
|
||||
{
|
||||
this.InitializeComponent();
|
||||
mainFrame.Navigate(typeof(FileListView));
|
||||
previewFrame.Navigate(typeof(PreviewView));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:controls="using:FileManager_UWP.Controls"
|
||||
mc:Ignorable="d"
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
|
||||
>
|
||||
|
||||
<StackPanel>
|
||||
<StackPanel Name="MicroshitPanel">
|
||||
<TextBlock
|
||||
FontSize="50"
|
||||
Text="Test Label View" />
|
||||
@@ -21,7 +22,9 @@
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>-->
|
||||
|
||||
<controls:LabelListControl ItemsSource="{x:Bind Labels}"></controls:LabelListControl>
|
||||
|
||||
<!--<controls:LabelListControl ItemsSource="{x:Bind Labels}" />-->
|
||||
<!--<controls:LabelListControl ItemsSource="{Binding empty}" />-->
|
||||
|
||||
</StackPanel>
|
||||
</Page>
|
||||
@@ -1,4 +1,5 @@
|
||||
using FileManager_UWP.Model;
|
||||
using FileManager_UWP.Controls;
|
||||
using FileManager_UWP.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -32,10 +33,18 @@ namespace FileManager_UWP.View {
|
||||
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) {
|
||||
@@ -58,5 +67,9 @@ namespace FileManager_UWP.View {
|
||||
}
|
||||
Debug.WriteLine(Labels.Count.ToString());
|
||||
}
|
||||
|
||||
private void LabelListControl_Tapped(object sender, TappedRoutedEventArgs e) {
|
||||
Debug.WriteLine(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,26 @@
|
||||
using FileManager_UWP.Model;
|
||||
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.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 {
|
||||
public class FileListViewModel: ViewModelBase {
|
||||
|
||||
public FileListViewModel() {
|
||||
// SimpleIoc.Default.Register<FileService>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前路径
|
||||
/// </summary>
|
||||
@@ -45,8 +55,10 @@ namespace FileManager_UWP.ViewModel {
|
||||
|
||||
public RelayCommand RefreshCommand =>
|
||||
_refreshCommand ?? (_refreshCommand = new RelayCommand(async () => {
|
||||
Debug.WriteLine("Refresh");
|
||||
try {
|
||||
var fileService = new FileService();
|
||||
var fileService = SimpleIoc.Default.GetInstance<IFileService>();
|
||||
// var fileService = new FileService();
|
||||
var fileList = await fileService.GetDisplayFileFolderList(Path);
|
||||
DisplayFileFolderItems = fileList;
|
||||
} catch (System.UnauthorizedAccessException) {
|
||||
@@ -56,8 +68,6 @@ namespace FileManager_UWP.ViewModel {
|
||||
CloseButtonText = "行"
|
||||
};
|
||||
ContentDialogResult result = await noWifiDialog.ShowAsync();
|
||||
} catch (Exception e) {
|
||||
Debug.WriteLine(e.Message);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -83,12 +93,54 @@ namespace FileManager_UWP.ViewModel {
|
||||
public RelayCommand DoubleTappedCommand =>
|
||||
_doubleTappedCommand ?? (_doubleTappedCommand = new RelayCommand(
|
||||
() => {
|
||||
Displayable i = ListSelectedItem as Displayable;
|
||||
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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user