|
@@ -1,21 +1,10 @@
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Diagnostics;
|
|
|
-using System.IO;
|
|
|
-using System.Linq;
|
|
|
-using System.Reflection;
|
|
|
-using System.Threading.Tasks;
|
|
|
-using Avalonia;
|
|
|
+using Avalonia;
|
|
|
using Avalonia.Controls;
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
|
using Avalonia.Input;
|
|
|
using Avalonia.Platform.Storage;
|
|
|
using Avalonia.Threading;
|
|
|
-using ChunkyImageLib;
|
|
|
-using Newtonsoft.Json.Linq;
|
|
|
-using PixiEditor.ChangeableDocument.Changeables.Graph;
|
|
|
-using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
|
|
|
using Drawie.Backend.Core;
|
|
|
-using Drawie.Backend.Core.Numerics;
|
|
|
using Drawie.Backend.Core.Surfaces.ImageData;
|
|
|
using PixiEditor.Exceptions;
|
|
|
using PixiEditor.Extensions.Common.Localization;
|
|
@@ -30,9 +19,10 @@ using PixiEditor.Models.Files;
|
|
|
using PixiEditor.Models.IO;
|
|
|
using PixiEditor.Models.UserData;
|
|
|
using Drawie.Numerics;
|
|
|
+using Microsoft.Extensions.DependencyInjection;
|
|
|
+using PixiEditor.Models.IO.CustomDocumentFormats;
|
|
|
using PixiEditor.OperatingSystem;
|
|
|
using PixiEditor.Parser;
|
|
|
-using PixiEditor.Parser.Graph;
|
|
|
using PixiEditor.UI.Common.Fonts;
|
|
|
using PixiEditor.ViewModels.Document;
|
|
|
using PixiEditor.Views;
|
|
@@ -57,6 +47,9 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
|
}
|
|
|
|
|
|
public RecentlyOpenedCollection RecentlyOpened { get; init; }
|
|
|
+ public IReadOnlyList<IDocumentBuilder> DocumentBuilders => documentBuilders;
|
|
|
+
|
|
|
+ private List<IDocumentBuilder> documentBuilders;
|
|
|
|
|
|
public FileViewModel(ViewModelMain owner)
|
|
|
: base(owner)
|
|
@@ -70,6 +63,7 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
|
}
|
|
|
|
|
|
PixiEditorSettings.File.MaxOpenedRecently.ValueChanged += (_, value) => UpdateMaxRecentlyOpened(value);
|
|
|
+ documentBuilders = owner.Services.GetServices<IDocumentBuilder>().ToList();
|
|
|
}
|
|
|
|
|
|
public void AddRecentlyOpened(string path)
|
|
@@ -209,6 +203,10 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
|
{
|
|
|
OpenDotPixi(path, associatePath);
|
|
|
}
|
|
|
+ else if (IsCustomFormat(path))
|
|
|
+ {
|
|
|
+ OpenCustomFormat(path);
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
OpenRegularImage(path, associatePath);
|
|
@@ -223,6 +221,27 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
|
NoticeDialog.Show("OLD_FILE_FORMAT_DESCRIPTION", "OLD_FILE_FORMAT");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private bool IsCustomFormat(string path)
|
|
|
+ {
|
|
|
+ string extension = Path.GetExtension(path);
|
|
|
+ return documentBuilders.Any(x => x.Extensions.Contains(extension, StringComparer.OrdinalIgnoreCase));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OpenCustomFormat(string path)
|
|
|
+ {
|
|
|
+ IDocumentBuilder builder = documentBuilders.First(x => x.Extensions.Contains(Path.GetExtension(path), StringComparer.OrdinalIgnoreCase));
|
|
|
+
|
|
|
+ if(!File.Exists(path))
|
|
|
+ {
|
|
|
+ NoticeDialog.Show("FILE_NOT_FOUND", "FAILED_TO_OPEN_FILE");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ DocumentViewModel document = DocumentViewModel.Build(docBuilder => builder.Build(docBuilder, path));
|
|
|
+ AddDocumentViewModelToTheSystem(document);
|
|
|
+ AddRecentlyOpened(document.FullFilePath);
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// Opens a .pixi file from path, creates a document from it, and adds it to the system
|