From af360a0753cfb322482db7ed8d8c0c2e9557e6c6 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Tue, 13 Sep 2022 09:53:45 -0400 Subject: [PATCH] various stuff --- Libraries/UniversalEditor.Core/ObjectModel.cs | 2 +- .../UniversalEditor.UserInterface/Editor.cs | 3 +- .../Editors/Database/DatabaseEditor.cs | 17 ++- .../Dialogs/ColumnPropertiesDialog.cs | 8 ++ .../Editors/Database/Views/DesignView.cs | 21 ++- .../Editors/FileSystem/FileSystemEditor.cs | 9 +- .../Text/Formatted/FormattedTextEditor.cs | 125 ++++++++++++++++++ .../UniversalEditor.UserInterface.csproj | 2 + .../Associations/Merscom/Scene.uexml | 22 +++ .../DataFormats/Scene/SceneChunk.cs | 31 +++++ .../DataFormats/Scene/SceneChunkDataFormat.cs | 64 +++++++++ .../DataFormats/Scene/SceneDataFormat.cs | 45 +++++++ .../Scene/IntrinsicGraphics.uexml | 25 ++++ .../PropertyList/A3DA/A3DADataFormat.cs | 9 ++ 14 files changed, 373 insertions(+), 10 deletions(-) create mode 100644 Libraries/UniversalEditor.UserInterface/Editors/Text/Formatted/FormattedTextEditor.cs create mode 100644 Plugins/UniversalEditor.Plugins.Merscom/Associations/Merscom/Scene.uexml create mode 100644 Plugins/UniversalEditor.Plugins.Merscom/DataFormats/Scene/SceneChunk.cs create mode 100644 Plugins/UniversalEditor.Plugins.Merscom/DataFormats/Scene/SceneChunkDataFormat.cs create mode 100644 Plugins/UniversalEditor.Plugins.Merscom/DataFormats/Scene/SceneDataFormat.cs create mode 100644 Plugins/UniversalEditor.Plugins.Multimedia3D/Associations/Scene/IntrinsicGraphics.uexml diff --git a/Libraries/UniversalEditor.Core/ObjectModel.cs b/Libraries/UniversalEditor.Core/ObjectModel.cs index 073fd516..5b8a78f5 100644 --- a/Libraries/UniversalEditor.Core/ObjectModel.cs +++ b/Libraries/UniversalEditor.Core/ObjectModel.cs @@ -66,7 +66,7 @@ namespace UniversalEditor /// /// The accessor. [Obsolete("ObjectModels should be Accessor-agnostic and not rely on being able to communicate with the Accessor"), NonSerializedProperty] - public Accessor Accessor { get; internal set; } + public Accessor Accessor { get; set; } /// /// Clears all data from this and returns it to a pristine state. diff --git a/Libraries/UniversalEditor.UserInterface/Editor.cs b/Libraries/UniversalEditor.UserInterface/Editor.cs index 3ca9c77c..2240de87 100644 --- a/Libraries/UniversalEditor.UserInterface/Editor.cs +++ b/Libraries/UniversalEditor.UserInterface/Editor.cs @@ -856,7 +856,8 @@ namespace UniversalEditor.UserInterface DataFormatReference dfr = Document.DataFormat.MakeReference(); if (dfr.ExportOptions != null) { - list.Add(dfr.ExportOptions); + // FIXME + list.Add(dfr.ExportOptions.Clone(dfr.Title)); } } } diff --git a/Libraries/UniversalEditor.UserInterface/Editors/Database/DatabaseEditor.cs b/Libraries/UniversalEditor.UserInterface/Editors/Database/DatabaseEditor.cs index f35bd4f3..d1bc6e79 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/Database/DatabaseEditor.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/Database/DatabaseEditor.cs @@ -20,15 +20,10 @@ // along with this program. If not, see . using System; -using System.Collections.Generic; - using MBS.Framework.UserInterface; -using MBS.Framework.UserInterface.Controls; -using MBS.Framework.UserInterface.Dialogs; using MBS.Framework.UserInterface.Layouts; -using UniversalEditor.UserInterface.Editors.Database.Dialogs; using UniversalEditor.ObjectModels.Database; -using UniversalEditor.UserInterface; +using UniversalEditor.UserInterface.Editors.Database.Dialogs; namespace UniversalEditor.UserInterface.Editors.Database { @@ -161,10 +156,17 @@ namespace UniversalEditor.UserInterface.Editors.Database private void DatabaseEditor_ContextMenu_Columns_Add(object sender, EventArgs e) { + if (DesignView.Table == null) + return; + ColumnPropertiesDialog dlg = new ColumnPropertiesDialog(); if (dlg.ShowDialog() == DialogResult.OK) { + DatabaseField field = new DatabaseField(); + dlg.UpdateProperties(field); + DesignView.Table.Fields.Add(field); + DesignView.AddColumn(field.Name, field.DataType?.ToString(), false /*field.Required*/, false /*field.Identity*/, field.Value); } } @@ -200,6 +202,9 @@ namespace UniversalEditor.UserInterface.Editors.Database EndEdit(); + // FIXME: the node collection needs to notify the Document Explorer panel that a new item has been added + // we do this so many times in various places that there really should be a better way to connect these notifications + // perhaps a ListViewControl.Observe(ICollection) method ? EditorDocumentExplorerNode node = new EditorDocumentExplorerNode(dt.Name); node.SetExtraData("table", dt); DocumentExplorer.Nodes[0].Nodes.Add(node); diff --git a/Libraries/UniversalEditor.UserInterface/Editors/Database/Dialogs/ColumnPropertiesDialog.cs b/Libraries/UniversalEditor.UserInterface/Editors/Database/Dialogs/ColumnPropertiesDialog.cs index c658610d..c2bd0f57 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/Database/Dialogs/ColumnPropertiesDialog.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/Database/Dialogs/ColumnPropertiesDialog.cs @@ -21,6 +21,7 @@ using System; using MBS.Framework.UserInterface; using MBS.Framework.UserInterface.Controls; +using UniversalEditor.ObjectModels.Database; namespace UniversalEditor.UserInterface.Editors.Database.Dialogs { @@ -34,6 +35,13 @@ namespace UniversalEditor.UserInterface.Editors.Database.Dialogs private TextBox txtDescription; private GroupBox fraDataTypeSpecificProperties; + public void UpdateProperties(DatabaseField field) + { + field.Name = txtColumnName.Text; + // field.DataType = cboDataType.SelectedItem + // field.Description = txtDescription.Text; + } + protected override void OnCreated(EventArgs e) { base.OnCreated(e); diff --git a/Libraries/UniversalEditor.UserInterface/Editors/Database/Views/DesignView.cs b/Libraries/UniversalEditor.UserInterface/Editors/Database/Views/DesignView.cs index a2bebbd7..55b56369 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/Database/Views/DesignView.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/Database/Views/DesignView.cs @@ -78,7 +78,7 @@ namespace UniversalEditor.UserInterface.Editors.Database.Views ((ToolbarItemButton)tbColumns.Items["tsbColumnMoveDown"]).Click += tsbColumnMoveDown_Click; } - private void tsbColumnAdd_Click(object sender, EventArgs e) + public void AddColumn() { TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[] { @@ -92,6 +92,25 @@ namespace UniversalEditor.UserInterface.Editors.Database.Views tvColumns.Model.Rows.Add(row); tvColumns.Focus(row, tvColumns.Columns[0], tvColumns.Columns[0].Renderers[0], true); } + public void AddColumn(string name, string dataType, bool notNull, bool identity, object defaultValue) + { + TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[] + { + new TreeModelRowColumn(tvColumns.Model.Columns[0], name), // Name + new TreeModelRowColumn(tvColumns.Model.Columns[1], dataType), // Data type + new TreeModelRowColumn(tvColumns.Model.Columns[2], notNull), // Not null + new TreeModelRowColumn(tvColumns.Model.Columns[3], identity), // Identity + new TreeModelRowColumn(tvColumns.Model.Columns[4], defaultValue) // Default value + }); + + tvColumns.Model.Rows.Add(row); + tvColumns.Focus(row, tvColumns.Columns[0], tvColumns.Columns[0].Renderers[0], true); + } + + private void tsbColumnAdd_Click(object sender, EventArgs e) + { + AddColumn(); + } private void tsbColumnEdit_Click(object sender, EventArgs e) { } diff --git a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs index b6ed707a..5d747de6 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs @@ -1086,7 +1086,14 @@ namespace UniversalEditor.Editors.FileSystem File f = (fso as File); string filePath = System.IO.Path.Combine(new string[] { fileName, System.IO.Path.GetFileName(f.Name) }); - System.IO.File.WriteAllBytes(filePath, f.GetData()); + try + { + System.IO.File.WriteAllBytes(filePath, f.GetData()); + } + catch (System.IO.IOException ex) + { + // FIXME: should this be an error dialog, a warning in the messages list, or ignored? + } } else if (fso is Folder) { diff --git a/Libraries/UniversalEditor.UserInterface/Editors/Text/Formatted/FormattedTextEditor.cs b/Libraries/UniversalEditor.UserInterface/Editors/Text/Formatted/FormattedTextEditor.cs new file mode 100644 index 00000000..b0c23a6c --- /dev/null +++ b/Libraries/UniversalEditor.UserInterface/Editors/Text/Formatted/FormattedTextEditor.cs @@ -0,0 +1,125 @@ +// +// TextEditor.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2019 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; + +using UniversalEditor.ObjectModels.Text.Formatted; +using UniversalEditor.UserInterface; + +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Controls; +using MBS.Framework.UserInterface.Layouts; +using System.ComponentModel; + +namespace UniversalEditor.Editors.Text.Formatted +{ + public class FormattedTextEditor : TextEditor + { + protected override Selection CreateSelectionInternal(object content) + { + if (content is string) + { + txt.SelectedText = (string)content; + return new TextEditorSelection(this, (string)content); + } + return null; + } + public override void UpdateSelections() + { + Selections.Clear(); + Selections.Add(new TextEditorSelection(this, txt.SelectedText, txt.SelectionStart, txt.SelectionLength)); + } + private TextBox txt = null; + + internal override void ClearSelectedText() + { + txt.SelectedText = null; + } + + private static EditorReference _er = null; + public override EditorReference MakeReference () + { + if (_er == null) { + _er = base.MakeReference (); + _er.SupportedObjectModels.Add (typeof (FormattedTextObjectModel)); + } + return _er; + } + + bool working = false; + + private void txt_Changed(object sender, EventArgs e) + { + FormattedTextObjectModel om = (this.ObjectModel as FormattedTextObjectModel); + if (om == null) + return; + + if (!IsCreated) + return; + + if (!working) + { + if (!InEdit) + { + BeginEdit(); + } + + // om.Text = txt.Text; + txt.ResetChangedByUser(); + + OnDocumentEdited(EventArgs.Empty); + } + } + + protected override void OnObjectModelSaving(CancelEventArgs e) + { + base.OnObjectModelSaving(e); + + if (InEdit) + EndEdit(); + } + + public FormattedTextEditor () + { + txt = new TextBox(); + txt.Changed += txt_Changed; + txt.Multiline = true; + + this.Layout = new BoxLayout(Orientation.Vertical); + this.Controls.Add(txt, new BoxLayout.Constraints(true, true)); + } + + protected override void OnObjectModelChanged(EventArgs e) + { + base.OnObjectModelChanged(e); + + working = true; + txt.Text = String.Empty; + working = false; + + FormattedTextObjectModel om = (this.ObjectModel as FormattedTextObjectModel); + if (om == null) return; + + working = true; + // txt.Text = om.Text; + working = false; + } + } +} diff --git a/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj b/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj index f096e467..e85bedeb 100644 --- a/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj +++ b/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj @@ -140,6 +140,7 @@ + @@ -199,6 +200,7 @@ + diff --git a/Plugins/UniversalEditor.Plugins.Merscom/Associations/Merscom/Scene.uexml b/Plugins/UniversalEditor.Plugins.Merscom/Associations/Merscom/Scene.uexml new file mode 100644 index 00000000..55fdbfa4 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Merscom/Associations/Merscom/Scene.uexml @@ -0,0 +1,22 @@ + + + + + + + + *.op + *.vhs + *.vob + + + + + + + + + + + + diff --git a/Plugins/UniversalEditor.Plugins.Merscom/DataFormats/Scene/SceneChunk.cs b/Plugins/UniversalEditor.Plugins.Merscom/DataFormats/Scene/SceneChunk.cs new file mode 100644 index 00000000..e2715ab0 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Merscom/DataFormats/Scene/SceneChunk.cs @@ -0,0 +1,31 @@ +// +// SceneChunk.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using UniversalEditor.ObjectModels.Chunked; + +namespace UniversalEditor.Plugins.Merscom.DataFormats.Scene +{ + public class SceneChunk : RIFFGroupChunk + { + public string Name { get; set; } + public byte[] Data { get; set; } + } +} diff --git a/Plugins/UniversalEditor.Plugins.Merscom/DataFormats/Scene/SceneChunkDataFormat.cs b/Plugins/UniversalEditor.Plugins.Merscom/DataFormats/Scene/SceneChunkDataFormat.cs new file mode 100644 index 00000000..f5116b43 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Merscom/DataFormats/Scene/SceneChunkDataFormat.cs @@ -0,0 +1,64 @@ +// +// SceneChunkDataFormat.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using UniversalEditor.ObjectModels.Chunked; + +namespace UniversalEditor.Plugins.Merscom.DataFormats.Scene +{ + /// + /// ChunkedObjectModel implementation of scene base data format. + /// + public class SceneChunkDataFormat : DataFormat + { + protected override void LoadInternal(ref ObjectModel objectModel) + { + ChunkedObjectModel chunked = (objectModel as ChunkedObjectModel); + + while (!Accessor.Reader.EndOfStream) + { + RIFFChunk chunk = ReadChunk(Accessor.Reader); + } + } + + private RIFFChunk ReadChunk(IO.Reader reader) + { + RIFFChunk chunk = null; + string chunkID = reader.ReadFixedLengthString(4); + uint preambleLength = reader.ReadUInt32(); + uint totalChunkSize = reader.ReadUInt32(); + + uint unknown1 = reader.ReadUInt32(); // offset to floats + uint dataLength = reader.ReadUInt32(); + + byte[] data = reader.ReadBytes(dataLength); + + chunk = new SceneChunk(); + ((SceneChunk)chunk).ID = chunkID; + ((SceneChunk)chunk).Data = data; + return chunk; + } + + protected override void SaveInternal(ObjectModel objectModel) + { + ChunkedObjectModel chunked = (objectModel as ChunkedObjectModel); + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.Merscom/DataFormats/Scene/SceneDataFormat.cs b/Plugins/UniversalEditor.Plugins.Merscom/DataFormats/Scene/SceneDataFormat.cs new file mode 100644 index 00000000..a8936f1f --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Merscom/DataFormats/Scene/SceneDataFormat.cs @@ -0,0 +1,45 @@ +// +// SceneDataFormat.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using System.Collections.Generic; +using UniversalEditor.DataFormats.Chunked.RIFF; +using UniversalEditor.ObjectModels.Chunked; + +namespace UniversalEditor.Plugins.Merscom.DataFormats.Scene +{ + public class SceneDataFormat : SceneChunkDataFormat + { + protected override void BeforeLoadInternal(Stack objectModels) + { + base.BeforeLoadInternal(objectModels); + + ChunkedObjectModel chunked = new ChunkedObjectModel(); + objectModels.Push(chunked); + } + protected override void AfterLoadInternal(Stack objectModels) + { + base.AfterLoadInternal(objectModels); + + ChunkedObjectModel chunked = (objectModels.Pop() as ChunkedObjectModel); + + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.Multimedia3D/Associations/Scene/IntrinsicGraphics.uexml b/Plugins/UniversalEditor.Plugins.Multimedia3D/Associations/Scene/IntrinsicGraphics.uexml new file mode 100644 index 00000000..1063c0e5 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Multimedia3D/Associations/Scene/IntrinsicGraphics.uexml @@ -0,0 +1,25 @@ + + + + + + + + *.igb + + + + DAFA + + + + + + + + + + + + + diff --git a/Plugins/UniversalEditor.Plugins.Sega/DataFormats/PropertyList/A3DA/A3DADataFormat.cs b/Plugins/UniversalEditor.Plugins.Sega/DataFormats/PropertyList/A3DA/A3DADataFormat.cs index 34d786eb..15605832 100644 --- a/Plugins/UniversalEditor.Plugins.Sega/DataFormats/PropertyList/A3DA/A3DADataFormat.cs +++ b/Plugins/UniversalEditor.Plugins.Sega/DataFormats/PropertyList/A3DA/A3DADataFormat.cs @@ -53,6 +53,8 @@ namespace UniversalEditor.Plugins.Sega.DataFormats.PropertyList.A3DA if (signature != "#A3DA__________") throw new InvalidDataFormatException("File does not begin with '#A3DA__________'"); + long lastreadpos = reader.Accessor.Position; + while (!reader.EndOfStream) { string line = reader.ReadLine(); @@ -61,7 +63,14 @@ namespace UniversalEditor.Plugins.Sega.DataFormats.PropertyList.A3DA line = line.Substring(0, line.IndexOf('#')); if (String.IsNullOrEmpty(line)) + { + if (lastreadpos == reader.Accessor.Position) + { + // exit out of infinite loop + return; + } continue; + } string[] values = line.Split(new char[] { '=' }, 2); string key = values[0];