Beispiel #1
0
        /// <summary>
        /// Tries to set new content to this socket.
        /// If <paramref name="content"/>'s key matches one of keys in this socket,
        /// returns true and set content. If not, returns false.
        /// If <paramref name="force"/> is true, set this content no matter what key it has.
        /// </summary>
        /// <returns><c>true</c>, if content was set, <c>false</c> otherwise.</returns>
        /// <param name="content">Content.</param>
        /// <param name="force">If set to <c>true</c> force.</param>
        public bool SetContent(IDragable content, bool force = false)
        {
            bool passed = MatchKey(content);

            if (passed || force)
            {
                DragSocket otherSocket = content.GetSocket();
                if (otherSocket != null)
                {
                    otherSocket.ResetContent();
                    // If this socket already have content, exchange content with given content's socket.
                    if (this.content != null)
                    {
                        if (!otherSocket.SetContent((IDragable)this.content))
                        {
                            otherSocket.SetContent(content, true);
                            return(false); // If setting socket is failed, return false.
                        }
                        components.Clear();
                    }
                }
                if (components.Count > 0)
                {
                    return(false);
                }
                components.Add((GUIComponent)content);
                content.ChangeSocket(this);
                return(true);
            }

            return(false);
        }