diff --git a/CSharp/Libraries/UniversalEditor.Core/Accessor.cs b/CSharp/Libraries/UniversalEditor.Core/Accessor.cs index 3d73d7c6..81c2c66c 100644 --- a/CSharp/Libraries/UniversalEditor.Core/Accessor.cs +++ b/CSharp/Libraries/UniversalEditor.Core/Accessor.cs @@ -19,7 +19,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -using System; +using System; using System.Collections.Generic; using System.Linq; @@ -36,6 +36,19 @@ namespace UniversalEditor [DebuggerNonUserCode()] public abstract class Accessor : References { + protected bool Initialized { get; private set; } = false; + protected void Initialize() + { + if (Initialized) + return; + + InitializeInternal(); + Initialized = true; + } + protected virtual void InitializeInternal() + { + } + /// /// Creates or returns an existing object referring to this object. /// @@ -200,6 +213,13 @@ namespace UniversalEditor { get { return String.Empty; } } + + /// + /// Gets or sets the original URI. + /// + /// The original URI. + public Uri OriginalUri { get; set; } + /// /// Gets the file name without path information for this , if applicable. /// diff --git a/CSharp/Libraries/UniversalEditor.Core/AccessorReference.cs b/CSharp/Libraries/UniversalEditor.Core/AccessorReference.cs index 89e6d665..47a66b67 100644 --- a/CSharp/Libraries/UniversalEditor.Core/AccessorReference.cs +++ b/CSharp/Libraries/UniversalEditor.Core/AccessorReference.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.Linq; using System.Text; @@ -51,6 +52,8 @@ namespace UniversalEditor private string mvarTitle = String.Empty; public string Title { get { return mvarTitle; } set { mvarTitle = value; } } + + public StringCollection Schemas { get; } = new StringCollection(); /// /// Gets the detail fields that are shown in lists of this object in details view. diff --git a/CSharp/Libraries/UniversalEditor.Essential/Common/Reflection.cs b/CSharp/Libraries/UniversalEditor.Essential/Common/Reflection.cs index c83d95fe..232f8cfe 100644 --- a/CSharp/Libraries/UniversalEditor.Essential/Common/Reflection.cs +++ b/CSharp/Libraries/UniversalEditor.Essential/Common/Reflection.cs @@ -494,6 +494,23 @@ namespace UniversalEditor.Common if (mvarAvailableAccessors == null) Initialize(); return mvarAvailableAccessors; } + public static AccessorReference[] GetAvailableAccessors(string fileName) + { + AccessorReference[] accrefs = GetAvailableAccessors(); + List _list = new List(); + foreach (AccessorReference ar in accrefs) + { + foreach (string schema in ar.Schemas) + { + if (fileName.StartsWith(schema + "://")) + { + _list.Add(ar); + break; + } + } + } + return _list.ToArray(); + } #endregion #region Data Formats private static DataFormatReference[] mvarAvailableDataFormats = null; diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs b/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs index e784e284..56544035 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs +++ b/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs @@ -591,12 +591,23 @@ namespace UniversalEditor.UserInterface /// The file name(s) of the document(s) to load. public void OpenWindow(params string[] fileNames) { - Document[] documents = new Document[fileNames.Length]; + List loadedDocuments = new List(); for (int i = 0; i < fileNames.Length; i++) { - documents[i] = new Document(null, null, new FileAccessor(fileNames[i])); + AccessorReference[] accs = UniversalEditor.Common.Reflection.GetAvailableAccessors(fileNames[i]); + if (accs.Length > 0) + { + Accessor fa = accs[0].Create(); + fa.OriginalUri = new Uri(fileNames[i]); + Document document = new Document(fa); + loadedDocuments.Add(document); + } + else + { + Console.Error.WriteLine("ue: accessor not found for path " + fileNames[i]); + } } - OpenWindow(documents); + OpenWindow(loadedDocuments.ToArray()); } /// /// Opens a new window, optionally loading the specified documents. diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/MainWindow.cs b/CSharp/Libraries/UniversalEditor.UserInterface/MainWindow.cs index b462fb9f..ebaf8d2c 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/MainWindow.cs +++ b/CSharp/Libraries/UniversalEditor.UserInterface/MainWindow.cs @@ -543,8 +543,12 @@ namespace UniversalEditor.UserInterface Document[] documents = new Document[fileNames.Length]; for (int i = 0; i < documents.Length; i++) { - FileAccessor fa = new FileAccessor(fileNames[i]); - documents[i] = new Document(fa); + AccessorReference[] accs = UniversalEditor.Common.Reflection.GetAvailableAccessors(fileNames[i]); + if (accs.Length > 0) + { + Accessor fa = accs[0].Create(); + documents[i] = new Document(fa); + } } OpenFile(documents); }