<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Windows.Forms;
using DotSpatial.Controls.Docking;

namespace DotSpatial.Controls
{
    /// <summary>
    /// Simple dock manager implementation. It can be used in design time.
    /// </summary>
    [PartNotDiscoverable] // Do not allow discover this class by MEF
    public class SpatialDockManager : SplitContainer, IDockManager
    {
        private readonly Dictionary<string, TabPage> _allTabs = new Dictionary<string, TabPage>();

        public SpatialDockManager()
        {
            Panel1.ControlAdded += delegate(object sender, ControlEventArgs args)
            {
                if (TabControl1 != null) return;
                TabControl1 = args.Control as TabControl;
            };
            Panel2.ControlAdded += delegate(object sender, ControlEventArgs args)
            {
                if (TabControl2 != null) return;
                TabControl2 = args.Control as TabControl;
            };
            Panel1.ControlRemoved += delegate(object sender, ControlEventArgs args)
            {
                if (args.Control == TabControl1) TabControl1 = null;
            };
            Panel2.ControlRemoved += delegate(object sender, ControlEventArgs args)
            {
                if (args.Control == TabControl2) TabControl2 = null;
            };
          
        }

        /// <summary>
        /// Gets or sets TabControl For Panel1. It used for storing Left and Top panels.
        /// </summary>
        [Description("Gets or sets TabControl For Panel1. It used for storing Left and Top panels.")]
        public TabControl TabControl1 { get; set; }

        /// <summary>
        /// Gets or sets TabControl For Panel2. It used for storing Right and Bottom panels.
        /// </summary>
        [Description("Gets or sets TabControl For Panel2. It used for storing Right and Bottom panels.")]
        public TabControl TabControl2 { get; set; }

        /// <summary>
        /// Add default tab controls to the dock manager
        /// </summary>
        public void AddDefaultTabControls()
        {
            if (TabControl1 == null)
            {
                Panel1.Controls.Add(new TabControl {Dock = DockStyle.Fill});
                Debug.Assert(TabControl1 != null);
            }
            if (TabControl2 == null)
            {
                Panel2.Controls.Add(new TabControl {Dock = DockStyle.Fill});
                Debug.Assert(TabControl2 != null);
            }
        }

        public event EventHandler<DockablePanelEventArgs> ActivePanelChanged;
        public event EventHandler<DockablePanelEventArgs> PanelClosed;
        public event EventHandler<DockablePanelEventArgs> PanelAdded;
        public event EventHandler<DockablePanelEventArgs> PanelRemoved;
        public event EventHandler<DockablePanelEventArgs> PanelHidden;

        public void Add(DockablePanel panel)
        {
            if (panel == null) throw new ArgumentNullException("panel");

            TabControl tabControl;
            if (panel.Dock == DockStyle.Left || panel.Dock == DockStyle.Top)
            {
                tabControl = TabControl1;
            }
            else
            {
                tabControl = TabControl2;
            }
            if (tabControl == null) return;

            var tabPage = new TabPage
                          {
                              Name = panel.Key,
                              Text = panel.Caption,
                          };
            tabPage.VisibleChanged += TabPageOnVisibleChanged;

            panel.InnerControl.Dock = DockStyle.Fill;
            tabPage.Controls.Add(panel.InnerControl);

            _allTabs.Add(panel.Key, tabPage);
            tabControl.TabPages.Add(tabPage);
            OnPanelAdded(new DockablePanelEventArgs(panel.Key));
            OnActivePanelChanged(new DockablePanelEventArgs(panel.Key));
        }

        private void TabPageOnVisibleChanged(object sender, EventArgs eventArgs)
        {
            var tabPage = (TabPage)sender;
            if (!tabPage.Visible)
            {
                OnPanelHidden(new DockablePanelEventArgs(tabPage.Name));
            }
        }

        public void Remove(string key)
        {
            var tabPage = GetByKey(key);
            if (tabPage == null) return;

            ((TabControl)tabPage.Parent).TabPages.Remove(tabPage);
            tabPage.VisibleChanged -= TabPageOnVisibleChanged;
            OnPanelRemoved(new DockablePanelEventArgs(key));
        }

        public void ResetLayout()
        {
            foreach (var tabPage in _allTabs)
            {
                tabPage.Value.Show();
            }
        }

        public void SelectPanel(string key)
        {
            var tabPage = GetByKey(key);
            if (tabPage == null) return;
            
            ((TabControl)tabPage.Parent).SelectTab(tabPage);
            OnActivePanelChanged(new DockablePanelEventArgs(key));
        }

        public void HidePanel(string key)
        {
            var tabPage = GetByKey(key);
            if (tabPage == null) return;

            var tabControl = ((TabControl) tabPage.Parent);
            // Select another tab (if any)
            var i = 0;<commit_msg>Remove the key from _allTabs on removing TabPage<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Windows.Forms;
using DotSpatial.Controls.Docking;

namespace DotSpatial.Controls
{
    /// <summary>
    /// Simple dock manager implementation. It can be used in design time.
    /// </summary>
    [PartNotDiscoverable] // Do not allow discover this class by MEF
    public class SpatialDockManager : SplitContainer, IDockManager
    {
        private readonly Dictionary<string, TabPage> _allTabs = new Dictionary<string, TabPage>();

        public SpatialDockManager()
        {
            Panel1.ControlAdded += delegate(object sender, ControlEventArgs args)
            {
                if (TabControl1 != null) return;
                TabControl1 = args.Control as TabControl;
            };
            Panel2.ControlAdded += delegate(object sender, ControlEventArgs args)
            {
                if (TabControl2 != null) return;
                TabControl2 = args.Control as TabControl;
            };
            Panel1.ControlRemoved += delegate(object sender, ControlEventArgs args)
            {
                if (args.Control == TabControl1) TabControl1 = null;
            };
            Panel2.ControlRemoved += delegate(object sender, ControlEventArgs args)
            {
                if (args.Control == TabControl2) TabControl2 = null;
            };
          
        }

        /// <summary>
        /// Gets or sets TabControl For Panel1. It used for storing Left and Top panels.
        /// </summary>
        [Description("Gets or sets TabControl For Panel1. It used for storing Left and Top panels.")]
        public TabControl TabControl1 { get; set; }

        /// <summary>
        /// Gets or sets TabControl For Panel2. It used for storing Right and Bottom panels.
        /// </summary>
        [Description("Gets or sets TabControl For Panel2. It used for storing Right and Bottom panels.")]
        public TabControl TabControl2 { get; set; }

        /// <summary>
        /// Add default tab controls to the dock manager
        /// </summary>
        public void AddDefaultTabControls()
        {
            if (TabControl1 == null)
            {
                Panel1.Controls.Add(new TabControl {Dock = DockStyle.Fill});
                Debug.Assert(TabControl1 != null);
            }
            if (TabControl2 == null)
            {
                Panel2.Controls.Add(new TabControl {Dock = DockStyle.Fill});
                Debug.Assert(TabControl2 != null);
            }
        }

        public event EventHandler<DockablePanelEventArgs> ActivePanelChanged;
        public event EventHandler<DockablePanelEventArgs> PanelClosed;
        public event EventHandler<DockablePanelEventArgs> PanelAdded;
        public event EventHandler<DockablePanelEventArgs> PanelRemoved;
        public event EventHandler<DockablePanelEventArgs> PanelHidden;

        public void Add(DockablePanel panel)
        {
            if (panel == null) throw new ArgumentNullException("panel");

            TabControl tabControl;
            if (panel.Dock == DockStyle.Left || panel.Dock == DockStyle.Top)
            {
                tabControl = TabControl1;
            }
            else
            {
                tabControl = TabControl2;
            }
            if (tabControl == null) return;

            var tabPage = new TabPage
                          {
                              Name = panel.Key,
                              Text = panel.Caption,
                          };
            tabPage.VisibleChanged += TabPageOnVisibleChanged;

            panel.InnerControl.Dock = DockStyle.Fill;
            tabPage.Controls.Add(panel.InnerControl);

            _allTabs.Add(panel.Key, tabPage);
            tabControl.TabPages.Add(tabPage);
            OnPanelAdded(new DockablePanelEventArgs(panel.Key));
            OnActivePanelChanged(new DockablePanelEventArgs(panel.Key));
        }

        private void TabPageOnVisibleChanged(object sender, EventArgs eventArgs)
        {
            var tabPage = (TabPage)sender;
            if (!tabPage.Visible)
            {
                OnPanelHidden(new DockablePanelEventArgs(tabPage.Name));
            }
        }

        public void Remove(string key)
        {
            var tabPage = GetByKey(key);
            if (tabPage == null) return;

            ((TabControl)tabPage.Parent).TabPages.Remove(tabPage);
            _allTabs.Remove(key);
            tabPage.VisibleChanged -= TabPageOnVisibleChanged;
            OnPanelRemoved(new DockablePanelEventArgs(key));
        }

        public void ResetLayout()
        {
            foreach (var tabPage in _allTabs)
            {
                tabPage.Value.Show();
            }
        }

        public void SelectPanel(string key)
        {
            var tabPage = GetByKey(key);
            if (tabPage == null) return;
            
            ((TabControl)tabPage.Parent).SelectTab(tabPage);
            OnActivePanelChanged(new DockablePanelEventArgs(key));
        }

        public void HidePanel(string key)
        {
            var tabPage = GetByKey(key);
            if (tabPage == null) return;

            var tabControl = ((TabControl) tabPage.Parent);
            // Select another tab (if any)
            var i = 0;
{'fraction_non_alphanumeric': 0.08580674988441979, 'fraction_numerical': 0.0049930651872399446, 'mean_word_length': 1.7423935091277891, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3217945', 'n_tokens_mistral': 2749, 'n_tokens_neox': 2643, 'n_words': 689}