/// <summary> /// Initializes the control with the inspector property it is for and the current value. /// </summary> /// <param name="inspectorProperty">Inspector property the control is for.</param> /// <param name="editorContext">Editor context this control lives in.</param> /// <param name="localizationContext">Context used for showing and changing localized attribute values.</param> /// <param name="currentValue">Current value.</param> /// <param name="valueInherited">Indicates if the current value was inherited.</param> public virtual void Init(InspectorPropertyAttribute inspectorProperty, EditorContext editorContext, LocalizationContext localizationContext, object currentValue, bool valueInherited) { // Setup data context of control. this.dataContext = new InspectorPropertyData(inspectorProperty, localizationContext) { EditorContext = editorContext, Value = currentValue, ValueInherited = valueInherited }; this.dataContext.ValueChanged += this.OnValueChanged; this.DataContext = this.dataContext; }
private object GetDefaultValue(InspectorPropertyAttribute inspectorProperty) { return this.selectedBlueprint != null ? this.selectedBlueprint.Blueprint.GetAttributeTable() .GetValueOrDefault(inspectorProperty.Name, inspectorProperty.Default) : null; }
protected void OnValueChanged(InspectorPropertyAttribute inspectorProperty, object newValue) { InspectorControlValueChangedDelegate handler = this.ValueChanged; if (handler != null) { handler(inspectorProperty, newValue); } }
private void OnPropertyValueChanged(InspectorPropertyAttribute inspectorProperty, object newValue) { if (this.value == null) { this.value = new AttributeTable(); } this.value.SetValue(inspectorProperty.Name, newValue); InspectorPropertyData dataContext = (InspectorPropertyData)this.DataContext; dataContext.Value = this.value; }
private object GetPropertyValue(InspectorPropertyAttribute inspectorProperty, out bool inherited) { object propertyValue; if (this.value != null && this.value.TryGetValue(inspectorProperty.Name, out propertyValue)) { inherited = false; return propertyValue; } inherited = true; return inspectorProperty.Default; }
public override void Init( InspectorPropertyAttribute inspectorProperty, EditorContext editorContext, LocalizationContext localizationContext, object currentValue, bool valueInherited) { base.Init(inspectorProperty, editorContext, localizationContext, currentValue, valueInherited); // Disable for localized strings. // TODO(np): Enable editing while not showing RAW values. var stringProperty = inspectorProperty as InspectorStringAttribute; if (stringProperty != null && stringProperty.Localized) { this.IsEnabled = false; } }
private object GetCurrentAttributeValue(InspectorPropertyAttribute inspectorProperty, out bool inherited) { object value; EntityConfiguration entityConfiguration = (EntityConfiguration)this.Value; if (entityConfiguration != null && entityConfiguration.Configuration.TryGetValue(inspectorProperty.Name, out value)) { inherited = false; } else { inherited = true; value = this.GetDefaultValue(inspectorProperty); } return value; }
public InspectorPropertyData( InspectorPropertyAttribute inspectorProperty, LocalizationContext localizationContext) { this.inspectorProperty = inspectorProperty; // Check for localized attribute. var stringProperty = this.inspectorProperty as InspectorStringAttribute; if (stringProperty != null && stringProperty.Localized) { this.localizationContext = localizationContext; if (this.localizationContext != null) { this.localizationContext.ProjectLanguageChanged += this.OnProjectLanguageChanged; } } }
private void OnPropertyControlValueChanged(InspectorPropertyAttribute inspectorProperty, object newValue) { EntityConfiguration entityConfiguration = (EntityConfiguration)this.Value ?? new EntityConfiguration(); // Remove value if default value or inherited from blueprint. Otherwise set it. object defaultValue = this.GetDefaultValue(inspectorProperty); var defaultList = defaultValue as IList; var newList = newValue as IList; if (defaultList != null && newList != null && CollectionUtils.ListEqual(defaultList, newList)) { entityConfiguration.Configuration.RemoveValue(inspectorProperty.Name); } else if (Equals(newValue, defaultValue)) { entityConfiguration.Configuration.RemoveValue(inspectorProperty.Name); } else { entityConfiguration.Configuration.SetValue(inspectorProperty.Name, newValue); } this.OnValueChanged(); }
/// <summary> /// Creates and positions a new inspector control for the passed property. /// </summary> /// <param name="inspectorProperty">Property to create an inspector control for.</param> /// <param name="currentValue">Current value of the observed property.</param> /// <param name="valueInherited">Indicates if the current value was inherited.</param> public IInspectorControl CreateInspectorControlFor( InspectorPropertyAttribute inspectorProperty, object currentValue, bool valueInherited) { // Create inspector control. IInspectorControl inspectorControl; if (inspectorProperty.IsList) { inspectorControl = new ListInspector(); } else if (inspectorProperty is InspectorBoolAttribute) { inspectorControl = new CheckBoxInspector(); } else if (inspectorProperty is InspectorStringAttribute) { inspectorControl = new TextBoxInspector(); } else if (inspectorProperty is InspectorFloatAttribute) { inspectorControl = new SingleUpDownInspector(); } else if (inspectorProperty is InspectorIntAttribute) { inspectorControl = new IntegerUpDownInspector(); } else if (inspectorProperty is InspectorEnumAttribute) { inspectorControl = new ComboBoxInspector(); } else if (inspectorProperty is InspectorBlueprintAttribute) { inspectorControl = null; } else if (inspectorProperty is InspectorDataAttribute) { inspectorControl = new DataInspector(); } else if (inspectorProperty is InspectorEntityAttribute) { inspectorControl = new EntityInspector(); } else { inspectorControl = null; } // Setup control. if (inspectorControl != null) { inspectorControl.Init(inspectorProperty, this.editorContext, this.localizationContext, currentValue, valueInherited); } return inspectorControl; }
private void OnValueChanged(InspectorPropertyAttribute inspectorProperty, object newValue) { this.RaiseEvent(new ValueChangedEventArgs { RoutedEvent = ValueChangedEvent, NewValue = newValue }); }
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { InspectorPropertyData dataContext = (InspectorPropertyData)this.DataContext; this.inspectorFactory = new InspectorFactory( dataContext.EditorContext, dataContext.EditorContext != null ? dataContext.EditorContext.LocalizationContext : null); InspectorPropertyAttribute inspectorProperty = dataContext.InspectorProperty; this.itemType = inspectorProperty.AttributeType ?? inspectorProperty.PropertyType.GetGenericArguments()[0]; this.itemInspectorProperty = inspectorProperty.Clone(); this.itemInspectorProperty.PropertyType = this.itemType; // Set items. this.ClearItemControls(); if (dataContext.Value != null) { // Backwards compatibility if the attribute was a single item first and // changed to a list now. IList items = dataContext.Value as IList; if (items != null) { foreach (var item in items) { this.AddItemControl(item); } } else { this.AddItemControl(dataContext.Value); } } }
private void OnPropertyControlValueChanged(InspectorPropertyAttribute inspectorProperty, object newValue) { BlueprintViewModel viewModel = (BlueprintViewModel)this.DataContext; viewModel.SetAttributeValue(inspectorProperty.Name, newValue); }
/// <summary> /// Gets the current value of the specified property for the passed blueprint, /// taking into account, in order: Blueprint attribute table, parents, default value. /// </summary> /// <param name="property">Property to get the current value of.</param> /// <returns>Current value of the specified property for the passed blueprint.</returns> private object GetCurrentAttributeValue(InspectorPropertyAttribute property, out bool inherited) { BlueprintViewModel viewModel = (BlueprintViewModel)this.DataContext; return viewModel.GetCurrentAttributeValue(property.Name, out inherited); }