Example #1
0
        /// <summary>
        ///     Registers a key binding for the type specified.
        /// </summary>
        /// <param name="type">
        ///     The entity type.
        /// </param>
        /// <param name="keyBinding">
        ///     The key binding.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the key binding has been added, <c>false</c> if an existing key binding has been replaced.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="type" /> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="keyBinding" /> is null.
        /// </exception>
        public bool RegisterKeyBinding(Type type, IKeyBinding keyBinding)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (keyBinding == null)
            {
                throw new ArgumentNullException(nameof(keyBinding));
            }

            lock (this.syncRoot)
            {
                this.Refresh();

                IKeyBinding existingKeyBinding;
                if (this.keyBindings.TryGetValue(type, out existingKeyBinding))
                {
                    this.RemovingKeyBinding(type, existingKeyBinding);
                }

                return(this.keyBindings.AddOrUpdate(type, keyBinding));
            }
        }
Example #2
0
 /// <summary>
 ///     Removes all entity references affected by the key binding specified.
 /// </summary>
 /// <param name="type">
 ///     The entity type.
 /// </param>
 /// <param name="keyBinding">
 ///     The key binding.
 /// </param>
 protected override void RemovingKeyBinding(Type type, IKeyBinding keyBinding)
 {
     this.entityReferences.Remove(
         from kv in this.entityReferences
         where type.IsAssignableFrom(kv.Key) ||
         (kv.Value != null && object.ReferenceEquals(kv.Value.KeyBinding, keyBinding))
         select kv.Key);
 }
Example #3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="EntityReference" /> class.
        /// </summary>
        /// <param name="entityReference">
        ///     The entity reference.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="entityReference" /> is null.
        /// </exception>
        internal EntityReference(EntityReference entityReference)
        {
            if (entityReference == null)
            {
                throw new ArgumentNullException(nameof(entityReference));
            }

            this.entityType    = entityReference.entityType;
            this.tableBinding  = entityReference.tableBinding;
            this.columnBinding = entityReference.columnBinding;
            this.keyBinding    = entityReference.keyBinding;
        }
Example #4
0
        /// <summary>
        ///     Gets the key binding associated with the specified type.
        /// </summary>
        /// <param name="type">
        ///     The type.
        /// </param>
        /// <param name="keyBinding">
        ///     When this method returns, contains the key binding associated with the specified type, if the type is found;
        ///     otherwise null.
        /// </param>
        /// <returns>
        ///     <c>true</c> if a key binding exists for the type specified; otherwise, <c>false</c>.
        /// </returns>
        public bool TryGetKeyBinding(Type type, out IKeyBinding keyBinding)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            lock (this.syncRoot)
            {
                var columnBinding = this.GetColumnBindingForType(type);
                keyBinding = this.GetKeyBindingForType(type, columnBinding);
            }

            return(keyBinding != null);
        }
Example #5
0
        private List <Drawable> getInputQueue(IKeyBinding binding, bool rebuildIfEmpty = false)
        {
            if (!keyBindingQueues.ContainsKey(binding))
            {
                keyBindingQueues.Add(binding, new List <Drawable>());
            }

            var currentQueue = keyBindingQueues[binding];

            if (rebuildIfEmpty && !currentQueue.Any())
            {
                currentQueue.AddRange(KeyBindingInputQueue);
            }

            return(currentQueue);
        }
Example #6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="EntityReference" /> class.
        /// </summary>
        /// <param name="entityType">
        ///     The entity type.
        /// </param>
        /// <param name="tableBinding">
        ///     The table binding.
        /// </param>
        /// <param name="columnBinding">
        ///     The column binding.
        /// </param>
        /// <param name="keyBinding">
        ///     The key binding.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="entityType" /> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="tableBinding" /> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="keyBinding" /> is null.
        /// </exception>
        internal EntityReference(Type entityType, ITableBinding tableBinding, IColumnBinding columnBinding,
                                 IKeyBinding keyBinding)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException(nameof(entityType));
            }

            if (tableBinding == null)
            {
                throw new ArgumentNullException(nameof(tableBinding));
            }

            if (keyBinding == null)
            {
                throw new ArgumentNullException(nameof(keyBinding));
            }

            this.entityType    = entityType;
            this.tableBinding  = tableBinding;
            this.columnBinding = columnBinding;
            this.keyBinding    = keyBinding;
        }
Example #7
0
 /// <summary>
 /// Removes all entity references affected by the key binding specified.
 /// </summary>
 /// <param name="type">
 /// The entity type.
 /// </param>
 /// <param name="keyBinding">
 /// The key binding.
 /// </param>
 protected override void RemovingKeyBinding(Type type, IKeyBinding keyBinding)
 {
     this.entityReferences.Remove(
         from kv in this.entityReferences where type.IsAssignableFrom(kv.Key) || (kv.Value != null && object.ReferenceEquals(kv.Value.KeyBinding, keyBinding)) select kv.Key);
 }
 /// <summary>
 /// Get the action associated with this binding, cast to the required enum type.
 /// </summary>
 /// <typeparam name="T">The enum type.</typeparam>
 /// <returns>A cast <typeparamref name="T"/> representation of <see cref="KeyBinding.Action"/>.</returns>
 public static T GetAction <T>(this IKeyBinding obj)
     where T : struct
 {
     return((T)obj.Action);
 }
Example #9
0
 /// <inheritdoc />
 public bool TryGetKeyBinding(BoundKeyFunction function, out IKeyBinding binding)
 {
     binding = _bindings.FirstOrDefault(k => k.Function == function);
     return(binding != null);
 }
Example #10
0
 /// <summary>
 ///     The removing key binding callback.
 /// </summary>
 /// <param name="type">
 ///     The entity type.
 /// </param>
 /// <param name="keyBinding">
 ///     The key binding.
 /// </param>
 protected virtual void RemovingKeyBinding(Type type, IKeyBinding keyBinding)
 {
 }
Example #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityReference"/> class.
        /// </summary>
        /// <param name="entityType">
        /// The entity type.
        /// </param>
        /// <param name="tableBinding">
        /// The table binding.
        /// </param>
        /// <param name="columnBinding">
        /// The column binding.
        /// </param>
        /// <param name="keyBinding">
        /// The key binding.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="entityType"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="tableBinding"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="keyBinding"/> is null.
        /// </exception>
        internal EntityReference(Type entityType, ITableBinding tableBinding, IColumnBinding columnBinding, IKeyBinding keyBinding)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }

            if (tableBinding == null)
            {
                throw new ArgumentNullException("tableBinding");
            }

            if (keyBinding == null)
            {
                throw new ArgumentNullException("keyBinding");
            }

            this.entityType = entityType;
            this.tableBinding = tableBinding;
            this.columnBinding = columnBinding;
            this.keyBinding = keyBinding;
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityReference"/> class.
        /// </summary>
        /// <param name="entityReference">
        /// The entity reference.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="entityReference"/> is null.
        /// </exception>
        internal EntityReference(EntityReference entityReference)
        {
            if (entityReference == null)
            {
                throw new ArgumentNullException("entityReference");
            }

            this.entityType = entityReference.entityType;
            this.tableBinding = entityReference.tableBinding;
            this.columnBinding = entityReference.columnBinding;
            this.keyBinding = entityReference.keyBinding;
        }