From dca1c130ffba591879e59a87bff05800bd5b6c81 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sat, 24 Jul 2021 17:17:08 -0400 Subject: [PATCH] allow creating empty document without an Accessor being set --- .../MainWindow.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Libraries/UniversalEditor.UserInterface/MainWindow.cs b/Libraries/UniversalEditor.UserInterface/MainWindow.cs index bf1ecc72..b032fa1a 100644 --- a/Libraries/UniversalEditor.UserInterface/MainWindow.cs +++ b/Libraries/UniversalEditor.UserInterface/MainWindow.cs @@ -632,7 +632,7 @@ namespace UniversalEditor.UserInterface bool first = true; bool loaded = false; - if (doc.DataFormat == null) + if (doc.DataFormat == null && doc.Accessor != null) { Console.WriteLine("InitEditorPage: DataFormat unspecified for Document"); @@ -754,7 +754,7 @@ namespace UniversalEditor.UserInterface // OKAY WHY THE **** ARE WE OPENING THE SAME FILE TWICE??? - if (doc.ObjectModel != null) + if (doc.ObjectModel != null && doc.Accessor != null) { EditorReference[] editors = Common.Reflection.GetAvailableEditors(doc.ObjectModel.MakeReference()); Console.WriteLine("found {0} editors for object model {1}", editors.Length.ToString(), doc.ObjectModel.ToString()); @@ -855,10 +855,20 @@ namespace UniversalEditor.UserInterface OpenDefaultEditor(doc); } } + else if (doc.ObjectModel == null) + { + Console.Error.WriteLine("ObjectModel not specified for accessor " + doc.Accessor?.ToString() + " ; using default editor"); + OpenDefaultEditor(doc); + } else { - Console.Error.WriteLine("ObjectModel not specified for accessor " + doc.Accessor.ToString() + " ; using default editor"); - OpenDefaultEditor(doc); + EditorPage page = new EditorPage(); + page.Document = doc; + page.DocumentEdited += page_DocumentEdited; + + string filename = doc.Accessor?.GetFileName(); + if (filename == null) filename = doc.Title; + InitDocTab(filename, doc.Title, page); } }