Exemple #1
0
    private void ShowBindingOptions()
    {
        SerializedProperty sourceRef      = serializedObject.FindProperty("SourceRef");
        SerializedProperty componentIndex = serializedObject.FindProperty("SelectedComponentIndex");

        MonoBehaviour sourceReference = sourceRef.objectReferenceValue as MonoBehaviour;

        if (sourceReference != null)
        {
            bool componentsChanged = availableComponentNames == null;
            if (GUILayout.Button("Refresh Source Options") || componentsChanged)
            {
                RegenerateComponentNames(sourceReference);
            }

            EditorGUI.BeginChangeCheck();
            componentIndex.intValue = EditorGUILayout.Popup("Source", componentIndex.intValue, availableComponentNames);
            componentsChanged       = componentsChanged || EditorGUI.EndChangeCheck();

            //if the index changed from the popup or the source was changed earlier
            if (componentsChanged && componentIndex.intValue < availableComponentNames.Length)
            {
                IBindingSource source = sourceReference.GetComponents <IBindingSource>()[componentIndex.intValue];
            }
        }
    }
Exemple #2
0
 public virtual void OnAfterDeserialize()
 {
     if (SourceRaw != null)
     {
         Source = SourceRaw.ObjectReference as IBindingSource;
     }
 }
        /// <summary>
        ///     Updates the relative source value.
        /// </summary>
        public void UpdateSource([NotNull] object target)
        {
            if (target == null)
            {
                throw BindingExceptionManager.InvalidBindingTarget(RelativeSourceNode.Path);
            }
            var path = RelativeSourceNode.Path ?? String.Empty;

            if (!String.IsNullOrEmpty(Path))
            {
                path = BindingExtensions.MergePath(path, Path);
            }


            if (RelativeSourceNode.Type != RelativeSourceExpressionNode.SelfType)
            {
                if (RelativeSourceNode.Type == RelativeSourceExpressionNode.MemberSourceType)
                {
                    target = BindingServiceProvider.ContextManager.GetBindingContext(target);
                }
                else
                {
                    target = new ParentSourceValue(target, RelativeSourceNode);
                }
            }
            IObserver observer = BindingServiceProvider.ObserverProvider.Observe(target, BindingPath.Create(path), false);

            _bindingSource = new BindingSource(observer);
        }
Exemple #4
0
        protected virtual IDataBinding CreateBinding([NotNull] IDataContext context, out object target, out IBindingPath targetPath)
        {
            IBindingSourceAccessor sourceAccessor;
            var formatExpression = context.GetData(BindingBuilderConstants.MultiExpression);
            var sourceDelegates  = context.GetData(BindingBuilderConstants.Sources, true);

            if (sourceDelegates.Count > 1 || formatExpression != null)
            {
                formatExpression = formatExpression ?? FormatMembersExpressionDelegate;
                var sources = new IBindingSource[sourceDelegates.Count];
                for (int index = 0; index < sourceDelegates.Count; index++)
                {
                    sources[index] = Decorate(sourceDelegates[index].Invoke(context), false, context);
                }
                sourceAccessor = new MultiBindingSourceAccessor(sources, formatExpression, context);
            }
            else
            {
                sourceAccessor = new BindingSourceAccessor(Decorate(sourceDelegates[0].Invoke(context), false, context), context, false);
            }
            var binding = new DataBinding(new BindingSourceAccessor(GetBindingTarget(context, out target, out targetPath), context, true), sourceAccessor);

            AddBehaviors(binding, context);
            return(binding);
        }
Exemple #5
0
 private IBindingSource Decorate(IBindingSource source, bool isTarget, IDataContext context)
 {
     for (int index = 0; index < _decorators.Count; index++)
     {
         _decorators[index].Decorate(ref source, isTarget, context);
     }
     return(source);
 }
 private void OneTimeSourceHandler(IBindingSource sender, ValueChangedEventArgs args)
 {
     IDataBinding binding = Binding;
     if (binding != null && binding.SourceAccessor.IsAllMembersAvailable() && binding.TargetAccessor.IsAllMembersAvailable())
     {
         UnsubscribeSources(OneTimeSourceHandler);
         binding.UpdateSource();
     }
 }
 private void OneTimeTargetHandler(IBindingSource sender, ValueChangedEventArgs args)
 {
     IDataBinding binding = Binding;
     if (binding != null && binding.SourceAccessor.IsAllMembersAvailable() && binding.TargetAccessor.IsAllMembersAvailable())
     {
         binding.TargetAccessor.Source.ValueChanged -= OneTimeTargetHandler;
         binding.UpdateTarget();
     }
 }
Exemple #8
0
 private void OnBindingSourceValueChanged(IBindingSource sender, ValueChangedEventArgs args)
 {
     if (args.LastMemberChanged)
     {
         return;
     }
     UpdateSources(false);
     UpdateErrors();
 }
    private void ShowBindingModeDropdown()
    {
        IBindingSource source = SourceRawObjectP.objectReferenceValue as IBindingSource;

        using (new EditorGUI.DisabledGroupScope(source == null || source.LockBindingMode))
        {
            EditorGUILayout.PropertyField(BindingModeP);
        }
    }
Exemple #10
0
        private static void SetDefaultValue(IBindingSource source)
        {
            var pathMembers = source.GetPathMembers(false);

            if (pathMembers.AllMembersAvailable)
            {
                pathMembers.LastMember.SetValue(pathMembers.PenultimateValue,
                                                new[] { pathMembers.LastMember.Type.GetDefaultValue() });
            }
        }
Exemple #11
0
 public FunctionInstance(Guid id, Guid?parentId, ExecutionReason reason, IBindingSource bindingSource,
                         IFunctionInvoker invoker, FunctionDescriptor functionDescriptor)
 {
     _id                 = id;
     _parentId           = parentId;
     _reason             = reason;
     _bindingSource      = bindingSource;
     _invoker            = invoker;
     _functionDescriptor = functionDescriptor;
 }
 public FunctionInstance(Guid id, Guid? parentId, ExecutionReason reason, IBindingSource bindingSource,
     IFunctionInvoker invoker, FunctionDescriptor functionDescriptor)
 {
     _id = id;
     _parentId = parentId;
     _reason = reason;
     _bindingSource = bindingSource;
     _invoker = invoker;
     _functionDescriptor = functionDescriptor;
 }
Exemple #13
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="BindingSourceAccessor" /> class.
 /// </summary>
 public BindingSourceAccessor([NotNull] IBindingSource bindingSource, [NotNull] IDataContext context, bool isTarget)
     : base(context, isTarget)
 {
     Should.NotBeNull(bindingSource, "bindingSource");
     _bindingSource = bindingSource;
     if (!context.TryGetData(BindingBuilderConstants.ToggleEnabledState, out _toggleEnabledState))
     {
         _toggleEnabledState = ToggleEnabledStateDefault;
     }
 }
Exemple #14
0
        private void OneTimeSourceHandler(IBindingSource sender, ValueChangedEventArgs args)
        {
            var members = sender.GetPathMembers(false);

            if (!members.AllMembersAvailable)
            {
                return;
            }
            UnsubscribeSources(OneTimeSourceHandler);
            Binding.UpdateSource();
        }
 public FunctionInstance(Guid id, IDictionary <string, string> triggerDetails, Guid?parentId, ExecutionReason reason, IBindingSource bindingSource,
                         IFunctionInvoker invoker, FunctionDescriptor functionDescriptor)
 {
     _id                 = id;
     _triggerDetails     = triggerDetails;
     _parentId           = parentId;
     _reason             = reason;
     _bindingSource      = bindingSource;
     _invoker            = invoker;
     _functionDescriptor = functionDescriptor;
 }
 private void CheckBindingModeConstraints()
 {
     serializedObject.Update();
     if (SourceRawObjectP.objectReferenceValue != null)
     {
         IBindingSource source = (SourceRawObjectP.objectReferenceValue as IBindingSource);
         if (source.LockBindingMode)
         {
             BindingModeP.enumValueIndex = (int)source.PrefferedMode;
         }
     }
 }
        private void OneTimeHandler(IBindingSource sender, ValueChangedEventArgs args)
        {
            IDataBinding binding = Binding;

            if (binding == null || !IsSourceAvailable() || !binding.UpdateTarget())
            {
                return;
            }
            UnsubscribeSources(OneTimeHandler);
            if (_disposeBinding)
            {
                binding.Dispose();
            }
        }
Exemple #18
0
        private void TrySubscribe(IBindingSource source)
        {
            var dataErrorInfo = source.GetPathMembers(false).PenultimateValue as INotifyDataErrorInfo;

            if (dataErrorInfo == null)
            {
                return;
            }
            var subscriber = BindingServiceProvider.WeakEventManager.TrySubscribe(dataErrorInfo, ErrorsChangedEvent, this);

            if (subscriber != null)
            {
                _subscribers.Add(subscriber);
            }
        }
 /// <summary>
 ///     Updates the source binding when target value changed.
 /// </summary>
 private void TargetOnValueChanged(IBindingSource sender, ValueChangedEventArgs valueChangedEventArg)
 {
     if (_isTargetUpdating)
     {
         return;
     }
     try
     {
         _isTargetUpdating = true;
         Binding.UpdateSource();
     }
     finally
     {
         _isTargetUpdating = false;
     }
 }
        public void SetUp()
        {
            firstBindingSource = A.Fake<IBindingSource>();
            secondBindingSource = A.Fake<IBindingSource>();

            A.CallTo(() => firstBindingSource.GetValues()).Returns(firstBindingSourceValues);
            A.CallTo(() => secondBindingSource.GetValues()).Returns(secondBindingSourceValues);

            A.CallTo(() => firstBindingSource.GetKeys()).Returns(new List<string> { "firsttest" });
            A.CallTo(() => secondBindingSource.GetKeys()).Returns(new List<string> { "secondtest" });

            bindingSourceCollection = new BindingSourceCollection(new List<IBindingSource>
                                                                      {
                                                                          firstBindingSource,
                                                                          secondBindingSource
                                                                      });
        }
Exemple #21
0
        private void CollectErrors(ref List <object> errors, IBindingSource bindingSource)
        {
            var notifyDataErrorInfo = bindingSource.GetPathMembers(false).PenultimateValue as INotifyDataErrorInfo;

            if (notifyDataErrorInfo == null)
            {
                return;
            }
            var path  = bindingSource.Path.Parts.LastOrDefault();
            var paths = ErrorPaths;

            if (!string.IsNullOrEmpty(path) || paths == null || paths.Length == 0)
            {
                CollectErrors(notifyDataErrorInfo, path, ref errors);
            }
            if (paths != null)
            {
                for (int i = 0; i < paths.Length; i++)
                {
                    CollectErrors(notifyDataErrorInfo, paths[i], ref errors);
                }
            }
        }
 private void SetDefaultValue(IBindingSource source)
 {
     var pathMembers = source.GetPathMembers(false);
     if (pathMembers.AllMembersAvailable)
     {
         object value = _value;
         if (!pathMembers.LastMember.Type.IsInstanceOfType(value))
             value = pathMembers.LastMember.Type.GetDefaultValue();
         pathMembers.LastMember.SetValue(pathMembers.PenultimateValue, new[] { value });
     }
 }
 /// <summary>
 ///     Updates the source binding when target value changed.
 /// </summary>
 private void TargetOnValueChanged(IBindingSource sender, ValueChangedEventArgs args)
 {
     Binding.UpdateSource();
 }
 private void TrySubscribe(IBindingSource source)
 {
     var dataErrorInfo = source.GetPathMembers(false).PenultimateValue as INotifyDataErrorInfo;
     if (dataErrorInfo == null)
         return;
     var subscriber = BindingServiceProvider.WeakEventManager.TrySubscribe(dataErrorInfo, ErrorsChangedEvent, this);
     if (subscriber != null)
         _subscribers.Add(subscriber);
 }
 /// <summary>
 ///     Decorates the source using <see cref="SourceDecorators" /> property.
 /// </summary>
 protected IBindingSource Decorate(IBindingSource source, bool isTarget, IDataContext context)
 {
     for (int index = 0; index < _decorators.Count; index++)
         _decorators[index].Decorate(ref source, isTarget, context);
     return source;
 }
 /// <summary>
 ///     Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public override void Dispose()
 {
     if (_closure != null)
         _closure.Unsubscribe(true);
     _bindingSource.Dispose();
     _bindingSource = null;
     ValueChanging = null;
     ValueChanged = null;
     _closure = null;
     base.Dispose();
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="BindingSourceAccessor" /> class.
 /// </summary>
 public BindingSourceAccessor([NotNull]IBindingSource bindingSource, [NotNull] IDataContext context, bool isTarget)
     : base(context, isTarget)
 {
     Should.NotBeNull(bindingSource, "bindingSource");
     _bindingSource = bindingSource;
     if (!context.TryGetData(BindingBuilderConstants.ToggleEnabledState, out _toggleEnabledState))
         _toggleEnabledState = ToggleEnabledStateDefault;
 }
 protected virtual IDataBinding CreateBinding([NotNull] IDataContext context, out object target, out IBindingPath targetPath)
 {
     IBindingSourceAccessor sourceAccessor;
     var formatExpression = context.GetData(BindingBuilderConstants.MultiExpression);
     var sourceDelegates = context.GetData(BindingBuilderConstants.Sources, true);
     if (sourceDelegates.Count > 1 || formatExpression != null)
     {
         formatExpression = formatExpression ?? FormatMembersExpressionDelegate;
         var sources = new IBindingSource[sourceDelegates.Count];
         for (int index = 0; index < sourceDelegates.Count; index++)
             sources[index] = Decorate(sourceDelegates[index].Invoke(context), false, context);
         sourceAccessor = new MultiBindingSourceAccessor(sources, formatExpression, context);
     }
     else
         sourceAccessor = new BindingSourceAccessor(Decorate(sourceDelegates[0].Invoke(context), false, context), context, false);
     var binding = new DataBinding(new BindingSourceAccessor(GetBindingTarget(context, out target, out targetPath), context, true), sourceAccessor);
     object source;
     if (context.TryGetData(BindingBuilderConstants.Source, out source))
         binding.Context.AddOrUpdate(BindingConstants.Source, ToolkitExtensions.GetWeakReference(source));
     AddBehaviors(binding, context);
     return binding;
 }
 internal static void BindingSourceShouldBeValid(IBindingSource bindingSource, string path, object source)
 {
     var src = bindingSource.GetSource(true);
     var resourceObject = src as ISourceValue;
     if (resourceObject == null)
     {
         src.ShouldEqual(source);
         bindingSource.Path.Path.ShouldEqual(path);
     }
     else
     {
         resourceObject.Value.ShouldEqual(source);
         bindingSource.Path.Path.ShouldEqual(path);
     }
 }
 internal static void BindingSourceShouldBeValidDataContext(object target, IBindingSource bindingSource, string path)
 {
     BindingSourceShouldBeValid(bindingSource, path,
         BindingServiceProvider.ContextManager.GetBindingContext(target).Value);
 }
 private void OneTimeHandler(IBindingSource sender, ValueChangedEventArgs args)
 {
     IDataBinding binding = Binding;
     if (binding == null || !binding.SourceAccessor.IsAllMembersAvailable() || !binding.TargetAccessor.IsAllMembersAvailable())
         return;
     EventHandler<IBindingSource, ValueChangedEventArgs> handler = OneTimeHandler;
     UnsubscribeSources(handler);
     binding.TargetAccessor.Source.ValueChanged -= handler;
     binding.UpdateTarget();
     if (_disposeBinding)
         binding.Dispose();
 }
 private void CollectErrors(ref List<object> errors, IBindingSource bindingSource)
 {
     var notifyDataErrorInfo = bindingSource.GetPathMembers(false).PenultimateValue as INotifyDataErrorInfo;
     if (notifyDataErrorInfo == null)
         return;
     var path = bindingSource.Path.Parts.LastOrDefault();
     var paths = ErrorPaths;
     if (!string.IsNullOrEmpty(path) || paths == null || paths.Length == 0)
         CollectErrors(notifyDataErrorInfo, path, ref errors);
     if (paths != null)
     {
         for (int i = 0; i < paths.Length; i++)
             CollectErrors(notifyDataErrorInfo, paths[i], ref errors);
     }
 }
 private void OnBindingSourceValueChanged(IBindingSource sender, ValueChangedEventArgs args)
 {
     if (args.LastMemberChanged && !sender.Path.IsEmpty)
         return;
     UpdateSources(false);
     UpdateErrors(null);
 }