From 218dcd844ef12551f877c12dbbdc37c14d65f030 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sun, 6 Sep 2020 06:04:07 -0400 Subject: [PATCH] Insert CustomOptions from the current DataFormat into Document Properties dialog --- .../UniversalEditor.UserInterface/Editor.cs | 46 +++++++++++- .../Editors/FileSystem/FileSystemEditor.cs | 2 +- .../Editors/Markup/MarkupEditor.cs | 2 +- .../UniversalEditor.UserInterface/Engine.cs | 68 +----------------- .../ExtensionMethods.cs | 71 +++++++++++++++++++ .../MainWindow.cs | 4 ++ .../Pages/EditorPage.cs | 1 + .../NewWorldComputing/Map/MapEditor.cs | 2 +- 8 files changed, 126 insertions(+), 70 deletions(-) diff --git a/Libraries/UniversalEditor.UserInterface/Editor.cs b/Libraries/UniversalEditor.UserInterface/Editor.cs index 9a430975..9a0c04b9 100644 --- a/Libraries/UniversalEditor.UserInterface/Editor.cs +++ b/Libraries/UniversalEditor.UserInterface/Editor.cs @@ -232,6 +232,8 @@ namespace UniversalEditor.UserInterface #region IEditorImplementation Members public string Title { get; set; } + public Document Document { get; set; } = null; + private ObjectModel mvarObjectModel = null; public ObjectModel ObjectModel { @@ -774,16 +776,56 @@ namespace UniversalEditor.UserInterface EndEdit (); } - protected virtual SettingsProvider[] GetDocumentPropertiesSettingsProviders() + protected virtual SettingsProvider[] GetDocumentPropertiesSettingsProvidersInternal() { return null; } + protected SettingsProvider[] GetDocumentPropertiesSettingsProviders() + { + SettingsProvider[] customs = GetDocumentPropertiesSettingsProvidersInternal(); + + List list = null; + if (customs == null) + { + list = new List(); + } + else + { + list = new List(customs); + } + + if (Document != null) + { + if (Document.DataFormat != null) + { + List listOptions = new List(); + DataFormatReference dfr = Document.DataFormat.MakeReference(); + for (int i = 0; i < dfr.ExportOptions.Count; i++) + { + if (!dfr.ExportOptions[i].Visible) continue; + listOptions.Add(dfr.ExportOptions[i]); + } + if (listOptions.Count > 0) + { + CustomSettingsProvider csp = new CustomSettingsProvider(); + SettingsGroup sg = new SettingsGroup(); + sg.Path = new string[] { dfr.Title }; + csp.SettingsGroups.Add(sg); + + sg.AddCustomOptions(listOptions, csp); + list.Add(csp); + } + } + } + return list.ToArray(); + } + /// /// Shows the document properties dialog. This function can be overridden to display a custom document properties dialog, but offers a /// built-in implementation based on the UWT which is populated with s from a call to /// . It is recommended that subclasses of override the - /// function instead of this one if they do not require a custom dialog layout. + /// function instead of this one if they do not require a custom dialog layout. /// /// true, if document properties dialog was shown (regardless of whether it was accepted or not), false otherwise. protected virtual bool ShowDocumentPropertiesDialogInternal() diff --git a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs index 162c740f..113ede61 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/FileSystem/FileSystemEditor.cs @@ -815,7 +815,7 @@ namespace UniversalEditor.Editors.FileSystem // (tv.ContextMenu.Items["FileSystemContextMenu_PasteShortcut"] as CommandMenuItem).Enabled = Clipboard.Default.ContainsFileList; } - protected override SettingsProvider[] GetDocumentPropertiesSettingsProviders() + protected override SettingsProvider[] GetDocumentPropertiesSettingsProvidersInternal() { List list = new List(); diff --git a/Libraries/UniversalEditor.UserInterface/Editors/Markup/MarkupEditor.cs b/Libraries/UniversalEditor.UserInterface/Editors/Markup/MarkupEditor.cs index c8aa9ff1..b82a8274 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/Markup/MarkupEditor.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/Markup/MarkupEditor.cs @@ -281,7 +281,7 @@ namespace UniversalEditor.Editors.Markup } private CustomSettingsProvider _spMarkupProvider = null; - protected override SettingsProvider[] GetDocumentPropertiesSettingsProviders() + protected override SettingsProvider[] GetDocumentPropertiesSettingsProvidersInternal() { if (_spMarkupProvider == null) { diff --git a/Libraries/UniversalEditor.UserInterface/Engine.cs b/Libraries/UniversalEditor.UserInterface/Engine.cs index 9abe1011..9a4b131b 100644 --- a/Libraries/UniversalEditor.UserInterface/Engine.cs +++ b/Libraries/UniversalEditor.UserInterface/Engine.cs @@ -312,15 +312,11 @@ namespace UniversalEditor.UserInterface dlg.SettingsProviders.Add(csp); SettingsGroup sg = new SettingsGroup(); + sg.Priority = 0; + sg.Path = new string[] { "General" }; csp.SettingsGroups.Add(sg); - foreach (CustomOption eo in customOptions) - { - // do not render the CustomOption if it's supposed to be invisible - if (!eo.Visible) continue; - - AddCustomOptionToSettingsGroup(csp, eo, sg); - } + sg.AddCustomOptions(customOptions, csp); if (dlg.ShowDialog() == DialogResult.OK) { @@ -336,64 +332,6 @@ namespace UniversalEditor.UserInterface } return false; } - - private void AddCustomOptionToSettingsGroup(CustomSettingsProvider csp, CustomOption eo, SettingsGroup sg, string[] path = null) - { - if (eo is CustomOptionChoice) - { - CustomOptionChoice option = (eo as CustomOptionChoice); - - List choices = new List(); - foreach (CustomOptionFieldChoice choice in option.Choices) - { - choices.Add(new ChoiceSetting.ChoiceSettingValue(choice.Title, choice.Title, choice.Value)); - } - sg.Settings.Add(new ChoiceSetting(option.PropertyName, option.Title, null, choices.ToArray())); - } - else if (eo is CustomOptionNumber) - { - CustomOptionNumber option = (eo as CustomOptionNumber); - sg.Settings.Add(new RangeSetting(option.PropertyName, option.Title, option.DefaultValue, option.MinimumValue, option.MaximumValue)); - } - else if (eo is CustomOptionText) - { - CustomOptionText option = (eo as CustomOptionText); - sg.Settings.Add(new TextSetting(option.PropertyName, option.Title, option.DefaultValue)); - } - else if (eo is CustomOptionBoolean) - { - CustomOptionBoolean option = (eo as CustomOptionBoolean); - sg.Settings.Add(new BooleanSetting(option.PropertyName, option.Title, option.DefaultValue)); - } - else if (eo is CustomOptionFile) - { - CustomOptionFile option = (eo as CustomOptionFile); - // sg.Settings.Add(new FileSetting(option.Title, option.DefaultValue)); - sg.Settings.Add(new TextSetting(option.PropertyName, option.Title, option.DefaultValue)); - } - else if (eo is CustomOptionGroup) - { - CustomOptionGroup cogrp = (eo as CustomOptionGroup); - SettingsGroup sg1 = new SettingsGroup(); - if (path == null) - { - path = new string[] { cogrp.Title }; - } - else - { - string[] path2 = new string[path.Length + 1]; - Array.Copy(path, 0, path2, 0, path.Length); - path2[path2.Length - 1] = cogrp.Title; - path = path2; - } - sg1.Path = path; - for (int j = 0; j < cogrp.Options.Count; j++) - { - AddCustomOptionToSettingsGroup(csp, cogrp.Options[j], sg1, path); - } - csp.SettingsGroups.Add(sg1); - } - } #endregion private static Engine[] m_AvailableEngines = null; diff --git a/Libraries/UniversalEditor.UserInterface/ExtensionMethods.cs b/Libraries/UniversalEditor.UserInterface/ExtensionMethods.cs index 2381c571..37160cc1 100644 --- a/Libraries/UniversalEditor.UserInterface/ExtensionMethods.cs +++ b/Libraries/UniversalEditor.UserInterface/ExtensionMethods.cs @@ -19,7 +19,9 @@ // 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 System.Text; +using MBS.Framework.UserInterface; using MBS.Framework.UserInterface.Dialogs; namespace UniversalEditor.UserInterface @@ -50,5 +52,74 @@ namespace UniversalEditor.UserInterface } dialog.FileNameFilters.Add(title, sb.ToString()); } + + private static void AddCustomOptionToSettingsGroup(CustomSettingsProvider csp, CustomOption eo, SettingsGroup sg, string[] path = null) + { + if (eo is CustomOptionChoice) + { + CustomOptionChoice option = (eo as CustomOptionChoice); + + List choices = new List(); + foreach (CustomOptionFieldChoice choice in option.Choices) + { + choices.Add(new ChoiceSetting.ChoiceSettingValue(choice.Title, choice.Title, choice.Value)); + } + sg.Settings.Add(new ChoiceSetting(option.PropertyName, option.Title, option.Value == null ? null : new ChoiceSetting.ChoiceSettingValue(option.Value.Title, option.Value.Title, option.Value.Value), choices.ToArray())); + } + else if (eo is CustomOptionNumber) + { + CustomOptionNumber option = (eo as CustomOptionNumber); + sg.Settings.Add(new RangeSetting(option.PropertyName, option.Title, (decimal)option.GetValue(), option.MinimumValue, option.MaximumValue)); + } + else if (eo is CustomOptionText) + { + CustomOptionText option = (eo as CustomOptionText); + sg.Settings.Add(new TextSetting(option.PropertyName, option.Title, (string)option.GetValue())); + } + else if (eo is CustomOptionBoolean) + { + CustomOptionBoolean option = (eo as CustomOptionBoolean); + sg.Settings.Add(new BooleanSetting(option.PropertyName, option.Title, (bool)option.GetValue())); + } + else if (eo is CustomOptionFile) + { + CustomOptionFile option = (eo as CustomOptionFile); + // sg.Settings.Add(new FileSetting(option.Title, option.DefaultValue)); + sg.Settings.Add(new TextSetting(option.PropertyName, option.Title, (string)option.GetValue())); + } + else if (eo is CustomOptionGroup) + { + CustomOptionGroup cogrp = (eo as CustomOptionGroup); + SettingsGroup sg1 = new SettingsGroup(); + if (path == null) + { + path = new string[] { cogrp.Title }; + } + else + { + string[] path2 = new string[path.Length + 1]; + Array.Copy(path, 0, path2, 0, path.Length); + path2[path2.Length - 1] = cogrp.Title; + path = path2; + } + sg1.Path = path; + for (int j = 0; j < cogrp.Options.Count; j++) + { + AddCustomOptionToSettingsGroup(csp, cogrp.Options[j], sg1, path); + } + csp.SettingsGroups.Add(sg1); + } + } + + public static void AddCustomOptions(this SettingsGroup sg, IEnumerable options, CustomSettingsProvider csp) + { + foreach (CustomOption eo in options) + { + // do not render the CustomOption if it's supposed to be invisible + if (!eo.Visible) continue; + + AddCustomOptionToSettingsGroup(csp, eo, sg); + } + } } } diff --git a/Libraries/UniversalEditor.UserInterface/MainWindow.cs b/Libraries/UniversalEditor.UserInterface/MainWindow.cs index 5bfa428a..c3d5266c 100644 --- a/Libraries/UniversalEditor.UserInterface/MainWindow.cs +++ b/Libraries/UniversalEditor.UserInterface/MainWindow.cs @@ -979,6 +979,8 @@ namespace UniversalEditor.UserInterface di.Name = document.OutputAccessor.GetFileName(); di.Title = System.IO.Path.GetFileName(document.OutputAccessor.GetFileName()); } + + GetCurrentEditor().Document = document; return true; } else @@ -1009,6 +1011,7 @@ namespace UniversalEditor.UserInterface document.OutputDataFormat = df; document.IsSaved = true; document.IsChanged = false; + return result; } return false; @@ -1050,6 +1053,7 @@ namespace UniversalEditor.UserInterface Document d = new Document(om, df, accessor); d.Save(); page.Document = d; + GetCurrentEditor().Document = d; DockingWindow di = dckContainer.Items[page] as DockingWindow; if (di != null) diff --git a/Libraries/UniversalEditor.UserInterface/Pages/EditorPage.cs b/Libraries/UniversalEditor.UserInterface/Pages/EditorPage.cs index cc2e7f3e..65ef7cbc 100644 --- a/Libraries/UniversalEditor.UserInterface/Pages/EditorPage.cs +++ b/Libraries/UniversalEditor.UserInterface/Pages/EditorPage.cs @@ -177,6 +177,7 @@ namespace UniversalEditor.UserInterface.Pages } ed.ObjectModel = om1; } + ed.Document = Document; if (requiresOpen) mvarDocument.Accessor.Close(); diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Editors/NewWorldComputing/Map/MapEditor.cs b/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Editors/NewWorldComputing/Map/MapEditor.cs index 8f3c11e6..07e956f7 100644 --- a/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Editors/NewWorldComputing/Map/MapEditor.cs +++ b/Plugins.UserInterface/UniversalEditor.Plugins.NewWorldComputing.UserInterface/Editors/NewWorldComputing/Map/MapEditor.cs @@ -75,7 +75,7 @@ namespace UniversalEditor.Plugins.NewWorldComputing.UserInterface.Editors.NewWor _mpds = new MapDocumentPropertiesSettingsProvider(this); } - protected override SettingsProvider[] GetDocumentPropertiesSettingsProviders() + protected override SettingsProvider[] GetDocumentPropertiesSettingsProvidersInternal() { return new SettingsProvider[] { _mpds }; }