Esempio n. 1
0
        public CodeBackgroundTextAdornment(
            IWpfTextView view,
            IClassificationFormatMapService classificationFormatMapService,
            IClassificationTypeRegistryService classificationTypeRegistry,
            ICoreShell coreShell)
        {
            _view  = view;
            _layer = view.GetAdornmentLayer("CodeBackgroundTextAdornment");

            _classificationTypeRegistry = classificationTypeRegistry;
            _classificationFormatMap    = classificationFormatMapService.GetClassificationFormatMap(view);
            _coreShell = coreShell;

            // Advise to events
            _classificationFormatMap.ClassificationFormatMappingChanged += OnClassificationFormatMappingChanged;
            _view.LayoutChanged += OnLayoutChanged;
            _view.Closed        += OnClosed;

            var projectionBufferManager = ServiceManager.GetService <IProjectionBufferManager>(view.TextBuffer);

            if (projectionBufferManager != null)
            {
                projectionBufferManager.MappingsChanged += OnMappingsChanged;
                _contanedLanguageHandler = ServiceManager.GetService <IContainedLanguageHandler>(projectionBufferManager.DiskBuffer);
                if (_contanedLanguageHandler == null)
                {
                    ServiceManager.AdviseServiceAdded <IContainedLanguageHandler>(projectionBufferManager.DiskBuffer, _coreShell, (s) => _contanedLanguageHandler = s);
                }
            }

            FetchColors();
        }
Esempio n. 2
0
        public void ServiceManager_Test01()
        {
            PropertyOwner propertyOwner = new PropertyOwner();
            Service1      s1            = new Service1();
            bool          added         = false;
            bool          removed       = false;

            ServiceManager.AdviseServiceAdded <IService1>(propertyOwner, null, s => { added = true; });

            // Verify notifications not sent out when advising
            added.Should().BeFalse();

            // Verify notifications not sent out after adding other service
            ServiceManager.AddService <Service1>(s1, propertyOwner, null);
            added.Should().BeFalse();

            // Verify added notification sent out after adding this service
            ServiceManager.AddService <IService1>(s1, propertyOwner, null);
            added.Should().BeTrue();

            added = false;
            ServiceManager.AdviseServiceRemoved <IService1>(propertyOwner, null, s => { removed = true; });

            // Verify notifications not sent out after removing other service
            ServiceManager.RemoveService <Service1>(propertyOwner);
            removed.Should().BeFalse();

            // Verify removed notification sent out after adding this service
            ServiceManager.RemoveService <IService1>(propertyOwner);
            removed.Should().BeTrue();

            // Verify we aren't still listening to advised events
            ServiceManager.AddService <IService1>(s1, propertyOwner, null);
            added.Should().BeFalse();

            // Verify notification sent out when advising to existing service
            ServiceManager.AdviseServiceAdded <IService1>(propertyOwner, null, s => { added = true; });
            added.Should().BeTrue();
        }