Improved differentiating office icons, the actual application has a different icon as the "document". For Outlook this is even different for the email & meeting.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1666 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-02-20 12:13:59 +00:00
commit be0569bb21
8 changed files with 117 additions and 47 deletions

View file

@ -40,12 +40,15 @@ namespace Greenshot.Destinations {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(EmailDestination));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private static string exePath = null;
private static Image icon = null;
private static Image applicationIcon = null;
private static Image mailIcon = null;
private static Image meetingIcon = null;
private static bool isActiveFlag = false;
private static bool isOutlookUsed = false;
private static string mapiClient = null;
public const string DESIGNATION = "EMail";
private string outlookInspectorCaption = null;
private string outlookInspectorCaption;
private OlObjectClass outlookInspectorType;
private ILanguage lang = Language.GetInstance();
static EmailDestination() {
@ -63,11 +66,15 @@ namespace Greenshot.Destinations {
isActiveFlag = true;
isOutlookUsed = true;
}
// Use default email icon
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ImageEditorForm));
mailIcon = ((System.Drawing.Image)(resources.GetObject("btnEmail.Image")));
if (isOutlookUsed) {
exePath = GetExePath("OUTLOOK.EXE");
if (exePath != null && File.Exists(exePath)) {
icon = GetExeIcon(exePath);
applicationIcon = GetExeIcon(exePath, 0);
meetingIcon = GetExeIcon(exePath, 2);
} else {
exePath = null;
}
@ -80,16 +87,16 @@ namespace Greenshot.Destinations {
}
if (isActiveFlag && !isOutlookUsed) {
// Use default email icon
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ImageEditorForm));
icon = ((System.Drawing.Image)(resources.GetObject("btnEmail.Image")));
applicationIcon = mailIcon;
}
}
public EmailDestination() {
}
public EmailDestination(string outlookInspectorCaption) {
public EmailDestination(string outlookInspectorCaption, OlObjectClass outlookInspectorType) {
this.outlookInspectorCaption = outlookInspectorCaption;
this.outlookInspectorType = outlookInspectorType;
}
public override string Designation {
@ -108,7 +115,7 @@ namespace Greenshot.Destinations {
if (outlookInspectorCaption == null) {
return mapiClient;
} else {
return mapiClient + " - " + outlookInspectorCaption;
return outlookInspectorCaption;
}
}
}
@ -139,7 +146,15 @@ namespace Greenshot.Destinations {
public override Image DisplayIcon {
get {
return icon;
if (isOutlookUsed && outlookInspectorCaption != null) {
if (OlObjectClass.olAppointment.Equals(outlookInspectorType)) {
return meetingIcon;
} else {
return mailIcon;
}
} else {
return applicationIcon;
}
}
}
@ -147,10 +162,10 @@ namespace Greenshot.Destinations {
if (!isOutlookUsed) {
yield break;
}
List<string> inspectorCaptions = OutlookExporter.RetrievePossibleTargets();
Dictionary<string, OlObjectClass> inspectorCaptions = OutlookExporter.RetrievePossibleTargets();
if (inspectorCaptions != null) {
foreach (string inspectorCaption in inspectorCaptions) {
yield return new EmailDestination(inspectorCaption);
foreach (string inspectorCaption in inspectorCaptions.Keys) {
yield return new EmailDestination(inspectorCaption, inspectorCaptions[inspectorCaption]);
}
}
}

View file

@ -39,14 +39,16 @@ namespace Greenshot.Destinations {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExcelDestination));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private static string exePath = null;
private static Image icon = null;
private static Image applicationIcon = null;
private static Image workbookIcon = null;
private ILanguage lang = Language.GetInstance();
private string workbookName = null;
static ExcelDestination() {
exePath = GetExePath("EXCEL.EXE");
if (exePath != null && File.Exists(exePath)) {
icon = GetExeIcon(exePath);
applicationIcon = GetExeIcon(exePath, 0);
workbookIcon = GetExeIcon(exePath, 1);
} else {
exePath = null;
}
@ -70,7 +72,7 @@ namespace Greenshot.Destinations {
if (workbookName == null) {
return "Microsoft Excel";
} else {
return "Microsoft Excel - " + workbookName;
return workbookName;
}
}
}
@ -95,7 +97,10 @@ namespace Greenshot.Destinations {
public override Image DisplayIcon {
get {
return icon;
if (!string.IsNullOrEmpty(workbookName)) {
return workbookIcon;
}
return applicationIcon;
}
}

View file

@ -39,14 +39,16 @@ namespace Greenshot.Destinations {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PowerpointDestination));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private static string exePath = null;
private static Image icon = null;
private static Image applicationIcon = null;
private static Image presentationIcon = null;
private ILanguage lang = Language.GetInstance();
private string presentationName = null;
static PowerpointDestination() {
exePath = GetExePath("POWERPNT.EXE");
if (exePath != null && File.Exists(exePath)) {
icon = GetExeIcon(exePath);
applicationIcon = GetExeIcon(exePath, 0);
presentationIcon = GetExeIcon(exePath, 1);
} else {
exePath = null;
}
@ -70,7 +72,7 @@ namespace Greenshot.Destinations {
if (presentationName == null) {
return "Microsoft Powerpoint";
} else {
return "Microsoft Powerpoint - " + presentationName;
return presentationName;
}
}
}
@ -95,7 +97,11 @@ namespace Greenshot.Destinations {
public override Image DisplayIcon {
get {
return icon;
if (!string.IsNullOrEmpty(presentationName)) {
return presentationIcon;
}
return applicationIcon;
}
}

View file

@ -40,14 +40,16 @@ namespace Greenshot.Destinations {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WordDestination));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private static string exePath = null;
private static Image icon = null;
private static Image applicationIcon = null;
private static Image documentIcon = null;
private ILanguage lang = Language.GetInstance();
private string wordCaption = null;
private string documentCaption = null;
static WordDestination() {
exePath = GetExePath("WINWORD.EXE");
if (exePath != null && File.Exists(exePath)) {
icon = GetExeIcon(exePath);
applicationIcon = GetExeIcon(exePath, 0);
documentIcon = GetExeIcon(exePath, 1);
} else {
exePath = null;
}
@ -58,7 +60,7 @@ namespace Greenshot.Destinations {
}
public WordDestination(string wordCaption) {
this.wordCaption = wordCaption;
this.documentCaption = wordCaption;
}
public override string Designation {
@ -69,10 +71,10 @@ namespace Greenshot.Destinations {
public override string Description {
get {
if (wordCaption == null) {
if (documentCaption == null) {
return "Microsoft Word";
} else {
return "Microsoft Word - " + wordCaption;
return documentCaption;
}
}
}
@ -97,7 +99,10 @@ namespace Greenshot.Destinations {
public override Image DisplayIcon {
get {
return icon;
if (!string.IsNullOrEmpty(documentCaption)) {
return documentIcon;
}
return applicationIcon;
}
}
@ -114,8 +119,8 @@ namespace Greenshot.Destinations {
tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality);
}
}
if (wordCaption != null) {
WordExporter.InsertIntoExistingDocument(wordCaption, tmpFile);
if (documentCaption != null) {
WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
} else {
WordExporter.InsertIntoNewDocument(tmpFile);
}

View file

@ -111,8 +111,8 @@ namespace Greenshot.Helpers.OfficeInterop {
/// </summary>
/// <param name="outlookApplication">IOutlookApplication</param>
/// <returns>List<string> with inspector captions (window title)</returns>
public static List<string> RetrievePossibleTargets() {
List<string> inspectorCaptions = new List<string>();
public static Dictionary<string, OlObjectClass> RetrievePossibleTargets() {
Dictionary<string, OlObjectClass> inspectorCaptions = new Dictionary<string, OlObjectClass>();
try {
using ( IOutlookApplication outlookApplication = GetOutlookApplication()) {
if (outlookApplication == null) {
@ -124,7 +124,9 @@ namespace Greenshot.Helpers.OfficeInterop {
for(int i=1; i <= inspectors.Count; i++) {
Inspector inspector = outlookApplication.Inspectors[i];
if (canExportToInspector(inspector)) {
inspectorCaptions.Add(inspector.Caption);
Item currentItem = inspector.CurrentItem;
OlObjectClass currentItemClass = currentItem.Class;
inspectorCaptions.Add(inspector.Caption, currentItemClass);
}
}
}
@ -150,7 +152,7 @@ namespace Greenshot.Helpers.OfficeInterop {
return true;
}
} else if (outlookVersion.Major >=12 && OlObjectClass.olAppointment.Equals(currentItemClass)) {
if (currentUser != null && currentUser.Equals(currentItem.Organizer)) {
if (string.IsNullOrEmpty(currentItem.Organizer) || (currentUser == null && currentUser.Equals(currentItem.Organizer))) {
return true;
} else {
LOG.DebugFormat("Not exporting to {0}, as organizer is {1} and currentuser {2}", inspector.Caption, currentItem.Organizer, currentUser);

View file

@ -3,7 +3,7 @@ Greenshot: A screenshot tool optimized for productivity. Save a screenshot or a
CHANGE LOG:
0.9.0 Build 1660
0.9.0 Build 1667
We changed the version to 0.9.0 as the amount of features in 0.8.1 was more than planned.

View file

@ -51,19 +51,21 @@ namespace GreenshotPlugin.Core {
/// <summary>
/// Internaly used to create an icon
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static Bitmap GetExeIcon(string path) {
/// <param name="path">path to the exe or dll</param>
/// <param name="index">index of the icon</param>
/// <returns>Bitmap with the icon or null if something happended</returns>
public static Bitmap GetExeIcon(string path, int index) {
if (!File.Exists(path)) {
return null;
}
try {
using (Icon appIcon = Icon.ExtractAssociatedIcon(path)) {
using (Icon appIcon = ImageHelper.ExtractAssociatedIcon(path, index, false)) {
if (appIcon != null) {
return appIcon.ToBitmap();
}
}
} catch {
} catch (Exception exIcon) {
LOG.Error("error retrieving icon: ", exIcon);
}
return null;
}

View file

@ -268,20 +268,55 @@ namespace GreenshotPlugin.Core {
return bmpPngExtracted;
}
public static Icon ExtractAssociatedIcon(this Icon icon, string location) {
/// <summary>
/// See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms648069%28v=vs.85%29.aspx
/// </summary>
/// <param name="icon">The icon to </param>
/// <param name="location">The file (EXE or DLL) to get the icon from</param>
/// <param name="index">Index of the icon</param>
/// <param name="takeLarge">true if the large icon is wanted</param>
/// <returns>Icon</returns>
public static Icon ExtractAssociatedIcon(string location, int index, bool takeLarge) {
IntPtr large;
IntPtr small;
Shell32.ExtractIconEx(location, 0, out large, out small, 1);
Icon returnIcon = Icon.FromHandle(small);
if (!IntPtr.Zero.Equals(small)){
User32.DestroyIcon(small);
}
if (!IntPtr.Zero.Equals(large)){
User32.DestroyIcon(large);
Shell32.ExtractIconEx(location, index, out large, out small, 1);
Icon returnIcon = null;
bool isLarge = false;
bool isSmall = false;
try {
if (takeLarge && !IntPtr.Zero.Equals(large)) {
returnIcon = Icon.FromHandle(large);
isLarge = true;
} else if (!IntPtr.Zero.Equals(small)) {
returnIcon = Icon.FromHandle(small);
isSmall = true;
} else if (!IntPtr.Zero.Equals(large)) {
returnIcon = Icon.FromHandle(large);
isLarge = true;
}
} finally {
if (isLarge && !IntPtr.Zero.Equals(small)) {
User32.DestroyIcon(small);
}
if (isSmall && !IntPtr.Zero.Equals(large)) {
User32.DestroyIcon(large);
}
}
return returnIcon;
}
/// <summary>
/// Get the number of icon in the file
/// </summary>
/// <param name="icon"></param>
/// <param name="location">Location of the EXE or DLL</param>
/// <returns></returns>
public static int CountAssociatedIcons(string location) {
IntPtr large = IntPtr.Zero;
IntPtr small = IntPtr.Zero;
return Shell32.ExtractIconEx(location, -1, out large, out small, 0);
}
/// <summary>
/// Make the picture look like it's torn
/// </summary>