private void addNewNameToolStripMenuItem_Click(object sender, EventArgs e) { string sel = lastSelection; if (!string.IsNullOrWhiteSpace(sel)) { ParseResult pr = lastSelectedParseResult; EdictMatch oldName = Edict.instance.findName(sel); string oldSense = ""; string oldNameType = null; if (oldName != null) { EdictEntry oldNameEntry = oldName.findAnyName(); if (oldNameEntry != null) { if (oldNameEntry.sense.Count > 0 && oldNameEntry.sense[0].glossary.Count > 0) { oldSense = oldNameEntry.sense[0].glossary[0]; } oldNameType = oldNameEntry.nameType; } } if (oldSense == "" && sel.All((c) => TextUtils.isKana(c))) { if (Settings.app.okuriganaType == OkuriganaType.RUSSIAN) { oldSense = TextUtils.kanaToCyrillic(sel); } else { oldSense = TextUtils.kanaToRomaji(sel); } oldSense = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(oldSense); } UserNameForm userNameForm = new UserNameForm(); this.hideHint(); this.SuspendTopMost(() => { moveBackgroundForm(); if (userNameForm.Open(sel, oldSense, oldNameType)) { string key = userNameForm.getKey(); string sense = userNameForm.getSense(); string nameType = userNameForm.getNameType(); if (sense != "") { Settings.session.addUserName(key, sense, nameType); } else { Settings.session.removeUserName(key); } if (pr != null) { TranslationService.instance.updateId(pr.id, pr.asText(), null); } } }); moveBackgroundForm(); } }
public void addUserName(string key, string sense, string nameType) { lock (this) { Settings.app.removeBannedWord(key); EdictMatch match = new EdictMatch(key); EdictEntryBuilder eb = new EdictEntryBuilder(); eb.addKanji(new DictionaryKeyBuilder(key)); eb.addKana(new DictionaryKeyBuilder(sense)); DictionarySense ds = new DictionarySense(); ds.addGloss(null, sense); eb.addSense(ds); if (nameType != "notname") { eb.addPOS("name"); } else { eb.addPOS("n"); } eb.nameType = nameType; match.addEntry(new RatedEntry { entry = eb.build(), rate = 5.0F }); userNames[key] = match; this.isDirty = true; } }