增加 添加系统和开始菜单项目功能

This commit is contained in:
liufei
2022-01-09 15:37:37 +08:00
parent 8ee27e247b
commit ab13cff769
19 changed files with 919 additions and 90 deletions

File diff suppressed because one or more lines are too long

View File

@@ -9,7 +9,6 @@
xmlns:DraggAnimatedPanel="clr-namespace:DraggAnimatedPanel"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
>
<UserControl.Resources>
<!--右侧栏样式动画-->
@@ -48,11 +47,16 @@
<hc:Card.ContextMenu>
<ContextMenu Width="200">
<MenuItem Header="添加URL项目" Click="AddUrlIcon"/>
<MenuItem Header="添加系统项目" Click="AddSystemIcon"/>
</ContextMenu>
</hc:Card.ContextMenu>
<WrapPanel Orientation="Horizontal" VirtualizingPanel.VirtualizationMode="Recycling" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.IsContainerVirtualizable="True">
<WrapPanel Orientation="Horizontal" VirtualizingPanel.VirtualizationMode="Recycling"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.IsContainerVirtualizable="True"
>
<ListBox x:Name="IconListBox" ItemsSource="{Binding AppConfig.SelectedMenuIcons, Mode=TwoWay}"
BorderThickness="0"
Padding="0,10,0,0"
>
<ListBox.Background>
<SolidColorBrush Opacity="0"/>
@@ -72,6 +76,7 @@
<MenuItem Header="管理员方式运行" Click="IconAdminStart" Tag="{Binding}"/>
<MenuItem Header="打开文件所在位置" Click="ShowInExplore" Tag="{Binding}"/>
<MenuItem Header="添加URL项目" Click="AddUrlIcon"/>
<MenuItem Header="添加系统项目" Click="AddSystemIcon"/>
<MenuItem Header="资源管理器菜单" Click="SystemContextMenu" Tag="{Binding}"/>
<MenuItem Header="属性" Click="PropertyConfig" Tag="{Binding}"/>
<MenuItem Header="从列表移除" Click="RemoveIcon" Tag="{Binding}"/>
@@ -99,7 +104,7 @@
hc:Poptip.Content="{Binding Content}"
hc:Poptip.Placement="BottomLeft"
Background="#00FFFFFF"
MouseLeftButtonUp="IconClick"
MouseLeftButtonDown="IconClick"
MouseEnter="StackPanel_MouseEnter"
MouseLeave="StackPanel_MouseLeave"
>
@@ -118,7 +123,7 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</WrapPanel>
</hc:Card>
</UserControl>

View File

@@ -1,6 +1,7 @@
using DraggAnimatedPanelExample;
using GeekDesk.Constant;
using GeekDesk.Control.Other;
using GeekDesk.Control.Windows;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using HandyControl.Controls;
@@ -66,15 +67,31 @@ namespace GeekDesk.Control.UserControls.PannelCard
/// <param name="e"></param>
private void IconClick(object sender, MouseButtonEventArgs e)
{
IconInfo icon = (IconInfo)((SimpleStackPanel)sender).Tag;
if (icon.AdminStartUp)
if (appData.AppConfig.DoubleOpen && e.ClickCount >= 2)
{
StartIconApp(icon, IconStartType.ADMIN_STARTUP);
IconInfo icon = (IconInfo)((SimpleStackPanel)sender).Tag;
if (icon.AdminStartUp)
{
StartIconApp(icon, IconStartType.ADMIN_STARTUP);
}
else
{
StartIconApp(icon, IconStartType.DEFAULT_STARTUP);
}
}
else
else if (!appData.AppConfig.DoubleOpen && e.ClickCount == 1)
{
StartIconApp(icon, IconStartType.DEFAULT_STARTUP);
IconInfo icon = (IconInfo)((SimpleStackPanel)sender).Tag;
if (icon.AdminStartUp)
{
StartIconApp(icon, IconStartType.ADMIN_STARTUP);
}
else
{
StartIconApp(icon, IconStartType.DEFAULT_STARTUP);
}
}
}
/// <summary>
@@ -103,30 +120,88 @@ namespace GeekDesk.Control.UserControls.PannelCard
{
try
{
Process p = new Process();
p.StartInfo.FileName = icon.Path;
if (icon.IconType == IconType.OTHER)
using (Process p = new Process())
{
if (!File.Exists(icon.Path) && !Directory.Exists(icon.Path))
p.StartInfo.UseShellExecute = true;
string startArg = icon.StartArg;
if (startArg != null && Constants.SYSTEM_ICONS != null
&& Constants.SYSTEM_ICONS.ContainsKey(startArg))
{
HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!");
return;
StartSystemApp(startArg, type);
}
p.StartInfo.WorkingDirectory = icon.Path.Substring(0, icon.Path.LastIndexOf("\\"));
switch (type)
else
{
case IconStartType.ADMIN_STARTUP:
p.StartInfo.Arguments = "1";//启动参数
p.StartInfo.Verb = "runas";
p.StartInfo.CreateNoWindow = false; //设置显示窗口
p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动进程
p.StartInfo.ErrorDialog = false;
p.StartInfo.FileName = icon.Path;
//p.StartInfo.CreateNoWindow = false; //设置显示窗口
//p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动进程
//p.StartInfo.ErrorDialog = false;
if (!StringUtil.IsEmpty(startArg))
{
p.StartInfo.Arguments = startArg;
}
if (icon.IconType == IconType.OTHER)
{
if (!File.Exists(icon.Path) && !Directory.Exists(icon.Path))
{
HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!");
return;
}
p.StartInfo.WorkingDirectory = icon.Path.Substring(0, icon.Path.LastIndexOf("\\"));
switch (type)
{
case IconStartType.ADMIN_STARTUP:
//p.StartInfo.Arguments = "1";//启动参数
p.StartInfo.Verb = "runas";
if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
{
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
if (appData.AppConfig.MarginHide)
{
if (!MarginHide.IS_HIDE)
{
MainWindow.HideApp();
}
}
else
{
MainWindow.HideApp();
}
}
break;// c#好像不能case穿透
case IconStartType.DEFAULT_STARTUP:
if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
{
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
if (appData.AppConfig.MarginHide)
{
if (!MarginHide.IS_HIDE)
{
MainWindow.HideApp();
}
}
else
{
MainWindow.HideApp();
}
}
break;
case IconStartType.SHOW_IN_EXPLORE:
p.StartInfo.FileName = "Explorer.exe";
p.StartInfo.Arguments = "/e,/select," + icon.Path;
break;
}
}
else
{
if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
{
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
if (appData.AppConfig.MarginHide)
{
if (!MainWindow.hide.IsMargin())
if (!MarginHide.IS_HIDE)
{
MainWindow.HideApp();
}
@@ -135,43 +210,100 @@ namespace GeekDesk.Control.UserControls.PannelCard
{
MainWindow.HideApp();
}
}
break;// c#好像不能case穿透
case IconStartType.DEFAULT_STARTUP:
if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
{
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
if (appData.AppConfig.MarginHide)
{
if (!MainWindow.hide.IsMargin())
{
MainWindow.HideApp();
}
} else
{
MainWindow.HideApp();
}
}
break;
case IconStartType.SHOW_IN_EXPLORE:
p.StartInfo.FileName = "Explorer.exe";
p.StartInfo.Arguments = "/e,/select," + icon.Path;
break;
}
icon.Count++;
p.Start();
}
}
p.Start();
icon.Count++;
}
catch (Exception)
catch (Exception e)
{
HandyControl.Controls.Growl.WarningGlobal("程序启动失败(不支持的启动方式)!");
LogUtil.WriteErrorLog(e, "程序启动失败:path=" + icon.Path + ",type=" + type);
}
}
private void StartSystemApp(string startArg, IconStartType type)
{
if (type == IconStartType.SHOW_IN_EXPLORE)
{
Growl.WarningGlobal("系统项目不支持打开文件位置操作!");
return;
}
switch (startArg)
{
case "Calculator":
Process.Start("calc.exe");
break;
case "Computer":
Process.Start("explorer.exe");
break;
case "GroupPolicy":
Process.Start("gpedit.msc");
break;
case "Notepad":
Process.Start("notepad");
break;
case "Network":
Process.Start("ncpa.cpl");
break;
case "RecycleBin":
Process.Start("shell:RecycleBinFolder");
break;
case "Registry":
Process.Start("regedit.exe");
break;
case "Mstsc":
if (type == IconStartType.ADMIN_STARTUP)
{
Process.Start("mstsc", "-admin");
}
else
{
Process.Start("mstsc");
}
break;
case "Control":
Process.Start("Control");
break;
case "CMD":
if (type == IconStartType.ADMIN_STARTUP)
{
using (Process process = new Process())
{
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Verb = "runas";
process.Start();
}
}
else
{
Process.Start("cmd");
}
break;
}
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
if (appData.AppConfig.MarginHide)
{
if (!MarginHide.IS_HIDE)
{
MainWindow.HideApp();
}
}
else
{
MainWindow.HideApp();
}
}
/// <summary>
/// 拖动添加项目
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Wrap_Drop(object sender, DragEventArgs e)
{
Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
@@ -179,35 +311,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
foreach (object obj in dropObject)
{
string path = (string)obj;
//string base64 = ImageUtil.FileImageToBase64(path, ImageFormat.Png);
string ext = "";
if (!ImageUtil.IsSystemItem(path))
{
ext = System.IO.Path.GetExtension(path).ToLower();
}
if (".lnk".Equals(ext))
{
string targetPath = FileUtil.GetTargetPathByLnk(path);
if (targetPath!=null)
{
path = targetPath;
}
}
BitmapImage bi = ImageUtil.GetBitmapIconByPath(path);
IconInfo iconInfo = new IconInfo
{
Path = path,
BitmapImage = bi
};
iconInfo.DefaultImage = iconInfo.ImageByteArr;
iconInfo.Name = System.IO.Path.GetFileNameWithoutExtension(path);
if (StringUtil.IsEmpty(iconInfo.Name))
{
iconInfo.Name = path;
}
IconInfo iconInfo = CommonCode.GetIconInfoByPath(path);
MainWindow.appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Add(iconInfo);
CommonCode.SaveAppData(MainWindow.appData);
}
@@ -279,7 +383,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
Panel sp = sender as Panel;
DependencyObject dos = sp.Parent;
DependencyObject dos = sp.Parent;
Image img = sp.Children[0] as Image;
@@ -288,16 +392,16 @@ namespace GeekDesk.Control.UserControls.PannelCard
//动画定义
Storyboard myStoryboard = new Storyboard();
DoubleAnimation heightAnimation = new DoubleAnimation
DoubleAnimation heightAnimation = new DoubleAnimation
{
From = afterHeight,
To = height,
Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds))
};
DoubleAnimation widthAnimation = new DoubleAnimation
DoubleAnimation widthAnimation = new DoubleAnimation
{
From = afterWidth,
To = width,
@@ -333,7 +437,8 @@ namespace GeekDesk.Control.UserControls.PannelCard
ThreadStart ts = new ThreadStart(crs.Remove);
System.Threading.Thread t = new System.Threading.Thread(ts);
t.Start();
} else
}
else
{
img.BeginAnimation(WidthProperty, null);
img.BeginAnimation(HeightProperty, null);
@@ -396,10 +501,25 @@ namespace GeekDesk.Control.UserControls.PannelCard
sb2.Remove();
}
/// <summary>
/// 添加URL项目
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddUrlIcon(object sender, RoutedEventArgs e)
{
IconInfoUrlDialog urlDialog = new IconInfoUrlDialog();
urlDialog.dialog = HandyControl.Controls.Dialog.Show(urlDialog, "IconInfoDialog");
}
/// <summary>
/// 添加系统项目
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddSystemIcon(object sender, RoutedEventArgs e)
{
SystemItemWindow.Show();
}
}
}

View File

@@ -0,0 +1,57 @@
<UserControl x:Class="GeekDesk.Control.UserControls.SystemItem.SystemItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:GeekDesk.Control.UserControls.IconFont"
mc:Ignorable="d"
Background="#00FFFFFF"
>
<WrapPanel HorizontalAlignment="Center" VerticalAlignment="Top" Background="Transparent">
<ListBox x:Name="ItemListBox" ItemsSource="{Binding IconInfos}" BorderThickness="0"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.IsContainerVirtualizable="True"
>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" Background="#00FFFFFF"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Background>
<SolidColorBrush Opacity="0"/>
</ListBox.Background>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Width="80" Height="80" HorizontalAlignment="Center"
Background="#00FFFFFF"
hc:Poptip.IsOpen="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
hc:Poptip.Content="{Binding Content_NoWrite, Mode=OneWay}"
Tag="{Binding}"
MouseLeftButtonDown="Icon_MouseLeftButtonDown"
hc:Poptip.Placement="BottomLeft"
hc:Poptip.HitMode="None"
>
<Image Source="{Binding BitmapImage_NoWrite, Mode=OneWay}" Width="45" Height="45" RenderOptions.BitmapScalingMode="HighQuality" />
<TextBlock TextAlignment="Center"
HorizontalAlignment="Center"
VerticalAlignment="Center"
TextWrapping="Wrap"
MaxHeight="40"
FontSize="13"
TextTrimming="WordEllipsis"
Width="65" Text="{Binding Name_NoWrite, Mode=OneWay}"
/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</WrapPanel>
</UserControl>

View File

@@ -0,0 +1,59 @@
using GeekDesk.Constant;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace GeekDesk.Control.UserControls.SystemItem
{
/// <summary>
/// IconPannel.xaml 的交互逻辑
/// </summary>
public partial class SystemItem : UserControl
{
public SystemItem()
{
InitializeComponent();
}
private void Icon_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
IconInfo thisInfo = (sender as StackPanel).Tag as IconInfo;
MenuInfo menuInfo = MainWindow.appData.MenuList[MainWindow.appData.AppConfig.SelectedMenuIndex];
string startArg = thisInfo.StartArg;
IconInfo iconInfo;
if (Constants.SYSTEM_ICONS.ContainsKey(startArg))
{
//系统项
iconInfo = new IconInfo
{
Name_NoWrite = thisInfo.Name_NoWrite,
Path_NoWrite = thisInfo.Path_NoWrite,
StartArg_NoWrite = thisInfo.StartArg_NoWrite,
BitmapImage_NoWrite = thisInfo.BitmapImage_NoWrite
};
iconInfo.Content_NoWrite = iconInfo.Name_NoWrite
+ "\n使用次数:" + iconInfo.Count;
} else
{
//startupMenu or Store
iconInfo = CommonCode.GetIconInfoByPath(thisInfo.LnkPath_NoWrite);
}
menuInfo.IconList.Add(iconInfo);
CommonCode.SaveAppData(MainWindow.appData);
}
}
}

View File

@@ -0,0 +1,100 @@
<Window x:Class="GeekDesk.Control.Windows.SystemItemWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GeekDesk.Control.Windows"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:uc="clr-namespace:GeekDesk.Control.UserControls.SystemItem"
xmlns:cvt="clr-namespace:GeekDesk.Converts"
mc:Ignorable="d"
Title="Svg"
Height="520" Width="700"
WindowStyle="None"
ResizeMode="NoResize"
AllowsTransparency="True"
Background="Transparent" ShowInTaskbar="False"
BorderThickness="0"
Focusable="True"
KeyDown="OnKeyDown"
>
<Window.Resources>
<Style x:Key="HcTabControl" TargetType="hc:TabControl" BasedOn="{StaticResource TabControlInLine}">
<Style.Setters>
<Setter Property="Background" Value="Transparent"/>
</Style.Setters>
</Style>
<Style x:Key="TabTitle" TargetType="hc:TabItem" BasedOn="{StaticResource TabItemInLine}">
<Style.Setters>
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="White" Opacity="0.68"/>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
<cvt:MenuInfoConvert x:Key="MenuInfoConvert"/>
</Window.Resources>
<Grid Margin="20">
<Grid.Effect>
<DropShadowEffect BlurRadius="30" Direction="-90" Color="Gray"
RenderingBias="Quality" ShadowDepth="2"/>
</Grid.Effect>
<Border MouseDown="DragMove" Style="{StaticResource BorderBG}" hc:Dialog.Token="IconUrlDialog">
<hc:DialogContainer>
<Grid MouseDown="DragMove">
<StackPanel HorizontalAlignment="Center" Margin="10">
<Border CornerRadius="8" Height="30" Width="150">
<Border.Background>
<SolidColorBrush Color="White" Opacity="0.7"/>
</Border.Background>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Background="Transparent"
BorderThickness="0"
hc:IconElement.Geometry="{Binding AppConfig.SelectedMenuIndex, Mode=OneWay, Converter={StaticResource MenuInfoConvert}, ConverterParameter=1}"
hc:IconElement.Height="18"
hc:IconElement.Width="18"
IsEnabled="False"
Opacity="1"
>
</Button>
<TextBlock x:Name="MenuName" Text="{Binding AppConfig.SelectedMenuIndex, Mode=OneWay, Converter={StaticResource MenuInfoConvert}, ConverterParameter=2}" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
</Border>
</StackPanel>
<hc:TabControl x:Name="MyTabControl"
IsAnimationEnabled="True"
SelectionChanged="TabControl_SelectionChanged"
ShowContextMenu="True"
IsTabFillEnabled="True"
Margin="20,60,20,20"
Height="350"
VerticalAlignment="Top"
Style="{StaticResource HcTabControl}">
<hc:TabItem Tag="System" IsSelected="True" Header="系统应用" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource SystemIcon}" Style="{StaticResource TabTitle}">
<hc:SimplePanel>
<uc:SystemItem x:Name="SystemItem"/>
</hc:SimplePanel>
</hc:TabItem>
<hc:TabItem x:Name="StartMenu" Tag="StartMenu" Header="开始菜单应用" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource SystemIcon}" Style="{StaticResource TabTitle}">
<hc:SimplePanel>
<uc:SystemItem x:Name="StartMenuItem"/>
<hc:LoadingCircle x:Name="StartMenuLoading"/>
</hc:SimplePanel>
</hc:TabItem>
<!--<hc:TabItem Tag="Store" Header="商店应用(未开放)" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CustomIcon}" Style="{StaticResource TabTitle}">
<hc:SimplePanel>
<uc:SystemItem x:Name="StoreItem"/>
</hc:SimplePanel>
</hc:TabItem>-->
</hc:TabControl>
<Button Content="关闭" Click="Close_Click" Margin="594,420,20,31.5"/>
</Grid>
</hc:DialogContainer>
</Border>
</Grid>
</Window>

View File

@@ -0,0 +1,283 @@
using GeekDesk.Constant;
using GeekDesk.Control.Other;
using GeekDesk.Interface;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Resources;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using static GeekDesk.Util.ShowWindowFollowMouse;
namespace GeekDesk.Control.Windows
{
/// <summary>
/// SystemItemWindow.xaml 的交互逻辑
/// 添加系统项目到对应菜单
/// </summary>
public partial class SystemItemWindow : Window, IWindowCommon
{
private static AppConfig appConfig = MainWindow.appData.AppConfig;
private static SystemItemViewModel vm;
private static List<IconInfo> systemIcons;
private static List<IconInfo> startMenuIcons;
private static List<IconInfo> storeIcons;
private SystemItemWindow()
{
vm = new SystemItemViewModel();
this.DataContext = vm;
InitializeComponent();
this.Topmost = true;
}
/// <summary>
/// 移动窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}
}
private void Close_Click(object sender, RoutedEventArgs e)
{
this.DataContext = null;
this.Close();
}
/// <summary>
/// 切换选项卡
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
TabItem ti = this.MyTabControl.SelectedItem as TabItem;
List<IconInfo> systemInfos = vm.IconInfos;
if (systemInfos == null)
{
systemInfos = new List<IconInfo>();
}
switch (ti.Tag.ToString())
{
case "StartMenu": //开始菜单
if (startMenuIcons == null)
{
vm.IconInfos = null;
System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(GetStartMenuInfos))
{
IsBackground = true
};
t.Start();
} else
{
StartMenuLoading.Visibility = Visibility.Collapsed;
vm.IconInfos = startMenuIcons;
}
break;
case "Store": //应用商店
if (storeIcons == null)
{
vm.IconInfos = null;
storeIcons = new List<IconInfo>();
vm.IconInfos = storeIcons;
}
else
{
vm.IconInfos = storeIcons;
}
break;
default: //默认系统项
if (systemIcons == null)
{
vm.IconInfos = null;
systemIcons = GetSysteIconInfos();
vm.IconInfos = systemIcons;
} else
{
vm.IconInfos = systemIcons;
}
break;
}
}
/// <summary>
/// 获取开始菜单路径下项目
/// </summary>
/// <returns></returns>
private void GetStartMenuInfos()
{
App.Current.Dispatcher.Invoke((Action)(() =>
{
StartMenuLoading.Visibility = Visibility.Visible;
}));
List<IconInfo> infos = new List<IconInfo>();
//获取开始菜单路径
string path = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\Programs";
//递归获取信息
GetInfos(path, infos);
App.Current.Dispatcher.Invoke((Action)(() =>
{
if (StartMenu.IsSelected)
{
startMenuIcons = infos;
vm.IconInfos = startMenuIcons;
}
StartMenuLoading.Visibility = Visibility.Collapsed;
}));
}
/// <summary>
/// 递归获取文件信息
/// </summary>
/// <param name="path"></param>
/// <param name="listInfos"></param>
private void GetInfos(string path, List<IconInfo> listInfos)
{
DirectoryInfo di = new DirectoryInfo(path);
FileSystemInfo[] fileInfoArr = di.GetFileSystemInfos();
foreach(FileSystemInfo fi in fileInfoArr)
{
path = fi.FullName;
if (File.Exists(path))
{
string ext = Path.GetExtension(path).ToLower();
if (".exe".Equals(ext) || ".lnk".Equals(ext))
{
try
{
IconInfo iconInfo = CommonCode.GetIconInfoByPath_NoWrite(path);
if (iconInfo.Path_NoWrite != null)
{
iconInfo.Content_NoWrite = iconInfo.Path_NoWrite + "\n" + iconInfo.Name_NoWrite;
listInfos.Add(iconInfo);
}
}
catch (Exception) { }
}
}
else if (Directory.Exists(path))
{
GetInfos(path, listInfos);
}
}
}
/// <summary>
/// 获取系统项目
/// </summary>
/// <returns></returns>
private List<IconInfo> GetSysteIconInfos()
{
List<IconInfo> iconInfos = new List<IconInfo>();
Hashtable systemIcons = Constants.SYSTEM_ICONS;
IconInfo iconInfo;
foreach (object key in systemIcons.Keys)
{
string keyStr = key.ToString();
iconInfo = new IconInfo
{
Name_NoWrite = systemIcons[key].ToString()
};
iconInfo.BitmapImage_NoWrite = new BitmapImage(
new Uri("pack://application:,,,/GeekDesk;component/Resource/Image/SystemIcon/" + keyStr + ".png"
, UriKind.RelativeOrAbsolute));
iconInfo.StartArg = keyStr;
iconInfo.Content_NoWrite = iconInfo.Name_NoWrite;
iconInfos.Add(iconInfo);
}
return iconInfos;
}
public class SystemItemViewModel : INotifyPropertyChanged
{
private List<IconInfo> iconInfos;
private AppConfig appConfig;
public SystemItemViewModel()
{
this.AppConfig = MainWindow.appData.AppConfig;
}
public AppConfig AppConfig
{
get
{
return appConfig;
}
set
{
appConfig = value;
OnPropertyChanged("AppConfig");
}
}
public List<IconInfo> IconInfos
{
get
{
return iconInfos;
}
set
{
iconInfos = value;
OnPropertyChanged("IconInfos");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
private static System.Windows.Window window = null;
public static void Show()
{
if (window == null || !window.Activate())
{
window = new SystemItemWindow();
}
window.Show();
Keyboard.Focus(window);
ShowWindowFollowMouse.Show(window, MousePosition.LEFT_CENTER, 0, 0, false);
}
public void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
this.DataContext = null;
this.Close();
}
}
}
}

View File

@@ -0,0 +1,45 @@
using GeekDesk.Constant;
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.Converts
{
public class MenuInfoConvert : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int menuIndex = MainWindow.appData.AppConfig.SelectedMenuIndex;
if (menuIndex == -1)
{
return "";
} else
{
string type = parameter.ToString();
if ("1".Equals(type))
{
return MainWindow.appData.MenuList[menuIndex].MenuGeometry;
}
else
{
return MainWindow.appData.MenuList[menuIndex].MenuName;
}
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
//bool isChecked = (bool)value;
//if (!isChecked)
//{
// return null;
//}
//return (AppHideType)int.Parse(parameter.ToString());
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@@ -1,8 +1,11 @@
using GeekDesk.Constant;
using GeekDesk.Util;
using Newtonsoft.Json;
using System;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Media.Imaging;
/// <summary>
@@ -22,10 +25,60 @@ namespace GeekDesk.ViewModel
private string content; //显示信息
private bool adminStartUp = false; //始终管理员方式启动 默认否
private byte[] defaultImage; //默认图标
private string startArg; //启动参数
private string lnkPath;
private IconType iconType = IconType.OTHER;
public string LnkPath_NoWrite
{
get
{
return lnkPath;
}
set
{
lnkPath = value;
}
}
public string LnkPath
{
get
{
return lnkPath;
}
set
{
lnkPath = value;
OnPropertyChanged("LnkPath");
}
}
public string StartArg
{
get
{
return startArg;
}
set
{
startArg = value;
OnPropertyChanged("StartArg");
}
}
public string StartArg_NoWrite
{
get
{
return startArg;
}
set
{
startArg = value;
}
}
public IconType IconType
{
get
@@ -53,6 +106,18 @@ namespace GeekDesk.ViewModel
}
}
public byte[] DefaultImage_NoWrite
{
get
{
return defaultImage;
}
set
{
defaultImage = value;
}
}
public bool AdminStartUp
{
get
@@ -75,7 +140,14 @@ namespace GeekDesk.ViewModel
set
{
count = value;
Content = Path + "\n" + Name + "\n使用次数: " + Count;
if (StringUtil.IsEmpty(Path))
{
Content = Name + "\n使用次数: " + Count;
}
else
{
Content = Path + "\n" + Name + "\n使用次数: " + Count;
}
OnPropertyChanged("Count");
}
}
@@ -89,11 +161,30 @@ namespace GeekDesk.ViewModel
set
{
name = value;
Content = Path + "\n" + Name + "\n使用次数: " + Count;
if (StringUtil.IsEmpty(Path))
{
Content = Name + "\n使用次数: " + Count;
}
else
{
Content = Path + "\n" + Name + "\n使用次数: " + Count;
}
OnPropertyChanged("Name");
}
}
public string Name_NoWrite
{
get
{
return name;
}
set
{
name = value;
}
}
public string Path
{
get
@@ -103,11 +194,31 @@ namespace GeekDesk.ViewModel
set
{
path = value;
Content = Path + "\n" + Name + "\n使用次数: " + Count;
if (StringUtil.IsEmpty(Path))
{
Content = Name + "\n使用次数: " + Count;
}
else
{
Content = Path + "\n" + Name + "\n使用次数: " + Count;
}
OnPropertyChanged("Path");
}
}
public string Path_NoWrite
{
get
{
return path;
}
set
{
path = value;
}
}
public BitmapImage BitmapImage
{
get
@@ -123,6 +234,20 @@ namespace GeekDesk.ViewModel
}
}
public BitmapImage BitmapImage_NoWrite
{
get
{
return ImageUtil.ByteArrToImage(ImageByteArr_NoWrite);
}
set
{
bitmapImage = value;
ImageByteArr_NoWrite = ImageUtil.BitmapImageToByte(bitmapImage);
}
}
public byte[] ImageByteArr
{
get
@@ -137,6 +262,19 @@ namespace GeekDesk.ViewModel
}
}
public byte[] ImageByteArr_NoWrite
{
get
{
return imageByteArr;
}
set
{
imageByteArr = value;
}
}
public string Content
{
get
@@ -150,10 +288,18 @@ namespace GeekDesk.ViewModel
}
}
public string Content_NoWrite
{
get
{
return content;
}
set
{
content = value;
}
}
[field: NonSerializedAttribute()]