private void AddAttributeTextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == Key.Return) { var attr = _view.AddAttributeTextBox.Text; attr = attr.ToLower(); attr = attr.Trim(); // See if we can find it in the nice names list. var found = NiceAttributeNames.FirstOrDefault(x => x.Value != null ? (x.Value.ToLower() == attr) : false); if (found.Key != null) { attr = found.Key; } else { // See if the thing they typed in is an imc attribute nice name. var ImcNiceNameRegex = new Regex("(.+) (?:variant|imc) ([a-j])$"); var match = ImcNiceNameRegex.Match(attr.ToLower()); if (match.Success) { var niceSlotName = match.Groups[1].Value; var letter = match.Groups[2].Value; found = NiceImcAttributeNames.FirstOrDefault(x => x.Value != null ? (x.Value.ToLower() == niceSlotName) : false); if (found.Key != null) { var rawSlotName = found.Key; attr = "atr_" + rawSlotName + "_" + letter; } } } var validator = new Regex("[^a-z_]"); attr = validator.Replace(attr, ""); if (attr == "") { return; } _view.AddAttributeBox.Focus(); var p = GetPart(); if (!p.Attributes.Contains(attr)) { p.Attributes.Add(attr); _view.AttributesSource.Add(new KeyValuePair <string, string>(attr, GetNiceAttributeName(attr))); } ResetAvailableAttributesList(); } }
// Gets the nice, human readable name for an attribute. private string GetNiceAttributeName(string attribute) { var niceName = NiceAttributeNames.ContainsKey(attribute) && NiceAttributeNames[attribute] != null ? NiceAttributeNames[attribute] : UnknownText; if (niceName == UnknownText) { var imcMatch = ImcAttributeRegex.Match(attribute); if (imcMatch.Success) { var slotPrefix = imcMatch.Groups[1].Value; var letter = imcMatch.Groups[2].Value; var niceImcName = NiceImcAttributeNames.ContainsKey(slotPrefix) && NiceImcAttributeNames[slotPrefix] != null ? NiceImcAttributeNames[slotPrefix] : UnknownText; niceName = niceImcName + " Variant " + letter; } } var fullNiceName = niceName + " (" + attribute + ")"; return(fullNiceName); }