Exemplo n.º 1
0
        public void Invert()
        {
            LanguageDataContainer fromLanguage = (LanguageDataContainer)lbFrom.SelectedItem;

            if (fromLanguage == null)
            {
                return;
            }

            if (lbTo.SelectedItem == null)
            {
                return;
            }

            int idx = lbFrom.Items.IndexOf(lbTo.SelectedItem);

            if (idx == -1)
            {
                return;
            }
            lbFrom.SelectedIndex = idx;

            idx = lbTo.Items.IndexOf(fromLanguage);
            if (idx == -1)
            {
                return;
            }
            lbTo.SelectedIndex = idx;
        }
Exemplo n.º 2
0
        void CbFromSelectedIndexChanged(object sender, EventArgs e)
        {
            if (!initialized)
            {
                return;
            }

            bool generatedName = tbName.Text == GetNewProfileName();

            LanguageDataContainer ld = cbFrom.SelectedItem as LanguageDataContainer;

            profile.TranslationDirection.From = ld.Language;

            ld = cbTo.SelectedItem as LanguageDataContainer;
            profile.TranslationDirection.To = ld.Language;

            SubjectContainer sc = cbSubject.SelectedItem as SubjectContainer;

            profile.Subject = sc.Subject;

            if (generatedName)
            {
                tbName.Text = GetNewProfileName();
            }
        }
        void CbToSelectedIndexChanged(object sender, EventArgs e)
        {
            if (ignoreLanguageChange)
            {
                return;
            }

            if (lvProfiles.SelectedItems.Count != 1)
            {
                return;
            }

            ListViewItem         lvi = lvProfiles.SelectedItems[0];
            UserTranslateProfile pf  = lvi.Tag as UserTranslateProfile;

            if (pf == null)
            {
                return;
            }

            LanguageDataContainer ld = cbTo.SelectedItem as LanguageDataContainer;

            pf.TranslationDirection.To = ld.Language;

            lvi.SubItems[1].Text = (LangPack.TranslateLanguage(pf.TranslationDirection.From) +
                                    " -> " +
                                    LangPack.TranslateLanguage(pf.TranslationDirection.To)
                                    );
        }
        void InitUserProfileControls()
        {
            cbFrom.Items.Clear();
            cbTo.Items.Clear();

            for (int i = 0; i < (int)Language.Last; i++)
            {
                LanguageDataContainer ld = new LanguageDataContainer((Language)i, LangPack.TranslateLanguage((Language)i));
                cbFrom.Items.Add(ld);
                cbTo.Items.Add(ld);
            }

            cbSubject.Items.Clear();
            foreach (string subject in Manager.Subjects)
            {
                SubjectContainer sc = new SubjectContainer(subject, LangPack.TranslateString(subject));
                cbSubject.Items.Add(sc);
            }

            SubjectContainer sc1 = new SubjectContainer(SubjectConstants.Any, LangPack.TranslateString(SubjectConstants.Any));

            cbSubject.Items.Add(sc1);

            changed = false;
            LvProfilesSelectedIndexChanged(lvProfiles, new EventArgs());
        }
Exemplo n.º 5
0
        void SbInvertClick(object sender, EventArgs e)
        {
            if (!initialized)
            {
                return;
            }

            LanguageDataContainer ldFrom = cbFrom.SelectedItem as LanguageDataContainer;
            LanguageDataContainer ldTo   = cbTo.SelectedItem as LanguageDataContainer;

            cbFrom.SelectedItem = ldTo;
            cbTo.SelectedItem   = ldFrom;
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 public LanguageContainerPair(LanguageDataContainer from, LanguageDataContainer to)
 {
     From = from;
     To   = to;
 }
Exemplo n.º 8
0
        public SetProfileNameForm(UserTranslateProfile profile, TranslateProfilesCollection profiles)
        {
            InitializeComponent();
            RegisterLanguageEvent(OnLanguageChanged);

            this.profile  = profile;
            this.profiles = profiles;

            cbFrom.Items.Clear();
            cbTo.Items.Clear();

            for (int i = 0; i < (int)Language.Last; i++)
            {
                LanguageDataContainer ld = new LanguageDataContainer((Language)i, LangPack.TranslateLanguage((Language)i));
                cbFrom.Items.Add(ld);
                cbTo.Items.Add(ld);
            }

            cbFrom.SelectedIndex = 0;
            cbTo.SelectedIndex   = 0;


            foreach (string subject in Manager.Subjects)
            {
                SubjectContainer sc = new SubjectContainer(subject, LangPack.TranslateString(subject));
                cbSubject.Items.Add(sc);
            }

            SubjectContainer sc1 = new SubjectContainer(SubjectConstants.Any, LangPack.TranslateString(SubjectConstants.Any));

            cbSubject.Items.Add(sc1);

            cbSubject.SelectedIndex = 0;

            for (int i = 0; i < cbFrom.Items.Count; i++)
            {
                LanguageDataContainer ld = cbFrom.Items[i] as LanguageDataContainer;

                if (ld.Language == profile.TranslationDirection.From)
                {
                    cbFrom.SelectedItem = ld;
                }

                if (ld.Language == profile.TranslationDirection.To)
                {
                    cbTo.SelectedItem = ld;
                }
            }

            for (int i = 0; i < cbSubject.Items.Count; i++)
            {
                SubjectContainer sc = cbSubject.Items[i] as SubjectContainer;
                if (profile.Subject == sc.Subject)
                {
                    cbSubject.SelectedItem = sc;
                    break;
                }
            }

            if (!string.IsNullOrEmpty(profile.Name))
            {
                tbName.Text = profile.Name;
            }
            else
            {
                tbName.Text = GetNewProfileName();
            }

            initialized = true;
        }
Exemplo n.º 9
0
        public CustomProfileServicesForm(UserTranslateProfile profile)
        {
            InitializeComponent();

            RegisterLanguageEvent(OnLanguageChanged);

            this.profile = profile;
            ServiceItemsDataCollection services = new ServiceItemsDataCollection();

            foreach (ServiceItemData sid in profile.Services)
            {
                services.Add(sid);
            }
            lvCurrent.Services = services;

            cbFrom.Items.Clear();
            cbTo.Items.Clear();

            for (int i = 0; i < (int)Language.Last; i++)
            {
                LanguageDataContainer ld = new LanguageDataContainer((Language)i, LangPack.TranslateLanguage((Language)i));
                cbFrom.Items.Add(ld);
                cbTo.Items.Add(ld);
            }

            cbFrom.SelectedIndex = 0;
            cbTo.SelectedIndex   = 0;

            //cbSubject
            foreach (string subject in Manager.Subjects)
            {
                SubjectContainer sc = new SubjectContainer(subject, LangPack.TranslateString(subject));
                cbSubject.Items.Add(sc);
            }

            SubjectContainer sc1 = new SubjectContainer(SubjectConstants.Any, "+" + LangPack.TranslateString(SubjectConstants.Any));

            cbSubject.Items.Add(sc1);

            cbSubject.SelectedIndex = 0;

            for (int i = 0; i < cbFrom.Items.Count; i++)
            {
                LanguageDataContainer ld = cbFrom.Items[i] as LanguageDataContainer;

                if (ld.Language == profile.TranslationDirection.From)
                {
                    cbFrom.SelectedItem = ld;
                }

                if (ld.Language == profile.TranslationDirection.To)
                {
                    cbTo.SelectedItem = ld;
                }
            }

            for (int i = 0; i < cbSubject.Items.Count; i++)
            {
                SubjectContainer sc = cbSubject.Items[i] as SubjectContainer;
                if (profile.Subject == sc.Subject)
                {
                    cbSubject.SelectedItem = sc;
                    break;
                }
            }

            serviceStatusSource.Visible  = false;
            serviceStatusCurrent.Visible = false;

            initialized = true;
            CbFromSelectedIndexChanged(null, new EventArgs());
        }
Exemplo n.º 10
0
        void LvProfilesSelectedIndexChanged(object sender, EventArgs e)
        {
            aEditServices.Enabled = false;
            if (lvProfiles.SelectedItems.Count == 0)
            {
                return;
            }
            TranslateProfile     pf  = lvProfiles.SelectedItems[0].Tag as TranslateProfile;
            UserTranslateProfile upf = pf as UserTranslateProfile;

            if (pf == defaultProfile)
            {
                if (!tcOptions.TabPages.Contains(tpDefaultOptions))
                {
                    tcOptions.TabPages.Add(tpDefaultOptions);
                }

                tcOptions.TabPages.Remove(tpOptions);
                tcOptions.TabPages.Remove(tpServices);
                tcOptions.TabPages.Remove(tpLanguageSelector);
            }
            else if (upf != null)
            {
                if (!tcOptions.TabPages.Contains(tpServices))
                {
                    tcOptions.TabPages.Add(tpServices);
                }

                if (!tcOptions.TabPages.Contains(tpOptions))
                {
                    tcOptions.TabPages.Add(tpOptions);
                }

                if (!tcOptions.TabPages.Contains(tpLanguageSelector))
                {
                    tcOptions.TabPages.Add(tpLanguageSelector);
                }

                tcOptions.TabPages.Remove(tpDefaultOptions);
                lProfileName.Text   = pf.Name;
                lvServices.Services = upf.Services;
            }

            aEditServices.Enabled = pf != defaultProfile;

            if (upf != null)
            {
                ignoreLanguageChange = true;
                for (int i = 0; i < cbFrom.Items.Count; i++)
                {
                    LanguageDataContainer ld = cbFrom.Items[i] as LanguageDataContainer;

                    if (ld.Language == upf.TranslationDirection.From)
                    {
                        cbFrom.SelectedItem = ld;
                    }

                    if (ld.Language == upf.TranslationDirection.To)
                    {
                        cbTo.SelectedItem = ld;
                    }
                }

                for (int i = 0; i < cbSubject.Items.Count; i++)
                {
                    SubjectContainer sc = cbSubject.Items[i] as SubjectContainer;
                    if (upf.Subject == sc.Subject)
                    {
                        cbSubject.SelectedItem = sc;
                        break;
                    }
                }

                cbShowServices.Checked  = upf.ShowServices;
                cbShowSubjects.Checked  = upf.ShowSubjects;
                cbShowLanguages.Checked = upf.ShowLanguages;

                ignoreLanguageChange = false;
            }
        }