private void OnEditImageMetdata(DomEventArgs ge)
{
var imageElement = GetImageNode(ge);
if(imageElement == null)
return;
string fileName = HtmlDom.GetImageElementUrl(imageElement).NotEncoded;
//enhance: this all could be done without loading the image into memory
//could just deal with the metadata
//e.g., var metadata = Metadata.FromFile(path)
var path = Path.Combine(_model.CurrentBook.FolderPath, fileName);
PalasoImage imageInfo = null;
try
{
imageInfo = PalasoImage.FromFileRobustly(path);
}
catch(TagLib.CorruptFileException e)
{
ErrorReport.NotifyUserOfProblem(e,
"Bloom ran into a problem while trying to read the metadata portion of this image, " + path);
return;
}
using(imageInfo)
{
var hasMetadata = !(imageInfo.Metadata == null || imageInfo.Metadata.IsEmpty);
if(hasMetadata)
{
// If we have metadata with an official collectionUri or we are translating a shell
// just give a summary of the metadata
var looksOfficial = !string.IsNullOrEmpty(imageInfo.Metadata.CollectionUri);
if(looksOfficial || !_model.CanEditCopyrightAndLicense)
{
MessageBox.Show(imageInfo.Metadata.GetSummaryParagraph("en"));
return;
}
}
else
{
// If we don't have metadata, but we are translating a shell
// don't allow the metadata to be edited
if(!_model.CanEditCopyrightAndLicense)
{
MessageBox.Show(LocalizationManager.GetString("EditTab.CannotChangeCopyright",
"Sorry, the copyright and license for this book cannot be changed."));
return;
}
}
// Otherwise, bring up the dialog to edit the metadata
Logger.WriteEvent("Showing Metadata Editor For Image");
using(var dlg = new SIL.Windows.Forms.ClearShare.WinFormsUI.MetadataEditorDialog(imageInfo.Metadata))
{
if(DialogResult.OK == dlg.ShowDialog())
{
imageInfo.Metadata = dlg.Metadata;
imageInfo.Metadata.StoreAsExemplar(Metadata.FileCategory.Image);
//update so any overlays on the image are brought up to data
PageEditingModel.UpdateMetadataAttributesOnImage(new ElementProxy(imageElement), imageInfo);
imageElement.Click(); //wake up javascript to update overlays
SaveChangedImage(imageElement, imageInfo, "Bloom had a problem updating the image metadata");
var answer =
MessageBox.Show(
LocalizationManager.GetString("EditTab.CopyImageIPMetadataQuestion",
"Copy this information to all other pictures in this book?", "get this after you edit the metadata of an image"),
LocalizationManager.GetString("EditTab.TitleOfCopyIPToWholeBooksDialog",
"Picture Intellectual Property Information"), MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
if(answer == DialogResult.Yes)
{
Cursor = Cursors.WaitCursor;
try
{
_model.CopyImageMetadataToWholeBook(dlg.Metadata);
// There might be more than one image on this page. Update overlays.
_model.RefreshDisplayOfCurrentPage();
}
catch(Exception e)
{
ErrorReport.NotifyUserOfProblem(e, "There was a problem copying the metadata to all the images.");
}
Cursor = Cursors.Default;
}
}
}
}
//_model.SaveNow();
//doesn't work: _browser1.WebBrowser.Reload();
}