1
0
mirror of synced 2024-11-28 01:10:51 +01:00

Cleanup how archive files update for layout editor

This commit is contained in:
KillzXGaming 2020-02-12 17:50:10 -05:00
parent a89f22042e
commit 2138a4b954
5 changed files with 15 additions and 17 deletions

View File

@ -16,8 +16,7 @@ using System.ComponentModel;
namespace LayoutBXLYT.Cafe namespace LayoutBXLYT.Cafe
{ {
public class BFLYT : IFileFormat, IEditorForm<LayoutEditor>, public class BFLYT : IFileFormat, IEditorForm<LayoutEditor>, IConvertableTextFormat
IEditorFormParameters, IConvertableTextFormat
{ {
public FileType FileType { get; set; } = FileType.Layout; public FileType FileType { get; set; } = FileType.Layout;
@ -28,9 +27,6 @@ namespace LayoutBXLYT.Cafe
public string FilePath { get; set; } public string FilePath { get; set; }
public IFileInfo IFileInfo { get; set; } public IFileInfo IFileInfo { get; set; }
public bool KeepOpen { get; } = true;
public EventHandler OnSave { get; set; }
public bool Identify(System.IO.Stream stream) public bool Identify(System.IO.Stream stream)
{ {
using (var reader = new Toolbox.Library.IO.FileReader(stream, true)) using (var reader = new Toolbox.Library.IO.FileReader(stream, true))

View File

@ -17,8 +17,10 @@ using LayoutBXLYT.Cafe;
namespace LayoutBXLYT namespace LayoutBXLYT
{ {
public partial class LayoutEditor : Form public partial class LayoutEditor : Form, IArchiveEditor
{ {
public EventHandler UpdateArchiveFile { get; set; } = null;
/// <summary> /// <summary>
/// Enables or disables legacy opengl support /// Enables or disables legacy opengl support
/// Modern support is not quite finished yet so keep enabled! /// Modern support is not quite finished yet so keep enabled!
@ -864,9 +866,7 @@ namespace LayoutBXLYT
if (fileFormat.IFileInfo != null && if (fileFormat.IFileInfo != null &&
fileFormat.IFileInfo.ArchiveParent != null && !ForceDialog) fileFormat.IFileInfo.ArchiveParent != null && !ForceDialog)
{ {
if (fileFormat is IEditorFormParameters) UpdateArchiveFile?.Invoke(fileFormat, new EventArgs());
((IEditorFormParameters)fileFormat).OnSave.Invoke(fileFormat, new EventArgs());
MessageBox.Show($"Saved {fileFormat.FileName} to archive!"); MessageBox.Show($"Saved {fileFormat.FileName} to archive!");
} }
else else

View File

@ -213,6 +213,10 @@ namespace Toolbox.Library
{ {
if (FileDataStream != null) if (FileDataStream != null)
{ {
Console.WriteLine($"Updating FileDataStream " + (FileDataStream is FileStream));
if (FileDataStream is FileStream)
FileDataStream.Close();
var mem = new System.IO.MemoryStream(); var mem = new System.IO.MemoryStream();
FileFormat.Save(mem); FileFormat.Save(mem);
FileDataStream = mem; FileDataStream = mem;
@ -1038,10 +1042,9 @@ namespace Toolbox.Library
{ {
activeForm = GetEditorForm(fileFormat); activeForm = GetEditorForm(fileFormat);
activeForm.Text = (((IFileFormat)fileFormat).FileName); activeForm.Text = (((IFileFormat)fileFormat).FileName);
if (fileFormat is IEditorFormParameters) if (activeForm is IArchiveEditor)
{ ((IArchiveEditor)activeForm).UpdateArchiveFile += OnFormSaved;
((IEditorFormParameters)fileFormat).OnSave += OnFormSaved;
}
activeForm.Show(); activeForm.Show();
} }
} }

View File

@ -6,9 +6,8 @@ using System.Threading.Tasks;
namespace Toolbox.Library namespace Toolbox.Library
{ {
public interface IEditorFormParameters public interface IArchiveEditor
{ {
bool KeepOpen { get; } EventHandler UpdateArchiveFile { get; set; }
EventHandler OnSave { get; set; }
} }
} }

View File

@ -394,12 +394,12 @@
<Compile Include="Helpers\DirectoryHelper.cs" /> <Compile Include="Helpers\DirectoryHelper.cs" />
<Compile Include="Helpers\DragHelper.cs" /> <Compile Include="Helpers\DragHelper.cs" />
<Compile Include="Imaging\BitmapFont.cs" /> <Compile Include="Imaging\BitmapFont.cs" />
<Compile Include="Interfaces\FileFormatting\IFormEditorParameters.cs" />
<Compile Include="Interfaces\FileFormatting\ILeaveOpenOnLoad.cs" /> <Compile Include="Interfaces\FileFormatting\ILeaveOpenOnLoad.cs" />
<Compile Include="Interfaces\FileFormatting\IPropertyContainer.cs" /> <Compile Include="Interfaces\FileFormatting\IPropertyContainer.cs" />
<Compile Include="Interfaces\FileFormatting\ISaveOpenedFileStream.cs" /> <Compile Include="Interfaces\FileFormatting\ISaveOpenedFileStream.cs" />
<Compile Include="Interfaces\Forms\IEditorForm.cs" /> <Compile Include="Interfaces\Forms\IEditorForm.cs" />
<Compile Include="Interfaces\IAnimationContainer.cs" /> <Compile Include="Interfaces\IAnimationContainer.cs" />
<Compile Include="Interfaces\Forms\IArchiveEditor.cs" />
<Compile Include="Interfaces\IArchiveQuickAccess.cs" /> <Compile Include="Interfaces\IArchiveQuickAccess.cs" />
<Compile Include="Interfaces\IMainForm.cs" /> <Compile Include="Interfaces\IMainForm.cs" />
<Compile Include="Interfaces\IMdiContainer.cs" /> <Compile Include="Interfaces\IMdiContainer.cs" />