UI & Options |
Scripts can present a configuration UI to the user by defining a class that extends ScriptOptions. Each public property becomes a configurable option in the ReadySuite property grid. Use attributes to control how properties are displayed, grouped, and validated.
Define a class that inherits from ScriptOptions, then override LoadOptions() in your script to wire it up:
public class MyOptions : ScriptOptions { public MyOptions() { // Set default values in the constructor Enabled = true; MaxItems = 100; } [Category("Settings")] [Description("Enable processing.")] public bool Enabled { get; set; } [Category("Settings")] [Description("Maximum number of items to process.")] public int MaxItems { get; set; } } public override void LoadOptions() { Options = new MyOptions(); }
| Attribute | Purpose |
|---|---|
| [Category("...")] | Groups properties under a collapsible heading in the property grid |
| [Description("...")] | Tooltip text shown when the property is selected |
| [DisplayName("...")] | Overrides the property name shown in the UI |
[Category("Output Fields")] [DisplayName("PDF Portfolio")] [Description("Field indicating whether the source is a PDF portfolio.")] public FieldItem IsPdfPortfolioField { get; set; }
Use FieldItem as a property type to present a field picker. The [FieldItem] attribute controls the picker behavior:
| Parameter | Purpose |
|---|---|
| AllowNew | Allow the user to create a new field |
| AllowNull | Allow no selection (optional field) |
| AllowSystemFields | Include system fields in the picker |
| Types | Restrict to specific FieldItemType values |
// Required text field picker that allows creating new fields [Category("Output")] [Required(ErrorMessage = "Output field is required.")] [FieldItem(AllowNew = true, AllowSystemFields = false, AllowNull = false, Types = new[] { FieldItemType.Text })] public FieldItem OutputField { get; set; } // Optional boolean field picker (read-only selection from existing fields) [Category("Input")] [FieldItem(AllowNew = false, AllowNull = true, Types = new[] { FieldItemType.Boolean })] public FieldItem FlagField { get; set; }
Use List<FieldItem> when the user needs to select multiple fields:
[Category("Input")] [Description("Fields to include in the export.")] [NotNullOrEmptyCollection(ErrorMessage = "At least one field is required.")] [FieldItem(Types = new[] { FieldItemType.Text, FieldItemType.Memo })] public List<FieldItem> InputFields { get; set; }
Any enum property automatically renders as a dropdown. Use [Description] attributes on enum members for display-friendly names:
public enum OutputMode { [Description("Write to field")] Field, [Description("Write to file")] File, [Description("Write to field and file")] Both } [Category("Settings")] [Description("Select where the output is written.")] public OutputMode Mode { get; set; }
For multi-select scenarios, use a [Flags] enum:
[Flags] public enum ReportTypes { None = 0, Summary = 1, Details = 2, Errors = 4 }
Use editor attributes to provide browse dialogs for path properties:
// Folder browser [Category("Output")] [Description("Folder where files will be saved.")] [Editor(typeof(FolderPathEditor), typeof(UITypeEditor))] public string OutputFolder { get; set; } // File open browser [Category("Input")] [Editor(typeof(FileNameEditor), typeof(UITypeEditor))] public string InputFile { get; set; } // File save browser [Category("Output")] [Editor(typeof(SaveFileNameEditor), typeof(UITypeEditor))] public string ReportFile { get; set; }
The DateFormatEditor provides a specialized picker for date format strings:
[Category("Settings")] [Editor("Compiled.EDD.Scripting.UI.DateFormatEditor, Compiled.EDD.Scripting.UI", typeof(System.Drawing.Design.UITypeEditor))] public string DateTimeFormat { get; set; }
Use validation attributes to enforce requirements before the script runs:
// Always required [Required(ErrorMessage = "Body field is required.")] public FieldItem Body { get; set; } // Required only when another property has a specific value [RequiredIf("Mode", OutputMode.File, ErrorMessage = "Output folder is required when writing to file.")] public string OutputFolder { get; set; } // Required when a bool is true [RequiredIf("Truncate", true, ErrorMessage = "Max length must be set when truncation is enabled.")] public int MaxLength { get; set; } // Collection must have at least one item [NotNullOrEmptyCollection(ErrorMessage = "At least one field must be selected.")] public List<FieldItem> Fields { get; set; }
Use List<string> for properties where the user enters multiple string values. These render as a line-based editor:
[Category("Settings")] [Description("File extensions to include.")] [NotNullOrEmptyCollection(AllowNullOrWhiteSpaceStrings = false, ErrorMessage = "At least one extension is required.")] public List<string> Extensions { get; set; }
| Type | UI Control |
|---|---|
| bool | Checkbox |
| string | Text box |
| int, long, float, double, decimal | Numeric text box |
| char | Single character text box |
| DateTime | Date/time picker |
| FieldItem | Field picker dropdown |
| List<FieldItem> | Multi-field picker |
| List<string> | Line-based string editor |
| List<FindAndReplaceItem> | Find-and-replace grid editor |
| enum | Dropdown selector |
| [Flags] enum | Multi-select dropdown |
Other primitive types render with the property grid's default editor. To customize how a property is displayed — file or folder browsers, custom pickers, etc. — apply an [Editor] attribute as shown in File and Folder Browsers.