Code quality changes [skip ci]

This commit is contained in:
Robin 2016-08-16 10:37:55 +02:00
commit 798ca503a5
108 changed files with 1981 additions and 2258 deletions

View file

@ -28,24 +28,25 @@ namespace GreenshotOfficePlugin {
/// </summary>
[IniSection("Office", Description="Greenshot Office configuration")]
public class OfficeConfiguration : IniSection {
[IniProperty("OutlookEmailFormat", Description = "Default type for emails. (Text, HTML)", DefaultValue="HTML")]
public EmailFormat OutlookEmailFormat;
[IniProperty("OutlookEmailFormat", Description = "Default type for emails. (Text, HTML)", DefaultValue = "HTML")]
public EmailFormat OutlookEmailFormat { get; set; }
[IniProperty("EmailSubjectPattern", Description = "Email subject pattern, works like the OutputFileFilenamePattern", DefaultValue = "${title}")]
public string EmailSubjectPattern;
public string EmailSubjectPattern { get; set; }
[IniProperty("EmailTo", Description = "Default value for the to in emails that are created", DefaultValue = "")]
public string EmailTo;
public string EmailTo { get; set; }
[IniProperty("EmailCC", Description = "Default value for the CC in emails that are created", DefaultValue = "")]
public string EmailCC;
public string EmailCC { get; set; }
[IniProperty("EmailBCC", Description = "Default value for the BCC in emails that are created", DefaultValue = "")]
public string EmailBCC;
public string EmailBCC { get; set; }
[IniProperty("OutlookAllowExportInMeetings", Description = "For Outlook: Allow export in meeting items", DefaultValue = "False")]
public bool OutlookAllowExportInMeetings;
public bool OutlookAllowExportInMeetings { get; set; }
[IniProperty("WordLockAspectRatio", Description = "For Word: Lock the aspect ratio of the image", DefaultValue = "True")]
public bool WordLockAspectRatio;
public bool WordLockAspectRatio { get; set; }
[IniProperty("PowerpointLockAspectRatio", Description = "For Powerpoint: Lock the aspect ratio of the image", DefaultValue = "True")]
public bool PowerpointLockAspectRatio;
public bool PowerpointLockAspectRatio { get; set; }
[IniProperty("PowerpointSlideLayout", Description = "For Powerpoint: Slide layout, changing this to a wrong value will fallback on ppLayoutBlank!!", DefaultValue = "ppLayoutPictureWithCaption")]
public PPSlideLayout PowerpointSlideLayout;
public PPSlideLayout PowerpointSlideLayout { get; set; }
}
}

View file

@ -34,7 +34,7 @@ namespace Greenshot.Interop.Office {
/// <summary>
/// Get all currently opened workbooks
/// </summary>
/// <returns>List<string> with names of the workbooks</returns>
/// <returns>List of string with names of the workbooks</returns>
public static List<string> GetWorkbooks() {
List<string> currentWorkbooks = new List<string>();
using (IExcelApplication excelApplication = GetExcelApplication()) {

View file

@ -49,7 +49,7 @@ namespace Greenshot.Interop.Office {
/// <summary>
/// A method to retrieve all inspectors which can act as an export target
/// </summary>
/// <returns>List<string> with inspector captions (window title)</returns>
/// <returns>List of strings with inspector captions (window title)</returns>
public static IDictionary<string, OlObjectClass> RetrievePossibleTargets() {
IDictionary<string, OlObjectClass> inspectorCaptions = new SortedDictionary<string, OlObjectClass>();
try {
@ -76,7 +76,6 @@ namespace Greenshot.Interop.Office {
if (inspectors != null && inspectors.Count > 0) {
for (int i = 1; i <= inspectors.Count; i++) {
using (IInspector inspector = outlookApplication.Inspectors[i]) {
string inspectorCaption = inspector.Caption;
using (IItem currentItem = inspector.CurrentItem) {
if (canExportToInspector(currentItem)) {
OlObjectClass currentItemClass = currentItem.Class;
@ -328,13 +327,20 @@ namespace Greenshot.Interop.Office {
LOG.Debug("Finished!");
return true;
}
/// <summary>
/// Export image to a new email
/// </summary>
/// <param name="outlookApplication"></param>
/// <param name="format"></param>
/// <param name="tmpFile"></param>
/// <param name="captureDetails"></param>
private static void ExportToNewEmail(IOutlookApplication outlookApplication, EmailFormat format, string tmpFile, string subject, string attachmentName, string to, string CC, string BCC, string url) {
/// <param name="subject"></param>
/// <param name="attachmentName"></param>
/// <param name="to"></param>
/// <param name="cc"></param>
/// <param name="bcc"></param>
/// <param name="url"></param>
private static void ExportToNewEmail(IOutlookApplication outlookApplication, EmailFormat format, string tmpFile, string subject, string attachmentName, string to, string cc, string bcc, string url) {
using (IItem newItem = outlookApplication.CreateItem(OlItemType.olMailItem)) {
if (newItem == null) {
return;
@ -345,11 +351,11 @@ namespace Greenshot.Interop.Office {
if (!string.IsNullOrEmpty(to)) {
newMail.To = to;
}
if (!string.IsNullOrEmpty(CC)) {
newMail.CC = CC;
if (!string.IsNullOrEmpty(cc)) {
newMail.CC = cc;
}
if (!string.IsNullOrEmpty(BCC)) {
newMail.BCC = BCC;
if (!string.IsNullOrEmpty(bcc)) {
newMail.BCC = bcc;
}
newMail.BodyFormat = OlBodyFormat.olFormatHTML;
string bodyString = null;
@ -362,7 +368,8 @@ namespace Greenshot.Interop.Office {
switch (format) {
case EmailFormat.Text:
// Create the attachment (and dispose the COM object after using)
using (IAttachment attachment = newMail.Attachments.Add(tmpFile, OlAttachmentType.olByValue, 1, attachmentName)) {
using (newMail.Attachments.Add(tmpFile, OlAttachmentType.olByValue, 1, attachmentName))
{
newMail.BodyFormat = OlBodyFormat.olFormatPlain;
if (bodyString == null) {
bodyString = "";
@ -433,14 +440,21 @@ namespace Greenshot.Interop.Office {
/// <summary>
/// Helper method to create an outlook mail item with attachment
/// </summary>
/// <param name="tmpfile">The file to send, do not delete the file right away!</param>
/// <param name="format"></param>
/// <param name="tmpFile">The file to send, do not delete the file right away!</param>
/// <param name="subject"></param>
/// <param name="attachmentName"></param>
/// <param name="to"></param>
/// <param name="cc"></param>
/// <param name="bcc"></param>
/// <param name="url"></param>
/// <returns>true if it worked, false if not</returns>
public static bool ExportToOutlook(EmailFormat format, string tmpFile, string subject, string attachmentName, string to, string CC, string BCC, string url) {
public static bool ExportToOutlook(EmailFormat format, string tmpFile, string subject, string attachmentName, string to, string cc, string bcc, string url) {
bool exported = false;
try {
using (IOutlookApplication outlookApplication = GetOrCreateOutlookApplication()) {
if (outlookApplication != null) {
ExportToNewEmail(outlookApplication, format, tmpFile, subject, attachmentName, to, CC, BCC, url);
ExportToNewEmail(outlookApplication, format, tmpFile, subject, attachmentName, to, cc, bcc, url);
exported = true;
}
}

View file

@ -69,7 +69,7 @@ namespace Greenshot.Interop.Office {
/// <param name="wordApplication"></param>
/// <param name="wordDocument"></param>
/// <param name="tmpFile"></param>
/// <param name="adress">link for the image</param>
/// <param name="address">link for the image</param>
/// <param name="tooltip">tooltip of the image</param>
/// <returns></returns>
internal static bool InsertIntoExistingDocument(IWordApplication wordApplication, IWordDocument wordDocument, string tmpFile, string address, string tooltip) {

View file

@ -20,8 +20,6 @@
*/
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Greenshot.Plugin;
namespace GreenshotOfficePlugin {
@ -30,15 +28,14 @@ namespace GreenshotOfficePlugin {
/// </summary>
public class OfficePlugin : IGreenshotPlugin {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OfficePlugin));
public static PluginAttribute Attributes;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
//if (disposing) {}
protected void Dispose(bool disposing) {
// Do nothing
}
public IEnumerable<IDestination> Destinations() {
@ -100,7 +97,6 @@ namespace GreenshotOfficePlugin {
/// <param name="myAttributes">My own attributes</param>
/// <returns>true if plugin is initialized, false if not (doesn't show)</returns>
public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) {
Attributes = myAttributes;
return true;
}
@ -113,15 +109,5 @@ namespace GreenshotOfficePlugin {
/// </summary>
public virtual void Configure() {
}
/// <summary>
/// This will be called when Greenshot is shutting down
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Closing(object sender, FormClosingEventArgs e) {
LOG.Debug("Application closing, de-registering Office Plugin!");
Shutdown();
}
}
}