This commit is contained in:
liufei
2021-04-13 15:26:19 +08:00
parent cc399e2ef7
commit 5f38782623
26 changed files with 1778 additions and 1787 deletions

View File

@@ -1,10 +1,4 @@
using System; using System.Windows;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace GeekDesk namespace GeekDesk
{ {

13
Constant/AppConstant.cs Normal file
View 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数据文件路径
}
}

View File

@@ -1,10 +1,4 @@
using System; /// <summary>
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// 默认参数 /// 默认参数
/// </summary> /// </summary>
namespace GeekDesk.Constant namespace GeekDesk.Constant

View File

@@ -1,10 +1,4 @@
using System; namespace GeekDesk.Constant
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GeekDesk.Constant
{ {
enum SortType enum SortType
{ {

View File

@@ -2,11 +2,8 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
namespace DraggAnimatedPanel namespace DraggAnimatedPanel
{ {
@@ -23,7 +20,8 @@ namespace DraggAnimatedPanel
#region private #region private
UIElement __draggedElement; UIElement __draggedElement;
public UIElement _draggedElement { public UIElement _draggedElement
{
get { return __draggedElement; } get { return __draggedElement; }
set set
{ {

View File

@@ -1,14 +1,11 @@
/*Developed by (doiTTeam)=>doiTTeam.mail = devdoiTTeam@gmail.com*/ /*Developed by (doiTTeam)=>doiTTeam.mail = devdoiTTeam@gmail.com*/
using System; using System;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
using System.Windows.Navigation;
namespace DraggAnimatedPanel namespace DraggAnimatedPanel
{ {

View File

@@ -85,6 +85,7 @@
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Command\DelegateCommand.cs" /> <Compile Include="Command\DelegateCommand.cs" />
<Compile Include="Command\DelegateCommandBase.cs" /> <Compile Include="Command\DelegateCommandBase.cs" />
<Compile Include="Constant\AppConstant.cs" />
<Compile Include="Constant\DefaultConstant.cs" /> <Compile Include="Constant\DefaultConstant.cs" />
<Compile Include="Constant\SortType.cs" /> <Compile Include="Constant\SortType.cs" />
<Compile Include="DraggAnimatedPanel\DraggAnimatedPanel.cs" /> <Compile Include="DraggAnimatedPanel\DraggAnimatedPanel.cs" />
@@ -98,9 +99,8 @@
<Compile Include="Util\MouseUtilities.cs" /> <Compile Include="Util\MouseUtilities.cs" />
<Compile Include="Util\SystemIcon.cs" /> <Compile Include="Util\SystemIcon.cs" />
<Compile Include="ViewModel\AppConfig.cs" /> <Compile Include="ViewModel\AppConfig.cs" />
<Compile Include="ViewModel\DataInfos.cs" /> <Compile Include="ViewModel\AppData.cs" />
<Compile Include="ViewModel\MainModel.cs" /> <Compile Include="ViewModel\IconInfo.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="ViewModel\MenuViewModel.cs" /> <Compile Include="ViewModel\MenuViewModel.cs" />
<Page Include="MainWindow.xaml"> <Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>

View File

@@ -8,7 +8,7 @@
xmlns:util="clr-namespace:GeekDesk.Util" xmlns:util="clr-namespace:GeekDesk.Util"
xmlns:DraggAnimatedPanel="clr-namespace:DraggAnimatedPanel" x:Name="window" xmlns:DraggAnimatedPanel="clr-namespace:DraggAnimatedPanel" x:Name="window"
xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:hc="https://handyorg.github.io/handycontrol"
Title="MainWindow" Height="450" Width="800"> Title="MainWindow" Height="500" Width="600">
<Window.Resources> <Window.Resources>
<Style x:Key="ListBoxStyle" BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox"/> <Style x:Key="ListBoxStyle" BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox"/>
@@ -143,7 +143,7 @@
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox>--> </ListBox>-->
<ListBox x:Name="menu" ItemsSource="{Binding}"> <ListBox x:Name="menus" ItemsSource="{Binding MenuList}">
<ListBox.Resources> <ListBox.Resources>
<ContextMenu x:Key="menuDialog" Width="200"> <ContextMenu x:Key="menuDialog" Width="200">
<MenuItem Header="新建菜单"/> <MenuItem Header="新建菜单"/>
@@ -165,7 +165,7 @@
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding menu}" PreviewMouseLeftButtonDown="menuClick" /> <TextBlock Text="{Binding}" PreviewMouseLeftButtonDown="menuClick" />
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </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"> <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"> <WrapPanel Orientation="Horizontal">
<ListBox x:Name="data" ItemsSource="{Binding}" <ListBox x:Name="icons" ItemsSource="{Binding}"
BorderThickness="0" BorderThickness="0"
SelectionChanged="data_SelectionChanged" SelectionChanged="data_SelectionChanged"
> >
<!--<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource dataStyle}"/>
</ListBox.ItemContainerStyle>-->
<ListBox.ItemsPanel> <ListBox.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<DraggAnimatedPanel:DraggAnimatedPanel ItemsHeight="115" ItemsWidth="100" HorizontalAlignment="Center" SwapCommand="{Binding SwapCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"/> <DraggAnimatedPanel:DraggAnimatedPanel ItemsHeight="115" ItemsWidth="100" HorizontalAlignment="Center" SwapCommand="{Binding SwapCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"/>
</ItemsPanelTemplate> </ItemsPanelTemplate>
</ListBox.ItemsPanel> </ListBox.ItemsPanel>
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border Margin="5,5,5,5" CornerRadius="10"> <Border Margin="5,5,5,5" CornerRadius="10">
<StackPanel Tag="{Binding Path}" <StackPanel Tag="{Binding}"
MouseLeftButtonDown="dataClick" MouseLeftButtonDown="dataClick"
HorizontalAlignment="Center" 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" Margin="5,5,5,5"
Height="115" 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> <Image Style="{StaticResource imageStyle}"></Image>
<TextBlock Width="80" TextWrapping="Wrap" TextAlignment="Center" Height="35" LineHeight="15" FontSize="12" Text="{Binding Name}"/> <TextBlock Width="80" TextWrapping="Wrap" TextAlignment="Center" Height="35" LineHeight="15" FontSize="12" Text="{Binding Name}"/>

View File

@@ -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.Collections.Generic;
using System.IO;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media.Imaging; 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 namespace GeekDesk
{ {
/// <summary> /// <summary>
@@ -25,15 +18,18 @@ namespace GeekDesk
/// ///
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
private static MainModel mainModel;
ListViewDragDropManager<ViewModel.Menu> dragMgr; private static AppData appData = CommonCode.GetAppData();
ListViewDragDropManager<ViewModel.DataInfos> dragMgr2;
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
loadData();
List<string> menuList = new List<string>();
Dictionary<string, List<IconInfo>> iconMap = new Dictionary<string, List<IconInfo>>();
mainModel = new MainModel();
//this.DataContext = mainModel; //this.DataContext = mainModel;
//menu.Items = mainModel; //menu.Items = mainModel;
//System.Diagnostics.Process.Start(@"D:\SoftWare\WeGame\wegame.exe"); //System.Diagnostics.Process.Start(@"D:\SoftWare\WeGame\wegame.exe");
@@ -41,6 +37,29 @@ namespace GeekDesk
this.SizeChanged += MainWindow_Resize; 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; DelegateCommand<int[]> _swap;
public DelegateCommand<int[]> SwapCommand public DelegateCommand<int[]> SwapCommand
{ {
@@ -52,17 +71,17 @@ namespace GeekDesk
{ {
int fromS = indexes[0]; int fromS = indexes[0];
int to = indexes[1]; int to = indexes[1];
var elementSource = data.Items[to]; var elementSource = icons.Items[to];
var dragged = data.Items[fromS]; var dragged = icons.Items[fromS];
if (fromS > to) if (fromS > to)
{ {
data.Items.Remove(dragged); icons.Items.Remove(dragged);
data.Items.Insert(to, dragged); icons.Items.Insert(to, dragged);
} }
else else
{ {
data.Items.Remove(dragged); icons.Items.Remove(dragged);
data.Items.Insert(to, dragged); icons.Items.Insert(to, dragged);
} }
} }
); );
@@ -80,17 +99,17 @@ namespace GeekDesk
{ {
int fromS = indexes[0]; int fromS = indexes[0];
int to = indexes[1]; int to = indexes[1];
var elementSource = menu.Items[to]; var elementSource = menus.Items[to];
var dragged = menu.Items[fromS]; var dragged = menus.Items[fromS];
if (fromS > to) if (fromS > to)
{ {
menu.Items.Remove(dragged); menus.Items.Remove(dragged);
menu.Items.Insert(to, dragged); menus.Items.Insert(to, dragged);
} }
else else
{ {
menu.Items.Remove(dragged); menus.Items.Remove(dragged);
menu.Items.Insert(to, dragged); menus.Items.Insert(to, dragged);
} }
} }
); );
@@ -104,23 +123,41 @@ namespace GeekDesk
{ {
Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop); Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
if (dropObject == null) return; if (dropObject == null) return;
string path = (string)dropObject.GetValue(0); foreach (object obj in dropObject)
{
string path = (string)obj;
if (File.Exists(path)) if (File.Exists(path))
{ {
// 文件 // 文件
BitmapImage bi = FileIcon.GetBitmapImage(path); BitmapImage bi = FileIcon.GetBitmapImage(path);
DataInfos infos = new DataInfos(); IconInfo iconInfo = new IconInfo();
infos.Path = path; iconInfo.Path = path;
infos.BitmapImage = bi; iconInfo.BitmapImage = bi;
infos.Name = Path.GetFileNameWithoutExtension(path); iconInfo.Name = Path.GetFileNameWithoutExtension(path);
data.Items.Add(infos); List<IconInfo> iconList;
data.Items.Refresh(); 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)) else if (Directory.Exists(path))
{ {
//文件夹 //文件夹
} }
}
icons.Items.Refresh();
} }
@@ -139,8 +176,10 @@ namespace GeekDesk
/// <param name="e"></param> /// <param name="e"></param>
private void dataClick(object sender, MouseButtonEventArgs e) private void dataClick(object sender, MouseButtonEventArgs e)
{ {
//string path = ((StackPanel)sender).Tag.ToString(); IconInfo icon = (IconInfo)((StackPanel)sender).Tag;
//System.Diagnostics.Process.Start(path); System.Diagnostics.Process.Start(icon.Path);
icon.Count++;
CommonCode.SaveAppData(appData);
} }
/// <summary> /// <summary>
@@ -150,128 +189,42 @@ namespace GeekDesk
/// <param name="e"></param> /// <param name="e"></param>
private void data_SelectionChanged(object sender, SelectionChangedEventArgs e) 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 #region Window_Loaded
void Window_Loaded(object sender, RoutedEventArgs e) void Window_Loaded(object sender, RoutedEventArgs e)
{ {
AppConfig config = CommonCode.GetAppConfig(); //this.menus.Items.Add(new ViewModel.Menu() { menu = "test1" });
this.Width = config.WindowWidth; //this.menus.Items.Add(new ViewModel.Menu() { menu = "test2" });
this.Height = config.WindowHeight; //this.menus.Items.Add(new ViewModel.Menu() { menu = "test3" });
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" });
} }
#endregion // Window_Loaded #endregion // Window_Loaded
#region Window_Closing //#region Window_Closing
void Window_Closing(object sender, CancelEventArgs e) //void Window_Closing(object sender, CancelEventArgs e)
{ //{
Rect rect = this.RestoreBounds; // Rect rect = this.RestoreBounds;
AppConfig config = this.DataContext as AppConfig; // AppConfig config = this.DataContext as AppConfig;
config.WindowWidth = rect.Width; // config.WindowWidth = rect.Width;
config.WindowHeight = rect.Height; // config.WindowHeight = rect.Height;
CommonCode.SaveAppConfig(config); // CommonCode.SaveAppConfig(config);
} //}
#endregion // Window_Closing //#endregion // Window_Closing
void MainWindow_Resize(object sender, System.EventArgs e) void MainWindow_Resize(object sender, System.EventArgs e)
{ {
if (this.DataContext != null) if (this.DataContext != null)
{ {
AppConfig config = this.DataContext as AppConfig; AppData appData = this.DataContext as AppData;
config.WindowWidth = this.Width; appData.AppConfig.WindowWidth = this.Width;
config.WindowHeight = this.Height; appData.AppConfig.WindowHeight = this.Height;
CommonCode.SaveAppConfig(config); CommonCode.SaveAppData(appData);
}
}
#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);
} }
} }
#endregion // OnListViewDrop
private void leftCard_MouseRightButtonDown(object sender, MouseButtonEventArgs e) private void leftCard_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{ {
@@ -287,13 +240,13 @@ namespace GeekDesk
ViewModel.Menu pojo = (ViewModel.Menu)((ContextMenu)((MenuItem)sender).Parent).DataContext; ViewModel.Menu pojo = (ViewModel.Menu)((ContextMenu)((MenuItem)sender).Parent).DataContext;
string menuTitle = pojo.menu; string menuTitle = pojo.menu;
int index = 0; int index = 0;
foreach (object obj in menu.Items) foreach (object obj in menus.Items)
{ {
string test = ((ViewModel.Menu)obj).menu; string test = ((ViewModel.Menu)obj).menu;
if (test == menuTitle) if (test == menuTitle)
{ {
menu.Items.RemoveAt(index); menus.Items.RemoveAt(index);
menu.Items.Refresh(); menus.Items.Refresh();
return; return;
} }
index++; 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.Menu> MenuList { get; set; }
public List<ViewModel.DataInfos> DataList { get; set; } public List<ViewModel.IconInfo> DataList { get; set; }
} }

View File

@@ -1,6 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows; using System.Windows;

View File

@@ -1,12 +1,7 @@
using Newtonsoft.Json; using GeekDesk.Constant;
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.ViewModel; using GeekDesk.ViewModel;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
/// <summary> /// <summary>
/// 提取一些代码 /// 提取一些代码
@@ -15,45 +10,49 @@ namespace GeekDesk.Util
{ {
class CommonCode class CommonCode
{ {
private static string appConfigFilePath = AppDomain.CurrentDomain.BaseDirectory.Trim() + "\\config";
/// <summary> /// <summary>
/// 获取app配置 /// 获取app 数据
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static AppConfig GetAppConfig() public static AppData GetAppData()
{ {
AppConfig config; AppData appData;
if (!File.Exists(appConfigFilePath)) if (!File.Exists(AppConstant.DATA_FILE_PATH))
{ {
using (FileStream fs = File.Create(appConfigFilePath)) { } using (FileStream fs = File.Create(AppConstant.DATA_FILE_PATH)) { }
config = new AppConfig(); appData = new AppData();
SaveAppConfig(config); SaveAppData(appData);
} }
else else
{ {
using (FileStream fs = new FileStream(appConfigFilePath, FileMode.Open)) using (FileStream fs = new FileStream(AppConstant.DATA_FILE_PATH, FileMode.Open))
{ {
BinaryFormatter bf = new BinaryFormatter(); BinaryFormatter bf = new BinaryFormatter();
string json = bf.Deserialize(fs) as string; appData = bf.Deserialize(fs) as AppData;
config = JsonConvert.DeserializeObject<AppConfig>(json);
} }
} }
return config; return appData;
} }
/// <summary> /// <summary>
/// 保存app配置 /// 保存app 数据
/// </summary> /// </summary>
/// <param name="config"></param> /// <param name="appData"></param>
public static void SaveAppConfig(AppConfig config) 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(); BinaryFormatter bf = new BinaryFormatter();
string json = JsonConvert.SerializeObject(config); bf.Serialize(fs, appData);
bf.Serialize(fs, json);
} }
} }
} }
} }

View File

@@ -1,12 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using System.Text;
using System.Threading.Tasks;
namespace GeekDesk.Util namespace GeekDesk.Util
{ {

View File

@@ -1,13 +1,8 @@
// Copyright (C) Josh Smith - January 2007 // 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;
using System.Windows.Documents;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes; using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Controls;
namespace WPF.JoshSmith.Adorners namespace WPF.JoshSmith.Adorners
{ {

View File

@@ -1,13 +1,7 @@
using System; 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;
using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
namespace GeekDesk.Util namespace GeekDesk.Util

View File

@@ -1,14 +1,12 @@
// Copyright (C) Josh Smith - January 2007 // Copyright (C) Josh Smith - January 2007
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using WPF.JoshSmith.Adorners; using WPF.JoshSmith.Adorners;
using WPF.JoshSmith.Controls.Utilities; using WPF.JoshSmith.Controls.Utilities;

View File

@@ -1,9 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data; using System.Windows.Data;
namespace GeekDesk.Util namespace GeekDesk.Util
@@ -15,7 +11,8 @@ namespace GeekDesk.Util
if (value != null && value.ToString().Length > 0) if (value != null && value.ToString().Length > 0)
{ {
return System.Convert.ToDouble(value.ToString()) - 10d; return System.Convert.ToDouble(value.ToString()) - 10d;
} else }
else
{ {
return 0d; return 0d;
} }

View File

@@ -1,6 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;

View File

@@ -1,13 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing; using System.Drawing;
using Microsoft.Win32;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using GeekDesk.Util;
namespace GeekDesk.Util namespace GeekDesk.Util
{ {

View File

@@ -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 GeekDesk.Constant;
using System;
using System.ComponentModel;
namespace GeekDesk.ViewModel namespace GeekDesk.ViewModel
{ {
[Serializable] [Serializable]
public class AppConfig : ViewModelBase public class AppConfig : System.ComponentModel.INotifyPropertyChanged
{ {
private int menuSortType = (int)SortType.CUSTOM; //菜单排序类型 private int menuSortType = (int)SortType.CUSTOM; //菜单排序类型
private int iconSortType = (int)SortType.CUSTOM; //图表排序类型 private int iconSortType = (int)SortType.CUSTOM; //图表排序类型
@@ -18,8 +16,10 @@ namespace GeekDesk.ViewModel
private double menuCardWidth = (double)DefaultConstant.MENU_CARD_WIDHT;//菜单栏宽度 private double menuCardWidth = (double)DefaultConstant.MENU_CARD_WIDHT;//菜单栏宽度
#region GetSet #region GetSet
public int MenuSortType { public int MenuSortType
{
get get
{ {
return menuSortType; return menuSortType;
@@ -27,7 +27,7 @@ namespace GeekDesk.ViewModel
set set
{ {
menuSortType = value; menuSortType = value;
RaisePropertyChanged(); OnPropertyChanged("MenuSortType");
} }
} }
@@ -40,7 +40,7 @@ namespace GeekDesk.ViewModel
set set
{ {
iconSortType = value; iconSortType = value;
RaisePropertyChanged(); OnPropertyChanged("IconSortType");
} }
} }
@@ -53,7 +53,7 @@ namespace GeekDesk.ViewModel
set set
{ {
windowWidth = value; windowWidth = value;
RaisePropertyChanged(); OnPropertyChanged("WindowWidth");
} }
} }
@@ -66,7 +66,7 @@ namespace GeekDesk.ViewModel
set set
{ {
windowHeight = value; windowHeight = value;
RaisePropertyChanged(); OnPropertyChanged("WindowHeight");
} }
} }
@@ -79,9 +79,17 @@ namespace GeekDesk.ViewModel
set set
{ {
menuCardWidth = value; menuCardWidth = value;
RaisePropertyChanged(); OnPropertyChanged("MenuCardWidth");
} }
} }
[field: NonSerializedAttribute()]
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion #endregion
} }

61
ViewModel/AppData.cs Normal file
View 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));
}
}
}

View File

@@ -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
View 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();
}
}
}
}

View File

@@ -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
{
}
}

View File

@@ -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"
////}
}
}
}

View File

@@ -1,9 +1,4 @@
using System; using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GeekDesk.ViewModel namespace GeekDesk.ViewModel
{ {