Exemplo n.º 1
0
        /// <summary>
        /// Save with showing a dialog
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="captureDetails"></param>
        /// <returns>Path to filename</returns>
        public static string SaveWithDialog(ISurface surface, ICaptureDetails captureDetails)
        {
            string returnValue = null;

            using (SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails))
            {
                DialogResult dialogResult = saveImageFileDialog.ShowDialog();
                if (dialogResult.Equals(DialogResult.OK))
                {
                    try
                    {
                        string fileNameWithExtension         = saveImageFileDialog.FileNameWithExtension;
                        SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(FormatForFilename(fileNameWithExtension));
                        if (conf.OutputFilePromptQuality)
                        {
                            QualityDialog qualityDialog = new QualityDialog(outputSettings);
                            qualityDialog.ShowDialog();
                        }
                        // TODO: For now we always overwrite, should be changed
                        Save(surface, fileNameWithExtension, true, outputSettings, conf.OutputFileCopyPathToClipboard);
                        returnValue = fileNameWithExtension;
                        IniConfig.Save();
                    }
                    catch (ExternalException)
                    {
                        MessageBox.Show(Language.GetFormattedString("error_nowriteaccess", saveImageFileDialog.FileName).Replace(@"\\", @"\"), Language.GetString("error"));
                    }
                }
            }
            return(returnValue);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Save with showing a dialog
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="captureDetails"></param>
        /// <returns>Path to filename</returns>
        public static string SaveWithDialog(ISurface surface, ICaptureDetails captureDetails)
        {
            string returnValue = null;

            using (SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails))
            {
                DialogResult dialogResult = saveImageFileDialog.ShowDialog();
                if (dialogResult.Equals(DialogResult.OK))
                {
                    try
                    {
                        string fileNameWithExtension         = saveImageFileDialog.FileNameWithExtension;
                        SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(FormatForFilename(fileNameWithExtension));
                        if (conf.OutputFilePromptQuality)
                        {
                            QualityDialog qualityDialog = new QualityDialog(outputSettings);
                            qualityDialog.ShowDialog();
                        }
                        // For now we always overwrite, should be changed
                        Save(surface, fileNameWithExtension, true, outputSettings, conf.OutputFileCopyPathToClipboard);
                        returnValue = fileNameWithExtension;
                        IniConfig.Save();
                    }
                    catch (ExternalException)
                    {
                        MessageBox.Show(string.Format("Cannot save file to {0}.\r\nPlease check write accessibility of the selected storage location.",
                                                      saveImageFileDialog.FileName).Replace(@"\\", @"\"), "Error");
                    }
                }
            }
            return(returnValue);
        }
Exemplo n.º 3
0
        public void SuggestBasicFileNameTest()
        {
            //conf.Output_FileAs_Fullpath = @"c:\path\to\greenshot_testdir\gstest_28.jpg";
            conf.OutputFilePath               = @"c:\path\to\greenshot_testdir\";
            conf.OutputFileFilenamePattern    = "gstest_${NUM}";
            conf.OutputFileFormat             = OutputFormat.png;
            conf.OutputFileIncrementingNumber = 28;
            SaveImageFileDialog sifd = new SaveImageFileDialog();

            Assert.AreEqual(sifd.InitialDirectory, @"c:\path\to\greenshot_testdir");
            Assert.AreEqual(sifd.FileNameWithExtension, "gstest_000028.jpg");
        }
Exemplo n.º 4
0
        public void GetSetExtensionTest()
        {
            SaveImageFileDialog sifd = new SaveImageFileDialog();

            sifd.Extension = "jpg";
            Assert.AreEqual(sifd.Extension, "jpg");
            sifd.Extension = "gif";
            Assert.AreEqual(sifd.Extension, "gif");
            sifd.Extension = "png";
            Assert.AreEqual(sifd.Extension, "png");
            sifd.Extension = "bmp";
            Assert.AreEqual(sifd.Extension, "bmp");
        }
Exemplo n.º 5
0
        public void GetFileNameWithExtensionTest()
        {
            SaveImageFileDialog sifd = new SaveImageFileDialog();

            sifd.InitialDirectory = @"C:\some\path";
            sifd.FileName         = "myimage.jpg";
            sifd.Extension        = "jpg";
            Assert.AreEqual("myimage.jpg", sifd.FileNameWithExtension);

            sifd.Extension = "gif";
            Assert.AreEqual("myimage.jpg.gif", sifd.FileNameWithExtension);

            sifd.FileName = "myimage";
            Assert.AreEqual("myimage.gif", sifd.FileNameWithExtension);
        }
        public static string SaveWithDialog(Image image, ICaptureDetails captureDetails)
        {
            string returnValue = null;
            SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails);
            DialogResult        dialogResult        = saveImageFileDialog.ShowDialog();

            if (dialogResult.Equals(DialogResult.OK))
            {
                try {
                    string fileNameWithExtension = saveImageFileDialog.FileNameWithExtension;
                    // TODO: For now we overwrite, should be changed
                    ImageOutput.Save(image, fileNameWithExtension, true);
                    returnValue = fileNameWithExtension;
                    conf.OutputFileAsFullpath = fileNameWithExtension;
                    IniConfig.Save();
                } catch (System.Runtime.InteropServices.ExternalException) {
                    MessageBox.Show(Language.GetFormattedString(LangKey.error_nowriteaccess, saveImageFileDialog.FileName).Replace(@"\\", @"\"), Language.GetString(LangKey.error));
                }
            }
            return(returnValue);
        }