Ejemplo n.º 1
0
        private void GetImageFileFromSystem()
        {
            try
            {
                SetMode(Modes.SingleImage);
                // The primary thing that OpenFileDialogWithViews buys us is the ability to default to large icons.
                // OpenFileDialogWithViews still doesn't let us read (and thus remember) the selected view.
                using (var dlg = new OpenFileDialogWithViews(OpenFileDialogWithViews.DialogViewTypes.Large_Icons))
                {
                    if (string.IsNullOrEmpty(ImageToolboxSettings.Default.LastImageFolder))
                    {
                        dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                    }
                    else
                    {
                        dlg.InitialDirectory = ImageToolboxSettings.Default.LastImageFolder;;
                    }

                    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
                    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))
                    {
                        ImageToolboxSettings.Default.LastImageFolder = Path.GetDirectoryName(dlg.FileName);
                        ImageToolboxSettings.Default.Save();

                        try
                        {
                            _currentImage = PalasoImage.FromFile(dlg.FileName);
                        }
                        catch (Exception err)                         //for example, http://jira.palaso.org/issues/browse/BL-199
                        {
                            var msg = "Sorry, there was a problem loading that image.".Localize(
                                "ImageToolbox.ProblemLoadingImage");
                            if (ImageLoadingExceptionReporter != null)
                            {
                                ImageLoadingExceptionReporter(dlg.FileName, err, msg);
                            }
                            else
                            {
                                ErrorReport.NotifyUserOfProblem(err, msg);
                            }

                            return;
                        }
                        _pictureBox.Image = _currentImage.Image;
                        if (ImageChanged != null)
                        {
                            ImageChanged.Invoke(this, null);
                        }
                    }
                }
            }
            finally
            {
                _actModal = false;
            }
        }
Ejemplo n.º 2
0
		private void OnGetFromFileSystemClick(object sender, EventArgs e)
		{
			SetMode(Modes.SingleImage);
#if __MonoCS__
			using (var dlg = new OpenFileDialog())
#else
			// The primary thing that OpenFileDialogWithViews buys us is the ability to default to large icons.
			// OpenFileDialogWithViews still doesn't let us read (and thus remember) the selected view.
			using (var dlg = new OpenFileDialogWithViews(OpenFileDialogWithViews.DialogViewTypes.Large_Icons))
#endif
			{
#if __MonoCS__
				// OpenFileDialogWithViews is Windows-only.  Until we need more of its functionality elsewhere,
				// it's much simpler to implement the one method we need here for Mono/Linux.
				SelectLargeIconView(dlg);
#endif
				if (string.IsNullOrEmpty(ImageToolboxSettings.Default.LastImageFolder))
				{
					dlg.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
				}
				else
				{
					dlg.InitialDirectory = ImageToolboxSettings.Default.LastImageFolder; ;
				}

				//NB: dissallowed 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())
				{
					ImageToolboxSettings.Default.LastImageFolder = Path.GetDirectoryName(dlg.FileName);
					ImageToolboxSettings.Default.Save();

					try
					{
						_currentImage = PalasoImage.FromFile(dlg.FileName);
					}
					catch (Exception err) //for example, http://jira.palaso.org/issues/browse/BL-199
					{
						ErrorReport.NotifyUserOfProblem(err,"Sorry, there was a problem loading that image.".Localize("ImageToolbox.ProblemLoadingImage"));
						return;
					}
					_pictureBox.Image = _currentImage.Image;
					if (ImageChanged != null)
						ImageChanged.Invoke(this, null);
				}
			}
		}