diff --git a/Libraries/UniversalEditor.UserInterface/Engine.cs b/Libraries/UniversalEditor.UserInterface/Engine.cs index ac2c072a..eccea01b 100644 --- a/Libraries/UniversalEditor.UserInterface/Engine.cs +++ b/Libraries/UniversalEditor.UserInterface/Engine.cs @@ -208,28 +208,13 @@ namespace UniversalEditor.UserInterface void Application_Activated(object sender, ApplicationActivatedEventArgs e) { - Document[] docs = new Document[e.CommandLine.FileNames.Count]; - if (e.CommandLine.FileNames.Count > 0) - { - for (int i = 0; i < e.CommandLine.FileNames.Count; i++) - { - if (String.IsNullOrEmpty(e.CommandLine.FileNames[i])) - { - Console.WriteLine("ue: warning: ignoring empty file name passed to command line"); - continue; - } - - docs[i] = new Document(new FileAccessor(e.CommandLine.FileNames[i])); - } - } - if (LastWindow != null) { - LastWindow.OpenFile(docs); + LastWindow.OpenFile(e.CommandLine.FileNames.ToArray()); } else { - OpenWindow(docs); + OpenWindow(e.CommandLine.FileNames.ToArray()); } List commandsToExecute = (Application.CommandLine.Options.GetValueOrDefault>("command", null)); @@ -287,22 +272,6 @@ namespace UniversalEditor.UserInterface // Glue.Common.Methods.SendApplicationEvent(new Glue.ApplicationEventEventArgs(Glue.Common.Constants.EventNames.ApplicationStop)); } - /// - /// Opens a new window, optionally loading the specified documents. - /// - /// The document model(s) of the document(s) to load. - /// An representing the window that was created. - protected IHostApplicationWindow OpenWindowInternal (params Document[] documents) - { - MainWindow mw = new MainWindow (); - LastWindow = mw; - if (documents.Length > 0) - { - mw.OpenFile(documents); - } - mw.Show (); - return mw; - } public void ShowAboutDialog (DataFormatReference dfr) { if (dfr == null) @@ -752,13 +721,12 @@ namespace UniversalEditor.UserInterface } } - private IHostApplicationWindowCollection mvarWindows = new IHostApplicationWindowCollection(); - public IHostApplicationWindowCollection Windows { get { return mvarWindows; } } + public IHostApplicationWindowCollection Windows { get; } = new IHostApplicationWindowCollection(); public void CloseAllWindows() { List windowsToClose = new List(); - foreach (IHostApplicationWindow window in mvarWindows) + foreach (IHostApplicationWindow window in Windows) { windowsToClose.Add(window); } @@ -830,7 +798,6 @@ namespace UniversalEditor.UserInterface { MainWindow mw = new MainWindow(); mw.Show(); - // OpenWindow(new Document[0]); } /// /// Opens a new window, optionally loading the specified documents. @@ -838,24 +805,10 @@ namespace UniversalEditor.UserInterface /// The file name(s) of the document(s) to load. public void OpenWindow(params string[] fileNames) { - List loadedDocuments = new List(); - for (int i = 0; i < fileNames.Length; 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] + "; assuming local file"); - loadedDocuments.Add(new Document(new FileAccessor(fileNames[i]))); - } - } - OpenWindow(loadedDocuments.ToArray()); + MainWindow mw = new MainWindow(); + mw.Show(); + + mw.OpenFile(fileNames); } /// /// Opens a new window, optionally loading the specified documents. @@ -863,12 +816,10 @@ namespace UniversalEditor.UserInterface /// The document model(s) of the document(s) to load. public void OpenWindow(params Document[] documents) { - IHostApplicationWindow window = OpenWindowInternal(documents); - window.WindowClosed += delegate(object sender, EventArgs e) - { - mvarWindows.Remove(window); - }; - mvarWindows.Add(window); + MainWindow mw = new MainWindow(); + mw.Show(); + + mw.OpenFile(documents); } // UniversalDataStorage.Editor.WindowsForms.Program diff --git a/Libraries/UniversalEditor.UserInterface/MainWindow.cs b/Libraries/UniversalEditor.UserInterface/MainWindow.cs index 889c1795..a8f61ee7 100644 --- a/Libraries/UniversalEditor.UserInterface/MainWindow.cs +++ b/Libraries/UniversalEditor.UserInterface/MainWindow.cs @@ -28,6 +28,7 @@ using UniversalEditor.UserInterface.Pages; using UniversalEditor.ObjectModels.Binary; using UniversalEditor.DataFormats.Binary; using System.Collections.Generic; +using System.Text; namespace UniversalEditor.UserInterface { @@ -704,7 +705,11 @@ namespace UniversalEditor.UserInterface protected override void OnClosed(EventArgs e) { - MBS.Framework.UserInterface.Application.Stop(); + Engine.CurrentEngine.Windows.Remove(this); + if (Engine.CurrentEngine.Windows.Count <= 0) + { + MBS.Framework.UserInterface.Application.Stop(); + } } protected override void OnCreated(EventArgs e) { @@ -712,9 +717,18 @@ namespace UniversalEditor.UserInterface { new DragDropTarget("text/uri-list", DragDropTargetFlags.SameApplication | DragDropTargetFlags.OtherApplication, 0x1) }, DragDropEffect.Copy, MouseButtons.Primary | MouseButtons.Secondary, KeyboardModifierKey.None); + + Engine.CurrentEngine.Windows.Add(this); + Engine.CurrentEngine.LastWindow = this; } -#region IHostApplicationWindow implementation + protected override void OnGotFocus(EventArgs e) + { + base.OnGotFocus(e); + Engine.CurrentEngine.LastWindow = this; + } + + #region IHostApplicationWindow implementation public void OpenFile() { /* @@ -745,6 +759,8 @@ namespace UniversalEditor.UserInterface public void OpenFile(params string[] fileNames) { Document[] documents = new Document[fileNames.Length]; + + List failedFiles = new List(); for (int i = 0; i < documents.Length; i++) { AccessorReference[] accs = UniversalEditor.Common.Reflection.GetAvailableAccessors(fileNames[i]); @@ -758,6 +774,29 @@ namespace UniversalEditor.UserInterface FileAccessor fa = new FileAccessor(fileNames[i], true, false, true); documents[i] = new Document(fa); } + else + { + failedFiles.Add(fileNames[i]); + } + } + if (failedFiles.Count > 0) + { + StringBuilder sb = new StringBuilder(); + if (failedFiles.Count == 1) + { + sb.Append(String.Format("The file '{0}' could not be found.", failedFiles[0])); + } + else + { + sb.AppendLine("The following files could not be found:"); + sb.AppendLine(); + for (int i = 0; i < failedFiles.Count; i++) + { + sb.AppendLine(failedFiles[i]); + } + } + + MessageDialog.ShowDialog(sb.ToString(), "Error", MessageDialogButtons.OK, MessageDialogIcon.Error); } OpenFile(documents); }