예제 #1
0
        void LoadLanguages()
        {
            LockUpdate(true);
            lbFrom.BeginUpdate();
            lbFrom.Items.Clear();
            lbTo.Items.Clear();

            LanguageCollection fromLangs = new LanguageCollection();
            int index;

            foreach (LanguagePair lp in languages)
            {
                index = fromLangs.BinarySearch(lp.From);
                if (index < 0)
                {
                    fromLangs.Insert(~index, lp.From);
                }
            }


            string val = "";

            if (fromLangs.Count > 1)
            {
                val = "+" + LangPack.TranslateLanguage(Language.Any);
                lbFrom.Items.Add(new LanguageDataContainer(Language.Any, val));
            }

            foreach (Language l in fromLangs)
            {
                val = LangPack.TranslateLanguage(l);
                if (l == Language.Autodetect)
                {
                    val = "÷" + val;
                }
                lbFrom.Items.Add(new LanguageDataContainer(l, val));
            }

            lbFrom.EndUpdate();

            if (lbFrom.Items.Count > 0 && !profileChanging)
            {
                lbFrom.SelectedIndex = 0;
            }
            LockUpdate(false);
        }
예제 #2
0
        void LbFromSelectedIndexChanged(object sender, EventArgs e)
        {
            LockUpdate(true);
            if (lbFrom.SelectedIndex == -1)
            {
                return;
            }

            Language fromLanguage            = ((LanguageDataContainer)lbFrom.SelectedItem).Language;
            LanguageDataContainer toLanguage = null;

            if (lbTo.SelectedItem != null)
            {
                toLanguage = ((LanguageDataContainer)lbTo.SelectedItem);
            }

            lbTo.BeginUpdate();

            lbTo.Items.Clear();

            LanguageCollection toLangs = new LanguageCollection();
            int index;

            foreach (LanguagePair lp in languages)
            {
                if ((lp.From == fromLanguage || fromLanguage == Language.Any))
                {
                    index = toLangs.BinarySearch(lp.To);
                    if (index < 0)
                    {
                        toLangs.Insert(~index, lp.To);
                    }
                }
            }

            string val = "";

            if (toLangs.Count > 1)
            {
                val = "+" + LangPack.TranslateLanguage(Language.Any);
                lbTo.Items.Add(new LanguageDataContainer(Language.Any, val));
            }

            foreach (Language l in toLangs)
            {
                val = LangPack.TranslateLanguage(l);
                lbTo.Items.Add(new LanguageDataContainer(l, val));
            }
            lbTo.EndUpdate();

            string caption = LangPack.TranslateLanguage(fromLanguage);

            lFrom.Text = caption;

            int idx = -1;

            if (toLanguage != null)
            {
                idx = lbTo.Items.IndexOf(toLanguage);
            }

            if (idx == -1)
            {
                idx = 0;
            }
            lbTo.SelectedIndex = idx;
            LockUpdate(false);
        }