✨ feture 增加关联实时文件夹
This commit is contained in:
@@ -49,7 +49,7 @@ namespace GeekDesk.Control.UserControls.Config
|
||||
OpenFileDialog ofd = new OpenFileDialog
|
||||
{
|
||||
Multiselect = false, //只允许选中单个文件
|
||||
Filter = "图像文件(*.png, *.jpg)|*.png;*.jpg;*.gif"
|
||||
Filter = "图像文件(*.png, *.jpg, *.gif)|*.png;*.jpg;*.gif"
|
||||
};
|
||||
if (ofd.ShowDialog() == true)
|
||||
{
|
||||
|
||||
@@ -139,6 +139,7 @@
|
||||
<hc:Card.ContextMenu>
|
||||
<ContextMenu Width="200">
|
||||
<MenuItem Header="新建菜单" Click="CreateMenu"/>
|
||||
<MenuItem Header="新建关联菜单" Click="CreateLinkMenu"/>
|
||||
<MenuItem x:Name="AlterPW1" Header="修改密码" Click="AlterPassword"/>
|
||||
</ContextMenu>
|
||||
</hc:Card.ContextMenu>
|
||||
@@ -158,6 +159,7 @@
|
||||
<ListBox.Resources>
|
||||
<ContextMenu x:Key="MenuDialog" Width="200">
|
||||
<MenuItem Header="新建菜单" Click="CreateMenu"/>
|
||||
<MenuItem Header="新建关联菜单" Click="CreateLinkMenu"/>
|
||||
<MenuItem Header="重命名" Click="RenameMenu" Tag="{Binding}"/>
|
||||
<MenuItem Header="加密此列表" Click="EncryptMenu" Tag="{Binding}"/>
|
||||
<MenuItem x:Name="AlterPW2" Header="修改密码" Click="AlterPassword"/>
|
||||
|
||||
@@ -4,14 +4,19 @@ using GeekDesk.Control.Other;
|
||||
using GeekDesk.Control.Windows;
|
||||
using GeekDesk.Util;
|
||||
using GeekDesk.ViewModel;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using WindowsAPICodePack.Dialogs;
|
||||
|
||||
namespace GeekDesk.Control.UserControls.PannelCard
|
||||
{
|
||||
@@ -200,6 +205,87 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
||||
Lbi_Selected(obj, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建实时文件菜单
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void CreateLinkMenu(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
CommonOpenFileDialog dialog = new CommonOpenFileDialog
|
||||
{
|
||||
IsFolderPicker = true,
|
||||
Title = "选择关联文件夹"
|
||||
};
|
||||
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
|
||||
{
|
||||
string menuId = System.Guid.NewGuid().ToString();
|
||||
new Thread(() =>
|
||||
{
|
||||
this.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
string path = dialog.FileName;
|
||||
|
||||
MenuInfo menuInfo = new MenuInfo
|
||||
{
|
||||
MenuName = Path.GetFileNameWithoutExtension(path),
|
||||
MenuId = menuId,
|
||||
MenuType = MenuType.LINK,
|
||||
LinkPath = path,
|
||||
IsEncrypt = false,
|
||||
};
|
||||
|
||||
appData.MenuList.Add(menuInfo);
|
||||
|
||||
MenuListBox.SelectedIndex = appData.MenuList.Count - 1;
|
||||
appData.AppConfig.SelectedMenuIndex = MenuListBox.SelectedIndex;
|
||||
appData.AppConfig.SelectedMenuIcons = menuInfo.IconList;
|
||||
//首次触发不了Selected事件
|
||||
object obj = MenuListBox.ItemContainerGenerator.ContainerFromIndex(MenuListBox.SelectedIndex);
|
||||
SetListBoxItemEvent((ListBoxItem)obj);
|
||||
Lbi_Selected(obj, null);
|
||||
|
||||
HandyControl.Controls.Growl.Success("菜单关联成功, 后台加载列表!", "MainWindowGrowl");
|
||||
|
||||
FileWatcher.LinkMenuWatcher(menuInfo);
|
||||
}));
|
||||
}).Start();
|
||||
|
||||
new Thread(() =>
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
this.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
MenuInfo info = null;
|
||||
foreach (MenuInfo menuInfo in appData.MenuList)
|
||||
{
|
||||
if (menuInfo.MenuId.Equals(menuId))
|
||||
{
|
||||
info = menuInfo;
|
||||
}
|
||||
}
|
||||
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(info.LinkPath);
|
||||
FileSystemInfo[] fileInfos = dirInfo.GetFileSystemInfos();
|
||||
foreach (FileSystemInfo fileInfo in fileInfos)
|
||||
{
|
||||
IconInfo iconInfo = CommonCode.GetIconInfoByPath_NoWrite(fileInfo.FullName);
|
||||
info.IconList.Add(iconInfo);
|
||||
}
|
||||
}));
|
||||
}).Start();
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogUtil.WriteErrorLog(ex, "新建关联菜单失败!");
|
||||
HandyControl.Controls.Growl.WarningGlobal("新建关联菜单失败!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重命名菜单 将textbox 设置为可见
|
||||
@@ -635,5 +721,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user