| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using TeamAAS.FlowEngine.Execution;
- namespace TeamAAS.FlowEditor
- {
- /// <summary>
- /// 流程编辑器外壳视图:多 Tab 管理
- /// </summary>
- 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
- }
- }
|