mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Improved document load flow
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ZuneUIXTools.ViewModels
|
||||
@@ -28,5 +29,37 @@ namespace ZuneUIXTools.ViewModels
|
||||
get => _selectedDocument;
|
||||
set => SetProperty(ref _selectedDocument, value);
|
||||
}
|
||||
|
||||
public DocumentViewModelBase LoadDocument(string fileName, string fileFormat = null)
|
||||
{
|
||||
if (fileFormat == null)
|
||||
fileFormat = System.IO.Path.GetExtension(fileName);
|
||||
|
||||
DocumentViewModelBase doc = UIXDocuments.FirstOrDefault(oldDoc => fileName == oldDoc.FileName);
|
||||
if (doc != null)
|
||||
return doc;
|
||||
|
||||
if (fileFormat.EndsWith(".uix"))
|
||||
doc = new UIXDocumentViewModel(fileName);
|
||||
else if (fileFormat.EndsWith(".uib"))
|
||||
doc = new CompiledUIXDocumentViewModel(fileName);
|
||||
else
|
||||
throw new ArgumentException($"\"{fileName}\" is not a known format.");
|
||||
|
||||
UIXDocuments.Add(doc);
|
||||
return doc;
|
||||
}
|
||||
|
||||
public void UnloadDocument(string fileName)
|
||||
{
|
||||
DocumentViewModelBase doc = UIXDocuments.FirstOrDefault(oldDoc => fileName == oldDoc.FileName);
|
||||
if (doc != null)
|
||||
UIXDocuments.Remove(doc);
|
||||
}
|
||||
|
||||
public void UnloadDocument(DocumentViewModelBase doc)
|
||||
{
|
||||
UIXDocuments.Remove(doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user