public PropertyEditorRegistry(IPropertyEditor[] propertyEditors)
 {
     this.propertyEditors = new Dictionary<string, IPropertyEditor>();
     foreach (IPropertyEditor editor in propertyEditors)
     {
         Register(editor);
     }
 }
Example #2
0
        public EditSession StartEditing(Gdk.Rectangle cell_area, StateType state)
        {
            IPropertyEditor ed = CreateEditor(cell_area, state);

            if (ed == null)
            {
                return(null);
            }
            return(new EditSession(container, obj, property, ed));
        }
        public object Edit(Rect region, GUIContent label, object element, fiGraphMetadata metadata)
        {
            metadata.Enter("AbstractTypeEditor").Metadata.GetPersistentMetadata <fiDropdownMetadata>().ForceDisable();

            try {
                fiEditorGUI.AnimatedBegin(ref region, metadata);

                _options.RemoveExtraneousOptions();


                // draw the popup
                {
                    int popupHeight = (int)EditorStyles.popup.CalcHeight(GUIContent.none, 100);

                    Rect popupRegion = new Rect(region);
                    popupRegion.height = popupHeight;
                    region.y          += popupRegion.height;
                    region.height     -= popupRegion.height;

                    int selectedIndex = _options.GetDisplayOptionIndex(element);
                    int updatedIndex  = EditorGUI.Popup(popupRegion, label, selectedIndex, _options.GetDisplayOptions());

                    if (selectedIndex != updatedIndex)
                    {
                        metadata.GetMetadata <AbstractTypeAnimationMetadata>().ChangedTypes = true;
                    }

                    element = _options.UpdateObjectInstance(element, selectedIndex, updatedIndex);
                }

                // no element; no editor
                if (element == null)
                {
                    return(null);
                }

                // draw the instance specific property editor
                {
                    Rect selectedRegion = new Rect(region);
                    selectedRegion = fiRectUtility.IndentedRect(selectedRegion);
                    region.y      += selectedRegion.height;
                    region.height -= selectedRegion.height;

                    // show custom editor
                    PropertyEditorChain chain  = PropertyEditor.Get(element.GetType(), null);
                    IPropertyEditor     editor = chain.SkipUntilNot(typeof(AbstractTypePropertyEditor));

                    return(editor.Edit(selectedRegion, GUIContent.none, element, metadata.Enter("AbstractTypeEditor")));
                }
            }
            finally {
                fiEditorGUI.AnimatedEnd(metadata);
            }
        }
Example #4
0
        /// <summary>
        /// Returns the height of the region that needs editing.
        /// </summary>
        /// <param name="label">The label that will be used when editing.</param>
        /// <param name="element">The element that will be edited.</param>
        /// <returns>The height of the region that needs editing.</returns>
        public static float GetElementHeight <T>(this IPropertyEditor editor, GUIContent label, T element, fiGraphMetadataChild metadata)
        {
            bool hasCachedHeight;
            CachedHeightMedatadata cachedHeight = metadata.Metadata.GetMetadata <CachedHeightMedatadata>(out hasCachedHeight);

            hasCachedHeight = !hasCachedHeight;

            // If we're calling from an Edit method, just reuse the last height
            // computation (if we have a previous height computation).
            if (hasCachedHeight && BaseMethod == BaseMethodCall.Edit)
            {
                return(cachedHeight.CachedHeight);
            }

            // If we're a dropdown that is not active, show the general foldout
            // height
            var dropdown = GetDropdownMetadata(editor, metadata.Metadata);

            if (dropdown.ShouldDisplayDropdownArrow && dropdown.IsAnimating == false && dropdown.IsActive == false)
            {
                cachedHeight.CachedHeight = FoldoutHeight;
                return(FoldoutHeight);
            }

            bool setBaseMethod = false;

            if (hasCachedHeight)
            {
                BeginMethodSet(BaseMethodCall.GetElementHeight, out setBaseMethod);
            }

            try {
                // We begin (but do not end) the cull zone here. The cull zone is
                // terminated inside of Edit(). It is safe to call
                // BeginCullZone() multiple times -- it has no effect past the
                // first call.
                metadata.Metadata.BeginCullZone();

                var   api    = GetEditingAPI(editor);
                float height = api.GetElementHeight(label, element, metadata.Metadata);
                if (dropdown.IsAnimating)
                {
                    fiEditorUtility.RepaintAllEditors();
                    fiEditorGUI.UpdateFadeGroupHeight(ref height, FoldoutHeight, dropdown.AnimPercentage);
                }
                return(metadata.Metadata.GetMetadata <CachedHeightMedatadata>().CachedHeight = height);
            }
            finally {
                if (hasCachedHeight)
                {
                    EndMethodSet(setBaseMethod);
                }
            }
        }
        /// <summary>
        /// Adds an editor to the end of this chain.
        /// </summary>
        internal void AddEditor(IPropertyEditor editor)
        {
            if (editor.EditorChain != null)
            {
                throw new InvalidOperationException("Editor " + editor + " is already part of " +
                                                    "another PropertyEditorChain");
            }

            _editors.Add(editor);
            editor.EditorChain = this;
        }
 private void Register(IPropertyEditor propertyEditor)
 {
     if (!propertyEditors.ContainsKey(propertyEditor.PropertyType))
     {
         propertyEditors.Add(propertyEditor.PropertyType, propertyEditor);
     }
     else
     {
         throw new CmsException("Duplicate editor property type: " + propertyEditor.PropertyType);
     }
 }
        public object OnSceneGUI(object element)
        {
            if (element != null)
            {
                PropertyEditorChain chain  = PropertyEditor.Get(element.GetType(), null);
                IPropertyEditor     editor = chain.SkipUntilNot(typeof(AbstractTypePropertyEditor));

                return(editor.OnSceneGUI(element));
            }
            return(element);
        }
Example #8
0
        private IEnumerable <IPropertyEditor> PopulatePropertyEditors(Type type, IEnumerable <object> objects, IEnumerable <object> rootObjects, Widget widget, Dictionary <string, List <PropertyEditorParams> > editorParams)
        {
            foreach (var header in editorParams.Keys.OrderBy((s) => s))
            {
                AddGroupHeader(header, widget);
                foreach (var param in editorParams[header])
                {
                    bool            isPropertyRegistered = false;
                    IPropertyEditor editor = null;
                    foreach (var i in InspectorPropertyRegistry.Instance.Items)
                    {
                        if (i.Condition(param))
                        {
                            isPropertyRegistered = true;
                            editor = i.Builder(param);
                            break;
                        }
                    }

                    if (!isPropertyRegistered)
                    {
                        var propertyType   = param.PropertyInfo.PropertyType;
                        var iListInterface = propertyType.GetInterfaces().FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IList <>));
                        if (propertyType.IsEnum)
                        {
                            editor = CreateEditorForEnum(param);
                        }
                        else if (iListInterface != null)
                        {
                            editor = PopulateEditorsForListType(objects, rootObjects, param, iListInterface);
                        }
                        else if ((propertyType.IsClass || propertyType.IsInterface) && !propertyType.GetInterfaces().Contains(typeof(IEnumerable)))
                        {
                            editor = PopulateEditorsForInstanceType(objects, rootObjects, param);
                        }
                    }

                    if (editor != null)
                    {
                        DecoratePropertyEditor(editor, row++);
                        editors.Add(editor);
                        var showCondition = PropertyAttributes <TangerineIgnoreIfAttribute> .Get(type, param.PropertyInfo.Name);

                        if (showCondition != null)
                        {
                            editor.ContainerWidget.Updated += (delta) => {
                                editor.ContainerWidget.Visible = !showCondition.Check(param.Objects.First());
                            };
                        }
                        yield return(editor);
                    }
                }
            }
        }
Example #9
0
        /// <summary>
        /// 焦点定位到指定的属性编辑器
        /// </summary>
        /// <param name="editor"></param>
        public bool FocusToEditor(IPropertyEditor editor)
        {
            /*********************** 代码块解释 *********************************
             * 由于表单中可以使用了页签控件来作为许多属性的划分容器,
             * 所以此时需要找到指定属性对应的 TabItem,先激活该页签,
             * 然后才能对其中的属性编辑器进行设置焦点的操作。
             **********************************************************************/

            var editorControl = editor.Control;
            var form          = this.Control;

            //查找 Form 中的 TabControl 控件。
            //如果还没有生成完毕,则先更新布局,再尝试查找一次。
            var tabControl = form.GetVisualChild <TabControl>();

            if (tabControl == null)
            {
                form.UpdateLayout();
                tabControl = form.GetVisualChild <TabControl>();
            }

            if (tabControl != null)
            {
                //找到编辑器对应的 TabItem,设置为选中状态,然后焦点选中。
                //方法:编辑器的可视根元素应该与 TabItem 的 Content 属性一致。
                foreach (var item in tabControl.Items)
                {
                    var tabItem = tabControl.ItemContainerGenerator.ContainerFromItem(item) as TabItem;
                    if (tabItem != null)
                    {
                        //如果 TabItem 包含了这个编辑器。
                        var content = tabItem.Content as Visual;
                        if (content != null && content.IsAncestorOf(editorControl))
                        {
                            tabItem.IsSelected = true;

                            //如果 TabItem 已经生成了可视树,则可以直接设置焦点成功。
                            //否则,则应该先更新布局,再设置编辑器的焦点。
                            var res = editorControl.Focus();
                            if (!res)
                            {
                                tabItem.UpdateLayout();
                                res = editorControl.Focus();
                            }

                            //简单处理:异步设置焦点的情况下,直接视为成功。
                            return(res);
                        }
                    }
                }
            }

            return(editorControl.Focus());
        }
        /// <summary>
        /// This method makes it easy to use a typical property editor as a GUILayout style method,
        /// where the rect is taken care of.
        /// </summary>
        /// <param name="editor">The editor that is being used.</param>
        /// <param name="label">The label to edit the region with.</param>
        /// <param name="element">The element that is being edited.</param>
        public static T EditWithGUILayout <T>(this IPropertyEditor editor, GUIContent label,
                                              T element, fiGraphMetadataChild metadata)
        {
            float height = editor.GetElementHeight(label, element, metadata);
            Rect  region = EditorGUILayout.GetControlRect(false, height);

            if (Event.current.type != EventType.Layout)
            {
                return(editor.Edit(region, label, element, metadata));
            }
            return(element);
        }
        /// <summary>
        /// Helper method to fetch the editing API for an IPropertyEditor.
        /// </summary>
        private static IPropertyEditorEditAPI GetEditingAPI(IPropertyEditor editor)
        {
            var api = editor as IPropertyEditorEditAPI;

            if (api == null)
            {
                throw new InvalidOperationException(string.Format("Type {0} needs to extend " +
                                                                  "IPropertyEditorEditAPI", editor.GetType()));
            }

            return(api);
        }
Example #12
0
        internal EditSession(Widget container, ITypeDescriptorContext context, IPropertyEditor currentEditor)
        {
            this.context       = context;
            this.container     = container;
            this.currentEditor = currentEditor;

            currentEditor.Initialize(this);
            if (Instance != null)
            {
                currentEditor.Value = context.PropertyDescriptor.GetValue(Instance);
            }

            currentEditor.ValueChanged += OnValueChanged;
        }
Example #13
0
 protected override void OnActivated()
 {
     base.OnActivated();
     if (View.ViewEditMode == ViewEditMode.Edit)
     {
         _dashboardTypesEditor            = View.GetItems <IPropertyEditor>().First(editor => editor.MemberInfo.Name == "DashboardTypes");
         _dashboardTypesEditor.ValueRead += DashboardTypesEditorOnValueRead;
         _xmlPropertyEditor = View.GetItems <IPropertyEditor>().FirstOrDefault(editor => editor.MemberInfo.Name == "Xml");
         if (_xmlPropertyEditor != null)
         {
             _xmlPropertyEditor.ValueRead += XMLPropertyEditorOnValueRead;
         }
     }
 }
        /// <summary>
        /// Returns the next editor that will be used, or null if the given
        /// editor is either the last one or was not found in the chain.
        /// </summary>
        /// <param name="editor">The editor that is currently being used.</param>
        /// <returns>The next editor, or null if there is no next one.</returns>
        public IPropertyEditor GetNextEditor(IPropertyEditor editor)
        {
            for (int i = 0; i < _editors.Count; ++i) {
                if (_editors[i] == editor) {
                    if ((i + 1) >= _editors.Count) {
                        return null;
                    }

                    return _editors[i + 1];
                }
            }

            return null;
        }
Example #15
0
        public object OnSceneGUI(object element)
        {
            try {
                if (_cycleScene == null)
                {
                    _cycleScene = new fiCycleDetector(_cycleEdit, _cycleHeight);
                }
                _cycleScene.Enter();

                // cycle; don't do anything
                if (_cycleScene.TryMark(element) == false)
                {
                    return(element);
                }

                // Not showing a scene GUI for the object for this frame should be fine
                if (element == null)
                {
                    return(element);
                }

                var inspectedProperties = _metadata.GetProperties(InspectedMemberFilters.InspectableMembers);
                for (int i = 0; i < inspectedProperties.Count; ++i)
                {
                    var property = inspectedProperties[i];

                    var             editorChain = PropertyEditor.Get(property.StorageType, property.MemberInfo);
                    IPropertyEditor editor      = editorChain.FirstEditor;

                    object currentValue = property.Read(element);
                    object updatedValue = editor.OnSceneGUI(currentValue);

                    // We use EqualityComparer instead of == because EqualityComparer will properly unbox structs
                    if (EqualityComparer <object> .Default.Equals(currentValue, updatedValue) == false)
                    {
                        property.Write(element, updatedValue);
                    }
                }

                return(element);
            }
            finally {
                _cycleScene.Exit();
                if (_cycleScene.Depth == 0)
                {
                    _cycleScene = null;
                }
            }
        }
        public float GetElementHeight(GUIContent label, object element, fiGraphMetadata metadata)
        {
            float height = EditorStyles.label.CalcHeight(label, 100);

            if (element != null)
            {
                PropertyEditorChain chain  = PropertyEditor.Get(element.GetType(), null);
                IPropertyEditor     editor = chain.SkipUntilNot(typeof(NullablePropertyEditor));

                height += fiRectUtility.IndentVertical;
                height += editor.GetElementHeight(GUIContent.none, element, metadata.Enter("NullableEditor", metadata.Context));
            }

            return(height);
        }
        public EditSession(Gtk.Widget container, object instance, PropertyDescriptor property, IPropertyEditor currentEditor)
        {
            this.property      = property;
            this.obj           = instance;
            this.container     = container;
            this.currentEditor = currentEditor;

            currentEditor.Initialize(this);
            if (instance != null)
            {
                currentEditor.Value = property.GetValue(instance);
            }

            currentEditor.ValueChanged += OnValueChanged;
        }
Example #18
0
        public EditSession StartEditing(Gdk.Rectangle cell_area, StateType state)
        {
            IPropertyEditor ed = CreateEditor(cell_area, state);

            if (ed == null)
            {
                return(null);
            }
            ed.Initialize(property);
            if (obj != null)
            {
                ed.AttachObject(obj);
                ed.Value = property.GetValue(obj);
            }
            return(new EditSession(container, obj, property, ed));
        }
Example #19
0
        /// <summary>
        /// Method called after the schema set has been loaded and the DomNodeTypes have been created, but
        /// before the DomNodeTypes have been frozen. This means that DomNodeType.SetIdAttribute, for example, has
        /// not been called on the DomNodeTypes. Is called shortly before OnDomNodeTypesFrozen.
        /// Defines DOM adapters on the DOM types.</summary>
        /// <param name="schemaSet">XML schema sets being loaded</param>
        protected override void OnSchemaSetLoaded(XmlSchemaSet schemaSet)
        {
            foreach (XmlSchemaTypeCollection typeCollection in GetTypeCollections())
            {
                m_namespace      = typeCollection.TargetNamespace;
                m_typeCollection = typeCollection;
                bitBoxSchema.Initialize(typeCollection);

                bitBoxSchema.graphType.Type.Define(new ExtensionInfo <SceneEditingContext>());
                bitBoxSchema.graphType.Type.Define(new ExtensionInfo <NodeEditingContext>());
                bitBoxSchema.graphType.Type.Define(new ExtensionInfo <SceneDocument>());
                //bitBoxSchema.graphType.Type.Define(new ExtensionInfo<UniqueIdValidator>());

                // register extensions
                //bitBoxSchema.graphType.Type.Define(new ExtensionInfo<Game>());
                //bitBoxSchema.graphType.Type.Define(new ExtensionInfo<ReferenceValidator>());
                //bitBoxSchema.graphType.Type.Define(new ExtensionInfo<UniqueIdValidator>());
                //
                //bitBoxSchema.nodeType.Type.Define(new ExtensionInfo<GameObject>());
                //bitBoxSchema.MeshNode.Type.Define(new ExtensionInfo<Dwarf>());

                //bitBoxSchema.MeshNode.Type.Define(new ExtensionInfo<MeshNode>());


                var creator = new AdapterCreator <CustomTypeDescriptorNodeAdapter>();

                foreach (DomNodeType type in GetNodeTypes(bitBoxSchema.nodeType.Type))
                {
                    type.AddAdapterCreator(creator);

                    string defaultNodeName = type.Name.Split(':').Last().Replace("Node", "");
                    type.SetTag(new NodeTypePaletteItem(type, defaultNodeName, defaultNodeName.Localize(), null));

                    PropertyDescriptorCollection propDescs = new PropertyDescriptorCollection(null);
                    foreach (AttributeInfo attr in type.Attributes)
                    {
                        IPropertyEditor             editor            = PropertyEditorFactory.createEditorForAttribute(attr);
                        AttributePropertyDescriptor attributePropDesc = new AttributePropertyDescriptor(attr.Name.Localize(), attr, "Attributes".Localize(), null, false, editor);

                        propDescs.Add(attributePropDesc);
                    }

                    type.SetTag(propDescs);
                }
                break;
            }
        }
        /// <summary>
        /// Fetches the dropdown metadata instance that should be used. This performs any necessary initialization.
        /// </summary>
        private static fiDropdownMetadata GetDropdownMetadata(IPropertyEditor editor, fiGraphMetadata metadata)
        {
            bool wasCreated;
            var  dropdown = metadata.GetPersistentMetadata <fiDropdownMetadata>(out wasCreated);

            if (wasCreated && editor is IPropertyEditorDefaultFoldoutState)
            {
                dropdown.InvertDefaultState();

                if (((IPropertyEditorDefaultFoldoutState)editor).DefaultFoldoutState == false)
                {
                    dropdown.ForceHideWithoutAnimation();
                }
            }

            return(dropdown);
        }
        /// <summary>
        /// Returns the next editor that will be used, or null if the given editor is either the
        /// last one or was not found in the chain.
        /// </summary>
        /// <param name="editor">The editor that is currently being used.</param>
        /// <returns>The next editor, or null if there is no next one.</returns>
        public IPropertyEditor GetNextEditor(IPropertyEditor editor)
        {
            for (int i = 0; i < _editors.Count; ++i)
            {
                if (_editors[i] == editor)
                {
                    if ((i + 1) >= _editors.Count)
                    {
                        return(null);
                    }

                    return(_editors[i + 1]);
                }
            }

            return(null);
        }
        public object Edit(Rect region, GUIContent label, object element, fiGraphMetadata metadata)
        {
            // draw the nullable type toggle
            {
                int labelHeight = (int)EditorStyles.label.CalcHeight(GUIContent.none, 100);

                Rect toggleRegion = new Rect(region);
                toggleRegion.height = labelHeight;
                region.y           += toggleRegion.height;
                region.height      -= toggleRegion.height;

                if (EditorGUI.Toggle(toggleRegion, label, element != null))
                {
                    if (element == null)
                    {
                        element     = _elementType.CreateInstance();
                        GUI.changed = true;
                    }
                }
                else
                {
                    element = null;
                }
            }

            // no element; no editor
            if (element == null)
            {
                return(null);
            }

            // we have a value for the nullable type; draw the property editor
            {
                Rect selectedRegion = new Rect(region);
                selectedRegion = fiRectUtility.IndentedRect(selectedRegion);
                region.y      += selectedRegion.height;
                region.height -= selectedRegion.height;

                // show custom editor
                PropertyEditorChain chain  = PropertyEditor.Get(element.GetType(), null);
                IPropertyEditor     editor = chain.SkipUntilNot(typeof(NullablePropertyEditor));

                return(editor.Edit(selectedRegion, GUIContent.none, element, metadata.Enter("NullableEditor", metadata.Context)));
            }
        }
        protected override void OnEdit(Rect rect, UnityObject behavior, fiGraphMetadata metadata)
        {
            fiGraphMetadataChild childMetadata = metadata.Enter("DefaultBehaviorEditor");

            childMetadata.Metadata.GetPersistentMetadata <fiDropdownMetadata>().ForceDisable();

            // We don't want to get the IObjectPropertyEditor for the given target, which extends
            // UnityObject, so that we can actually edit the property instead of getting a Unity
            // reference field. We also don't want the AbstractTypePropertyEditor, which we will get
            // if the behavior has any derived types.
            PropertyEditorChain editorChain = PropertyEditor.Get(behavior.GetType(), null);
            IPropertyEditor     editor      = editorChain.SkipUntilNot(
                typeof(IObjectPropertyEditor),
                typeof(AbstractTypePropertyEditor));

            // Run the editor
            editor.Edit(rect, GUIContent.none, behavior, childMetadata);
        }
Example #24
0
        private void DecoratePropertyEditor(IPropertyEditor editor, int row)
        {
            var ctr = editor.ContainerWidget;

            if (!(editor is IExpandablePropertyEditor))
            {
                ctr.Nodes.Insert(0, new HSpacer(20));
            }

            var index = ctr.Nodes.Count() - 1;

            if (PropertyAttributes <TangerineStaticPropertyAttribute> .Get(editor.EditorParams.PropertyInfo) == null)
            {
                var keyFunctionButton = new KeyFunctionButton {
                    LayoutCell = new LayoutCell(Alignment.LeftCenter, stretchX: 0),
                };
                var keyframeButton = new KeyframeButton {
                    LayoutCell = new LayoutCell(Alignment.LeftCenter, stretchX: 0),
                    KeyColor   = KeyframePalette.Colors[editor.EditorParams.TangerineAttribute.ColorIndex],
                };
                keyFunctionButton.Clicked += editor.SetFocus;
                keyframeButton.Clicked    += editor.SetFocus;
                ctr.Nodes.Insert(index++, keyFunctionButton);
                ctr.Nodes.Insert(index++, keyframeButton);
                ctr.Nodes.Insert(index, new HSpacer(4));
                ctr.Tasks.Add(new KeyframeButtonBinding(editor.EditorParams, keyframeButton));
                ctr.Tasks.Add(new KeyFunctionButtonBinding(editor.EditorParams, keyFunctionButton));
            }
            else
            {
                ctr.Nodes.Insert(2, new HSpacer(42));
            }
            editor.ContainerWidget.Padding = new Thickness {
                Left = 4, Top = 1, Right = 12, Bottom = 1
            };
            editor.ContainerWidget.CompoundPresenter.Add(new WidgetFlatFillPresenter(
                                                             row % 2 == 0 ?
                                                             ColorTheme.Current.Inspector.StripeBackground1 :
                                                             ColorTheme.Current.Inspector.StripeBackground2
                                                             )
            {
                IgnorePadding = true
            });
        }
Example #25
0
 public IPropertyEditor GetNextEditor(IPropertyEditor editor)
 {
     int i = 0;
     while (i < this._editors.Count)
     {
         if (this._editors[i] == editor)
         {
             if (i + 1 >= this._editors.Count)
             {
                 return null;
             }
             return this._editors[i + 1];
         }
         else
         {
             i++;
         }
     }
     return null;
 }
        public float GetElementHeight(GUIContent label, object element, fiGraphMetadata metadata)
        {
            float height = EditorStyles.popup.CalcHeight(label, 100);

            height += fiRectUtility.IndentVertical;

            if (element != null)
            {
                PropertyEditorChain chain  = PropertyEditor.Get(element.GetType(), null);
                IPropertyEditor     editor = chain.SkipUntilNot(typeof(AbstractTypePropertyEditor));

                height += editor.GetElementHeight(GUIContent.none, element, metadata.Enter("AbstractTypeEditor"));
            }

            var abstractTypeMetadata = metadata.GetMetadata <AbstractTypeAnimationMetadata>();

            height = fiEditorGUI.AnimatedHeight(height, abstractTypeMetadata.ChangedTypes, metadata);
            abstractTypeMetadata.ChangedTypes = false;
            return(height);
        }
Example #27
0
 private static bool TryCreateInstance(Type editorType, Type usedEditedType, Type actualEditedType, out IPropertyEditor editor)
 {
     if (editorType.GetConstructor(Type.EmptyTypes) == null)
     {
         Debug.LogWarning("Type " + editorType + " can serve as a property editor if it has a default constructor");
         editor = null;
         return false;
     }
     editor = (IPropertyEditor)Activator.CreateInstance(editorType);
     if (!PropertyEditorTools.CanEdit(usedEditedType, editorType.GetAttribute<CustomPropertyEditorAttribute>()))
     {
         editor = null;
         return false;
     }
     if (!editor.CanEdit(actualEditedType))
     {
         editor = null;
         return false;
     }
     return true;
 }
Example #28
0
        protected virtual IPropertyEditor CreateEditor(Gdk.Rectangle cell_area, StateType state)
        {
            Type editorType = property.EditorType;

            if (editorType == null)
            {
                editorType = GetEditorForType(property.PropertyType);
                if (editorType == null)
                {
                    return(null);
                }
            }

            IPropertyEditor editor = Activator.CreateInstance(editorType) as IPropertyEditor;

            if (editor == null)
            {
                throw new Exception("The property editor '" + editorType + "' must implement the interface IPropertyEditor");
            }
            return(editor);
        }
        protected virtual IPropertyEditor CreateEditor(Gdk.Rectangle cell_area, StateType state)
        {
            if (DialogueEdit && (!property.IsReadOnly || EditsReadOnlyObject))
            {
                return(new PropertyDialogueEditor(this));
            }
            else
            {
                Type editorType = editorManager.GetEditorType(property);
                if (editorType == null)
                {
                    return(null);
                }

                IPropertyEditor editor = Activator.CreateInstance(editorType) as IPropertyEditor;
                if (editor == null)
                {
                    throw new Exception("The property editor '" + editorType + "' must implement the interface IPropertyEditor");
                }
                return(editor);
            }
        }
Example #30
0
        /// <summary>
        /// Creates a new instance of the given editorType. It is assumed that editorType extends
        /// IPropertyEditor.
        /// </summary>
        private static bool TryCreateInstance(Type editorType, Type usedEditedType,
            Type actualEditedType, ICustomAttributeProvider attributes, out IPropertyEditor editor) {

            if (editorType.GetConstructor(fsPortableReflection.EmptyTypes) == null &&
                editorType.GetConstructor(NonEmptyConstructorArgs) == null) {

                Debug.LogWarning("Type " + editorType + " can serve as a property editor if it " +
                    "has a default constructor or a constructor that takes a Type and an ICustomAttributeProvider arguments");
                editor = null;
                return false;
            }

            if (CanEdit(usedEditedType,
                fsPortableReflection.GetAttribute<CustomPropertyEditorAttribute>(editorType)) == false) {
                editor = null;
                return false;
            }

            try {
                if (editorType.GetConstructor(NonEmptyConstructorArgs) != null) {
                    editor = (IPropertyEditor)Activator.CreateInstance(editorType, new object[] { actualEditedType, attributes });
                }
                else {
                    editor = (IPropertyEditor)Activator.CreateInstance(editorType);
                }
            }
            catch (Exception e) {
                Debug.LogException(e);
                editor = null;
                return false;
            }

            if (editor.CanEdit(actualEditedType) == false) {
                editor = null;
                return false;
            }

            return true;
        }
Example #31
0
        /// <summary>
        /// Creates a new instance of the given editorType. It is assumed that editorType extends
        /// IPropertyEditor.
        /// </summary>
        private static bool TryCreateInstance(Type editorType, Type usedEditedType,
            Type actualEditedType, ICustomAttributeProvider attributes, out IPropertyEditor editor) {

            if (editorType.GetConstructor(fsPortableReflection.EmptyTypes) == null &&
                editorType.GetConstructor(NonEmptyConstructorArgs) == null) {

                Debug.LogWarning("Type " + editorType + " can serve as a property editor if it " +
                    "has a default constructor or a constructor that takes a Type and an ICustomAttributeProvider arguments");
                editor = null;
                return false;
            }

            if (CanEdit(usedEditedType,
                fsPortableReflection.GetAttribute<CustomPropertyEditorAttribute>(editorType)) == false) {
                editor = null;
                return false;
            }

            try {
                if (editorType.GetConstructor(NonEmptyConstructorArgs) != null) {
                    editor = (IPropertyEditor)Activator.CreateInstance(editorType, new object[] { actualEditedType, attributes });
                }
                else {
                    editor = (IPropertyEditor)Activator.CreateInstance(editorType);
                }
            }
            catch (Exception e) {
                Debug.LogException(e);
                editor = null;
                return false;
            }

            if (editor.CanEdit(actualEditedType) == false) {
                editor = null;
                return false;
            }

            return true;
        }
Example #32
0
        /// <summary>
        /// Constructs the main form.
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            MapUtils.SetPROJ_LIB(Environment.CurrentDirectory + "\\ProjLib");

            Gdal.SetConfigOption("GDAL_DATA", Environment.CurrentDirectory);
            LocateDependencies();

            textChanged = false;
            scrollPos = 0;
            caretPos = 0;

            dirtyFlag = false;
            isTemplate = false;
            fileHasChanged = false;
            selectedEditor = null;
            LoadSettings();

            selectListForm = new SelectListForm();
            selectListForm.VisibleChanged += new EventHandler(selectListForm_VisibleChanged);
            selectListForm.HelpRequested += new HelpEventHandler(editor_HelpRequested);

            EventProvider.EventMessage += new EventProvider.EventMessageEventHandler(EventProvider_EventMessage);

            this.splitContainer1.Panel1.Click += new EventHandler(LeftPanel_Click);
            this.splitContainer1.Panel2.Click += new EventHandler(LeftPanel_Click);

            // add render checkbox to status bar
            checkBoxRender = new CheckBox();
            checkBoxRender.Text = "";
            checkBoxRender.Checked = true;
            checkBoxRender.CheckedChanged += checkBoxRender_CheckedChanged;
            ToolStripControlHost cbItem = new ToolStripControlHost(checkBoxRender);
            //statusStripMain.Items.Add(cbItem);
            statusStripMain.Items.Insert(1, cbItem);

            UpdateMRU();
        }
        protected override float OnGetHeight(UnityObject behavior, fiGraphMetadata metadata)
        {
            fiGraphMetadataChild childMetadata = metadata.Enter("DefaultBehaviorEditor", null);

            childMetadata.Metadata.GetPersistentMetadata <fiDropdownMetadata>().ForceDisable();

            float height = 0;

            // We don't want to get the IObjectPropertyEditor for the given
            // target, which extends UnityObject, so that we can actually edit
            // the property instead of getting a Unity reference field. We also
            // don't want the AbstractTypePropertyEditor, which we will get if
            // the behavior has any derived types.
            PropertyEditorChain editorChain = PropertyEditor.Get(behavior.GetType(), null);
            IPropertyEditor     editor      = editorChain.SkipUntilNot(
                typeof(IObjectPropertyEditor),
                typeof(AbstractTypePropertyEditor));

            height += editor.GetElementHeight(GUIContent.none, behavior, childMetadata);

            return(height);
        }
Example #34
0
        /// <summary>
        /// Draws a GUI for editing the given property and returns the updated
        /// value. This does
        /// *not* write the updated value to a container.
        /// </summary>
        /// <param name="context">
        /// An optional context that the property value came from. If this is not
        /// given, then a prefab context menu will not be displayable.
        /// </param>
        public static object EditPropertyDirect(Rect region, InspectedProperty property, object propertyValue, fiGraphMetadataChild metadataChild, object context)
        {
            fiGraphMetadata metadata = metadataChild.Metadata;

            // Show a "revert to prefab" value context-menu if possible
            if (context != null)
            {
                RevertPrefabContextMenu(region, context, property);
            }

            // get the label / tooltip
            GUIContent label = new GUIContent(property.DisplayName,
                                              InspectorTooltipAttribute.GetTooltip(property.MemberInfo));

            var             editorChain = PropertyEditor.Get(property.StorageType, property.MemberInfo);
            IPropertyEditor editor      = editorChain.FirstEditor;

            EditorGUI.BeginDisabledGroup(property.CanWrite == false);
            propertyValue = editor.Edit(region, label, propertyValue, metadata.Enter("EditProperty", metadata.Context));
            EditorGUI.EndDisabledGroup();

            return(propertyValue);
        }
Example #35
0
        /// <summary>
        /// Attempts to create a property editor for the given edited data type
        /// from the given editor type.
        /// </summary>
        /// <param name="editedType">The type that is being edited.</param>
        /// <param name="editorType">The editor type.</param>
        /// <param name="attributes">
        /// The attributes that were specified for the type.
        /// </param>
        /// <param name="forceInherit">
        /// Should inheritance behavior be forced? The expected value is false.
        /// </param>
        /// <returns>
        /// A property editor that can edit the given edited type.
        /// </returns>
        public static IPropertyEditor TryCreateEditor(Type editedType, Type editorType, ICustomAttributeProvider attributes, bool forceInherit)
        {
            // If our editor isn't inherited, then we only want to create a
            // specific editor
            var customPropertyEditorAttribute = fsPortableReflection.GetAttribute <CustomPropertyEditorAttribute>(editorType);

            if (!forceInherit && (customPropertyEditorAttribute == null || customPropertyEditorAttribute.Inherit == false))
            {
                return(TryCreateSpecificEditor(editedType, editedType, editorType, attributes));
            }

            // Otherwise we want to try to create a property editor from any of
            // the edited type's associated types.
            Type baseType = editedType;

            while (baseType != null)
            {
                IPropertyEditor editor = TryCreateSpecificEditor(baseType, editedType, editorType, attributes);
                if (editor != null)
                {
                    return(editor);
                }

                foreach (Type iface in baseType.GetInterfaces())
                {
                    editor = TryCreateSpecificEditor(iface, editedType, editorType, attributes);
                    if (editor != null)
                    {
                        return(editor);
                    }
                }

                baseType = baseType.BaseType;
            }

            return(null);
        }
 public EditSession(Gtk.Widget container, object instance, PropertyDescriptor property, IPropertyEditor currentEditor)
     : this(container,instance,property,currentEditor,property.Converter)
 {
 }
Example #37
0
        /// <summary>
        /// 焦点定位到指定的属性编辑器
        /// </summary>
        /// <param name="editor"></param>
        public bool FocusToEditor(IPropertyEditor editor)
        {
            /*********************** 代码块解释 *********************************
             * 由于表单中可以使用了页签控件来作为许多属性的划分容器,
             * 所以此时需要找到指定属性对应的 TabItem,先激活该页签,
             * 然后才能对其中的属性编辑器进行设置焦点的操作。
            **********************************************************************/

            var editorControl = editor.Control;
            var form = this.Control;

            //查找 Form 中的 TabControl 控件。
            //如果还没有生成完毕,则先更新布局,再尝试查找一次。
            var tabControl = form.GetVisualChild<TabControl>();
            if (tabControl == null)
            {
                form.UpdateLayout();
                tabControl = form.GetVisualChild<TabControl>();
            }

            if (tabControl != null)
            {
                //找到编辑器对应的 TabItem,设置为选中状态,然后焦点选中。
                //方法:编辑器的可视根元素应该与 TabItem 的 Content 属性一致。
                foreach (var item in tabControl.Items)
                {
                    var tabItem = tabControl.ItemContainerGenerator.ContainerFromItem(item) as TabItem;
                    if (tabItem != null)
                    {
                        //如果 TabItem 包含了这个编辑器。
                        var content = tabItem.Content as Visual;
                        if (content != null && content.IsAncestorOf(editorControl))
                        {
                            tabItem.IsSelected = true;

                            //如果 TabItem 已经生成了可视树,则可以直接设置焦点成功。
                            //否则,则应该先更新布局,再设置编辑器的焦点。
                            var res = editorControl.Focus();
                            if (!res)
                            {
                                tabItem.UpdateLayout();
                                res = editorControl.Focus();
                            }

                            //简单处理:异步设置焦点的情况下,直接视为成功。
                            return res;
                        }
                    }
                }
            }

            return editorControl.Focus();
        }
Example #38
0
 /// <summary>
 /// 添加某个编辑器。
 /// </summary>
 /// <param name="editor"></param>
 /// <returns></returns>
 internal void AddPropertyEditor(IPropertyEditor editor)
 {
     this._editors.Add(editor);
 }
Example #39
0
		public PropertyEditor (PropertyDescriptor prop) : base (false, 0)
		{
			propEditor = CreateEditor (prop);
			Add ((Gtk.Widget) propEditor);
		}
Example #40
0
        /// <summary>
        /// The ItemSelect event handler of the layer control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="target">The object which have been selected.</param>
        private void layerControl_ItemSelect(object sender, MapObjectHolder target)
        {
            ConfirmChanges();

            layerPropertyEditor.Visible = false;
            mapPropertyEditor.Visible = false;
            selectedEditor = null;
            if (target == null)
            {

            }
            else if (target.GetType() == typeof(mapObj))
            {
                mapPropertyEditor.Target = target;
                mapPropertyEditor.Visible = true;
                selectedEditor = mapPropertyEditor;
            }
            else if (target.GetType() == typeof(layerObj) ||
                     target.GetType() == typeof(classObj) ||
                     target.GetType() == typeof(styleObj) ||
                     target.GetType() == typeof(labelObj))
            {
                layerPropertyEditor.Target = target;
                layerPropertyEditor.Visible = true;
                selectedEditor = layerPropertyEditor;
            }
        }
 /// <summary>
 /// Returns true if there is another editor after the given one.
 /// </summary>
 public bool HasNextEditor(IPropertyEditor editor)
 {
     return GetNextEditor(editor) != null;
 }
Example #42
0
		void SetupPropertyEditor (IPropertyEditor peditor)
		{
			// Ensure the key exists
			Preferences.Get (peditor.Key);
			peditor.Setup ();
		}
        /// <summary>
        /// Adds an editor to the end of this chain.
        /// </summary>
        internal void AddEditor(IPropertyEditor editor)
        {
            if (editor.EditorChain != null) {
                throw new InvalidOperationException("Editor " + editor + " is already part of " +
                    "another PropertyEditorChain");
            }

            _editors.Add(editor);
            editor.EditorChain = this;
        }
		public EditSession (Gtk.Widget container, object instance, PropertyDescriptor property, IPropertyEditor currentEditor)
		{
			this.property = property;
			this.obj = instance;
			this.container = container;
			this.currentEditor = currentEditor;
			currentEditor.ValueChanged += OnValueChanged;
			initialVal = currentEditor.Value;
		}
		internal EditSession (Widget container, ITypeDescriptorContext context, IPropertyEditor currentEditor)
		{
			this.context = context;
			this.container = container;
			this.currentEditor = currentEditor;
			
			currentEditor.Initialize (this);
			if (Instance != null)
				currentEditor.Value = context.PropertyDescriptor.GetValue (Instance);
			
			currentEditor.ValueChanged += OnValueChanged;
		}
Example #46
0
		public EditSession (Gtk.Widget container, object instance, PropertyDescriptor property, IPropertyEditor currentEditor)
		{
			this.property = property;
			this.obj = instance;
			this.container = container;
			this.currentEditor = currentEditor;
			
			currentEditor.Initialize (this);
			if (instance != null)
				currentEditor.Value = property.GetValue (instance);
			
			currentEditor.ValueChanged += OnValueChanged;
		}
Example #47
0
        /// <summary>
        /// Constructs a new MapPropertyEditorForm object.
        /// </summary>
        /// <param name="target">The target object to be edited.</param>
        /// <param name="editor">The editor to be used.</param>
        public MapPropertyEditorForm(MapObjectHolder target, IPropertyEditor editor)
        {
            InitializeComponent();
            this.SuspendLayout();
            if (target.GetType() == typeof(mapObj))
            {
                if (editor == null)
                {
                    editor = new MapPropertyEditor();
                    ((MapPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Map Properties";
                mapObj map = (mapObj)target;
                if (map.name != "")
                {
                    this.Text += " (" + map.name + ")";
                }
                this.editor = editor;
            }
            else if (target.GetType() == typeof(layerObj))
            {
                if (editor == null)
                {
                    editor = new LayerPropertyEditor();
                    ((LayerPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Layer Properties";
                layerObj layer = (layerObj)target;
                if (layer.name != "")
                {
                    this.Text += " (" + layer.name + ")";
                }
                this.editor = editor;
            }
            else if (target.GetType() == typeof(classObj))
            {
                if (editor == null)
                {
                    editor = new ClassPropertyEditor();
                    ((ClassPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Class Properties";
                classObj classObject = (classObj)target;

                StringBuilder scaledomain = new StringBuilder("");
                if (classObject.minscaledenom >= 0)
                {
                    if (classObject.maxscaledenom >= 0)
                    {
                        scaledomain.Append(" 1:" + classObject.minscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        scaledomain.Append(" from 1:" + classObject.minscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                    }
                }
                if (classObject.maxscaledenom >= 0)
                {
                    scaledomain.Append(" to 1:" + classObject.maxscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                }

                if (classObject.name != "")
                {
                    this.Text += " (" + classObject.name + scaledomain + ")";
                }
                this.editor = editor;
            }
            else if (target.GetType() == typeof(styleObj))
            {
                if (editor == null)
                {
                    editor = new StylePropertyEditor();
                    ((StylePropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text   = "Style Properties";
                this.editor = editor;
            }

            else if (target.GetType() == typeof(labelObj))
            {
                if (editor == null)
                {
                    editor = new LabelPropertyEditor();
                    ((LabelPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text   = "Label Properties";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(scalebarObj))
            {
                if (editor == null)
                {
                    editor = new ScalebarPropertyEditor();
                    ((ScalebarPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text   = "Scalebar Properties";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(queryMapObj))
            {
                if (editor == null)
                {
                    editor = new QueryMapPropertyEditor();
                    ((QueryMapPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text   = "Query Map Properties";
                this.editor = editor;
            }
            else
            {
                throw new Exception("No editor have been implemented for this item");
            }

            if (this.editor != null)
            {
                Control c = (Control)this.editor;
                c.Location = new System.Drawing.Point(3, 4);
                c.TabIndex = 0;

                editor.Target = target;
                this.Controls.Add(c);
                target.PropertyChanging += new EventHandler(target_PropertyChanging);
                editor.EditProperties   += new EditPropertiesEventHandler(editor_EditProperties);

                buttonOK.Top     = c.Bottom + 8;
                buttonCancel.Top = c.Bottom + 8;
                buttonApply.Top  = c.Bottom + 8;
            }

            UpdateButtonState();

            this.ResumeLayout(false);
        }
        /// <summary>
        /// Constructs a new MapPropertyEditorForm object.
        /// </summary>
        /// <param name="target">The target object to be edited.</param>
        /// <param name="editor">The editor to be used.</param>
        public MapPropertyEditorForm(MapObjectHolder target, IPropertyEditor editor)
        {
            InitializeComponent();
            this.SuspendLayout();
            if (target.GetType() == typeof(mapObj))
            {
                if (editor == null)
                {
                    editor = new MapPropertyEditor();
                    ((MapPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Map Properties";
                mapObj map = (mapObj)target;
                if (map.name != "")
                this.Text += " (" + map.name + ")";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(layerObj))
            {
                if (editor == null)
                {
                    editor = new LayerPropertyEditor();
                    ((LayerPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Layer Properties";
                layerObj layer = (layerObj)target;
                if (layer.name != "")
                    this.Text += " (" + layer.name + ")";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(classObj))
            {
                if (editor == null)
                {
                    editor = new ClassPropertyEditor();
                    ((ClassPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Class Properties";
                classObj classObject = (classObj)target;

                StringBuilder scaledomain = new StringBuilder("");
                if (classObject.minscaledenom >= 0)
                {
                    if (classObject.maxscaledenom >= 0)
                        scaledomain.Append(" 1:" + classObject.minscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                    else
                        scaledomain.Append(" from 1:" + classObject.minscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                }
                if (classObject.maxscaledenom >= 0)
                {
                    scaledomain.Append(" to 1:" + classObject.maxscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                }

                if (classObject.name != "")
                    this.Text += " (" + classObject.name + scaledomain + ")";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(styleObj))
            {
                if (editor == null)
                {
                    editor = new StylePropertyEditor();
                    ((StylePropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Style Properties";
                this.editor = editor;
            }

            else if (target.GetType() == typeof(labelObj))
            {
                if (editor == null)
                {
                    editor = new LabelPropertyEditor();
                    ((LabelPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Label Properties";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(scalebarObj))
            {
                if (editor == null)
                {
                    editor = new ScalebarPropertyEditor();
                    ((ScalebarPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Scalebar Properties";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(queryMapObj))
            {
                if (editor == null)
                {
                    editor = new QueryMapPropertyEditor();
                    ((QueryMapPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Query Map Properties";
                this.editor = editor;
            }
            else
                throw new Exception("No editor have been implemented for this item");

            if (this.editor != null)
            {
                Control c = (Control)this.editor;
                c.Location = new System.Drawing.Point(3, 4);
                c.TabIndex = 0;

                editor.Target = target;
                this.Controls.Add(c);
                target.PropertyChanging += new EventHandler(target_PropertyChanging);
                editor.EditProperties += new EditPropertiesEventHandler(editor_EditProperties);

                buttonOK.Top = c.Bottom + 8;
                buttonCancel.Top = c.Bottom + 8;
                buttonApply.Top = c.Bottom + 8;
            }

            UpdateButtonState();

            this.ResumeLayout(false);
        }
Example #49
0
        public void OnGUI()
        {
            EnsureResources();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            _disablePopups = GUILayout.Toggle(_disablePopups, "Disable Dialog Boxes");
            GUILayout.EndHorizontal();

            GUILayout.Label("<b><size=25>About</size></b> If you've decided to change serializers (for example, from Json.NET to Full Serializer), then this utility will assist your migration.", RichLabel);

            fiEditorGUILayout.Splitter(3);

            IPropertyEditor editor = PropertyEditor.Get(typeof(TypeSpecifier <BaseSerializer>), null).FirstEditor;

            GUILayout.Label("Select the <i>current</i> serializer and then the <i>new</i> serializer", RichLabel);

            fiEditorGUILayout.WithIndent(50, () => {
                WithTemporaryLabelWidth(120, () => {
                    editor.EditWithGUILayout(new GUIContent("Current Serializer"), _currentSerializer, _metadata.Enter(0));
                    editor.EditWithGUILayout(new GUIContent("New Serializer"), _newSerializer, _metadata.Enter(1));
                });
            });

            fiEditorGUILayout.Splitter(3);

            if (_currentSerializer.Type == null || _newSerializer.Type == null)
            {
                return;
            }
            if (_currentSerializer.Type == _newSerializer.Type)
            {
                EditorGUILayout.HelpBox("You cannot migrate to the same serializer", MessageType.Error);
                return;
            }

            _selectedMode = GUILayout.SelectionGrid(_selectedMode, new string[] { "Migrate Active Selection", "Migrate Scene Objects", "Migrate Persistent Objects" }, 3);

            if (_selectedMode == 0)
            {
                GameObject[] toMigrate = DisplaySelection();

                if (GUILayout.Button("Run Migration") && CheckAnnotationsPopup())
                {
                    BeforeMigrate();
                    foreach (var obj in toMigrate)
                    {
                        fiSerializerMigrationUtility.MigrateUnityObject(obj, _currentSerializer.Type, _newSerializer.Type);
                    }
                    DisplayPostSerializeMessage();
                }
            }

            else if (_selectedMode == 1)
            {
                DisplayScenesGUI();

                if (SceneObjectSelections == null)
                {
                    SceneObjectSelections = new UnityObjectSelectionGroup(fiSerializerMigrationUtility.GetSceneObjects());
                }

                GUILayout.Label("Scene Objects to Process", EditorStyles.boldLabel);
                SceneObjectSelections.OnGUI();

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Run Migration", GUILayout.ExpandWidth(true)) && CheckAnnotationsPopup())
                {
                    BeforeMigrate();
                    foreach (var obj in SceneObjectSelections.Selected)
                    {
                        fiSerializerMigrationUtility.MigrateUnityObject(obj, _currentSerializer.Type, _newSerializer.Type);
                    }
                    DisplayPostSerializeMessage();
                }
            }

            else if (_selectedMode == 2)
            {
                if (PersistentObjectSelections == null)
                {
                    PersistentObjectSelections = new UnityObjectSelectionGroup(fiSerializerMigrationUtility.GetPersistentObjects());
                }

                GUILayout.Label("Persistent GameObjects to Process", EditorStyles.boldLabel);
                PersistentObjectSelections.OnGUI();

                if (GUILayout.Button("Run Migration", GUILayout.ExpandWidth(true)) && CheckAnnotationsPopup())
                {
                    BeforeMigrate();
                    foreach (var obj in PersistentObjectSelections.Selected)
                    {
                        fiSerializerMigrationUtility.MigrateUnityObject(obj, _currentSerializer.Type, _newSerializer.Type);
                    }
                    DisplayPostSerializeMessage();
                }
            }
        }
Example #50
0
        public override void OnApplyTemplate()
        {
            /*********************** 代码块解释 *********************************
             *
             * 在应用模板时:
             * 找到属性界面元数据;
             * 生成属性编辑器;
             * 把属性编辑器中的控件加入到本控件模板的相应位置;
             *
            **********************************************************************/

            base.OnApplyTemplate();

            this.InitForm();
            if (this._form == null) { return; }

            var detailView = this._form.DetailView;
            if (detailView == null) { return; }

            var property = this.GetPropertyViewMeta(detailView);
            if (property == null) { return; }

            //由于这个控件可以被所有属性使用,所以这里还需要对是否在 Detail 中显示进行判断。
            if (!property.CanShowIn(ShowInWhere.Detail))
            {
                this.Visibility = Visibility.Collapsed;
                return;
            }

            this.BindVisibility(property);

            #region 生成编辑器

            var editor = AutoUI.BlockUIFactory.PropertyEditorFactory.Create(property, false);

            //如果还没有给 Form 赋值,则不能给 editor 设置值。
            //否则 PropertyEditorFactory 在创建 editor 时为其设置的只读性会在此处被清除。
            var ro = this._form.IsReadOnly;
            if (ro != ReadOnlyStatus.Dynamic) { editor.IsReadOnly = ro; }

            this.PropertyEditor = editor;
            detailView.AddPropertyEditor(editor);

            #endregion

            #region 把编辑器中的两个控件放到模板控件中

            var labelContainer = this.Template.FindName("PART_LabelContainer", this) as ContentControl;
            var editorControlContainer = this.Template.FindName("PART_EditorControlContainer", this) as ContentControl;
            if (labelContainer != null) labelContainer.Content = editor.LabelControl;
            if (editorControlContainer != null) editorControlContainer.Content = editor.Control;

            #endregion

            this.SetLayoutValues(detailView, property);

            #region 处理需要根据实体状态变化的:动态属性编辑器

            var dynamicPE = editor as EntityDynamicPropertyEditor;
            if (dynamicPE != null)
            {
                detailView.CurrentChanged += (o, e) =>
                {
                    editor.PrepareElementForEdit(dynamicPE.Control, new RoutedEventArgs());
                };
            }

            #endregion

            #region 支持 UI Test

            var label = property.Label;
            if (label != null) { AutomationProperties.SetName(editor.Control, property.Label); }

            #endregion
        }