/// <summary>
        /// Fires when the plug-in should become inactive
        /// </summary>
        public override void Deactivate()
        {
            App.HeaderControl.RemoveAll();

            App.Map.LayerAdded                     -= Map_LayerAdded;
            App.Map.Layers.LayerRemoved            -= Layers_LayerRemoved;
            App.SerializationManager.Deserializing -= SerializationManager_Deserializing;
            DownloadManager.Completed              -= DownloadManager_Completed;

            foreach (var layer in App.Map.MapFrame.Layers)
            {
                UnattachLayerFromPlugin(layer);
            }
            if (_searchLayerInformer != null)
            {
                _searchLayerInformer.Stop();
                _searchLayerInformer = null;
            }

            Global.PluginEntryPoint = null;

            // Remove added menu items from SeriesControl ContextMenu
            SeriesControl.ContextMenuStrip.Items.Remove(_seriesControlUpdateValuesMenuItem);

            // This line ensures that "Enabled" is set to false.
            base.Deactivate();
        }
        /// <summary>
        /// Fires when the plug-in should become inactive
        /// </summary>
        public override void Deactivate()
        {
            App.HeaderControl.RemoveAll();

            // Unsubscribe from events
            App.Map.LayerAdded                     -= Map_LayerAdded;
            App.Map.Layers.LayerRemoved            -= Layers_LayerRemoved;
            App.SerializationManager.Deserializing -= SerializationManager_Deserializing;
            DownloadManager.Completed              -= DownloadManager_Completed;
            App.ExtensionsActivated                -= AppOnExtensionsActivated;
            App.DockManager.PanelHidden            -= DockManager_PanelHidden;

            foreach (var layer in App.Map.MapFrame.Layers)
            {
                UnattachLayerFromPlugin(layer);
            }
            if (_searchLayerInformer != null)
            {
                _searchLayerInformer.Deactivate();
                _searchLayerInformer = null;
            }

            // Remove added menu items from SeriesControl ContextMenu
            SeriesControl.ContextMenuStrip.Items.Remove(_seriesControlUpdateValuesMenuItem);

            // This line ensures that "Enabled" is set to false.
            base.Deactivate();
        }
        private void AttachLayerToPlugin(ILayer layer, bool isDeserializing = false)
        {
            if (SearchLayerModifier.IsSearchLayer(layer))
            {
                if (_searchLayerInformer == null)
                {
                    // Create popup-informer
                    var extractor = new HISCentralInfoExtractor(new Lazy <Dictionary <string, string> >(() => HisCentralServices.Services));
                    _searchLayerInformer = new SearchLayerInformer(extractor, (Map)App.Map);
                }

                var lm = SearchLayerModifier.Create(layer, (Map)App.Map, this);
                Debug.Assert(lm != null);

                if (!isDeserializing)
                {
                    lm.UpdateLabeling();
                    lm.UpdateSymbolizing();
                }
                lm.UpdateContextMenu();

                btnDownload1.Enabled = true;
                btnDownload2.Enabled = true;
            }

            var group = layer as IGroup;

            if (group != null)
            {
                group.LayerAdded   += Map_LayerAdded;
                group.LayerRemoved += Layers_LayerRemoved;

                foreach (var child in group.GetLayers())
                {
                    AttachLayerToPlugin(child, isDeserializing);
                }
            }
        }
        private void AttachLayerToPlugin(ILayer layer, bool isDeserializing = false)
        {
            if (SearchLayerModifier.IsSearchLayer(layer))
            {
                if (_searchLayerInformer == null)
                {
                    // Create popup-informer
                    var extractor = new HISCentralInfoExtractor(new Lazy <Dictionary <string, string> >(() => new HisCentralServices(App).Services));
                    _searchLayerInformer = new SearchLayerInformer(this, extractor, (Map)App.Map);
                }

                var lm = SearchLayerModifier.Create(layer, (Map)App.Map, this);
                Debug.Assert(lm != null);

                if (!isDeserializing)
                {
                    lm.UpdateLabeling();
                    lm.UpdateSymbolizing();
                }
                lm.UpdateContextMenu();

                if (_btnDownloadInSearch != null)
                {
                    _btnDownloadInSearch.Enabled = true;
                }
                if (_btnSearchOptions != null)
                {
                    _btnSearchOptions.Enabled = true;
                }
                //if (_btnSearchOptions != null)
                //{
                //    _btnSearchOptions.Enabled = true;
                //}
                if (_btnSearchResults != null)
                {
                    _btnSearchResults.Enabled = true;
                }
                if (_btnShowPopups != null)
                {
                    if (!_btnShowPopups.Enabled)
                    {
                        _btnShowPopups.Enabled = true;
                    }
                    if (!ShowPopups)
                    {
                        _btnShowPopups.Toggle();
                    }
                }


                //_btnDownload.Enabled = true;
                //_btnUpdate.Enabled = true;
                //_btnShowPopups.Enabled = true;
            }

            var group = layer as IGroup;

            if (group != null)
            {
                group.LayerAdded   += Map_LayerAdded;
                group.LayerRemoved += Layers_LayerRemoved;

                foreach (var child in group.GetLayers())
                {
                    AttachLayerToPlugin(child, isDeserializing);
                }
            }
        }