void DetectBindings() { if (IsListeningForBinding) { BindingSource binding = null; var listenOptions = ListenOptions ?? Owner.ListenOptions; var bindingSourceListenerCount = bindingSourceListeners.Length; for (var i = 0; i < bindingSourceListenerCount; i++) { binding = bindingSourceListeners[i].Listen(listenOptions, device); if (binding != null) { break; } } if (binding == null) { // No binding found. return; } var onBindingFound = listenOptions.OnBindingFound; if (onBindingFound != null && !onBindingFound(this, binding)) { // Binding rejected by user. return; } if (HasBinding(binding)) { var onBindingRejected = listenOptions.OnBindingRejected; if (onBindingRejected != null) { onBindingRejected(this, binding, BindingSourceRejectionType.DuplicateBindingOnAction); } return; } if (listenOptions.UnsetDuplicateBindingsOnSet) { Owner.RemoveBinding(binding); } if (!listenOptions.AllowDuplicateBindingsPerSet && Owner.HasBinding(binding)) { var onBindingRejected = listenOptions.OnBindingRejected; if (onBindingRejected != null) { onBindingRejected(this, binding, BindingSourceRejectionType.DuplicateBindingOnActionSet); } return; } StopListeningForBinding(); if (listenOptions.ReplaceBinding == null) { if (listenOptions.MaxAllowedBindingsPerType > 0) { while (CountBindingsOfType(binding.BindingSourceType) >= listenOptions.MaxAllowedBindingsPerType) { RemoveFirstBindingOfType(binding.BindingSourceType); } } else { if (listenOptions.MaxAllowedBindings > 0) { while (regularBindings.Count >= listenOptions.MaxAllowedBindings) { var removeIndex = Mathf.Max(0, IndexOfFirstInvalidBinding()); regularBindings.RemoveAt(removeIndex); } } } AddBinding(binding); } else { ReplaceBinding(listenOptions.ReplaceBinding, binding); } UpdateVisibleBindings(); var onBindingAdded = listenOptions.OnBindingAdded; if (onBindingAdded != null) { onBindingAdded(this, binding); } } }
void DetectBindings() { if (IsListeningForBinding) { BindingSource binding = null; var listenOptions = ListenOptions ?? Owner.ListenOptions; var bindingSourceListenerCount = bindingSourceListeners.Length; for (int i = 0; i < bindingSourceListenerCount; i++) { binding = bindingSourceListeners[i].Listen(listenOptions, device); if (binding != null) { break; } } if (binding == null) { return; } if (listenOptions.AllowDuplicateBindingsPerSet) { if (HasBinding(binding)) { return; } } else { if (Owner.HasBinding(binding)) { return; } } var onBindingFound = listenOptions.OnBindingFound; if (onBindingFound != null && !onBindingFound(this, binding)) { return; } StopListeningForBinding(); if (listenOptions.MaxAllowedBindingsPerType > 0) { while (regularBindings.Count(b => b.BindingSourceType == binding.BindingSourceType) >= listenOptions.MaxAllowedBindingsPerType) { regularBindings.RemoveAt(regularBindings.FindIndex(b => b.BindingSourceType == binding.BindingSourceType)); } } else { if (listenOptions.MaxAllowedBindings > 0) { while (regularBindings.Count >= listenOptions.MaxAllowedBindings) { regularBindings.RemoveAt(0); } } } AddBinding(binding); UpdateVisibleBindings(); var onBindingAdded = listenOptions.OnBindingAdded; if (onBindingAdded != null) { onBindingAdded(this, binding); } } }
void DetectBindings() { if (IsListeningForBinding) { BindingSource binding = null; var listenOptions = ListenOptions ?? Owner.ListenOptions; var bindingSourceListenerCount = bindingSourceListeners.Length; for (var i = 0; i < bindingSourceListenerCount; i++) { binding = bindingSourceListeners[i].Listen(listenOptions, device); if (binding != null) { break; } } if (binding == null) { // No binding found. return; } if (!listenOptions.CallOnBindingFound(this, binding)) { // Binding rejected by user. return; } if (HasBinding(binding)) { if (listenOptions.RejectRedundantBindings) { listenOptions.CallOnBindingRejected(this, binding, BindingSourceRejectionType.DuplicateBindingOnActionSet); return; } // By default, we just accept a reduntant binding, do nothing, and move on. StopListeningForBinding(); listenOptions.CallOnBindingAdded(this, binding); return; } if (listenOptions.UnsetDuplicateBindingsOnSet) { var actionsCount = Owner.Actions.Count; for (var i = 0; i < actionsCount; i++) { Owner.Actions[i].HardRemoveBinding(binding); } } if (!listenOptions.AllowDuplicateBindingsPerSet && Owner.HasBinding(binding)) { listenOptions.CallOnBindingRejected(this, binding, BindingSourceRejectionType.DuplicateBindingOnActionSet); return; } StopListeningForBinding(); if (listenOptions.ReplaceBinding == null) { if (listenOptions.MaxAllowedBindingsPerType > 0) { while (CountBindingsOfType(binding.BindingSourceType) >= listenOptions.MaxAllowedBindingsPerType) { RemoveFirstBindingOfType(binding.BindingSourceType); } } else { if (listenOptions.MaxAllowedBindings > 0) { while (regularBindings.Count >= listenOptions.MaxAllowedBindings) { var removeIndex = Mathf.Max(0, IndexOfFirstInvalidBinding()); regularBindings.RemoveAt(removeIndex); triggerBindingChanged = true; } } } AddBinding(binding); } else { ReplaceBinding(listenOptions.ReplaceBinding, binding); } UpdateVisibleBindings(); listenOptions.CallOnBindingAdded(this, binding); } }