Example #1
0
        // <summary>
        // Looks for and returns the UIElement used to represent the specified CategoryEditor. Returns
        // null if not found.
        // </summary>
        // <param name="editor">CategoryEditor to look for.</param>
        // <param name="category">Category to look in.</param>
        // <param name="pendingGeneration">Set to true if the specified editor exists in a collapsed container
        // (CategoryContainer or an advanced section).  If so, the section is expanded, but the visual does not
        // exist yet and should be requested later.</param>
        // <returns>UIElement for the specified CategoryEditor if found, null otherwise</returns>
        internal UIElement FindCategoryEditorVisual(CategoryEditor editor, ModelCategoryEntry category, out bool pendingGeneration)
        {
            pendingGeneration = false;

            if (editor == null || category == null)
            {
                return(null);
            }

            UIElement editorVisual = null;

            CiderCategoryContainer categoryContainer = this.ItemContainerGenerator.ContainerFromItem(category) as CiderCategoryContainer;

            if (categoryContainer == null)
            {
                return(null);
            }

            // Expand the parent category, if it isn't already
            if (!categoryContainer.Expanded)
            {
                categoryContainer.Expanded = true;
                pendingGeneration          = true;
            }

            // Expand the parent advanced section, if any and if it isn't already
            if (!categoryContainer.AdvancedSectionPinned && ExtensibilityAccessor.GetIsAdvanced(editor))
            {
                categoryContainer.AdvancedSectionPinned = true;
                pendingGeneration = true;
            }

            bool pendingGenerationTemp;

            editorVisual       = categoryContainer.ContainerFromEditor(editor, out pendingGenerationTemp);
            pendingGeneration |= pendingGenerationTemp;

            if (editorVisual != null)
            {
                pendingGeneration = false;
            }

            return(editorVisual);
        }
        private static List <ModelProperty> GetTypeConverterSubPropertiesHelper(ModelItem item, TypeConverter customConverter)
        {
            if (item == null)
            {
                return(null);
            }

            List <ModelProperty> subProperties = null;

            TypeConverter converter = customConverter;

            if (converter == null)
            {
                // See if there is a converter associated with the item type itself
                converter = ExtensibilityAccessor.GetTypeConverter(item);
            }

            if (converter != null)
            {
                PropertyDescriptorCollection subPropertyDescriptors =
                    converter.GetProperties(item.GetCurrentValue());

                if (subPropertyDescriptors != null && subPropertyDescriptors.Count > 0)
                {
                    foreach (PropertyDescriptor subPropertyDescriptor in subPropertyDescriptors)
                    {
                        ModelProperty subProperty = item.Properties[subPropertyDescriptor.Name];

                        // We want to expose all properties through the model regardless of whether they
                        // are browsable or not.  That distinction should be made by the UI utilizing it
                        if (subProperty != null)
                        {
                            if (subProperties == null)
                            {
                                subProperties = new List <ModelProperty>();
                            }

                            subProperties.Add(subProperty);
                        }
                    }
                }
            }
            return(subProperties);
        }
        // Check if the category is shown for the current category editor type
        private bool IsCategoryShown(Type categoryEditorType)
        {
            bool           ret            = true;
            CategoryEditor editorToRemove = (CategoryEditor)ExtensibilityAccessor.SafeCreateInstance(categoryEditorType);

            if (editorToRemove != null)
            {
                ModelCategoryEntry affectedCategory = _categoryList.FindCategory(editorToRemove.TargetCategory) as ModelCategoryEntry;
                if (affectedCategory == null)
                {
                    ret = false;
                }
            }
            else
            {
                ret = false;
            }
            return(ret);
        }
        // Helper method that adjusts the visible set of CategoryEditors based on the specified selection
        private void UpdateCategoryEditors(View.Selection selection)
        {
            // Figure out which category editors to show
            Dictionary <Type, object> newCategoryEditorTypes = _propertyToolBar.CurrentViewManager.GetCategoryEditors(
                FindCommonType(selection == null ? null : selection.SelectedObjects),
                _categoryList);

            // Figure out which CategoryEditors are no longer needed and remove them
            List <Type> editorTypesToRemove = null;

            foreach (KeyValuePair <Type, string> item in _activeCategoryEditors)
            {
                if (!newCategoryEditorTypes.ContainsKey(item.Key) || !IsCategoryShown(item.Key))
                {
                    // New selection does not include this existing category editor
                    // or the category that contains this editor
                    // so remove the editor.
                    if (editorTypesToRemove == null)
                    {
                        editorTypesToRemove = new List <Type>();
                    }

                    editorTypesToRemove.Add(item.Key);
                }
                else
                {
                    // This category editor already exists, so don't re-add it
                    newCategoryEditorTypes.Remove(item.Key);
                }
            }

            if (editorTypesToRemove != null)
            {
                foreach (Type editorTypeToRemove in editorTypesToRemove)
                {
                    ModelCategoryEntry affectedCategory = _categoryList.FindCategory(_activeCategoryEditors[editorTypeToRemove]) as ModelCategoryEntry;
                    if (affectedCategory != null)
                    {
                        affectedCategory.RemoveCategoryEditor(editorTypeToRemove);
                    }

                    _activeCategoryEditors.Remove(editorTypeToRemove);
                }
            }

            // Figure out which CategoryEditors are now required and add them
            foreach (Type editorTypeToAdd in newCategoryEditorTypes.Keys)
            {
                CategoryEditor editor = (CategoryEditor)ExtensibilityAccessor.SafeCreateInstance(editorTypeToAdd);
                if (editor == null)
                {
                    continue;
                }

                ModelCategoryEntry affectedCategory = _categoryList.FindCategory(editor.TargetCategory) as ModelCategoryEntry;
                if (affectedCategory == null)
                {
                    continue;
                }

                affectedCategory.AddCategoryEditor(editor);
                _activeCategoryEditors[editorTypeToAdd] = editor.TargetCategory;
            }
        }