private static void AddExistingWssToContextMenu(ContextMenuStrip cmnuAddWs, IEnumerable<IWritingSystem> wssToAdd, ListBox listToAddExistingTo, EventHandler clickHandlerExistingWs) { bool fAddDivider = cmnuAddWs.Items.Count > 0; IEnumerable<IWritingSystem> q = from ws in wssToAdd where !listToAddExistingTo.Items.Cast<IWritingSystem>().Contains(ws, new WsIdEqualityComparer()) orderby ws.DisplayLabel select ws; foreach (IWritingSystem ws in q) { if (fAddDivider) { cmnuAddWs.Items.Add(new ToolStripSeparator()); fAddDivider = false; } var mnu = new WsMenuItem(ws, listToAddExistingTo, clickHandlerExistingWs); cmnuAddWs.Items.Add(mnu); } }
private static void AddExistingWssToContextMenu(ContextMenuStrip cmnuAddWs, Set<NamedWritingSystem> wssToAdd, ListBox listToAddExistingTo, EventHandler clickHandlerExistingWs) { List<NamedWritingSystem> al = new List<NamedWritingSystem>(wssToAdd.ToArray()); al.Sort(); bool fAddDivider = cmnuAddWs.Items.Count > 0; foreach (NamedWritingSystem namedWs in al) { // Make sure we only add language names (actually ICULocales in case any // language names happen to be identical) that aren't already in the list box. bool fFound = false; for (int iws = 0; iws < listToAddExistingTo.Items.Count; ++iws) { object item = listToAddExistingTo.Items[iws]; if (item is LgWritingSystem) { LgWritingSystem lws = (LgWritingSystem)item; if (lws.ICULocale == namedWs.IcuLocale) { fFound = true; break; } } else { // just compare the full names. if (item.ToString() == namedWs.ToString()) { fFound = true; break; } } } if (!fFound) { if (fAddDivider) { cmnuAddWs.Items.Add(new ToolStripSeparator()); fAddDivider = false; } WsMenuItem mnu = new WsMenuItem(namedWs, listToAddExistingTo, clickHandlerExistingWs); cmnuAddWs.Items.Add(mnu); } } }