-
Notifications
You must be signed in to change notification settings - Fork 9
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 #28 from ItsTheSky/features/projects
Better projects
- Loading branch information
Showing
16 changed files
with
744 additions
and
62 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
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
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
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
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,88 @@ | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using Avalonia.Platform.Storage; | ||
using CommunityToolkit.Mvvm.Input; | ||
using SkEditor.API; | ||
using SkEditor.Utilities.Files; | ||
|
||
namespace SkEditor.Utilities.Projects.Elements; | ||
|
||
public class File : StorageElement | ||
{ | ||
|
||
public string StorageFilePath { get; set; } | ||
|
||
public File(string file, Folder? parent = null) | ||
{ | ||
Parent = parent; | ||
StorageFilePath = file; | ||
|
||
Name = Path.GetFileName(file); | ||
IsFile = true; | ||
|
||
var icon = Files.Icon.GetIcon(Path.GetExtension(file)); | ||
if (icon is not null) | ||
Icon = icon; | ||
|
||
// Commands | ||
OpenInExplorerCommand = new RelayCommand(OpenInExplorer); | ||
DeleteCommand = new RelayCommand(DeleteFile); | ||
CopyAbsolutePathCommand = new RelayCommand(CopyAbsolutePath); | ||
CopyPathCommand = new RelayCommand(CopyPath); | ||
} | ||
|
||
public void OpenInExplorer() | ||
{ | ||
Process.Start(new ProcessStartInfo(Parent.StorageFolderPath) { UseShellExecute = true }); | ||
} | ||
|
||
public void DeleteFile() | ||
{ | ||
System.IO.File.Delete(StorageFilePath); | ||
Parent.Children.Remove(this); | ||
} | ||
|
||
public override string? ValidateName(string input) | ||
{ | ||
if (input == Name) | ||
return Translation.Get("ProjectRenameErrorSameName"); | ||
|
||
if (Parent is null) | ||
return Translation.Get("ProjectRenameErrorParentNull"); | ||
|
||
var file = Parent.Children.FirstOrDefault(x => x.Name == input); | ||
if (file is not null) | ||
return Translation.Get("ProjectRenameErrorNameExists"); | ||
|
||
return null; | ||
} | ||
|
||
public override void RenameElement(string newName) | ||
{ | ||
var newPath = Path.Combine(Parent.StorageFolderPath, newName); | ||
|
||
System.IO.File.Move(StorageFilePath, newPath); | ||
StorageFilePath = newPath; | ||
|
||
Name = newName; | ||
|
||
RefreshSelf(); | ||
} | ||
|
||
public override void HandleDoubleClick() | ||
{ | ||
FileHandler.OpenFile(StorageFilePath); | ||
} | ||
|
||
public void CopyAbsolutePath() | ||
{ | ||
ApiVault.Get().GetMainWindow().Clipboard.SetTextAsync(StorageFilePath.Replace("\\", "/")); | ||
} | ||
|
||
public void CopyPath() | ||
{ | ||
var path = StorageFilePath.Replace(ProjectOpener.ProjectRootFolder.StorageFolderPath, ""); | ||
ApiVault.Get().GetMainWindow().Clipboard.SetTextAsync(path.Replace("\\", "/")); | ||
} | ||
} |
Oops, something went wrong.