diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs index c47beaf..471b77a 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs +++ b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs @@ -399,8 +399,8 @@ namespace AIStudio.Wpf.DiagramDesigner protected override void OnMouseMove(MouseEventArgs e) { - //var focusedElement = Keyboard.FocusedElement; - //Debug.WriteLine("focusedElement:" + focusedElement?.ToString()); + var focusedElement = Keyboard.FocusedElement; + Debug.WriteLine("focusedElement:" + focusedElement?.ToString()); base.OnMouseMove(e); diff --git a/AIStudio.Wpf.DiagramDesigner/Helpers/TextBoxEnterKeyUpdateBehavior.cs b/AIStudio.Wpf.DiagramDesigner/Helpers/TextBoxEnterKeyUpdateBehavior.cs new file mode 100644 index 0000000..c28d584 --- /dev/null +++ b/AIStudio.Wpf.DiagramDesigner/Helpers/TextBoxEnterKeyUpdateBehavior.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xaml.Behaviors; +using System.Windows.Input; +using System.Windows.Controls; + +namespace AIStudio.Wpf.DiagramDesigner +{ + public class TextBoxEnterKeyUpdateBehavior : Behavior + { + protected override void OnAttached() + { + if (this.AssociatedObject != null) + { + base.OnAttached(); + this.AssociatedObject.KeyDown += AssociatedObject_KeyDown; + } + } + + protected override void OnDetaching() + { + if (this.AssociatedObject != null) + { + this.AssociatedObject.KeyDown -= AssociatedObject_KeyDown; + base.OnDetaching(); + } + } + + private void AssociatedObject_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) + { + TextBox textBox = sender as TextBox; + if (textBox != null) + { + if (e.Key == Key.Return) + { + if (e.Key == Key.Enter) + { + textBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); + } + } + } + } + } +} diff --git a/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml b/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml index cb561ab..f9eebc0 100644 --- a/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml +++ b/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml @@ -30,7 +30,7 @@ HorizontalContentAlignment="{Binding FontViewModel.HorizontalAlignment}" VerticalContentAlignment="{Binding FontViewModel.VerticalAlignment}" TextBlock.LineHeight="{Binding FontViewModel.LineHeight}" - AcceptsReturn="True" + AcceptsReturn="{Binding AcceptsReturn,RelativeSource={RelativeSource AncestorType=dd:TextControl}}" IsHitTestVisible="False" dd:ControlAttachProperty.Watermark="{Binding Path=(dd:ControlAttachProperty.Watermark),RelativeSource={RelativeSource AncestorType={x:Type dd:TextControl}}}" Style="{StaticResource WaterTextBoxWithEffect}" IsReadOnly="True"> @@ -49,7 +49,7 @@ HorizontalContentAlignment="{Binding FontViewModel.HorizontalAlignment}" VerticalContentAlignment="{Binding FontViewModel.VerticalAlignment}" TextBlock.LineHeight="{Binding FontViewModel.LineHeight}" - AcceptsReturn="True" + AcceptsReturn="{Binding AcceptsReturn,RelativeSource={RelativeSource AncestorType=dd:TextControl}}" Focusable="False" dd:ControlAttachProperty.Watermark="{Binding Path=(dd:ControlAttachProperty.Watermark),RelativeSource={RelativeSource AncestorType={x:Type dd:TextControl}}}" Style="{StaticResource WaterTextBoxWithEffect}" Visibility="Collapsed"> diff --git a/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml.cs b/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml.cs index b92eec2..f3fb815 100644 --- a/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml.cs +++ b/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml.cs @@ -18,6 +18,16 @@ namespace AIStudio.Wpf.DiagramDesigner /// public partial class TextControl : UserControl { + public static readonly DependencyProperty AcceptsReturnProperty = DependencyProperty.Register( + nameof(AcceptsReturn), typeof(bool), typeof(TextControl), new FrameworkPropertyMetadata( + true)); + + public bool AcceptsReturn + { + get => (bool)GetValue(AcceptsReturnProperty); + set => SetValue(AcceptsReturnProperty, value); + } + public TextControl() { InitializeComponent(); @@ -78,9 +88,11 @@ namespace AIStudio.Wpf.DiagramDesigner BindingExpression binding = PART_ShowText.GetBindingExpression(TextBox.TextProperty); binding.UpdateSource(); + PART_ShowText.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); PART_ShowText.Visibility = Visibility.Collapsed; - PART_TextBlock.Visibility = Visibility.Visible; - + PART_TextBlock.Visibility = Visibility.Visible; + + selectable.IsEditing = false; } } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramOption.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramOption.cs index c49f092..3430308 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramOption.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramOption.cs @@ -150,5 +150,11 @@ namespace AIStudio.Wpf.DiagramDesigner { get; set; } = e => e.KeyboardDevice.Modifiers == ModifierKeys.Alt | e.Key == Key.A; + + [Description("Next Node (CEnter by default)")] + public Func Next + { + get; set; + } = e => e.KeyboardDevice.Modifiers == ModifierKeys.None && e.Key == Key.Enter; } } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs index fb0aa90..d045eff 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs @@ -14,6 +14,7 @@ using AIStudio.Wpf.DiagramDesigner.Helpers; using AIStudio.Wpf.DiagramDesigner.Models; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using static System.Net.Mime.MediaTypeNames; namespace AIStudio.Wpf.DiagramDesigner { @@ -735,6 +736,15 @@ namespace AIStudio.Wpf.DiagramDesigner } } + private ICommand _nextCommand; + public ICommand NextCommand + { + get + { + return this._nextCommand ?? (this._nextCommand = new SimpleCommand(ExecuteEnable, ExecuteNextCommand)); + } + } + private ICommand _alignTopCommand; public ICommand AlignTopCommand { @@ -1511,6 +1521,11 @@ namespace AIStudio.Wpf.DiagramDesigner } } + public virtual void ExecuteNextCommand(object parameter) + { + + } + private void ExecuteSelectAllCommand(object parameter) { List selectedItems = Items.ToList(); @@ -3146,7 +3161,11 @@ namespace AIStudio.Wpf.DiagramDesigner ReplaceAllCommand.Execute(new object[] { SearchText, ReplaceText }); return true; } - + else if (DiagramOption.ShortcutOption.Next(e)) + { + NextCommand.Execute(null); + return true; + } return false; } #endregion diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs index 9b836a0..b7f27f3 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs @@ -44,10 +44,7 @@ namespace AIStudio.Wpf.DiagramDesigner protected override void Init(IDiagramViewModel root, bool initNew) { - base.Init(root, initNew); - - SelectItemCommand = new SimpleCommand(Command_Enable, ExecuteSelectItemCommand); - EditCommand = new SimpleCommand(Command_Enable, ExecuteEditCommand); + base.Init(root, initNew); } protected override void InitNew() @@ -69,13 +66,31 @@ namespace AIStudio.Wpf.DiagramDesigner return true; } + private ICommand _selectItemCommand; public ICommand SelectItemCommand { - get; private set; + get + { + return this._editCommand ?? (this._editCommand = new SimpleCommand(Command_Enable, ExecuteSelectItemCommand)); + } } + + private ICommand _editCommand; public ICommand EditCommand { - get; private set; + get + { + return this._editCommand ?? (this._editCommand = new SimpleCommand(Command_Enable, ExecuteEditCommand)); + } + } + + private ICommand _exitEditCommand; + public ICommand ExitEditCommand + { + get + { + return this._exitEditCommand ?? (this._exitEditCommand = new SimpleCommand(Command_Enable, ExecuteExitEditCommand)); + } } private bool enabledForSelection = true; @@ -162,6 +177,11 @@ namespace AIStudio.Wpf.DiagramDesigner if (IsReadOnly == true) return; ShowText = true; - } + } + + protected virtual void ExecuteExitEditCommand(object param) + { + IsSelected = false; + } } } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs index e5e3e79..e7e3cd7 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs @@ -47,6 +47,10 @@ namespace AIStudio.Wpf.DiagramDesigner { get; } + ICommand NextCommand + { + get; + } ICommand AlignTopCommand { get; @@ -204,7 +208,7 @@ namespace AIStudio.Wpf.DiagramDesigner { get; } - ICommand ShowSearchCommand + ICommand ShowSearchCommand { get; } @@ -368,7 +372,7 @@ namespace AIStudio.Wpf.DiagramDesigner DoCommandManager DoCommandManager { - get; + get; } #region 设置选项 DiagramOption DiagramOption diff --git a/Extensions/AIStudio.Wpf.Mind/Themes/MindNode.xaml b/Extensions/AIStudio.Wpf.Mind/Themes/MindNode.xaml index 0f651e4..b0f8eaf 100644 --- a/Extensions/AIStudio.Wpf.Mind/Themes/MindNode.xaml +++ b/Extensions/AIStudio.Wpf.Mind/Themes/MindNode.xaml @@ -88,7 +88,11 @@ - + + + + + p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout()); @@ -614,6 +620,11 @@ namespace AIStudio.Wpf.Mind.ViewModels }); } + public override void ExecuteNextCommand(object parameter) + { + ExecuteAddPearCommand(parameter); + } + private void ExecuteMoveBackCommand(object parameter) { List items = new List(); @@ -1083,7 +1094,7 @@ namespace AIStudio.Wpf.Mind.ViewModels { roots = MindSelectedItems.Select(p => p.RootNode).Distinct().ToList(); } - + if (roots.Count > 0) { DoCommandManager.DoNewCommand(this.ToString(), diff --git a/Extensions/AIStudio.Wpf.Mind/ViewModels/MindNode.cs b/Extensions/AIStudio.Wpf.Mind/ViewModels/MindNode.cs index 6d1cfa5..96ee8ef 100644 --- a/Extensions/AIStudio.Wpf.Mind/ViewModels/MindNode.cs +++ b/Extensions/AIStudio.Wpf.Mind/ViewModels/MindNode.cs @@ -746,7 +746,10 @@ namespace AIStudio.Wpf.Mind.ViewModels IsSelected = selected; } - + protected override void ExecuteExitEditCommand(object param) + { + Root.NextCommand.Execute(this); + } #endregion }