Exemplo n.º 1
0
        public TypeBrowser(AssemblyContextControlItem assemblyContext, EditingContext context, Func <Type, bool> filter)
        {
            this.assemblyContext = assemblyContext;
            this.Context         = context;
            this.filter          = filter;
            SetValue(GenericTypeMappingProperty, new ObservableCollection <TypeKeyValue>());
            GenericTypeMapping.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(GenericTypeMappingCollectionChanged);
            InitializeComponent();
            this.typeEntryTextBox.Focus();

            if (!size.IsEmpty)
            {
                this.Height = size.Height;
                this.Width  = size.Width;
            }

            this.SizeChanged += new SizeChangedEventHandler(TypeBrowser_SizeChanged);

            this.HelpKeyword       = HelpKeywords.TypeBrowser;
            this.perfEventProvider = new DesignerPerfEventProvider();
        }
        public TypeBrowser(AssemblyContextControlItem assemblyContext, EditingContext context, Func<Type, bool> filter)
        {
            this.assemblyContext = assemblyContext;
            this.Context = context;
            this.filter = filter;
            SetValue(GenericTypeMappingProperty, new ObservableCollection<TypeKeyValue>());
            GenericTypeMapping.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(GenericTypeMappingCollectionChanged);
            InitializeComponent();
            this.typeEntryTextBox.Focus();

            if (!size.IsEmpty)
            {
                this.Height = size.Height;
                this.Width = size.Width;
            }

            this.SizeChanged += new SizeChangedEventHandler(TypeBrowser_SizeChanged);

            this.HelpKeyword = HelpKeywords.TypeBrowser;
            this.perfEventProvider = new DesignerPerfEventProvider();
        }
Exemplo n.º 3
0
        // Tries to figure out what property to select and selects is
        private void UpdateSelectedProperty(View.Selection selection)
        {
            // If we are not loaded, skip any and all selection magic
            if (!this.IsLoaded)
            {
                return;
            }

            if (selection != null)
            {
                // See what the view would like us to select if we run out of things
                // we can think of selecting
                //
                SelectionPath fallbackSelection = null;
                if (_propertyToolBar.CurrentViewManager != null)
                {
                    fallbackSelection = _propertyToolBar.CurrentViewManager.GetDefaultSelectionPath(_categoryList);
                }

                // Select the first thing we request that exists, using the following
                // precedence order:
                //
                //  * LastSelectionPath
                //  * DefaultProperty
                //  * Whatever the view wants to show (first category, first property, ...)
                //
                _categoryList.UpdateSelectedProperty(
                    this.LastSelectionPath,
                    ModelPropertyMerger.GetMergedDefaultProperty(selection.SelectedObjects),
                    fallbackSelection);
            }

            if (DesignerPerfEventProvider != null)
            {
                DesignerPerfEventProvider.PropertyInspectorUpdatePropertyListEnd();
            }
        }
        /// <summary>
        /// Selection helper method.  This sets itemToSelect into the selection.
        /// Any existing items are deselected.
        /// </summary>
        /// <param name="context">The editing context to apply this selection change to.</param>
        /// <param name="itemToSelect">The item to select.</param>
        /// <returns>A Selection object that contains the new selection.</returns>
        /// <exception cref="ArgumentNullException">If context or itemToSelect is null.</exception>
        public static Selection SelectOnly(EditingContext context, ModelItem itemToSelect)
        {
            if (context == null)
            {
                throw FxTrace.Exception.ArgumentNull("context");
            }
            if (itemToSelect == null)
            {
                throw FxTrace.Exception.ArgumentNull("itemToSelect");
            }

            // Check to see if only this object is selected.  If so, bail.
            Selection existing = context.Items.GetValue <Selection>();

            if (existing.PrimarySelection == itemToSelect)
            {
                IEnumerator <ModelItem> en = existing.SelectedObjects.GetEnumerator();
                en.MoveNext();
                if (!en.MoveNext())
                {
                    return(existing);
                }
            }

            DesignerPerfEventProvider designerPerfEventProvider = context.Services.GetService <DesignerPerfEventProvider>();

            if (designerPerfEventProvider != null)
            {
                designerPerfEventProvider.SelectionChangedStart();
            }

            Selection selection = new Selection(itemToSelect);

            context.Items.SetValue(selection);
            return(selection);
        }
        private void OnValidationWorkCompleted(Tuple <ValidationReason, ValidationResults, Exception> input)
        {
            ValidationReason  reason    = input.Item1;
            ValidationResults results   = input.Item2;
            Exception         exception = input.Item3;

            Fx.Assert(results != null ^ exception != null, "result and exception should not both be null");

            bool needsToMarkValidationErrors        = false;
            ValidationErrorInfo validationErrorInfo = null;

            if (exception != null)
            {
                ModelItem rootModelItem = this.modelService.Root;
                Activity  rootActivity  = rootModelItem.GetRootActivity();

                if (rootActivity != null)
                {
                    // We don't want any crash propagating from here as it causes VS to crash.
                    if (!this.ValidationErrors.ContainsKey(rootActivity))
                    {
                        ValidationErrorState validationError = new ValidationErrorState(new List <string>(), ValidationState.Error);
                        this.ValidationErrors.Add(rootActivity, validationError);
                    }
                    else
                    {
                        this.ValidationErrors[rootActivity].ValidationState = ValidationState.Error;
                    }

                    this.ValidationErrors[rootActivity].ErrorMessages.Add(exception.ToString());

                    // Notify an update to the attached properties
                    this.NotifyValidationPropertiesChanged(rootModelItem);
                }

                validationErrorInfo         = new ValidationErrorInfo(exception.ToString());
                needsToMarkValidationErrors = true;
            }

            DesignerPerfEventProvider perfProvider = this.context.Services.GetService <DesignerPerfEventProvider>();

            perfProvider.WorkflowDesignerValidationStart();

            List <ValidationError> validationErrors = null;

            if (results != null)
            {
                validationErrors = new List <ValidationError>(results.Errors);
                validationErrors.AddRange(results.Warnings);
                Activity rootActivity = this.modelService.Root.GetRootActivity();
                needsToMarkValidationErrors = this.MarkErrors(validationErrors, reason, rootActivity);
            }

            if (this.errorService != null && needsToMarkValidationErrors) // Error service could be null if no implementation has been provided
            {
                List <ValidationErrorInfo> errors = new List <ValidationErrorInfo>();

                if (validationErrors != null)
                {
                    foreach (ValidationError validationError in validationErrors)
                    {
                        Activity            currentActivity = validationError.Source;
                        ValidationErrorInfo error           = new ValidationErrorInfo(validationError);

                        // The acquired activity reference will be release in the Main AppDomain when it clear the error list
                        if (validationError.SourceDetail != null)
                        {
                            error.SourceReferenceId = this.objectReferenceService.AcquireObjectReference(validationError.SourceDetail);
                        }
                        else if (validationError.Source != null)
                        {
                            error.SourceReferenceId = this.objectReferenceService.AcquireObjectReference(validationError.Source);
                        }
                        else
                        {
                            error.SourceReferenceId = Guid.Empty;
                        }
                        errors.Add(error);
                    }
                }

                if (validationErrorInfo != null)
                {
                    errors.Add(validationErrorInfo);
                }

                foreach (Guid acquiredObjectReference in this.AcquiredObjectReferences)
                {
                    this.objectReferenceService.ReleaseObjectReference(acquiredObjectReference);
                }

                this.AcquiredObjectReferences.Clear();

                foreach (ValidationErrorInfo error in errors)
                {
                    if (error.SourceReferenceId != Guid.Empty)
                    {
                        this.AcquiredObjectReferences.Add(error.SourceReferenceId);
                    }
                }

                this.errorService.ShowValidationErrors(errors);
            }

            perfProvider.WorkflowDesignerValidationEnd();
            this.OnValidationCompleted();
        }
Exemplo n.º 6
0
        // Updates PI when the application becomes Idle (perf optimization)
        private void OnSelectionChangedIdle()
        {
            if (DesignerPerfEventProvider != null)
            {
                DesignerPerfEventProvider.PropertyInspectorUpdatePropertyListStart();
            }

            if (AreSelectionsEquivalent(_lastNotifiedSelection, _displayedSelection))
            {
                return;
            }

            if (!VisualTreeUtils.IsVisible(this))
            {
                return;
            }

            // Change the SelectedControlFlowDirectionRTL resource property
            // This will allow the 3rd party editors to look at this property
            // and change to RTL for controls that support RTL.
            // We set the resource to the primary selections RTL property.
            FlowDirection commmonFD = this.FlowDirection;

            if (_lastNotifiedSelection != null && _lastNotifiedSelection.PrimarySelection != null)
            {
                FrameworkElement selectedElement = _lastNotifiedSelection.PrimarySelection.View as FrameworkElement;
                if (selectedElement != null)
                {
                    commmonFD = selectedElement.FlowDirection;
                }

                // In case of mulitislection,
                // if the FlowDirection is different then always set it to LTR.
                // else set it to common FD.
                if (_lastNotifiedSelection.SelectionCount > 1)
                {
                    foreach (ModelItem item in _lastNotifiedSelection.SelectedObjects)
                    {
                        FrameworkElement curElm = item.View as FrameworkElement;
                        if (curElm != null && curElm.FlowDirection != commmonFD)
                        {
                            //reset to LTR (since the FD's are different within multiselect)
                            commmonFD = FlowDirection.LeftToRight;
                            break;
                        }
                    }
                }
            }

            PropertyInspectorResources.GetResources()["SelectedControlFlowDirectionRTL"] = commmonFD;

            RefreshPropertyList(false);

            UpdateSelectionPropertyChangedEventHooks(_displayedSelection, _lastNotifiedSelection);
            _displayedSelection = _lastNotifiedSelection;
            _lastParent         = GetCommonParent(_lastNotifiedSelection);

            // Handle dangling transactions
            _defaultCommandHandler.CommitOpenTransactions();

            OnPropertyChanged("IsInfoBarNameReadOnly");
            OnPropertyChanged("SelectionName");
            OnPropertyChanged("SelectionIcon");
            OnPropertyChanged("SelectionTypeName");
        }