/// ------------------------------------------------------------------------------------ /// <summary> /// Get a value determining if the new writing systems should be created as a side-effect /// of a paste operation. /// </summary> /// <param name="wsf">writing system factory containing the new writing systems</param> /// <param name="destWs">The destination writing system (writing system used at the /// selection).</param> /// <returns> /// an indication of how the paste should be handled. /// </returns> /// ------------------------------------------------------------------------------------ public override PasteStatus DeterminePasteWs(ILgWritingSystemFactory wsf, out int destWs) { // Determine writing system at selection (destination for paste). destWs = 0; if (CurrentSelection != null) { destWs = CurrentSelection.GetWritingSystem(SelectionHelper.SelLimitType.Anchor); } if (destWs <= 0) { destWs = Cache.DefaultAnalWs; // set to default analysis, if 0. } int cws = wsf.NumberOfWs; using (ArrayPtr ptr = MarshalEx.ArrayToNative <int>(cws)) { wsf.GetWritingSystems(ptr, cws); int[] vws = MarshalEx.NativeToArray <int>(ptr, cws); for (int iws = 0; iws < cws; iws++) { if (vws[iws] != 0 && wsf.get_EngineOrNull(vws[iws]) == null) { // found corrupt writing system--don't want to use any ws in this pasted string return(PasteStatus.UseDestWs); } } } return(PasteStatus.PreserveWs); }
public void WritingSystemsLists() { List <IWritingSystem> list = new List <IWritingSystem>(); foreach (var x in Cache.LangProject.AllWritingSystems) { list.Add(x); } Assert.AreEqual(2, list.Count); ILgWritingSystemFactory factWs = Cache.ServiceLocator.GetInstance <ILgWritingSystemFactory>(); Assert.LessOrEqual(list.Count, factWs.NumberOfWs, "factory list is at least as large as AllWritingSystems"); Set <int> set = new Set <int>(); using (ArrayPtr rgwsT = MarshalEx.ArrayToNative <int>(factWs.NumberOfWs)) { factWs.GetWritingSystems(rgwsT, factWs.NumberOfWs); set.AddRange(MarshalEx.NativeToArray <int>(rgwsT, factWs.NumberOfWs)); } int wsEn = factWs.GetWsFromStr("en"); Assert.AreNotEqual(0, wsEn, "factory should contain English WS"); int wsFr = factWs.GetWsFromStr("fr"); Assert.AreNotEqual(0, wsFr, "factory should contain French WS"); IWritingSystem eng = null; IWritingSystem frn = null; foreach (var x in list) { Assert.IsTrue(set.Contains(x.Handle), "AllWritingSystems should be a subset of the factory list"); if (x.Handle == wsEn) { eng = x; } else if (x.Handle == wsFr) { frn = x; } } Assert.IsNotNull(eng, "AllWritingSystems should contain English"); Assert.AreEqual("English", factWs.get_EngineOrNull(wsEn).LanguageName); Assert.AreEqual("English", eng.LanguageName); Assert.IsNotNull(frn, "AllWritingSystems should contain French"); Assert.AreEqual("French", frn.LanguageName); Assert.AreEqual("French", factWs.get_Engine("fr").LanguageName); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Return a hash table from converter name to writing system name for converters /// that are currently in use by some writing system. (This is a needed argument /// for initializeing an AddCnvtrDlg, so that it can avoid deleting converters that /// are currently in use by writing systems.) /// </summary> /// ------------------------------------------------------------------------------------ public static Set<string> ConvertersInUse(ILgWritingSystemFactory wsf) { Set<string> wsInUse = new Set<string>(); // Make a hash of the writing systems currently in use. IWritingSystem currentWS; int cws = wsf.NumberOfWs; using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int))) { wsf.GetWritingSystems(ptr, cws); int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int)); for (int iws = 0; iws < cws; iws++) { if (vws[iws] == 0) continue; currentWS = wsf.get_EngineOrNull(vws[iws]); if (currentWS == null) continue; string legMapping = currentWS.LegacyMapping; if (legMapping == null) continue; wsInUse.Add(legMapping); } } return wsInUse; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get a value determining if the new writing systems should be created as a side-effect /// of a paste operation. /// </summary> /// <param name="wsf">writing system factory containing the new writing systems</param> /// <param name="destWs">The destination writing system (writing system used at the /// selection).</param> /// <returns> /// an indication of how the paste should be handled. /// </returns> /// ------------------------------------------------------------------------------------ public override PasteStatus DeterminePasteWs(ILgWritingSystemFactory wsf, out int destWs) { // Determine writing system at selection (destination for paste). destWs = 0; if (CurrentSelection != null) destWs = CurrentSelection.GetWritingSystem(SelectionHelper.SelLimitType.Anchor); if (destWs <= 0) destWs = Cache.DefaultAnalWs; // set to default analysis, if 0. // Get list of writing system names. List<string> wsMissingNames = new List<string>(); int cws = wsf.NumberOfWs; using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int))) { wsf.GetWritingSystems(ptr, cws); int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int)); IWritingSystem ws; for (int iws = 0; iws < cws; iws++) { if (vws[iws] == 0) continue; ws = wsf.get_EngineOrNull(vws[iws]); if (ws == null) { // found corrupt writing system--don't want to use any ws in this pasted string return PasteStatus.UseDestWs; } if (Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(ws.IcuLocale) == 0) wsMissingNames.Add(ws.LanguageName); // writing system not found in ws factory } } PasteStatus pasteStatus; if (wsMissingNames.Count > 0) { if (!Options.ShowPasteWsChoice) return PasteStatus.UseDestWs; // Ask user whether to use destination writing system or copy original writing systems. LgWritingSystem lgws = new LgWritingSystem(Cache, destWs); Debug.Assert(lgws != null); using (AddWsFromPastedTextDlg newWsDlg = new AddWsFromPastedTextDlg( m_cache.LangProject.Name.BestAnalysisAlternative.Text, lgws.Name.BestAnalysisAlternative.Text, wsMissingNames)) { newWsDlg.ShowDialog(Control.FindForm()); pasteStatus = newWsDlg.PasteStatus; } } else // no missing writing systems in TsString to paste pasteStatus = PasteStatus.PreserveWs; return pasteStatus; }
private void UpdateLanguageCodes() { if (m_sLastXmlFileName != m_LinguaLinksXmlFileName.Text) { m_sLastXmlFileName = m_LinguaLinksXmlFileName.Text; listViewMapping.Items.Clear(); btnImport.Enabled = false; // default to not enabled now that there are no items m_nextInput = m_LinguaLinksXmlFileName.Text; if (!File.Exists(m_nextInput)) { MessageBox.Show( String.Format(ITextStrings.ksLLFileNotFound, m_nextInput), ITextStrings.ksLLImport, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } StringUtils.InitIcuDataDir(); // used for normalizing strings to NFC m_startPhase = 1; string nameTest; if (m_nextInput.Length > 19) { nameTest = m_nextInput.Substring(m_nextInput.Length - 19, 19); if (nameTest == "\\LLPhase1Output.xml") { m_startPhase = 2; } else if (nameTest == "\\LLPhase2Output.xml") { m_startPhase = 3; } else if (nameTest == "\\LLPhase3Output.xml") { m_startPhase = 4; } } if (m_startPhase == 1) { StreamReader streamReader = File.OpenText(m_nextInput); String input; bool inWritingSystem = false; bool inIcuLocale24 = false; bool inName24 = false; bool lineDone = false; bool formatOkay = false; int pos, pos1, pos2, pos3; string wsLLCode = ""; string wsName = ""; Dictionary <string, WsInfo> wsInfo = new Dictionary <string, WsInfo>(); // Dictioanry of wsInfo //getting name for a writing system given the ICU code. ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor; int wsUser = wsf.UserWs; int wsVern = m_cache.DefaultVernWs; IWritingSystem ws = wsf.get_EngineOrNull(wsVern); // getting list of writing systems to eventually populate a list box int cws = wsf.NumberOfWs; using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int))) { wsf.GetWritingSystems(ptr, cws); int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int)); for (int iws = 0; iws < cws; iws++) { if (vws[iws] == 0) { continue; } ws = wsf.get_EngineOrNull(vws[iws]); if (ws == null) { continue; } string name = ws.get_UiName(wsUser); string icuLocal = ws.IcuLocale; string mapName = ws.LegacyMapping; if ((mapName == null) || (mapName == "")) { mapName = "Windows1252<>Unicode"; // REVIEW: SHOULD THIS NAME BE LOCALIZED? } WsInfo wsi = new WsInfo(vws[iws], name, icuLocal, mapName); wsInfo.Add(wsi.KEY, wsi); } } while ((input = streamReader.ReadLine()) != null) { lineDone = false; while (!lineDone) { if (!inWritingSystem) { pos = input.IndexOf("<LgWritingSystem"); if (pos >= 0) { inWritingSystem = true; wsLLCode = ""; wsName = ""; if (input.Length >= pos + 21) { input = input.Substring(pos + 21, input.Length - pos - 21); } else { input = input.Substring(pos + 16); } } else { lineDone = true; } } if (inWritingSystem && !inIcuLocale24 && !inName24) { pos1 = input.IndexOf("</LgWritingSystem>"); pos2 = input.IndexOf("<ICULocale24>"); pos3 = input.IndexOf("<Name24>"); if (pos1 < 0 && pos2 < 0 && pos3 < 0) { lineDone = true; } else if (pos1 >= 0 && (pos2 < 0 || pos2 > pos1) && (pos3 < 0 || pos3 > pos1)) { input = input.Substring(pos1 + 18, input.Length - pos1 - 18); if (wsLLCode != "") { if (wsName == "") { wsName = "<" + wsLLCode + ">"; } string wsFWName = ""; string wsEC = ""; string wsFWCode = ""; foreach (KeyValuePair <string, WsInfo> kvp in wsInfo) { WsInfo wsi = kvp.Value; if (wsName == wsi.Name) { wsFWName = StringUtils.NormalizeToNFC(wsi.Name); wsEC = StringUtils.NormalizeToNFC(wsi.Map); wsFWCode = StringUtils.NormalizeToNFC(wsi.Locale); } } if (wsFWName == "") { foreach (KeyValuePair <string, WsInfo> kvp in wsInfo) { WsInfo wsi = kvp.Value; if (BaseName(wsName) == BaseName(wsi.Name)) { wsFWName = StringUtils.NormalizeToNFC(wsi.Name); wsEC = StringUtils.NormalizeToNFC(wsi.Map); wsFWCode = StringUtils.NormalizeToNFC(wsi.Locale); } } } ListViewItem lvItem = new ListViewItem(new string[] { StringUtils.NormalizeToNFC(wsName), wsFWName, wsEC, StringUtils.NormalizeToNFC(wsLLCode), wsFWCode }); lvItem.Tag = wsName; listViewMapping.Items.Add(lvItem); formatOkay = true; } inWritingSystem = false; } else if (pos2 >= 0 && (pos3 < 0 || pos3 > pos2)) { input = input.Substring(pos2 + 13, input.Length - pos2 - 13); inIcuLocale24 = true; } else { input = input.Substring(pos3 + 8, input.Length - pos3 - 8); inName24 = true; } } if (inIcuLocale24) { pos = input.IndexOf(">"); if (pos < 0) { lineDone = true; } else { input = input.Substring(pos + 1, input.Length - pos - 1); pos = input.IndexOf("<"); wsLLCode = input.Substring(0, pos); input = input.Substring(pos, input.Length - pos); inIcuLocale24 = false; } } if (inName24) { pos = input.IndexOf(">"); if (pos < 0) { lineDone = true; } else { input = input.Substring(pos + 1, input.Length - pos - 1); pos = input.IndexOf("<"); wsName = input.Substring(0, pos); input = input.Substring(pos, input.Length - pos); inName24 = false; } } } } streamReader.Close(); listViewMapping_SelectedIndexChanged(); CheckImportEnabled(); if (!formatOkay) { ShowFinishLabel(); // update the button before showing the msg box just in case... MessageBox.Show( String.Format(ITextStrings.ksInvalidLLFile, m_nextInput), ITextStrings.ksLLImport, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } } else { btnImport.Enabled = true; } ShowFinishLabel(); } }
/// <summary> /// get the writing systems we should consider as candidates to be selected whent the user makes an /// external choice of keyboard. overridden in root site to use only active ones. /// </summary> /// <param name="wsf"></param> /// <returns></returns> protected virtual int[] GetPossibleWritingSystemsToSelectByInputLanguage(ILgWritingSystemFactory wsf) { int cws = wsf.NumberOfWs; int[] vwsTemp = new int[0]; using (ArrayPtr ptr = MarshalEx.ArrayToNative<int>(cws)) { wsf.GetWritingSystems(ptr, cws); vwsTemp = MarshalEx.NativeToArray<int>(ptr, cws); } return vwsTemp; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get a value determining if the new writing systems should be created as a side-effect /// of a paste operation. /// </summary> /// <param name="wsf">writing system factory containing the new writing systems</param> /// <param name="destWs">The destination writing system (writing system used at the /// selection).</param> /// <returns> /// an indication of how the paste should be handled. /// </returns> /// ------------------------------------------------------------------------------------ public override PasteStatus DeterminePasteWs(ILgWritingSystemFactory wsf, out int destWs) { // Determine writing system at selection (destination for paste). destWs = 0; if (CurrentSelection != null) destWs = CurrentSelection.GetWritingSystem(SelectionHelper.SelLimitType.Anchor); if (destWs <= 0) destWs = Cache.DefaultAnalWs; // set to default analysis, if 0. int cws = wsf.NumberOfWs; using (ArrayPtr ptr = MarshalEx.ArrayToNative<int>(cws)) { wsf.GetWritingSystems(ptr, cws); int[] vws = MarshalEx.NativeToArray<int>(ptr, cws); for (int iws = 0; iws < cws; iws++) { if (vws[iws] != 0 && wsf.get_EngineOrNull(vws[iws]) == null) { // found corrupt writing system--don't want to use any ws in this pasted string return PasteStatus.UseDestWs; } } } return PasteStatus.PreserveWs; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get a value determining if the new writing systems should be created as a side-effect /// of a paste operation. /// </summary> /// <param name="wsf">writing system factory containing the new writing systems</param> /// <param name="destWs">The destination writing system (writing system used at the /// selection).</param> /// <returns> /// an indication of how the paste should be handled. /// </returns> /// ------------------------------------------------------------------------------------ public override PasteStatus DeterminePasteWs(ILgWritingSystemFactory wsf, out int destWs) { // Determine writing system at selection (destination for paste). destWs = 0; if (CurrentSelection != null) { destWs = CurrentSelection.GetWritingSystem(SelectionHelper.SelLimitType.Anchor); } if (destWs <= 0) { destWs = Cache.DefaultAnalWs; // set to default analysis, if 0. } // Get list of writing system names. List <string> wsMissingNames = new List <string>(); int cws = wsf.NumberOfWs; using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int))) { wsf.GetWritingSystems(ptr, cws); int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int)); IWritingSystem ws; for (int iws = 0; iws < cws; iws++) { if (vws[iws] == 0) { continue; } ws = wsf.get_EngineOrNull(vws[iws]); if (ws == null) { // found corrupt writing system--don't want to use any ws in this pasted string return(PasteStatus.UseDestWs); } if (Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(ws.IcuLocale) == 0) { wsMissingNames.Add(ws.LanguageName); // writing system not found in ws factory } } } PasteStatus pasteStatus; if (wsMissingNames.Count > 0) { if (!Options.ShowPasteWsChoice) { return(PasteStatus.UseDestWs); } // Ask user whether to use destination writing system or copy original writing systems. LgWritingSystem lgws = new LgWritingSystem(Cache, destWs); Debug.Assert(lgws != null); using (AddWsFromPastedTextDlg newWsDlg = new AddWsFromPastedTextDlg( m_cache.LangProject.Name.BestAnalysisAlternative.Text, lgws.Name.BestAnalysisAlternative.Text, wsMissingNames)) { newWsDlg.ShowDialog(Control.FindForm()); pasteStatus = newWsDlg.PasteStatus; } } else // no missing writing systems in TsString to paste { pasteStatus = PasteStatus.PreserveWs; } return(pasteStatus); }
private void LexImportWizardLanguage_Load(object sender, System.EventArgs e) { // (Bev) modify a few labels if (m_LinguaLinksImport) { this.Text = LexTextControls.ksSpecifyFwWs; lblComment.Text = LexTextControls.ksSpecifyFwWsDescription; lblLangDesc.Text = LexTextControls.ksLanguageDefinition; } else { if (m_AddUsage) { this.Text = LexTextControls.ksAddLangMapping; } else { this.Text = LexTextControls.ksModifyLangMapping; } } tbLangDesc.Text = m_LangDesc; //getting name for a writing system given the ICU code. ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor; int wsUser = wsf.UserWs; int wsVern = m_cache.DefaultVernWs; IWritingSystem ws = wsf.get_EngineOrNull(wsVern); m_wsiDefault = new WsInfo(wsVern, ws.get_UiName(wsVern), ws.IcuLocale, ws.LegacyMapping); // getting list of writing systems to populate a combo. int cws = wsf.NumberOfWs; using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int))) { wsf.GetWritingSystems(ptr, cws); int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int)); for (int iws = 0; iws < cws; iws++) { if (vws[iws] == 0) { continue; } ws = wsf.get_EngineOrNull(vws[iws]); if (ws == null) { continue; } string name = ws.get_UiName(wsUser); string icuLocal = ws.IcuLocale; string mapName = ws.LegacyMapping; WsInfo wsi = new WsInfo(vws[iws], name, icuLocal, mapName); m_wsInfo.Add(wsi.KEY, wsi); } } // initialize the 'ws' combo box with the data from the DB foreach (DictionaryEntry entry in m_wsInfo) { WsInfo wsi = entry.Value as WsInfo; cbWS.Items.Add(wsi); } cbWS.Sorted = false; WsInfo wsiIgnore = new WsInfo(); cbWS.Items.Add(wsiIgnore); // select the proper index if there is a valid writhing system int index = 0; if (m_wsName != null && m_wsName != "") { index = cbWS.FindStringExact(m_wsName); if (index < 0) { index = 0; } } cbWS.SelectedIndex = index; LoadEncodingConverters(); index = 0; if (m_encConverter != null && m_encConverter != "") { index = cbEC.FindStringExact(m_encConverter); if (index < 0) { index = 0; } } cbEC.SelectedIndex = index; }