Ejemplo n.º 1
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(Designation, Description);
            bool   outputMade;
            bool   overwrite;
            string fullPath;
            // Get output settings from the configuration
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings();

            if (captureDetails != null && captureDetails.Filename != null)
            {
                // As we save a pre-selected file, allow to overwrite.
                overwrite = true;
                LOG.InfoFormat("Using previous filename");
                fullPath = captureDetails.Filename;
                outputSettings.Format = ImageOutput.FormatForFilename(fullPath);
            }
            else
            {
                fullPath = CreateNewFilename(captureDetails);
                // As we generate a file, the configuration tells us if we allow to overwrite
                overwrite = conf.OutputFileAllowOverwrite;
            }
            if (conf.OutputFilePromptQuality)
            {
                QualityDialog qualityDialog = new QualityDialog(outputSettings);
                qualityDialog.ShowDialog();
            }

            // Catching any exception to prevent that the user can't write in the directory.
            // This is done for e.g. bugs #2974608, #2963943, #2816163, #2795317, #2789218, #3004642
            try {
                ImageOutput.Save(surface, fullPath, overwrite, outputSettings, conf.OutputFileCopyPathToClipboard);
                outputMade = true;
            } catch (ArgumentException ex1) {
                // Our generated filename exists, display 'save-as'
                LOG.InfoFormat("Not overwriting: {0}", ex1.Message);
                // when we don't allow to overwrite present a new SaveWithDialog
                fullPath   = ImageOutput.SaveWithDialog(surface, captureDetails);
                outputMade = (fullPath != null);
            } catch (Exception ex2) {
                LOG.Error("Error saving screenshot!", ex2);
                // Show the problem
                MessageBox.Show(Language.GetString(LangKey.error_save), Language.GetString(LangKey.error));
                // when save failed we present a SaveWithDialog
                fullPath   = ImageOutput.SaveWithDialog(surface, captureDetails);
                outputMade = (fullPath != null);
            }
            // Don't overwrite filename if no output is made
            if (outputMade)
            {
                exportInformation.ExportMade = outputMade;
                exportInformation.Filepath   = fullPath;
                captureDetails.Filename      = fullPath;
                conf.OutputFileAsFullpath    = fullPath;
            }

            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
        public static string SaveImage(Image img)
        {
            if (img != null)
            {
                return(ImageOutput.SaveWithDialog(img));
            }

            return(string.Empty);
        }
 void SaveAsToolStripMenuItemClick(object sender, System.EventArgs e)
 {
     lastSaveFullPath = ImageOutput.SaveWithDialog(surface.GetImageForExport());
     if (lastSaveFullPath != null)
     {
         SetImagePath(lastSaveFullPath);
         updateStatusLabel(lang.GetString("editor_imagesaved").Replace("%storagelocation%", lastSaveFullPath), fileSavedStatusContextMenu);
     }
     else
     {
         clearStatusLabel();
     }
 }
Ejemplo n.º 4
0
        protected override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var exportInformation = new ExportInformation(Designation, Description);
            // Bug #2918756 don't overwrite path if SaveWithDialog returns null!
            var savedTo = ImageOutput.SaveWithDialog(surface, captureDetails);

            if (savedTo != null)
            {
                exportInformation.ExportMade            = true;
                exportInformation.Filepath              = savedTo;
                captureDetails.Filename                 = savedTo;
                _coreConfiguration.OutputFileAsFullpath = savedTo;
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            bool   outputMade = false;
            string pattern    = "${title}";

            if (string.IsNullOrEmpty(pattern))
            {
                pattern = "greenshot ${capturetime}";
            }
            string filename = FilenameHelper.GetFilenameFromPattern(pattern, conf.OutputFileFormat, captureDetails);
            string filepath = FilenameHelper.FillVariables(conf.OutputFilePath, false);
            string fullPath = Path.Combine(filepath, filename);

            // Catching any exception to prevent that the user can't write in the directory.
            // This is done for e.g. bugs #2974608, #2963943, #2816163, #2795317, #2789218, #3004642
            using (Image image = surface.GetImageForExport())
            {
                try
                {
                    // TODO: For now we overwrite, but this should be fixed some time
                    ImageOutput.Save(image, fullPath, true);
                    outputMade = true;
                }
                catch (Exception e)
                {
                    LOG.Error("Error saving screenshot!", e);
                    // Show the problem
                    MessageBox.Show(Language.GetString(LangKey.error_save), Language.GetString(LangKey.error));
                    // when save failed we present a SaveWithDialog
                    fullPath   = ImageOutput.SaveWithDialog(image, captureDetails);
                    outputMade = (fullPath != null);
                }
            }
            // Don't overwite filename if no output is made
            if (outputMade)
            {
                surface.LastSaveFullPath = fullPath;
                surface.Modified         = false;
                captureDetails.Filename  = fullPath;
                surface.SendMessageEvent(this, SurfaceMessageTyp.FileSaved, Language.GetFormattedString(LangKey.editor_imagesaved, surface.LastSaveFullPath));
            }
            else
            {
                surface.SendMessageEvent(this, SurfaceMessageTyp.Info, "");
            }
            return(outputMade);
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            string savedTo = null;

            using (Image image = surface.GetImageForExport()) {
                // Bug #2918756 don't overwrite path if SaveWithDialog returns null!
                savedTo = ImageOutput.SaveWithDialog(image, captureDetails);
                if (savedTo != null)
                {
                    surface.Modified         = false;
                    surface.LastSaveFullPath = savedTo;
                    captureDetails.Filename  = savedTo;
                    surface.SendMessageEvent(this, SurfaceMessageTyp.FileSaved, Language.GetFormattedString(LangKey.editor_imagesaved, surface.LastSaveFullPath));
                }
            }
            return(savedTo != null);
        }
Ejemplo n.º 7
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
            string            savedTo           = null;

            // Bug #2918756 don't overwrite path if SaveWithDialog returns null!
            savedTo = ImageOutput.SaveWithDialog(surface, captureDetails);
            if (savedTo != null)
            {
                exportInformation.ExportMade = true;
                exportInformation.Filepath   = savedTo;
                captureDetails.Filename      = savedTo;
                conf.OutputFileAsFullpath    = savedTo;
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
        void CaptureImage(Image img)
        {
            DoCaptureFeedback();
            this.Hide();
            string fullPath = null;

            ImageOutput.PrepareClipboardObject();
            if ((conf.Output_Destinations & ScreenshotDestinations.FileDefault) == ScreenshotDestinations.FileDefault)
            {
                string filename = FilenameHelper.GetFilenameFromPattern(conf.Output_File_FilenamePattern, conf.Output_File_Format);
                fullPath = Path.Combine(conf.Output_File_Path, filename);
                ImageOutput.Save(img, fullPath);
            }
            if ((conf.Output_Destinations & ScreenshotDestinations.FileWithDialog) == ScreenshotDestinations.FileWithDialog)
            {
                fullPath = ImageOutput.SaveWithDialog(img);
            }
            if ((conf.Output_Destinations & ScreenshotDestinations.Clipboard) == ScreenshotDestinations.Clipboard)
            {
                ImageOutput.CopyToClipboard(img);
            }
            if ((conf.Output_Destinations & ScreenshotDestinations.Printer) == ScreenshotDestinations.Printer)
            {
                new PrintHelper(img).PrintWithDialog();
            }
            if ((conf.Output_Destinations & ScreenshotDestinations.Editor) == ScreenshotDestinations.Editor)
            {
                ImageEditorForm editor = new ImageEditorForm();
                editor.SetImage(img);
                if (fullPath != null)
                {
                    editor.SetImagePath(fullPath);
                }
                editor.Show();
            }
        }