diff --git a/Greenshot/Greenshot.csproj b/Greenshot/Greenshot.csproj index 3c955d9cb..40623cf9c 100644 --- a/Greenshot/Greenshot.csproj +++ b/Greenshot/Greenshot.csproj @@ -162,7 +162,6 @@ PrintOptionsDialog.cs - Form @@ -187,7 +186,6 @@ - @@ -216,7 +214,6 @@ - @@ -370,13 +367,6 @@ Never - - - QualityDialog.cs - - - Form - ColorDialog.cs diff --git a/Greenshot/Helpers/CaptureHelper.cs b/Greenshot/Helpers/CaptureHelper.cs index cf68ea91e..19d05abbd 100644 --- a/Greenshot/Helpers/CaptureHelper.cs +++ b/Greenshot/Helpers/CaptureHelper.cs @@ -301,7 +301,10 @@ namespace Greenshot.Helpers { if (!string.IsNullOrEmpty(filename)) { try { if (filename.EndsWith(".gsf")) { - ISurface surface = ImageOutput.LoadGreenshotSurface(filename); + + ISurface surface = new Surface(); + + surface = ImageOutput.LoadGreenshotSurface(filename, surface); DestinationHelper.GetDestination(EditorDestination.DESIGNATION).ExportCapture(true, surface, capture.CaptureDetails); break; } diff --git a/Greenshot/Helpers/PluginHelper.cs b/Greenshot/Helpers/PluginHelper.cs index 945130d0d..9ef182548 100644 --- a/Greenshot/Helpers/PluginHelper.cs +++ b/Greenshot/Helpers/PluginHelper.cs @@ -94,26 +94,6 @@ namespace Greenshot.Helpers { #region Implementation of IGreenshotPluginHost private ContextMenuStrip mainMenu = null; - - public void SaveToStream(Image img, Stream stream, OutputSettings outputSettings) { - ImageOutput.SaveToStream(img, stream, outputSettings); - } - - public string SaveToTmpFile(Image img, OutputSettings outputSettings, string destinationPath) { - return ImageOutput.SaveToTmpFile(img, outputSettings, destinationPath); - } - - public string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings) { - return ImageOutput.SaveNamedTmpFile(image, captureDetails, outputSettings); - } - - public string GetFilename(OutputFormat format, ICaptureDetails captureDetails) { - string pattern = conf.OutputFileFilenamePattern; - if (pattern == null || string.IsNullOrEmpty(pattern.Trim())) { - pattern = "greenshot ${capturetime}"; - } - return FilenameHelper.GetFilenameFromPattern(pattern, format, captureDetails); - } /// /// Create a Thumbnail diff --git a/GreenshotConfluencePlugin/ConfluenceDestination.cs b/GreenshotConfluencePlugin/ConfluenceDestination.cs index 771177da2..34f0450c2 100644 --- a/GreenshotConfluencePlugin/ConfluenceDestination.cs +++ b/GreenshotConfluencePlugin/ConfluenceDestination.cs @@ -123,7 +123,7 @@ namespace GreenshotConfluencePlugin { Page selectedPage = page; bool openPage = (page == null) && config.OpenPageAfterUpload; - string filename = ConfluencePlugin.Host.GetFilename(config.UploadFormat, captureDetails); + string filename = FilenameHelper.GetFilename(config.UploadFormat, captureDetails); if (selectedPage == null) { ConfluenceUpload confluenceUpload = new ConfluenceUpload(filename); Nullable dialogResult = confluenceUpload.ShowDialog(); @@ -160,7 +160,7 @@ namespace GreenshotConfluencePlugin { OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); byte[] buffer; using (MemoryStream stream = new MemoryStream()) { - ConfluencePlugin.Host.SaveToStream(image, stream, outputSettings); + ImageOutput.SaveToStream(image, stream, outputSettings); // COPY buffer to array buffer = stream.ToArray(); } diff --git a/GreenshotConfluencePlugin/ConfluencePlugin.cs b/GreenshotConfluencePlugin/ConfluencePlugin.cs index 26f660335..a602055b2 100644 --- a/GreenshotConfluencePlugin/ConfluencePlugin.cs +++ b/GreenshotConfluencePlugin/ConfluencePlugin.cs @@ -74,12 +74,6 @@ namespace GreenshotConfluencePlugin { return confluenceConnector; } } - - public static IGreenshotHost Host { - get { - return host; - } - } public ConfluencePlugin() { } diff --git a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs index fdd6e036a..a690885e6 100644 --- a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs +++ b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs @@ -36,11 +36,9 @@ namespace ExternalCommand { public class ExternalCommandDestination : AbstractDestination { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExternalCommandDestination)); private static ExternalCommandConfiguration config = IniConfig.GetIniSection(); - private IGreenshotHost host; private string presetCommand; - public ExternalCommandDestination(IGreenshotHost host, string commando) { - this.host = host; + public ExternalCommandDestination(string commando) { this.presetCommand = commando; } @@ -79,7 +77,7 @@ namespace ExternalCommand { string fullPath = captureDetails.Filename; if (fullPath == null) { using (Image image = surface.GetImageForExport()) { - fullPath = host.SaveNamedTmpFile(image, captureDetails, outputSettings); + fullPath = ImageOutput.SaveNamedTmpFile(image, captureDetails, outputSettings); } } diff --git a/GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs b/GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs index aadbec1a7..c227a13ef 100644 --- a/GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs +++ b/GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs @@ -42,7 +42,7 @@ namespace ExternalCommand { public IEnumerable Destinations() { foreach(string command in config.commands) { - yield return new ExternalCommandDestination(host, command); + yield return new ExternalCommandDestination(command); } } diff --git a/GreenshotImgurPlugin/ImgurPlugin.cs b/GreenshotImgurPlugin/ImgurPlugin.cs index 4fe33f2a6..8445547e0 100644 --- a/GreenshotImgurPlugin/ImgurPlugin.cs +++ b/GreenshotImgurPlugin/ImgurPlugin.cs @@ -139,9 +139,9 @@ namespace GreenshotImgurPlugin { public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadURL) { OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); using (MemoryStream stream = new MemoryStream()) { - host.SaveToStream(image, stream, outputSettings); + ImageOutput.SaveToStream(image, stream, outputSettings); try { - string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails)); + string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails)); ImgurInfo imgurInfo = null; // Run upload in the background diff --git a/GreenshotJiraPlugin/JiraDestination.cs b/GreenshotJiraPlugin/JiraDestination.cs index 80923f4b9..a3820bd6a 100644 --- a/GreenshotJiraPlugin/JiraDestination.cs +++ b/GreenshotJiraPlugin/JiraDestination.cs @@ -103,13 +103,13 @@ namespace GreenshotJiraPlugin { public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); - string filename = Path.GetFileName(jiraPlugin.Host.GetFilename(config.UploadFormat, captureDetails)); + string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails)); byte[] buffer; OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); if (jira != null) { using (MemoryStream stream = new MemoryStream()) { using (Image image = surface.GetImageForExport()) { - jiraPlugin.Host.SaveToStream(image, stream, outputSettings); + ImageOutput.SaveToStream(image, stream, outputSettings); } // COPY stream to buffer buffer = stream.ToArray(); @@ -136,7 +136,7 @@ namespace GreenshotJiraPlugin { if (result == DialogResult.OK) { using (MemoryStream stream = new MemoryStream()) { using (Image image = surface.GetImageForExport()) { - jiraPlugin.Host.SaveToStream(image, stream, outputSettings); + ImageOutput.SaveToStream(image, stream, outputSettings); } // COPY stream to buffer buffer = stream.ToArray(); diff --git a/GreenshotJiraPlugin/JiraPlugin.cs b/GreenshotJiraPlugin/JiraPlugin.cs index 4803a9d86..5c8641785 100644 --- a/GreenshotJiraPlugin/JiraPlugin.cs +++ b/GreenshotJiraPlugin/JiraPlugin.cs @@ -59,12 +59,6 @@ namespace GreenshotJiraPlugin { return jiraPluginAttributes; } } - - public IGreenshotHost Host { - get { - return host; - } - } public IEnumerable Destinations() { yield return new JiraDestination(this); diff --git a/GreenshotOCRPlugin/OCRPlugin.cs b/GreenshotOCRPlugin/OCRPlugin.cs index 6baa3ddae..109ba24e9 100644 --- a/GreenshotOCRPlugin/OCRPlugin.cs +++ b/GreenshotOCRPlugin/OCRPlugin.cs @@ -153,10 +153,10 @@ namespace GreenshotOCR { graphics.Clear(Color.White); graphics.DrawImage(capturedImage, Point.Empty); } - filePath = host.SaveToTmpFile(tmpImage, outputSettings, null); + filePath = ImageOutput.SaveToTmpFile(tmpImage, outputSettings, null); } } else { - filePath = host.SaveToTmpFile(capturedImage, outputSettings, null); + filePath = ImageOutput.SaveToTmpFile(capturedImage, outputSettings, null); } LOG.Debug("Saved tmp file to: " + filePath); diff --git a/Greenshot/Forms/QualityDialog.Designer.cs b/GreenshotPlugin/Controls/QualityDialog.Designer.cs similarity index 85% rename from Greenshot/Forms/QualityDialog.Designer.cs rename to GreenshotPlugin/Controls/QualityDialog.Designer.cs index 3681f993b..fe32acfce 100644 --- a/Greenshot/Forms/QualityDialog.Designer.cs +++ b/GreenshotPlugin/Controls/QualityDialog.Designer.cs @@ -18,8 +18,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -namespace Greenshot { - partial class QualityDialog : System.Windows.Forms.Form { +namespace GreenshotPlugin.Controls { + partial class QualityDialog { /// /// Designer variable used to keep track of non-visual components. /// @@ -46,11 +46,11 @@ namespace Greenshot { /// private void InitializeComponent() { - this.label_choosejpegquality = new System.Windows.Forms.Label(); + this.label_choosejpegquality = new GreenshotPlugin.Controls.GreenshotLabel(); this.textBoxJpegQuality = new System.Windows.Forms.TextBox(); this.trackBarJpegQuality = new System.Windows.Forms.TrackBar(); - this.checkbox_dontaskagain = new System.Windows.Forms.CheckBox(); - this.button_ok = new System.Windows.Forms.Button(); + this.checkbox_dontaskagain = new GreenshotPlugin.Controls.GreenshotCheckBox(); + this.button_ok = new GreenshotPlugin.Controls.GreenshotButton(); this.checkBox_reduceColors = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).BeginInit(); this.SuspendLayout(); @@ -61,7 +61,7 @@ namespace Greenshot { this.label_choosejpegquality.Name = "label_choosejpegquality"; this.label_choosejpegquality.Size = new System.Drawing.Size(268, 19); this.label_choosejpegquality.TabIndex = 15; - this.label_choosejpegquality.Text = "Choose JPEG Quality"; + this.label_choosejpegquality.LanguageKey = "jpegqualitydialog_choosejpegquality"; // // textBoxJpegQuality // @@ -89,9 +89,9 @@ namespace Greenshot { this.checkbox_dontaskagain.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.checkbox_dontaskagain.Location = new System.Drawing.Point(12, 106); this.checkbox_dontaskagain.Name = "checkbox_dontaskagain"; + this.checkbox_dontaskagain.LanguageKey = "qualitydialog_dontaskagain"; this.checkbox_dontaskagain.Size = new System.Drawing.Size(268, 37); this.checkbox_dontaskagain.TabIndex = 17; - this.checkbox_dontaskagain.Text = "Save as default quality and do not ask again."; this.checkbox_dontaskagain.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.checkbox_dontaskagain.UseVisualStyleBackColor = true; // @@ -102,7 +102,7 @@ namespace Greenshot { this.button_ok.Name = "button_ok"; this.button_ok.Size = new System.Drawing.Size(75, 23); this.button_ok.TabIndex = 18; - this.button_ok.Text = "OK"; + this.button_ok.LanguageKey = "OK"; this.button_ok.UseVisualStyleBackColor = true; this.button_ok.Click += new System.EventHandler(this.Button_okClick); // @@ -113,7 +113,7 @@ namespace Greenshot { this.checkBox_reduceColors.Name = "checkBox_reduceColors"; this.checkBox_reduceColors.Size = new System.Drawing.Size(95, 17); this.checkBox_reduceColors.TabIndex = 19; - this.checkBox_reduceColors.Text = "Reduce colors"; + this.checkBox_reduceColors.Text = "settings_reducecolors"; this.checkBox_reduceColors.UseVisualStyleBackColor = true; // // QualityDialog @@ -132,17 +132,17 @@ namespace Greenshot { this.MinimizeBox = false; this.Name = "QualityDialog"; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; - this.Text = "QualityDialog"; + this.LanguageKey = "qualitydialog_title"; ((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } - private System.Windows.Forms.Button button_ok; - private System.Windows.Forms.CheckBox checkbox_dontaskagain; + private GreenshotPlugin.Controls.GreenshotButton button_ok; + private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_dontaskagain; private System.Windows.Forms.TrackBar trackBarJpegQuality; private System.Windows.Forms.TextBox textBoxJpegQuality; - private System.Windows.Forms.Label label_choosejpegquality; + private GreenshotPlugin.Controls.GreenshotLabel label_choosejpegquality; private System.Windows.Forms.CheckBox checkBox_reduceColors; } } diff --git a/Greenshot/Forms/QualityDialog.cs b/GreenshotPlugin/Controls/QualityDialog.cs similarity index 81% rename from Greenshot/Forms/QualityDialog.cs rename to GreenshotPlugin/Controls/QualityDialog.cs index 2755107e5..4dc1af9df 100644 --- a/Greenshot/Forms/QualityDialog.cs +++ b/GreenshotPlugin/Controls/QualityDialog.cs @@ -20,21 +20,21 @@ */ using System; using System.Windows.Forms; -using Greenshot.Configuration; using GreenshotPlugin.Core; using Greenshot.IniFile; using Greenshot.Plugin; -namespace Greenshot { +namespace GreenshotPlugin.Controls { /// /// Description of JpegQualityDialog. /// - public partial class QualityDialog : Form { + public partial class QualityDialog : GreenshotForm { private static CoreConfiguration conf = IniConfig.GetIniSection(); public OutputSettings Settings { get; set; } + public QualityDialog(OutputSettings outputSettings) { Settings = outputSettings; // @@ -48,7 +48,6 @@ namespace Greenshot { this.trackBarJpegQuality.Value = Settings.JPGQuality; this.textBoxJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format); this.textBoxJpegQuality.Text = Settings.JPGQuality.ToString(); - UpdateUI(); WindowDetails.ToForeground(Handle); } @@ -63,13 +62,6 @@ namespace Greenshot { } } - void UpdateUI() { - this.Text = Language.GetString(LangKey.qualitydialog_title); - this.label_choosejpegquality.Text = Language.GetString(LangKey.jpegqualitydialog_choosejpegquality); - this.checkbox_dontaskagain.Text = Language.GetString(LangKey.qualitydialog_dontaskagain); - this.checkBox_reduceColors.Text = Language.GetString(LangKey.settings_reducecolors); - } - void TrackBarJpegQualityScroll(object sender, System.EventArgs e) { textBoxJpegQuality.Text = trackBarJpegQuality.Value.ToString(); } diff --git a/Greenshot/Forms/SaveImageFileDialog.cs b/GreenshotPlugin/Controls/SaveImageFileDialog.cs similarity index 96% rename from Greenshot/Forms/SaveImageFileDialog.cs rename to GreenshotPlugin/Controls/SaveImageFileDialog.cs index 0e3f6f883..377dec04c 100644 --- a/Greenshot/Forms/SaveImageFileDialog.cs +++ b/GreenshotPlugin/Controls/SaveImageFileDialog.cs @@ -22,12 +22,11 @@ using System; using System.IO; using System.Windows.Forms; -using Greenshot.Helpers; using Greenshot.Plugin; using GreenshotPlugin.Core; using Greenshot.IniFile; -namespace Greenshot.Forms { +namespace GreenshotPlugin.Controls { /// /// Custom dialog for saving images, wraps SaveFileDialog. /// For some reason SFD is sealed :( diff --git a/Greenshot/Helpers/ClipboardHelper.cs b/GreenshotPlugin/Core/ClipboardHelper.cs similarity index 92% rename from Greenshot/Helpers/ClipboardHelper.cs rename to GreenshotPlugin/Core/ClipboardHelper.cs index 2d91e1aa0..23252617d 100644 --- a/Greenshot/Helpers/ClipboardHelper.cs +++ b/GreenshotPlugin/Core/ClipboardHelper.cs @@ -28,13 +28,12 @@ using System.Text; using System.Threading; using System.Windows.Forms; -using Greenshot.Configuration; using GreenshotPlugin.UnmanagedHelpers; using GreenshotPlugin.Core; using Greenshot.IniFile; using Greenshot.Plugin; -namespace Greenshot.Helpers { +namespace GreenshotPlugin.Core { /// /// Description of ClipboardHelper. /// @@ -141,9 +140,9 @@ EndSelection:<<<<<<<4 string messageText = null; string clipboardOwner = GetClipboardOwner(); if (clipboardOwner != null) { - messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner); + messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner); } else { - messageText = Language.GetString(LangKey.clipboard_error); + messageText = Language.GetString("clipboard_error"); } LOG.Error(messageText, ee); } else { @@ -172,9 +171,9 @@ EndSelection:<<<<<<<4 string messageText = null; string clipboardOwner = GetClipboardOwner(); if (clipboardOwner != null) { - messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner); + messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner); } else { - messageText = Language.GetString(LangKey.clipboard_error); + messageText = Language.GetString("clipboard_error"); } LOG.Error(messageText, ee); } else { @@ -204,9 +203,9 @@ EndSelection:<<<<<<<4 string messageText = null; string clipboardOwner = GetClipboardOwner(); if (clipboardOwner != null) { - messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner); + messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner); } else { - messageText = Language.GetString(LangKey.clipboard_error); + messageText = Language.GetString("clipboard_error"); } LOG.Error(messageText, ee); } else { @@ -247,9 +246,9 @@ EndSelection:<<<<<<<4 string messageText = null; string clipboardOwner = GetClipboardOwner(); if (clipboardOwner != null) { - messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner); + messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner); } else { - messageText = Language.GetString(LangKey.clipboard_error); + messageText = Language.GetString("clipboard_error"); } LOG.Error(messageText, ee); } else { @@ -279,9 +278,9 @@ EndSelection:<<<<<<<4 string messageText = null; string clipboardOwner = GetClipboardOwner(); if (clipboardOwner != null) { - messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner); + messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner); } else { - messageText = Language.GetString(LangKey.clipboard_error); + messageText = Language.GetString("clipboard_error"); } LOG.Error(messageText, ee); } else { diff --git a/Greenshot/Helpers/FilenameHelper.cs b/GreenshotPlugin/Core/FilenameHelper.cs similarity index 85% rename from Greenshot/Helpers/FilenameHelper.cs rename to GreenshotPlugin/Core/FilenameHelper.cs index d0c7f59e8..026306dfb 100644 --- a/Greenshot/Helpers/FilenameHelper.cs +++ b/GreenshotPlugin/Core/FilenameHelper.cs @@ -1,4 +1,4 @@ -/* +/* * Greenshot - a free and open source screenshot tool * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom * @@ -28,7 +28,7 @@ using Greenshot.Plugin; using GreenshotPlugin.Core; using Greenshot.IniFile; -namespace Greenshot.Helpers { +namespace GreenshotPlugin.Core { public static class FilenameHelper { private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(FilenameHelper)); private static readonly Regex VAR_REGEXP = new Regex(@"\${(?[^:}]+)[:]?(?[^}]*)}", RegexOptions.Compiled); @@ -58,7 +58,7 @@ namespace Greenshot.Helpers { // Make the filename save! if (filename != null) { foreach (char disallowed in Path.GetInvalidFileNameChars()) { - filename = filename.Replace( disallowed.ToString(), UNSAFE_REPLACEMENT ); + filename = filename.Replace(disallowed.ToString(), UNSAFE_REPLACEMENT); } } return filename; @@ -73,7 +73,7 @@ namespace Greenshot.Helpers { // Make the path save! if (path != null) { foreach (char disallowed in Path.GetInvalidPathChars()) { - path = path.Replace( disallowed.ToString(), UNSAFE_REPLACEMENT ); + path = path.Replace(disallowed.ToString(), UNSAFE_REPLACEMENT); } } return path; @@ -94,7 +94,22 @@ namespace Greenshot.Helpers { public static string GetFilenameFromPattern(string pattern, OutputFormat imageFormat, ICaptureDetails captureDetails) { return FillPattern(pattern, captureDetails, true) + "." + imageFormat.ToString().ToLower(); } + + /// + /// Return a filename for the current image format (png,jpg etc) with the default file pattern + /// that is specified in the configuration + /// + /// A string with the format + /// The filename which should be used to save the image + public static string GetFilename(OutputFormat format, ICaptureDetails captureDetails) { + string pattern = conf.OutputFileFilenamePattern; + if (pattern == null || string.IsNullOrEmpty(pattern.Trim())) { + pattern = "greenshot ${capturetime}"; + } + return FilenameHelper.GetFilenameFromPattern(pattern, format, captureDetails); + } + /// /// This method will be called by the regexp.replace as a MatchEvaluator delegate! /// Will delegate this to the MatchVarEvaluatorInternal and catch any exceptions @@ -132,14 +147,15 @@ namespace Greenshot.Helpers { string parameters = match.Groups["parameters"].Value; if (parameters != null && parameters.Length > 0) { - string []parms = SPLIT_REGEXP.Split(parameters); - foreach(string parameter in parms) { - switch (parameter.Substring(0,1)) { + string[] parms = SPLIT_REGEXP.Split(parameters); + foreach (string parameter in parms) { + switch (parameter.Substring(0, 1)) { case "p": - string []padParams = parameter.Substring(1).Split(new char[] {','}); + string[] padParams = parameter.Substring(1).Split(new char[] { ',' }); try { padWidth = int.Parse(padParams[0]); - } catch {}; + } catch { + }; if (padParams.Length > 1) { padChar = padParams[1][0]; } @@ -150,12 +166,12 @@ namespace Greenshot.Helpers { dateFormat = dateFormat.Substring(1); } if (dateFormat.EndsWith("\"")) { - dateFormat = dateFormat.Substring(0, dateFormat.Length-1); + dateFormat = dateFormat.Substring(0, dateFormat.Length - 1); } break; case "s": - string range=parameter.Substring(1); - string []rangelist = range.Split(new char[] {','}); + string range = parameter.Substring(1); + string[] rangelist = range.Split(new char[] { ',' }); if (rangelist.Length > 0) { try { startIndex = int.Parse(rangelist[0]); @@ -196,11 +212,11 @@ namespace Greenshot.Helpers { } } else { // Handle other variables - // Default use "now" for the capture take´n + // Default use "now" for the capture take´n DateTime capturetime = DateTime.Now; // Use default application name for title string title = Application.ProductName; - + // Check if we have capture details if (captureDetails != null) { capturetime = captureDetails.DateTime; @@ -211,7 +227,7 @@ namespace Greenshot.Helpers { } } } - switch(variable) { + switch (variable) { case "domain": replaceValue = Environment.UserDomainName; break; @@ -277,13 +293,13 @@ namespace Greenshot.Helpers { break; case "NUM": conf.OutputFileIncrementingNumber++; - IniConfig.Save(); + IniConfig.Save(); replaceValue = conf.OutputFileIncrementingNumber.ToString(); if (padWidth == 0) { padWidth = -6; padChar = '0'; } - + break; case "title": replaceValue = title; @@ -294,7 +310,7 @@ namespace Greenshot.Helpers { } } // do padding - if (padWidth >0) { + if (padWidth > 0) { replaceValue = replaceValue.PadRight(padWidth, padChar); } else if (padWidth < 0) { replaceValue = replaceValue.PadLeft(-padWidth, padChar); @@ -322,7 +338,7 @@ namespace Greenshot.Helpers { } } } - + return replaceValue; } @@ -355,8 +371,10 @@ namespace Greenshot.Helpers { } return VAR_REGEXP.Replace(pattern, - new MatchEvaluator(delegate(Match m) { return MatchVarEvaluator(m, null, processVars, userVars, machineVars, filenameSafeMode); }) - ); + new MatchEvaluator(delegate(Match m) { + return MatchVarEvaluator(m, null, processVars, userVars, machineVars, filenameSafeMode); + }) + ); } /// @@ -390,8 +408,10 @@ namespace Greenshot.Helpers { try { return VAR_REGEXP.Replace(pattern, - new MatchEvaluator(delegate(Match m) { return MatchVarEvaluator(m, captureDetails, processVars, userVars, machineVars, filenameSafeMode); }) - ); + new MatchEvaluator(delegate(Match m) { + return MatchVarEvaluator(m, captureDetails, processVars, userVars, machineVars, filenameSafeMode); + }) + ); } catch (Exception e) { // adding additional data for bug tracking e.Data.Add("title", captureDetails.Title); diff --git a/Greenshot/Helpers/ImageOutput.cs b/GreenshotPlugin/Core/ImageOutput.cs similarity index 90% rename from Greenshot/Helpers/ImageOutput.cs rename to GreenshotPlugin/Core/ImageOutput.cs index 279c9d312..a17cea9b9 100644 --- a/Greenshot/Helpers/ImageOutput.cs +++ b/GreenshotPlugin/Core/ImageOutput.cs @@ -1,4 +1,4 @@ -/* +/* * Greenshot - a free and open source screenshot tool * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom * @@ -26,14 +26,12 @@ using System.Reflection; using System.Text.RegularExpressions; using System.Windows.Forms; -using Greenshot.Configuration; -using Greenshot.Forms; using Greenshot.Plugin; using GreenshotPlugin.Core; using Greenshot.IniFile; -using Greenshot.Drawing; +using GreenshotPlugin.Controls; -namespace Greenshot.Helpers { +namespace GreenshotPlugin.Core { /// /// Description of ImageOutput. /// @@ -41,8 +39,8 @@ namespace Greenshot.Helpers { private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImageOutput)); private static CoreConfiguration conf = IniConfig.GetIniSection(); private static readonly int PROPERTY_TAG_SOFTWARE_USED = 0x0131; - private static Cache tmpFileCache = new Cache(10*60*60, new Cache.CacheObjectExpired(RemoveExpiredTmpFile)); - + private static Cache tmpFileCache = new Cache(10 * 60 * 60, new Cache.CacheObjectExpired(RemoveExpiredTmpFile)); + /// /// Creates a PropertyItem (Metadata) to store with the image. /// For the possible ID's see: http://msdn.microsoft.com/de-de/library/system.drawing.imaging.propertyitem.id(v=vs.80).aspx @@ -54,16 +52,16 @@ namespace Greenshot.Helpers { private static PropertyItem CreatePropertyItem(int id, string text) { PropertyItem propertyItem = null; try { - ConstructorInfo ci = typeof(PropertyItem).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public , null, new Type[] { }, null); + ConstructorInfo ci = typeof(PropertyItem).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, null, new Type[] { }, null); propertyItem = (PropertyItem)ci.Invoke(null); // Make sure it's of type string - propertyItem.Type =2; + propertyItem.Type = 2; // Set the ID propertyItem.Id = id; // Set the text - byte [] byteString = System.Text.ASCIIEncoding.ASCII.GetBytes(text + " "); + byte[] byteString = System.Text.ASCIIEncoding.ASCII.GetBytes(text + " "); // Set Zero byte for String end. - byteString[byteString.Length-1] = 0; + byteString[byteString.Length - 1] = 0; propertyItem.Value = byteString; propertyItem.Len = text.Length + 1; } catch (Exception e) { @@ -161,13 +159,13 @@ namespace Greenshot.Helpers { } } } - + /// /// Save a Greenshot surface /// /// Surface to save /// Path to file - public static void SaveGreenshotSurface(Surface surface, string fullPath) { + public static void SaveGreenshotSurface(ISurface surface, string fullPath) { fullPath = FilenameHelper.MakeFQFilenameSafe(fullPath); string path = Path.GetDirectoryName(fullPath); // Get output settings from the configuration @@ -186,14 +184,13 @@ namespace Greenshot.Helpers { } } } - + /// /// Load a Greenshot surface /// /// /// - public static Surface LoadGreenshotSurface(string fullPath) { - Surface returnSurface = null; + public static ISurface LoadGreenshotSurface(string fullPath, ISurface returnSurface) { if (string.IsNullOrEmpty(fullPath)) { return null; } @@ -203,19 +200,18 @@ namespace Greenshot.Helpers { using (Stream imageFileStream = File.OpenRead(fullPath)) { // And fixed problem that the bitmap stream is disposed... by Cloning the image // This also ensures the bitmap is correctly created - + // We create a copy of the bitmap, so everything else can be disposed imageFileStream.Position = 0; using (Image tmpImage = Image.FromStream(imageFileStream, true, true)) { LOG.DebugFormat("Loaded {0} with Size {1}x{2} and PixelFormat {3}", fullPath, tmpImage.Width, tmpImage.Height, tmpImage.PixelFormat); fileBitmap = ImageHelper.Clone(tmpImage); } - returnSurface = new Surface(fileBitmap); imageFileStream.Seek(-8, SeekOrigin.End); long bytesWritten = 0; using (BinaryReader reader = new BinaryReader(imageFileStream)) { bytesWritten = reader.ReadInt64(); - imageFileStream.Seek(-(bytesWritten+8), SeekOrigin.End); + imageFileStream.Seek(-(bytesWritten + 8), SeekOrigin.End); returnSurface.LoadElementsFromStream(imageFileStream); } } @@ -224,7 +220,7 @@ namespace Greenshot.Helpers { } return returnSurface; } - + /// /// Saves image to specific path with specified quality /// @@ -246,7 +242,7 @@ namespace Greenshot.Helpers { if (extension != null) { format = (OutputFormat)Enum.Parse(typeof(OutputFormat), extension.ToLower()); } - } catch(ArgumentException ae) { + } catch (ArgumentException ae) { LOG.Warn("Couldn't parse extension: " + extension, ae); } if (!allowOverwrite && File.Exists(fullPath)) { @@ -291,7 +287,7 @@ namespace Greenshot.Helpers { Save(img, fullPath, allowOverwrite, outputSettings, conf.OutputFileCopyPathToClipboard); } #endregion - + #region save-as public static string SaveWithDialog(Image image) { return SaveWithDialog(image, null); @@ -309,8 +305,8 @@ namespace Greenshot.Helpers { 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)); + } catch (System.Runtime.InteropServices.ExternalException) { + MessageBox.Show(Language.GetFormattedString("error_nowriteaccess", saveImageFileDialog.FileName).Replace(@"\\", @"\"), Language.GetString("error")); } } return returnValue; @@ -327,10 +323,10 @@ namespace Greenshot.Helpers { filename = Regex.Replace(filename, @"[^\d\w\.]", "_"); // Remove multiple "_" filename = Regex.Replace(filename, @"_+", "_"); - string tmpFile = Path.Combine(Path.GetTempPath(),filename); + string tmpFile = Path.Combine(Path.GetTempPath(), filename); LOG.Debug("Creating TMP File: " + tmpFile); - + // 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 try { @@ -344,8 +340,8 @@ namespace Greenshot.Helpers { } return tmpFile; } - - /// + + /// /// Helper method to create a temp image file /// /// @@ -359,7 +355,7 @@ namespace Greenshot.Helpers { } string tmpPath = Path.Combine(destinationPath, tmpFile); LOG.Debug("Creating TMP File : " + tmpPath); - + try { ImageOutput.Save(image, tmpPath, true, outputSettings, false); tmpFileCache.Add(tmpPath, tmpPath); @@ -373,7 +369,7 @@ namespace Greenshot.Helpers { /// Cleanup all created tmpfiles /// public static void RemoveTmpFiles() { - foreach(string tmpFile in tmpFileCache.Elements) { + foreach (string tmpFile in tmpFileCache.Elements) { if (File.Exists(tmpFile)) { LOG.DebugFormat("Removing old temp file {0}", tmpFile); File.Delete(tmpFile); @@ -381,7 +377,7 @@ namespace Greenshot.Helpers { tmpFileCache.Remove(tmpFile); } } - + /// /// Cleanup handler for expired tempfiles /// diff --git a/GreenshotPlugin/GreenshotPlugin.csproj b/GreenshotPlugin/GreenshotPlugin.csproj index 49403b0ee..5437a720c 100644 --- a/GreenshotPlugin/GreenshotPlugin.csproj +++ b/GreenshotPlugin/GreenshotPlugin.csproj @@ -215,6 +215,13 @@ PleaseWaitForm.cs + + Form + + + QualityDialog.cs + + Form @@ -223,9 +230,12 @@ + + + @@ -275,15 +285,7 @@ - - - - - - - - - + rmdir /S /Q "$(SolutionDir)bin\$(Configuration)\Plugins" diff --git a/GreenshotPlugin/Interfaces/Generic.cs b/GreenshotPlugin/Interfaces/Generic.cs index fc3310495..f8fa9261b 100644 --- a/GreenshotPlugin/Interfaces/Generic.cs +++ b/GreenshotPlugin/Interfaces/Generic.cs @@ -24,6 +24,7 @@ using System.Drawing.Imaging; using System.Windows.Forms; using Greenshot.Plugin.Drawing; +using System.IO; namespace Greenshot.Plugin { /// @@ -111,6 +112,8 @@ namespace Greenshot.Plugin { ICursorContainer AddCursorContainer(string filename, int x, int y); IIconContainer AddIconContainer(string filename, int x, int y); IMetafileContainer AddMetafileContainer(string filename, int x, int y); + long SaveElementsToStream(Stream stream); + void LoadElementsFromStream(Stream stream); bool HasSelectedElements(); void RemoveSelectedElements(); diff --git a/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs b/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs index ef4ffb617..a6258b164 100644 --- a/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs +++ b/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs @@ -129,38 +129,6 @@ namespace Greenshot.Plugin { get; } - /// - /// Saves the image to the supplied stream using the specified extension as the format - /// - /// The Image to save - /// The Stream to save to - /// OutputSettings - void SaveToStream(Image image, Stream stream, OutputSettings outputSettings); - - /// - /// Saves the image to a temp file (random name) using the specified outputformat - /// - /// The Image to save - /// OutputSettings - /// destination path, can be empty - string SaveToTmpFile(Image image, OutputSettings outputSettings, string destinationPath); - - /// - /// Saves the image to a temp file, but the name is build with the capture details & pattern - /// - /// The Image to save - /// captureDetails with the information to build the filename - /// OutputSettings - string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings); - - /// - /// Return a filename for the current image format (png,jpg etc) with the default file pattern - /// that is specified in the configuration - /// - /// A string with the format - /// The filename which should be used to save the image - string GetFilename(OutputFormat format, ICaptureDetails captureDetails); - /// /// Create a Thumbnail ///