예제 #1
0
        public void AddCreator(ToolboxItemCreatorCallback creator, string format, IDesignerHost host)
        {
            if (creator == null || format == null)
            {
                throw new ArgumentNullException(creator == null ? "creator" : "format");
            }

            if (customCreators == null)
            {
                customCreators = new Hashtable();
            }
            else
            {
                string key = format;

                if (host != null)
                {
                    key += ", " + host.GetHashCode().ToString();
                }

                if (customCreators.ContainsKey(key))
                {
                    throw new Exception("There is already a creator registered for the format '" + format + "'.");
                }
            }

            customCreators[format] = creator;
        }
예제 #2
0
        private ToolboxItemCreatorCallback FindToolboxItemCreator(IDataObject dataObj, IDesignerHost host, out string foundFormat)
        {
            foundFormat = string.Empty;

            ToolboxItemCreatorCallback creator = null;

            if (customCreators != null)
            {
                IEnumerator keys = customCreators.Keys.GetEnumerator();
                while (keys.MoveNext())
                {
                    string   key      = (string)keys.Current;
                    string[] keyParts = key.Split(new char[] { ',' });
                    string   format   = keyParts[0];

                    if (dataObj.GetDataPresent(format))
                    {
                        // Check to see if the host matches.
                        if (keyParts.Length == 1 || (host != null && host.GetHashCode().ToString().Equals(keyParts[1])))
                        {
                            creator     = (ToolboxItemCreatorCallback)customCreators[format];
                            foundFormat = format;
                            break;
                        }
                    }
                }
            }

            return(creator);
        }
예제 #3
0
        public void RemoveCreator(string format, IDesignerHost host)
        {
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }

            if (customCreators != null)
            {
                string key = format;
                if (host != null)
                {
                    key += ", " + host.GetHashCode().ToString();
                }
                customCreators.Remove(key);
            }
        }
예제 #4
0
        private ToolboxItemCreatorCallback FindToolboxItemCreator(IDataObject dataObj, IDesignerHost host, out string foundFormat)
        {
            foundFormat = string.Empty;

            ToolboxItemCreatorCallback creator = null;
            if (customCreators != null)
            {
                IEnumerator keys = customCreators.Keys.GetEnumerator();
                while (keys.MoveNext())
                {
                    string key = (string)keys.Current;
                    string[] keyParts = key.Split(new char[] { ',' });
                    string format = keyParts[0];

                    if (dataObj.GetDataPresent(format))
                    {
                        if (keyParts.Length == 1 || (host != null && host.GetHashCode().ToString().Equals(keyParts[1])))
                        {
                            creator = (ToolboxItemCreatorCallback)customCreators[format];
                            foundFormat = format;
                            break;
                        }
                    }
                }
            }

            return creator;
        }
예제 #5
0
        public void RemoveCreator(string format, IDesignerHost host)
        {
            if (format == null)
                throw new ArgumentNullException("format");

            if (customCreators != null)
            {
                string key = format;
                if (host != null)
                    key += ", " + host.GetHashCode().ToString();
                customCreators.Remove(key);
            }
        }
예제 #6
0
        public void AddCreator(ToolboxItemCreatorCallback creator, string format, IDesignerHost host)
        {
            if (creator == null || format == null)
            {
                throw new ArgumentNullException(creator == null ? "creator" : "format");
            }

            if (customCreators == null)
            {
                customCreators = new Hashtable();
            }
            else
            {
                string key = format;

                if (host != null) key += ", " + host.GetHashCode().ToString();

                if (customCreators.ContainsKey(key))
                {
                    throw new Exception("There is already a creator registered for the format '" + format + "'.");
                }
            }

            customCreators[format] = creator;
        }