You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
6.1 KiB
170 lines
6.1 KiB
using System.Windows; |
|
using System.Windows.Input; |
|
using GlobalHotKey; |
|
using HandyControl.Controls; |
|
using SparkClient.Model.Helper; |
|
using SparkClient.ViewModel.Grading; |
|
using MessageBox = SparkClient.Views.Dialog.MessageBox; |
|
namespace SparkClient.ViewModel.BaseWindow; |
|
|
|
public class BaseControlVM : BaseViewModel |
|
{ |
|
string _windowTitle; |
|
|
|
private Visibility _showFunctionButton; |
|
private string _functionButtonIcon; |
|
|
|
private Object _viewContent; |
|
|
|
public string WindowTitle { get { return _windowTitle; } set { _windowTitle = value; OnPropertyChanged("WindowTitle"); } } |
|
public Visibility ShowFunctionButton { get { return _showFunctionButton; } set { _showFunctionButton = value; OnPropertyChanged("ShowFunctionButton"); } } |
|
public Visibility ShowCloseButton { get { return _showFunctionButton; } set { _showFunctionButton = value; OnPropertyChanged("ShowFunctionButton"); } } |
|
public string FunctionButtonIcon { get { return _functionButtonIcon; } set { _functionButtonIcon = value; OnPropertyChanged("FunctionButtonIcon"); } } |
|
public Object ViewControl { get { return _viewContent; } set { _viewContent = value; OnPropertyChanged("ViewControl"); } } |
|
|
|
public object Content { get; } |
|
public ICommand CloseCommand { get; } |
|
public ICommand EscCloseCommand { get; } |
|
|
|
public ICommand NextCommand { get; } |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
/// 构造:创建一个带有子页面的模板,并指定子窗口标题,并指定右侧按钮事件内容 |
|
/// </summary> |
|
/// <param name="vm">子页面</param> |
|
/// <param name="windowTitle">子窗口标题</param> |
|
/// <param name="Function">事件内哦那个</param> |
|
public BaseControlVM(BaseViewModel vm, string windowTitle, ICommand Function) |
|
{ |
|
Content = vm; |
|
WindowTitle = windowTitle; |
|
CloseCommand = new RelayCommand(CloseVM); |
|
EscCloseCommand = new RelayCommand(OnClose); |
|
NextCommand = new RelayCommand(NextDiamond); |
|
} |
|
|
|
/// <summary> |
|
/// 构造:创建一个带有子页面的模板,并指定子窗口标题 |
|
/// </summary> |
|
/// <param name="vm">子页面</param> |
|
/// <param name="windowTitle">子窗口标题</param> |
|
public BaseControlVM(BaseViewModel vm, string windowTitle) |
|
{ |
|
Content = vm; |
|
WindowTitle = windowTitle; |
|
ShowFunctionButton = Visibility.Hidden; |
|
ShowCloseButton = Visibility.Visible; |
|
CloseCommand = new RelayCommand(CloseVM); |
|
NextCommand = new RelayCommand(NextDiamond); |
|
|
|
if (vm.GetType().Equals(typeof(GradingResultVM))) |
|
{ |
|
Application.Current.Dispatcher.Invoke(() => |
|
{ |
|
try |
|
{ |
|
HotKeyManager _hotKeyManager = new HotKeyManager(); |
|
var hotKey = new HotKey(Key.Q, ModifierKeys.Control | ModifierKeys.Alt); |
|
_hotKeyManager.Register(hotKey); |
|
_hotKeyManager.KeyPressed += OnHotKeyPressed; |
|
|
|
HotKeyManager _hotKeyManagerClose = new HotKeyManager(); |
|
var hotKeyClose = new HotKey(Key.E, ModifierKeys.Control | ModifierKeys.Alt); |
|
_hotKeyManagerClose.Register(hotKeyClose); |
|
_hotKeyManagerClose.KeyPressed += OnHotKeyPressedClose; |
|
} |
|
catch (Exception ex) |
|
{ |
|
Logger.Info("设计缺陷:快捷键重复注册"); |
|
} |
|
}); |
|
} |
|
else if(vm.GetType().Equals(typeof(GradingLoadingVM))) |
|
{ |
|
ShowCloseButton = Visibility.Hidden; |
|
} |
|
|
|
} |
|
/// <summary> |
|
/// 构造:创建一个带有子页面的模板 |
|
/// </summary> |
|
/// <param name="vm"></param> |
|
public BaseControlVM(BaseViewModel vm) |
|
{ |
|
Content = vm; |
|
CloseCommand = new RelayCommand(CloseVM); |
|
} |
|
private void OnClose(object parameter) |
|
{ |
|
if (parameter is KeyEventArgs keyEventArgs && keyEventArgs.Key == Key.Escape) |
|
{ |
|
CloseVM(parameter); |
|
} |
|
} |
|
|
|
private void OnHotKeyPressed(object sender, KeyPressedEventArgs e) |
|
{ |
|
// if(Content.GetType().Equals(typeof(GradingResultVM))) |
|
// |
|
if (WindowManager.mainViewModel.Content is BaseControlVM baseVM) |
|
{ |
|
if(baseVM.Content.GetType().Equals(typeof(GradingResultVM))) |
|
NextDiamond(""); |
|
} |
|
} |
|
private void OnHotKeyPressedClose(object sender, KeyPressedEventArgs e) |
|
{ |
|
// if(WindowTitle.StartsWith(MultilingualHelper.getString("DetectionResult"))) |
|
if (WindowManager.mainViewModel.Content is BaseControlVM baseVM) |
|
{ |
|
if(baseVM.Content.GetType().Equals(typeof(GradingResultVM))) |
|
CloseVM(""); |
|
} |
|
|
|
|
|
} |
|
|
|
public void NextDiamond(object parameter) |
|
{ |
|
CloseVM(parameter); |
|
DiamondSelectVM selectVm = new DiamondSelectVM(); |
|
ViewControl = selectVm; |
|
WindowTitle = MultilingualHelper.getString("DiamondSelect"); |
|
selectVm.StartGrading("ROUND P8 P8"); |
|
|
|
} |
|
|
|
/// <summary> |
|
/// 关闭并退回至上一个页面 |
|
/// </summary> |
|
/// <param name="parameter"></param> |
|
public void CloseVM(object parameter) |
|
{ |
|
if(Content is GradingResultVM) |
|
{ |
|
bool isSaved = (Content as GradingResultVM).isSaved; |
|
if (isSaved) { |
|
WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); |
|
} |
|
else { |
|
// 部署改造:2 |
|
WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); |
|
// MessageBox message = new MessageBox(); |
|
// MessageBoxResult result = message.ShowAsk(MultilingualHelper.getString("DiamodResultCloseConfirm")); |
|
// if (MessageBoxResult.OK.Equals(result)) |
|
// { |
|
// WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); |
|
// } |
|
} |
|
} |
|
else |
|
{ |
|
WindowManager.mainViewModel.Content = WindowManager.PreviousVM(); |
|
} |
|
|
|
} |
|
|
|
} |