mirror of
https://github.com/Kopano-dev/kopano-ol-extension.git
synced 2023-10-10 13:37:40 +02:00
Further fixes for item events
This commit is contained in:
parent
b3c0aae951
commit
49efb68298
@ -35,12 +35,9 @@ namespace Acacia.Stubs
|
|||||||
string Subject { get; set; }
|
string Subject { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the events for the item. The same object is returned, it does not need to be disposed.
|
/// Returns the events for the item. The caller is responsible for disposing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IItemEvents Events
|
IItemEvents GetEvents();
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ using NSOutlook = Microsoft.Office.Interop.Outlook;
|
|||||||
|
|
||||||
namespace Acacia.Stubs
|
namespace Acacia.Stubs
|
||||||
{
|
{
|
||||||
public interface IItemEvents
|
public interface IItemEvents : IComWrapper
|
||||||
{
|
{
|
||||||
#region Event handlers
|
#region Event handlers
|
||||||
|
|
||||||
|
@ -7,13 +7,11 @@ using NSOutlook = Microsoft.Office.Interop.Outlook;
|
|||||||
|
|
||||||
namespace Acacia.Stubs.OutlookWrappers
|
namespace Acacia.Stubs.OutlookWrappers
|
||||||
{
|
{
|
||||||
class ItemEventsWrapper : IItemEvents
|
class ItemEventsWrapper : ComWrapper<NSOutlook.ItemEvents_10_Event>, IItemEvents
|
||||||
{
|
{
|
||||||
private readonly NSOutlook.ItemEvents_10_Event _item;
|
internal ItemEventsWrapper(NSOutlook.ItemEvents_10_Event item) : base(item)
|
||||||
|
|
||||||
internal ItemEventsWrapper(object item)
|
|
||||||
{
|
{
|
||||||
this._item = (NSOutlook.ItemEvents_10_Event)item;
|
MustRelease = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
|
@ -16,15 +16,9 @@ namespace Acacia.Stubs.OutlookWrappers
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemEventsWrapper _events;
|
public IItemEvents GetEvents()
|
||||||
public IItemEvents Events
|
|
||||||
{
|
{
|
||||||
get
|
return new ItemEventsWrapper((NSOutlook.ItemEvents_10_Event)_item);
|
||||||
{
|
|
||||||
if (_events == null)
|
|
||||||
_events = new ItemEventsWrapper(_item);
|
|
||||||
return _events;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type GetUserProperty<Type>(string name)
|
public Type GetUserProperty<Type>(string name)
|
||||||
|
@ -190,8 +190,8 @@ namespace Acacia.Utils
|
|||||||
|
|
||||||
private void OnItemLoad(object item)
|
private void OnItemLoad(object item)
|
||||||
{
|
{
|
||||||
IItem wrapped = Wrappers.Wrap<IItem>(item);
|
IItem wrapped = Wrappers.Wrap<IItem>(item, false);
|
||||||
// TODO: check type
|
// TODO: only register for desired types
|
||||||
if (wrapped != null)
|
if (wrapped != null)
|
||||||
{
|
{
|
||||||
new MailEventHooker(wrapped, this);
|
new MailEventHooker(wrapped, this);
|
||||||
@ -214,40 +214,37 @@ namespace Acacia.Utils
|
|||||||
HookEvents(true);
|
HookEvents(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*~MailEventHooker()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected override void DoRelease()
|
protected override void DoRelease()
|
||||||
{
|
{
|
||||||
Logger.Instance.Debug(this, "DoRelease: {0}", _id);
|
Logger.Instance.Debug(this, "DoRelease: {0}", _id);
|
||||||
// TODO: It looks like release _itemEvents is not only not needed, but causes exceptions.
|
|
||||||
// If that is really the case, this doesn't need to be a ComWrapper
|
|
||||||
_item.Dispose();
|
_item.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HookEvents(bool add)
|
private void HookEvents(bool add)
|
||||||
{
|
{
|
||||||
if (add)
|
using (IItemEvents events = _item.GetEvents())
|
||||||
{
|
{
|
||||||
_item.Events.BeforeDelete += HandleBeforeDelete;
|
if (add)
|
||||||
_item.Events.Forward += HandleForward;
|
{
|
||||||
_item.Events.Read += HandleRead;
|
|
||||||
_item.Events.Reply += HandleReply;
|
events.BeforeDelete += HandleBeforeDelete;
|
||||||
_item.Events.ReplyAll += HandleReplyAll;
|
events.Forward += HandleForward;
|
||||||
_item.Events.Unload += HandleUnload;
|
events.Read += HandleRead;
|
||||||
_item.Events.Write += HandleWrite;
|
events.Reply += HandleReply;
|
||||||
}
|
events.ReplyAll += HandleReplyAll;
|
||||||
else
|
events.Unload += HandleUnload;
|
||||||
{
|
events.Write += HandleWrite;
|
||||||
_item.Events.BeforeDelete -= HandleBeforeDelete;
|
}
|
||||||
_item.Events.Forward -= HandleForward;
|
else
|
||||||
_item.Events.Read -= HandleRead;
|
{
|
||||||
_item.Events.Reply -= HandleReply;
|
events.BeforeDelete -= HandleBeforeDelete;
|
||||||
_item.Events.ReplyAll -= HandleReplyAll;
|
events.Forward -= HandleForward;
|
||||||
_item.Events.Unload -= HandleUnload;
|
events.Read -= HandleRead;
|
||||||
_item.Events.Write -= HandleWrite;
|
events.Reply -= HandleReply;
|
||||||
|
events.ReplyAll -= HandleReplyAll;
|
||||||
|
events.Unload -= HandleUnload;
|
||||||
|
events.Write -= HandleWrite;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user