Insert CustomOptions from the current DataFormat into Document Properties dialog
This commit is contained in:
parent
2cf265e898
commit
218dcd844e
@ -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<SettingsProvider> list = null;
|
||||
if (customs == null)
|
||||
{
|
||||
list = new List<SettingsProvider>();
|
||||
}
|
||||
else
|
||||
{
|
||||
list = new List<SettingsProvider>(customs);
|
||||
}
|
||||
|
||||
if (Document != null)
|
||||
{
|
||||
if (Document.DataFormat != null)
|
||||
{
|
||||
List<CustomOption> listOptions = new List<CustomOption>();
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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 <see cref="SettingsDialog" /> which is populated with <see cref="SettingsProvider" />s from a call to
|
||||
/// <see cref="GetDocumentPropertiesSettingsProviders" />. It is recommended that subclasses of <see cref="Editor" /> override the
|
||||
/// <see cref="GetDocumentPropertiesSettingsProviders" /> function instead of this one if they do not require a custom dialog layout.
|
||||
/// <see cref="GetDocumentPropertiesSettingsProvidersInternal" /> function instead of this one if they do not require a custom dialog layout.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c>, if document properties dialog was shown (regardless of whether it was accepted or not), <c>false</c> otherwise.</returns>
|
||||
protected virtual bool ShowDocumentPropertiesDialogInternal()
|
||||
|
||||
@ -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<SettingsProvider> list = new List<SettingsProvider>();
|
||||
|
||||
|
||||
@ -281,7 +281,7 @@ namespace UniversalEditor.Editors.Markup
|
||||
}
|
||||
|
||||
private CustomSettingsProvider _spMarkupProvider = null;
|
||||
protected override SettingsProvider[] GetDocumentPropertiesSettingsProviders()
|
||||
protected override SettingsProvider[] GetDocumentPropertiesSettingsProvidersInternal()
|
||||
{
|
||||
if (_spMarkupProvider == null)
|
||||
{
|
||||
|
||||
@ -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<ChoiceSetting.ChoiceSettingValue> choices = new List<ChoiceSetting.ChoiceSettingValue>();
|
||||
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;
|
||||
|
||||
@ -19,7 +19,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
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<ChoiceSetting.ChoiceSettingValue> choices = new List<ChoiceSetting.ChoiceSettingValue>();
|
||||
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<CustomOption> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -177,6 +177,7 @@ namespace UniversalEditor.UserInterface.Pages
|
||||
}
|
||||
ed.ObjectModel = om1;
|
||||
}
|
||||
ed.Document = Document;
|
||||
|
||||
if (requiresOpen)
|
||||
mvarDocument.Accessor.Close();
|
||||
|
||||
@ -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 };
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user