Refactoring some more classes, making easier code in plug-ins possible. Needed this for better testing some problems with the CreateShadow function.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2094 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-09-25 11:36:52 +00:00
parent 017b874de3
commit 9488200886
20 changed files with 128 additions and 190 deletions

View file

@ -162,7 +162,6 @@
<Compile Include="Forms\PrintOptionsDialog.Designer.cs"> <Compile Include="Forms\PrintOptionsDialog.Designer.cs">
<DependentUpon>PrintOptionsDialog.cs</DependentUpon> <DependentUpon>PrintOptionsDialog.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Forms\SaveImageFileDialog.cs" />
<Compile Include="Forms\SettingsForm.cs"> <Compile Include="Forms\SettingsForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -187,7 +186,6 @@
<None Include="App.config" /> <None Include="App.config" />
<None Include="Helpers\AviHelper.cs" /> <None Include="Helpers\AviHelper.cs" />
<Compile Include="Helpers\CaptureHelper.cs" /> <Compile Include="Helpers\CaptureHelper.cs" />
<Compile Include="Helpers\ClipboardHelper.cs" />
<Compile Include="Helpers\Colors.cs" /> <Compile Include="Helpers\Colors.cs" />
<Compile Include="Helpers\CopyData.cs" /> <Compile Include="Helpers\CopyData.cs" />
<Compile Include="Helpers\GeometryHelper.cs" /> <Compile Include="Helpers\GeometryHelper.cs" />
@ -216,7 +214,6 @@
<Compile Include="Helpers\MailHelper.cs" /> <Compile Include="Helpers\MailHelper.cs" />
<Compile Include="Helpers\PluginHelper.cs" /> <Compile Include="Helpers\PluginHelper.cs" />
<Compile Include="Helpers\PrintHelper.cs" /> <Compile Include="Helpers\PrintHelper.cs" />
<Compile Include="Helpers\ImageOutput.cs" />
<Compile Include="Helpers\ScaleHelper.cs" /> <Compile Include="Helpers\ScaleHelper.cs" />
<Compile Include="Helpers\SoundHelper.cs" /> <Compile Include="Helpers\SoundHelper.cs" />
<Compile Include="Helpers\StartupHelper.cs" /> <Compile Include="Helpers\StartupHelper.cs" />
@ -370,13 +367,6 @@
<None Include="log4net.xml"> <None Include="log4net.xml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory> <CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None> </None>
<Compile Include="Helpers\FilenameHelper.cs" />
<Compile Include="Forms\QualityDialog.Designer.cs">
<DependentUpon>QualityDialog.cs</DependentUpon>
</Compile>
<Compile Include="Forms\QualityDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\ColorDialog.Designer.cs"> <Compile Include="Forms\ColorDialog.Designer.cs">
<DependentUpon>ColorDialog.cs</DependentUpon> <DependentUpon>ColorDialog.cs</DependentUpon>
</Compile> </Compile>

View file

@ -301,7 +301,10 @@ namespace Greenshot.Helpers {
if (!string.IsNullOrEmpty(filename)) { if (!string.IsNullOrEmpty(filename)) {
try { try {
if (filename.EndsWith(".gsf")) { 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); DestinationHelper.GetDestination(EditorDestination.DESIGNATION).ExportCapture(true, surface, capture.CaptureDetails);
break; break;
} }

View file

@ -95,26 +95,6 @@ namespace Greenshot.Helpers {
#region Implementation of IGreenshotPluginHost #region Implementation of IGreenshotPluginHost
private ContextMenuStrip mainMenu = null; 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);
}
/// <summary> /// <summary>
/// Create a Thumbnail /// Create a Thumbnail
/// </summary> /// </summary>

View file

@ -123,7 +123,7 @@ namespace GreenshotConfluencePlugin {
Page selectedPage = page; Page selectedPage = page;
bool openPage = (page == null) && config.OpenPageAfterUpload; bool openPage = (page == null) && config.OpenPageAfterUpload;
string filename = ConfluencePlugin.Host.GetFilename(config.UploadFormat, captureDetails); string filename = FilenameHelper.GetFilename(config.UploadFormat, captureDetails);
if (selectedPage == null) { if (selectedPage == null) {
ConfluenceUpload confluenceUpload = new ConfluenceUpload(filename); ConfluenceUpload confluenceUpload = new ConfluenceUpload(filename);
Nullable<bool> dialogResult = confluenceUpload.ShowDialog(); Nullable<bool> dialogResult = confluenceUpload.ShowDialog();
@ -160,7 +160,7 @@ namespace GreenshotConfluencePlugin {
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
byte[] buffer; byte[] buffer;
using (MemoryStream stream = new MemoryStream()) { using (MemoryStream stream = new MemoryStream()) {
ConfluencePlugin.Host.SaveToStream(image, stream, outputSettings); ImageOutput.SaveToStream(image, stream, outputSettings);
// COPY buffer to array // COPY buffer to array
buffer = stream.ToArray(); buffer = stream.ToArray();
} }

View file

@ -75,12 +75,6 @@ namespace GreenshotConfluencePlugin {
} }
} }
public static IGreenshotHost Host {
get {
return host;
}
}
public ConfluencePlugin() { public ConfluencePlugin() {
} }

View file

@ -36,11 +36,9 @@ namespace ExternalCommand {
public class ExternalCommandDestination : AbstractDestination { public class ExternalCommandDestination : AbstractDestination {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExternalCommandDestination)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExternalCommandDestination));
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>(); private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
private IGreenshotHost host;
private string presetCommand; private string presetCommand;
public ExternalCommandDestination(IGreenshotHost host, string commando) { public ExternalCommandDestination(string commando) {
this.host = host;
this.presetCommand = commando; this.presetCommand = commando;
} }
@ -79,7 +77,7 @@ namespace ExternalCommand {
string fullPath = captureDetails.Filename; string fullPath = captureDetails.Filename;
if (fullPath == null) { if (fullPath == null) {
using (Image image = surface.GetImageForExport()) { using (Image image = surface.GetImageForExport()) {
fullPath = host.SaveNamedTmpFile(image, captureDetails, outputSettings); fullPath = ImageOutput.SaveNamedTmpFile(image, captureDetails, outputSettings);
} }
} }

View file

@ -42,7 +42,7 @@ namespace ExternalCommand {
public IEnumerable<IDestination> Destinations() { public IEnumerable<IDestination> Destinations() {
foreach(string command in config.commands) { foreach(string command in config.commands) {
yield return new ExternalCommandDestination(host, command); yield return new ExternalCommandDestination(command);
} }
} }

View file

@ -139,9 +139,9 @@ namespace GreenshotImgurPlugin {
public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadURL) { public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadURL) {
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
using (MemoryStream stream = new MemoryStream()) { using (MemoryStream stream = new MemoryStream()) {
host.SaveToStream(image, stream, outputSettings); ImageOutput.SaveToStream(image, stream, outputSettings);
try { try {
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails)); string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
ImgurInfo imgurInfo = null; ImgurInfo imgurInfo = null;
// Run upload in the background // Run upload in the background

View file

@ -103,13 +103,13 @@ namespace GreenshotJiraPlugin {
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); 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; byte[] buffer;
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
if (jira != null) { if (jira != null) {
using (MemoryStream stream = new MemoryStream()) { using (MemoryStream stream = new MemoryStream()) {
using (Image image = surface.GetImageForExport()) { using (Image image = surface.GetImageForExport()) {
jiraPlugin.Host.SaveToStream(image, stream, outputSettings); ImageOutput.SaveToStream(image, stream, outputSettings);
} }
// COPY stream to buffer // COPY stream to buffer
buffer = stream.ToArray(); buffer = stream.ToArray();
@ -136,7 +136,7 @@ namespace GreenshotJiraPlugin {
if (result == DialogResult.OK) { if (result == DialogResult.OK) {
using (MemoryStream stream = new MemoryStream()) { using (MemoryStream stream = new MemoryStream()) {
using (Image image = surface.GetImageForExport()) { using (Image image = surface.GetImageForExport()) {
jiraPlugin.Host.SaveToStream(image, stream, outputSettings); ImageOutput.SaveToStream(image, stream, outputSettings);
} }
// COPY stream to buffer // COPY stream to buffer
buffer = stream.ToArray(); buffer = stream.ToArray();

View file

@ -60,12 +60,6 @@ namespace GreenshotJiraPlugin {
} }
} }
public IGreenshotHost Host {
get {
return host;
}
}
public IEnumerable<IDestination> Destinations() { public IEnumerable<IDestination> Destinations() {
yield return new JiraDestination(this); yield return new JiraDestination(this);
} }

View file

@ -153,10 +153,10 @@ namespace GreenshotOCR {
graphics.Clear(Color.White); graphics.Clear(Color.White);
graphics.DrawImage(capturedImage, Point.Empty); graphics.DrawImage(capturedImage, Point.Empty);
} }
filePath = host.SaveToTmpFile(tmpImage, outputSettings, null); filePath = ImageOutput.SaveToTmpFile(tmpImage, outputSettings, null);
} }
} else { } else {
filePath = host.SaveToTmpFile(capturedImage, outputSettings, null); filePath = ImageOutput.SaveToTmpFile(capturedImage, outputSettings, null);
} }
LOG.Debug("Saved tmp file to: " + filePath); LOG.Debug("Saved tmp file to: " + filePath);

View file

@ -18,8 +18,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Greenshot { namespace GreenshotPlugin.Controls {
partial class QualityDialog : System.Windows.Forms.Form { partial class QualityDialog {
/// <summary> /// <summary>
/// Designer variable used to keep track of non-visual components. /// Designer variable used to keep track of non-visual components.
/// </summary> /// </summary>
@ -46,11 +46,11 @@ namespace Greenshot {
/// </summary> /// </summary>
private void InitializeComponent() 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.textBoxJpegQuality = new System.Windows.Forms.TextBox();
this.trackBarJpegQuality = new System.Windows.Forms.TrackBar(); this.trackBarJpegQuality = new System.Windows.Forms.TrackBar();
this.checkbox_dontaskagain = new System.Windows.Forms.CheckBox(); this.checkbox_dontaskagain = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.button_ok = new System.Windows.Forms.Button(); this.button_ok = new GreenshotPlugin.Controls.GreenshotButton();
this.checkBox_reduceColors = new System.Windows.Forms.CheckBox(); this.checkBox_reduceColors = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -61,7 +61,7 @@ namespace Greenshot {
this.label_choosejpegquality.Name = "label_choosejpegquality"; this.label_choosejpegquality.Name = "label_choosejpegquality";
this.label_choosejpegquality.Size = new System.Drawing.Size(268, 19); this.label_choosejpegquality.Size = new System.Drawing.Size(268, 19);
this.label_choosejpegquality.TabIndex = 15; this.label_choosejpegquality.TabIndex = 15;
this.label_choosejpegquality.Text = "Choose JPEG Quality"; this.label_choosejpegquality.LanguageKey = "jpegqualitydialog_choosejpegquality";
// //
// textBoxJpegQuality // textBoxJpegQuality
// //
@ -89,9 +89,9 @@ namespace Greenshot {
this.checkbox_dontaskagain.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.checkbox_dontaskagain.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkbox_dontaskagain.Location = new System.Drawing.Point(12, 106); this.checkbox_dontaskagain.Location = new System.Drawing.Point(12, 106);
this.checkbox_dontaskagain.Name = "checkbox_dontaskagain"; 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.Size = new System.Drawing.Size(268, 37);
this.checkbox_dontaskagain.TabIndex = 17; 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.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkbox_dontaskagain.UseVisualStyleBackColor = true; this.checkbox_dontaskagain.UseVisualStyleBackColor = true;
// //
@ -102,7 +102,7 @@ namespace Greenshot {
this.button_ok.Name = "button_ok"; this.button_ok.Name = "button_ok";
this.button_ok.Size = new System.Drawing.Size(75, 23); this.button_ok.Size = new System.Drawing.Size(75, 23);
this.button_ok.TabIndex = 18; this.button_ok.TabIndex = 18;
this.button_ok.Text = "OK"; this.button_ok.LanguageKey = "OK";
this.button_ok.UseVisualStyleBackColor = true; this.button_ok.UseVisualStyleBackColor = true;
this.button_ok.Click += new System.EventHandler(this.Button_okClick); 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.Name = "checkBox_reduceColors";
this.checkBox_reduceColors.Size = new System.Drawing.Size(95, 17); this.checkBox_reduceColors.Size = new System.Drawing.Size(95, 17);
this.checkBox_reduceColors.TabIndex = 19; this.checkBox_reduceColors.TabIndex = 19;
this.checkBox_reduceColors.Text = "Reduce colors"; this.checkBox_reduceColors.Text = "settings_reducecolors";
this.checkBox_reduceColors.UseVisualStyleBackColor = true; this.checkBox_reduceColors.UseVisualStyleBackColor = true;
// //
// QualityDialog // QualityDialog
@ -132,17 +132,17 @@ namespace Greenshot {
this.MinimizeBox = false; this.MinimizeBox = false;
this.Name = "QualityDialog"; this.Name = "QualityDialog";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Text = "QualityDialog"; this.LanguageKey = "qualitydialog_title";
((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
} }
private System.Windows.Forms.Button button_ok; private GreenshotPlugin.Controls.GreenshotButton button_ok;
private System.Windows.Forms.CheckBox checkbox_dontaskagain; private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_dontaskagain;
private System.Windows.Forms.TrackBar trackBarJpegQuality; private System.Windows.Forms.TrackBar trackBarJpegQuality;
private System.Windows.Forms.TextBox textBoxJpegQuality; 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; private System.Windows.Forms.CheckBox checkBox_reduceColors;
} }
} }

View file

@ -20,21 +20,21 @@
*/ */
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
using Greenshot.Configuration;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using Greenshot.IniFile; using Greenshot.IniFile;
using Greenshot.Plugin; using Greenshot.Plugin;
namespace Greenshot { namespace GreenshotPlugin.Controls {
/// <summary> /// <summary>
/// Description of JpegQualityDialog. /// Description of JpegQualityDialog.
/// </summary> /// </summary>
public partial class QualityDialog : Form { public partial class QualityDialog : GreenshotForm {
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>(); private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
public OutputSettings Settings { public OutputSettings Settings {
get; get;
set; set;
} }
public QualityDialog(OutputSettings outputSettings) { public QualityDialog(OutputSettings outputSettings) {
Settings = outputSettings; Settings = outputSettings;
// //
@ -48,7 +48,6 @@ namespace Greenshot {
this.trackBarJpegQuality.Value = Settings.JPGQuality; this.trackBarJpegQuality.Value = Settings.JPGQuality;
this.textBoxJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format); this.textBoxJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format);
this.textBoxJpegQuality.Text = Settings.JPGQuality.ToString(); this.textBoxJpegQuality.Text = Settings.JPGQuality.ToString();
UpdateUI();
WindowDetails.ToForeground(Handle); 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) { void TrackBarJpegQualityScroll(object sender, System.EventArgs e) {
textBoxJpegQuality.Text = trackBarJpegQuality.Value.ToString(); textBoxJpegQuality.Text = trackBarJpegQuality.Value.ToString();
} }

View file

@ -22,12 +22,11 @@ using System;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using Greenshot.Helpers;
using Greenshot.Plugin; using Greenshot.Plugin;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using Greenshot.IniFile; using Greenshot.IniFile;
namespace Greenshot.Forms { namespace GreenshotPlugin.Controls {
/// <summary> /// <summary>
/// Custom dialog for saving images, wraps SaveFileDialog. /// Custom dialog for saving images, wraps SaveFileDialog.
/// For some reason SFD is sealed :( /// For some reason SFD is sealed :(

View file

@ -28,13 +28,12 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using Greenshot.Configuration;
using GreenshotPlugin.UnmanagedHelpers; using GreenshotPlugin.UnmanagedHelpers;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using Greenshot.IniFile; using Greenshot.IniFile;
using Greenshot.Plugin; using Greenshot.Plugin;
namespace Greenshot.Helpers { namespace GreenshotPlugin.Core {
/// <summary> /// <summary>
/// Description of ClipboardHelper. /// Description of ClipboardHelper.
/// </summary> /// </summary>
@ -141,9 +140,9 @@ EndSelection:<<<<<<<4
string messageText = null; string messageText = null;
string clipboardOwner = GetClipboardOwner(); string clipboardOwner = GetClipboardOwner();
if (clipboardOwner != null) { if (clipboardOwner != null) {
messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner); messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner);
} else { } else {
messageText = Language.GetString(LangKey.clipboard_error); messageText = Language.GetString("clipboard_error");
} }
LOG.Error(messageText, ee); LOG.Error(messageText, ee);
} else { } else {
@ -172,9 +171,9 @@ EndSelection:<<<<<<<4
string messageText = null; string messageText = null;
string clipboardOwner = GetClipboardOwner(); string clipboardOwner = GetClipboardOwner();
if (clipboardOwner != null) { if (clipboardOwner != null) {
messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner); messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner);
} else { } else {
messageText = Language.GetString(LangKey.clipboard_error); messageText = Language.GetString("clipboard_error");
} }
LOG.Error(messageText, ee); LOG.Error(messageText, ee);
} else { } else {
@ -204,9 +203,9 @@ EndSelection:<<<<<<<4
string messageText = null; string messageText = null;
string clipboardOwner = GetClipboardOwner(); string clipboardOwner = GetClipboardOwner();
if (clipboardOwner != null) { if (clipboardOwner != null) {
messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner); messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner);
} else { } else {
messageText = Language.GetString(LangKey.clipboard_error); messageText = Language.GetString("clipboard_error");
} }
LOG.Error(messageText, ee); LOG.Error(messageText, ee);
} else { } else {
@ -247,9 +246,9 @@ EndSelection:<<<<<<<4
string messageText = null; string messageText = null;
string clipboardOwner = GetClipboardOwner(); string clipboardOwner = GetClipboardOwner();
if (clipboardOwner != null) { if (clipboardOwner != null) {
messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner); messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner);
} else { } else {
messageText = Language.GetString(LangKey.clipboard_error); messageText = Language.GetString("clipboard_error");
} }
LOG.Error(messageText, ee); LOG.Error(messageText, ee);
} else { } else {
@ -279,9 +278,9 @@ EndSelection:<<<<<<<4
string messageText = null; string messageText = null;
string clipboardOwner = GetClipboardOwner(); string clipboardOwner = GetClipboardOwner();
if (clipboardOwner != null) { if (clipboardOwner != null) {
messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner); messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner);
} else { } else {
messageText = Language.GetString(LangKey.clipboard_error); messageText = Language.GetString("clipboard_error");
} }
LOG.Error(messageText, ee); LOG.Error(messageText, ee);
} else { } else {

View file

@ -1,4 +1,4 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
* *
@ -28,7 +28,7 @@ using Greenshot.Plugin;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using Greenshot.IniFile; using Greenshot.IniFile;
namespace Greenshot.Helpers { namespace GreenshotPlugin.Core {
public static class FilenameHelper { public static class FilenameHelper {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(FilenameHelper)); private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(FilenameHelper));
private static readonly Regex VAR_REGEXP = new Regex(@"\${(?<variable>[^:}]+)[:]?(?<parameters>[^}]*)}", RegexOptions.Compiled); private static readonly Regex VAR_REGEXP = new Regex(@"\${(?<variable>[^:}]+)[:]?(?<parameters>[^}]*)}", RegexOptions.Compiled);
@ -95,6 +95,21 @@ namespace Greenshot.Helpers {
return FillPattern(pattern, captureDetails, true) + "." + imageFormat.ToString().ToLower(); return FillPattern(pattern, captureDetails, true) + "." + imageFormat.ToString().ToLower();
} }
/// <summary>
/// Return a filename for the current image format (png,jpg etc) with the default file pattern
/// that is specified in the configuration
/// </summary>
/// <param name="format">A string with the format</param>
/// <returns>The filename which should be used to save the image</returns>
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);
}
/// <summary> /// <summary>
/// This method will be called by the regexp.replace as a MatchEvaluator delegate! /// This method will be called by the regexp.replace as a MatchEvaluator delegate!
/// Will delegate this to the MatchVarEvaluatorInternal and catch any exceptions /// Will delegate this to the MatchVarEvaluatorInternal and catch any exceptions
@ -139,7 +154,8 @@ namespace Greenshot.Helpers {
string[] padParams = parameter.Substring(1).Split(new char[] { ',' }); string[] padParams = parameter.Substring(1).Split(new char[] { ',' });
try { try {
padWidth = int.Parse(padParams[0]); padWidth = int.Parse(padParams[0]);
} catch {}; } catch {
};
if (padParams.Length > 1) { if (padParams.Length > 1) {
padChar = padParams[1][0]; padChar = padParams[1][0];
} }
@ -196,7 +212,7 @@ namespace Greenshot.Helpers {
} }
} else { } else {
// Handle other variables // Handle other variables
// Default use "now" for the capture take´n // Default use "now" for the capture take´n
DateTime capturetime = DateTime.Now; DateTime capturetime = DateTime.Now;
// Use default application name for title // Use default application name for title
string title = Application.ProductName; string title = Application.ProductName;
@ -355,7 +371,9 @@ namespace Greenshot.Helpers {
} }
return VAR_REGEXP.Replace(pattern, 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,7 +408,9 @@ namespace Greenshot.Helpers {
try { try {
return VAR_REGEXP.Replace(pattern, 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) { } catch (Exception e) {
// adding additional data for bug tracking // adding additional data for bug tracking

View file

@ -1,4 +1,4 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
* *
@ -26,14 +26,12 @@ using System.Reflection;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows.Forms;
using Greenshot.Configuration;
using Greenshot.Forms;
using Greenshot.Plugin; using Greenshot.Plugin;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using Greenshot.IniFile; using Greenshot.IniFile;
using Greenshot.Drawing; using GreenshotPlugin.Controls;
namespace Greenshot.Helpers { namespace GreenshotPlugin.Core {
/// <summary> /// <summary>
/// Description of ImageOutput. /// Description of ImageOutput.
/// </summary> /// </summary>
@ -167,7 +165,7 @@ namespace Greenshot.Helpers {
/// </summary> /// </summary>
/// <param name="surface">Surface to save</param> /// <param name="surface">Surface to save</param>
/// <param name="fullPath">Path to file</param> /// <param name="fullPath">Path to file</param>
public static void SaveGreenshotSurface(Surface surface, string fullPath) { public static void SaveGreenshotSurface(ISurface surface, string fullPath) {
fullPath = FilenameHelper.MakeFQFilenameSafe(fullPath); fullPath = FilenameHelper.MakeFQFilenameSafe(fullPath);
string path = Path.GetDirectoryName(fullPath); string path = Path.GetDirectoryName(fullPath);
// Get output settings from the configuration // Get output settings from the configuration
@ -192,8 +190,7 @@ namespace Greenshot.Helpers {
/// </summary> /// </summary>
/// <param name="fullPath"></param> /// <param name="fullPath"></param>
/// <returns></returns> /// <returns></returns>
public static Surface LoadGreenshotSurface(string fullPath) { public static ISurface LoadGreenshotSurface(string fullPath, ISurface returnSurface) {
Surface returnSurface = null;
if (string.IsNullOrEmpty(fullPath)) { if (string.IsNullOrEmpty(fullPath)) {
return null; return null;
} }
@ -210,7 +207,6 @@ namespace Greenshot.Helpers {
LOG.DebugFormat("Loaded {0} with Size {1}x{2} and PixelFormat {3}", fullPath, tmpImage.Width, tmpImage.Height, tmpImage.PixelFormat); LOG.DebugFormat("Loaded {0} with Size {1}x{2} and PixelFormat {3}", fullPath, tmpImage.Width, tmpImage.Height, tmpImage.PixelFormat);
fileBitmap = ImageHelper.Clone(tmpImage); fileBitmap = ImageHelper.Clone(tmpImage);
} }
returnSurface = new Surface(fileBitmap);
imageFileStream.Seek(-8, SeekOrigin.End); imageFileStream.Seek(-8, SeekOrigin.End);
long bytesWritten = 0; long bytesWritten = 0;
using (BinaryReader reader = new BinaryReader(imageFileStream)) { using (BinaryReader reader = new BinaryReader(imageFileStream)) {
@ -310,7 +306,7 @@ namespace Greenshot.Helpers {
conf.OutputFileAsFullpath = fileNameWithExtension; conf.OutputFileAsFullpath = fileNameWithExtension;
IniConfig.Save(); IniConfig.Save();
} catch (System.Runtime.InteropServices.ExternalException) { } catch (System.Runtime.InteropServices.ExternalException) {
MessageBox.Show(Language.GetFormattedString(LangKey.error_nowriteaccess,saveImageFileDialog.FileName).Replace(@"\\",@"\"), Language.GetString(LangKey.error)); MessageBox.Show(Language.GetFormattedString("error_nowriteaccess", saveImageFileDialog.FileName).Replace(@"\\", @"\"), Language.GetString("error"));
} }
} }
return returnValue; return returnValue;

View file

@ -215,6 +215,13 @@
<Compile Include="Controls\PleaseWaitForm.Designer.cs"> <Compile Include="Controls\PleaseWaitForm.Designer.cs">
<DependentUpon>PleaseWaitForm.cs</DependentUpon> <DependentUpon>PleaseWaitForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Controls\QualityDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Controls\QualityDialog.Designer.cs">
<DependentUpon>QualityDialog.cs</DependentUpon>
</Compile>
<Compile Include="Controls\SaveImageFileDialog.cs" />
<Compile Include="Controls\ThumbnailForm.cs"> <Compile Include="Controls\ThumbnailForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -223,9 +230,12 @@
<Compile Include="Core\AccessibleHelper.cs" /> <Compile Include="Core\AccessibleHelper.cs" />
<Compile Include="Core\BitmapBuffer.cs" /> <Compile Include="Core\BitmapBuffer.cs" />
<Compile Include="Core\Cache.cs" /> <Compile Include="Core\Cache.cs" />
<Compile Include="Core\ClipboardHelper.cs" />
<Compile Include="Core\CoreConfiguration.cs" /> <Compile Include="Core\CoreConfiguration.cs" />
<Compile Include="Core\CredentialsHelper.cs" /> <Compile Include="Core\CredentialsHelper.cs" />
<Compile Include="Core\EncryptionHelper.cs" /> <Compile Include="Core\EncryptionHelper.cs" />
<Compile Include="Core\FilenameHelper.cs" />
<Compile Include="Core\ImageOutput.cs" />
<Compile Include="Core\InterfaceUtils.cs" /> <Compile Include="Core\InterfaceUtils.cs" />
<Compile Include="Core\DisplayKeyAttribute.cs" /> <Compile Include="Core\DisplayKeyAttribute.cs" />
<Compile Include="Core\EmailConfigHelper.cs" /> <Compile Include="Core\EmailConfigHelper.cs" />
@ -275,15 +285,7 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="IniFile" /> <Folder Include="Interfaces\Drawing\Filters\" />
<Folder Include="Interfaces\Drawing" />
<Folder Include="Interfaces\Drawing\Filters" />
<Folder Include="Interfaces\Forms" />
<Folder Include="Interfaces" />
<Folder Include="Core" />
<Folder Include="Interfaces\Plugin" />
<Folder Include="Controls" />
<Folder Include="UnmanagedHelpers" />
</ItemGroup> </ItemGroup>
<PropertyGroup> <PropertyGroup>
<PreBuildEvent>rmdir /S /Q "$(SolutionDir)bin\$(Configuration)\Plugins" <PreBuildEvent>rmdir /S /Q "$(SolutionDir)bin\$(Configuration)\Plugins"

View file

@ -24,6 +24,7 @@ using System.Drawing.Imaging;
using System.Windows.Forms; using System.Windows.Forms;
using Greenshot.Plugin.Drawing; using Greenshot.Plugin.Drawing;
using System.IO;
namespace Greenshot.Plugin { namespace Greenshot.Plugin {
/// <summary> /// <summary>
@ -111,6 +112,8 @@ namespace Greenshot.Plugin {
ICursorContainer AddCursorContainer(string filename, int x, int y); ICursorContainer AddCursorContainer(string filename, int x, int y);
IIconContainer AddIconContainer(string filename, int x, int y); IIconContainer AddIconContainer(string filename, int x, int y);
IMetafileContainer AddMetafileContainer(string filename, int x, int y); IMetafileContainer AddMetafileContainer(string filename, int x, int y);
long SaveElementsToStream(Stream stream);
void LoadElementsFromStream(Stream stream);
bool HasSelectedElements(); bool HasSelectedElements();
void RemoveSelectedElements(); void RemoveSelectedElements();

View file

@ -129,38 +129,6 @@ namespace Greenshot.Plugin {
get; get;
} }
/// <summary>
/// Saves the image to the supplied stream using the specified extension as the format
/// </summary>
/// <param name="image">The Image to save</param>
/// <param name="stream">The Stream to save to</param>
/// <param name="outputSettings">OutputSettings</param>
void SaveToStream(Image image, Stream stream, OutputSettings outputSettings);
/// <summary>
/// Saves the image to a temp file (random name) using the specified outputformat
/// </summary>
/// <param name="image">The Image to save</param>
/// <param name="outputSettings">OutputSettings</param>
/// <param name="destinationPath">destination path, can be empty</param>
string SaveToTmpFile(Image image, OutputSettings outputSettings, string destinationPath);
/// <summary>
/// Saves the image to a temp file, but the name is build with the capture details & pattern
/// </summary>
/// <param name="image">The Image to save</param>
/// <param name="captureDetails">captureDetails with the information to build the filename</param>
/// <param name="outputSettings">OutputSettings</param>
string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings);
/// <summary>
/// Return a filename for the current image format (png,jpg etc) with the default file pattern
/// that is specified in the configuration
/// </summary>
/// <param name="format">A string with the format</param>
/// <returns>The filename which should be used to save the image</returns>
string GetFilename(OutputFormat format, ICaptureDetails captureDetails);
/// <summary> /// <summary>
/// Create a Thumbnail /// Create a Thumbnail
/// </summary> /// </summary>