Beispiel #1
0
        public void RegisterResourceDragDropHandler(string resType, IResourceDragDropHandler handler)
        {
            #region Preconditions
            if (!Core.ResourceStore.ResourceTypes.Exist(resType))
            {
                throw new ArgumentException("Invalid resource type \"" + resType + "\".", "resType");
            }
            #endregion Preconditions

            lock ( _resourceDragDropHandlerHash )
            {
                // Check if a handler is already registered
                IResourceDragDropHandler existing = _resourceDragDropHandlerHash[resType] as IResourceDragDropHandler;
                if (existing != null)
                {
                    // The handler's registered; if it's already a composite one, add a new handler to it
                    // If it's a simple handler, create a new composite of the old and new ones
                    ResourceDragDropCompositeHandler composite = existing as ResourceDragDropCompositeHandler;
                    if (composite != null)
                    {
                        composite.AddHandler(handler);
                    }
                    else
                    {
                        _resourceDragDropHandlerHash[resType] = new ResourceDragDropCompositeHandler(existing, handler);
                    }
                }
                else         // There were no handler yet, just write the raw unwrapped handler
                {
                    _resourceDragDropHandlerHash[resType] = handler;
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Creates a composite handler with no contained handlers, just with the default link handler.
 /// </summary>
 public ResourceDragDropCompositeHandler()
 {
     if (_linkhandler == null)
     {
         _linkhandler = new ResourceDragDropLinkHandler();
     }
 }
Beispiel #3
0
        private void HandleItemDrag(object sender, ItemDragEventArgs e)
        {
            if (!_allowDrag)
            {
                return;
            }

            DataObject    dataObj           = new DataObject();
            IResourceList selectedResources = GetSelectedResources();

            dataObj.SetData(typeof(IResourceList), selectedResources);
            dataObj.SetData(typeof(ResourceListView2), this);

            string[] dragResTypes = selectedResources.GetAllTypes();
            if (dragResTypes.Length == 1)
            {
                IResourceDragDropHandler handler = Core.PluginLoader.GetResourceDragDropHandler(selectedResources[0]);
                if (handler != null)
                {
                    handler.AddResourceDragData(selectedResources, dataObj);
                }
            }

            DoDragDrop(dataObj, DragDropEffects.All | DragDropEffects.Move | DragDropEffects.Link);
        }
Beispiel #4
0
 /// <summary>
 /// Wraps the <paramref name="baseHandler"/> handler.
 /// </summary>
 public DragDropLinkAdapter(IResourceDragDropHandler baseHandler)
 {
     _baseHandler = baseHandler;
     if (_linkhandler == null)              // Lazy-instantiate
     {
         _linkhandler = new ResourceDragDropLinkHandler();
     }
 }
Beispiel #5
0
        /// <summary>
        /// Creates a composite handler wrapping one raw handler, plus the default link handler.
        /// <see cref="AddHandler"/> for more details.
        /// </summary>
        public ResourceDragDropCompositeHandler(IResourceDragDropHandler handlerBase)
        {
            if (_linkhandler == null)
            {
                _linkhandler = new ResourceDragDropLinkHandler();
            }

            AddHandler(handlerBase);
        }
Beispiel #6
0
        /// <summary>
        /// Adds a new handler to the wrapped handlers list, as the last one in the list.
        /// The handlers will be executed in the same order as they were added.
        /// If the <paramref name="handler"/> is a composite handler of the same type as <c>this</c>,
        /// its members are added one by one instead of adding the composite handler itself.
        /// </summary>
        public void AddHandler(IResourceDragDropHandler handler)
        {
            // For a composite, add all of its members
            ResourceDragDropCompositeHandler composite = handler as ResourceDragDropCompositeHandler;

            if (composite != null)
            {
                foreach (IResourceDragDropHandler handlerInner in composite.Handlers)
                {
                    AddHandler(handlerInner);
                }
            }
            else
            {
                _handlers.Add(handler);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Creates a composite handler wrapping an arbitiary number of handlers, plus the default link handler.
        /// <see cref="AddHandler"/> for more details.
        /// </summary>
        public ResourceDragDropCompositeHandler(params object[] args)
        {
            if (_linkhandler == null)
            {
                _linkhandler = new ResourceDragDropLinkHandler();
            }

            foreach (object oHandler in args)
            {
                IResourceDragDropHandler handler = oHandler as IResourceDragDropHandler;
                if (handler == null)
                {
                    throw new ArgumentException("All the arguments must implement the IResourceDragDropHandler interface.");
                }
                AddHandler(handler);
            }
        }
Beispiel #8
0
 public void EnableDropOnEmpty(IResourceDragDropHandler emptyDropHandler)
 {
     _resourceTree.EmptyDropHandler = emptyDropHandler;
 }
Beispiel #9
0
        /// <summary>
        /// Looks for a handler within the composed ones and the link-handler, if enabled, and picks the first one that
        /// confirms it can handle the situation in response to the dragover event.
        /// That handler is then returned.
        /// Note that the drag-over operation is thus already executed for that handler.
        /// </summary>
        protected DragDropEffects GetDragOverHandler(IResource targetResource, IDataObject data, DragDropEffects allowedEffect, int keyState, out IResourceDragDropHandler handlerFit)
        {
            DragDropEffects effect;

            // Try the composed handlers
            foreach (IResourceDragDropHandler handler in _handlers)
            {
                handlerFit = handler;
                if ((effect = handlerFit.DragOver(targetResource, data, allowedEffect, keyState)) != DragDropEffects.None)
                {
                    return(effect);
                }
            }

            // Try the link-handler
            if (_bAddLink)
            {
                handlerFit = _linkhandler;
                if ((effect = handlerFit.DragOver(targetResource, data, allowedEffect, keyState)) != DragDropEffects.None)
                {
                    return(effect);
                }
            }

            // None has fit
            handlerFit = null;
            return(DragDropEffects.None);
        }
Beispiel #10
0
 public static void Register()
 {
     parentHandler = Core.PluginLoader.GetResourceDragDropHandler("AddressBook");
     Guard.NullMember(parentHandler, "parentHandler");
     Core.PluginLoader.RegisterResourceDragDropHandler("AddressBook", new ContactDragDropHandler());
 }