35 lines
939 B
C#
35 lines
939 B
C#
using System.IO;
|
|
using Intromat.Interfaces;
|
|
using Intromat.ViewModels;
|
|
|
|
namespace Intromat.Actions.Hierarchy
|
|
{
|
|
public class CreateModuleAction : IUndoItem
|
|
{
|
|
private readonly ModuleViewModel _module;
|
|
private readonly ProjectViewModel _parent;
|
|
|
|
public CreateModuleAction(string name, ProjectViewModel parent)
|
|
{
|
|
var modulePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(parent.FullPath)!, name, $"{name}.imodule"));
|
|
_module = new ModuleViewModel(parent, name, modulePath);
|
|
File = _parent = parent;
|
|
}
|
|
|
|
public IFile File { get; }
|
|
|
|
public void Redo()
|
|
{
|
|
_parent.Modules.Add(_module);
|
|
_parent.IsExpanded = true;
|
|
_module.IsSelected = true;
|
|
}
|
|
|
|
public void Undo()
|
|
{
|
|
_parent.Modules.Remove(_module);
|
|
_parent.IsSelected = true;
|
|
}
|
|
}
|
|
}
|