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.Clear(Color.White);
graphics.DrawImage(capturedImage, Point.Empty); graphics.DrawImage(capturedImage, Point.Empty);
} }
filePath = host.SaveToTmpFile(tmpImage, outputSettings); filePath = host.SaveToTmpFile(tmpImage, outputSettings, null);
} }
} else { } else {
filePath = host.SaveToTmpFile(capturedImage, outputSettings); filePath = host.SaveToTmpFile(capturedImage, outputSettings, null);
} }
} }

View file

@ -381,7 +381,7 @@ EndSelection:<<<<<<<4
// Set the HTML // Set the HTML
if (config.ClipboardFormats.Contains(ClipboardFormat.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); string html = getHTMLString(image, tmpFile);
ido.SetText(html, TextDataFormat.Html); ido.SetText(html, TextDataFormat.Html);
} else if (config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL)) { } else if (config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL)) {

View file

@ -350,11 +350,14 @@ namespace Greenshot.Helpers {
/// </summary> /// </summary>
/// <param name="image"></param> /// <param name="image"></param>
/// <returns></returns> /// <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(); string tmpFile = Path.GetRandomFileName() + "." + outputSettings.Format.ToString();
// Prevent problems with "other characters", which could cause problems // Prevent problems with "other characters", which could cause problems
tmpFile = Regex.Replace(tmpFile, @"[^\d\w\.]", ""); 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); LOG.Debug("Creating TMP File : " + tmpPath);
try { try {

View file

@ -99,8 +99,8 @@ namespace Greenshot.Helpers {
ImageOutput.SaveToStream(img, stream, outputSettings); ImageOutput.SaveToStream(img, stream, outputSettings);
} }
public string SaveToTmpFile(Image img, OutputSettings outputSettings) { public string SaveToTmpFile(Image img, OutputSettings outputSettings, string destinationPath) {
return ImageOutput.SaveToTmpFile(img, outputSettings); return ImageOutput.SaveToTmpFile(img, outputSettings, destinationPath);
} }
public string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings) { public string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings) {

View file

@ -35,7 +35,7 @@ namespace GreenshotPlugin.Core {
/// <summary> /// <summary>
/// Description of AbstractDestination. /// Description of AbstractDestination.
/// </summary> /// </summary>
public abstract class AbstractDestination : IDestination { public abstract class AbstractDestination : IDestination {
private const string PATH_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"; private const string PATH_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\";
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AbstractDestination)); private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AbstractDestination));
private static CoreConfiguration configuration = IniConfig.GetIniSection<CoreConfiguration>(); private static CoreConfiguration configuration = IniConfig.GetIniSection<CoreConfiguration>();
@ -124,26 +124,37 @@ namespace GreenshotPlugin.Core {
basisMenuItem.DropDownOpening += delegate (object source, EventArgs eventArgs) { basisMenuItem.DropDownOpening += delegate (object source, EventArgs eventArgs) {
if (basisMenuItem.DropDownItems.Count == 0) { if (basisMenuItem.DropDownItems.Count == 0) {
List<IDestination> subDestinations = new List<IDestination>(); List<IDestination> subDestinations = new List<IDestination>();
// Fixing Bug #3536968 by catching the COMException (every exception) and not displaying the "subDestinations" // Fixing Bug #3536968 by catching the COMException (every exception) and not displaying the "subDestinations"
try { try {
subDestinations.AddRange(DynamicDestinations()); subDestinations.AddRange(DynamicDestinations());
} catch(Exception ex) { } catch(Exception ex) {
LOG.ErrorFormat("Skipping {0}, due to the following error: {1}", Description, ex.Message); LOG.ErrorFormat("Skipping {0}, due to the following error: {1}", Description, ex.Message);
} }
if (subDestinations.Count > 0) { if (subDestinations.Count > 0) {
subDestinations.Sort(); subDestinations.Sort();
ToolStripMenuItem destinationMenuItem = new ToolStripMenuItem(Description);
destinationMenuItem.Tag = this; ToolStripMenuItem destinationMenuItem = null;
destinationMenuItem.Image = DisplayIcon; if (!useDynamicsOnly) {
destinationMenuItem.Click += destinationClickHandler; destinationMenuItem = new ToolStripMenuItem(Description);
basisMenuItem.DropDownItems.Add(destinationMenuItem); destinationMenuItem.Tag = this;
foreach(IDestination subDestination in subDestinations) { destinationMenuItem.Image = DisplayIcon;
destinationMenuItem = new ToolStripMenuItem(subDestination.Description);
destinationMenuItem.Tag = subDestination;
destinationMenuItem.Image = subDestination.DisplayIcon;
destinationMenuItem.Click += destinationClickHandler; destinationMenuItem.Click += destinationClickHandler;
basisMenuItem.DropDownItems.Add(destinationMenuItem); basisMenuItem.DropDownItems.Add(destinationMenuItem);
} }
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 { } else {
// Setting base "click" only if there are no sub-destinations // 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 { public virtual bool isLinkable {
get { get {
return false; return false;

View file

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

View file

@ -142,7 +142,8 @@ namespace Greenshot.Plugin {
/// </summary> /// </summary>
/// <param name="image">The Image to save</param> /// <param name="image">The Image to save</param>
/// <param name="outputSettings">OutputSettings</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> /// <summary>
/// Saves the image to a temp file, but the name is build with the capture details & pattern /// Saves the image to a temp file, but the name is build with the capture details & pattern