1.0beta
This commit is contained in:
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
|
||||
namespace GeekDesk
|
||||
{
|
||||
|
||||
13
Constant/AppConstant.cs
Normal file
13
Constant/AppConstant.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace GeekDesk.Constant
|
||||
{
|
||||
class AppConstant
|
||||
{
|
||||
private static string APP_DIR = AppDomain.CurrentDomain.BaseDirectory.Trim();
|
||||
/// <summary>
|
||||
/// app数据文件路径
|
||||
/// </summary>
|
||||
public static string DATA_FILE_PATH = APP_DIR + "//Data"; //app数据文件路径
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 默认参数
|
||||
/// </summary>
|
||||
namespace GeekDesk.Constant
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GeekDesk.Constant
|
||||
namespace GeekDesk.Constant
|
||||
{
|
||||
enum SortType
|
||||
{
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace DraggAnimatedPanel
|
||||
{
|
||||
@@ -23,7 +20,8 @@ namespace DraggAnimatedPanel
|
||||
#region private
|
||||
UIElement __draggedElement;
|
||||
|
||||
public UIElement _draggedElement {
|
||||
public UIElement _draggedElement
|
||||
{
|
||||
get { return __draggedElement; }
|
||||
set
|
||||
{
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
/*Developed by (doiTTeam)=>doiTTeam.mail = devdoiTTeam@gmail.com*/
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace DraggAnimatedPanel
|
||||
{
|
||||
|
||||
@@ -85,6 +85,7 @@
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Command\DelegateCommand.cs" />
|
||||
<Compile Include="Command\DelegateCommandBase.cs" />
|
||||
<Compile Include="Constant\AppConstant.cs" />
|
||||
<Compile Include="Constant\DefaultConstant.cs" />
|
||||
<Compile Include="Constant\SortType.cs" />
|
||||
<Compile Include="DraggAnimatedPanel\DraggAnimatedPanel.cs" />
|
||||
@@ -98,9 +99,8 @@
|
||||
<Compile Include="Util\MouseUtilities.cs" />
|
||||
<Compile Include="Util\SystemIcon.cs" />
|
||||
<Compile Include="ViewModel\AppConfig.cs" />
|
||||
<Compile Include="ViewModel\DataInfos.cs" />
|
||||
<Compile Include="ViewModel\MainModel.cs" />
|
||||
<Compile Include="ViewModel\MainViewModel.cs" />
|
||||
<Compile Include="ViewModel\AppData.cs" />
|
||||
<Compile Include="ViewModel\IconInfo.cs" />
|
||||
<Compile Include="ViewModel\MenuViewModel.cs" />
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
xmlns:util="clr-namespace:GeekDesk.Util"
|
||||
xmlns:DraggAnimatedPanel="clr-namespace:DraggAnimatedPanel" x:Name="window"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
Title="MainWindow" Height="500" Width="600">
|
||||
<Window.Resources>
|
||||
|
||||
<Style x:Key="ListBoxStyle" BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox"/>
|
||||
@@ -143,7 +143,7 @@
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>-->
|
||||
|
||||
<ListBox x:Name="menu" ItemsSource="{Binding}">
|
||||
<ListBox x:Name="menus" ItemsSource="{Binding MenuList}">
|
||||
<ListBox.Resources>
|
||||
<ContextMenu x:Key="menuDialog" Width="200">
|
||||
<MenuItem Header="新建菜单"/>
|
||||
@@ -165,7 +165,7 @@
|
||||
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding menu}" PreviewMouseLeftButtonDown="menuClick" />
|
||||
<TextBlock Text="{Binding}" PreviewMouseLeftButtonDown="menuClick" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
@@ -176,31 +176,29 @@
|
||||
<!--右侧栏-->
|
||||
<hc:Card AllowDrop="True" Drop="Wrap_Drop" Opacity="1" x:Name="rightCard" Grid.Row="1" Grid.Column="1" BorderThickness="1" Effect="{DynamicResource EffectShadow2}" Margin="5,5,5,5">
|
||||
<WrapPanel Orientation="Horizontal">
|
||||
<ListBox x:Name="data" ItemsSource="{Binding}"
|
||||
<ListBox x:Name="icons" ItemsSource="{Binding}"
|
||||
BorderThickness="0"
|
||||
SelectionChanged="data_SelectionChanged"
|
||||
>
|
||||
<!--<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource dataStyle}"/>
|
||||
</ListBox.ItemContainerStyle>-->
|
||||
<ListBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<DraggAnimatedPanel:DraggAnimatedPanel ItemsHeight="115" ItemsWidth="100" HorizontalAlignment="Center" SwapCommand="{Binding SwapCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"/>
|
||||
</ItemsPanelTemplate>
|
||||
</ListBox.ItemsPanel>
|
||||
|
||||
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Margin="5,5,5,5" CornerRadius="10">
|
||||
<StackPanel Tag="{Binding Path}"
|
||||
<StackPanel Tag="{Binding}"
|
||||
MouseLeftButtonDown="dataClick"
|
||||
HorizontalAlignment="Center"
|
||||
hc:Poptip.HitMode="None"
|
||||
hc:Poptip.IsOpen="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
|
||||
hc:Poptip.Content="{Binding Path}"
|
||||
hc:Poptip.Placement="BottomLeft"
|
||||
Margin="5,5,5,5"
|
||||
Height="115"
|
||||
hc:Poptip.HitMode="None"
|
||||
hc:Poptip.IsOpen="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
|
||||
hc:Poptip.Content="{Binding Content}"
|
||||
hc:Poptip.Placement="BottomLeft"
|
||||
>
|
||||
<Image Style="{StaticResource imageStyle}"></Image>
|
||||
<TextBlock Width="80" TextWrapping="Wrap" TextAlignment="Center" Height="35" LineHeight="15" FontSize="12" Text="{Binding Name}"/>
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
using System;
|
||||
using DraggAnimatedPanelExample;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GeekDesk.Util;
|
||||
using GeekDesk.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
using GeekDesk.ViewModel;
|
||||
using System.IO;
|
||||
using GeekDesk.Util;
|
||||
using GalaSoft.MvvmLight;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Collections.ObjectModel;
|
||||
using WPF.JoshSmith.ServiceProviders.UI;
|
||||
using DraggAnimatedPanelExample;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace GeekDesk
|
||||
{
|
||||
/// <summary>
|
||||
@@ -25,15 +18,18 @@ namespace GeekDesk
|
||||
///
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private static MainModel mainModel;
|
||||
|
||||
ListViewDragDropManager<ViewModel.Menu> dragMgr;
|
||||
ListViewDragDropManager<ViewModel.DataInfos> dragMgr2;
|
||||
private static AppData appData = CommonCode.GetAppData();
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
loadData();
|
||||
List<string> menuList = new List<string>();
|
||||
|
||||
Dictionary<string, List<IconInfo>> iconMap = new Dictionary<string, List<IconInfo>>();
|
||||
|
||||
|
||||
|
||||
mainModel = new MainModel();
|
||||
//this.DataContext = mainModel;
|
||||
//menu.Items = mainModel;
|
||||
//System.Diagnostics.Process.Start(@"D:\SoftWare\WeGame\wegame.exe");
|
||||
@@ -41,6 +37,29 @@ namespace GeekDesk
|
||||
this.SizeChanged += MainWindow_Resize;
|
||||
}
|
||||
|
||||
private void loadData()
|
||||
{
|
||||
this.DataContext = appData;
|
||||
appData.MenuList.Add("Test1");
|
||||
this.Width = appData.AppConfig.WindowWidth;
|
||||
this.Height = appData.AppConfig.WindowHeight;
|
||||
|
||||
|
||||
List<IconInfo> iconList;
|
||||
if (appData.IconMap.ContainsKey("1"))
|
||||
{
|
||||
iconList = appData.IconMap["1"];
|
||||
}
|
||||
else
|
||||
{
|
||||
iconList = new List<IconInfo>();
|
||||
appData.IconMap.Add("1", iconList);
|
||||
}
|
||||
icons.ItemsSource = iconList;
|
||||
|
||||
}
|
||||
|
||||
|
||||
DelegateCommand<int[]> _swap;
|
||||
public DelegateCommand<int[]> SwapCommand
|
||||
{
|
||||
@@ -52,17 +71,17 @@ namespace GeekDesk
|
||||
{
|
||||
int fromS = indexes[0];
|
||||
int to = indexes[1];
|
||||
var elementSource = data.Items[to];
|
||||
var dragged = data.Items[fromS];
|
||||
var elementSource = icons.Items[to];
|
||||
var dragged = icons.Items[fromS];
|
||||
if (fromS > to)
|
||||
{
|
||||
data.Items.Remove(dragged);
|
||||
data.Items.Insert(to, dragged);
|
||||
icons.Items.Remove(dragged);
|
||||
icons.Items.Insert(to, dragged);
|
||||
}
|
||||
else
|
||||
{
|
||||
data.Items.Remove(dragged);
|
||||
data.Items.Insert(to, dragged);
|
||||
icons.Items.Remove(dragged);
|
||||
icons.Items.Insert(to, dragged);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -80,17 +99,17 @@ namespace GeekDesk
|
||||
{
|
||||
int fromS = indexes[0];
|
||||
int to = indexes[1];
|
||||
var elementSource = menu.Items[to];
|
||||
var dragged = menu.Items[fromS];
|
||||
var elementSource = menus.Items[to];
|
||||
var dragged = menus.Items[fromS];
|
||||
if (fromS > to)
|
||||
{
|
||||
menu.Items.Remove(dragged);
|
||||
menu.Items.Insert(to, dragged);
|
||||
menus.Items.Remove(dragged);
|
||||
menus.Items.Insert(to, dragged);
|
||||
}
|
||||
else
|
||||
{
|
||||
menu.Items.Remove(dragged);
|
||||
menu.Items.Insert(to, dragged);
|
||||
menus.Items.Remove(dragged);
|
||||
menus.Items.Insert(to, dragged);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -104,23 +123,41 @@ namespace GeekDesk
|
||||
{
|
||||
Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
|
||||
if (dropObject == null) return;
|
||||
string path = (string)dropObject.GetValue(0);
|
||||
foreach (object obj in dropObject)
|
||||
{
|
||||
string path = (string)obj;
|
||||
if (File.Exists(path))
|
||||
{
|
||||
// 文件
|
||||
BitmapImage bi = FileIcon.GetBitmapImage(path);
|
||||
DataInfos infos = new DataInfos();
|
||||
infos.Path = path;
|
||||
infos.BitmapImage = bi;
|
||||
infos.Name = Path.GetFileNameWithoutExtension(path);
|
||||
data.Items.Add(infos);
|
||||
data.Items.Refresh();
|
||||
IconInfo iconInfo = new IconInfo();
|
||||
iconInfo.Path = path;
|
||||
iconInfo.BitmapImage = bi;
|
||||
iconInfo.Name = Path.GetFileNameWithoutExtension(path);
|
||||
List<IconInfo> iconList;
|
||||
if (appData.IconMap.ContainsKey("1"))
|
||||
{
|
||||
iconList = appData.IconMap["1"];
|
||||
}
|
||||
else
|
||||
{
|
||||
iconList = new List<IconInfo>();
|
||||
appData.IconMap.Add("1", iconList);
|
||||
}
|
||||
iconList.Add(iconInfo);
|
||||
icons.ItemsSource = iconList;
|
||||
CommonCode.SaveAppData(appData);
|
||||
|
||||
}
|
||||
else if (Directory.Exists(path))
|
||||
{
|
||||
//文件夹
|
||||
|
||||
}
|
||||
}
|
||||
icons.Items.Refresh();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -139,8 +176,10 @@ namespace GeekDesk
|
||||
/// <param name="e"></param>
|
||||
private void dataClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
//string path = ((StackPanel)sender).Tag.ToString();
|
||||
//System.Diagnostics.Process.Start(path);
|
||||
IconInfo icon = (IconInfo)((StackPanel)sender).Tag;
|
||||
System.Diagnostics.Process.Start(icon.Path);
|
||||
icon.Count++;
|
||||
CommonCode.SaveAppData(appData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -150,128 +189,42 @@ namespace GeekDesk
|
||||
/// <param name="e"></param>
|
||||
private void data_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (data.SelectedIndex != -1) data.SelectedIndex = -1;
|
||||
if (icons.SelectedIndex != -1) icons.SelectedIndex = -1;
|
||||
}
|
||||
|
||||
#region Window_Loaded
|
||||
void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
AppConfig config = CommonCode.GetAppConfig();
|
||||
this.Width = config.WindowWidth;
|
||||
this.Height = config.WindowHeight;
|
||||
this.DataContext = config;
|
||||
|
||||
this.menu.Items.Add(new ViewModel.Menu() { menu = "test1" });
|
||||
this.menu.Items.Add(new ViewModel.Menu() { menu = "test2" });
|
||||
this.menu.Items.Add(new ViewModel.Menu() { menu = "test3" });
|
||||
//this.menus.Items.Add(new ViewModel.Menu() { menu = "test1" });
|
||||
//this.menus.Items.Add(new ViewModel.Menu() { menu = "test2" });
|
||||
//this.menus.Items.Add(new ViewModel.Menu() { menu = "test3" });
|
||||
}
|
||||
#endregion // Window_Loaded
|
||||
|
||||
#region Window_Closing
|
||||
void Window_Closing(object sender, CancelEventArgs e)
|
||||
{
|
||||
Rect rect = this.RestoreBounds;
|
||||
AppConfig config = this.DataContext as AppConfig;
|
||||
config.WindowWidth = rect.Width;
|
||||
config.WindowHeight = rect.Height;
|
||||
CommonCode.SaveAppConfig(config);
|
||||
}
|
||||
#endregion // Window_Closing
|
||||
//#region Window_Closing
|
||||
//void Window_Closing(object sender, CancelEventArgs e)
|
||||
//{
|
||||
// Rect rect = this.RestoreBounds;
|
||||
// AppConfig config = this.DataContext as AppConfig;
|
||||
// config.WindowWidth = rect.Width;
|
||||
// config.WindowHeight = rect.Height;
|
||||
// CommonCode.SaveAppConfig(config);
|
||||
//}
|
||||
//#endregion // Window_Closing
|
||||
|
||||
void MainWindow_Resize(object sender, System.EventArgs e)
|
||||
{
|
||||
if (this.DataContext != null)
|
||||
{
|
||||
AppConfig config = this.DataContext as AppConfig;
|
||||
config.WindowWidth = this.Width;
|
||||
config.WindowHeight = this.Height;
|
||||
CommonCode.SaveAppConfig(config);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region dragMgr_ProcessDrop
|
||||
|
||||
// Performs custom drop logic for the top ListView.
|
||||
void dragMgr_ProcessDrop(object sender, ProcessDropEventArgs<object> e)
|
||||
{
|
||||
// This shows how to customize the behavior of a drop.
|
||||
// Here we perform a swap, instead of just moving the dropped item.
|
||||
|
||||
int higherIdx = Math.Max(e.OldIndex, e.NewIndex);
|
||||
int lowerIdx = Math.Min(e.OldIndex, e.NewIndex);
|
||||
|
||||
if (lowerIdx < 0)
|
||||
{
|
||||
// The item came from the lower ListView
|
||||
// so just insert it.
|
||||
e.ItemsSource.Insert(higherIdx, e.DataItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
// null values will cause an error when calling Move.
|
||||
// It looks like a bug in ObservableCollection to me.
|
||||
if (e.ItemsSource[lowerIdx] == null ||
|
||||
e.ItemsSource[higherIdx] == null)
|
||||
return;
|
||||
|
||||
// The item came from the ListView into which
|
||||
// it was dropped, so swap it with the item
|
||||
// at the target index.
|
||||
e.ItemsSource.Move(lowerIdx, higherIdx);
|
||||
e.ItemsSource.Move(higherIdx - 1, lowerIdx);
|
||||
}
|
||||
|
||||
// Set this to 'Move' so that the OnListViewDrop knows to
|
||||
// remove the item from the other ListView.
|
||||
e.Effects = DragDropEffects.Move;
|
||||
}
|
||||
|
||||
#endregion // dragMgr_ProcessDrop
|
||||
|
||||
#region OnListViewDragEnter
|
||||
|
||||
// Handles the DragEnter event for both ListViews.
|
||||
void OnListViewDragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
e.Effects = DragDropEffects.Move;
|
||||
}
|
||||
|
||||
#endregion // OnListViewDragEnter
|
||||
|
||||
#region OnListViewDrop
|
||||
|
||||
// Handles the Drop event for both ListViews.
|
||||
void OnListViewDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Effects == DragDropEffects.None)
|
||||
return;
|
||||
ViewModel.Menu menuV = e.Data.GetData(typeof(ViewModel.Menu)) as ViewModel.Menu;
|
||||
DataInfos data = e.Data.GetData(typeof(DataInfos)) as DataInfos;
|
||||
|
||||
if (sender == this.menu)
|
||||
{
|
||||
if (this.dragMgr.IsDragInProgress)
|
||||
return;
|
||||
|
||||
// An item was dragged from the bottom ListView into the top ListView
|
||||
// so remove that item from the bottom ListView.
|
||||
(this.data.ItemsSource as ObservableCollection<DataInfos>).Remove(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.dragMgr2.IsDragInProgress)
|
||||
return;
|
||||
|
||||
// An item was dragged from the top ListView into the bottom ListView
|
||||
// so remove that item from the top ListView.
|
||||
(this.menu.ItemsSource as ObservableCollection<ViewModel.Menu>).Remove(menuV);
|
||||
AppData appData = this.DataContext as AppData;
|
||||
appData.AppConfig.WindowWidth = this.Width;
|
||||
appData.AppConfig.WindowHeight = this.Height;
|
||||
CommonCode.SaveAppData(appData);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion // OnListViewDrop
|
||||
|
||||
|
||||
|
||||
private void leftCard_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
@@ -287,13 +240,13 @@ namespace GeekDesk
|
||||
ViewModel.Menu pojo = (ViewModel.Menu)((ContextMenu)((MenuItem)sender).Parent).DataContext;
|
||||
string menuTitle = pojo.menu;
|
||||
int index = 0;
|
||||
foreach (object obj in menu.Items)
|
||||
foreach (object obj in menus.Items)
|
||||
{
|
||||
string test = ((ViewModel.Menu)obj).menu;
|
||||
if (test == menuTitle)
|
||||
{
|
||||
menu.Items.RemoveAt(index);
|
||||
menu.Items.Refresh();
|
||||
menus.Items.RemoveAt(index);
|
||||
menus.Items.Refresh();
|
||||
return;
|
||||
}
|
||||
index++;
|
||||
@@ -301,10 +254,7 @@ namespace GeekDesk
|
||||
|
||||
}
|
||||
|
||||
public Double ConvertString(string val)
|
||||
{
|
||||
return Convert.ToDouble(val);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -315,7 +265,7 @@ namespace GeekDesk
|
||||
{
|
||||
public List<ViewModel.Menu> MenuList { get; set; }
|
||||
|
||||
public List<ViewModel.DataInfos> DataList { get; set; }
|
||||
public List<ViewModel.IconInfo> DataList { get; set; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GeekDesk.Constant;
|
||||
using GeekDesk.ViewModel;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
/// <summary>
|
||||
/// 提取一些代码
|
||||
@@ -15,45 +10,49 @@ namespace GeekDesk.Util
|
||||
{
|
||||
class CommonCode
|
||||
{
|
||||
private static string appConfigFilePath = AppDomain.CurrentDomain.BaseDirectory.Trim() + "\\config";
|
||||
|
||||
/// <summary>
|
||||
/// 获取app配置
|
||||
/// 获取app 数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static AppConfig GetAppConfig()
|
||||
public static AppData GetAppData()
|
||||
{
|
||||
AppConfig config;
|
||||
if (!File.Exists(appConfigFilePath))
|
||||
AppData appData;
|
||||
if (!File.Exists(AppConstant.DATA_FILE_PATH))
|
||||
{
|
||||
using (FileStream fs = File.Create(appConfigFilePath)) { }
|
||||
config = new AppConfig();
|
||||
SaveAppConfig(config);
|
||||
using (FileStream fs = File.Create(AppConstant.DATA_FILE_PATH)) { }
|
||||
appData = new AppData();
|
||||
SaveAppData(appData);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
using (FileStream fs = new FileStream(appConfigFilePath, FileMode.Open))
|
||||
using (FileStream fs = new FileStream(AppConstant.DATA_FILE_PATH, FileMode.Open))
|
||||
{
|
||||
BinaryFormatter bf = new BinaryFormatter();
|
||||
string json = bf.Deserialize(fs) as string;
|
||||
config = JsonConvert.DeserializeObject<AppConfig>(json);
|
||||
appData = bf.Deserialize(fs) as AppData;
|
||||
}
|
||||
}
|
||||
return config;
|
||||
return appData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存app配置
|
||||
/// 保存app 数据
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
public static void SaveAppConfig(AppConfig config)
|
||||
/// <param name="appData"></param>
|
||||
public static void SaveAppData(AppData appData)
|
||||
{
|
||||
using (FileStream fs = new FileStream(appConfigFilePath, FileMode.Create))
|
||||
|
||||
using (FileStream fs = new FileStream(AppConstant.DATA_FILE_PATH, FileMode.Create))
|
||||
{
|
||||
BinaryFormatter bf = new BinaryFormatter();
|
||||
string json = JsonConvert.SerializeObject(config);
|
||||
bf.Serialize(fs, json);
|
||||
bf.Serialize(fs, appData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GeekDesk.Util
|
||||
{
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
// Copyright (C) Josh Smith - January 2007
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace WPF.JoshSmith.Adorners
|
||||
{
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace GeekDesk.Util
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
// Copyright (C) Josh Smith - January 2007
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using WPF.JoshSmith.Adorners;
|
||||
using WPF.JoshSmith.Controls.Utilities;
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace GeekDesk.Util
|
||||
@@ -15,7 +11,8 @@ namespace GeekDesk.Util
|
||||
if (value != null && value.ToString().Length > 0)
|
||||
{
|
||||
return System.Convert.ToDouble(value.ToString()) - 10d;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0d;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
using Microsoft.Win32;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Drawing.Imaging;
|
||||
using GeekDesk.Util;
|
||||
|
||||
namespace GeekDesk.Util
|
||||
{
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
using GalaSoft.MvvmLight;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using GeekDesk.Constant;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace GeekDesk.ViewModel
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
public class AppConfig : ViewModelBase
|
||||
public class AppConfig : System.ComponentModel.INotifyPropertyChanged
|
||||
{
|
||||
private int menuSortType = (int)SortType.CUSTOM; //菜单排序类型
|
||||
private int iconSortType = (int)SortType.CUSTOM; //图表排序类型
|
||||
@@ -18,8 +16,10 @@ namespace GeekDesk.ViewModel
|
||||
private double menuCardWidth = (double)DefaultConstant.MENU_CARD_WIDHT;//菜单栏宽度
|
||||
|
||||
|
||||
|
||||
#region GetSet
|
||||
public int MenuSortType {
|
||||
public int MenuSortType
|
||||
{
|
||||
get
|
||||
{
|
||||
return menuSortType;
|
||||
@@ -27,7 +27,7 @@ namespace GeekDesk.ViewModel
|
||||
set
|
||||
{
|
||||
menuSortType = value;
|
||||
RaisePropertyChanged();
|
||||
OnPropertyChanged("MenuSortType");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace GeekDesk.ViewModel
|
||||
set
|
||||
{
|
||||
iconSortType = value;
|
||||
RaisePropertyChanged();
|
||||
OnPropertyChanged("IconSortType");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace GeekDesk.ViewModel
|
||||
set
|
||||
{
|
||||
windowWidth = value;
|
||||
RaisePropertyChanged();
|
||||
OnPropertyChanged("WindowWidth");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace GeekDesk.ViewModel
|
||||
set
|
||||
{
|
||||
windowHeight = value;
|
||||
RaisePropertyChanged();
|
||||
OnPropertyChanged("WindowHeight");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,9 +79,17 @@ namespace GeekDesk.ViewModel
|
||||
set
|
||||
{
|
||||
menuCardWidth = value;
|
||||
RaisePropertyChanged();
|
||||
OnPropertyChanged("MenuCardWidth");
|
||||
}
|
||||
}
|
||||
|
||||
[field: NonSerializedAttribute()]
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
private void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
61
ViewModel/AppData.cs
Normal file
61
ViewModel/AppData.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace GeekDesk.ViewModel
|
||||
{
|
||||
[Serializable]
|
||||
class AppData : INotifyPropertyChanged
|
||||
{
|
||||
private List<string> menuList = new List<string>();
|
||||
private Dictionary<string, List<IconInfo>> iconMap = new Dictionary<string, List<IconInfo>>();
|
||||
private AppConfig appConfig = new AppConfig();
|
||||
|
||||
public List<string> MenuList
|
||||
{
|
||||
get
|
||||
{
|
||||
return menuList;
|
||||
}
|
||||
set
|
||||
{
|
||||
menuList = value;
|
||||
OnPropertyChanged("MenuList");
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, List<IconInfo>> IconMap
|
||||
{
|
||||
get
|
||||
{
|
||||
return iconMap;
|
||||
}
|
||||
set
|
||||
{
|
||||
iconMap = value;
|
||||
OnPropertyChanged("IconMap");
|
||||
}
|
||||
}
|
||||
|
||||
public AppConfig AppConfig
|
||||
{
|
||||
get
|
||||
{
|
||||
return appConfig;
|
||||
}
|
||||
set
|
||||
{
|
||||
appConfig = value;
|
||||
OnPropertyChanged("AppConfig");
|
||||
}
|
||||
}
|
||||
|
||||
[field: NonSerializedAttribute()]
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
private void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using GalaSoft.MvvmLight;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace GeekDesk.ViewModel
|
||||
{
|
||||
public class DataInfos : ViewModelBase
|
||||
{
|
||||
private string path; //路径
|
||||
private string name; //文件名
|
||||
private int count = 0; //打开次数
|
||||
private BitmapImage bitmapImage; //位图
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return count;
|
||||
}
|
||||
set
|
||||
{
|
||||
count = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return name;
|
||||
}
|
||||
set
|
||||
{
|
||||
name = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return path;
|
||||
}
|
||||
set
|
||||
{
|
||||
path = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public BitmapImage BitmapImage
|
||||
{
|
||||
get
|
||||
{
|
||||
return bitmapImage;
|
||||
}
|
||||
set
|
||||
{
|
||||
bitmapImage = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
137
ViewModel/IconInfo.cs
Normal file
137
ViewModel/IconInfo.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace GeekDesk.ViewModel
|
||||
{
|
||||
[Serializable]
|
||||
public class IconInfo : INotifyPropertyChanged
|
||||
{
|
||||
private string path; //路径
|
||||
private string name; //文件名
|
||||
private int count = 0; //打开次数
|
||||
[field: NonSerialized]
|
||||
private BitmapImage bitmapImage; //位图
|
||||
private byte[] imageByteArr; //图片 base64
|
||||
private string content; //显示信息
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return count;
|
||||
}
|
||||
set
|
||||
{
|
||||
count = value;
|
||||
Content = Path + "\n" + Name + "\n使用次数: " + Count;
|
||||
OnPropertyChanged("Count");
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return name;
|
||||
}
|
||||
set
|
||||
{
|
||||
name = value;
|
||||
Content = Path + "\n" + Name + "\n使用次数: " + Count;
|
||||
OnPropertyChanged("Name");
|
||||
}
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return path;
|
||||
}
|
||||
set
|
||||
{
|
||||
path = value;
|
||||
Content = Path + "\n" + Name + "\n使用次数: " + Count;
|
||||
OnPropertyChanged("Path");
|
||||
}
|
||||
}
|
||||
|
||||
public BitmapImage BitmapImage
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
return ToImage(ImageByteArr);
|
||||
}
|
||||
set
|
||||
{
|
||||
bitmapImage = value;
|
||||
ImageByteArr = getJPGFromImageControl(bitmapImage);
|
||||
OnPropertyChanged("BitmapImage");
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] ImageByteArr
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
return imageByteArr;
|
||||
}
|
||||
set
|
||||
{
|
||||
imageByteArr = value;
|
||||
OnPropertyChanged("ImageByteArr");
|
||||
}
|
||||
}
|
||||
|
||||
public string Content
|
||||
{
|
||||
get
|
||||
{
|
||||
return content;
|
||||
}
|
||||
set
|
||||
{
|
||||
content = value;
|
||||
OnPropertyChanged("Content");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[field: NonSerializedAttribute()]
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
private void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public BitmapImage ToImage(byte[] array)
|
||||
{
|
||||
using (var ms = new System.IO.MemoryStream(array))
|
||||
{
|
||||
var image = new BitmapImage();
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad; // here
|
||||
image.StreamSource = ms;
|
||||
image.EndInit();
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getJPGFromImageControl(BitmapImage bi)
|
||||
{
|
||||
using (MemoryStream memStream = new MemoryStream())
|
||||
{
|
||||
PngBitmapEncoder encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(bi));
|
||||
encoder.Save(memStream);
|
||||
return memStream.GetBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GeekDesk.ViewModel
|
||||
{
|
||||
class MainModel
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
using GalaSoft.MvvmLight;
|
||||
|
||||
namespace GeekDesk.ViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains properties that the main View can data bind to.
|
||||
/// <para>
|
||||
/// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// You can also use Blend to data bind with the tool's support.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// See http://www.galasoft.ch/mvvm
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public class MainViewModel : ViewModelBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the MainViewModel class.
|
||||
/// </summary>
|
||||
public MainViewModel()
|
||||
{
|
||||
////if (IsInDesignMode)
|
||||
////{
|
||||
//// // Code runs in Blend --> create design time data.
|
||||
////}
|
||||
////else
|
||||
////{
|
||||
//// // Code runs "for real"
|
||||
////}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace GeekDesk.ViewModel
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user