private void OnChangeImage(DomEventArgs ge)
{
if(!_model.CanChangeImages())
{
MessageBox.Show(
LocalizationManager.GetString("EditTab.CantPasteImageLocked",
"Sorry, this book is locked down so that images cannot be changed."));
return;
}
var imageElement = GetImageNode(ge);
if(imageElement == null)
return;
string currentPath = HtmlDom.GetImageElementUrl(imageElement).NotEncoded;
if(!CheckIfLockedAndWarn(currentPath))
return;
var target = (GeckoHtmlElement) ge.Target.CastToGeckoElement();
if(target.ClassName.Contains("licenseImage"))
return;
Cursor = Cursors.WaitCursor;
var imageInfo = new PalasoImage();
var existingImagePath = Path.Combine(_model.CurrentBook.FolderPath, currentPath);
//don't send the placeholder to the imagetoolbox... we get a better user experience if we admit we don't have an image yet.
if(!currentPath.ToLowerInvariant().Contains("placeholder") && RobustFile.Exists(existingImagePath))
{
try
{
imageInfo = PalasoImage.FromFileRobustly(existingImagePath);
}
catch(Exception e)
{
Logger.WriteMinorEvent("Not able to load image for ImageToolboxDialog: " + e.Message);
}
}
Logger.WriteEvent("Showing ImageToolboxDialog Editor Dialog");
// Check memory for the benefit of developers. The user won't see anything.
SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(true, "about to choose picture", false);
// Deep in the ImageToolboxDialog, when the user asks to see images from the ArtOfReading,
// We need to use the Gecko version of the thumbnail viewer, since the original ListView
// one has a sticky scroll bar in applications that are using Gecko. On Linux, we also
// need to use the Gecko version of the text box. Except that the Gecko version of the
// text box totally freezes the system if the user is using LinuxMint/cinnamon (ie, Wasta).
// See https://jira.sil.org/browse/BL-1147.
ThumbnailViewer.UseWebViewer = true;
if(SIL.PlatformUtilities.Platform.IsUnix &&
!(SIL.PlatformUtilities.Platform.IsWasta || SIL.PlatformUtilities.Platform.IsCinnamon))
{
TextInputBox.UseWebTextBox = true;
}
using(var dlg = new ImageToolboxDialog(imageInfo, null))
{
var searchLanguage = Settings.Default.ImageSearchLanguage;
if(String.IsNullOrWhiteSpace(searchLanguage))
{
// Pass in the current UI language. We want only the main language part of the tag.
// (for example, "zh-Hans" should pass in as "zh".)
searchLanguage = Settings.Default.UserInterfaceLanguage;
var idx = searchLanguage.IndexOfAny(new char[] {'-', '_'});
if(idx > 0)
searchLanguage = searchLanguage.Substring(0, idx);
}
dlg.SearchLanguage = searchLanguage;
var result = dlg.ShowDialog();
// Check memory for the benefit of developers. The user won't see anything.
SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(true, "picture chosen or canceled", false);
if(DialogResult.OK == result && dlg.ImageInfo != null)
{
// var path = MakePngOrJpgTempFileForImage(dlg.ImageInfo.Image);
SaveChangedImage(imageElement, dlg.ImageInfo, "Bloom had a problem including that image");
// Warn the user if we're starting to use too much memory.
SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(true, "picture chosen and saved", true);
}
// If the user changed the search language for art of reading, remember their change. But if they didn't
// touch it, don't remember it. Instead, let it continue to track the UI language so that if
// they are new and just haven't got around to setting the main UI Language,
// AOR can automatically start using that when they do.
if(searchLanguage != dlg.SearchLanguage)
{
//store their language selection even if they hit "cancel"
Settings.Default.ImageSearchLanguage = dlg.SearchLanguage;
Settings.Default.Save();
}
}
Logger.WriteMinorEvent("Emerged from ImageToolboxDialog Editor Dialog");
Cursor = Cursors.Default;
imageInfo.Dispose(); // ensure memory doesn't leak
}