首次提交:本地项目同步到Gitea
This commit is contained in:
25
LibShapes/Core/Command/CommandCreate.cs
Normal file
25
LibShapes/Core/Command/CommandCreate.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
/// <summary>
|
||||
/// 新建形状的命令,
|
||||
/// </summary>
|
||||
public class CommandCreate : ShapeCommand
|
||||
{
|
||||
public override void Redo()
|
||||
{
|
||||
this.canvas.shapes.lstShapes.Add(this.NewShape);
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Undo()
|
||||
{
|
||||
this.canvas.shapes.lstShapes.Remove(this.NewShape);
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
30
LibShapes/Core/Command/CommandDelete.cs
Normal file
30
LibShapes/Core/Command/CommandDelete.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
public class CommandDelete : ShapeCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// 从哪一项删除的。
|
||||
/// </summary>
|
||||
public int index { get; set; }
|
||||
|
||||
public override void Redo()
|
||||
{
|
||||
// 重新删除
|
||||
this.index = this.canvas.shapes.lstShapes.IndexOf(this.NewShape);
|
||||
this.canvas.shapes.lstShapes.Remove(this.NewShape);
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Undo()
|
||||
{
|
||||
// 从这个位置重新插入。
|
||||
this.canvas.shapes.lstShapes.Insert(this.index, this.NewShape);
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
14
LibShapes/Core/Command/CommandMove.cs
Normal file
14
LibShapes/Core/Command/CommandMove.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
/// <summary>
|
||||
/// 这个实际上没有用到,我用CommandResize来统一了。
|
||||
/// </summary>
|
||||
public class CommandMove : ShapeCommand
|
||||
{
|
||||
}
|
||||
}
|
||||
23
LibShapes/Core/Command/CommandPropertyChanged.cs
Normal file
23
LibShapes/Core/Command/CommandPropertyChanged.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
public class CommandPropertyChanged : ShapeCommand
|
||||
{
|
||||
public override void Redo()
|
||||
{
|
||||
this.canvas.shapes.replaceShape(this.OldShape.ID, this.NewShape);
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Undo()
|
||||
{
|
||||
this.canvas.shapes.replaceShape(this.OldShape.ID, this.OldShape);
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
65
LibShapes/Core/Command/CommandRecorder.cs
Normal file
65
LibShapes/Core/Command/CommandRecorder.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
public class CommandRecorder:ICommandRecorder
|
||||
{
|
||||
// 保存一堆的命令
|
||||
private List<ICommand> commands = new List<ICommand>();
|
||||
// 当前的下标
|
||||
private int current_index = -1;
|
||||
|
||||
public void addCommand(ICommand command)
|
||||
{
|
||||
// 这里要判断是否是最后一个
|
||||
if (current_index < commands.Count - 1)
|
||||
{
|
||||
// 说明后边还有,首先删除后边的
|
||||
commands.RemoveRange(current_index + 1, commands.Count - current_index-1);
|
||||
}
|
||||
// 添加进去
|
||||
commands.Add(command);
|
||||
// 重新设置
|
||||
current_index += 1;
|
||||
}
|
||||
|
||||
public bool isRedoAble()
|
||||
{
|
||||
return current_index < this.commands.Count - 1;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool isUndoAble()
|
||||
{
|
||||
return current_index > 0;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
//
|
||||
current_index += 1;// 往后退一步
|
||||
if (current_index >= commands.Count) current_index = commands.Count - 1;// 不能再前进了。
|
||||
// 这里表示有操作
|
||||
if (current_index >= 0 && current_index < commands.Count)
|
||||
{
|
||||
commands[current_index].Redo();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
// 这里表示有操作
|
||||
if (current_index >= 0 && current_index < commands.Count)
|
||||
{
|
||||
commands[current_index].Undo();
|
||||
}
|
||||
current_index -= 1;// 往后退一步
|
||||
if (current_index < 0) current_index = -1;// 有最小的不能再退
|
||||
}
|
||||
}
|
||||
}
|
||||
12
LibShapes/Core/Command/CommandResize.cs
Normal file
12
LibShapes/Core/Command/CommandResize.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
public class CommandResize : ShapeCommand
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
12
LibShapes/Core/Command/CommandShapeBackward.cs
Normal file
12
LibShapes/Core/Command/CommandShapeBackward.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
class CommandShapeBackward : ShapeCommand
|
||||
{
|
||||
// todo 命令
|
||||
}
|
||||
}
|
||||
12
LibShapes/Core/Command/CommandShapeBackwardToEnd.cs
Normal file
12
LibShapes/Core/Command/CommandShapeBackwardToEnd.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
class CommandShapeBackwardToEnd : ShapeCommand
|
||||
{
|
||||
// todo 命令
|
||||
}
|
||||
}
|
||||
12
LibShapes/Core/Command/CommandShapeCancelGroup.cs
Normal file
12
LibShapes/Core/Command/CommandShapeCancelGroup.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
class CommandShapeCancelGroup : ShapeCommand
|
||||
{
|
||||
// todo 命令
|
||||
}
|
||||
}
|
||||
12
LibShapes/Core/Command/CommandShapeForward.cs
Normal file
12
LibShapes/Core/Command/CommandShapeForward.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
public class CommandShapeForward:ShapeCommand
|
||||
{
|
||||
// todo 命令
|
||||
}
|
||||
}
|
||||
12
LibShapes/Core/Command/CommandShapeForwardToFront.cs
Normal file
12
LibShapes/Core/Command/CommandShapeForwardToFront.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
class CommandShapeForwardToFront:ShapeCommand
|
||||
{
|
||||
// todo 命令
|
||||
}
|
||||
}
|
||||
12
LibShapes/Core/Command/CommandShapeMergeGroup.cs
Normal file
12
LibShapes/Core/Command/CommandShapeMergeGroup.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
class CommandShapeMergeGroup : ShapeCommand
|
||||
{
|
||||
// todo 命令
|
||||
}
|
||||
}
|
||||
46
LibShapes/Core/Command/CommandShapesChanged.cs
Normal file
46
LibShapes/Core/Command/CommandShapesChanged.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
/**
|
||||
* 我这里做一个省事,所有的更改都改成这种更改,而不是单独的区分了。
|
||||
*
|
||||
* **/
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Shapes的更改
|
||||
/// </summary>
|
||||
public class CommandShapesChanged:ICommand
|
||||
{
|
||||
/// <summary>
|
||||
/// 原先的
|
||||
/// </summary>
|
||||
public Shapes OldShapes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 新的
|
||||
/// </summary>
|
||||
public Shapes NewShapes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 画布
|
||||
/// </summary>
|
||||
public UserControlCanvas canvas { get; set; }
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
this.canvas.shapes = NewShapes;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
this.canvas.shapes = OldShapes;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
14
LibShapes/Core/Command/ICommand.cs
Normal file
14
LibShapes/Core/Command/ICommand.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
public interface ICommand
|
||||
{
|
||||
void Undo();
|
||||
|
||||
void Redo();
|
||||
}
|
||||
}
|
||||
20
LibShapes/Core/Command/ICommandRecorder.cs
Normal file
20
LibShapes/Core/Command/ICommandRecorder.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
public interface ICommandRecorder
|
||||
{
|
||||
void addCommand(ICommand command);
|
||||
|
||||
void Undo();
|
||||
|
||||
void Redo();
|
||||
|
||||
bool isUndoAble();
|
||||
|
||||
bool isRedoAble();
|
||||
}
|
||||
}
|
||||
35
LibShapes/Core/Command/ShapeCommand.cs
Normal file
35
LibShapes/Core/Command/ShapeCommand.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.Command
|
||||
{
|
||||
/// <summary>
|
||||
/// 形状方面的命令。
|
||||
/// </summary>
|
||||
public abstract class ShapeCommand: ICommand
|
||||
{
|
||||
/// <summary>
|
||||
/// 原先的形状
|
||||
/// </summary>
|
||||
public ShapeEle OldShape { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 新的形状
|
||||
/// </summary>
|
||||
public ShapeEle NewShape { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 画布
|
||||
/// </summary>
|
||||
public UserControlCanvas canvas { get; set; }
|
||||
|
||||
// 如下是两个操作。
|
||||
|
||||
public virtual void Undo() { this.canvas.shapes.replaceShape(this.OldShape.ID, this.NewShape); }
|
||||
|
||||
public virtual void Redo() { this.canvas.shapes.replaceShape(this.OldShape.ID, this.OldShape); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user