diff --git a/SIL.Windows.Forms/ImageToolbox/AcquireImageControl.cs b/SIL.Windows.Forms/ImageToolbox/AcquireImageControl.cs index f0281bb66..3f9d8b4a7 100644 --- a/SIL.Windows.Forms/ImageToolbox/AcquireImageControl.cs +++ b/SIL.Windows.Forms/ImageToolbox/AcquireImageControl.cs @@ -38,7 +38,7 @@ public AcquireImageControl() void _galleryControl_ImageChanged(object sender, EventArgs e) { - //propogate that event to the outer toolbox + // Propagate that event to the outer toolbox if (ImageChanged != null) ImageChanged(sender, e); } @@ -50,9 +50,9 @@ private void OnGetFromFileSystemClick(object sender, EventArgs e) if (_actModal) return; // The GTK file chooser on Linux isn't acting modal, so we simulate it. _actModal = true; - // Something in the Mono runtime state machine keeps the GTK filechooser from getting the + // Something in the Mono runtime state machine keeps the GTK file chooser from getting the // focus immediately when we invoke OpenFileDialogWithViews.ShowDialog() directly at this - // point. Waiting for the next idle gets it into a state where the filechooser does receive + // point. Waiting for the next idle gets it into a state where the file chooser does receive // the focus as desired. See https://silbloom.myjetbrains.com/youtrack/issue/BL-5809. if (Platform.IsMono) Application.Idle += DelayGetImageFileFromSystem; @@ -74,7 +74,7 @@ private void DelayGetImageFileFromSystem(object sender, EventArgs e) // load, but it's the default exception if anything is wrong with a file loaded by // Image.FromFile(), so it could happen with a largish image that's corrupted; // TagLib.CorruptFileException (most cases where file is not valid image data, though - // its main meaning is that specfically the metadata can't be read). + // its main meaning is that specifically the metadata can't be read). public Action ImageLoadingExceptionReporter { get; set; } private void GetImageFileFromSystem() @@ -97,7 +97,7 @@ private void GetImageFileFromSystem() dlg.Title = "Choose Picture File".Localize("ImageToolbox.FileChooserTitle", "Title shown for a file chooser dialog brought up by the ImageToolbox"); - //NB: dissallowed gif because of a .net crash: http://jira.palaso.org/issues/browse/BL-85 + //NB: disallowed gif because of a .net crash: http://jira.palaso.org/issues/browse/BL-85 dlg.Filter = "picture files".Localize("ImageToolbox.PictureFiles", "Shown in the file-picking dialog to describe what kind of files the dialog is filtering for") + "(*.png;*.tif;*.tiff;*.jpg;*.jpeg;*.bmp)|*.png;*.tif;*.tiff;*.jpg;*.jpeg;*.bmp;"; if (DialogResult.OK == dlg.ShowDialog(this.ParentForm)) @@ -166,7 +166,7 @@ private void OnDragDrop(object sender, DragEventArgs e) BeginInvoke(new Action(OpenFileFromDrag), s); - ParentForm.Activate(); // in the case Explorer overlaps this form + ParentForm?.Activate(); // in the case Explorer overlaps this form } } catch (Exception) @@ -183,14 +183,7 @@ public void SetImage(PalasoImage image) _scannerButton.Checked = _cameraButton.Checked = false; _currentImage = image; SetMode(Modes.SingleImage); - if (image == null) - { - _pictureBox.Image = null; - } - else - { - _pictureBox.Image = image.Image; - } + _pictureBox.Image = image?.Image; } public PalasoImage GetImage() @@ -264,17 +257,20 @@ private void GetFromDevice(ImageAcquisitionService.DeviceKind deviceKind) // Interop.WIA by reflection, so any strings contained in methods that depend on WIA // calls are omitted. private string TwainDriverNotSupportedMessage => - "Note: this program works with devices that have a 'WIA' driver, not the old-style " + - "'TWAIN' driver".Localize("ImageToolbox.TwainDriverNotSupported"); + LocalizationManager.GetString("ImageToolbox.TwainDriverNotSupported", + "Note: this program works with devices that have a \"WIA\" driver, not the " + + "old-style \"TWAIN\" driver"); // This is a separate property because L10nSharp's extraction code cannot properly load // Interop.WIA by reflection, so any strings contained in methods that depend on WIA // calls are omitted. private string WIAVersion2MissingMessage => + string.Format( + LocalizationManager.GetString("ImageToolbox.WindowsXpMissingWiaV2Dll", "Windows XP does not come with a crucial DLL that lets you use a WIA scanner with " + - "this program. Get a technical person to download and follow the directions at " + - "http://vbnet.mvps.org/files/updates/wiaautsdk.zip".Localize( - "ImageToolbox.WindowsXpMissingWiaV2Dll"); + "this program. Get a technical person to download and follow the directions at {0}", + "Param 0: URL to download a zip file"), + "http://vbnet.mvps.org/files/updates/wiaautsdk.zip"); // This is a separate property because L10nSharp's extraction code cannot properly load // Interop.WIA by reflection, so any strings contained in methods that depend on WIA @@ -302,7 +298,7 @@ public string SearchLanguage /* /// - /// Bitmaps --> PNG, JPEGs stay as jpegs. + /// Bitmaps --> PNG, JPEGs stay as JPEGs. /// Will delete the incoming file if it needs to do a conversion. /// private string ConvertToPngOrJpegIfNotAlready(string incoming) @@ -344,8 +340,6 @@ private string ConvertToPngOrJpegIfNotAlready(string incoming) private string ConvertToPngOrJpegIfNotAlready(ImageFile wiaImageFile) { - Image acquiredImage;//with my scanner, always a .bmp - var imageBytes = (byte[])wiaImageFile.FileData.get_BinaryData(); if (wiaImageFile.FileExtension == ".jpg" || wiaImageFile.FileExtension == ".png") { @@ -369,8 +363,8 @@ private string ConvertToPngOrJpegIfNotAlready(ImageFile wiaImageFile) TempFile jpeg = TempFile.WithExtension(".jpg"); TempFile png = TempFile.WithExtension(".png"); - //DOCS: "You must keep the stream open for the lifetime of the Image."(maybe just true for jpegs) - using (acquiredImage = Image.FromStream(stream)) + //DOCS: "You must keep the stream open for the lifetime of the Image." (maybe just true for jpeg images) + using (var acquiredImage = Image.FromStream(stream)) { acquiredImage.Save(jpeg.Path, ImageFormat.Jpeg); acquiredImage.Save(png.Path, ImageFormat.Png); @@ -410,7 +404,7 @@ private void SetMode(Modes mode) _galleryControl.Visible = false; break; default: - throw new ArgumentOutOfRangeException("mode"); + throw new ArgumentOutOfRangeException(nameof(mode)); } } @@ -434,7 +428,7 @@ private void AcquireImageControl_Load(object sender, EventArgs e) } // This control can get loaded when the overall dialog is being disposed. // See https://issues.bloomlibrary.org/youtrack/issue/BL-10314 if you don't believe me. - Load -= new EventHandler(AcquireImageControl_Load); + Load -= AcquireImageControl_Load; } ///