diff --git a/Greenshot/Configuration/AppConfig.cs b/Greenshot/Configuration/AppConfig.cs index 6a6bfb129..3906bebf5 100644 --- a/Greenshot/Configuration/AppConfig.cs +++ b/Greenshot/Configuration/AppConfig.cs @@ -168,7 +168,7 @@ namespace Greenshot.Configuration { coreConfiguration.OutputPrintAllowShrink = (bool)appConfig.Output_Print_AllowShrink; coreConfiguration.OutputPrintCenter = (bool)appConfig.Output_Print_Center; coreConfiguration.OutputPrintPromptOptions = (bool)appConfig.Output_Print_PromptOptions; - coreConfiguration.OutputPrintTimestamp = (bool)appConfig.Output_Print_Timestamp; + coreConfiguration.OutputPrintFooter = (bool)appConfig.Output_Print_Timestamp; int delay = appConfig.Capture_Wait_Time-1; if (delay < 0) { delay = 0; diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index bb0a14d47..4224d3769 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -920,7 +920,9 @@ namespace Greenshot { foreach(string propertyName in conf.Values.Keys) { if (propertyName.StartsWith("OutputPrint")) { iniValue = conf.Values[propertyName]; - selectList.AddItem(lang.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value); + if (iniValue.Attributes.LanguageKey != null) { + selectList.AddItem(lang.GetString(iniValue.Attributes.LanguageKey), iniValue, (bool)iniValue.Value); + } } } selectList.CheckedChanged += new EventHandler(this.QuickSettingBoolItemChanged); diff --git a/Greenshot/Forms/PrintOptionsDialog.cs b/Greenshot/Forms/PrintOptionsDialog.cs index d05fa7721..3eecbde4d 100644 --- a/Greenshot/Forms/PrintOptionsDialog.cs +++ b/Greenshot/Forms/PrintOptionsDialog.cs @@ -52,7 +52,7 @@ namespace Greenshot.Forms { this.AllowPrintRotate = this.checkboxAllowRotate.Checked = conf.OutputPrintAllowRotate; this.AllowPrintShrink = this.checkboxAllowShrink.Checked = conf.OutputPrintAllowShrink; this.PrintInverted = this.checkboxPrintInverted.Checked = conf.OutputPrintInverted; - this.PrintDateTime = this.checkboxDateTime.Checked = conf.OutputPrintTimestamp; + this.PrintDateTime = this.checkboxDateTime.Checked = conf.OutputPrintFooter; this.checkbox_dontaskagain.Checked = false; UpdateUI(); } @@ -82,7 +82,7 @@ namespace Greenshot.Forms { conf.OutputPrintAllowEnlarge = this.AllowPrintEnlarge; conf.OutputPrintAllowRotate = this.AllowPrintRotate; conf.OutputPrintAllowShrink = this.AllowPrintShrink; - conf.OutputPrintTimestamp = this.PrintDateTime; + conf.OutputPrintFooter = this.PrintDateTime; conf.OutputPrintInverted = this.PrintInverted; conf.OutputPrintPromptOptions = !this.checkbox_dontaskagain.Checked; IniConfig.Save(); diff --git a/Greenshot/Forms/SettingsForm.cs b/Greenshot/Forms/SettingsForm.cs index 019c9d22e..b2ef9d7ec 100644 --- a/Greenshot/Forms/SettingsForm.cs +++ b/Greenshot/Forms/SettingsForm.cs @@ -289,7 +289,7 @@ namespace Greenshot { checkboxAllowEnlarge.Checked = coreConfiguration.OutputPrintAllowEnlarge; checkboxAllowRotate.Checked = coreConfiguration.OutputPrintAllowRotate; checkboxAllowShrink.Checked = coreConfiguration.OutputPrintAllowShrink; - checkboxTimestamp.Checked = coreConfiguration.OutputPrintTimestamp; + checkboxTimestamp.Checked = coreConfiguration.OutputPrintFooter; checkbox_alwaysshowprintoptionsdialog.Checked = coreConfiguration.OutputPrintPromptOptions; checkbox_capture_mousepointer.Checked = coreConfiguration.CaptureMousepointer; checkbox_capture_windows_interactive.Checked = coreConfiguration.CaptureWindowsInteractive; @@ -348,7 +348,7 @@ namespace Greenshot { coreConfiguration.OutputPrintAllowEnlarge = checkboxAllowEnlarge.Checked; coreConfiguration.OutputPrintAllowRotate = checkboxAllowRotate.Checked; coreConfiguration.OutputPrintAllowShrink = checkboxAllowShrink.Checked; - coreConfiguration.OutputPrintTimestamp = checkboxTimestamp.Checked; + coreConfiguration.OutputPrintFooter = checkboxTimestamp.Checked; coreConfiguration.OutputPrintPromptOptions = checkbox_alwaysshowprintoptionsdialog.Checked; coreConfiguration.CaptureMousepointer = checkbox_capture_mousepointer.Checked; coreConfiguration.CaptureWindowsInteractive = checkbox_capture_windows_interactive.Checked; diff --git a/Greenshot/Helpers/FilenameHelper.cs b/Greenshot/Helpers/FilenameHelper.cs index 1d1ebffdc..d0c7f59e8 100644 --- a/Greenshot/Helpers/FilenameHelper.cs +++ b/Greenshot/Helpers/FilenameHelper.cs @@ -84,7 +84,7 @@ namespace Greenshot.Helpers { } public static string GetFilenameWithoutExtensionFromPattern(string pattern, ICaptureDetails captureDetails) { - return FillPattern(pattern, captureDetails); + return FillPattern(pattern, captureDetails, true); } public static string GetFilenameFromPattern(string pattern, OutputFormat imageFormat) { @@ -92,7 +92,7 @@ namespace Greenshot.Helpers { } public static string GetFilenameFromPattern(string pattern, OutputFormat imageFormat, ICaptureDetails captureDetails) { - return FillPattern(pattern, captureDetails) + "." + imageFormat.ToString().ToLower(); + return FillPattern(pattern, captureDetails, true) + "." + imageFormat.ToString().ToLower(); } /// @@ -175,25 +175,25 @@ namespace Greenshot.Helpers { } } if (processVars != null && processVars.Contains(variable)) { + replaceValue = (string)processVars[variable]; if (filenameSafeMode) { - replaceValue = MakePathSafe((string)processVars[variable]); - } else { - replaceValue = (string)processVars[variable]; + replaceValue = MakePathSafe(replaceValue); } } else if (userVars != null && userVars.Contains(variable)) { + replaceValue = (string)userVars[variable]; if (filenameSafeMode) { - replaceValue = MakePathSafe((string)userVars[variable]); - } else { - replaceValue = (string)userVars[variable]; + replaceValue = MakePathSafe(replaceValue); } } else if (machineVars != null && machineVars.Contains(variable)) { + replaceValue = (string)machineVars[variable]; if (filenameSafeMode) { - replaceValue = MakePathSafe((string)machineVars[variable]); - } else { - replaceValue = (string)machineVars[variable]; + replaceValue = MakePathSafe(replaceValue); } } else if (captureDetails != null && captureDetails.MetaData != null && captureDetails.MetaData.ContainsKey(variable)) { - replaceValue = MakePathSafe(captureDetails.MetaData[variable]); + replaceValue = captureDetails.MetaData[variable]; + if (filenameSafeMode) { + replaceValue = MakePathSafe(replaceValue); + } } else { // Handle other variables // Default use "now" for the capture takeŽn @@ -264,10 +264,16 @@ namespace Greenshot.Helpers { replaceValue = capturetime.Second.ToString(); break; case "now": - replaceValue = MakeFilenameSafe(DateTime.Now.ToString(dateFormat)); + replaceValue = DateTime.Now.ToString(dateFormat); + if (filenameSafeMode) { + replaceValue = MakeFilenameSafe(replaceValue); + } break; case "capturetime": - replaceValue = MakeFilenameSafe(capturetime.ToString(dateFormat)); + replaceValue = capturetime.ToString(dateFormat); + if (filenameSafeMode) { + replaceValue = MakeFilenameSafe(replaceValue); + } break; case "NUM": conf.OutputFileIncrementingNumber++; @@ -280,7 +286,10 @@ namespace Greenshot.Helpers { break; case "title": - replaceValue = MakeFilenameSafe(title); + replaceValue = title; + if (filenameSafeMode) { + replaceValue = MakeFilenameSafe(replaceValue); + } break; } } @@ -350,7 +359,14 @@ namespace Greenshot.Helpers { ); } - private static string FillPattern(string pattern, ICaptureDetails captureDetails) { + /// + /// Fill the pattern wit the supplied details + /// + /// Pattern + /// CaptureDetails + /// Should the result be made "filename" safe? + /// Filled pattern + public static string FillPattern(string pattern, ICaptureDetails captureDetails, bool filenameSafeMode) { IDictionary processVars = null; IDictionary userVars = null; IDictionary machineVars = null; @@ -374,7 +390,7 @@ namespace Greenshot.Helpers { try { return VAR_REGEXP.Replace(pattern, - new MatchEvaluator(delegate(Match m) { return MatchVarEvaluator(m, captureDetails, processVars, userVars, machineVars, true); }) + new MatchEvaluator(delegate(Match m) { return MatchVarEvaluator(m, captureDetails, processVars, userVars, machineVars, filenameSafeMode); }) ); } catch (Exception e) { // adding additional data for bug tracking diff --git a/Greenshot/Helpers/PrintHelper.cs b/Greenshot/Helpers/PrintHelper.cs index 2a1d7895d..92c5d7f76 100644 --- a/Greenshot/Helpers/PrintHelper.cs +++ b/Greenshot/Helpers/PrintHelper.cs @@ -132,13 +132,14 @@ namespace Greenshot.Helpers { ContentAlignment alignment = pod.AllowPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft; // prepare timestamp - float dateStringWidth = 0; - float dateStringHeight = 0; - string dateString = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); - if (conf.OutputPrintTimestamp) { + float footerStringWidth = 0; + float footerStringHeight = 0; + string footerString = null; //DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); + if (conf.OutputPrintFooter) { + footerString = FilenameHelper.FillPattern(conf.OutputPrintFooterPattern, captureDetails, false); using (Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)) { - dateStringWidth = e.Graphics.MeasureString(dateString, f).Width; - dateStringHeight = e.Graphics.MeasureString(dateString, f).Height; + footerStringWidth = e.Graphics.MeasureString(footerString, f).Width; + footerStringHeight = e.Graphics.MeasureString(footerString, f).Height; } } @@ -146,7 +147,7 @@ namespace Greenshot.Helpers { RectangleF pageRect = e.PageSettings.PrintableArea; // Subtract the dateString height from the available area, this way the area stays free - pageRect.Height -= dateStringHeight; + pageRect.Height -= footerStringHeight; GraphicsUnit gu = GraphicsUnit.Pixel; RectangleF imageRect = image.GetBounds(ref gu); @@ -172,10 +173,10 @@ namespace Greenshot.Helpers { // align the image printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height), alignment); - if (conf.OutputPrintTimestamp) { + if (conf.OutputPrintFooter) { //printRect = new RectangleF(0, 0, printRect.Width, printRect.Height - (dateStringHeight * 2)); using (Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)) { - e.Graphics.DrawString(dateString, f, Brushes.Black, pageRect.Width / 2 - (dateStringWidth / 2), pageRect.Height); + e.Graphics.DrawString(footerString, f, Brushes.Black, pageRect.Width / 2 - (footerStringWidth / 2), pageRect.Height); } } if (conf.OutputPrintInverted) { diff --git a/GreenshotPlugin/Core/CoreConfiguration.cs b/GreenshotPlugin/Core/CoreConfiguration.cs index 0672fb45a..27e450be2 100644 --- a/GreenshotPlugin/Core/CoreConfiguration.cs +++ b/GreenshotPlugin/Core/CoreConfiguration.cs @@ -86,7 +86,7 @@ namespace GreenshotPlugin.Core { [IniProperty("OutputFilePath", Description="Output file path.")] public string OutputFilePath; - [IniProperty("OutputFileFilenamePattern", Description="Filename pattern for screenshot.", DefaultValue="${capturetime}_${title}")] + [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; @@ -122,8 +122,10 @@ namespace GreenshotPlugin.Core { public bool OutputPrintCenter; [IniProperty("OutputPrintInverted", LanguageKey="printoptions_inverted", Description="Print image inverted (use e.g. for console captures)", DefaultValue="false")] public bool OutputPrintInverted; - [IniProperty("OutputPrintTimestamp", LanguageKey="printoptions_timestamp", Description="Print timestamp on print?", DefaultValue="true")] - public bool OutputPrintTimestamp; + [IniProperty("OutputPrintFooter", LanguageKey = "printoptions_timestamp", Description = "Print footer on print?", DefaultValue = "true")] + public bool OutputPrintFooter; + [IniProperty("OutputPrintFooterPattern", Description = "Footer pattern", DefaultValue = "${capturetime:d\"D\"} ${capturetime:d\"T\"} - ${title}")] + public string OutputPrintFooterPattern; [IniProperty("UseProxy", Description="Use your global proxy?", DefaultValue="True")] public bool UseProxy; @@ -153,7 +155,7 @@ namespace GreenshotPlugin.Core { [IniProperty("NoDWMCaptureForProduct", Description="List of products for which DWM capturing doesn't work.", DefaultValue="Citrix ICA Client")] public List NoDWMCaptureForProduct; - [IniProperty("OptimizeForRDP", Description="Make some optimizations for remote desktop usage", DefaultValue="False")] + [IniProperty("OptimizeForRDP", Description="Make some optimizations for usage with remote desktop", DefaultValue="False")] public bool OptimizeForRDP; [IniProperty("ActiveTitleFixes", Description="The fixes that are active.")] @@ -227,6 +229,9 @@ namespace GreenshotPlugin.Core { /// object with the default value for the supplied property public override object GetDefault(string property) { switch(property) { + case "OutputPrintFooterPattern": + + break; case "PluginWhitelist": case "PluginBacklist": return new List();