/// <summary>
		/// serialize the language definitions to temporary files, so we don't clobber the ones
		/// used by the application or other tests.
		/// </summary>
		/// <param name="finalLangDef"></param>
		protected override void Serialize(LanguageDefinition finalLangDef)
		{
			if (m_cache.LanguageWritingSystemFactoryAccessor.BypassInstall)
				SerializeToTempfile(finalLangDef);
			else
				base.Serialize(finalLangDef);
		}
Ejemplo n.º 2
0
		public void GetAbbreviationsNameOnly()
		{
			LanguageDefinition langDef = new LanguageDefinition(m_wsEn);
			langDef.XmlWritingSystem.WritingSystem.IcuLocale = "en";

			Assert.AreEqual("en", langDef.LocaleAbbr);
			Assert.AreEqual("", langDef.CountryAbbr);
			Assert.AreEqual("", langDef.VariantAbbr);
		}
Ejemplo n.º 3
0
		/// ----------------------------------------------------------------------------------------
		/// <summary>
		/// For a given LanguageDefinition, if the ValidChars field is empty then try to get a set
		/// of ExemplarCharacters (valid characters) from ICU for this language.
		/// </summary>
		/// <param name="langDef"></param>
		/// <param name="cpe">A character property engine (needed for normalization).</param>
		/// ----------------------------------------------------------------------------------------
		public static void TryLoadValidCharsIfEmpty(LanguageDefinition langDef,
			ILgCharacterPropertyEngine cpe)
		{
			//Try to load the ValidChars if none have been loaded yet.
			if (string.IsNullOrEmpty(langDef.ValidChars))
			{
				string IcuLocale = (langDef.BaseLocale ?? langDef.LocaleAbbr);
				langDef.ValidChars = GetValidCharsForLocale(IcuLocale, cpe);
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void SetupEthnologueCode(LanguageDefinition langDef)
		{
			string strNone = FwCoreDlgs.kstidNone;
			if (langDef.EthnoCode != null && langDef.EthnoCode.Length > 0)
			{
				SetLanguageCodeLabels(langDef.EthnoCode);
			}
			else
			{
				SqlConnection dbConnection = null;
				SqlCommand sqlCommand = null;
				string sConnection = string.Format("Server={0}; Database=Ethnologue; User ID=FWDeveloper; " +
					"Password=careful; Pooling=false;", MiscUtils.LocalServerName);

				dbConnection = new SqlConnection(sConnection);
				dbConnection.Open();
				sqlCommand = dbConnection.CreateCommand();
				// REVIEW (SteveMiller): Isn't there a better way to get the output variable
				// than to do the IF and SELECT in dynamic SQL code? Seems like there should
				// be something in C# that would do this.
				sqlCommand.CommandText = string.Format("declare @EthnoCode nchar(3); " +
					"exec GetIsoCode '{0}', @EthnoCode output; " +
					"if @EthnoCode is not null select @EthnoCode",
					langDef.LocaleAbbr);
				SqlDataReader reader =
					sqlCommand.ExecuteReader(System.Data.CommandBehavior.Default);
				if (reader.HasRows)
				{
					reader.Read();
					SetLanguageCodeLabels(reader.GetString(0));
					langDef.EthnoCode = reader.GetString(0);
				}
				else
				{
					SetLanguageCodeLabels(strNone);
				}
				reader.Close();
				dbConnection.Close();
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void SavePUACheckedChars(LanguageDefinition langDef)
		{
			if (m_lstPUACharacters.Items.Count == 0)
				return;

			ValidCharacters validChars = ValidCharacters.Load(langDef);
			if (validChars == null)
				return;

			// First clear out any characters in the PUA list for the writing system
			// unless they are still in the list of checked items.
			// Also remove them from the valid characters list.
			foreach (PuaListItem puaItem in m_lstPUACharacters.Items)
			{
				if (!m_lstPUACharacters.CheckedItems.Contains(puaItem))
				{
					langDef.RemovePuaDefinition(puaItem.PUAChar.CharDef);

					char c = (char)puaItem.PUAChar.Character;
					validChars.RemoveCharacter(c.ToString());
				}
			}

			// Add the characters which are checked to the PUA list for the writing system and
			// the valid characters list.
			foreach (PuaListItem puaItem in m_lstPUACharacters.CheckedItems)
			{
				langDef.AddPuaDefinition(puaItem.PUAChar.CharDef);

				// Now add the character to the valid characters list if it is not a diacritic
				// or some other category that is disallowed in the valid characters list.
				string chr = ((char)puaItem.PUAChar.Character).ToString();
				ValidCharacterType chrType = langDef.GetOverrideCharType(chr);
				if (chrType != ValidCharacterType.None)
					validChars.AddCharacter(chr, chrType);
			}

			// Put the updated valid characters back into the final lang. definition.
			langDef.ValidChars = validChars.XmlString;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void SaveICUrules(LanguageDefinition langDef)
		{
			if (txtIcuRules.Enabled)
			{
				ICollation coll = UseOrCreateCollation(langDef);
				coll.IcuRules = txtIcuRules.Text;
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing"><c>true</c> to release both managed and unmanaged
		/// resources; <c>false</c> to release only unmanaged resources.
		/// </param>
		/// ------------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if (disposing)
			{
				// release managed objects
				if (components != null)
					components.Dispose();
				if (m_fwTextBoxTestWs != null)
					m_fwTextBoxTestWs.Dispose();
				// We may have made the cache from COM objects given to us by a COM client.
				// In that case, we have to dispose it.
				if (m_cacheMadeLocally && m_cache != null)
					m_cache.Dispose();
				if (m_langDefCurrent != null)
					m_langDefCurrent.ReleaseRootRb();
				if (cbDictionaries != null)
					cbDictionaries.Dispose();
			}

			// release unmanaged objects regardless of disposing flag
			if (m_fwt != null && Marshal.IsComObject(m_fwt))
			{
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_fwt);
				m_fwt = null;
			}

			if (m_strmLog != null && Marshal.IsComObject(m_strmLog))
			{
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_strmLog);
				m_strmLog = null;
			}

			PUACharacter.ReleaseTheCom();

			// Garbage collect the cached ICU
			m_cachedIcu = null;
			// GC.Collect(); Can't be deterministic about when it happens, even by calling for a collection.
			m_langDefCurrent = null;
			m_fwTextBoxTestWs = null;
			cbDictionaries = null;

			base.Dispose(disposing);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected void btnRemove_Click(object sender, EventArgs e)
		{
			// if we're removing from the end of the list, the new index will be the previous one,
			// otherwise, keep the index the same.
			int indexNext = m_listBoxRelatedWSs.SelectedIndex == m_listBoxRelatedWSs.Items.Count - 1 ?
				m_listBoxRelatedWSs.SelectedIndex - 1 : m_listBoxRelatedWSs.SelectedIndex;
			m_listOrigLangDefs.Remove(m_langDefCurrent);
			m_listFinalLangDefs.Remove(m_langDefCurrent);
			PopulateRelatedWSsListBox();
			m_langDefCurrent = m_listFinalLangDefs[indexNext];
			SetupDialogFromCurrentLanguageDefinition();
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected virtual void ShowMsgTooBadWsAlreadyInDb(LanguageDefinition finalLangDef, string origIcuLocale, string strExisting)
		{
			string msg = string.Format(FwCoreDlgs.kstidTooBadWsAlreadyInDb,
				strExisting, finalLangDef.WritingSystem.IcuLocale, origIcuLocale);

			MessageBox.Show(msg, FwCoreDlgs.kstidWspLabel, MessageBoxButtons.OK);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Tests can override this to specify a temp location to store the output.
		/// </summary>
		/// <param name="finalLangDef"></param>
		/// ------------------------------------------------------------------------------------
		protected virtual void Serialize(LanguageDefinition finalLangDef)
		{
			finalLangDef.Serialize();
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void Set_regionVariantControl(LanguageDefinition langDef)
		{
			m_fUserChangedVariantControl = false;
			m_regionVariantControl.LangDef = langDef;
			m_fUserChangedVariantControl = true;

			m_FullCode.Text = langDef.CurrentFullLocale();

			m_regionVariantControl.PropDlg = true;

			LoadShortWsNameFromCurrentLanguageDefn();
			rbLeftToRight.Checked = !langDef.WritingSystem.RightToLeft;
			rbRightToLeft.Checked = langDef.WritingSystem.RightToLeft;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Save the selected encoding converter
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected void Save_cbEncodingConverter(LanguageDefinition langdef)
		{
			// save the selected encoding converter
			string str = cbEncodingConverter.SelectedItem as string;
			if (str == FwCoreDlgs.kstidNone)
				str = null;
			Debug.Assert(str == null || !str.Contains(FwCoreDlgs.kstidNotInstalled));
			langdef.WritingSystem.LegacyMapping = str;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds the "invalid" character as a valid character.
		/// </summary>
		/// <param name="addedCharError">The checking error containing the character that will
		/// be added to the valid character inventory.</param>
		/// ------------------------------------------------------------------------------------
		private void AddAsValidCharacter(CheckingError addedCharError)
		{
			Debug.Assert(addedCharError.CheckId == StandardCheckIds.kguidCharacters,
				"Checking error should be from the valid characters check");

			ILgWritingSystemFactory lgwsf = m_cache.LanguageWritingSystemFactoryAccessor;
			int hvoWs = m_cache.DefaultVernWs;
			IWritingSystem ws = lgwsf.get_EngineOrNull(hvoWs);
			LanguageDefinition langDef = new LanguageDefinition(ws);
			LgWritingSystem lgWs = new LgWritingSystem(m_cache, hvoWs);
			langDef.ValidChars = ws.ValidChars;

			if (StringUtils.IsCharacterDefined(addedCharError.CitedText))
			{
				using (new WaitCursor(Parent))
				{
					// Get the valid characters from the database
					ValidCharacters validChars = ValidCharacters.Load(langDef);
					if (validChars != null)
					{
						validChars.AddCharacter(addedCharError.CitedText);
						ws.ValidChars = langDef.ValidChars = validChars.XmlString;
						StringUtils.UpdatePUACollection(langDef, validChars.AllCharacters);
						ws.SaveIfDirty(m_cache.DatabaseAccessor);
						langDef.Serialize();
					}

					// Mark all data grid view rows containing the newly-defined valid character to irrelevant.
					for (int iRow = 0; iRow < m_list.Count; iRow++)
					{
						CheckingError checkError = GetCheckingError(iRow);
						if (((StTxtPara)checkError.QuoteOA.ParagraphsOS[0]).Contents.Text ==
							addedCharError.CitedText)
						{
							// We don't want to create an undoable action, so we suppress subtasks.
							using (SuppressSubTasks supressActionHandler = new SuppressSubTasks(m_cache, true))
								checkError.Status = CheckingStatus.StatusEnum.Irrelevant;
						}
					}

					IsStale = true;

					m_dataGridView.Invalidate();
				}
			}
			else
			{
				string msg =
					ResourceHelper.GetResourceString("kstidUndefinedCharacterMsg");
				MessageBox.Show(this, msg, Application.ProductName,
					MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
		}
Ejemplo n.º 14
0
		/// <summary>
		/// Create a New LanguageDefinition and inherit its general data from the current language definition.
		/// </summary>
		/// <param name="wsf"></param>
		/// <param name="langDef"></param>
		/// <returns></returns>
		public ILanguageDefinition CreateNewFrom(ILgWritingSystemFactory wsf, LanguageDefinition langDef)
		{
			LanguageDefinition newLangDef = CreateNew(wsf) as LanguageDefinition;
			newLangDef.LocaleName = langDef.LocaleName;
			newLangDef.SetEthnologueCode(langDef.EthnoCode, langDef.LocaleName);
			newLangDef.LocaleAbbr = langDef.LocaleAbbr;
			newLangDef.ValidChars = langDef.ValidChars;
			newLangDef.MatchedPairs = langDef.MatchedPairs;
			newLangDef.PunctuationPatterns = langDef.PunctuationPatterns;
			newLangDef.CapitalizationInfo = langDef.CapitalizationInfo;
			newLangDef.QuotationMarks = langDef.QuotationMarks;
			newLangDef.LoadDefaultICUValues();
			newLangDef.FinishedInitializing();
			return newLangDef;
		}
Ejemplo n.º 15
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Check if we can go to next tab.
		/// </summary>
		/// -----------------------------------------------------------------------------------
		protected override bool ValidToGoForward()
		{
			if (CurrentStepNumber != 1)
				return true;

			// Don't leave the region/variant page if we don't have valid data.
			if (!m_regionVariantControl.CheckValid())
				return false;

			string caption = FwCoreDlgs.kstidNwsCaption;
			string strLoc = m_langDef.WritingSystem.IcuLocale;

			// Catch case where we are going to overwrite an existing writing system in the Db.
			if (m_langDef.IsWritingSystemInDb())
			{
				ILgWritingSystemFactory wsf = m_langDef.XmlWritingSystem.WritingSystem.WritingSystemFactory;
				int defWs = wsf.UserWs;
				int ws = wsf.GetWsFromStr(strLoc);
				IWritingSystem qws = wsf.get_EngineOrNull(ws);
				string strDispName = qws.get_UiName(defWs);

				string msg = string.Format(FwCoreDlgs.kstidCantOverwriteWsInDb,
					strDispName, strLoc, Environment.NewLine, m_langDef.DisplayName);
				MessageBox.Show(msg, caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				return false;
			}

			// Catch case where we are going to overwrite an existing LD.xml file.
			// This should be avoided by the callers to this dialog, but just in case, we'll
			// handle it here as well.
			if (m_langDef.IsLocaleInLanguagesDir())
			{
				string msg = string.Format(FwCoreDlgs.kstidLocaleAlreadyInLanguages,
					m_langDef.DisplayName, m_langDef.WritingSystem.IcuLocale, Environment.NewLine);
				DialogResult dr = MessageBox.Show(msg, FwCoreDlgs.ksWsAlreadyExists, MessageBoxButtons.YesNo,
					MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
				// If the user cancels, we don't leave the dialog.
				if (dr == DialogResult.Yes)
				{
					// We need to load the existing LD.xml file and then write it out to the
					// database, overwriting the original writing system. We then close the wizard.
					try
					{
						m_langDef = null;
						LanguageDefinitionFactory ldf = new LanguageDefinitionFactory();
						m_langDef = ldf.InitializeFromXml(m_wsf, strLoc) as LanguageDefinition;
						Debug.Assert(m_langDef != null);
						if (m_langDef != null)
						{
							m_langDef.SaveWritingSystem(strLoc);
						}
						DialogResult = DialogResult.OK;
						Visible = false;
					}
					catch
					{
						MessageBox.Show(FwCoreDlgs.kstidErrorSavingWs, caption,
							MessageBoxButtons.OK, MessageBoxIcon.Error);
						DialogResult = DialogResult.Cancel;
						Visible = false;
					}
				}
				return false;
			}
			return true;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected virtual DialogResult ShowMsgLocaleAlreadyInLanguages(LanguageDefinition finalLangDef)
		{
			string msg = string.Format(FwCoreDlgs.kstidLocaleAlreadyInLanguages,
									 finalLangDef.DisplayName, finalLangDef.WritingSystem.IcuLocale, Environment.NewLine);
			DialogResult dr = MessageBox.Show(msg, FwCoreDlgs.kstidWspLabel, MessageBoxButtons.YesNo,
				MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
			return dr;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected virtual DialogResult ShowMsgWsAlreadyInDb(LanguageDefinition finalLangDef, string origIcuLocale, string strExisting, IWritingSystem wsOld)
		{
			string msg = string.Format(FwCoreDlgs.kstidWsAlreadyInDb,
									 strExisting, finalLangDef.WritingSystem.IcuLocale,
									 origIcuLocale, wsOld.LanguageName, Environment.NewLine);
			using (MergeToExistingWsDlg dlg = new MergeToExistingWsDlg(m_helpTopicProvider))
			{
				dlg.Initialize(msg, m_app);
				dlg.ShowDialog(this);
				return dlg.DialogResult;
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// <returns>true if the two LanguageDefinitions' PuaDefinitions are the same</returns>
		/// ------------------------------------------------------------------------------------
		private static bool ComparePuaDefinitions(LanguageDefinition originalLangDef, LanguageDefinition finalLangDef)
		{
			//determine if originalLangDef.PuaDefinitions==null before this....
			if (originalLangDef.PuaDefinitions == null && finalLangDef.PuaDefinitions == null)
			{
				return true;
			}
			else if ((originalLangDef.PuaDefinitions == null && finalLangDef.PuaDefinitions != null) ||
				(originalLangDef.PuaDefinitions != null && finalLangDef.PuaDefinitions == null))
			{
				return false;
			}
			//it is safe to perform further checks
			else if (originalLangDef.PuaDefinitions.Length != finalLangDef.PuaDefinitions.Length)
			{
				return false;
			}
			else
			{
				for (int j = 0; j < originalLangDef.PuaDefinitions.Length; j++)
				{
					if (!originalLangDef.PuaDefinitions[j].Equals(finalLangDef.PuaDefinitions[j]))
						return false;
				}
			}
			return true;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private bool IsNew(LanguageDefinition langDef)
		{
			// the givin language definition is new if its object is in both
			// the original list and the final list.
			int indexInFinalLangDefs = m_listFinalLangDefs.IndexOf(langDef);
			int indexInOrigLangDefs = m_listOrigLangDefs.IndexOf(langDef);
			return indexInOrigLangDefs != -1 && indexInFinalLangDefs != -1;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// <param name="originalLangDef"></param>
		/// <param name="finalLangDef"></param>
		/// <returns>true if the two LanguageDefinitions' IcuLocale are the same</returns>
		/// ------------------------------------------------------------------------------------
		private static bool CompareIcuLocale(LanguageDefinition originalLangDef, LanguageDefinition finalLangDef)
		{
			string oldIcuLocale = originalLangDef.WritingSystem.IcuLocale;
			string newIcuLocale = finalLangDef.WritingSystem.IcuLocale;
			//I suppose this is what we really want to check for the name change????
			return oldIcuLocale.Equals(newIcuLocale);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void AddLangDefinition(LanguageDefinition newLangDef, bool fSwitchToGeneralTab)
		{
			SaveCurrentLangDef();
			// add the new language definition to our language definitions.
			// Note: we'll add the same object to original and final definitions to indicate these are new
			// and will always be equivalent in comparisons.
			m_listOrigLangDefs.Add(newLangDef);
			m_listFinalLangDefs.Add(newLangDef);
			// make this new current language def.
			m_langDefCurrent = newLangDef;
			PopulateRelatedWSsListBox();
			SetupDialogFromCurrentLanguageDefinition();
			if (fSwitchToGeneralTab)
			{
				try
				{
					// switch to General tab to allow the user to make the current ws valid but don't do context checking.
					m_fSkipCheckOkToChangeContext = true;
					SwitchTab(kWsGeneral);
				}
				finally
				{
					m_fSkipCheckOkToChangeContext = false;
				}
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// <param name="originalLangDef"></param>
		/// <param name="finalLangDef"></param>
		/// <returns>true if the two LanguageDefinitions' SpellCheckDictionary are the same</returns>
		/// ------------------------------------------------------------------------------------
		private static bool CompareSpellDictionary(LanguageDefinition originalLangDef, LanguageDefinition finalLangDef)
		{
			string oldSpellDictionary = originalLangDef.WritingSystem.SpellCheckDictionary;
			string newSpellDictionary = finalLangDef.WritingSystem.SpellCheckDictionary;
			//I suppose this is what we really want to check for the name change????
			return oldSpellDictionary.Equals(newSpellDictionary);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private LanguageDefinition EstablishCurrentLangDefFromSelectedIndex()
		{
			m_langDefCurrentIndex = m_listBoxRelatedWSs.SelectedIndex;
			m_langDefCurrent = m_listFinalLangDefs[m_langDefCurrentIndex];
			m_listBoxRelatedWSs.Focus();
			UpdateListBoxButtons();
			return m_langDefCurrent;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private static bool CompareIcuRules(LanguageDefinition originalLangDef, LanguageDefinition finalLangDef)
		{
			return GetIcuRules(originalLangDef) == GetIcuRules(finalLangDef);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private static ICollation UseOrCreateCollation(LanguageDefinition langDef)
		{
			ICollation coll = null;
			if (langDef.WritingSystem.CollationCount > 0)
				coll = langDef.WritingSystem.get_Collation(0);
			if (coll == null)
				coll = CollationClass.Create();
			langDef.WritingSystem.set_Collation(0, coll);
			return coll;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// <param name="langDef"></param>
		/// <returns>icuRules string for first collation, or empty string if no icu rules were found for given language definition</returns>
		/// ------------------------------------------------------------------------------------
		protected static string GetIcuRules(LanguageDefinition langDef)
		{
			string icuRules = "";
			if (langDef.WritingSystem.CollationCount > 0)
				icuRules = langDef.WritingSystem.get_Collation(0).IcuRules;
			if (icuRules == null)
				icuRules = "";
			return icuRules;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void SetupSortTab(LanguageDefinition langDef)
		{
			if (m_langDefCurrent.BaseLocale != null)
			{
				btnSimilarWs.SelectedLocaleId = m_langDefCurrent.BaseLocale;
			}
			else
			{
				System.ComponentModel.ComponentResourceManager resources =
					new System.ComponentModel.ComponentResourceManager(typeof(WritingSystemPropertiesDialog));
				// apply default text
				btnSimilarWs.Text = (string)resources.GetObject("btnSimilarWs.Text");
			}
			SetupICURulesAndBtnSimilarWs();
			// Copy the ICU rules from the first collation if it exists.
			if (langDef.WritingSystem.CollationCount > 0)
			{
				string icuRules = GetIcuRules(langDef);
				if (txtIcuRules.Enabled)
					txtIcuRules.Text = icuRules;
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private LanguageDefinition ReloadLangDefFromExistingLangDefInLanguageDir(LanguageDefinition langDef)
		{
			ILgWritingSystemFactory qwsf = langDef.WritingSystem.WritingSystemFactory;
			Debug.Assert(langDef.IcuLocaleOriginal != langDef.WritingSystem.IcuLocale);
			string origIcuLocale = langDef.IcuLocaleOriginal;
			string locale = langDef.WritingSystem.IcuLocale;
			langDef.ReleaseRootRb(); // Ensure this is clear before setting to null.
			int indexToReplace = FinalLanguageDefns.IndexOf(langDef);
			langDef = null;
			langDef = CreateLanguageDefFromXml(qwsf, locale);
			Debug.Assert(langDef.IcuLocaleOriginal == langDef.WritingSystem.IcuLocale);
			langDef.IcuLocaleTarget = origIcuLocale;
			// replace the existing language definition with this one.
			Debug.Assert(langDef != null);
			FinalLanguageDefns.RemoveAt(indexToReplace);
			FinalLanguageDefns.Insert(indexToReplace, langDef);
			if (indexToReplace == m_langDefCurrentIndex)
			{
				EstablishCurrentLangDefFromSelectedIndex();
				SetupDialogFromCurrentLanguageDefinition();
			}
			return langDef;
		}
Ejemplo n.º 29
0
		/// <summary>
		/// Adds the default word-forming character overrides to the list of valid
		/// characters for each vernacular writing system that is using the old
		/// valid characters representation.
		/// </summary>
		/// <param name="cache">The cache.</param>
		void AddDefaultWordformingOverridesIfNeeded(FdoCache cache)
		{
			ILgWritingSystemFactory lgwsf = cache.LanguageWritingSystemFactoryAccessor;
			foreach (ILgWritingSystem wsObj in cache.LangProject.VernWssRC)
			{
				IWritingSystem ws = lgwsf.get_EngineOrNull(wsObj.Hvo);
				string validCharsSrc = ws.ValidChars;
				if (!ValidCharacters.IsNewValidCharsString(validCharsSrc))
				{
					LanguageDefinition langDef = new LanguageDefinition(ws);
					ValidCharacters valChars = ValidCharacters.Load(langDef);
					valChars.AddDefaultWordformingCharOverrides();

					ws.ValidChars = langDef.ValidChars = valChars.XmlString;
					using (new SuppressSubTasks(cache))
					{
						ws.SaveIfDirty(cache.DatabaseAccessor);
					}
					langDef.Serialize();
				}
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected virtual bool IsLocaleInLanguagesDir(LanguageDefinition finalLangDef)
		{
			return finalLangDef.IsLocaleInLanguagesDir();
		}