public void ShowToolboxWith_PreExisting_EnsureRawFormatUnchanged()
		{
			Application.EnableVisualStyles();
			PalasoImage i = PalasoImage.FromImage(TestImages.logo);

			using (var dlg = new ImageToolboxDialog(i, ""))
				{
					dlg.ShowDialog();
					Assert.AreEqual(ImageFormat.Jpeg.Guid, dlg.ImageInfo.Image.RawFormat.Guid);
				}
		}
		public void ShowGeckoToolbox()
		{
			Application.EnableVisualStyles();
			ThumbnailViewer.UseWebViewer = true;
			using (var dlg = new ImageToolboxDialog(new PalasoImage(), null))// "arrow"))
			{
				if (DialogResult.OK == dlg.ShowDialog())
				{
					// File name ending in .tmp will confuse TagLib#...doesn't know what kind of metadata to write.
					string path = Path.ChangeExtension(Path.GetTempFileName(), ".png");
					dlg.ImageInfo.Save(path);
					Process.Start("explorer.exe", "/select, \"" + path + "\"");
				}

			}
		}
		public void ShowToolboxWith_PreExisting_Image_WithMetadata()
		{
			Application.EnableVisualStyles();
			PalasoImage i = PalasoImage.FromImage(LicenseLogos.by_nd);
			i.Metadata.License = new CreativeCommonsLicense(true,true, CreativeCommonsLicense.DerivativeRules.DerivativesWithShareAndShareAlike);
			i.Metadata.CopyrightNotice = "Copyright 1992 Papua New Guinea Department of Education and Other Good Things";
			i.Metadata.CollectionName = "International Illustrations: The Art Of Reading";
			i.Metadata.Creator = "Various Talented Illustrators";
			//using (var f = TempFile.WithExtension(".png"))
			{
				//i.Save(f.Path);
				using (var dlg = new ImageToolboxDialog(i, "arrow"))
				{
					dlg.ShowDialog();
				}
			}
		}
		public void ShowToolbox()
		{
			Application.EnableVisualStyles();
			using (var dlg = new ImageToolboxDialog(new PalasoImage(),null))// "arrow"))
			{
				if (DialogResult.OK == dlg.ShowDialog())
				{
					// File name ending in .tmp will confuse TagLib#...doesn't know what kind of metadata to write.
					var ext = ".png";
					if (Path.GetExtension(dlg.ImageInfo.OriginalFilePath) == ".jpg")
						ext = ".jpg";
					string path  = Path.ChangeExtension(Path.GetTempFileName(), ext);
					dlg.ImageInfo.Save(path);
					Process.Start("explorer.exe", "/select, \"" + path + "\"");
				}
			}
		}
        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
        }
Exemple #6
0
 private void OnImageToolboxClicked(object sender, EventArgs e)
 {
     Application.EnableVisualStyles();
     ThumbnailViewer.UseWebViewer = true;
     using (var dlg = new ImageToolboxDialog(new PalasoImage(), null))
     {
         dlg.ShowDialog();
     }
 }