void BOkClick(object sender, EventArgs e) { LanguageCollection checkedFromLanguages = new LanguageCollection(); LanguageCollection checkedToLanguages = new LanguageCollection(); foreach (LanguageDataContainer ldc in lbFrom.CheckedItems) { if (ldc.Language != Language.Any) { checkedFromLanguages.Add(ldc.Language); } } foreach (LanguageDataContainer ldc in lbTo.CheckedItems) { if (ldc.Language != Language.Any) { checkedToLanguages.Add(ldc.Language); } } if (checkedFromLanguages.Count == 0) { MessageBox.Show(FindForm(), TranslateString("Please select at least one source language"), Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Warning); DialogResult = DialogResult.None; return; } if (checkedToLanguages.Count == 0) { MessageBox.Show(FindForm(), TranslateString("Please select at least one target language"), Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Warning); DialogResult = DialogResult.None; return; } profile.DisabledSourceLanguages.Clear(); foreach (LanguageDataContainer ldc in lbFrom.Items) { if (ldc.Language != Language.Any && !checkedFromLanguages.Contains(ldc.Language)) { profile.DisabledSourceLanguages.Add(ldc.Language); } } profile.DisabledTargetLanguages.Clear(); foreach (LanguageDataContainer ldc in lbTo.Items) { if (ldc.Language != Language.Any && !checkedToLanguages.Contains(ldc.Language)) { profile.DisabledTargetLanguages.Add(ldc.Language); } } }
void LoadLanguages() { SuspendLayout(); lbFrom.Items.Clear(); lbTo.Items.Clear(); LanguageCollection fromLangs = new LanguageCollection(); LanguageCollection toLangs = new LanguageCollection(); foreach (LanguagePair lp in Manager.LanguagePairServiceItems.Keys) { if (!fromLangs.Contains(lp.From)) { fromLangs.Add(lp.From); } if (!toLangs.Contains(lp.To)) { toLangs.Add(lp.To); } } fromLangs.Sort(); string val = ""; int idx; val = "+" + TranslateString("Toggle all"); lbFrom.Items.Add(new LanguageDataContainer(Language.Any, val)); foreach (Language l in fromLangs) { val = LangPack.TranslateLanguage(l); idx = lbFrom.Items.Add(new LanguageDataContainer(l, val)); lbFrom.SetItemChecked(idx, !profile.DisabledSourceLanguages.Contains(l)); } lbFrom.SetItemChecked(0, lbFrom.CheckedItems.Count == fromLangs.Count); if (lbFrom.Items.Count > 0) { lbFrom.SelectedIndex = 0; } toLangs.Sort(); val = "+" + TranslateString("Toggle all"); lbTo.Items.Add(new LanguageDataContainer(Language.Any, val)); foreach (Language l in toLangs) { val = LangPack.TranslateLanguage(l); idx = lbTo.Items.Add(new LanguageDataContainer(l, val)); lbTo.SetItemChecked(idx, !profile.DisabledTargetLanguages.Contains(l)); } lbTo.SetItemChecked(0, lbTo.CheckedItems.Count == toLangs.Count); if (lbTo.Items.Count > 0) { lbTo.SelectedIndex = 0; } ResumeLayout(true); }