using System.Windows; using System.Windows.Controls; using System.Windows.Input; using TeamAAS.FlowEngine.Execution; namespace TeamAAS.FlowEditor { /// /// 流程编辑器外壳视图:多 Tab 管理 /// public partial class FlowEditorShellView : UserControl { private FlowEditorShellViewModel _vm; public FlowEditorShellView() { InitializeComponent(); Loaded += OnLoaded; } private void OnLoaded(object sender, RoutedEventArgs e) { _vm = DataContext as FlowEditorShellViewModel; if (_vm == null) { _vm = new FlowEditorShellViewModel(); DataContext = _vm; } } #region Tab管理 private void TabItem_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (sender is FrameworkElement fe && fe.DataContext is FlowTabItem tab) { if (e.ClickCount == 2) { if (_vm?.IsReadOnly == true) { e.Handled = true; return; } // 只读监控禁重命名 _vm?.RenameFlowCommand.Execute(tab); e.Handled = true; } else if (_vm != null && _vm.ActiveTab != tab) { _vm.ActiveTab = tab; } } } private void TabClose_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { e.Handled = true; if (_vm?.IsReadOnly == true) return; // 只读监控禁关闭流程 if (sender is FrameworkElement fe && fe.DataContext is FlowTabItem tab) { _vm?.CloseFlowCommand.Execute(tab); } } private void TabItem_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { if (sender is FrameworkElement fe && fe.DataContext is FlowTabItem tab) { if (_vm != null && _vm.ActiveTab != tab) _vm.ActiveTab = tab; var readOnly = _vm?.IsReadOnly == true; var menu = new ContextMenu(); var itemProps = new MenuItem { Header = "属性设置", IsEnabled = !readOnly }; itemProps.Click += (s, args) => _vm?.OpenTabPropertiesCommand.Execute(tab); var itemRename = new MenuItem { Header = "重命名", IsEnabled = !readOnly }; itemRename.Click += (s, args) => _vm?.RenameFlowCommand.Execute(tab); var itemImport = new MenuItem { Header = "导入流程...", IsEnabled = !readOnly }; itemImport.Click += (s, args) => _vm?.ImportFlowCommand.Execute(); var itemExport = new MenuItem { Header = "导出流程..." }; itemExport.Click += (s, args) => _vm?.ExportFlowCommand.Execute(); menu.Items.Add(itemProps); menu.Items.Add(new Separator()); menu.Items.Add(itemRename); menu.Items.Add(new Separator()); menu.Items.Add(itemImport); menu.Items.Add(itemExport); menu.IsOpen = true; e.Handled = true; } } #endregion } }