From 78da8f4852b56c32e4ee5454861d0dc380235b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Sat, 8 Apr 2023 14:22:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E8=BF=91=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E6=9C=89=E4=BA=9Bbug=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml | 7 +- .../Views/MainWindow.xaml.cs | 24 ++-- .../Adorners/RubberbandAdorner.cs | 90 +++++++------ .../Controls/DesignerCanvas.cs | 127 +++++------------- .../UserControls/DiagramControl.xaml | 9 +- .../UserControls/GridControl.cs | 28 ++++ .../UserControls/TextControl.xaml.cs | 22 +-- .../DesignerItemViewModelBase.cs | 13 -- .../BaseViewModel/DiagramViewModel.cs | 2 +- .../SelectableDesignerItemViewModelBase.cs | 37 +++-- .../BaseViewModel/SelectableViewModelBase.cs | 17 ++- .../TextDesignerItemViewModel.cs | 8 +- .../ViewModels/IDiagramViewModel.cs | 2 + .../ViewModels/ISelectable.cs | 5 + AIStudio.Wpf.Mind/Helpers/DirectoryLayout.cs | 1 + 15 files changed, 193 insertions(+), 199 deletions(-) create mode 100644 AIStudio.Wpf.DiagramDesigner/UserControls/GridControl.cs diff --git a/AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml b/AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml index 3136027..493a9a7 100644 --- a/AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml +++ b/AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml @@ -2383,9 +2383,10 @@ + Background="{DynamicResource GrayBrush8}" + HorizontalScrollBarVisibility="Auto" + VerticalScrollBarVisibility="Auto" + Focusable="False"> e) @@ -55,20 +55,20 @@ namespace AIStudio.Wpf.DiagramApp TextOptions.SetTextFormattingMode(this, textFormattingMode); } - private void OnPreviewMouseWheel(object sender, MouseWheelEventArgs e) - { - if (Keyboard.IsKeyDown(Key.LeftCtrl) == false - && Keyboard.IsKeyDown(Key.RightCtrl) == false) - { - return; - } + //private void OnPreviewMouseWheel(object sender, MouseWheelEventArgs e) + //{ + // if (Keyboard.IsKeyDown(Key.LeftCtrl) == false + // && Keyboard.IsKeyDown(Key.RightCtrl) == false) + // { + // return; + // } - var newZoomValue = this.zoomSlider.Value + (e.Delta > 0 ? 0.1 : -0.1); + // var newZoomValue = this.zoomSlider.Value + (e.Delta > 0 ? 0.1 : -0.1); - this.zoomSlider.Value = Math.Max(Math.Min(newZoomValue, this.zoomSlider.Maximum), this.zoomSlider.Minimum); + // this.zoomSlider.Value = Math.Max(Math.Min(newZoomValue, this.zoomSlider.Maximum), this.zoomSlider.Minimum); - e.Handled = true; - } + // e.Handled = true; + //} private void btnPrint_Click(object sender, RoutedEventArgs e) { diff --git a/AIStudio.Wpf.DiagramDesigner/Adorners/RubberbandAdorner.cs b/AIStudio.Wpf.DiagramDesigner/Adorners/RubberbandAdorner.cs index 9e9e895..e6ff227 100644 --- a/AIStudio.Wpf.DiagramDesigner/Adorners/RubberbandAdorner.cs +++ b/AIStudio.Wpf.DiagramDesigner/Adorners/RubberbandAdorner.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using AIStudio.Wpf.DiagramDesigner.ViewModels; using AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel; +using System.Windows.Threading; namespace AIStudio.Wpf.DiagramDesigner { @@ -15,19 +16,31 @@ namespace AIStudio.Wpf.DiagramDesigner { private Point? startPoint; private Point? endPoint; - private List pointList = new List(); - private List pointDesignerItemViewModelList = new List(); + private List pointList = new List(); private Pen rubberbandPen; private DesignerCanvas _designerCanvas; - private IDiagramViewModel _viewModel { get { return _designerCanvas.DataContext as IDiagramViewModel; } } - private IDiagramServiceProvider _service { get { return DiagramServicesProvider.Instance.Provider; } } + private IDiagramViewModel _viewModel + { + get + { + return _designerCanvas.DataContext as IDiagramViewModel; + } + } + private IDiagramServiceProvider _service + { + get + { + return DiagramServicesProvider.Instance.Provider; + } + } public RubberbandAdorner(DesignerCanvas designerCanvas, Point? dragStartPoint) : base(designerCanvas) { this._designerCanvas = designerCanvas; + this._designerCanvas.Focus(); this.startPoint = dragStartPoint; rubberbandPen = new Pen(Brushes.LightSlateGray, 1); rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1); @@ -55,14 +68,18 @@ namespace AIStudio.Wpf.DiagramDesigner } else if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine) { + if (!this.IsMouseCaptured) + this.CaptureMouse(); + + endPoint = e.GetPosition(this); + if (pointList.Count == 0 && this.startPoint.HasValue) { pointList.Add(this.startPoint.Value); - var item = new PointDesignerItemViewModel(startPoint.Value); - item.ShowConnectors = true; - _viewModel.Add(item); - pointDesignerItemViewModelList.Add(item); } + + UpdateSelection(); + this.InvalidateVisual(); } else { @@ -74,38 +91,23 @@ namespace AIStudio.Wpf.DiagramDesigner protected override void OnMouseUp(System.Windows.Input.MouseButtonEventArgs e) { - if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine && e.ChangedButton == MouseButton.Left ) + if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine && e.ChangedButton == MouseButton.Left) { - endPoint = e.GetPosition(this); - - bool isend = false; - var connector = ControlExtession.TryFindFromPoint(this._designerCanvas, endPoint.Value); - if (connector != null) - { - if (object.Equals(connector.DataContext, pointDesignerItemViewModelList[0].TopConnector)) - { - isend = true; - } - } - - if (isend == false) + //按着ctrl自动封闭曲线 + if (Keyboard.IsKeyDown(Key.LeftCtrl) == true || Keyboard.IsKeyDown(Key.RightCtrl) == true) + { + pointList.Add(this.startPoint.Value); + } + else { + endPoint = e.GetPosition(this); pointList.Add(endPoint.Value); - var item = new PointDesignerItemViewModel(endPoint.Value); - item.ShowConnectors = true; - _viewModel.Add(item); - pointDesignerItemViewModelList.Add(item); UpdateSelection(); this.InvalidateVisual(); return; } - else - { - this._service.DrawModeViewModel.SetDrawMode(DrawMode.Polygon); - } - } // release mouse capture @@ -136,25 +138,27 @@ namespace AIStudio.Wpf.DiagramDesigner itemBase.ItemHeight = Math.Abs(this.endPoint.Value.Y - this.startPoint.Value.Y); _viewModel.AddItemCommand.Execute(itemBase); + + this.Dispatcher.BeginInvoke((System.Action)(() => { + itemBase.ShowText = true; + })); } - else if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Polyline + else if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Polyline || this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Polygon || this._service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine) { ShapeDesignerItemViewModel itemBase = new ShapeDesignerItemViewModel(this._service.DrawModeViewModel.GetDrawMode(), pointList); - _viewModel.AddItemCommand.Execute(itemBase); + _viewModel.AddItemCommand.Execute(itemBase); } else { ShapeDesignerItemViewModel itemBase = new ShapeDesignerItemViewModel(this._service.DrawModeViewModel.GetDrawMode(), new List { this.startPoint.Value, this.endPoint.Value }); _viewModel.AddItemCommand.Execute(itemBase); } - } + } this._service.DrawModeViewModel.ResetDrawMode(); } - pointDesignerItemViewModelList.ForEach(p => _viewModel.Remove(p)); - e.Handled = true; } @@ -189,7 +193,17 @@ namespace AIStudio.Wpf.DiagramDesigner else if (_service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine) { var disList = pointList.ToList(); - for (int i = 1; i < pointList.Count; i++) + //按着ctrl自动封闭曲线 + if (Keyboard.IsKeyDown(Key.LeftCtrl) == true || Keyboard.IsKeyDown(Key.RightCtrl) == true) + { + disList.Add(this.startPoint.Value); + } + else + { + disList.Add(this.endPoint.Value); + } + + for (int i = 1; i < disList.Count; i++) { dc.DrawLine(rubberbandPen, disList[i - 1], disList[i]); } @@ -211,8 +225,6 @@ namespace AIStudio.Wpf.DiagramDesigner return GetParent(parentType, parent); } - - private void UpdateSelection() { IDiagramViewModel vm = (_designerCanvas.DataContext as IDiagramViewModel); diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs index a9abc1c..e81edad 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs +++ b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs @@ -16,11 +16,13 @@ using Newtonsoft.Json; using AIStudio.Wpf.DiagramDesigner.Models; using AIStudio.Wpf.DiagramDesigner.ViewModels; using AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel; +using System.Diagnostics; namespace AIStudio.Wpf.DiagramDesigner { public class DesignerCanvas : Canvas { + #region 属性 private IDiagramViewModel _viewModel { get @@ -35,7 +37,6 @@ namespace AIStudio.Wpf.DiagramDesigner return DiagramServicesProvider.Instance.Provider; } } - private ConnectionViewModel partialConnection; private List connectorsHit = new List(); @@ -188,6 +189,9 @@ namespace AIStudio.Wpf.DiagramDesigner #endregion + #endregion + + #region 初始化 public DesignerCanvas() { this.Focusable = true; @@ -200,7 +204,6 @@ namespace AIStudio.Wpf.DiagramDesigner private void DesignerCanvas_Loaded(object sender, RoutedEventArgs e) { this.Focus(); - } protected override void OnRender(DrawingContext dc) @@ -222,7 +225,9 @@ namespace AIStudio.Wpf.DiagramDesigner dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(i, GridMarginSize.Height), new Point(i, rect.Height - GridMarginSize.Height)); dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(rect.Width - GridMarginSize.Width, GridMarginSize.Height), new Point(rect.Width - GridMarginSize.Width, rect.Height - GridMarginSize.Height)); } + #endregion + #region Format/Move private void _service_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (sender is IDrawModeViewModel) @@ -241,7 +246,6 @@ namespace AIStudio.Wpf.DiagramDesigner } } - #region Format/Move private void EnterFormat() { StreamResourceInfo sri = Application.GetResourceStream(new Uri("pack://application:,,,/AIStudio.Wpf.DiagramDesigner;component/Images/FormatPainter.cur", UriKind.RelativeOrAbsolute)); @@ -270,13 +274,14 @@ namespace AIStudio.Wpf.DiagramDesigner } _service.DrawModeViewModel.CursorMode = CursorMode.Normal; } - #endregion private void Format(SelectableDesignerItemViewModelBase source, SelectableDesignerItemViewModelBase target) { CopyHelper.CopyPropertyValue(source.ColorViewModel, target.ColorViewModel); CopyHelper.CopyPropertyValue(source.FontViewModel, target.FontViewModel); + CopyHelper.CopyPropertyValue(source.ShapeViewModel, target.ShapeViewModel); } + #endregion private Connector sourceConnector; public Connector SourceConnector @@ -294,7 +299,6 @@ namespace AIStudio.Wpf.DiagramDesigner FullyCreatedConnectorInfo sourceDataItem = sourceConnector.Info; - Rect rectangleBounds = sourceConnector.TransformToVisual(this).TransformBounds(new Rect(sourceConnector.RenderSize)); Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2), rectangleBounds.Bottom + (rectangleBounds.Height / 2)); @@ -305,38 +309,12 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private FullyCreatedConnectorInfo sourceConnectorInfo; - public FullyCreatedConnectorInfo SourceConnectorInfo - { - get - { - return sourceConnectorInfo; - } - set - { - if (sourceConnectorInfo != value) - { - sourceConnectorInfo = value; - sourceConnector = new Connector() { Name = "占位" };//占位使用 - connectorsHit.Add(sourceConnector); - - Rect rectangleBounds = new Rect(sourceConnectorInfo.DataItem.Left, sourceConnectorInfo.DataItem.Top, 3, 3); - Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2), - rectangleBounds.Bottom + (rectangleBounds.Height / 2)); - partialConnection = new ConnectionViewModel(_viewModel, sourceConnectorInfo, new PartCreatedConnectorInfo(point.X, point.Y), DrawMode, RouterMode); - _viewModel.Add(partialConnection); - } - } - } - protected override void OnMouseDown(MouseButtonEventArgs e) { - base.OnMouseDown(e); + base.OnMouseDown(e); if (_viewModel.IsReadOnly) return; - this.Focus(); - if (_service.DrawModeViewModel.CursorMode == CursorMode.Format) { var element = (e.OriginalSource as FrameworkElement); @@ -365,20 +343,10 @@ namespace AIStudio.Wpf.DiagramDesigner if (!(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))) { - _viewModel.ClearSelectedItemsCommand.Execute(null); + _viewModel.ClearSelectedItems(); } - //e.Handled = true; - - if (_service.DrawModeViewModel.GetDrawMode() == DrawMode.ConnectingLineSmooth) - { - if (connectorsHit.Count == 0) - { - LinkPointDesignerItemViewModel pointItemView = new LinkPointDesignerItemViewModel(rubberbandSelectionStartPoint.Value); - _viewModel.Add(pointItemView); - SourceConnectorInfo = pointItemView.Connectors.FirstOrDefault(); - } - } + e.Handled = true; } } @@ -386,12 +354,13 @@ namespace AIStudio.Wpf.DiagramDesigner protected override void OnMouseMove(MouseEventArgs e) { + var focusedElement = Keyboard.FocusedElement; + Debug.WriteLine("focusedElement:" + focusedElement?.ToString()); + base.OnMouseMove(e); if (_viewModel.IsReadOnly) return; - this.Focus(); - Point currentPoint = e.GetPosition(this); _viewModel.CurrentPoint = new Point(ScreenHelper.WidthToMm(currentPoint.X), ScreenHelper.WidthToMm(currentPoint.Y)); var point = CursorPointManager.GetCursorPosition(); @@ -418,10 +387,6 @@ namespace AIStudio.Wpf.DiagramDesigner var nearPort = FindNearPortToAttachTo(); if (nearPort != null || partialConnection.SinkConnectorInfoFully != null) { - //var oldPort = _ongoingLink.TargetPort; - //_ongoingLink.SetTargetPort(nearPort); - //oldPort?.Refresh(); - //nearPort?.Refresh(); partialConnection.SinkConnectorInfo = nearPort; } } @@ -447,10 +412,10 @@ namespace AIStudio.Wpf.DiagramDesigner adornerLayer.Add(adorner); } } - } + } } - - //e.Handled = true; + + e.Handled = true; } protected override void OnMouseUp(MouseButtonEventArgs e) @@ -459,18 +424,11 @@ namespace AIStudio.Wpf.DiagramDesigner if (_viewModel.IsReadOnly) return; - this.Focus(); - - if (_service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine) - { - return; - } - Mediator.Instance.NotifyColleagues("DoneDrawingMessage", true); if (sourceConnector != null) { - FullyCreatedConnectorInfo sourceDataItem = sourceConnectorInfo ?? (sourceConnector.Info); + FullyCreatedConnectorInfo sourceDataItem = sourceConnector.Info; if (connectorsHit.Count() == 2) { Connector sinkConnector = connectorsHit.Last(); @@ -481,25 +439,10 @@ namespace AIStudio.Wpf.DiagramDesigner sinkDataItem.DataItem.Root.Items[indexOfLastTempConnection]); sinkDataItem.DataItem.Root.AddItemCommand.Execute(new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, DrawMode, RouterMode)); } - else if (partialConnection.IsFullConnection) + else if (partialConnection.IsFullConnection)//自动连接模式 { partialConnection.RaiseFullConnection(); } - else if (_service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine && connectorsHit.Count() == 1) - { - LinkPointDesignerItemViewModel pointItemView = new LinkPointDesignerItemViewModel(e.GetPosition(this)); - FullyCreatedConnectorInfo sinkDataItem = pointItemView.TopConnector; - - int indexOfLastTempConnection = _viewModel.Items.Count - 1; - _viewModel.Remove(_viewModel.Items[indexOfLastTempConnection]); - _viewModel.Add(pointItemView); - - var connector = new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, DrawMode, RouterMode); - _viewModel.AddItemCommand.Execute(connector); - - sourceDataItem.DataItem.ZIndex++; - connector.ZIndex--; - } else { //Need to remove last item as we did not finish drawing the path @@ -513,9 +456,11 @@ namespace AIStudio.Wpf.DiagramDesigner connectorsHit = new List(); sourceConnector = null; - sourceConnectorInfo = null; - _service.DrawModeViewModel.ResetDrawMode(); + if (_service.DrawModeViewModel.GetDrawMode() != DrawMode.DirectLine) + { + _service.DrawModeViewModel.ResetDrawMode(); + } } protected override void OnPreviewKeyDown(KeyEventArgs e) @@ -577,34 +522,26 @@ namespace AIStudio.Wpf.DiagramDesigner while (hitObject != null && hitObject.GetType() != typeof(DesignerCanvas)) { - if (hitObject is Connector connector && connector.Info != null) + if (hitObject is Connector connector) { - if (SourceConnector == null || connector.Info.CanAttachTo(SourceConnector.Info)) - { - if (connectorsHit.Any(p => p.Name == "占位")) - { - connectorsHit.Remove(connectorsHit.FirstOrDefault(p => p.Name == "占位")); - } - if (!connectorsHit.Contains(hitObject as Connector)) - connectorsHit.Add(hitObject as Connector); - } + if (!connectorsHit.Contains(hitObject as Connector)) + connectorsHit.Add(hitObject as Connector); } hitObject = VisualTreeHelper.GetParent(hitObject); } - } protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); - if (_viewModel.IsReadOnly) return; + if (_viewModel.IsReadOnly) return; DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null) { _viewModel.ClearSelectedItemsCommand.Execute(null); - Point position = e.GetPosition(this); + Point position = e.GetPosition(this); if (dragObject.DesignerItem is SerializableObject serializableObject) { var designerItems = serializableObject.ToObject(); @@ -618,7 +555,7 @@ namespace AIStudio.Wpf.DiagramDesigner foreach (var item in designerItems.OfType()) { item.Left += position.X - itemswidth / 2; - item.Top += position.Y - itemsheight / 2; + item.Top += position.Y - itemsheight / 2; } _viewModel.AddItemCommand.Execute(designerItems); } @@ -668,7 +605,8 @@ namespace AIStudio.Wpf.DiagramDesigner this.Focus(); } - public FullyCreatedConnectorInfo FindNearPortToAttachTo() + #region 自动依附节点 + private FullyCreatedConnectorInfo FindNearPortToAttachTo() { foreach (var port in _viewModel.Items.OfType().ToList().SelectMany(n => n.Connectors)) { @@ -679,5 +617,6 @@ namespace AIStudio.Wpf.DiagramDesigner return null; } + #endregion } } \ No newline at end of file diff --git a/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml b/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml index a6125c6..56e937e 100644 --- a/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml +++ b/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml @@ -315,7 +315,7 @@ - + @@ -462,8 +462,8 @@ Value="{Binding Area.Left}" /> - + @@ -860,7 +860,8 @@ + VerticalScrollBarVisibility="Auto" + Focusable="False"> diff --git a/AIStudio.Wpf.DiagramDesigner/UserControls/GridControl.cs b/AIStudio.Wpf.DiagramDesigner/UserControls/GridControl.cs new file mode 100644 index 0000000..80776af --- /dev/null +++ b/AIStudio.Wpf.DiagramDesigner/UserControls/GridControl.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; +using System.Windows.Input; + +namespace AIStudio.Wpf.DiagramDesigner +{ + public class GridControl : Grid + { + public IDiagramViewModel DiagramViewModel + { + get + { + return (this.DataContext as SelectableDesignerItemViewModelBase)?.Root; + } + } + + //protected override void OnPreviewKeyDown(KeyEventArgs e) + //{ + // base.OnPreviewKeyDown(e); + + // e.Handled = DiagramViewModel?.ExecuteShortcut(e) ?? false; + //} + } +} diff --git a/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml.cs b/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml.cs index 4d41cb2..c9df145 100644 --- a/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml.cs +++ b/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml.cs @@ -59,9 +59,9 @@ namespace AIStudio.Wpf.DiagramDesigner private void TextControl_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { - if (e.PropertyName == "IsSelected") + if (sender is ISelectable selectable) { - if (sender is ISelectable selectable) + if (e.PropertyName == "IsSelected") { if (selectable.IsSelected == false) { @@ -70,16 +70,16 @@ namespace AIStudio.Wpf.DiagramDesigner selectable.IsEditing = false; } } - } - else if (e.PropertyName == "ShowText") - { - PART_ShowText.Visibility = Visibility.Visible; - PART_TextBlock.Visibility = Visibility.Collapsed; - PART_ShowText.Focus(); - if (!string.IsNullOrEmpty(PART_ShowText.Text)) + else if (e.PropertyName == "ShowText") { - PART_ShowText.SelectionStart = PART_ShowText.Text.Length; - } + PART_ShowText.Visibility = Visibility.Visible; + PART_TextBlock.Visibility = Visibility.Collapsed; + PART_ShowText.Focus(); + if (!string.IsNullOrEmpty(PART_ShowText.Text)) + { + PART_ShowText.SelectionStart = PART_ShowText.Text.Length; + } + } } } } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DesignerItemViewModelBase.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DesignerItemViewModelBase.cs index 87198f5..cecc9da 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DesignerItemViewModelBase.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DesignerItemViewModelBase.cs @@ -356,19 +356,6 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private bool enabledForSelection = true; - public bool EnabledForSelection - { - get - { - return enabledForSelection; - } - set - { - SetProperty(ref enabledForSelection, value); - } - } - private double _left; [CanDo] public double Left diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs index 4a263a0..c676784 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs @@ -1251,7 +1251,7 @@ namespace AIStudio.Wpf.DiagramDesigner DoCommandManager.DoNewCommand(this.ToString(), () => { ClearSelectedItems(); - Add(newitems); + Add(newitems, true); }, () => { foreach (var item in newitems) diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs index c0ab39a..e59dcbd 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableDesignerItemViewModelBase.cs @@ -78,6 +78,20 @@ namespace AIStudio.Wpf.DiagramDesigner get; private set; } + private bool enabledForSelection = true; + public bool EnabledForSelection + { + get + { + return enabledForSelection; + } + set + { + SetProperty(ref enabledForSelection, value); + } + } + + private bool _isReadOnlyText = false; public bool IsReadOnlyText { @@ -105,27 +119,12 @@ namespace AIStudio.Wpf.DiagramDesigner { SetProperty(ref _customText, value); } - } - - private bool _showText; - public bool ShowText - { - get - { - return _showText; - } - set - { - if (!SetProperty(ref _showText, value)) - { - RaisePropertyChanged(nameof(ShowText)); - } - } - } + } protected override void ClearText() { ShowText = false; + } private void ExecuteSelectItemCommand(object param) @@ -163,8 +162,6 @@ namespace AIStudio.Wpf.DiagramDesigner if (IsReadOnly == true) return; ShowText = true; - } - - + } } } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableViewModelBase.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableViewModelBase.cs index 7870875..63701c7 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableViewModelBase.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableViewModelBase.cs @@ -191,6 +191,22 @@ namespace AIStudio.Wpf.DiagramDesigner } } + private bool _showText; + public bool ShowText + { + get + { + return _showText; + } + set + { + if (!SetProperty(ref _showText, value)) + { + RaisePropertyChanged(nameof(ShowText)); + } + } + } + private bool _visible = true; public bool Visible { @@ -343,7 +359,6 @@ namespace AIStudio.Wpf.DiagramDesigner } } - protected virtual void ClearText() { diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/TextDesignerItemViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/TextDesignerItemViewModel.cs index f422361..cb466b2 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/TextDesignerItemViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/TextDesignerItemViewModel.cs @@ -39,13 +39,14 @@ namespace AIStudio.Wpf.DiagramDesigner { base.Init(root, initNew); - CustomText = true; + CustomText = true; } protected override void InitNew() { this.ItemWidth = 150; this.ClearConnectors(); + ShowText = true; } private string _watermark = "请输入文本"; @@ -60,5 +61,10 @@ namespace AIStudio.Wpf.DiagramDesigner SetProperty(ref _watermark, value); } } + + protected override void ClearText() + { + Root.RemoveItemCommand.Execute(this); + } } } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs index f1480cc..40b08ca 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs @@ -339,6 +339,8 @@ namespace AIStudio.Wpf.DiagramDesigner void Remove(object parameter); + void ClearSelectedItems(); + bool ExecuteShortcut(KeyEventArgs e); event PropertyChangedEventHandler PropertyChanged; diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/ISelectable.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/ISelectable.cs index e91ead0..0113751 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/ISelectable.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/ISelectable.cs @@ -23,6 +23,11 @@ namespace AIStudio.Wpf.DiagramDesigner get; set; } + bool ShowText + { + get; set; + } + void AddToSelection(bool selected); event PropertyChangedEventHandler PropertyChanged; diff --git a/AIStudio.Wpf.Mind/Helpers/DirectoryLayout.cs b/AIStudio.Wpf.Mind/Helpers/DirectoryLayout.cs index 51c8a18..b883fb3 100644 --- a/AIStudio.Wpf.Mind/Helpers/DirectoryLayout.cs +++ b/AIStudio.Wpf.Mind/Helpers/DirectoryLayout.cs @@ -92,6 +92,7 @@ namespace AIStudio.Wpf.Mind.Helpers { connector?.UpdateConnectionMode(source.FirstConnector, sink.FirstConnector, DrawMode.ConnectingLineStraight.ToString(), RouterMode.RouterOrthogonal.ToString()); } + connector.EnabledForSelection = false; connector.ColorViewModel.LineColor = source.ColorViewModel.LineColor; connector.ShapeViewModel.SinkMarker.PathStyle = source.ShapeViewModel.SinkMarker.PathStyle; connector.ShapeViewModel.SinkMarker.SizeStyle = source.ShapeViewModel.SinkMarker.SizeStyle;