1
0
mirror of https://github.com/Kopano-dev/kopano-ol-extension.git synced 2023-10-10 13:37:40 +02:00

[KOE-20] Move of items into Kopano Folders is now suppressed, with a warning. Also only hiding "Deleted Items" in it now.

This commit is contained in:
Patrick Simpson 2018-04-18 13:30:55 +03:00
parent 772c4630b7
commit f248bc7dd4
5 changed files with 106 additions and 17 deletions

View File

@ -194,7 +194,7 @@ namespace Acacia.Features
#region Event helpers
protected static MailEvents MailEvents
public static MailEvents MailEvents
{
get
{
@ -202,7 +202,7 @@ namespace Acacia.Features
}
}
protected ZPushWatcher Watcher
public ZPushWatcher Watcher
{
get
{

View File

@ -71,15 +71,24 @@ namespace Acacia.Features.GAB
public override void Startup()
{
if (SuppressModifications && MailEvents != null)
SetupModificationSuppression();
Watcher.AccountDiscovered += AccountDiscovered;
Watcher.AccountRemoved += AccountRemoved;
Watcher.AccountsScanned += AccountsScanned;
}
private void SetupModificationSuppression()
{
if (MailEvents == null)
return;
// GAB modification suppression
if (SuppressModifications)
{
MailEvents.BeforeDelete += SuppressEventHandler_Delete;
MailEvents.PropertyChange += SuppressEventHandler_PropertyChange;
MailEvents.Write += SuppressEventHandler_Write;
}
Watcher.AccountDiscovered += AccountDiscovered;
Watcher.AccountRemoved += AccountRemoved;
Watcher.AccountsScanned += AccountsScanned;
}
#region Settings
@ -367,7 +376,7 @@ namespace Acacia.Features.GAB
// Delete any contacts folders in the local store
if (DeleteExistingFolder)
{
using (IStore store = ZPushLocalStore.GetInstance(ThisAddIn.Instance))
using (IStore store = ZPushLocalStore.GetInstance(ThisAddIn.Instance, this))
{
if (store != null)
{
@ -471,7 +480,7 @@ namespace Acacia.Features.GAB
_store.Dispose();
_store = null;
}
_store = ZPushLocalStore.GetInstance(ThisAddIn.Instance);
_store = ZPushLocalStore.GetInstance(ThisAddIn.Instance, this);
if (_store == null)
return null;
@ -614,7 +623,7 @@ namespace Acacia.Features.GAB
_store.Dispose();
_store = null;
}
_store = ZPushLocalStore.GetInstance(ThisAddIn.Instance);
_store = ZPushLocalStore.GetInstance(ThisAddIn.Instance, this);
if (_store == null)
return;

View File

@ -205,6 +205,24 @@ namespace Acacia.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Storing items in Kopano Folders is not supported..
/// </summary>
internal static string LocalStore_Move_Body {
get {
return ResourceManager.GetString("LocalStore_Move_Body", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Kopano Folders.
/// </summary>
internal static string LocalStore_Move_Title {
get {
return ResourceManager.GetString("LocalStore_Move_Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to There are unsaved changes. Do you really want to to discard these?.
/// </summary>

View File

@ -539,4 +539,10 @@ Please contact your system administrator for any required changes.</value>
<data name="SharedFolders_SendAsUpdateFailed_Label" xml:space="preserve">
<value>Unable to determine the send-as email address for the existing shared folder {0}. Send-as will only work if you specify the email address manually. Would you like to open the Shared Folders dialog?</value>
</data>
<data name="LocalStore_Move_Body" xml:space="preserve">
<value>Storing items in Kopano Folders is not supported.</value>
</data>
<data name="LocalStore_Move_Title" xml:space="preserve">
<value>Kopano Folders</value>
</data>
</root>

View File

@ -23,6 +23,9 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Acacia.Features.GAB;
using Acacia.Features;
using System.Windows.Forms;
namespace Acacia.ZPush
{
@ -35,7 +38,7 @@ namespace Acacia.ZPush
/// Returns or creates the local store.
/// </summary>
/// <returns>The store, or null on error. If a store is returned, the caller is responsible for disposing.</returns>
public static IStore GetInstance(IAddIn addIn)
public static IStore GetInstance(IAddIn addIn, Feature feature)
{
IStore store = OpenOrCreateInstance(addIn);
if (store == null)
@ -44,6 +47,7 @@ namespace Acacia.ZPush
try
{
HideAllFolders(store);
SetupChangeSuppression(store, feature);
return store;
}
catch(Exception e)
@ -106,6 +110,60 @@ namespace Acacia.ZPush
}
}
private static readonly Dictionary<string, Suppressor> _suppressors = new Dictionary<string, Suppressor>();
private static void SetupChangeSuppression(IStore localStore, Feature feature)
{
string localStoreID = localStore.StoreID;
if (!_suppressors.ContainsKey(localStoreID))
{
_suppressors.Add(localStoreID, new Suppressor(localStoreID, feature));
}
}
private class Suppressor
{
private readonly string _localStoreID;
public Suppressor(string localStoreID, Feature feature)
{
this._localStoreID = localStoreID;
feature.Watcher.WatchFolder(new FolderRegistrationAny(feature),
(folder) =>
{
folder.BeforeFolderMove += Folder_BeforeFolderMove;
folder.BeforeItemMove += Folder_BeforeItemMove;
});
}
private void Folder_BeforeItemMove(IFolder src, IItem item, IFolder moveTo, ref bool cancel)
{
SuppressCore(src, item, moveTo, ref cancel);
}
private void Folder_BeforeFolderMove(IFolder src, IFolder moveTo, ref bool cancel)
{
SuppressCore(src, null, moveTo, ref cancel);
}
private void SuppressCore(IFolder src, IItem item, IFolder moveTo, ref bool cancel)
{
if (moveTo.StoreID == _localStoreID)
{
Logger.Instance.Trace(this, "Move into Kopano Folders: {0} - {1}: {2}", src.Name, src.EntryID, item?.EntryID);
cancel = true;
MessageBox.Show(ThisAddIn.Instance.Window,
Properties.Resources.LocalStore_Move_Body,
Properties.Resources.LocalStore_Move_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Warning
);
}
}
}
private static IStore FindInstance(IAddIn addIn, string prefix)
{
foreach (IStore store in addIn.Stores)
@ -122,16 +180,14 @@ namespace Acacia.ZPush
}
return null;
}
private static bool IsCustomFolder(IFolder folder)
{
return Features.GAB.FeatureGAB.IsGABContactsFolder(folder, null);
}
private static void HideAllFolders(IStore store)
{
if (GlobalOptions.INSTANCE.LocalFolders_Hide)
{
HashSet<string> hideIds = new HashSet<string>();
hideIds.Add(store.GetDefaultFolderId(DefaultFolder.DeletedItems));
// Hide the folders that are not custom folders
using (IFolder root = store.GetRootFolder())
{
@ -139,7 +195,7 @@ namespace Acacia.ZPush
{
using (sub)
{
sub.AttrHidden = !IsCustomFolder(sub);
sub.AttrHidden = hideIds.Contains(sub.EntryID);
}
}
}