2023-01-24 09:02:40 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Models;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public interface ISelectItems
|
|
|
|
|
|
{
|
2023-03-24 22:32:42 +08:00
|
|
|
|
ICommand SelectItemCommand
|
2023-01-24 09:02:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
get;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public abstract class SelectableDesignerItemViewModelBase : SelectableViewModelBase, ISelectItems, ISelectable, IGroupable
|
|
|
|
|
|
{
|
2023-01-27 14:54:03 +08:00
|
|
|
|
public SelectableDesignerItemViewModelBase() : this(null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2023-01-24 09:02:40 +08:00
|
|
|
|
|
2023-01-27 14:54:03 +08:00
|
|
|
|
public SelectableDesignerItemViewModelBase(IDiagramViewModel root) :base(root)
|
2023-01-24 09:02:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-24 16:20:39 +08:00
|
|
|
|
public SelectableDesignerItemViewModelBase(IDiagramViewModel root, SelectableItemBase designer):base(root, designer)
|
2023-01-24 09:02:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
public SelectableDesignerItemViewModelBase(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
2023-01-24 09:02:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-25 11:59:31 +08:00
|
|
|
|
protected override void Init(IDiagramViewModel root, bool initNew)
|
2023-01-24 09:02:40 +08:00
|
|
|
|
{
|
2023-05-03 23:42:34 +08:00
|
|
|
|
base.Init(root, initNew);
|
2023-01-25 23:55:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-25 11:59:31 +08:00
|
|
|
|
protected override void InitNew()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.InitNew();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-27 14:54:03 +08:00
|
|
|
|
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
|
2023-01-25 23:55:30 +08:00
|
|
|
|
{
|
2023-01-27 14:54:03 +08:00
|
|
|
|
base.LoadDesignerItemViewModel(designerbase);
|
2023-01-24 09:02:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-03 18:35:01 +08:00
|
|
|
|
public virtual bool Verify()
|
2023-01-24 09:02:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
public virtual bool EditData()
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-03 23:42:34 +08:00
|
|
|
|
private ICommand _selectItemCommand;
|
2023-03-24 22:32:42 +08:00
|
|
|
|
public ICommand SelectItemCommand
|
2023-01-24 09:02:40 +08:00
|
|
|
|
{
|
2023-05-03 23:42:34 +08:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return this._editCommand ?? (this._editCommand = new SimpleCommand(Command_Enable, ExecuteSelectItemCommand));
|
|
|
|
|
|
}
|
2023-01-24 09:02:40 +08:00
|
|
|
|
}
|
2023-05-03 23:42:34 +08:00
|
|
|
|
|
|
|
|
|
|
private ICommand _editCommand;
|
2023-01-24 09:02:40 +08:00
|
|
|
|
public ICommand EditCommand
|
|
|
|
|
|
{
|
2023-05-03 23:42:34 +08:00
|
|
|
|
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));
|
|
|
|
|
|
}
|
2023-01-25 23:55:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-08 14:22:12 +08:00
|
|
|
|
private bool enabledForSelection = true;
|
|
|
|
|
|
public bool EnabledForSelection
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return enabledForSelection;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref enabledForSelection, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-02-01 23:05:56 +08:00
|
|
|
|
private bool _isReadOnlyText = false;
|
|
|
|
|
|
public bool IsReadOnlyText
|
2023-01-24 09:02:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2023-02-01 23:05:56 +08:00
|
|
|
|
if (IsReadOnly)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
return _isReadOnlyText;
|
2023-01-24 09:02:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2023-02-01 23:05:56 +08:00
|
|
|
|
SetProperty(ref _isReadOnlyText, value);
|
2023-01-24 09:02:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-01 23:05:56 +08:00
|
|
|
|
//自己定义文本显示,文本框不显示
|
|
|
|
|
|
private bool _customText = false;
|
|
|
|
|
|
public bool CustomText
|
2023-01-24 09:02:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2023-02-01 23:05:56 +08:00
|
|
|
|
return _customText;
|
2023-01-24 09:02:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2023-02-01 23:05:56 +08:00
|
|
|
|
SetProperty(ref _customText, value);
|
2023-01-24 09:02:40 +08:00
|
|
|
|
}
|
2023-04-08 14:22:12 +08:00
|
|
|
|
}
|
2023-01-24 09:02:40 +08:00
|
|
|
|
|
2023-02-01 23:05:56 +08:00
|
|
|
|
protected override void ClearText()
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowText = false;
|
2023-04-08 14:22:12 +08:00
|
|
|
|
|
2023-02-01 23:05:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-24 09:02:40 +08:00
|
|
|
|
private void ExecuteSelectItemCommand(object param)
|
|
|
|
|
|
{
|
|
|
|
|
|
SelectItem((bool)param, !IsSelected);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SelectItem(bool newselect, bool select)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (newselect)
|
|
|
|
|
|
{
|
2023-01-24 16:20:39 +08:00
|
|
|
|
foreach (var designerItemViewModelBase in Root.SelectedItems.ToList())
|
2023-01-24 09:02:40 +08:00
|
|
|
|
{
|
2023-02-01 23:05:56 +08:00
|
|
|
|
designerItemViewModelBase.ClearSelected();
|
2023-01-24 09:02:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IsSelected = select;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void AddToSelection(bool selected)
|
|
|
|
|
|
{
|
2023-01-24 16:20:39 +08:00
|
|
|
|
foreach (SelectableDesignerItemViewModelBase item in Root.SelectedItems.ToList())
|
2023-01-24 09:02:40 +08:00
|
|
|
|
item.IsSelected = false;
|
|
|
|
|
|
|
2023-01-24 16:20:39 +08:00
|
|
|
|
Root.SelectedItems.Clear();
|
2023-01-24 09:02:40 +08:00
|
|
|
|
if (selected == true)
|
|
|
|
|
|
{
|
2023-01-24 16:20:39 +08:00
|
|
|
|
Root.SelectionService.AddToSelection(this);
|
2023-01-24 09:02:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void ExecuteEditCommand(object param)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsReadOnly == true) return;
|
|
|
|
|
|
|
|
|
|
|
|
ShowText = true;
|
2023-05-03 23:42:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void ExecuteExitEditCommand(object param)
|
|
|
|
|
|
{
|
|
|
|
|
|
IsSelected = false;
|
|
|
|
|
|
}
|
2023-01-24 09:02:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|