Fixed a problem that the hotkeys were always disabled in the setting form, also allowing "esc" now to cancel the form. Fixed a problem in the SaveDestination, this didn't "honor" the supplied filename. Added a configuration setting (not yet in the settings form) which can be used to disable overwriting, a SaveAs dialog will be shown instead.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1912 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-06-08 13:30:39 +00:00
parent b3a3c1da4e
commit 292160b793
5 changed files with 75 additions and 29 deletions

View file

@ -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

View file

@ -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));

View file

@ -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);

View file

@ -44,7 +44,8 @@ namespace Greenshot {
private static CoreConfiguration coreConfiguration = IniConfig.GetIniSection<CoreConfiguration>();
private static EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
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();
}
/// <summary>
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;
}
/// <summary>
/// This is a method to popululate the ComboBox
/// with the items from the enumeration
/// </summary>
@ -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();
}
/// <summary>
/// Check the destination settings
/// </summary>

View file

@ -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;