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-03-25 11:59:31 +08:00
|
|
|
|
base.Init(root, initNew);
|
2023-01-24 09:02:40 +08:00
|
|
|
|
|
2023-01-25 23:55:30 +08:00
|
|
|
|
SelectItemCommand = new SimpleCommand(Command_Enable, ExecuteSelectItemCommand);
|
|
|
|
|
|
EditCommand = new SimpleCommand(Command_Enable, ExecuteEditCommand);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual bool InitData()
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
public virtual bool EditData()
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-24 22:32:42 +08:00
|
|
|
|
public ICommand SelectItemCommand
|
2023-01-24 09:02:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
get; private set;
|
|
|
|
|
|
}
|
|
|
|
|
|
public ICommand EditCommand
|
|
|
|
|
|
{
|
|
|
|
|
|
get; private set;
|
2023-01-25 23:55:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool _showText;
|
2023-02-01 23:05:56 +08:00
|
|
|
|
public bool ShowText
|
2023-01-24 09:02:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _showText;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2023-01-29 22:54:06 +08:00
|
|
|
|
if (!SetProperty(ref _showText, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
RaisePropertyChanged(nameof(ShowText));
|
|
|
|
|
|
}
|
2023-01-24 09:02:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-01 23:05:56 +08:00
|
|
|
|
protected override void ClearText()
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowText = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-02-03 22:25:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
2023-01-24 09:02:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|