颜色,字体,支持redo undo

This commit is contained in:
艾竹
2023-04-08 23:38:01 +08:00
parent 8ad42aec49
commit 2ef5b7a1ed
6 changed files with 110 additions and 14 deletions

View File

@@ -88,9 +88,12 @@ namespace AIStudio.Wpf.DiagramDesigner
{ {
RaisePropertyChanged(nameof(FillColor)); RaisePropertyChanged(nameof(FillColor));
} }
RaisePropertyChanged(sender, e);
} }
private Color _shadowColor = Colors.Transparent; private Color _shadowColor = Colors.Transparent;
[CanDo]
public Color ShadowColor public Color ShadowColor
{ {
get get
@@ -107,6 +110,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private double _lineWidth = 1d; private double _lineWidth = 1d;
[CanDo]
public double LineWidth public double LineWidth
{ {
get get
@@ -123,6 +127,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private LineDashStyle _lineDashStyle = LineDashStyle.None; private LineDashStyle _lineDashStyle = LineDashStyle.None;
[CanDo]
public LineDashStyle LineDashStyle public LineDashStyle LineDashStyle
{ {
get get
@@ -139,6 +144,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private LineAnimation _lineAnimation = LineAnimation.None; private LineAnimation _lineAnimation = LineAnimation.None;
[CanDo]
public LineAnimation LineAnimation public LineAnimation LineAnimation
{ {
get get
@@ -152,6 +158,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private double _lineAnimationDuration = 1; private double _lineAnimationDuration = 1;
[CanDo]
public double LineAnimationDuration public double LineAnimationDuration
{ {
get get
@@ -214,6 +221,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private BrushType _brushType = BrushType.SolidColorBrush; private BrushType _brushType = BrushType.SolidColorBrush;
[CanDo]
public BrushType BrushType public BrushType BrushType
{ {
get get
@@ -230,6 +238,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private Color _color = new Color(); private Color _color = new Color();
[CanDo]
public Color Color public Color Color
{ {
get get
@@ -279,6 +288,7 @@ namespace AIStudio.Wpf.DiagramDesigner
SetProperty(ref _selectedGradientStop, value); SetProperty(ref _selectedGradientStop, value);
} }
} }
private Point _startPoint; private Point _startPoint;
public Point StartPoint public Point StartPoint
{ {
@@ -306,6 +316,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private double _opacity = 1; private double _opacity = 1;
[CanDo]
public double Opacity public double Opacity
{ {
get get
@@ -332,6 +343,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private string _image; private string _image;
[CanDo]
public string Image public string Image
{ {
get get
@@ -345,6 +357,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private LinearOrientation _linearOrientation; private LinearOrientation _linearOrientation;
[CanDo]
public LinearOrientation LinearOrientation public LinearOrientation LinearOrientation
{ {
get get
@@ -358,6 +371,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private RadialOrientation _radialOrientation; private RadialOrientation _radialOrientation;
[CanDo]
public RadialOrientation RadialOrientation public RadialOrientation RadialOrientation
{ {
get get
@@ -371,6 +385,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private int _angle; private int _angle;
[CanDo]
public int Angle public int Angle
{ {
get get

View File

@@ -197,6 +197,7 @@ namespace AIStudio.Wpf.DiagramDesigner
#endregion #endregion
private string _fontFamily = "Arial"; private string _fontFamily = "Arial";
[CanDo]
public string FontFamily public string FontFamily
{ {
get get
@@ -213,6 +214,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private double _fontSize = 12; private double _fontSize = 12;
[CanDo]
public double FontSize public double FontSize
{ {
get get
@@ -230,6 +232,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private Color _fontColor = Colors.Black; private Color _fontColor = Colors.Black;
[CanDo]
public Color FontColor public Color FontColor
{ {
get get
@@ -246,7 +249,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private FontWeight _fontWeight = FontWeights.Regular; private FontWeight _fontWeight = FontWeights.Regular;
[CanDo]
public FontWeight FontWeight public FontWeight FontWeight
{ {
get get
@@ -263,6 +266,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private FontStyle _fontStyle = FontStyles.Normal; private FontStyle _fontStyle = FontStyles.Normal;
[CanDo]
public FontStyle FontStyle public FontStyle FontStyle
{ {
get get
@@ -279,7 +283,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private FontStretch _fontStretch = FontStretches.Normal; private FontStretch _fontStretch = FontStretches.Normal;
[CanDo]
public FontStretch FontStretch public FontStretch FontStretch
{ {
get get
@@ -296,6 +300,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private bool _underline; private bool _underline;
[CanDo]
public bool Underline public bool Underline
{ {
get get
@@ -316,6 +321,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private bool _strikethrough; private bool _strikethrough;
[CanDo]
public bool Strikethrough public bool Strikethrough
{ {
get get
@@ -336,6 +342,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private bool _overLine; private bool _overLine;
[CanDo]
public bool OverLine public bool OverLine
{ {
get get
@@ -356,7 +363,6 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private TextDecorationCollection _textDecorations; private TextDecorationCollection _textDecorations;
public TextDecorationCollection TextDecorations public TextDecorationCollection TextDecorations
{ {
get get
@@ -383,6 +389,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private Color _textEffectColor = Colors.Transparent; private Color _textEffectColor = Colors.Transparent;
[CanDo]
public Color TextEffectColor public Color TextEffectColor
{ {
get { return _textEffectColor; } get { return _textEffectColor; }
@@ -397,6 +404,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private Color _highlightColor = Colors.Transparent; private Color _highlightColor = Colors.Transparent;
[CanDo]
public Color HighlightColor public Color HighlightColor
{ {
get { return _highlightColor; } get { return _highlightColor; }
@@ -411,6 +419,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private FontCase _fontCase = FontCase.None; private FontCase _fontCase = FontCase.None;
[CanDo]
public FontCase FontCase public FontCase FontCase
{ {
get get
@@ -427,6 +436,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private HorizontalAlignment _horizontalAlignment = HorizontalAlignment.Center; private HorizontalAlignment _horizontalAlignment = HorizontalAlignment.Center;
[CanDo]
public HorizontalAlignment HorizontalAlignment public HorizontalAlignment HorizontalAlignment
{ {
get get
@@ -443,6 +453,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private VerticalAlignment _verticalAlignment = VerticalAlignment.Center; private VerticalAlignment _verticalAlignment = VerticalAlignment.Center;
[CanDo]
public VerticalAlignment VerticalAlignment public VerticalAlignment VerticalAlignment
{ {
get get
@@ -459,6 +470,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private double _lineHeight = Double.NaN; private double _lineHeight = Double.NaN;
[CanDo]
public double LineHeight public double LineHeight
{ {
get get

View File

@@ -105,6 +105,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private string _path; private string _path;
[CanDo]
public string Path public string Path
{ {
get get
@@ -118,6 +119,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private double _witdh; private double _witdh;
[CanDo]
public double Width public double Width
{ {
get get
@@ -131,6 +133,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private double _height; private double _height;
[CanDo]
public double Height public double Height
{ {
get get
@@ -144,6 +147,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private ArrowPathStyle _pathStyle = ArrowPathStyle.None; private ArrowPathStyle _pathStyle = ArrowPathStyle.None;
[CanDo]
public ArrowPathStyle PathStyle public ArrowPathStyle PathStyle
{ {
get get
@@ -163,6 +167,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
private ArrowSizeStyle _sizeStyle = ArrowSizeStyle.Middle; private ArrowSizeStyle _sizeStyle = ArrowSizeStyle.Middle;
[CanDo]
public ArrowSizeStyle SizeStyle public ArrowSizeStyle SizeStyle
{ {
get get

View File

@@ -93,23 +93,23 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
} }
} }
private IShapeViewModel _linkMarkerViewModel; private IShapeViewModel _shapeViewModel;
public IShapeViewModel ShapeViewModel public IShapeViewModel ShapeViewModel
{ {
get get
{ {
return _linkMarkerViewModel; return _shapeViewModel;
} }
set set
{ {
if (_linkMarkerViewModel != null) if (_shapeViewModel != null)
{ {
_linkMarkerViewModel.PropertyChanged -= ViewModel_PropertyChanged; _shapeViewModel.PropertyChanged -= ViewModel_PropertyChanged;
} }
SetProperty(ref _linkMarkerViewModel, value); SetProperty(ref _shapeViewModel, value);
if (_linkMarkerViewModel != null) if (_shapeViewModel != null)
{ {
_linkMarkerViewModel.PropertyChanged += ViewModel_PropertyChanged; _shapeViewModel.PropertyChanged += ViewModel_PropertyChanged;
} }
} }
} }

View File

@@ -29,23 +29,26 @@ namespace AIStudio.Wpf.DiagramDesigner
public SelectableViewModelBase(IDiagramViewModel root) public SelectableViewModelBase(IDiagramViewModel root)
{ {
IsLoaded = false;
Init(root, true); Init(root, true);
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged; IsLoaded = true;
} }
public SelectableViewModelBase(IDiagramViewModel root, SelectableItemBase designer) public SelectableViewModelBase(IDiagramViewModel root, SelectableItemBase designer)
{ {
IsLoaded = false;
Init(root, false); Init(root, false);
LoadDesignerItemViewModel(designer); LoadDesignerItemViewModel(designer);
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged; IsLoaded = true;
} }
public SelectableViewModelBase(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) public SelectableViewModelBase(IDiagramViewModel root, SerializableItem serializableItem, string serializableType)
{ {
IsLoaded = false;
Init(root, false); Init(root, false);
SelectableItemBase obj = SerializeHelper.DeserializeObject(serializableItem.SerializableTypeName, serializableItem.SerializableString, serializableType); SelectableItemBase obj = SerializeHelper.DeserializeObject(serializableItem.SerializableTypeName, serializableItem.SerializableString, serializableType);
LoadDesignerItemViewModel(obj); LoadDesignerItemViewModel(obj);
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged; IsLoaded = true;
} }
public virtual SerializableItem ToSerializableItem(string serializableType) public virtual SerializableItem ToSerializableItem(string serializableType)
@@ -67,7 +70,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
protected virtual void Init(IDiagramViewModel root, bool initNew) protected virtual void Init(IDiagramViewModel root, bool initNew)
{ {
Root = root; Root = root;
if (Root?.ColorViewModel != null) if (Root?.ColorViewModel != null)
@@ -103,6 +106,9 @@ namespace AIStudio.Wpf.DiagramDesigner
{ {
InitNew(); InitNew();
} }
this.PropertyChanged -= Item_PropertyChanged;
this.PropertyChanged += Item_PropertyChanged;
} }
protected virtual void InitNew() protected virtual void InitNew()
@@ -123,6 +129,11 @@ namespace AIStudio.Wpf.DiagramDesigner
ShapeViewModel = CopyHelper.Mapper(designerbase.SharpItem); ShapeViewModel = CopyHelper.Mapper(designerbase.SharpItem);
} }
protected bool IsLoaded
{
get;set;
}
public IDiagramViewModel Root public IDiagramViewModel Root
{ {
get; set; get; set;
@@ -299,7 +310,15 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
set set
{ {
if (_colorViewModel != null)
{
_colorViewModel.PropertyChanged -= ColorViewModel_PropertyChanged;
}
SetProperty(ref _colorViewModel, value); SetProperty(ref _colorViewModel, value);
if (_colorViewModel != null)
{
_colorViewModel.PropertyChanged += ColorViewModel_PropertyChanged;
}
} }
} }
@@ -312,7 +331,15 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
set set
{ {
if (_fontViewModel != null)
{
_fontViewModel.PropertyChanged -= FontViewModel_PropertyChanged;
}
SetProperty(ref _fontViewModel, value); SetProperty(ref _fontViewModel, value);
if (_fontViewModel != null)
{
_fontViewModel.PropertyChanged += FontViewModel_PropertyChanged;
}
} }
} }
@@ -325,7 +352,15 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
set set
{ {
if (_shapeViewModel != null)
{
_shapeViewModel.PropertyChanged -= ShapeViewModel_PropertyChanged;
}
SetProperty(ref _shapeViewModel, value); SetProperty(ref _shapeViewModel, value);
if (_shapeViewModel != null)
{
_shapeViewModel.PropertyChanged += ShapeViewModel_PropertyChanged;
}
} }
} }
@@ -384,14 +419,38 @@ namespace AIStudio.Wpf.DiagramDesigner
return IsReadOnly == false; return IsReadOnly == false;
} }
protected virtual void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (IsLoaded == false) { return; }
}
protected virtual void FontViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) protected virtual void FontViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
if (IsLoaded == false) { return; }
if (e.PropertyName == nameof(FontViewModel.FontCase)) if (e.PropertyName == nameof(FontViewModel.FontCase))
{ {
RaisePropertyChanged("Text"); RaisePropertyChanged("Text");
} }
RaisePropertyChanged(sender, e);
} }
protected virtual void ColorViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (IsLoaded == false) { return; }
RaisePropertyChanged(sender, e);
}
protected virtual void ShapeViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (IsLoaded == false) { return; }
RaisePropertyChanged(sender, e);
}
public override string ToString() public override string ToString()
{ {
return $"{Id}-{Text}"; return $"{Id}-{Text}";

View File

@@ -134,6 +134,11 @@ namespace AIStudio.Wpf.DiagramDesigner
PropertyChanged?.Invoke(sender, new ValuePropertyChangedEventArgs(propertyName, oldvalue, newvalue)); PropertyChanged?.Invoke(sender, new ValuePropertyChangedEventArgs(propertyName, oldvalue, newvalue));
} }
protected void RaisePropertyChanged(object sender, PropertyChangedEventArgs args)
{
PropertyChanged?.Invoke(sender, args);
}
/// <summary> /// <summary>
/// Raises this object's PropertyChanged event. /// Raises this object's PropertyChanged event.
/// </summary> /// </summary>