Added some support for opening the url when an upload is made from a Destination (currently Jira & Picasa) and the tooltip is clicked.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1797 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-04-18 13:42:42 +00:00
parent 05f9fb930e
commit 9bf5e44c94
12 changed files with 169 additions and 135 deletions

View file

@ -138,6 +138,11 @@ namespace Greenshot.Drawing {
} }
} }
public string UploadURL {
get;
set;
}
public ICaptureDetails CaptureDetails { public ICaptureDetails CaptureDetails {
get {return captureDetails;} get {return captureDetails;}
set {captureDetails = value;} set {captureDetails = value;}

View file

@ -252,7 +252,9 @@ namespace Greenshot {
private void SurfaceMessageReceived(object sender, SurfaceMessageEventArgs eventArgs) { private void SurfaceMessageReceived(object sender, SurfaceMessageEventArgs eventArgs) {
string dateTime = DateTime.Now.ToLongTimeString(); string dateTime = DateTime.Now.ToLongTimeString();
if (eventArgs.MessageType == SurfaceMessageTyp.FileSaved) { // TODO: Fix that we only open files, like in the tooltip
//if (eventArgs.MessageType == SurfaceMessageTyp.FileSaved || eventArgs.MessageType == SurfaceMessageTyp.UploadedUrl) {
if (eventArgs.MessageType == SurfaceMessageTyp.FileSaved || eventArgs.MessageType == SurfaceMessageTyp.UploadedUrl) {
updateStatusLabel(dateTime + " - " + eventArgs.Message, fileSavedStatusContextMenu); updateStatusLabel(dateTime + " - " + eventArgs.Message, fileSavedStatusContextMenu);
} else { } else {
updateStatusLabel(dateTime + " - " + eventArgs.Message); updateStatusLabel(dateTime + " - " + eventArgs.Message);

View file

@ -438,6 +438,7 @@ namespace Greenshot.Helpers {
MainForm.instance.notifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Info); MainForm.instance.notifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Info);
break; break;
case SurfaceMessageTyp.FileSaved: case SurfaceMessageTyp.FileSaved:
case SurfaceMessageTyp.UploadedUrl:
EventHandler balloonTipClickedHandler = null; EventHandler balloonTipClickedHandler = null;
EventHandler balloonTipClosedHandler = null; EventHandler balloonTipClosedHandler = null;
balloonTipClosedHandler = delegate(object sender, EventArgs e) { balloonTipClosedHandler = delegate(object sender, EventArgs e) {
@ -447,13 +448,19 @@ namespace Greenshot.Helpers {
}; };
balloonTipClickedHandler = delegate(object sender, EventArgs e) { balloonTipClickedHandler = delegate(object sender, EventArgs e) {
if (surface.LastSaveFullPath != null) { if (eventArgs.MessageType == SurfaceMessageTyp.FileSaved) {
ProcessStartInfo psi = new ProcessStartInfo("explorer"); if (!string.IsNullOrEmpty(surface.LastSaveFullPath)) {
psi.Arguments = Path.GetDirectoryName(eventArgs.Surface.LastSaveFullPath); ProcessStartInfo psi = new ProcessStartInfo("explorer");
psi.UseShellExecute = false; psi.Arguments = Path.GetDirectoryName(surface.LastSaveFullPath);
Process p = new Process(); psi.UseShellExecute = false;
p.StartInfo = psi; Process p = new Process();
p.Start(); p.StartInfo = psi;
p.Start();
}
} else {
if (!string.IsNullOrEmpty(surface.UploadURL)) {
System.Diagnostics.Process.Start(surface.UploadURL);
}
} }
LOG.DebugFormat("Deregistering the BalloonTipClicked"); LOG.DebugFormat("Deregistering the BalloonTipClicked");
MainForm.instance.notifyIcon.BalloonTipClicked -= balloonTipClickedHandler; MainForm.instance.notifyIcon.BalloonTipClicked -= balloonTipClickedHandler;

View file

@ -31,7 +31,7 @@ namespace GreenshotJiraPlugin {
public partial class JiraForm : Form { public partial class JiraForm : Form {
private JiraConnector jiraConnector; private JiraConnector jiraConnector;
private JiraIssue selectedIssue; private JiraIssue selectedIssue;
private ListViewColumnSorter columnSorter; private GreenshotColumnSorter columnSorter;
private JiraConfiguration config = IniConfig.GetIniSection<JiraConfiguration>(); private JiraConfiguration config = IniConfig.GetIniSection<JiraConfiguration>();
public JiraForm(JiraConnector jiraConnector) { public JiraForm(JiraConnector jiraConnector) {
@ -39,7 +39,7 @@ namespace GreenshotJiraPlugin {
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon(); this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
initializeComponentText(); initializeComponentText();
this.columnSorter = new ListViewColumnSorter(); this.columnSorter = new GreenshotColumnSorter();
this.jiraListView.ListViewItemSorter = columnSorter; this.jiraListView.ListViewItemSorter = columnSorter;
this.jiraConnector = jiraConnector; this.jiraConnector = jiraConnector;

View file

@ -1,115 +0,0 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System.Collections;
using System.Windows.Forms;
/// <summary>
/// This class is an implementation of the 'IComparer' interface.
/// </summary>
public class ListViewColumnSorter : IComparer {
/// <summary>
/// Specifies the column to be sorted
/// </summary>
private int ColumnToSort;
/// <summary>
/// Specifies the order in which to sort (i.e. 'Ascending').
/// </summary>
private SortOrder OrderOfSort;
/// <summary>
/// Case insensitive comparer object
/// </summary>
private CaseInsensitiveComparer ObjectCompare;
/// <summary>
/// Class constructor. Initializes various elements
/// </summary>
public ListViewColumnSorter() {
// Initialize the column to '0'
ColumnToSort = 0;
// Initialize the sort order to 'none'
OrderOfSort = SortOrder.None;
// Initialize the CaseInsensitiveComparer object
ObjectCompare = new CaseInsensitiveComparer();
}
/// <summary>
/// This method is inherited from the IComparer interface. It compares the two objects passed using a case insensitive comparison.
/// </summary>
/// <param name="x">First object to be compared</param>
/// <param name="y">Second object to be compared</param>
/// <returns>The result of the comparison. "0" if equal, negative if 'x' is less than 'y' and positive if 'x' is greater than 'y'</returns>
public int Compare(object x, object y) {
int compareResult;
ListViewItem listviewX, listviewY;
if (x == null && y == null) {
return 0;
} else if (x == null && y != null) {
return -1;
} else if (x != null && y == null) {
return 1;
}
// Cast the objects to be compared to ListViewItem objects
listviewX = (ListViewItem)x;
listviewY = (ListViewItem)y;
// Compare the two items
compareResult = ObjectCompare.Compare(listviewX.SubItems[ColumnToSort].Text, listviewY.SubItems[ColumnToSort].Text);
// Calculate correct return value based on object comparison
if (OrderOfSort == SortOrder.Ascending) {
// Ascending sort is selected, return normal result of compare operation
return compareResult;
} else if (OrderOfSort == SortOrder.Descending) {
// Descending sort is selected, return negative result of compare operation
return (-compareResult);
} else {
// Return '0' to indicate they are equal
return 0;
}
}
/// <summary>
/// Gets or sets the number of the column to which to apply the sorting operation (Defaults to '0').
/// </summary>
public int SortColumn {
set {
ColumnToSort = value;
}
get {
return ColumnToSort;
}
}
/// <summary>
/// Gets or sets the order of sorting to apply (for example, 'Ascending' or 'Descending').
/// </summary>
public SortOrder Order {
set {
OrderOfSort = value;
}
get {
return OrderOfSort;
}
}
}

View file

@ -59,7 +59,6 @@
<Compile Include="Forms\JiraForm.Designer.cs"> <Compile Include="Forms\JiraForm.Designer.cs">
<DependentUpon>JiraForm.cs</DependentUpon> <DependentUpon>JiraForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Forms\ListViewColumnSorter.cs" />
<Compile Include="Forms\SettingsForm.cs"> <Compile Include="Forms\SettingsForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>

View file

@ -285,6 +285,10 @@ namespace Jira {
return issuesToReturn.ToArray(); ; return issuesToReturn.ToArray(); ;
} }
public string getURL(string issueKey) {
return url.Replace(DEFAULT_POSTFIX,"") + "/browse/" + issueKey;
}
public void addAttachment(string issueKey, string filename, byte [] buffer) { public void addAttachment(string issueKey, string filename, byte [] buffer) {
checkCredentials(); checkCredentials();
try { try {

View file

@ -57,12 +57,16 @@ namespace GreenshotJiraPlugin {
} }
} }
private string FormatUpload(JiraIssue jira) {
return Designation + " - " + jira.Key + ": " + jira.Summary.Substring(0, Math.Min(20, jira.Summary.Length));
}
public override string Description { public override string Description {
get { get {
if (jira == null) { if (jira == null) {
return Language.GetString("jira", LangKey.upload_menu_item); return Language.GetString("jira", LangKey.upload_menu_item);
} else { } else {
return Language.GetString("jira", LangKey.upload_menu_item) + " - " + jira.Key + ": " + jira.Summary.Substring(0, Math.Min(20, jira.Summary.Length)); return FormatUpload(jira);
} }
} }
} }
@ -113,8 +117,8 @@ namespace GreenshotJiraPlugin {
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(); backgroundForm.CloseDialog();
MessageBox.Show(Language.GetString("jira", LangKey.upload_success)); surface.UploadURL = jiraPlugin.JiraConnector.getURL(jira.Key);
surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString("exported_to", Description)); 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) {
@ -140,8 +144,8 @@ namespace GreenshotJiraPlugin {
jiraForm.upload(buffer); jiraForm.upload(buffer);
LOG.Debug("Uploaded to Jira."); LOG.Debug("Uploaded to Jira.");
backgroundForm.CloseDialog(); backgroundForm.CloseDialog();
MessageBox.Show(Language.GetString("jira", LangKey.upload_success)); surface.UploadURL = jiraPlugin.JiraConnector.getURL(jiraForm.getJiraIssue().Key);
surface.SendMessageEvent(this, SurfaceMessageTyp.Info, "Exported to Jira " + jiraForm.getJiraIssue().Key); 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) {

View file

@ -49,7 +49,8 @@ namespace GreenshotJiraPlugin {
} }
MatchCollection jiraKeyMatch = JIRA_KEY_REGEX.Matches(url); MatchCollection jiraKeyMatch = JIRA_KEY_REGEX.Matches(url);
if (jiraKeyMatch != null && jiraKeyMatch.Count > 0) { if (jiraKeyMatch != null && jiraKeyMatch.Count > 0) {
jirakeys.Add(jiraKeyMatch[0].Groups[1].Value); string jiraKey = jiraKeyMatch[0].Groups[1].Value;
jirakeys.Add(jiraKey);
} }
} }
if (!string.IsNullOrEmpty(config.LastUsedJira) && !jirakeys.Contains(config.LastUsedJira)) { if (!string.IsNullOrEmpty(config.LastUsedJira) && !jirakeys.Contains(config.LastUsedJira)) {
@ -60,7 +61,9 @@ namespace GreenshotJiraPlugin {
foreach(string jiraKey in jirakeys) { foreach(string jiraKey in jirakeys) {
try { try {
JiraIssue issue = JiraPlugin.Instance.JiraConnector.getIssue(jiraKey); JiraIssue issue = JiraPlugin.Instance.JiraConnector.getIssue(jiraKey);
jiraIssues.Add(issue); if (issue != null) {
jiraIssues.Add(issue);
}
} catch {} } catch {}
} }
if (jiraIssues.Count > 0) { if (jiraIssues.Count > 0) {

View file

@ -0,0 +1,119 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System.Collections;
using System.Windows.Forms;
namespace GreenshotPlugin.Controls {
/// <summary>
/// This class is an implementation of the 'IComparer' interface.
/// </summary>
public class GreenshotColumnSorter : IComparer {
/// <summary>
/// Specifies the column to be sorted
/// </summary>
private int ColumnToSort;
/// <summary>
/// Specifies the order in which to sort (i.e. 'Ascending').
/// </summary>
private SortOrder OrderOfSort;
/// <summary>
/// Case insensitive comparer object
/// </summary>
private CaseInsensitiveComparer ObjectCompare;
/// <summary>
/// Class constructor. Initializes various elements
/// </summary>
public GreenshotColumnSorter() {
// Initialize the column to '0'
ColumnToSort = 0;
// Initialize the sort order to 'none'
OrderOfSort = SortOrder.None;
// Initialize the CaseInsensitiveComparer object
ObjectCompare = new CaseInsensitiveComparer();
}
/// <summary>
/// This method is inherited from the IComparer interface. It compares the two objects passed using a case insensitive comparison.
/// </summary>
/// <param name="x">First object to be compared</param>
/// <param name="y">Second object to be compared</param>
/// <returns>The result of the comparison. "0" if equal, negative if 'x' is less than 'y' and positive if 'x' is greater than 'y'</returns>
public int Compare(object x, object y) {
int compareResult;
ListViewItem listviewX, listviewY;
if (x == null && y == null) {
return 0;
} else if (x == null && y != null) {
return -1;
} else if (x != null && y == null) {
return 1;
}
// Cast the objects to be compared to ListViewItem objects
listviewX = (ListViewItem)x;
listviewY = (ListViewItem)y;
// Compare the two items
compareResult = ObjectCompare.Compare(listviewX.SubItems[ColumnToSort].Text, listviewY.SubItems[ColumnToSort].Text);
// Calculate correct return value based on object comparison
if (OrderOfSort == SortOrder.Ascending) {
// Ascending sort is selected, return normal result of compare operation
return compareResult;
} else if (OrderOfSort == SortOrder.Descending) {
// Descending sort is selected, return negative result of compare operation
return (-compareResult);
} else {
// Return '0' to indicate they are equal
return 0;
}
}
/// <summary>
/// Gets or sets the number of the column to which to apply the sorting operation (Defaults to '0').
/// </summary>
public int SortColumn {
set {
ColumnToSort = value;
}
get {
return ColumnToSort;
}
}
/// <summary>
/// Gets or sets the order of sorting to apply (for example, 'Ascending' or 'Descending').
/// </summary>
public SortOrder Order {
set {
OrderOfSort = value;
}
get {
return OrderOfSort;
}
}
}
}

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<ProjectGuid>{5B924697-4DCD-4F98-85F1-105CB84B7341}</ProjectGuid> <ProjectGuid>{5B924697-4DCD-4F98-85F1-105CB84B7341}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -177,6 +177,7 @@
</Compile> </Compile>
<Compile Include="Controls\GreenshotButton.cs" /> <Compile Include="Controls\GreenshotButton.cs" />
<Compile Include="Controls\GreenshotCheckBox.cs" /> <Compile Include="Controls\GreenshotCheckBox.cs" />
<Compile Include="Controls\GreenshotColumnSorter.cs" />
<Compile Include="Controls\GreenshotComboBox.cs" /> <Compile Include="Controls\GreenshotComboBox.cs" />
<Compile Include="Controls\GreenshotForm.cs" /> <Compile Include="Controls\GreenshotForm.cs" />
<Compile Include="Controls\GreenshotGroupBox.cs" /> <Compile Include="Controls\GreenshotGroupBox.cs" />

View file

@ -36,7 +36,8 @@ namespace Greenshot.Plugin {
public enum SurfaceMessageTyp { public enum SurfaceMessageTyp {
FileSaved, FileSaved,
Error, Error,
Info Info,
UploadedUrl
} }
public class SurfaceMessageEventArgs : EventArgs { public class SurfaceMessageEventArgs : EventArgs {
@ -130,6 +131,10 @@ namespace Greenshot.Plugin {
get; get;
set; set;
} }
string UploadURL {
get;
set;
}
void RemoveElement(IDrawableContainer elementToRemove, bool makeUndoable); void RemoveElement(IDrawableContainer elementToRemove, bool makeUndoable);
void SendMessageEvent(object source, SurfaceMessageTyp messageType, string message); void SendMessageEvent(object source, SurfaceMessageTyp messageType, string message);
void ApplyBitmapEffect(Effects effect); void ApplyBitmapEffect(Effects effect);