Exemplo n.º 1
0
        private async void RequestOtherType(ITypeInfo previousType)
        {
            var args = new TypeRequestedEventArgs();

            TypeRequested?.Invoke(this, args);

            ITypeInfo st = null;

            try {
                st = await args.SelectedType;
            } catch (OperationCanceledException) {
            }

            if (st != null)
            {
                if (!this.suggestedTypes.Contains(st))
                {
                    this.suggestedTypes.Insert(0, st);
                }
            }
            else
            {
                st = previousType;
            }

            // Fixes an issue in Windows where ComboBox won't recognize inline selection changes without modifying the list.
            SynchronizationContext.Current.Post(o =>
                                                SelectedType = (ITypeInfo)o, st);
        }
Exemplo n.º 2
0
        private async void SetType()
        {
            using (await AsyncWork.RequestAsyncWork(this)) {
                ITypeInfo selectedType = null;
                var       args         = new TypeRequestedEventArgs();
                TypeRequested?.Invoke(this, args);
                if (args.SelectedType == null)
                {
                    return;
                }

                try {
                    selectedType = await args.SelectedType;
                    if (selectedType == null)
                    {
                        return;
                    }
                } catch (OperationCanceledException) {
                    return;
                }

                await SetValueAsync(new ValueInfo <ITypeInfo> {
                    Value  = selectedType,
                    Source = ValueSource.Local
                });
            }
        }
Exemplo n.º 3
0
        private async void CreateInstance()
        {
            IsCreateInstancePending = true;

            try {
                using (await AsyncWork.RequestAsyncWork(this)) {
                    ITypeInfo selectedType = null;

                    var types = await AssignableTypes.Task;
                    // If there's only one assignable type, we'll skip selection
                    if (types.Count == 1)
                    {
                        var kvp = types.First();
                        if (kvp.Value.Count == 1)
                        {
                            var group = kvp.Value.First();
                            if (!group.Skip(1).Any())
                            {
                                selectedType = group.First();
                            }
                        }
                    }

                    if (selectedType == null)
                    {
                        var args = new TypeRequestedEventArgs();
                        TypeRequested?.Invoke(this, args);
                        if (args.SelectedType == null)
                        {
                            return;
                        }

                        try {
                            selectedType = await args.SelectedType;
                            if (selectedType == null)
                            {
                                return;
                            }
                        } catch (OperationCanceledException) {
                            return;
                        }
                    }

                    await SetValueAsync(new ValueInfo <object> {
                        Value           = await TargetPlatform.EditorProvider.CreateObjectAsync(selectedType),
                        ValueDescriptor = selectedType,
                        Source          = ValueSource.Local
                    });
                }
            } finally {
                IsCreateInstancePending = false;
            }
        }