Small cleanups. Made HookItemEvents disabled by default. Restored DebugSupport buttons.

This commit is contained in:
Patrick Simpson 2017-02-10 13:30:22 +01:00
parent 5842e90203
commit a56cb98ce8
13 changed files with 73 additions and 61 deletions

View File

@ -48,16 +48,16 @@ namespace Acacia.Features.DebugSupport
public override void AfterStartup()
{
//ShowAbout();
/*DebugDialog dd = new DebugDialog();
dd.Show();
dd.DebugCycle(5);*/
}
#region About dialog
public void ShowAbout()
{
DebugDialog dd = new DebugDialog();
dd.Show();
dd.DebugCycle(5);
new AboutDialog().ShowDialog();
}
#endregion
@ -79,9 +79,7 @@ namespace Acacia.Features.DebugSupport
public void ShowSettings()
{
//new SettingsDialog().ShowDialog();
ThisAddIn.Instance.GetFeature<GAB.FeatureGAB>()?.FullResync();
Tasks.Task(this, "GC", () => Util.GarbageCollect());
new SettingsDialog().ShowDialog();
}
public override FeatureSettings GetSettings()

View File

@ -125,7 +125,7 @@ namespace Acacia
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);
private static readonly BoolOption HOOK_ITEM_EVENTS = new BoolOption("HookItemEvents", false);
#region UI Options

View File

@ -13,5 +13,11 @@ namespace Acacia.Stubs
/// </summary>
/// <returns>The command bars. The caller is responsible for disposing.</returns>
ICommandBars GetCommandBars();
/// <summary>
/// Returns the currently selected folder, or null if no folder is selected.
/// </summary>
/// <returns>The folder. The caller is responsible for disposing.</returns>
IFolder GetCurrentFolder();
}
}

View File

@ -106,5 +106,9 @@ namespace Acacia.Stubs
/// function prevents creating lots of wrappers.
/// </summary>
bool IsAtDepth(int depth);
// TODO: remove this. It's a quick hack to find the events associated with this folder for ZPushWatcher.
// make event watching part of the folder instead
ZPushFolder ZPush { get; set; }
}
}

View File

@ -88,10 +88,7 @@ namespace Acacia.Stubs.OutlookWrappers
public IExplorer GetActiveExplorer()
{
using (ComRelease com = new ComRelease())
{
return new ExplorerWrapper(com.Add(_thisAddIn.Application).ActiveExplorer());
}
return new ExplorerWrapper(_app.ActiveExplorer());
}
#region Window handle

View File

@ -14,9 +14,19 @@ namespace Acacia.Stubs.OutlookWrappers
{
}
protected override void DoRelease()
{
base.DoRelease();
}
public ICommandBars GetCommandBars()
{
return new CommandBarsWrapper(_item.CommandBars);
}
public IFolder GetCurrentFolder()
{
return _item.CurrentFolder.Wrap();
}
}
}

View File

@ -467,5 +467,11 @@ namespace Acacia.Stubs.OutlookWrappers
{
get { return (ItemType)(int)_item.DefaultItemType; }
}
public ZPushFolder ZPush
{
get;
set;
}
}
}

View File

@ -36,18 +36,30 @@ namespace Acacia.Stubs.OutlookWrappers
return new FolderWrapper((NSOutlook.Folder)_item.GetRootFolder());
}
private NSOutlook.MAPIFolder GetDefaultFolderObj(DefaultFolder folder)
{
try
{
return (NSOutlook.Folder)_item.GetDefaultFolder((NSOutlook.OlDefaultFolders)(int)folder);
}
catch(Exception)
{
return null;
}
}
public IFolder GetDefaultFolder(DefaultFolder folder)
{
// FolderWrapper manages the returned Folder
return new FolderWrapper((NSOutlook.Folder)_item.GetDefaultFolder((NSOutlook.OlDefaultFolders)(int)folder));
return GetDefaultFolderObj(folder).Wrap();
}
public string GetDefaultFolderId(DefaultFolder folder)
{
NSOutlook.MAPIFolder mapiFolder = _item.GetDefaultFolder((NSOutlook.OlDefaultFolders)(int)folder);
NSOutlook.MAPIFolder mapiFolder = GetDefaultFolderObj(folder);
try
{
return mapiFolder.EntryID;
return mapiFolder?.EntryID;
}
finally
{

View File

@ -1,4 +1,5 @@
using System;
using Acacia.Stubs.OutlookWrappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -11,7 +12,7 @@ namespace Acacia.Stubs
{
public static IFolder Wrap(this NSOutlook.MAPIFolder obj)
{
throw new NotImplementedException(); // TODO
return Mapping.WrapOrDefault<IFolder>(obj);
}
}
}

View File

@ -28,7 +28,6 @@ using System.Security;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using NSOutlook = Microsoft.Office.Interop.Outlook;
namespace Acacia.ZPush
{

View File

@ -293,7 +293,7 @@ namespace Acacia.ZPush
/// <param name="account">The account. The caller is responsible for releasing this.</param>
/// <returns>The associated ZPushAccount</returns>
/// <exception cref="Exception">If the registry key cannot be found</exception>
// TODO: check management of account
// TODO: check owner
private ZPushAccount CreateFromRegistry(NSOutlook.Account account)
{
// TODO: check that caller releases account everywhere

View File

@ -50,14 +50,16 @@ namespace Acacia.ZPush
this._parent = parent;
this._watcher = watcher;
this._folder = folder;
folder.ZPush = this;
}
protected override void DoRelease()
{
Cleanup();
_folder.Dispose();
}
public IFolder Folder { get; }
public IFolder Folder { get { return _folder; } }
public string Name { get { return _folder.Name; } }
private void Initialise()
@ -75,16 +77,6 @@ namespace Acacia.ZPush
}
}
// TODO
/*public override void Dispose()
{
Logger.Instance.Trace(this, "Disposing folder: {0}", _item.Name);
Cleanup();
base.Dispose();
ComRelease.Release(_items);
ComRelease.Release(_subFolders);
}*/
internal ItemsWatcher ItemsWatcher()
{
ItemsWatcher watcher = new ItemsWatcher();
@ -168,7 +160,7 @@ namespace Acacia.ZPush
}
// Release the folder if not used
ComRelease.Release(child);
child.Dispose();
}
}
}

View File

@ -37,24 +37,27 @@ namespace Acacia.ZPush
/// </summary>
public class ZPushWatcher
{
private readonly IAddIn _addIn;
// TODO: remove
private readonly NSOutlook.Application _app;
public readonly ZPushAccounts Accounts;
public readonly ZPushSync Sync;
private NSOutlook.Explorer _explorer;
private NSOutlook.Explorer _explorer2;
#region Setup
public ZPushWatcher(IAddIn addIn)
{
this._addIn = addIn;
this._app = addIn.RawApp;
Sync = new ZPushSync(this, _app);
Accounts = new ZPushAccounts(this, _app);
// Need to keep a link to keep receiving events
_explorer = _app.ActiveExplorer();
_explorer.SelectionChange += Explorer_SelectionChange;
_explorer2 = _app.ActiveExplorer();
_explorer2.SelectionChange += Explorer_SelectionChange;
}
/// <summary>
@ -208,17 +211,15 @@ namespace Acacia.ZPush
{
if (ActiveFolderChange != null)
{
NSOutlook.MAPIFolder active = _explorer.CurrentFolder;
if (active != null)
using (IFolder folder = _addIn.GetActiveExplorer()?.GetCurrentFolder())
{
using (IFolder folder = Mapping.Wrap<IFolder>(active))
try
{
try
{
if (folder != null)
ActiveFolderChange(folder);
}
catch (System.Exception e) { Logger.Instance.Error(this, "Exception in Explorer_SelectionChange.ActiveFolderChange: {0}", e); }
}
catch (System.Exception e) { Logger.Instance.Error(this, "Exception in Explorer_SelectionChange.ActiveFolderChange: {0}", e); }
}
}
// TODO: cache value
@ -236,18 +237,13 @@ namespace Acacia.ZPush
public ZPushAccount CurrentZPushAccount()
{
if (_explorer.CurrentFolder == null)
return null;
NSOutlook.MAPIFolder folder = _explorer.CurrentFolder;
try
using (IExplorer explorer = _addIn.GetActiveExplorer())
using (IFolder folder = explorer?.GetCurrentFolder())
{
if (folder == null)
return null;
return Accounts.GetAccount(folder);
}
finally
{
ComRelease.Release(folder);
}
}
#endregion
@ -392,17 +388,8 @@ namespace Acacia.ZPush
if (!DebugOptions.GetOption(null, DebugOptions.WATCHER_ENABLED))
return;
// Must have a ZPush folder to watch events, create one if necessary
ZPushFolder zPushFolder;
if (!(folder is ZPushFolder))
{
// TODO
throw new NotImplementedException();
}
else
{
zPushFolder = (ZPushFolder)folder;
}
// Must have a ZPush folder to watch events.
ZPushFolder zPushFolder = folder.ZPush;
// Register the handlers
ItemsWatcher watcher = zPushFolder.ItemsWatcher();