private void OnEditImageMetdata(GeckoDomEventArgs ge) { var imageElement = GetImageNode(ge); if (imageElement == null) { return; } string fileName = imageElement.GetAttribute("src").Replace("%20", " "); var path = Path.Combine(_model.CurrentBook.FolderPath, fileName); using (var imageInfo = PalasoImage.FromFile(path)) { bool looksOfficial = imageInfo.Metadata != null && !string.IsNullOrEmpty(imageInfo.Metadata.CollectionUri); if (looksOfficial) { MessageBox.Show(imageInfo.Metadata.GetSummaryParagraph("en")); return; } Logger.WriteEvent("Showing Metadata Editor For Image"); using (var dlg = new Palaso.UI.WindowsForms.ClearShare.WinFormsUI.MetadataEditorDialog(imageInfo.Metadata)) { if (DialogResult.OK == dlg.ShowDialog()) { imageInfo.Metadata = dlg.Metadata; imageInfo.SaveUpdatedMetadataIfItMakesSense(); imageInfo.Metadata.StoreAsExemplar(Metadata.FileCategory.Image); //update so any overlays on the image are brough up to data var editor = new PageEditingModel(); editor.UpdateMetdataAttributesOnImgElement(imageElement, imageInfo); var answer = MessageBox.Show(LocalizationManager.GetString("EditTab.copyImageIPMetdataQuestion", "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); if (answer == DialogResult.Yes) { Cursor = Cursors.WaitCursor; try { _model.CopyImageMetadataToWholeBook(dlg.Metadata); } 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(); }
private void OnShowBookMetadataEditor() { try { if(!_model.CanEditCopyrightAndLicense) { MessageBox.Show(LocalizationManager.GetString("EditTab.CannotChangeCopyright", "Sorry, the copyright and license for this book cannot be changed.")); return; } _model.SaveNow();//in case we were in this dialog already and made changes, which haven't found their way out to the Book yet Metadata metadata = _model.CurrentBook.GetLicenseMetadata(); Logger.WriteEvent("Showing Metadata Editor Dialog"); using (var dlg = new Palaso.UI.WindowsForms.ClearShare.WinFormsUI.MetadataEditorDialog(metadata)) { dlg.ShowCreator = false; if (DialogResult.OK == dlg.ShowDialog()) { string imagePath = _model.CurrentBook.FolderPath.CombineForPath("license.png"); if (File.Exists(imagePath)) File.Delete(imagePath); Image licenseImage = dlg.Metadata.License.GetImage(); if (licenseImage != null) { licenseImage.Save(imagePath); } else if (File.Exists(imagePath)) { File.Delete(imagePath); } //NB: we are mapping "RightsStatement" (which comes from XMP-dc:Rights) to "LicenseNotes" in the html. //note that the only way currently to recognize a custom license is that RightsStatement is non-empty while description is emtpy string rights = dlg.Metadata.License.RightsStatement==null ? string.Empty : dlg.Metadata.License.RightsStatement.Replace("'", "\\'"); string description = dlg.Metadata.License.GetDescription("en") == null ? string.Empty : dlg.Metadata.License.GetDescription("en").Replace("'", "\\'"); string licenseImageName = licenseImage==null? string.Empty: "license.png"; string result = string.Format( "{{ copyright: '{0}', licenseImage: '{1}', licenseUrl: '{2}', licenseNotes: '{3}', licenseDescription: '{4}' }}", dlg.Metadata.CopyrightNotice.Replace("'","\\'"), licenseImageName, dlg.Metadata.License.Url, rights, description); _browser1.RunJavaScript("SetCopyrightAndLicense(" + result + ")"); //ok, so the the dom for *that page* is updated, but if the page doesn't display some of those values, they won't get //back to the data div in the actual html file even when the page is read and saved, because individual pages don't //have the data div. _model.CurrentBook.UpdateLicenseMetdata(dlg.Metadata); _model.SaveNow(); _model.RefreshDisplayOfCurrentPage();//the cleanup() that is part of Save removes qtips, so let' redraw everything } } Logger.WriteMinorEvent("Emerged from Metadata Editor Dialog"); } catch (Exception error) { #if DEBUG throw; #endif Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "There was a problem recording your changes to the copyright and license."); } }
private void OnEditImageMetdata(GeckoDomEventArgs ge) { var imageElement = GetImageNode(ge); if (imageElement == null) return; string fileName = imageElement.GetAttribute("src").Replace("%20", " "); var path = Path.Combine(_model.CurrentBook.FolderPath, fileName); using (var imageInfo = PalasoImage.FromFile(path)) { bool looksOfficial = imageInfo.Metadata!=null && !string.IsNullOrEmpty(imageInfo.Metadata.CollectionUri); if(looksOfficial) { MessageBox.Show(imageInfo.Metadata.GetSummaryParagraph("en")); return; } Logger.WriteEvent("Showing Metadata Editor For Image"); using (var dlg = new Palaso.UI.WindowsForms.ClearShare.WinFormsUI.MetadataEditorDialog(imageInfo.Metadata)) { if (DialogResult.OK == dlg.ShowDialog()) { imageInfo.Metadata = dlg.Metadata; imageInfo.SaveUpdatedMetadataIfItMakesSense(); imageInfo.Metadata.StoreAsExemplar(Metadata.FileCategory.Image); //update so any overlays on the image are brough up to data var editor = new PageEditingModel(); editor.UpdateMetdataAttributesOnImgElement(imageElement, imageInfo); var answer = MessageBox.Show(LocalizationManager.GetString("EditTab.copyImageIPMetdataQuestion","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); if(answer == DialogResult.Yes) { Cursor = Cursors.WaitCursor; try { _model.CopyImageMetadataToWholeBook(dlg.Metadata); } 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(); }
private void OnShowBookMetadataEditor() { try { if (!_model.CanEditCopyrightAndLicense) { MessageBox.Show(LocalizationManager.GetString("EditTab.CannotChangeCopyright", "Sorry, the copyright and license for this book cannot be changed.")); return; } _model.SaveNow(); //in case we were in this dialog already and made changes, which haven't found their way out to the Book yet Metadata metadata = _model.CurrentBook.GetLicenseMetadata(); Logger.WriteEvent("Showing Metadata Editor Dialog"); using (var dlg = new Palaso.UI.WindowsForms.ClearShare.WinFormsUI.MetadataEditorDialog(metadata)) { dlg.ShowCreator = false; if (DialogResult.OK == dlg.ShowDialog()) { string imagePath = _model.CurrentBook.FolderPath.CombineForPath("license.png"); if (File.Exists(imagePath)) { File.Delete(imagePath); } Image licenseImage = dlg.Metadata.License.GetImage(); if (licenseImage != null) { licenseImage.Save(imagePath); } else if (File.Exists(imagePath)) { File.Delete(imagePath); } //NB: we are mapping "RightsStatement" (which comes from XMP-dc:Rights) to "LicenseNotes" in the html. //note that the only way currently to recognize a custom license is that RightsStatement is non-empty while description is emtpy string rights = dlg.Metadata.License.RightsStatement == null ? string.Empty : dlg.Metadata.License.RightsStatement.Replace("'", "\\'"); string description = dlg.Metadata.License.GetDescription("en") == null ? string.Empty : dlg.Metadata.License.GetDescription("en").Replace("'", "\\'"); string licenseImageName = licenseImage == null? string.Empty: "license.png"; string result = string.Format( "{{ copyright: '{0}', licenseImage: '{1}', licenseUrl: '{2}', licenseNotes: '{3}', licenseDescription: '{4}' }}", dlg.Metadata.CopyrightNotice.Replace("'", "\\'"), licenseImageName, dlg.Metadata.License.Url, rights, description); _browser1.RunJavaScript("SetCopyrightAndLicense(" + result + ")"); //ok, so the the dom for *that page* is updated, but if the page doesn't display some of those values, they won't get //back to the data div in the actual html file even when the page is read and saved, because individual pages don't //have the data div. _model.CurrentBook.UpdateLicenseMetdata(dlg.Metadata); _model.SaveNow(); _model.RefreshDisplayOfCurrentPage(); //the cleanup() that is part of Save removes qtips, so let' redraw everything } } Logger.WriteMinorEvent("Emerged from Metadata Editor Dialog"); } catch (Exception error) { #if DEBUG throw; #endif Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "There was a problem recording your changes to the copyright and license."); } }