Added option to disable item event hooking

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

View File

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

View File

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

View File

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

View File

@ -49,7 +49,10 @@ namespace Acacia.Features.SendAs
public override void Startup() public override void Startup()
{ {
MailEvents.ItemSend += MailEvents_ItemSend; if (MailEvents != null)
{
MailEvents.ItemSend += MailEvents_ItemSend;
}
if (SendAsOwner) if (SendAsOwner)
{ {
@ -57,7 +60,10 @@ namespace Acacia.Features.SendAs
_sharedFolders = ThisAddIn.Instance.GetFeature<FeatureSharedFolders>(); _sharedFolders = ThisAddIn.Instance.GetFeature<FeatureSharedFolders>();
if (_sharedFolders != null) 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 #region UI Options
[AcaciaOption("Completely enables or disables modifications to the Outlook UI." + [AcaciaOption("Completely enables or disables modifications to the Outlook UI." +

View File

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

View File

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

View File

@ -63,6 +63,22 @@ namespace Acacia
private set; 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 #region Startup / Shutdown
private void ThisAddIn_Startup(object sender, System.EventArgs args) private void ThisAddIn_Startup(object sender, System.EventArgs args)