void LbHistorySelectedIndexChanged(object sender, EventArgs e) { if (lbHistory.SelectedIndex == -1) { return; } LanguageContainerPair currSel = new LanguageContainerPair((LanguageDataContainer)lbFrom.SelectedItem, (LanguageDataContainer)lbTo.SelectedItem); LanguageContainerPair currHistorySel = (LanguageContainerPair)lbHistory.SelectedItem; if (currSel != currHistorySel) { try { Selection = new LanguagePair(currHistorySel.From.Language, currHistorySel.To.Language); } catch { lbHistory.Items.RemoveAt(lbHistory.SelectedIndex); history.Remove(new LanguagePair(currHistorySel.From.Language, currHistorySel.To.Language)); try { Selection = new LanguagePair(Language.Any, Language.Any); } catch {} } } }
public void AddSelectionToHistory() { if (lbFrom.SelectedIndex == -1 || lbTo.SelectedIndex == -1) { return; } LanguageContainerPair currSel = new LanguageContainerPair((LanguageDataContainer)lbFrom.SelectedItem, (LanguageDataContainer)lbTo.SelectedItem); int idx = lbHistory.Items.IndexOf(currSel); if (idx != -1) { lbHistory.Items.RemoveAt(idx); } lbHistory.Items.Insert(0, currSel); lbHistory.SelectedIndex = 0; LanguagePair lp = new LanguagePair(currSel.From.Language, currSel.To.Language); idx = history.IndexOf(lp); if (idx != -1) { history.RemoveAt(idx); } history.Insert(0, lp); }
public override bool Equals(Object obj) { if (From == null) { return(false); } if (To == null) { return(false); } LanguageContainerPair arg = obj as LanguageContainerPair; if (arg == null) { return(false); } if (arg.From == null) { return(false); } if (arg.To == null) { return(false); } return(From.Equals(arg.From) && To.Equals(arg.To)); }
public void LoadHistory() { //int idx = lbHistory.SelectedIndex; lbHistory.BeginUpdate(); lbHistory.Items.Clear(); foreach (LanguagePair lp in history) { LanguageContainerPair lpc = new LanguageContainerPair( new LanguageDataContainer(lp.From, LangPack.TranslateLanguage(lp.From)), new LanguageDataContainer(lp.To, LangPack.TranslateLanguage(lp.To)) ); lbHistory.Items.Add(lpc); } lbHistory.EndUpdate(); if (history.Count > 0) { lbHistory.SelectedIndex = 0; } }
void LbHistorySelectedIndexChanged(object sender, EventArgs e) { if(lbHistory.SelectedIndex == -1) return; LanguageContainerPair currSel = new LanguageContainerPair((LanguageDataContainer)lbFrom.SelectedItem, (LanguageDataContainer)lbTo.SelectedItem); LanguageContainerPair currHistorySel = (LanguageContainerPair)lbHistory.SelectedItem; if(currSel != currHistorySel) { try { Selection = new LanguagePair(currHistorySel.From.Language, currHistorySel.To.Language); } catch { lbHistory.Items.RemoveAt(lbHistory.SelectedIndex); history.Remove(new LanguagePair(currHistorySel.From.Language, currHistorySel.To.Language)); try { Selection = new LanguagePair(Language.Any, Language.Any); } catch{} } } }
public void LoadHistory() { //int idx = lbHistory.SelectedIndex; lbHistory.BeginUpdate(); lbHistory.Items.Clear(); foreach(LanguagePair lp in history) { LanguageContainerPair lpc = new LanguageContainerPair( new LanguageDataContainer(lp.From, LangPack.TranslateLanguage(lp.From)), new LanguageDataContainer(lp.To, LangPack.TranslateLanguage(lp.To)) ); lbHistory.Items.Add(lpc); } lbHistory.EndUpdate(); if(history.Count > 0) lbHistory.SelectedIndex = 0; }
public void AddSelectionToHistory() { if(lbFrom.SelectedIndex == -1 || lbTo.SelectedIndex == -1) return; LanguageContainerPair currSel = new LanguageContainerPair((LanguageDataContainer)lbFrom.SelectedItem, (LanguageDataContainer)lbTo.SelectedItem); int idx = lbHistory.Items.IndexOf(currSel); if(idx != -1) { lbHistory.Items.RemoveAt(idx); } lbHistory.Items.Insert(0, currSel); lbHistory.SelectedIndex = 0; LanguagePair lp = new LanguagePair(currSel.From.Language, currSel.To.Language); idx = history.IndexOf(lp); if(idx != -1) { history.RemoveAt(idx); } history.Insert(0, lp); }