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

View file

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

View file

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

View file

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

View file

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