Beispiel #1
0
 /// <summary>
 /// Constructor that calls base and caches off the action lists.
 /// </summary>
 internal DesignerActionBehavior(IServiceProvider serviceProvider, IComponent relatedComponent, DesignerActionListCollection actionLists, DesignerActionUI parentUI)
 {
     _actionLists      = actionLists;
     _serviceProvider  = serviceProvider;
     _relatedComponent = relatedComponent;
     _parentUI         = parentUI;
 }
        private bool _selectionChanging;                    //we dont want the OnSelectionChanged to be recursively called.

        /// <summary>
        ///  Constructor.  Here we query for necessary services and cache them for perf. reasons. We also hook to Component Added/Removed/Changed notifications so we can keep in sync when the designers' components change.  Also, we create our custom Adorner and add it to the BehaviorService.
        /// </summary>
        public SelectionManager(IServiceProvider serviceProvider, BehaviorService behaviorService)
        {
            _prevSelectionBounds  = null;
            _prevPrimarySelection = null;
            _behaviorService      = behaviorService;
            _serviceProvider      = serviceProvider;

            _selSvc       = (ISelectionService)serviceProvider.GetService(typeof(ISelectionService));
            _designerHost = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost));

            if (_designerHost is null || _selSvc is null)
            {
                Debug.Fail("SelectionManager - Host or SelSvc is null, can't continue");
            }

            //sync the BehaviorService's begindrag event
            behaviorService.BeginDrag += new BehaviorDragDropEventHandler(OnBeginDrag);

            //sync the BehaviorService's Synchronize event
            behaviorService.Synchronize += new EventHandler(OnSynchronize);

            _selSvc.SelectionChanged += new EventHandler(OnSelectionChanged);
            _rootComponent            = (Control)_designerHost.RootComponent;

            //create and add both of our adorners,
            //one for selection, one for bodies
            _selectionAdorner = new Adorner();
            _bodyAdorner      = new Adorner();
            behaviorService.Adorners.Add(_bodyAdorner);
            behaviorService.Adorners.Add(_selectionAdorner); //adding this will cause the adorner to get setup with a ptr
                                                             //to the beh.svc.

            _componentToDesigner = new Hashtable();

            IComponentChangeService cs = (IComponentChangeService)serviceProvider.GetService(typeof(IComponentChangeService));

            if (cs != null)
            {
                cs.ComponentAdded   += new ComponentEventHandler(OnComponentAdded);
                cs.ComponentRemoved += new ComponentEventHandler(OnComponentRemoved);
                cs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
            }

            _designerHost.TransactionClosed += new DesignerTransactionCloseEventHandler(OnTransactionClosed);

            // designeraction UI
            if (_designerHost.GetService(typeof(DesignerOptionService)) is DesignerOptionService options)
            {
                PropertyDescriptor p = options.Options.Properties["UseSmartTags"];
                if (p != null && p.PropertyType == typeof(bool) && (bool)p.GetValue(null))
                {
                    _designerActionUI = new DesignerActionUI(serviceProvider, _selectionAdorner);
                    behaviorService.DesignerActionUI = _designerActionUI;
                }
            }
        }
 public void Dispose()
 {
     if (this.designerHost != null)
     {
         this.designerHost.TransactionClosed -= new DesignerTransactionCloseEventHandler(this.OnTransactionClosed);
         this.designerHost = null;
     }
     if (this.serviceProvider != null)
     {
         IComponentChangeService service = (IComponentChangeService)this.serviceProvider.GetService(typeof(IComponentChangeService));
         if (service != null)
         {
             service.ComponentAdded   -= new ComponentEventHandler(this.OnComponentAdded);
             service.ComponentChanged -= new ComponentChangedEventHandler(this.OnComponentChanged);
             service.ComponentRemoved -= new ComponentEventHandler(this.OnComponentRemoved);
         }
         if (this.selSvc != null)
         {
             this.selSvc.SelectionChanged -= new EventHandler(this.OnSelectionChanged);
             this.selSvc = null;
         }
         this.serviceProvider = null;
     }
     if (this.behaviorService != null)
     {
         this.behaviorService.Adorners.Remove(this.bodyAdorner);
         this.behaviorService.Adorners.Remove(this.selectionAdorner);
         this.behaviorService.BeginDrag   -= new BehaviorDragDropEventHandler(this.OnBeginDrag);
         this.behaviorService.Synchronize -= new EventHandler(this.OnSynchronize);
         this.behaviorService              = null;
     }
     if (this.selectionAdorner != null)
     {
         this.selectionAdorner.Glyphs.Clear();
         this.selectionAdorner = null;
     }
     if (this.bodyAdorner != null)
     {
         this.bodyAdorner.Glyphs.Clear();
         this.bodyAdorner = null;
     }
     if (this.designerActionUI != null)
     {
         this.designerActionUI.Dispose();
         this.designerActionUI = null;
     }
 }
        public SelectionManager(IServiceProvider serviceProvider, BehaviorService behaviorService)
        {
            this.behaviorService = behaviorService;
            this.serviceProvider = serviceProvider;
            this.selSvc          = (ISelectionService)serviceProvider.GetService(typeof(ISelectionService));
            this.designerHost    = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost));
            if (this.designerHost != null)
            {
                ISelectionService selSvc = this.selSvc;
            }
            behaviorService.BeginDrag    += new BehaviorDragDropEventHandler(this.OnBeginDrag);
            behaviorService.Synchronize  += new EventHandler(this.OnSynchronize);
            this.selSvc.SelectionChanged += new EventHandler(this.OnSelectionChanged);
            this.rootComponent            = (Control)this.designerHost.RootComponent;
            this.selectionAdorner         = new Adorner();
            this.bodyAdorner              = new Adorner();
            behaviorService.Adorners.Add(this.bodyAdorner);
            behaviorService.Adorners.Add(this.selectionAdorner);
            this.componentToDesigner = new Hashtable();
            IComponentChangeService service = (IComponentChangeService)serviceProvider.GetService(typeof(IComponentChangeService));

            if (service != null)
            {
                service.ComponentAdded   += new ComponentEventHandler(this.OnComponentAdded);
                service.ComponentRemoved += new ComponentEventHandler(this.OnComponentRemoved);
                service.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
            }
            this.designerHost.TransactionClosed += new DesignerTransactionCloseEventHandler(this.OnTransactionClosed);
            DesignerOptionService service2 = this.designerHost.GetService(typeof(DesignerOptionService)) as DesignerOptionService;

            if (service2 != null)
            {
                PropertyDescriptor descriptor = service2.Options.Properties["UseSmartTags"];
                if (((descriptor != null) && (descriptor.PropertyType == typeof(bool))) && ((bool)descriptor.GetValue(null)))
                {
                    this.designerActionUI            = new DesignerActionUI(serviceProvider, this.selectionAdorner);
                    behaviorService.DesignerActionUI = this.designerActionUI;
                }
            }
        }