diff --git a/Libraries/UniversalEditor.Core/Document.cs b/Libraries/UniversalEditor.Core/Document.cs index fa186e00..8eade78e 100644 --- a/Libraries/UniversalEditor.Core/Document.cs +++ b/Libraries/UniversalEditor.Core/Document.cs @@ -96,6 +96,7 @@ namespace UniversalEditor IsSaved = true; IsChanged = false; + OnSaved(EventArgs.Empty); } public Document(ObjectModel objectModel, DataFormat dataFormat) : this(objectModel, dataFormat, null) @@ -258,5 +259,11 @@ namespace UniversalEditor OutputDataFormat = value; } } + + public event EventHandler Saved; + protected virtual void OnSaved(EventArgs e) + { + Saved?.Invoke(this, e); + } } } diff --git a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs index 113ede61..a6d1e62e 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs @@ -33,6 +33,7 @@ using MBS.Framework.UserInterface.DragDrop; using MBS.Framework.UserInterface.Input.Keyboard; using MBS.Framework.UserInterface.Input.Mouse; using System.Collections.Specialized; +using UniversalEditor.ObjectModels.FileSystem.FileSources; namespace UniversalEditor.Editors.FileSystem { @@ -69,6 +70,7 @@ namespace UniversalEditor.Editors.FileSystem tv.SortContainerRowsFirst = true; Context.AttachCommandEventHandler("FileSystemContextMenu_Open", FileSystemContextMenu_Open_Click); + Context.AttachCommandEventHandler("FileSystemContextMenu_Add_NewItem", FileAddNewItem_Click); Context.AttachCommandEventHandler("FileSystemContextMenu_Add_ExistingItem", FileAddExistingItem_Click); Context.AttachCommandEventHandler("FileSystemContextMenu_Add_ExistingFolder", FileAddExistingFolder_Click); Context.AttachCommandEventHandler("FileSystemContextMenu_Add_FilesFromFolder", FileAddItemsFromFolder_Click); @@ -108,6 +110,29 @@ namespace UniversalEditor.Editors.FileSystem e.Data = list.ToArray(); } + /// + /// Prompts the user to create a new item as an embedded inside the currently-loaded . + /// + /// Sender. + /// E. + private void FileAddNewItem_Click(object sender, EventArgs e) + { + FileSystemObjectModel fsom = ObjectModel as FileSystemObjectModel; + if (fsom == null) + return; + + Document d = HostApplication.CurrentWindow.NewFile(); + if (d != null) + { + File file = fsom.AddFile(d.Title.Replace("<", String.Empty).Replace(">", String.Empty)); + RecursiveAddFile(file); + + EmbeddedFileAccessor efa = new EmbeddedFileAccessor(file); + d.Accessor = efa; + file.Source = new MemoryFileSource(efa); + } + } + /// /// Prompts the user to select an existing file to add to the currently-loaded . /// @@ -193,11 +218,18 @@ namespace UniversalEditor.Editors.FileSystem EmbeddedFileAccessor ma = new EmbeddedFileAccessor(f); Document doc = new Document(ma); + doc.Saved += doc_Saved; HostApplication.CurrentWindow.OpenFile(doc); } } } + private void doc_Saved(object sender, EventArgs e) + { + BeginEdit(); + EndEdit(); + } + /// /// Creates a new folder in the current directory of the currently-loaded . /// diff --git a/Libraries/UniversalEditor.UserInterface/IHostApplicationWindow.cs b/Libraries/UniversalEditor.UserInterface/IHostApplicationWindow.cs index 2068b2f0..22d43259 100644 --- a/Libraries/UniversalEditor.UserInterface/IHostApplicationWindow.cs +++ b/Libraries/UniversalEditor.UserInterface/IHostApplicationWindow.cs @@ -11,7 +11,7 @@ namespace UniversalEditor.UserInterface { event EventHandler WindowClosed; - void NewFile(); + Document NewFile(); void NewProject(bool combineObjects = false); void OpenFile(); diff --git a/Libraries/UniversalEditor.UserInterface/MainWindow.cs b/Libraries/UniversalEditor.UserInterface/MainWindow.cs index c3d5266c..3a1d3832 100644 --- a/Libraries/UniversalEditor.UserInterface/MainWindow.cs +++ b/Libraries/UniversalEditor.UserInterface/MainWindow.cs @@ -282,7 +282,7 @@ namespace UniversalEditor.UserInterface private int iUntitledDocCount = 0; - public void NewFile() + public Document NewFile() { /* NewDialog2 dlg2 = new NewDialog2(); @@ -297,7 +297,7 @@ namespace UniversalEditor.UserInterface iUntitledDocCount++; DocumentTemplate template = (dlg.SelectedItem as DocumentTemplate); - if (template == null) return; + if (template == null) return null; Pages.EditorPage page = new Pages.EditorPage(); page.DocumentEdited += page_DocumentEdited; @@ -307,10 +307,12 @@ namespace UniversalEditor.UserInterface if (objm == null) { MessageDialog.ShowDialog("Failed to create an ObjectModel for the type \"" + template.ObjectModelReference.TypeName + "\"", "Error", MessageDialogButtons.OK, MessageDialogIcon.Error); - return; + return null; } page.Document = new Document(objm, null, null); + page.Document.Title = String.Format("", iUntitledDocCount); + /* DockingWindow dwNewDocument = dcc.Windows.Add("", "", page); dwNewDocument.Behavior = DockBehavior.Dock; @@ -325,7 +327,9 @@ namespace UniversalEditor.UserInterface Glue.Common.Methods.SendApplicationEvent(ae); */ InitDocTab(String.Format("", iUntitledDocCount), page.Title, page); + return page.Document; } + return null; } private Editor _prevEditor = null; @@ -505,7 +509,7 @@ namespace UniversalEditor.UserInterface break; } if (!found) { - OpenDefaultEditor (doc.Accessor); + OpenDefaultEditor(doc); return; } } @@ -531,7 +535,7 @@ namespace UniversalEditor.UserInterface catch (ObjectModelNotSupportedException ex) { // we're catching this one because there's nothing anyone (not even the developer) can do about it if the DF throws ObjectModelNotSupported - DialogResult result = MessageDialog.ShowDialog("The object model you specified is not supported by the selected DataFormat.", "Error", MessageDialogButtons.RetryCancel, MessageDialogIcon.Error); + DialogResult result = MessageDialog.ShowDialog(String.Format("The object model you specified is not supported by the selected DataFormat.\r\n\r\n{0}", ex.Message), "Error", MessageDialogButtons.RetryCancel, MessageDialogIcon.Error); if (result == DialogResult.Retry) { DocumentPropertiesDialog dlg = new DocumentPropertiesDialog(); @@ -556,7 +560,7 @@ namespace UniversalEditor.UserInterface // we're catching this one because there's nothing anyone (not even the developer) can do about it if the DF throws ObjectModelNotSupported // TODO: For DataFormats that support it (i.e. Layout-based) we should be able to "debug" the DataFormat to find out exactly where it failed - DialogResult result = MessageDialog.ShowDialog("The data format you specified could not load the file.", "Error", MessageDialogButtons.RetryCancel, MessageDialogIcon.Error); + DialogResult result = MessageDialog.ShowDialog(String.Format("The data format you specified could not load the file.\r\n\r\n{0}", ex.Message), "Error", MessageDialogButtons.RetryCancel, MessageDialogIcon.Error); if (result == DialogResult.Retry) { DocumentPropertiesDialog dlg = new DocumentPropertiesDialog(); @@ -609,13 +613,13 @@ namespace UniversalEditor.UserInterface else { Console.Error.WriteLine("Editor not found for object model " + doc.ObjectModel.MakeReference().Title + " ; using default editor"); - OpenDefaultEditor(doc.Accessor); + OpenDefaultEditor(doc); } } else { Console.Error.WriteLine("ObjectModel not specified for accessor " + doc.Accessor.ToString() + " ; using default editor"); - OpenDefaultEditor(doc.Accessor); + OpenDefaultEditor(doc); } } @@ -705,13 +709,13 @@ namespace UniversalEditor.UserInterface } } - private void OpenDefaultEditor(Accessor acc) + private void OpenDefaultEditor(Document doc) { EditorPage page = new EditorPage(); - page.Document = new Document(null, null, acc); + page.Document = doc; page.DocumentEdited += page_DocumentEdited; - InitDocTab(acc.GetFileName(), System.IO.Path.GetFileName(acc.GetFileName()), page); + InitDocTab(doc.Accessor.GetFileName(), System.IO.Path.GetFileName(doc.Accessor.GetFileName()), page); } [ContainerLayout("~/Panels/StartPage.glade")] @@ -1050,10 +1054,18 @@ namespace UniversalEditor.UserInterface EditorPage page = GetCurrentEditorPage(); if (page == null) return false; - Document d = new Document(om, df, accessor); - d.Save(); - page.Document = d; - GetCurrentEditor().Document = d; + if (page.Document == null) + { + page.Document = new Document(om, df, accessor); + } + else + { + page.Document.ObjectModel = om; + page.Document.DataFormat = df; + page.Document.Accessor = accessor; + } + page.Document.Save(); + GetCurrentEditor().Document = page.Document; DockingWindow di = dckContainer.Items[page] as DockingWindow; if (di != null)