More changes for the PleaseWaitForm, rewrote the jira plug-in to use it. Added some more comments to the code. Fixed the context menu, added a separator for the plug-in entries. Fixed an issue with the PickerDestination, when an export is canceled the menu was shown visible in the task-bar.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1986 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-08-13 14:17:12 +00:00
commit 431b31cc5e
10 changed files with 130 additions and 77 deletions

View file

@ -34,7 +34,7 @@ using GreenshotPlugin.UnmanagedHelpers;
namespace Greenshot.Destinations { namespace Greenshot.Destinations {
/// <summary> /// <summary>
/// Description of PickerDestination. /// The PickerDestination shows a context menu with all possible destinations, so the user can "pick" one
/// </summary> /// </summary>
public class PickerDestination : AbstractDestination { public class PickerDestination : AbstractDestination {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PickerDestination)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PickerDestination));
@ -59,6 +59,14 @@ namespace Greenshot.Destinations {
} }
} }
/// <summary>
/// This method will create the destination picker menu
/// </summary>
/// <param name="addDynamics">Boolean if the dynamic values also need to be added</param>
/// <param name="surface">The surface which can be exported</param>
/// <param name="captureDetails">Details for the surface</param>
/// <param name="destinations">The list of destinations to show</param>
/// <returns></returns>
public static ContextMenuStrip CreatePickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable<IDestination> destinations) { public static ContextMenuStrip CreatePickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable<IDestination> destinations) {
ContextMenuStrip menu = new ContextMenuStrip(); ContextMenuStrip menu = new ContextMenuStrip();
menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) { menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {
@ -106,7 +114,8 @@ namespace Greenshot.Destinations {
} }
} else { } else {
LOG.Info("Export failed, showing menu again"); LOG.Info("Export failed, showing menu again");
menu.Show(); // This prevents the problem that the context menu shows in the task-bar
ShowMenuAtCursor(menu);
} }
} }
); );
@ -129,6 +138,10 @@ namespace Greenshot.Destinations {
return menu; return menu;
} }
/// <summary>
/// This method will show the supplied context menu at the mouse cursor, also makes sure it has focus and it's not visible in the taskbar.
/// </summary>
/// <param name="menu"></param>
public static void ShowMenuAtCursor(ContextMenuStrip menu) { public static void ShowMenuAtCursor(ContextMenuStrip menu) {
// find a suitable location // find a suitable location
Point location = Cursor.Position; Point location = Cursor.Position;
@ -146,6 +159,13 @@ namespace Greenshot.Destinations {
menu.Focus(); menu.Focus();
} }
/// <summary>
/// Export the capture with the destination picker
/// </summary>
/// <param name="manuallyInitiated">Did the user select this destination?</param>
/// <param name="surface">Surface to export</param>
/// <param name="captureDetails">Details of the capture</param>
/// <returns>true if export was made</returns>
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
List<IDestination> destinations = new List<IDestination>(); List<IDestination> destinations = new List<IDestination>();
foreach(IDestination destination in DestinationHelper.GetAllDestinations()) { foreach(IDestination destination in DestinationHelper.GetAllDestinations()) {

View file

@ -52,7 +52,7 @@ namespace Greenshot {
this.contextmenu_capturewindow = new GreenshotPlugin.Controls.GreenshotToolStripMenuItem(); this.contextmenu_capturewindow = new GreenshotPlugin.Controls.GreenshotToolStripMenuItem();
this.contextmenu_capturefullscreen = new GreenshotPlugin.Controls.GreenshotToolStripMenuItem(); this.contextmenu_capturefullscreen = new GreenshotPlugin.Controls.GreenshotToolStripMenuItem();
this.contextmenu_captureie = new GreenshotPlugin.Controls.GreenshotToolStripMenuItem(); this.contextmenu_captureie = new GreenshotPlugin.Controls.GreenshotToolStripMenuItem();
this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripPluginSeparator = new System.Windows.Forms.ToolStripSeparator();
this.contextmenu_captureclipboard = new GreenshotPlugin.Controls.GreenshotToolStripMenuItem(); this.contextmenu_captureclipboard = new GreenshotPlugin.Controls.GreenshotToolStripMenuItem();
this.contextmenu_openfile = new GreenshotPlugin.Controls.GreenshotToolStripMenuItem(); this.contextmenu_openfile = new GreenshotPlugin.Controls.GreenshotToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
@ -79,7 +79,7 @@ namespace Greenshot {
this.contextmenu_capturewindow, this.contextmenu_capturewindow,
this.contextmenu_capturefullscreen, this.contextmenu_capturefullscreen,
this.contextmenu_captureie, this.contextmenu_captureie,
this.toolStripSeparator4, this.toolStripPluginSeparator,
this.contextmenu_captureclipboard, this.contextmenu_captureclipboard,
this.contextmenu_openfile, this.contextmenu_openfile,
this.toolStripSeparator2, this.toolStripSeparator2,
@ -134,10 +134,11 @@ namespace Greenshot {
this.contextmenu_captureie.Size = new System.Drawing.Size(308, 22); this.contextmenu_captureie.Size = new System.Drawing.Size(308, 22);
this.contextmenu_captureie.DropDownOpening += new System.EventHandler(this.CaptureIEMenuDropDownOpening); this.contextmenu_captureie.DropDownOpening += new System.EventHandler(this.CaptureIEMenuDropDownOpening);
// //
// toolStripSeparator4 // toolStripPluginSeparator
// //
this.toolStripSeparator4.Name = "toolStripSeparator4"; this.toolStripPluginSeparator.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(305, 6); this.toolStripPluginSeparator.Size = new System.Drawing.Size(305, 6);
this.toolStripPluginSeparator.Tag = "PluginsAreAddedBefore";
// //
// contextmenu_captureclipboard // contextmenu_captureclipboard
// //
@ -251,7 +252,7 @@ namespace Greenshot {
private GreenshotPlugin.Controls.GreenshotToolStripMenuItem contextmenu_captureie; private GreenshotPlugin.Controls.GreenshotToolStripMenuItem contextmenu_captureie;
private GreenshotPlugin.Controls.GreenshotToolStripMenuItem contextmenu_donate; private GreenshotPlugin.Controls.GreenshotToolStripMenuItem contextmenu_donate;
private GreenshotPlugin.Controls.GreenshotToolStripMenuItem contextmenu_openfile; private GreenshotPlugin.Controls.GreenshotToolStripMenuItem contextmenu_openfile;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator4; private System.Windows.Forms.ToolStripSeparator toolStripPluginSeparator;
private GreenshotPlugin.Controls.GreenshotToolStripMenuItem contextmenu_captureclipboard; private GreenshotPlugin.Controls.GreenshotToolStripMenuItem contextmenu_captureclipboard;
private GreenshotPlugin.Controls.GreenshotToolStripMenuItem contextmenu_quicksettings; private GreenshotPlugin.Controls.GreenshotToolStripMenuItem contextmenu_quicksettings;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;

View file

@ -121,7 +121,7 @@ namespace GreenshotImgurPlugin {
// Should fix Bug #3378699 // Should fix Bug #3378699
pictureBox1.Image = pictureBox1.ErrorImage; pictureBox1.Image = pictureBox1.ErrorImage;
try { try {
new PleaseWaitForm().ShowAndWait(ImgurPlugin.Attributes.Name, Language.GetString("imgur", LangKey.communication_wait), Language.GetString("CANCEL"), new PleaseWaitForm().ShowAndWait(ImgurPlugin.Attributes.Name, Language.GetString("imgur", LangKey.communication_wait),
delegate() { delegate() {
ImgurUtils.DeleteImgurImage(imgurInfo); ImgurUtils.DeleteImgurImage(imgurInfo);
} }

View file

@ -69,7 +69,7 @@ namespace GreenshotImgurPlugin {
public bool ShowConfigDialog() { public bool ShowConfigDialog() {
SettingsForm settingsForm = null; SettingsForm settingsForm = null;
new PleaseWaitForm().ShowAndWait(ImgurPlugin.Attributes.Name, Language.GetString("imgur", LangKey.communication_wait), Language.GetString("CANCEL"), new PleaseWaitForm().ShowAndWait(ImgurPlugin.Attributes.Name, Language.GetString("imgur", LangKey.communication_wait),
delegate() { delegate() {
settingsForm = new SettingsForm(this); settingsForm = new SettingsForm(this);
} }

View file

@ -145,7 +145,7 @@ namespace GreenshotImgurPlugin {
ImgurInfo imgurInfo = null; ImgurInfo imgurInfo = null;
// Run upload in the background // Run upload in the background
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait), Language.GetString("CANCEL"), new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait),
delegate() { delegate() {
imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, captureDetails.Title, filename); imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, captureDetails.Title, filename);
LOG.InfoFormat("Storing imgur upload for hash {0} and delete hash {1}", imgurInfo.Hash, imgurInfo.DeleteHash); LOG.InfoFormat("Storing imgur upload for hash {0} and delete hash {1}", imgurInfo.Hash, imgurInfo.DeleteHash);

View file

@ -128,14 +128,18 @@ namespace GreenshotJiraPlugin {
private void jiraFilterBox_SelectedIndexChanged(object sender, EventArgs e) { private void jiraFilterBox_SelectedIndexChanged(object sender, EventArgs e) {
if (jiraConnector.isLoggedIn) { if (jiraConnector.isLoggedIn) {
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(JiraPlugin.Instance.JiraPluginAttributes.Name, Language.GetString("jira", LangKey.communication_wait)); JiraIssue[] issues = null;
try {
uploadButton.Enabled = false; uploadButton.Enabled = false;
JiraFilter filter = (JiraFilter)jiraFilterBox.SelectedItem; JiraFilter filter = (JiraFilter)jiraFilterBox.SelectedItem;
if (filter == null) { if (filter == null) {
return; return;
} }
JiraIssue[] issues = jiraConnector.getIssuesForFilter(filter.Id); // Run upload in the background
new PleaseWaitForm().ShowAndWait(JiraPlugin.Instance.JiraPluginAttributes.Name, Language.GetString("jira", LangKey.communication_wait),
delegate() {
issues = jiraConnector.getIssuesForFilter(filter.Id);
}
);
jiraListView.BeginUpdate(); jiraListView.BeginUpdate();
jiraListView.Items.Clear(); jiraListView.Items.Clear();
if (issues.Length > 0) { if (issues.Length > 0) {
@ -159,9 +163,6 @@ namespace GreenshotJiraPlugin {
} }
jiraListView.EndUpdate(); jiraListView.EndUpdate();
jiraListView.Refresh(); jiraListView.Refresh();
} finally {
backgroundForm.CloseDialog();
}
} }
} }

View file

@ -28,6 +28,7 @@ using GreenshotJiraPlugin;
using GreenshotPlugin.Controls; using GreenshotPlugin.Controls;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using Greenshot.IniFile; using Greenshot.IniFile;
using System.Threading;
namespace Jira { namespace Jira {
#region transport classes #region transport classes
@ -118,12 +119,11 @@ namespace Jira {
this.url = config.Url; this.url = config.Url;
this.timeout = config.Timeout; this.timeout = config.Timeout;
if (!suppressBackgroundForm) { if (!suppressBackgroundForm) {
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(JiraPlugin.Instance.JiraPluginAttributes.Name, Language.GetString("jira", LangKey.communication_wait)); new PleaseWaitForm().ShowAndWait(JiraPlugin.Instance.JiraPluginAttributes.Name, Language.GetString("jira", LangKey.communication_wait),
try { delegate() {
jira = new JiraSoapServiceService(); jira = new JiraSoapServiceService();
} finally {
backgroundForm.CloseDialog();
} }
);
} else { } else {
jira = new JiraSoapServiceService(); jira = new JiraSoapServiceService();
} }
@ -140,16 +140,23 @@ namespace Jira {
/// </summary> /// </summary>
/// <returns>true if login was done sucessfully</returns> /// <returns>true if login was done sucessfully</returns>
private bool doLogin(string user, string password, bool suppressBackgroundForm) { private bool doLogin(string user, string password, bool suppressBackgroundForm) {
BackgroundForm backgroundForm = null;
if (!suppressBackgroundForm) { // This is what needs to be done
backgroundForm = BackgroundForm.ShowAndWait(JiraPlugin.Instance.JiraPluginAttributes.Name, Language.GetString("jira", LangKey.communication_wait)); ThreadStart jiraLogin = delegate {
}
try {
LOG.DebugFormat("Loggin in"); LOG.DebugFormat("Loggin in");
this.credentials = jira.login(user, password); this.credentials = jira.login(user, password);
LOG.DebugFormat("Logged in"); LOG.DebugFormat("Logged in");
this.loggedInTime = DateTime.Now; this.loggedInTime = DateTime.Now;
this.loggedIn = true; this.loggedIn = true;
};
// Here we do it
try {
if (!suppressBackgroundForm) {
new PleaseWaitForm().ShowAndWait(JiraPlugin.Instance.JiraPluginAttributes.Name, Language.GetString("jira", LangKey.communication_wait), jiraLogin);
} else {
jiraLogin.Invoke();
}
} catch (Exception e) { } catch (Exception e) {
// check if auth failed // check if auth failed
if (e.Message.Contains(AUTH_FAILED_EXCEPTION_NAME)) { if (e.Message.Contains(AUTH_FAILED_EXCEPTION_NAME)) {
@ -161,10 +168,6 @@ namespace Jira {
e.Data.Add("user", user); e.Data.Add("user", user);
e.Data.Add("url", url); e.Data.Add("url", url);
throw; throw;
} finally {
if (backgroundForm != null) {
backgroundForm.CloseDialog();
}
} }
return true; return true;
} }

View file

@ -113,17 +113,19 @@ namespace GreenshotJiraPlugin {
// COPY stream to buffer // COPY stream to buffer
buffer = stream.ToArray(); buffer = stream.ToArray();
} }
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait));
try { try {
// Run upload in the background
new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
delegate() {
jiraPlugin.JiraConnector.addAttachment(jira.Key, filename, buffer); jiraPlugin.JiraConnector.addAttachment(jira.Key, filename, buffer);
}
);
LOG.Debug("Uploaded to Jira."); LOG.Debug("Uploaded to Jira.");
backgroundForm.CloseDialog();
surface.UploadURL = jiraPlugin.JiraConnector.getURL(jira.Key); surface.UploadURL = jiraPlugin.JiraConnector.getURL(jira.Key);
surface.SendMessageEvent(this, SurfaceMessageTyp.UploadedUrl, Language.GetFormattedString("exported_to", FormatUpload(jira))); surface.SendMessageEvent(this, SurfaceMessageTyp.UploadedUrl, Language.GetFormattedString("exported_to", FormatUpload(jira)));
surface.Modified = false; surface.Modified = false;
return true; return true;
} catch (Exception e) { } catch (Exception e) {
backgroundForm.CloseDialog();
MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message); MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
} }
} else { } else {
@ -140,17 +142,19 @@ namespace GreenshotJiraPlugin {
// COPY stream to buffer // COPY stream to buffer
buffer = stream.ToArray(); buffer = stream.ToArray();
} }
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait));
try { try {
// Run upload in the background
new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
delegate() {
jiraForm.upload(buffer); jiraForm.upload(buffer);
}
);
LOG.Debug("Uploaded to Jira."); LOG.Debug("Uploaded to Jira.");
backgroundForm.CloseDialog();
surface.UploadURL = jiraPlugin.JiraConnector.getURL(jiraForm.getJiraIssue().Key); surface.UploadURL = jiraPlugin.JiraConnector.getURL(jiraForm.getJiraIssue().Key);
surface.SendMessageEvent(this, SurfaceMessageTyp.UploadedUrl, Language.GetFormattedString("exported_to", FormatUpload(jiraForm.getJiraIssue()))); surface.SendMessageEvent(this, SurfaceMessageTyp.UploadedUrl, Language.GetFormattedString("exported_to", FormatUpload(jiraForm.getJiraIssue())));
surface.Modified = false; surface.Modified = false;
return true; return true;
} catch(Exception e) { } catch(Exception e) {
backgroundForm.CloseDialog();
MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message); MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
} }
} }

View file

@ -22,6 +22,7 @@ using System;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Threading; using System.Threading;
using GreenshotPlugin.Core;
namespace GreenshotPlugin.Controls { namespace GreenshotPlugin.Controls {
/// <summary> /// <summary>
@ -40,7 +41,7 @@ namespace GreenshotPlugin.Controls {
} }
/// <summary> /// <summary>
/// Prevent the close button showing /// Prevent the close-window button showing
/// </summary> /// </summary>
private const int CP_NOCLOSE_BUTTON = 0x200; private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams { protected override CreateParams CreateParams {
@ -51,17 +52,26 @@ namespace GreenshotPlugin.Controls {
} }
} }
public void ShowAndWait(string title, string text, string cancelText, ThreadStart waitDelegate) { /// <summary>
/// Show the "please wait" form, execute the code from the delegate and wait until execution finishes.
/// The supplied delegate will be wrapped with a try/catch so this method can return any exception that was thrown.
/// </summary>
/// <param name="title">The title of the form (and Thread)</param>
/// <param name="text">The text in the form</param>
/// <param name="waitDelegate">delegate { with your code }</param>
public void ShowAndWait(string title, string text, ThreadStart waitDelegate) {
this.title = title; this.title = title;
this.Text = title; this.Text = title;
this.label_pleasewait.Text = text; this.label_pleasewait.Text = text;
this.cancelButton.Text = cancelText; this.cancelButton.Text = Language.GetString("CANCEL");
// Make sure the form is shown.
Show(); Show();
// Variable to store the exception, if one is generated, from inside the thread.
Exception threadException = null; Exception threadException = null;
try { try {
// Wrap the passed delegate in a try/catch which saves the exception // Wrap the passed delegate in a try/catch which makes it possible to save the exception
waitFor = new Thread(new ThreadStart( waitFor = new Thread(new ThreadStart(
delegate { delegate {
try { try {
@ -93,6 +103,11 @@ namespace GreenshotPlugin.Controls {
} }
} }
/// <summary>
/// Called if the cancel button is clicked, will use Thread.Abort()
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void CancelButtonClick(object sender, EventArgs e) { void CancelButtonClick(object sender, EventArgs e) {
LOG.DebugFormat("Cancel clicked on {0}", title); LOG.DebugFormat("Cancel clicked on {0}", title);
cancelButton.Enabled = false; cancelButton.Enabled = false;

View file

@ -90,7 +90,7 @@ namespace GreenshotPlugin.Core {
} }
} }
/// <summary> /// <summary>
/// Helper method to add a MenuItem to the Greenshot context menu /// Helper method to add a plugin MenuItem to the Greenshot context menu
/// </summary> /// </summary>
/// <param name="imageEditor"></param> /// <param name="imageEditor"></param>
/// <param name="item"></param> /// <param name="item"></param>
@ -102,8 +102,17 @@ namespace GreenshotPlugin.Core {
// Try to find a separator, so we insert ourselves after it // Try to find a separator, so we insert ourselves after it
for(int i=0; i < contextMenu.Items.Count; i++) { for(int i=0; i < contextMenu.Items.Count; i++) {
if (contextMenu.Items[i].GetType() == typeof(ToolStripSeparator)) { if (contextMenu.Items[i].GetType() == typeof(ToolStripSeparator)) {
// Check if we need to add a new separator, which is done if the first found has a Tag with the value "PluginsAreAddedBefore"
if ("PluginsAreAddedBefore".Equals(contextMenu.Items[i].Tag)) {
ToolStripSeparator separator = new ToolStripSeparator();
separator.Size = new Size(305, 6);
contextMenu.Items.Insert(i, separator);
contextMenu.Items.Insert(i+1, item); contextMenu.Items.Insert(i+1, item);
addedItem = true; addedItem = true;
} else {
contextMenu.Items.Insert(i+1, item);
addedItem = true;
}
break; break;
} }
} }