private void okButton_Click(object sender, EventArgs e) { bool checkNameCollision = editingMode == LabelEditMode.Add ? true : !nameBox.Text.Equals(editedLabel.Name, StringComparison.Ordinal); int off = -1; int len = 0; Symbol sym = new Symbol() { Name = nameBox.Text }; if (!Utility.IsWord(nameBox.Text)) { Error.ShowErrorMessage(ErrorMessage.Label_InvalidName); } else if (checkNameCollision && labelContainer.IsSymbolDefined(sym)) { Error.ShowErrorMessage(ErrorMessage.Label_NameAlreadyDefined); } else if (!Utility.OffsetStringToInt(offsetBox.Text, out off)) { Error.ShowErrorMessage(ErrorMessage.Label_InvalidOffset); } else if (!Int32.TryParse(lengthBox.Text, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out len) || len <= 0) { Error.ShowErrorMessage(ErrorMessage.Label_InvalidLength); } else { TemplateBuilder tb = new TemplateBuilder(); string input = dataTemplateBox.Text; bool success = false; CompError error = new CompError(); var printTemplate = tb.ValidateTemplate(input, ref error, out success); if (!success) { Error.ShowErrorMessage(error); } else { if (editingMode == LabelEditMode.Edit) { labelContainer.RemoveDataLabel(editedLabel); } editedLabel = new DataLabel(off, len, nameBox.Text, printTemplate, commentBox.Text, (DataSectionType)dataTypeBox.SelectedIndex); labelContainer.AddDataLabel(editedLabel); this.DialogResult = System.Windows.Forms.DialogResult.OK; } } }
private void removeDataLabelMenuItem_Click(object sender, EventArgs e) { labelContainer.RemoveDataLabel((DataLabel)dataLabelBox.SelectedItem); UpdateDataBoxView(); }