mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
166 lines
4.0 KiB
C#
166 lines
4.0 KiB
C#
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
|
|
{
|
|
SimpleCommand SelectItemCommand
|
|
{
|
|
get;
|
|
}
|
|
}
|
|
|
|
|
|
public abstract class SelectableDesignerItemViewModelBase : SelectableViewModelBase, ISelectItems, ISelectable, IGroupable
|
|
{
|
|
|
|
public SelectableDesignerItemViewModelBase():base()
|
|
{
|
|
|
|
}
|
|
|
|
public SelectableDesignerItemViewModelBase(IDiagramViewModel root, SelectableItemBase designer):base(root, designer)
|
|
{
|
|
|
|
}
|
|
|
|
public SelectableDesignerItemViewModelBase(IDiagramViewModel root, string serializableString, string serializableType) : base(root, serializableString, serializableType)
|
|
{
|
|
|
|
}
|
|
|
|
protected override void Init()
|
|
{
|
|
base.Init();
|
|
|
|
SelectItemCommand = new SimpleCommand(ExecuteSelectItemCommand);
|
|
EditCommand = new SimpleCommand(ExecuteEditCommand);
|
|
}
|
|
|
|
public virtual bool InitData()
|
|
{
|
|
return true;
|
|
}
|
|
public virtual bool EditData()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public SimpleCommand SelectItemCommand
|
|
{
|
|
get; private set;
|
|
}
|
|
public ICommand EditCommand
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
private string _text;
|
|
[Browsable(true)]
|
|
[CanDo]
|
|
public override string Text
|
|
{
|
|
get
|
|
{
|
|
var text = _text;
|
|
if (FontViewModel.FontCase == FontCase.Upper)
|
|
{
|
|
return text?.ToUpper();
|
|
}
|
|
else if (FontViewModel.FontCase == FontCase.Lower)
|
|
{
|
|
return text?.ToLower();
|
|
}
|
|
else
|
|
{
|
|
return text;
|
|
}
|
|
}
|
|
set
|
|
{
|
|
if (SetProperty(ref _text, value))
|
|
{
|
|
if (!string.IsNullOrEmpty(_text))
|
|
{
|
|
ShowText = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool _isReadOnlyText = false;
|
|
public bool IsReadOnlyText
|
|
{
|
|
get
|
|
{
|
|
if (IsReadOnly)
|
|
return true;
|
|
return _isReadOnlyText;
|
|
}
|
|
set
|
|
{
|
|
SetProperty(ref _isReadOnlyText, value);
|
|
}
|
|
}
|
|
|
|
private bool _showText;
|
|
public virtual bool ShowText
|
|
{
|
|
get
|
|
{
|
|
return _showText;
|
|
}
|
|
set
|
|
{
|
|
SetProperty(ref _showText, value);
|
|
}
|
|
}
|
|
|
|
private void ExecuteSelectItemCommand(object param)
|
|
{
|
|
SelectItem((bool)param, !IsSelected);
|
|
}
|
|
|
|
private void SelectItem(bool newselect, bool select)
|
|
{
|
|
if (newselect)
|
|
{
|
|
foreach (var designerItemViewModelBase in Root.SelectedItems.ToList())
|
|
{
|
|
designerItemViewModelBase._isSelected = false;
|
|
}
|
|
}
|
|
|
|
IsSelected = select;
|
|
}
|
|
|
|
public override void AddToSelection(bool selected)
|
|
{
|
|
foreach (SelectableDesignerItemViewModelBase item in Root.SelectedItems.ToList())
|
|
item.IsSelected = false;
|
|
|
|
Root.SelectedItems.Clear();
|
|
if (selected == true)
|
|
{
|
|
Root.SelectionService.AddToSelection(this);
|
|
}
|
|
}
|
|
|
|
protected virtual void ExecuteEditCommand(object param)
|
|
{
|
|
if (IsReadOnly == true) return;
|
|
|
|
ShowText = true;
|
|
}
|
|
}
|
|
}
|