diff --git a/Greenshot/Destinations/FileDestination.cs b/Greenshot/Destinations/FileDestination.cs index 60d297edb..d77c15234 100644 --- a/Greenshot/Destinations/FileDestination.cs +++ b/Greenshot/Destinations/FileDestination.cs @@ -70,24 +70,41 @@ namespace Greenshot.Destinations { } public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { - bool outputMade = false; - string pattern = conf.OutputFileFilenamePattern; - 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); - + bool outputMade; + bool overwrite; + string fullPath; + + if (captureDetails.Filename != null) { + // As we save a pre-selected file, allow to overwrite. + overwrite = true; + LOG.InfoFormat("Using previous filename"); + fullPath = captureDetails.Filename; + } else { + LOG.InfoFormat("Creating new filename"); + string pattern = conf.OutputFileFilenamePattern; + if (string.IsNullOrEmpty(pattern)) { + pattern = "greenshot ${capturetime}"; + } + string filename = FilenameHelper.GetFilenameFromPattern(pattern, conf.OutputFileFormat, captureDetails); + string filepath = FilenameHelper.FillVariables(conf.OutputFilePath, false); + fullPath = Path.Combine(filepath, filename); + // As we generate a file, the configuration tells us if we allow to overwrite + overwrite = conf.OutputFileAllowOverwrite; + } // 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); + ImageOutput.Save(image, fullPath, overwrite); outputMade = true; - } catch (Exception e) { - LOG.Error("Error saving screenshot!", e); + } 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(image, 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 diff --git a/Greenshot/Forms/AboutForm.cs b/Greenshot/Forms/AboutForm.cs index 9af83284e..512cfabbd 100644 --- a/Greenshot/Forms/AboutForm.cs +++ b/Greenshot/Forms/AboutForm.cs @@ -62,7 +62,7 @@ namespace Greenshot { try { switch (keyData) { case Keys.Escape: - DialogResult = DialogResult.OK; + DialogResult = DialogResult.Cancel; break; case Keys.E: MessageBox.Show(EnvironmentInfo.EnvironmentToString(true)); diff --git a/Greenshot/Forms/SettingsForm.Designer.cs b/Greenshot/Forms/SettingsForm.Designer.cs index 5a60770c9..a09590a51 100644 --- a/Greenshot/Forms/SettingsForm.Designer.cs +++ b/Greenshot/Forms/SettingsForm.Designer.cs @@ -1229,8 +1229,6 @@ namespace Greenshot { this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "SettingsForm"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SettingsFormFormClosing); - this.Shown += new System.EventHandler(this.SettingsFormShown); this.groupbox_preferredfilesettings.ResumeLayout(false); this.groupbox_preferredfilesettings.PerformLayout(); this.groupbox_applicationsettings.ResumeLayout(false); diff --git a/Greenshot/Forms/SettingsForm.cs b/Greenshot/Forms/SettingsForm.cs index b3e4aa6f4..003e310f1 100644 --- a/Greenshot/Forms/SettingsForm.cs +++ b/Greenshot/Forms/SettingsForm.cs @@ -44,7 +44,8 @@ namespace Greenshot { private static CoreConfiguration coreConfiguration = IniConfig.GetIniSection(); private static EditorConfiguration editorConfiguration = IniConfig.GetIniSection(); private ToolTip toolTip = new ToolTip(); - + private bool inHotkey = false; + public SettingsForm() : base() { InitializeComponent(); } @@ -61,14 +62,50 @@ namespace Greenshot { this.trackBarJpegQuality.BackColor = System.Drawing.SystemColors.Control; } - DisplayPluginTab(); + // This makes it possible to still capture the settings screen + this.fullscreen_hotkeyControl.Enter += delegate { EnterHotkeyControl(); }; + this.fullscreen_hotkeyControl.Leave += delegate { LeaveHotkeyControl(); }; + this.window_hotkeyControl.Enter += delegate { EnterHotkeyControl(); }; + this.window_hotkeyControl.Leave += delegate { LeaveHotkeyControl(); }; + this.region_hotkeyControl.Enter += delegate { EnterHotkeyControl(); }; + this.region_hotkeyControl.Leave += delegate { LeaveHotkeyControl(); }; + this.ie_hotkeyControl.Enter += delegate { EnterHotkeyControl(); }; + this.ie_hotkeyControl.Leave += delegate { LeaveHotkeyControl(); }; + this.lastregion_hotkeyControl.Enter += delegate { EnterHotkeyControl(); }; + this.lastregion_hotkeyControl.Leave += delegate { LeaveHotkeyControl(); }; + + DisplayPluginTab(); UpdateUI(); ExpertSettingsEnableState(false); DisplaySettings(); CheckSettings(); } - - /// + + private void EnterHotkeyControl() { + GreenshotPlugin.Controls.HotkeyControl.UnregisterHotkeys(); + inHotkey = true; + } + private void LeaveHotkeyControl() { + MainForm.RegisterHotkeys(); + inHotkey = false; + } + + protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { + switch (keyData) { + case Keys.Escape: + if (!inHotkey) { + DialogResult = DialogResult.Cancel; + } else { + return base.ProcessCmdKey(ref msg, keyData); + } + break; + default: + return base.ProcessCmdKey(ref msg, keyData); + } + return true; + } + + /// /// This is a method to popululate the ComboBox /// with the items from the enumeration /// @@ -430,14 +467,6 @@ namespace Greenshot { colorButton_window_background.Visible = false; } - void SettingsFormFormClosing(object sender, FormClosingEventArgs e) { - MainForm.RegisterHotkeys(); - } - - void SettingsFormShown(object sender, EventArgs e) { - HotkeyControl.UnregisterHotkeys(); - } - /// /// Check the destination settings /// diff --git a/GreenshotPlugin/Core/CoreConfiguration.cs b/GreenshotPlugin/Core/CoreConfiguration.cs index 81d50f73c..67545bdd8 100644 --- a/GreenshotPlugin/Core/CoreConfiguration.cs +++ b/GreenshotPlugin/Core/CoreConfiguration.cs @@ -90,7 +90,9 @@ namespace GreenshotPlugin.Core { [IniProperty("OutputFilePath", Description="Output file path.")] public string OutputFilePath; - [IniProperty("OutputFileFilenamePattern", Description="Filename pattern for screenshot.", DefaultValue="${capturetime:d\"yyyy-MM-dd HH_mm_ss\"}-${title}")] + [IniProperty("OutputFileAllowOverwrite", Description = "If the target file already exists True will make Greenshot always overwrite and False will display a 'Save-As' dialog.", DefaultValue = "true")] + public bool OutputFileAllowOverwrite; + [IniProperty("OutputFileFilenamePattern", Description = "Filename pattern for screenshot.", DefaultValue = "${capturetime:d\"yyyy-MM-dd HH_mm_ss\"}-${title}")] public string OutputFileFilenamePattern; [IniProperty("OutputFileFormat", Description="Default file type for writing screenshots. (bmp, gif, jpg, png, tiff)", DefaultValue="png")] public OutputFormat OutputFileFormat = OutputFormat.png;