Fix the Open File Dialog

This commit is contained in:
Michael Becker 2019-08-05 01:54:07 -04:00
parent e38e067bfa
commit 179bd78616
5 changed files with 99 additions and 60 deletions

View File

@ -40,11 +40,14 @@ namespace UniversalEditor.UserInterface.Controls
public ObjectModel ObjectModel { get; set; } = null;
public DataFormat DataFormat { get; set; } = null;
public System.Collections.ObjectModel.ReadOnlyCollection<string> SelectedFileNames { get { return _Browser.SelectedFileNames; } }
public UniversalEditorFileBrowserControl ()
{
this.Layout = new BoxLayout (Orientation.Vertical);
_Browser = new FileBrowserControl ();
_Browser.ItemActivated += _Browser_ItemActivated;
this.Controls.Add (_Browser, new BoxLayout.Constraints (true, true));
cboObjectModel = new GenericBrowserButton<ObjectModel, ObjectModelReference> ();
@ -146,6 +149,18 @@ namespace UniversalEditor.UserInterface.Controls
_Table.Controls.Add (cboDataFormat, new BoxLayout.Constraints (true, true));
this.Controls.Add (_Table, new BoxLayout.Constraints (false, false));
}
public event EventHandler ItemActivated;
protected virtual void OnItemActivated (EventArgs e)
{
ItemActivated?.Invoke (this, e);
}
void _Browser_ItemActivated (object sender, EventArgs e)
{
OnItemActivated (e);
}
}
}

View File

@ -63,9 +63,12 @@ namespace UniversalEditor.UserInterface.Dialogs
void cmdOK_Click (object sender, EventArgs e)
{
StackSidebarPanel pnl = sidebar.SelectedPanel;
if (pnl == null) return;
Container ct = (pnl.Control as Container);
AccessorReference accref = pnl.GetExtraData<AccessorReference> ("ar");
CustomOption.CustomOptionCollection coll = new CustomOption.CustomOptionCollection ();
foreach (Control ctl in ct.Controls) {
CustomOption eo = (ctl.GetExtraData ("eo") as CustomOption);
if (eo == null)
@ -91,12 +94,19 @@ namespace UniversalEditor.UserInterface.Dialogs
UniversalEditorFileBrowserControl fbc = (ctl as UniversalEditorFileBrowserControl);
if (eo is CustomOptionFile)
{
// (eo as CustomOptionFile).Value = fbc.SelectedFileNames [0];
(eo as CustomOptionFile).Value = fbc.SelectedFileNames [0];
}
}
coll.Add (eo);
}
Accessor acc = accref.Create ();
Engine.CurrentEngine.ApplyCustomOptions (ref acc, coll);
Accessor = acc;
this.DialogResult = DialogResult.OK;
this.Close ();
}
@ -119,6 +129,11 @@ namespace UniversalEditor.UserInterface.Dialogs
private StackSidebar sidebar = null;
private void fbc_ItemActivated (object sender, EventArgs e)
{
cmdOK_Click (sender, e);
}
private void InitializeComponent()
{
sidebar = new StackSidebar ();
@ -238,6 +253,7 @@ namespace UniversalEditor.UserInterface.Dialogs
UniversalEditorFileBrowserControl fbc = new UniversalEditorFileBrowserControl ();
fbc.SetExtraData("eo", option);
fbc.ItemActivated += fbc_ItemActivated;
// TextBox cmd = new TextBox();
// AwesomeControls.FileTextBox.FileTextBoxControl cmd = new AwesomeControls.FileTextBox.FileTextBoxControl();
// cmd.Click += cmdFileBrowse_Click;

View File

@ -1537,63 +1537,68 @@ namespace UniversalEditor.UserInterface
if (retval)
{
foreach (CustomOption eo in coll)
{
System.Reflection.PropertyInfo pi = dfr.AccessorType.GetProperty(eo.PropertyName);
if (pi == null) continue;
if (eo is CustomOptionNumber)
{
CustomOptionNumber itm = (eo as CustomOptionNumber);
pi.SetValue(df, Convert.ChangeType(itm.Value, pi.PropertyType), null);
}
else if (eo is CustomOptionBoolean)
{
CustomOptionBoolean itm = (eo as CustomOptionBoolean);
pi.SetValue(df, Convert.ChangeType(itm.Value, pi.PropertyType), null);
}
else if (eo is CustomOptionChoice)
{
CustomOptionFieldChoice choice = (eo as CustomOptionChoice).Value;
if (choice != null)
{
Type[] interfaces = pi.PropertyType.GetInterfaces();
bool convertible = false;
foreach (Type t in interfaces)
{
if (t == typeof(IConvertible))
{
convertible = true;
break;
}
}
if (convertible)
{
pi.SetValue(df, Convert.ChangeType(choice.Value, pi.PropertyType), null);
}
else
{
pi.SetValue(df, choice.Value, null);
}
}
}
else if (eo is CustomOptionText)
{
CustomOptionText itm = (eo as CustomOptionText);
pi.SetValue(df, Convert.ChangeType(itm.Value, pi.PropertyType), null);
}
else if (eo is CustomOptionFile)
{
CustomOptionFile itm = (eo as CustomOptionFile);
pi.SetValue(df, Convert.ChangeType(itm.Value, pi.PropertyType), null);
}
}
ApplyCustomOptions (ref df, coll);
return true;
}
return false;
}
public void ApplyCustomOptions (ref Accessor df, CustomOption.CustomOptionCollection coll)
{
AccessorReference dfr = df.MakeReference ();
foreach (CustomOption eo in coll)
{
System.Reflection.PropertyInfo pi = dfr.AccessorType.GetProperty(eo.PropertyName);
if (pi == null) continue;
if (eo is CustomOptionNumber)
{
CustomOptionNumber itm = (eo as CustomOptionNumber);
pi.SetValue(df, Convert.ChangeType(itm.Value, pi.PropertyType), null);
}
else if (eo is CustomOptionBoolean)
{
CustomOptionBoolean itm = (eo as CustomOptionBoolean);
pi.SetValue(df, Convert.ChangeType(itm.Value, pi.PropertyType), null);
}
else if (eo is CustomOptionChoice)
{
CustomOptionFieldChoice choice = (eo as CustomOptionChoice).Value;
if (choice != null)
{
Type[] interfaces = pi.PropertyType.GetInterfaces();
bool convertible = false;
foreach (Type t in interfaces)
{
if (t == typeof(IConvertible))
{
convertible = true;
break;
}
}
if (convertible)
{
pi.SetValue(df, Convert.ChangeType(choice.Value, pi.PropertyType), null);
}
else
{
pi.SetValue(df, choice.Value, null);
}
}
}
else if (eo is CustomOptionText)
{
CustomOptionText itm = (eo as CustomOptionText);
pi.SetValue(df, Convert.ChangeType(itm.Value, pi.PropertyType), null);
}
else if (eo is CustomOptionFile)
{
CustomOptionFile itm = (eo as CustomOptionFile);
pi.SetValue(df, Convert.ChangeType(itm.Value, pi.PropertyType), null);
}
}
}
public virtual ActionMenuItem[] CreateMenuItemsFromPlaceholder(PlaceholderMenuItem pmi)
{
List<ActionMenuItem> list = new List<ActionMenuItem>();

View File

@ -325,7 +325,7 @@ namespace UniversalEditor.UserInterface
if (dfrs.Length > 0)
{
ObjectModelReference[] omrs = UniversalEditor.Common.Reflection.GetAvailableObjectModels(doc.Accessor);
ObjectModelReference [] omrs = UniversalEditor.Common.Reflection.GetAvailableObjectModels (dfrs [0]);
if (omrs.Length < 1)
{
Console.WriteLine("Object model not found for data format " + dfrs[0].Title + " ; using default editor");
@ -476,12 +476,14 @@ namespace UniversalEditor.UserInterface
{
using (DocumentPropertiesDialogV2 dlg = new DocumentPropertiesDialogV2 ())
{
if (dlg.ShowDialog () == DialogResult.OK)
DialogResult result = dlg.ShowDialog ();
if (result == DialogResult.OK)
{
if (dlg.ObjectModel == null || dlg.DataFormat == null || dlg.Accessor == null) {
if (dlg.Accessor == null) {
return;
}
Document doc = new Document(dlg.ObjectModel, dlg.DataFormat, dlg.Accessor);
Document doc = new Document(null, null, dlg.Accessor);
OpenFile(doc);
}
}

View File

@ -46,10 +46,12 @@ namespace UniversalEditor.UserInterface
this.Controls.Add(image, new BoxLayout.Constraints(true, true));
// this.Controls.Add(lbl, new BoxLayout.Constraints(true, true));
}
private static bool created = false;
protected override void OnCreated(EventArgs e)
{
Application.DoEvents();
if (created) return;
created = true;
// less do this
Application.ShortName = "mbs-editor";
// Application.Title = "Universal Editor";
@ -69,7 +71,6 @@ namespace UniversalEditor.UserInterface
private void threadLoader_ThreadStart()
{
Application.DoEvents();
/*
if (Configuration.SplashScreen.Enabled)
{