Added option to disable item event hooking

This commit is contained in:
Patrick Simpson 2017-02-09 16:00:21 +01:00
parent d7df634a3d
commit cc51366c7f
8 changed files with 48 additions and 11 deletions

View File

@ -194,14 +194,11 @@ namespace Acacia.Features
#region Event helpers
private static MailEvents _mailEvents;
protected static MailEvents MailEvents
{
get
{
if (_mailEvents == null)
_mailEvents = new MailEvents(ThisAddIn.Instance);
return _mailEvents;
return ThisAddIn.Instance.MailEvents;
}
}

View File

@ -64,7 +64,7 @@ namespace Acacia.Features.GAB
public override void Startup()
{
if (SuppressModifications)
if (SuppressModifications && MailEvents != null)
{
MailEvents.BeforeDelete += SuppressEventHandler_Delete;
MailEvents.Write += SuppressEventHandler_Modify;

View File

@ -47,15 +47,21 @@ namespace Acacia.Features.ReplyFlags
if (ReadEvent)
{
// As a fallback, add an event handler to update the message when displaying it
MailEvents.Read += UpdateReplyStatus;
if (MailEvents != null)
{
MailEvents.Read += UpdateReplyStatus;
}
}
if (SendEvents)
{
// Hook reply and send events to update local state to server
MailEvents.Reply += OnReply;
MailEvents.ReplyAll += OnReplyAll;
MailEvents.Forward += OnForwarded;
if (MailEvents != null)
{
MailEvents.Reply += OnReply;
MailEvents.ReplyAll += OnReplyAll;
MailEvents.Forward += OnForwarded;
}
}
}

View File

@ -49,7 +49,10 @@ namespace Acacia.Features.SendAs
public override void Startup()
{
MailEvents.ItemSend += MailEvents_ItemSend;
if (MailEvents != null)
{
MailEvents.ItemSend += MailEvents_ItemSend;
}
if (SendAsOwner)
{
@ -57,7 +60,10 @@ namespace Acacia.Features.SendAs
_sharedFolders = ThisAddIn.Instance.GetFeature<FeatureSharedFolders>();
if (_sharedFolders != null)
{
MailEvents.Respond += MailEvents_Respond;
if (MailEvents != null)
{
MailEvents.Respond += MailEvents_Respond;
}
}
}
}

View File

@ -118,6 +118,15 @@ namespace Acacia
}
}
[AcaciaOption("Enables or disables item event hooking." +
"Note that if this is disabled, several features may not work correctly.")]
virtual public bool HookItemEvents
{
get { return GetOption(null, HOOK_ITEM_EVENTS); }
set { SetOption(null, HOOK_ITEM_EVENTS, value); }
}
private static readonly BoolOption HOOK_ITEM_EVENTS = new BoolOption("HookItemEvents", true);
#region UI Options
[AcaciaOption("Completely enables or disables modifications to the Outlook UI." +

View File

@ -1,5 +1,6 @@
using Acacia.Features;
using Acacia.UI.Outlook;
using Acacia.Utils;
using Acacia.ZPush;
using System;
using System.Collections.Generic;
@ -16,6 +17,7 @@ namespace Acacia.Stubs
NSOutlook.Application RawApp { get; } // TODO: remove
ZPushWatcher Watcher { get; }
MailEvents MailEvents { get; }
IEnumerable<Feature> Features { get; }
IEnumerable<KeyValuePair<string,string>> COMAddIns { get; }
string Version { get; }

View File

@ -85,6 +85,7 @@ namespace Acacia.Stubs.OutlookWrappers
public OutlookUI OutlookUI { get { return _thisAddIn.OutlookUI; } }
public ZPushWatcher Watcher { get { return _thisAddIn.Watcher; } }
public MailEvents MailEvents { get { return _thisAddIn.MailEvents; } }
public IEnumerable<Feature> Features { get { return _thisAddIn.Features; } }
public IEnumerable<KeyValuePair<string, string>> COMAddIns
{

View File

@ -63,6 +63,22 @@ namespace Acacia
private set;
}
private MailEvents _mailEvents;
public MailEvents MailEvents
{
get
{
if (_mailEvents == null)
{
if (GlobalOptions.INSTANCE.HookItemEvents)
{
_mailEvents = new MailEvents(Instance);
}
}
return _mailEvents;
}
}
#region Startup / Shutdown
private void ThisAddIn_Startup(object sender, System.EventArgs args)