Commit da028ffb by liulongfei

快捷键

parent eb2e1563
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace VIZ.Package.Domain
{
/// <summary>
/// 热键消息
/// </summary>
public class HotkeyMessage
{
/// <summary>
/// 热键
/// </summary>
public string Key { get; set; }
/// <summary>
/// 当前激活的视图
/// </summary>
public FrameworkElement View { get; set; }
}
}
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using VIZ.Framework.Core;
using VIZ.Package.Storage;
......@@ -125,6 +126,20 @@ namespace VIZ.Package.Domain
#endregion
#region View -- 视图
private WeakReference<FrameworkElement> view;
/// <summary>
/// 视图
/// </summary>
public WeakReference<FrameworkElement> View
{
get { return view; }
set { view = value; this.RaisePropertyChanged(nameof(View)); }
}
#endregion
/// <summary>
/// 空插件
/// </summary>
......
......@@ -87,6 +87,7 @@
<Compile Include="Message\Conn\ConnChangedMessage.cs" />
<Compile Include="Message\ControlObject\ControlListFieldChangedMessage.cs" />
<Compile Include="Message\ControlObject\ControlFieldChangedMessage.cs" />
<Compile Include="Message\Hotkey\HotkeyMessage.cs" />
<Compile Include="Message\Log\ErrorLogMessage.cs" />
<Compile Include="Message\Log\VizCommandLogMessage.cs" />
<Compile Include="Message\Page\PageDeleteMessage.cs" />
......
......@@ -27,6 +27,9 @@ namespace VIZ.Package.Module
// 初始化命令
this.InitCommand();
// 初始化消息
this.InitMessage();
// 注册服务
ApplicationDomainEx.ServiceManager.AddService(ViewServiceKeys.CONTROL_SERVICE, this);
}
......@@ -42,6 +45,14 @@ namespace VIZ.Package.Module
this.UpdateCommand = new VCommand(this.Update);
}
/// <summary>
/// 初始化消息
/// </summary>
private void InitMessage()
{
ApplicationDomainEx.MessageManager.Register<HotkeyMessage>(this, this.OnHotkeyMessage);
}
// ==============================================================
// Service & Controller
// ==============================================================
......@@ -182,6 +193,52 @@ namespace VIZ.Package.Module
#endregion
// ==============================================================
// Message
// ==============================================================
/// <summary>
/// 处理热键消息
/// </summary>
/// <param name="msg">消息</param>
private void OnHotkeyMessage(HotkeyMessage msg)
{
try
{
// 上板
if (string.Equals(msg.Key, ApplicationDomainEx.HotKeyConfig.Take))
{
this.Take();
return;
}
// 继续
if (string.Equals(msg.Key, ApplicationDomainEx.HotKeyConfig.TakeContinue))
{
this.Continue();
return;
}
// 下版
if (string.Equals(msg.Key, ApplicationDomainEx.HotKeyConfig.TakeOut))
{
this.TakeOut();
return;
}
// 更新
if (string.Equals(msg.Key, ApplicationDomainEx.HotKeyConfig.TakeUpdate))
{
this.Update();
return;
}
}
catch (Exception ex)
{
log.Error(ex);
}
}
// ==============================================================
// Private Function
// ==============================================================
......
......@@ -51,6 +51,7 @@ namespace VIZ.Package.Module
/// </summary>
private void InitMessage()
{
ApplicationDomainEx.MessageManager.Register<HotkeyMessage>(this, this.OnHotkeyMessage);
ApplicationDomainEx.MessageManager.Register<ControlFieldChangedMessage>(this, this.OnControlFieldChangedMessage);
ApplicationDomainEx.MessageManager.Register<PageOpenMessage>(this, this.OnPageOpenMessage);
}
......@@ -292,6 +293,27 @@ namespace VIZ.Package.Module
this.SelectedNavigationConfig = config;
}
/// <summary>
/// 热键消息
/// </summary>
/// <param name="msg">消息</param>
private void OnHotkeyMessage(HotkeyMessage msg)
{
try
{
// 保存
if (string.Equals(msg.Key, ApplicationDomainEx.HotKeyConfig.SaveOpendPageOrTemplateAndProject))
{
this.Save();
return;
}
}
catch (Exception ex)
{
log.Error(ex);
}
}
// =============================================================
// Public Function
// =============================================================
......
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using VIZ.Framework.Core;
using VIZ.Package.Domain;
using VIZ.Package.Plugin;
namespace VIZ.Package.Module
{
/// <summary>
/// 热键控制器
/// </summary>
public class HotkeyController
{
/// <summary>
/// 热键控制器
/// </summary>
/// <param name="vm">视图模型</param>
public HotkeyController(MainViewModel vm)
{
this.MainViewModel = vm;
}
/// <summary>
/// 主视图模型
/// </summary>
public MainViewModel MainViewModel { get; set; }
/// <summary>
/// 开始执行热键
/// </summary>
/// <param name="key">热键</param>
public void BeginExecute(string key)
{
if (string.IsNullOrWhiteSpace(key))
return;
WPFHelper.BeginInvoke(() =>
{
// 主视图未打开时不处理快捷键
if (!ApplicationDomainEx.MainWindow.IsActive)
return;
// 插件视图
FrameworkElement pluginView = this.GetPluginView();
HotkeyMessage msg = new HotkeyMessage();
msg.Key = key;
msg.View = pluginView;
ApplicationDomainEx.MessageManager.Send(msg);
if (!ApplicationDomainEx.IS_DEBUG)
return;
Debug.WriteLine($"Hotkey: {key} , View: {pluginView?.ToString()}");
});
}
/// <summary>
/// 获取插件视图
/// </summary>
/// <returns>插件视图</returns>
private FrameworkElement GetPluginView()
{
MainView view = this.MainViewModel.GetView<MainView>();
if (view == null)
return null;
FrameworkElement element = view.dockLayoutManager.ActiveDockItem as FrameworkElement;
if (element == null)
return null;
PluginInfo info = element.DataContext as PluginInfo;
if (info == null)
return null;
FrameworkElement pluginView = null;
info.View?.TryGetTarget(out pluginView);
return pluginView;
}
}
}
using DevExpress.Xpf.Bars;
using DevExpress.Xpf.Core;
using log4net;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
......@@ -20,6 +21,11 @@ namespace VIZ.Package.Module
/// </summary>
public class MainTopViewModel : ViewModelBase
{
/// <summary>
/// 日志
/// </summary>
private readonly static ILog log = LogManager.GetLogger(typeof(MainTopViewModel));
public MainTopViewModel()
{
// 初始化命令
......@@ -52,6 +58,7 @@ namespace VIZ.Package.Module
/// </summary>
private void InitMessage()
{
ApplicationDomainEx.MessageManager.Register<HotkeyMessage>(this, this.OnHotkeyMessage);
ApplicationDomainEx.MessageManager.Register<VizPreviewReadyMessage>(this, this.OnVizPreviewReadyMessage);
ApplicationDomainEx.MessageManager.Register<VizPreviewRestartMessage>(this, this.OnVizPreviewRestartMessage);
ApplicationDomainEx.MessageManager.Register<ApplicationClosingMessage>(this, this.OnApplicationClosingMessage);
......@@ -482,6 +489,26 @@ namespace VIZ.Package.Module
}
}
/// <summary>
/// 热键消息
/// </summary>
/// <param name="msg">消息</param>
private void OnHotkeyMessage(HotkeyMessage msg)
{
try
{
if (string.Equals(msg.Key, ApplicationDomainEx.HotKeyConfig.SaveOpendPageOrTemplateAndProject))
{
this.SaveProject();
return;
}
}
catch (Exception ex)
{
log.Error(ex);
}
}
// =====================================================================
// Public Function
// =====================================================================
......
using System;
using Gma.System.MouseKeyHook;
using log4net;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Common;
using VIZ.Framework.Core;
using VIZ.Package.Domain;
using VIZ.Package.Plugin;
......@@ -16,6 +19,11 @@ namespace VIZ.Package.Module
/// </summary>
public class MainViewModel : ViewModelBase, IMainViewService
{
/// <summary>
/// 日志
/// </summary>
private readonly static ILog log = LogManager.GetLogger(typeof(MainViewModel));
public MainViewModel()
{
// 初始化命令
......@@ -24,6 +32,9 @@ namespace VIZ.Package.Module
// 初始化消息
this.InitMessage();
// 初始化控制器
this.InitController();
// 初始化热键
this.InitHotkey();
......@@ -48,17 +59,43 @@ namespace VIZ.Package.Module
}
/// <summary>
/// 初始化控制器
/// </summary>
private void InitController()
{
this.HotkeyController = new HotkeyController(this);
}
/// <summary>
/// 初始化热键
/// </summary>
private void InitHotkey()
{
// 注册键盘钩子
this.KeyboardMouseEvents = Hook.GlobalEvents();
this.KeyboardMouseEvents.KeyDown -= KeyboardMouseEvents_KeyDown;
this.KeyboardMouseEvents.KeyDown += KeyboardMouseEvents_KeyDown;
}
// ============================================================
// Field
// ============================================================
/// <summary>
/// 鼠标键盘钩子
/// </summary>
private IKeyboardMouseEvents KeyboardMouseEvents;
// ============================================================
// Service & Controller
// ============================================================
/// <summary>
/// 热键控制器
/// </summary>
private HotkeyController HotkeyController;
// ============================================================
// Property
// ============================================================
......@@ -254,5 +291,22 @@ namespace VIZ.Package.Module
return path;
}
/// <summary>
/// 键盘钩子事件
/// </summary>
private void KeyboardMouseEvents_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
try
{
string key = HotkeyHelper.GetHotkey(e);
this.HotkeyController.BeginExecute(key);
}
catch (Exception ex)
{
log.Error(ex);
}
}
}
}
......@@ -109,6 +109,7 @@ namespace VIZ.Package.Module
/// </summary>
private void InitMessage()
{
ApplicationDomainEx.MessageManager.Register<HotkeyMessage>(this, this.OnHotkeyMessage);
ApplicationDomainEx.MessageManager.Register<ProjectOpenMessage>(this, this.OnProjectOpenMessage);
ApplicationDomainEx.MessageManager.Register<ProjectCloseMessage>(this, this.OnProjectCloseMessage);
ApplicationDomainEx.MessageManager.Register<ProjectSaveMessage>(this, this.OnProjectSaveMessage);
......@@ -819,6 +820,38 @@ namespace VIZ.Package.Module
}
}
/// <summary>
/// 处理热键消息
/// </summary>
/// <param name="msg">消息</param>
private void OnHotkeyMessage(HotkeyMessage msg)
{
try
{
// 打开下一页
if (string.Equals(msg.Key, ApplicationDomainEx.HotKeyConfig.OpenNextPage))
{
this.OpenNextPageItem();
return;
}
// 只有当前激活视图为节目单视图时处理
PageGroupView view = this.GetView<PageGroupView>();
if (view == null || msg.View != view)
return;
// 删除页
if (string.Equals(msg.Key, ApplicationDomainEx.HotKeyConfig.DeletePageOrTemplate))
{
this.DeleteItem();
}
}
catch (Exception ex)
{
log.Error(ex);
}
}
// ======================================================================================
// Public Function
// ======================================================================================
......@@ -929,6 +962,33 @@ namespace VIZ.Package.Module
this.ConnGroups = ApplicationDomainEx.ConnGroups;
}
/// <summary>
/// 打开下一页
/// </summary>
public void OpenNextPageItem()
{
if (this.SelectedPageGroupModel == null)
return;
PageModel page = ApplicationDomainEx.CurrentPage as PageModel;
if (page == null)
return;
if (this.SelectedPageGroupModel.Pages == null || this.SelectedPageGroupModel.Pages.Count == 0)
return;
int index = this.SelectedPageGroupModel.Pages.IndexOf(page);
if (index < 0)
return;
++index;
if (index < this.SelectedPageGroupModel.Pages.Count)
{
this.SelectedPageGroupModel.SelectedPage = this.SelectedPageGroupModel.Pages[index];
this.OpenPage();
}
}
// ======================================================================================
// Private Function
// ======================================================================================
......
......@@ -8,7 +8,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Media.Animation;
using VIZ.Framework.Core;
using VIZ.Package.Domain;
using VIZ.Package.Service;
......@@ -54,6 +56,7 @@ namespace VIZ.Package.Module
/// </summary>
private void InitMessage()
{
ApplicationDomainEx.MessageManager.Register<HotkeyMessage>(this, this.OnHotkeyMessage);
ApplicationDomainEx.MessageManager.Register<ProjectOpenMessage>(this, this.OnProjectOpenMessage);
ApplicationDomainEx.MessageManager.Register<ProjectCloseMessage>(this, this.OnProjectCloseMessage);
ApplicationDomainEx.MessageManager.Register<ProjectSaveMessage>(this, this.OnProjectSaveMessage);
......@@ -290,7 +293,8 @@ namespace VIZ.Package.Module
if (this.SelectedSceneTemplateModels == null || this.SelectedSceneTemplateModels.Count == 0)
return;
if (DXMessageBox.Show($"是否删除模板?", "提示", System.Windows.MessageBoxButton.YesNo) != System.Windows.MessageBoxResult.Yes)
string scenes = string.Join(" ,", this.SelectedSceneTemplateModels.Select(p => p.Scene));
if (DXMessageBox.Show($"是否删除模板 [{scenes}] ?", "提示", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
return;
List<PageTemplateModel> templates = this.SelectedSceneTemplateModels.ToList();
......@@ -354,6 +358,32 @@ namespace VIZ.Package.Module
this.pageService.SavePageTemplates(this.SceneTemplateModels);
}
/// <summary>
/// 处理热键消息
/// </summary>
/// <param name="msg">消息</param>
private void OnHotkeyMessage(HotkeyMessage msg)
{
try
{
// 只有当前激活视图是模板页时处理
PageTemplateView view = this.GetView<PageTemplateView>();
if (msg.View == null || msg.View != view)
return;
// 删除
if (string.Equals(msg.Key, ApplicationDomainEx.HotKeyConfig.DeletePageOrTemplate))
{
this.Delete();
return;
}
}
catch (Exception ex)
{
log.Error(ex);
}
}
// ======================================================================================
// Public Function
// ======================================================================================
......
......@@ -154,7 +154,7 @@ namespace VIZ.Package.Module
/// <summary>
/// 发送Viz引擎准备完毕消息
/// </summary>
public void BeginSendVizEngineReadlyMessage()
private void BeginSendVizEngineReadlyMessage()
{
WPFHelper.BeginInvoke(() =>
{
......
......@@ -129,6 +129,7 @@
<Compile Include="ControlObject\FieldEdit\ViewModel\FieldEditViewModelBase.cs" />
<Compile Include="ControlObject\FieldTree\Service\IFieldTreeService.cs" />
<Compile Include="Log\ViewModel\VizCommandWindowModel.cs" />
<Compile Include="Main\Controller\HotkeyController.cs" />
<Compile Include="Page\Core\View\PageLoadingWindow.xaml.cs">
<DependentUpon>PageLoadingWindow.xaml</DependentUpon>
</Compile>
......@@ -407,7 +408,6 @@
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Main\Controller\" />
<Folder Include="ProjectManager\Model\" />
</ItemGroup>
<ItemGroup>
......
......@@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using VIZ.Package.Domain;
namespace VIZ.Package.Plugin
{
......@@ -63,6 +64,12 @@ namespace VIZ.Package.Plugin
FrameworkElement view = this.ViewType.Assembly.CreateInstance(this.ViewType.FullName) as FrameworkElement;
this.Content = view;
PluginInfo info = this.DataContext as PluginInfo;
if (info != null)
{
info.View = new WeakReference<FrameworkElement>(view);
}
}
catch (Exception ex)
{
......
......@@ -111,10 +111,18 @@
<Project>{75b39591-4bc3-4b09-bd7d-ec9f67efa96e}</Project>
<Name>VIZ.Framework.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Domain\VIZ.Framework.Domain.csproj">
<Project>{28661e82-c86a-4611-a028-c34f6ac85c97}</Project>
<Name>VIZ.Framework.Domain</Name>
</ProjectReference>
<ProjectReference Include="..\..\VIZ.Framework\VIZ.Framework.Storage\VIZ.Framework.Storage.csproj">
<Project>{06b80c09-343d-4bb2-aeb1-61cfbfbf5cad}</Project>
<Name>VIZ.Framework.Storage</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.Package.Domain\VIZ.Package.Domain.csproj">
<Project>{dbaeae47-1f2d-4b05-82c3-abf7cc33aa2d}</Project>
<Name>VIZ.Package.Domain</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.Package.Storage\VIZ.Package.Storage.csproj">
<Project>{5bf08a07-9405-4f5d-a7f7-9d9ee17d6dd0}</Project>
<Name>VIZ.Package.Storage</Name>
......
......@@ -14,7 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "10-Core", "10-Core", "{38A2
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "20-Storage", "20-Storage", "{DA43E9E0-AFD0-4764-8228-44A01DF922A3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "25-Plugin", "25-Plugin", "{9AA1CFFD-41A1-448C-9144-1115A6B19AFA}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "45-Plugin", "45-Plugin", "{9AA1CFFD-41A1-448C-9144-1115A6B19AFA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "30-Domain", "30-Domain", "{7E1F0C7E-1A9C-4E9E-AB5F-C38BBB1B3E4A}"
EndProject
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment