it is now possible to automate the opening of 'embedded' documents in proper Editors without an Accessor

This commit is contained in:
Michael Becker 2020-08-10 16:16:09 -04:00
parent 23e35d5282
commit 70730ac1a0
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
2 changed files with 57 additions and 45 deletions

View File

@ -199,6 +199,7 @@ namespace UniversalEditor
}
return mvarTitle;
}
set { mvarTitle = value; }
}
/// <summary>

View File

@ -516,57 +516,60 @@ namespace UniversalEditor.UserInterface
{
while (!loaded)
{
try
if (doc.Accessor != null)
{
doc.Accessor.Open();
doc.Load();
doc.IsSaved = true;
loaded = true;
}
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);
if (result == DialogResult.Retry)
try
{
DocumentPropertiesDialog dlg = new DocumentPropertiesDialog();
dlg.DataFormat = doc.DataFormat;
dlg.ObjectModel = doc.ObjectModel;
dlg.Accessor = doc.Accessor;
if (dlg.ShowDialog() == DialogResult.OK)
{
doc.DataFormat = dlg.DataFormat;
doc.ObjectModel = dlg.ObjectModel;
doc.Accessor = dlg.Accessor;
}
// try loading it again
continue;
doc.Accessor.Open();
doc.Load();
doc.IsSaved = true;
loaded = true;
}
return;
}
catch (InvalidDataFormatException 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 data format you specified could not load the file.", "Error", MessageDialogButtons.RetryCancel, MessageDialogIcon.Error);
if (result == DialogResult.Retry)
catch (ObjectModelNotSupportedException ex)
{
DocumentPropertiesDialog dlg = new DocumentPropertiesDialog();
dlg.DataFormat = doc.DataFormat;
dlg.ObjectModel = doc.ObjectModel;
dlg.Accessor = doc.Accessor;
if (dlg.ShowDialog() == DialogResult.OK)
// 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);
if (result == DialogResult.Retry)
{
doc.DataFormat = dlg.DataFormat;
doc.ObjectModel = dlg.ObjectModel;
doc.Accessor = dlg.Accessor;
}
DocumentPropertiesDialog dlg = new DocumentPropertiesDialog();
dlg.DataFormat = doc.DataFormat;
dlg.ObjectModel = doc.ObjectModel;
dlg.Accessor = doc.Accessor;
if (dlg.ShowDialog() == DialogResult.OK)
{
doc.DataFormat = dlg.DataFormat;
doc.ObjectModel = dlg.ObjectModel;
doc.Accessor = dlg.Accessor;
}
// try loading it again
continue;
// try loading it again
continue;
}
return;
}
catch (InvalidDataFormatException ex)
{
// 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);
if (result == DialogResult.Retry)
{
DocumentPropertiesDialog dlg = new DocumentPropertiesDialog();
dlg.DataFormat = doc.DataFormat;
dlg.ObjectModel = doc.ObjectModel;
dlg.Accessor = doc.Accessor;
if (dlg.ShowDialog() == DialogResult.OK)
{
doc.DataFormat = dlg.DataFormat;
doc.ObjectModel = dlg.ObjectModel;
doc.Accessor = dlg.Accessor;
}
// try loading it again
continue;
}
return;
}
return;
}
#if !DEBUG
catch (Exception ex)
{
@ -582,12 +585,20 @@ namespace UniversalEditor.UserInterface
}
}
#endif
}
else
{
loaded = true;
}
}
EditorPage page = new EditorPage();
page.Document = doc;
page.DocumentEdited += page_DocumentEdited;
InitDocTab(doc.Accessor.GetFileName(), doc.Title, page);
string filename = doc.Accessor?.GetFileName();
if (filename == null) filename = doc.Title;
InitDocTab(filename, doc.Title, page);
}
else
{