|
@@ -1,5 +1,6 @@
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Windows.Input;
|
|
using System.Windows.Input;
|
|
|
|
+using System.Windows.Shapes;
|
|
using ChunkyImageLib;
|
|
using ChunkyImageLib;
|
|
using ChunkyImageLib.DataHolders;
|
|
using ChunkyImageLib.DataHolders;
|
|
using Microsoft.Win32;
|
|
using Microsoft.Win32;
|
|
@@ -59,84 +60,92 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Generates new Layer and sets it as active one.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="parameter">CommandParameter.</param>
|
|
|
|
- [Command.Basic("PixiEditor.File.New", "New image", "Create new image", Key = Key.N, Modifiers = ModifierKeys.Control)]
|
|
|
|
- public void OpenNewFilePopup()
|
|
|
|
|
|
+ private void OpenHelloTherePopup()
|
|
{
|
|
{
|
|
- NewFileDialog newFile = new NewFileDialog();
|
|
|
|
- if (newFile.ShowDialog())
|
|
|
|
- {
|
|
|
|
- NewDocument(b => b
|
|
|
|
- .WithSize(newFile.Width,newFile.Height)
|
|
|
|
- .WithLayer(l => l
|
|
|
|
- .WithName("Base Layer")
|
|
|
|
- .WithSurface(new Surface(new VecI(newFile.Width, newFile.Height)))));
|
|
|
|
- }
|
|
|
|
|
|
+ new HelloTherePopup(this).Show();
|
|
}
|
|
}
|
|
|
|
|
|
- public void OpenHelloTherePopup()
|
|
|
|
|
|
+ private void Owner_OnStartupEvent(object sender, System.EventArgs e)
|
|
{
|
|
{
|
|
- new HelloTherePopup(this).Show();
|
|
|
|
|
|
+ List<string> args = StartupArgs.Args;
|
|
|
|
+ string file = args.FirstOrDefault(x => Importer.IsSupportedFile(x) && File.Exists(x));
|
|
|
|
+ if (file != null)
|
|
|
|
+ {
|
|
|
|
+ OpenFromPath(file);
|
|
|
|
+ }
|
|
|
|
+ else if ((Owner.DocumentManagerSubViewModel.Documents.Count == 0
|
|
|
|
+ || !args.Contains("--crash")) && !args.Contains("--openedInExisting"))
|
|
|
|
+ {
|
|
|
|
+ if (IPreferences.Current.GetPreference("ShowStartupWindow", true))
|
|
|
|
+ {
|
|
|
|
+ OpenHelloTherePopup();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- public DocumentViewModel NewDocument(Action<DocumentViewModelBuilder> builder)
|
|
|
|
|
|
+ [Command.Internal("PixiEditor.File.OpenRecent")]
|
|
|
|
+ public void OpenRecent(object parameter)
|
|
{
|
|
{
|
|
- var doc = DocumentViewModel.Build(builder);
|
|
|
|
-
|
|
|
|
- doc.MarkAsSaved();
|
|
|
|
- Owner.DocumentManagerSubViewModel.Documents.Add(doc);
|
|
|
|
- Owner.WindowSubViewModel.CreateNewViewport(doc);
|
|
|
|
- Owner.WindowSubViewModel.MakeDocumentViewportActive(doc);
|
|
|
|
|
|
+ string path = (string)parameter;
|
|
|
|
+ if (!File.Exists(path))
|
|
|
|
+ {
|
|
|
|
+ NoticeDialog.Show("The file does not exist", "Failed to open the file");
|
|
|
|
+ RecentlyOpened.Remove(path);
|
|
|
|
+ IPreferences.Current.UpdateLocalPreference("RecentlyOpened", RecentlyOpened.Select(x => x.FilePath));
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- return doc;
|
|
|
|
|
|
+ OpenFromPath(path);
|
|
}
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Opens file from path.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="path">Path to file.</param>
|
|
|
|
- public void OpenFile(string path)
|
|
|
|
|
|
+ [Command.Basic("PixiEditor.File.Open", "Open", "Open file", Key = Key.O, Modifiers = ModifierKeys.Control)]
|
|
|
|
+ public void OpenFromOpenFileDialog()
|
|
{
|
|
{
|
|
- ImportFileDialog dialog = new ImportFileDialog();
|
|
|
|
|
|
+ string filter = SupportedFilesHelper.BuildOpenFilter();
|
|
|
|
|
|
- if (path != null && File.Exists(path))
|
|
|
|
|
|
+ OpenFileDialog dialog = new OpenFileDialog
|
|
{
|
|
{
|
|
- dialog.FilePath = path;
|
|
|
|
- }
|
|
|
|
|
|
+ Filter = filter,
|
|
|
|
+ FilterIndex = 0
|
|
|
|
+ };
|
|
|
|
|
|
- if (dialog.ShowDialog())
|
|
|
|
|
|
+ if (!(bool)dialog.ShowDialog() || !Importer.IsSupportedFile(dialog.FileName))
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ OpenFromPath(dialog.FileName);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private bool MakeExistingDocumentActiveIfOpened(string path)
|
|
|
|
+ {
|
|
|
|
+ foreach (DocumentViewModel document in Owner.DocumentManagerSubViewModel.Documents)
|
|
{
|
|
{
|
|
- DocumentViewModel doc = NewDocument(b => b
|
|
|
|
- .WithSize(dialog.FileWidth, dialog.FileHeight)
|
|
|
|
- .WithLayer(l => l
|
|
|
|
- .WithName("Image")
|
|
|
|
- .WithSize(dialog.FileWidth, dialog.FileHeight)
|
|
|
|
- .WithSurface(Importer.ImportImage(dialog.FilePath, new VecI(dialog.FileWidth, dialog.FileHeight)))));
|
|
|
|
- doc.FullFilePath = path;
|
|
|
|
|
|
+ if (document.FullFilePath is not null && System.IO.Path.GetFullPath(document.FullFilePath) == System.IO.Path.GetFullPath(path))
|
|
|
|
+ {
|
|
|
|
+ Owner.WindowSubViewModel.MakeDocumentViewportActive(document);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
- [Command.Basic("PixiEditor.File.Open", "Open", "Open file", Key = Key.O, Modifiers = ModifierKeys.Control)]
|
|
|
|
- public void Open(string path)
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Tries to open the passed file if it isn't already open
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="path"></param>
|
|
|
|
+ public void OpenFromPath(string path)
|
|
{
|
|
{
|
|
- if (path == null)
|
|
|
|
- {
|
|
|
|
- Open();
|
|
|
|
|
|
+ if (MakeExistingDocumentActiveIfOpened(path))
|
|
return;
|
|
return;
|
|
- }
|
|
|
|
|
|
|
|
try
|
|
try
|
|
{
|
|
{
|
|
if (path.EndsWith(".pixi"))
|
|
if (path.EndsWith(".pixi"))
|
|
{
|
|
{
|
|
- OpenDocument(path);
|
|
|
|
|
|
+ OpenDotPixi(path);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- OpenFile(path);
|
|
|
|
|
|
+ OpenRegularImage(path);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (CorruptedFileException ex)
|
|
catch (CorruptedFileException ex)
|
|
@@ -149,88 +158,75 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void Owner_OnStartupEvent(object sender, System.EventArgs e)
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Opens a .pixi file from path, creates a document from it, and adds it to the system
|
|
|
|
+ /// </summary>
|
|
|
|
+ private void OpenDotPixi(string path)
|
|
{
|
|
{
|
|
- List<string> args = StartupArgs.Args;
|
|
|
|
- string file = args.FirstOrDefault(x => Importer.IsSupportedFile(x) && File.Exists(x));
|
|
|
|
- if (file != null)
|
|
|
|
- {
|
|
|
|
- Open(file);
|
|
|
|
- }
|
|
|
|
- else if ((Owner.DocumentManagerSubViewModel.Documents.Count == 0
|
|
|
|
- || !args.Contains("--crash")) && !args.Contains("--openedInExisting"))
|
|
|
|
- {
|
|
|
|
- if (IPreferences.Current.GetPreference("ShowStartupWindow", true))
|
|
|
|
- {
|
|
|
|
- OpenHelloTherePopup();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ DocumentViewModel document = Importer.ImportDocument(path);
|
|
|
|
+ AddDocumentViewModelToTheSystem(document);
|
|
}
|
|
}
|
|
|
|
|
|
- [Command.Internal("PixiEditor.File.OpenRecent")]
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Opens a .pixi file from path, creates a document from it, and adds it to the system
|
|
|
|
+ /// </summary>
|
|
|
|
+ public void OpenRecoveredDotPixi(string? originalPath, byte[] dotPixiBytes)
|
|
|
|
+ {
|
|
|
|
+ DocumentViewModel document = Importer.ImportDocument(dotPixiBytes, originalPath);
|
|
|
|
+ document.MarkAsUnsaved();
|
|
|
|
+ AddDocumentViewModelToTheSystem(document);
|
|
|
|
+ }
|
|
|
|
|
|
- public void OpenRecent(object parameter)
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Opens a regular image file from path, creates a document from it, and adds it to the system.
|
|
|
|
+ /// </summary>
|
|
|
|
+ private void OpenRegularImage(string path)
|
|
{
|
|
{
|
|
- string path = (string)parameter;
|
|
|
|
|
|
+ ImportFileDialog dialog = new ImportFileDialog();
|
|
|
|
|
|
- foreach (DocumentViewModel document in Owner.DocumentManagerSubViewModel.Documents)
|
|
|
|
|
|
+ if (path != null && File.Exists(path))
|
|
{
|
|
{
|
|
- if (document.FullFilePath is not null && document.FullFilePath == path)
|
|
|
|
- {
|
|
|
|
- Owner.WindowSubViewModel.MakeDocumentViewportActive(document);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ dialog.FilePath = path;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!File.Exists(path))
|
|
|
|
|
|
+ if (dialog.ShowDialog())
|
|
{
|
|
{
|
|
- NoticeDialog.Show("The file does not exist", "Failed to open the file");
|
|
|
|
- RecentlyOpened.Remove(path);
|
|
|
|
- IPreferences.Current.UpdateLocalPreference("RecentlyOpened", RecentlyOpened.Select(x => x.FilePath));
|
|
|
|
- return;
|
|
|
|
|
|
+ DocumentViewModel doc = NewDocument(b => b
|
|
|
|
+ .WithSize(dialog.FileWidth, dialog.FileHeight)
|
|
|
|
+ .WithLayer(l => l
|
|
|
|
+ .WithName("Image")
|
|
|
|
+ .WithSize(dialog.FileWidth, dialog.FileHeight)
|
|
|
|
+ .WithSurface(Importer.ImportImage(dialog.FilePath, new VecI(dialog.FileWidth, dialog.FileHeight)))));
|
|
|
|
+ doc.FullFilePath = path;
|
|
}
|
|
}
|
|
-
|
|
|
|
- Open((string)parameter);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- public void Open()
|
|
|
|
|
|
+ [Command.Basic("PixiEditor.File.New", "New image", "Create new image", Key = Key.N, Modifiers = ModifierKeys.Control)]
|
|
|
|
+ public void CreateFromNewFileDialog()
|
|
{
|
|
{
|
|
- string filter = SupportedFilesHelper.BuildOpenFilter();
|
|
|
|
-
|
|
|
|
- OpenFileDialog dialog = new OpenFileDialog
|
|
|
|
- {
|
|
|
|
- Filter = filter,
|
|
|
|
- FilterIndex = 0
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- if ((bool)dialog.ShowDialog())
|
|
|
|
|
|
+ NewFileDialog newFile = new NewFileDialog();
|
|
|
|
+ if (newFile.ShowDialog())
|
|
{
|
|
{
|
|
- if (Importer.IsSupportedFile(dialog.FileName))
|
|
|
|
- {
|
|
|
|
- Open(dialog.FileName);
|
|
|
|
-
|
|
|
|
- if (Owner.DocumentManagerSubViewModel.Documents.Count > 0)
|
|
|
|
- {
|
|
|
|
- Owner.WindowSubViewModel.MakeDocumentViewportActive(Owner.DocumentManagerSubViewModel.Documents[^1]);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ NewDocument(b => b
|
|
|
|
+ .WithSize(newFile.Width, newFile.Height)
|
|
|
|
+ .WithLayer(l => l
|
|
|
|
+ .WithName("Base Layer")
|
|
|
|
+ .WithSurface(new Surface(new VecI(newFile.Width, newFile.Height)))));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void OpenDocument(string path)
|
|
|
|
|
|
+ private DocumentViewModel NewDocument(Action<DocumentViewModelBuilder> builder)
|
|
{
|
|
{
|
|
- DocumentViewModel document = Importer.ImportDocument(path);
|
|
|
|
- DocumentManagerViewModel manager = Owner.DocumentManagerSubViewModel;
|
|
|
|
- if (manager.Documents.Select(x => x.FullFilePath).All(y => y != path))
|
|
|
|
- {
|
|
|
|
- manager.Documents.Add(document);
|
|
|
|
- Owner.WindowSubViewModel.CreateNewViewport(document);
|
|
|
|
- Owner.WindowSubViewModel.MakeDocumentViewportActive(document);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- Owner.WindowSubViewModel.MakeDocumentViewportActive(manager.Documents.First(y => y.FullFilePath == path));
|
|
|
|
- }
|
|
|
|
|
|
+ var doc = DocumentViewModel.Build(builder);
|
|
|
|
+ AddDocumentViewModelToTheSystem(doc);
|
|
|
|
+ return doc;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void AddDocumentViewModelToTheSystem(DocumentViewModel doc)
|
|
|
|
+ {
|
|
|
|
+ Owner.DocumentManagerSubViewModel.Documents.Add(doc);
|
|
|
|
+ Owner.WindowSubViewModel.CreateNewViewport(doc);
|
|
|
|
+ Owner.WindowSubViewModel.MakeDocumentViewportActive(doc);
|
|
}
|
|
}
|
|
|
|
|
|
[Command.Basic("PixiEditor.File.Save", false, "Save", "Save image", CanExecute = "PixiEditor.HasDocument", Key = Key.S, Modifiers = ModifierKeys.Control, IconPath = "Save.png")]
|
|
[Command.Basic("PixiEditor.File.Save", false, "Save", "Save image", CanExecute = "PixiEditor.HasDocument", Key = Key.S, Modifiers = ModifierKeys.Control, IconPath = "Save.png")]
|
|
@@ -257,9 +253,9 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
success = path != null;
|
|
success = path != null;
|
|
}
|
|
}
|
|
|
|
|
|
- document.FullFilePath = path;
|
|
|
|
if (success)
|
|
if (success)
|
|
{
|
|
{
|
|
|
|
+ document.FullFilePath = path;
|
|
document.MarkAsSaved();
|
|
document.MarkAsSaved();
|
|
}
|
|
}
|
|
|
|
|