public EnumerationType Clone() { var newEnumerationType = new EnumerationType(); newEnumerationType.AddRange(this); newEnumerationType.Name = this.Name; return(newEnumerationType); }
private void EditEnumerationTypeButton_Click(object sender, EventArgs e) { var enumerationType = GetSelectedEnumerationType(); if (enumerationType == null) { enumerationType = new EnumerationType(); } using (var editor = new EnumerationTypeEditor(ainFile, enumerationType.Name)) { editor.ShowDialog(); this.EnumerationTypeComboBox.Text = editor.EnumerationName; LoadEnumerationTypes(); } }
public SpreadEnumerationTypeForm(IVariable variable, EnumerationType enumerationType) : this() { this.ainFile = variable.Root; this.variable = variable; this.enumerationType = enumerationType; }
private void ReadMetadata() { //quit if we're not attached to anything if (variable == null || ainFile == null) { return; } //display variable name declaration this.VariableTextBox.ReadOnly = false; this.VariableTextBox.Text = variable.ToString(); this.VariableTextBox.SelectionStart = 0; this.VariableTextBox.SelectionLength = 0; this.VariableTextBox.ScrollToCaret(); this.VariableTextBox.ReadOnly = true; //get metadata or use a blank variable Metadata metaData; if (ainFile.MetadataFile.Metadata.ContainsKey(variable)) { metaData = ainFile.MetadataFile.Metadata[variable]; } else { metaData = new Metadata(); } //set alternative name - either the default for what is specified string defaultAlternativeName = ainFile.AlternativeNames.GetOrNull(variable.Name); AlternativeNameTextBox.Text = metaData.ReplacementName ?? defaultAlternativeName; //is this a function parameter? Allow a default value if (variable.Parent is Function && variable.Index < variable.Parent.ParameterCount) { this.currentDefaultValue = metaData.DefaultValue; } else if (variable is Global) { //if it's a global, display the initial value specified in the AIN file, and don't allow editing this.currentDefaultValue = ainFile.GlobalInitialValues.Where(i => i.GlobalVariable == variable).FirstOrDefault(); } else { //DefaultValueTextBox.ReadOnly = true; findDefaultValueButton.Enabled = false; } if (this.currentDefaultValue != null) { string defaultValueString = this.currentDefaultValue.GetValue(); DefaultValueTextBox.Text = defaultValueString; if (variable is Global) { //DefaultValueTextBox.ReadOnly = true; findDefaultValueButton.Enabled = false; } } //get enumeration type EnumerationType enumerationType = null; if (variable.DataType.GetTypeOfArrayElement().IsInteger()) { enumerationType = metaData.EnumerationType; if (enumerationType != null) { EnumerationTypeComboBox.Text = enumerationType.Name; } } else if (variable.DataType.IsFunction()) { EditEnumerationTypeButton.Visible = false; spreadEnumerationTypeButton.Visible = false; if (variable.DataType.IsFuncType()) { int structType = variable.StructType; if (metaData.FuncTypeIndex != -1) { structType = metaData.FuncTypeIndex; } var functionType = ainFile.GetFuncType(structType); if (functionType != null) { EnumerationTypeComboBox.Text = functionType.ToString(); } } else //it's a delegate { int structType = variable.StructType; if (metaData.FuncTypeIndex != -1) { structType = metaData.FuncTypeIndex; } var delegateType = ainFile.Delegates.GetOrNull(structType); if (delegateType != null) { EnumerationTypeComboBox.Text = delegateType.ToString(); } } } else { EnumerationTypeComboBox.Enabled = false; EditEnumerationTypeButton.Enabled = false; spreadEnumerationTypeButton.Enabled = false; } //get description DescriptionTextBox.Text = metaData.Description ?? ""; }