<commit_before>﻿/// Copyright 2016 <NAME>.
/// 
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License, version 3,
/// as published by the Free Software Foundation.
/// 
/// This program is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
/// GNU Affero General Public License for more details.
/// 
/// You should have received a copy of the GNU Affero General Public License
/// along with this program.If not, see<http://www.gnu.org/licenses/>.
/// 
/// Consult LICENSE file for details

using Acacia.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Acacia.ZPush;
using Acacia.Utils;
using System.Threading;
using Acacia.ZPush.API.SharedFolders;
using Acacia.ZPush.Connect;
using Acacia.Native;
using Acacia.Features.GAB;
using Acacia.Features.SendAs;
using Acacia.Stubs;

namespace Acacia.Features.SharedFolders
{
    /// <summary>
    /// A tree node representing the root node for a store. Responsible for loading the store contents and managing the
    /// shares for that store.
    /// </summary>
    public class StoreTreeNode : KTreeNode
    {
        private KAnimator _reloader;

        // The initial and current shares states. The initial state is kept to check for modifications
        private readonly Dictionary<BackendId, SharedFolder> _initialShares;
        private readonly Dictionary<BackendId, SharedFolder> _currentShares;

        private readonly FeatureSharedFolders _feature;
        private readonly FeatureSendAs _featureSendAs;
        private readonly ZPushAccount _account;
        private readonly GABHandler _gab;
        private readonly GABUser _user;
        private readonly string _sendAsAddress;

        public readonly bool IsReadOnly;

        private bool _isShared;
        public bool IsShared
        {
            get { return _isShared; }
            set
            {
                if (value != _isShared)
                {
                    _isShared = value;
                }
            }
        }

        public bool ShowReminders
        {
            get;
            set;
        }
        public bool ShowRemindersInitial
        {
            get;
            set;
        }

        public StoreTreeNode(SharedFoldersManager folders, GABHandler gab, GABUser user, string sendAsAddress, string text, 
                             Dictionary<BackendId, SharedFolder> currentFolders, bool isShared, bool showRemindersWholeStore)
        :
        base(text)
        {
            this._initialShares = currentFolders;
            // Patch in send as address
            foreach (SharedFolder share in _initialShares.Values)
                if (string.IsNullOrWhiteSpace(share.SendAsAddress))
                    share.SendAsAddress = sendAsAddress;
            this._feature = folders.Feature;
            this._featureSendAs = ThisAddIn.Instance.GetFeature<FeatureSendAs>();
            this._account = folders.Account;
            this._gab = gab;
            this._user = user;
            this._sendAsAddress = sendAsAddress;
            this.IsReadOnly = false;
            this._isShared = isShared;

            // Create an empty current state. When loading the nodes, the shares will be added. This has the benefit of
            // cleaning up automatically any obsolote shares.
            this._currentShares = new Dictionary<BackendId, SharedFolder>();

            ChildLoader = new UserFolderLoader(this, folders, user);
            ChildLoader.ReloadOnCloseOpen = true;
            HasCheckBox = folders.SupportsWholeStore && !string.IsNullOrWhiteSpace(user.EmailAddress);
            ApplyReadOnly(this, IsReadOnly);

            // TODO: better icons, better way of handling this
            ImageIndex = user == GABUser.USER_PUBLIC ? 0 : 11;

            // Reloader
            _reloader = new KAnimator();
            _reloader.Animation = Properties.Resources.TreeLoading;
            _reloader.Visible = false;
            _reloader.Click += (s, e) =>
            {
                ChildLoader.Reload();
            };
            Control = _reloader;

            // Set up sharing
            WantShare = isShared;<commit_msg>[KOE-166] Showing checkbox for impersonated stores that are already opened even without an email address, to allow removing it<commit_after>﻿/// Copyright 2016 <NAME>.v.
/// 
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License, version 3,
/// as published by the Free Software Foundation.
/// 
/// This program is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
/// GNU Affero General Public License for more details.
/// 
/// You should have received a copy of the GNU Affero General Public License
/// along with this program.If not, see<http://www.gnu.org/licenses/>.
/// 
/// Consult LICENSE file for details

using Acacia.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Acacia.ZPush;
using Acacia.Utils;
using System.Threading;
using Acacia.ZPush.API.SharedFolders;
using Acacia.ZPush.Connect;
using Acacia.Native;
using Acacia.Features.GAB;
using Acacia.Features.SendAs;
using Acacia.Stubs;

namespace Acacia.Features.SharedFolders
{
    /// <summary>
    /// A tree node representing the root node for a store. Responsible for loading the store contents and managing the
    /// shares for that store.
    /// </summary>
    public class StoreTreeNode : KTreeNode
    {
        private KAnimator _reloader;

        // The initial and current shares states. The initial state is kept to check for modifications
        private readonly Dictionary<BackendId, SharedFolder> _initialShares;
        private readonly Dictionary<BackendId, SharedFolder> _currentShares;

        private readonly FeatureSharedFolders _feature;
        private readonly FeatureSendAs _featureSendAs;
        private readonly ZPushAccount _account;
        private readonly GABHandler _gab;
        private readonly GABUser _user;
        private readonly string _sendAsAddress;

        public readonly bool IsReadOnly;

        private bool _isShared;
        public bool IsShared
        {
            get { return _isShared; }
            set
            {
                if (value != _isShared)
                {
                    _isShared = value;
                }
            }
        }

        public bool ShowReminders
        {
            get;
            set;
        }
        public bool ShowRemindersInitial
        {
            get;
            set;
        }

        public StoreTreeNode(SharedFoldersManager folders, GABHandler gab, GABUser user, string sendAsAddress, string text, 
                             Dictionary<BackendId, SharedFolder> currentFolders, bool isShared, bool showRemindersWholeStore)
        :
        base(text)
        {
            this._initialShares = currentFolders;
            // Patch in send as address
            foreach (SharedFolder share in _initialShares.Values)
                if (string.IsNullOrWhiteSpace(share.SendAsAddress))
                    share.SendAsAddress = sendAsAddress;
            this._feature = folders.Feature;
            this._featureSendAs = ThisAddIn.Instance.GetFeature<FeatureSendAs>();
            this._account = folders.Account;
            this._gab = gab;
            this._user = user;
            this._sendAsAddress = sendAsAddress;
            this.IsReadOnly = false;
            this._isShared = isShared;

            // Create an empty current state. When loading the nodes, the shares will be added. This has the benefit of
            // cleaning up automatically any obsolote shares.
            this._currentShares = new Dictionary<BackendId, SharedFolder>();

            ChildLoader = new UserFolderLoader(this, folders, user);
            ChildLoader.ReloadOnCloseOpen = true;
            // Can only open the whole store if it's supported and there's an email address, as that's needed to open it
            // However, if it's already opened, we can remove it without the email address
            HasCheckBox = folders.SupportsWholeStore && (!string.IsNullOrWhiteSpace(user.EmailAddress) || isShared);
            ApplyReadOnly(this, IsReadOnly);

            // TODO: better icons, better way of handling this
            ImageIndex = user == GABUser.USER_PUBLIC ? 0 : 11;

            // Reloader
            _reloader = new KAnimator();
            _reloader.Animation = Properties.Resources.TreeLoading;
            _reloader.Visible = false;
            _reloader.Click += (s, e) =>
            {
                ChildLoader.Reload();
            };
            Control = _reloader;

            // Set up sharing
            WantShare = isShared;
{'fraction_non_alphanumeric': 0.07329043516195878, 'fraction_numerical': 0.0020721998036863343, 'mean_word_length': 2.125426039536469, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '682519', 'n_tokens_mistral': 2324, 'n_tokens_neox': 2257, 'n_words': 777}