/// <summary>
		/// Shows the new writing system properties dialog.
		/// </summary>
		/// <param name="owner">The owner.</param>
		/// <param name="cache">The cache.</param>
		/// <param name="wsManager">The ws manager.</param>
		/// <param name="wsContainer">The ws container.</param>
		/// <param name="helpTopicProvider">The help topic provider.</param>
		/// <param name="app">The app.</param>
		/// <param name="stylesheet">The stylesheet.</param>
		/// <param name="displayRelatedWss">if set to <c>true</c> related writing systems will be displayed.</param>
		/// <param name="defaultName">The default language name for the new writing system.</param>
		/// <param name="newWritingSystems">The new writing systems.</param>
		/// <returns></returns>
		public static bool ShowNewDialog(Form owner, FdoCache cache, IWritingSystemManager wsManager,
			IWritingSystemContainer wsContainer, IHelpTopicProvider helpTopicProvider, IApp app,
			IVwStylesheet stylesheet, bool displayRelatedWss, string defaultName,
			out IEnumerable<IWritingSystem> newWritingSystems)
		{
			newWritingSystems = null;
			LanguageSubtag languageSubtag;

			using (new WaitCursor(owner))
			using (var dlg = new LanguageSelectionDlg(wsManager, helpTopicProvider))
			{
				dlg.Text = FwCoreDlgs.kstidLanguageSelectionNewWsCaption;
				dlg.DefaultLanguageName = defaultName;

				if (dlg.ShowDialog(owner) != DialogResult.OK)
					return false;

				languageSubtag = dlg.LanguageSubtag;
			}

			using (new WaitCursor(owner))
			using (var wsPropsDlg = new WritingSystemPropertiesDialog(cache, wsManager, wsContainer, helpTopicProvider, app, stylesheet))
			{
				wsPropsDlg.SetupDialog(languageSubtag, displayRelatedWss);

				if (wsPropsDlg.ShowDialog(owner) == DialogResult.OK)
				{
					newWritingSystems = wsPropsDlg.NewWritingSystems;
					return true;
				}
			}
			return false;
		}
 /// <summary>
 /// simulate choosing settings with those specified in SelectEthnologueCodeDlg().
 /// </summary>
 /// <param name="dlg"></param>
 /// <returns></returns>
 protected override DialogResult CallShowDialog(LanguageSelectionDlg dlg)
 {
     if (m_ethnologueDlgResultToEnforce == DialogResult.OK)
     {
         // overwrite
         dlg.LanguageName   = m_selectedLanguageName;
         dlg.EthnologueCode = m_selectedEthnologueCode;
     }
     return(DialogResult = m_ethnologueDlgResultToEnforce);
 }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// write out the new ethnologue codes.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void SetupDialogFromLanguageSelectionDlg(LanguageSelectionDlg dlg)
		{
			foreach (LanguageDefinition langDef in m_listFinalLangDefs)
			{
				langDef.SetEthnologueCode(dlg.EthCode, dlg.LangName.Trim());
				langDef.LocaleName = dlg.LangName.Trim();
			}
			SetupDialogFromCurrentLanguageDefinition();
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected virtual DialogResult CallShowDialog(LanguageSelectionDlg dlg)
		{
			return dlg.ShowDialog();
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Lanches the Dialog.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected void btnModifyEthnologueInfo_Click(object sender, System.EventArgs e)
		{
			if (!CheckOkToChangeContext())
				return;
			SaveCurrentLangDef();
			using (LanguageSelectionDlg dlg = new LanguageSelectionDlg())
			{
				dlg.SetDialogProperties(m_helpTopicProvider);
				dlg.StartedInModifyState = true;	// started in modify state

				string origLangName = m_LanguageName;
				string origEthCode = null;
				dlg.LangName = origLangName;
				if (m_LanguageCode.Text != FwCoreDlgs.kstidNone)
					origEthCode = m_LanguageCode.Text;
				dlg.EthCode = origEthCode;

				if (CallShowDialog(dlg) != DialogResult.OK)
					return;
				CreateTemporaryLanguageDefs();
				// If the language name changes, change the abbreviation as well.  See LT-8652.
				string oldLangName = m_LanguageName;
				SetupDialogFromLanguageSelectionDlg(dlg);
				if (m_LanguageName != oldLangName)
				{
					int len = Math.Min(3, m_LanguageName.Length);
					m_ShortWsName.Text = m_LanguageName.Substring(0, len);
				}
				if (!CheckIcuNames())
				{
					// something wasn't right about the name changes, so revert to previous state.
					RestoreFinalLangDefs();
					btnModifyEthnologueInfo.Focus();
					return;
				}
				UpdateDialogWithChangesToLanguageName();
			}
		}
		/// <summary>
		/// simulate choosing settings with those specified in SelectEthnologueCodeDlg().
		/// </summary>
		/// <param name="dlg"></param>
		/// <returns></returns>
		protected override DialogResult CallShowDialog(LanguageSelectionDlg dlg)
		{
			if (m_ethnologueDlgResultToEnforce == DialogResult.OK)
			{
				// overwrite
				dlg.LangName = m_selectedLanguageName;
				dlg.EthCode = m_selectedEthnologueCode;
			}
			return DialogResult = m_ethnologueDlgResultToEnforce;
		}
		/// <summary>
		/// Handles the Click event of the btnModifyEthnologueInfo control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
		protected void btnModifyEthnologueInfo_Click(object sender, EventArgs e)
		{
			if (!CheckOkToChangeContext())
				return;

			using (var dlg = new LanguageSelectionDlg(m_wsManager, m_helpTopicProvider))
			{
				dlg.StartedInModifyState = true;	// started in modify state

				string origLangName = m_tbLanguageName.Text;
				dlg.LanguageSubtag = CurrentWritingSystem.LanguageSubtag;

				if (CallShowDialog(dlg) != DialogResult.OK)
					return;

				List<Tuple<IWritingSystem, LanguageSubtag, bool>> origWsData =
					m_listBoxRelatedWSs.Items.Cast<IWritingSystem>().Select(ws => Tuple.Create(ws, ws.LanguageSubtag, ws.Modified)).ToList();
				LanguageSubtag subtag = dlg.LanguageSubtag;
				foreach (IWritingSystem ws in m_listBoxRelatedWSs.Items)
				{
					ws.LanguageSubtag = subtag;
					if (ws.LanguageSubtag.Code == "zh" && ws.LanguageSubtag.ISO3Code == "cmn" && ws.RegionSubtag == null)
						ws.RegionSubtag = new RegionSubtag("CN", "China", false);
				}

				if (!CheckWsIdChange())
				{
					// revert back to original language
					foreach (Tuple<IWritingSystem, LanguageSubtag, bool> wsData in origWsData)
					{
						wsData.Item1.LanguageSubtag = wsData.Item2;
						wsData.Item1.Modified = wsData.Item3;
					}
				}
				else
				{
					Set_tbLanguageName(subtag.Name);
					SetupEthnologueCode(CurrentWritingSystem);
					if (m_tbLanguageName.Text != origLangName)
					{
						int len = Math.Min(3, m_tbLanguageName.Text.Length);
						m_ShortWsName.Text = m_tbLanguageName.Text.Substring(0, len);
					}

					UpdateDialogWithChangesToLanguageName();
				}
			}
		}