// PF TODO: This API and ConstantEditorBuilder is badly designed. /// <summary> /// Creates an editor for a constant. /// </summary> /// <param name="uiContext">The view in which the editor constant will be displayed.</param> /// <param name="portModel">The port that owns the constant, if any.</param> /// <param name="constant">The constant.</param> /// <param name="onValueChanged">An action to call when the user has finished editing the value.</param> /// <param name="modelIsLocked">Whether the node owning the constant, if any, is locked.</param> /// <returns>A VisualElement that contains an editor for the constant.</returns> public static VisualElement CreateEditorForConstant( IModelView uiContext, IPortModel portModel, IConstant constant, Action <IChangeEvent, object> onValueChanged, bool modelIsLocked) { Action <IChangeEvent> myValueChanged = evt => { if (evt != null) // Enum editor sends null { var p = evt.GetType().GetProperty("newValue"); var newValue = p.GetValue(evt); if (constant is IStringWrapperConstantModel stringWrapperConstantModel) { stringWrapperConstantModel.StringValue = (string)newValue; } else { onValueChanged(evt, newValue); } } }; var ext = ExtensionMethodCache <IConstantEditorBuilder> .GetExtensionMethod( uiContext.GetType(), constant.GetType(), ConstantEditorBuilder.FilterMethods, ConstantEditorBuilder.KeySelector); if (ext != null) { var constantBuilder = new ConstantEditorBuilder(myValueChanged, uiContext.CommandDispatcher, modelIsLocked, portModel); return((VisualElement)ext.Invoke(null, new object[] { constantBuilder, constant })); } Debug.Log($"Could not draw Editor GUI for node of type {constant.Type}"); return(new Label("<Unknown>")); }
public virtual bool IsFileGroup(IConstant ccc) { Globe.cstat(ConsoleColor.Green, "IsFileGroup?\r\t{0}: {1}", ccc.GetType(), ConsoleColor.Red, ccc.Value); if (ccc is efx.Environment.Scheme.ConstFileGroup) { return(true); } return(false); }
public virtual bool IsFile(IConstant ccc) { Globe.cstat(ConsoleColor.Green, "IsFile?\r\t{0}: {1}", ccc.GetType(), ConsoleColor.Red, ccc.Value); if (ccc is efx.Environment.Scheme.ConstFile) { return(true); } if (ccc is efx.Environment.Scheme.FileCommand) { return(true); } //if (ccc is efx.Environment.Scheme.FileFilter) return true; return(false); }
public virtual bool IsDir(IConstant ccc) { Globe.cstat(ConsoleColor.Green, "IsDir?\r\t{0}: {1}", ccc.GetType(), ConsoleColor.Red, ccc.Value); if (ccc is efx.Forms.Specialized.SelectionInfo) { return(true); } if (ccc is efx.Environment.Scheme.ConstDirectory) { return(true); } if (ccc is efx.Environment.Scheme.ConstDirectoryFiltered) { return(true); } return(false); }
/// <summary> /// Gets the value of a Constant expression if it's of the specified type T or throws an exception. /// </summary> public static T Value <T>(this IConstant constant) { if (typeof(T) == typeof(object)) { return((T)constant.Value); } else { return (constant.Value is T value ? value : throw DynamicException.Create ( "ValueType", $"Expected {typeof(Constant<T>).ToPrettyString()} but found {constant.GetType().ToPrettyString()}." )); } }