-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from Atypical-Consulting/features/undo-redo
Features/undo redo
- Loading branch information
Showing
101 changed files
with
2,092 additions
and
1,017 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Atypical.VirtualFileSystem.DemoCli" type="DotNetProject" factoryName=".NET Project"> | ||
<option name="EXE_PATH" value="$PROJECT_DIR$/Atypical.VirtualFileSystem.DemoCli/bin/Debug/net8.0/Atypical.VirtualFileSystem.DemoCli" /> | ||
<option name="PROGRAM_PARAMETERS" value="" /> | ||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Atypical.VirtualFileSystem.DemoCli/bin/Debug/net8.0" /> | ||
<option name="PASS_PARENT_ENVS" value="1" /> | ||
<option name="USE_EXTERNAL_CONSOLE" value="0" /> | ||
<option name="USE_MONO" value="0" /> | ||
<option name="RUNTIME_ARGUMENTS" value="" /> | ||
<option name="PROJECT_PATH" value="$PROJECT_DIR$/Atypical.VirtualFileSystem.DemoCli/Atypical.VirtualFileSystem.DemoCli.csproj" /> | ||
<option name="PROJECT_EXE_PATH_TRACKING" value="1" /> | ||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" /> | ||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" /> | ||
<option name="PROJECT_KIND" value="DotNetCore" /> | ||
<option name="PROJECT_TFM" value="net8.0" /> | ||
<method v="2"> | ||
<option name="Build" /> | ||
</method> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
Atypical.VirtualFileSystem.DemoCli/Commands/DemonstrateVFS.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using Spectre.Console.Cli; | ||
|
||
namespace Atypical.VirtualFileSystem.DemoCli.Commands; | ||
|
||
public class DemonstrateVFS : Command | ||
{ | ||
public override int Execute(CommandContext context) | ||
{ | ||
// Create a virtual file system | ||
var factory = new VirtualFileSystemFactory(); | ||
var vfs = factory.CreateFileSystem(); | ||
|
||
// Subscribe to VFS events | ||
SubscribeToWriteVFSEvents(vfs, OnChange); | ||
|
||
// Display a banner | ||
AnsiConsole.Write( | ||
new FigletText("VFS Demo") | ||
.LeftJustified() | ||
.Color(Color.Gold1)); | ||
|
||
// Create a directory structure | ||
ProcessStep(vfs, "CREATE A FILE STRUCTURE", () => | ||
{ | ||
vfs.CreateDirectory(new VFSDirectoryPath("/heroes")); | ||
vfs.CreateFile(new VFSFilePath("/heroes/ironman.txt"), "Tony Stark"); | ||
vfs.CreateFile(new VFSFilePath("/heroes/captain_america.txt"), "Steve Rogers"); | ||
vfs.CreateFile(new VFSFilePath("/heroes/hulk.txt"), "Bruce Banner"); | ||
vfs.CreateFile(new VFSFilePath("/heroes/thor.txt"), "Thor Odinson"); | ||
vfs.CreateFile(new VFSFilePath("/heroes/black_widow.txt"), "Natasha Romanoff"); | ||
|
||
vfs.CreateDirectory(new VFSDirectoryPath("/villains")); | ||
vfs.CreateFile(new VFSFilePath("/villains/loki.txt"), "Loki Laufeyson"); | ||
vfs.CreateFile(new VFSFilePath("/villains/ultron.txt"), "Ultron"); | ||
vfs.CreateFile(new VFSFilePath("/villains/thanos.txt"), "Thanos"); | ||
}); | ||
|
||
// Rename a file | ||
ProcessStep(vfs, "RENAME A FILE", | ||
() => vfs.RenameFile(new VFSFilePath("/heroes/ironman.txt"), "tommy_stark.txt")); | ||
|
||
// UNDO | ||
ProcessStep(vfs, "UNDO", () => vfs.ChangeHistory.Undo()); | ||
|
||
// REDO | ||
ProcessStep(vfs, "REDO", () => vfs.ChangeHistory.Redo()); | ||
|
||
// Move a file | ||
ProcessStep(vfs, "MOVE A FILE", | ||
() => vfs.MoveFile(new VFSFilePath("/heroes/tony_stark.txt"), new VFSFilePath("/villains/tony_stark.txt"))); | ||
|
||
// Delete a file | ||
ProcessStep(vfs, "DELETE A FILE", | ||
() => vfs.DeleteFile(new VFSFilePath("/villains/tony_stark.txt"))); | ||
|
||
// Delete a directory | ||
ProcessStep(vfs, "DELETE DIRECTORY", | ||
() => vfs.DeleteDirectory(new VFSDirectoryPath("/villains"))); | ||
|
||
// Move a directory | ||
ProcessStep(vfs, "MOVE DIRECTORY", | ||
() => vfs.MoveDirectory(new VFSDirectoryPath("/heroes"), new VFSDirectoryPath("/avengers"))); | ||
|
||
// Rename a directory | ||
// TODO: fix rename directory | ||
// ProcessStep(vfs, "RENAME DIRECTORY", | ||
// () => vfs.RenameDirectory(new VFSDirectoryPath("/avengers"), new VFSDirectoryPath("/heroes"))); | ||
|
||
return 0; | ||
} | ||
|
||
private static void SubscribeToWriteVFSEvents( | ||
IVirtualFileSystem virtualFileSystem, | ||
Action<VFSEventArgs> action) | ||
{ | ||
virtualFileSystem.DirectoryCreated += action; | ||
virtualFileSystem.FileCreated += action; | ||
virtualFileSystem.DirectoryDeleted += action; | ||
virtualFileSystem.FileDeleted += action; | ||
virtualFileSystem.DirectoryMoved += action; | ||
virtualFileSystem.FileMoved += action; | ||
virtualFileSystem.DirectoryRenamed += action; | ||
virtualFileSystem.FileRenamed += action; | ||
} | ||
|
||
private static void OnChange(VFSEventArgs args) | ||
{ | ||
AnsiConsole.Write(new Markup($" - {args.MessageWithMarkup}")); | ||
AnsiConsole.WriteLine(); | ||
} | ||
|
||
private static void ProcessStep(IVirtualFileSystem virtualFileSystem, string sectionHeader, Action action) | ||
{ | ||
WriteSectionHeader(sectionHeader); | ||
action(); | ||
WriteTree(virtualFileSystem); | ||
} | ||
|
||
private static void WriteSectionHeader(string header = "") | ||
{ | ||
AnsiConsole.Write(new Markup($"[underline yellow]{header}[/]")); | ||
AnsiConsole.WriteLine(); | ||
AnsiConsole.WriteLine(); | ||
} | ||
|
||
private static void WriteTree(IVirtualFileSystem virtualFileSystem) | ||
{ | ||
AnsiConsole.WriteLine(); | ||
AnsiConsole.Write(new Tree("Marvel Universe").FillTree(virtualFileSystem)); | ||
AnsiConsole.WriteLine(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// Global using directives | ||
|
||
global using Atypical.VirtualFileSystem.Core; | ||
global using Atypical.VirtualFileSystem.Core.Contracts; | ||
global using Atypical.VirtualFileSystem.DemoCli.Extensions; | ||
global using Spectre.Console; |
Oops, something went wrong.