Added some fixes for the IDestination code, allowing a Destination to supply dynamics without base. Also made the savetmpfile able to store in a supplied path.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2037 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-09-14 16:43:15 +00:00
parent c037b99d6e
commit 203a34ee6f
7 changed files with 52 additions and 24 deletions

View file

@ -164,10 +164,10 @@ namespace GreenshotOCR {
graphics.Clear(Color.White);
graphics.DrawImage(capturedImage, Point.Empty);
}
filePath = host.SaveToTmpFile(tmpImage, outputSettings);
filePath = host.SaveToTmpFile(tmpImage, outputSettings, null);
}
} else {
filePath = host.SaveToTmpFile(capturedImage, outputSettings);
filePath = host.SaveToTmpFile(capturedImage, outputSettings, null);
}
}

View file

@ -381,7 +381,7 @@ EndSelection:<<<<<<<4
// Set the HTML
if (config.ClipboardFormats.Contains(ClipboardFormat.HTML)) {
string tmpFile = ImageOutput.SaveToTmpFile(image, new OutputSettings(OutputFormat.png));
string tmpFile = ImageOutput.SaveToTmpFile(image, new OutputSettings(OutputFormat.png), null);
string html = getHTMLString(image, tmpFile);
ido.SetText(html, TextDataFormat.Html);
} else if (config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL)) {

View file

@ -350,11 +350,14 @@ namespace Greenshot.Helpers {
/// </summary>
/// <param name="image"></param>
/// <returns></returns>
public static string SaveToTmpFile(Image image, OutputSettings outputSettings) {
public static string SaveToTmpFile(Image image, OutputSettings outputSettings, string destinationPath) {
string tmpFile = Path.GetRandomFileName() + "." + outputSettings.Format.ToString();
// Prevent problems with "other characters", which could cause problems
tmpFile = Regex.Replace(tmpFile, @"[^\d\w\.]", "");
string tmpPath = Path.Combine(Path.GetTempPath(), tmpFile);
if (destinationPath == null) {
destinationPath = Path.GetTempPath();
}
string tmpPath = Path.Combine(destinationPath, tmpFile);
LOG.Debug("Creating TMP File : " + tmpPath);
try {

View file

@ -99,8 +99,8 @@ namespace Greenshot.Helpers {
ImageOutput.SaveToStream(img, stream, outputSettings);
}
public string SaveToTmpFile(Image img, OutputSettings outputSettings) {
return ImageOutput.SaveToTmpFile(img, 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) {

View file

@ -132,18 +132,29 @@ namespace GreenshotPlugin.Core {
}
if (subDestinations.Count > 0) {
subDestinations.Sort();
ToolStripMenuItem destinationMenuItem = new ToolStripMenuItem(Description);
ToolStripMenuItem destinationMenuItem = null;
if (!useDynamicsOnly) {
destinationMenuItem = new ToolStripMenuItem(Description);
destinationMenuItem.Tag = this;
destinationMenuItem.Image = DisplayIcon;
destinationMenuItem.Click += destinationClickHandler;
basisMenuItem.DropDownItems.Add(destinationMenuItem);
foreach(IDestination subDestination in subDestinations) {
}
if (useDynamicsOnly && subDestinations.Count == 1) {
basisMenuItem.Tag = subDestinations[0];
basisMenuItem.Text = subDestinations[0].Description;
basisMenuItem.Click -= destinationClickHandler;
basisMenuItem.Click += destinationClickHandler;
} else {
foreach (IDestination subDestination in subDestinations) {
destinationMenuItem = new ToolStripMenuItem(subDestination.Description);
destinationMenuItem.Tag = subDestination;
destinationMenuItem.Image = subDestination.DisplayIcon;
destinationMenuItem.Click += destinationClickHandler;
basisMenuItem.DropDownItems.Add(destinationMenuItem);
}
}
} else {
// Setting base "click" only if there are no sub-destinations
@ -173,6 +184,12 @@ namespace GreenshotPlugin.Core {
}
}
public virtual bool useDynamicsOnly {
get {
return false;
}
}
public virtual bool isLinkable {
get {
return false;

View file

@ -159,6 +159,13 @@ namespace Greenshot.Plugin {
get;
}
/// <summary>
/// Returns if the destination is active
/// </summary>
bool useDynamicsOnly {
get;
}
/// <summary>
/// Returns true if this destination returns a link
/// </summary>

View file

@ -142,7 +142,8 @@ namespace Greenshot.Plugin {
/// </summary>
/// <param name="image">The Image to save</param>
/// <param name="outputSettings">OutputSettings</param>
string SaveToTmpFile(Image image, OutputSettings outputSettings);
/// <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