FlowEditorShellView.xaml.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Input;
  4. using TeamAAS.FlowEngine.Execution;
  5. namespace TeamAAS.FlowEditor
  6. {
  7. /// <summary>
  8. /// 流程编辑器外壳视图:多 Tab 管理
  9. /// </summary>
  10. public partial class FlowEditorShellView : UserControl
  11. {
  12. private FlowEditorShellViewModel _vm;
  13. public FlowEditorShellView()
  14. {
  15. InitializeComponent();
  16. Loaded += OnLoaded;
  17. }
  18. private void OnLoaded(object sender, RoutedEventArgs e)
  19. {
  20. _vm = DataContext as FlowEditorShellViewModel;
  21. if (_vm == null)
  22. {
  23. _vm = new FlowEditorShellViewModel();
  24. DataContext = _vm;
  25. }
  26. }
  27. #region Tab管理
  28. private void TabItem_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  29. {
  30. if (sender is FrameworkElement fe && fe.DataContext is FlowTabItem tab)
  31. {
  32. if (e.ClickCount == 2)
  33. {
  34. if (_vm?.IsReadOnly == true) { e.Handled = true; return; } // 只读监控禁重命名
  35. _vm?.RenameFlowCommand.Execute(tab);
  36. e.Handled = true;
  37. }
  38. else if (_vm != null && _vm.ActiveTab != tab)
  39. {
  40. _vm.ActiveTab = tab;
  41. }
  42. }
  43. }
  44. private void TabClose_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  45. {
  46. e.Handled = true;
  47. if (_vm?.IsReadOnly == true) return; // 只读监控禁关闭流程
  48. if (sender is FrameworkElement fe && fe.DataContext is FlowTabItem tab)
  49. {
  50. _vm?.CloseFlowCommand.Execute(tab);
  51. }
  52. }
  53. private void TabItem_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  54. {
  55. if (sender is FrameworkElement fe && fe.DataContext is FlowTabItem tab)
  56. {
  57. if (_vm != null && _vm.ActiveTab != tab)
  58. _vm.ActiveTab = tab;
  59. var readOnly = _vm?.IsReadOnly == true;
  60. var menu = new ContextMenu();
  61. var itemProps = new MenuItem { Header = "属性设置", IsEnabled = !readOnly };
  62. itemProps.Click += (s, args) => _vm?.OpenTabPropertiesCommand.Execute(tab);
  63. var itemRename = new MenuItem { Header = "重命名", IsEnabled = !readOnly };
  64. itemRename.Click += (s, args) => _vm?.RenameFlowCommand.Execute(tab);
  65. var itemImport = new MenuItem { Header = "导入流程...", IsEnabled = !readOnly };
  66. itemImport.Click += (s, args) => _vm?.ImportFlowCommand.Execute();
  67. var itemExport = new MenuItem { Header = "导出流程..." };
  68. itemExport.Click += (s, args) => _vm?.ExportFlowCommand.Execute();
  69. menu.Items.Add(itemProps);
  70. menu.Items.Add(new Separator());
  71. menu.Items.Add(itemRename);
  72. menu.Items.Add(new Separator());
  73. menu.Items.Add(itemImport);
  74. menu.Items.Add(itemExport);
  75. menu.IsOpen = true;
  76. e.Handled = true;
  77. }
  78. }
  79. #endregion
  80. }
  81. }