Ejemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="UNSQuestionsDialog"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public UNSQuestionsDialog(string projectName, IEnumerable<IKeyTerm> keyTerms,
			Font vernFont, string VernIcuLocale, bool fVernIsRtoL, string sDefaultLcfFolder,
			ComprehensionCheckingSettings settings, string appName, ScrReference startRef,
			ScrReference endRef, Action<bool> selectKeyboard, Action helpDelegate,
			Action<IEnumerable<IKeyTerm>, int, int> lookupTermDelegate)
		{
			if (startRef != ScrReference.Empty && endRef != ScrReference.Empty && startRef > endRef)
				throw new ArgumentException("startRef must be before endRef");
			m_projectName = projectName;
			m_keyTerms = keyTerms;
			m_vernFont = vernFont;
			m_vernIcuLocale = VernIcuLocale;
			m_selectKeyboard = selectKeyboard;
			m_helpDelegate = helpDelegate;
			m_lookupTermDelegate = lookupTermDelegate;
			m_defaultLcfFolder = sDefaultLcfFolder;
			m_appName = appName;
			TermRenderingCtrl.s_AppName = appName;
			m_startRef = startRef;
			m_endRef = endRef;

			InitializeComponent();

			TxlSplashScreen splashScreen = new TxlSplashScreen();
			splashScreen.Show(Screen.FromPoint(settings.Location));
			splashScreen.Message = Properties.Resources.kstidSplashMsgInitializing;

			ClearBiblicalTermsPane();

			Text = String.Format(Text, projectName);
			HelpButton = (m_helpDelegate != null);

			mnuShowAllPhrases.Tag = PhraseTranslationHelper.KeyTermFilterType.All;
			mnuShowPhrasesWithKtRenderings.Tag = PhraseTranslationHelper.KeyTermFilterType.WithRenderings;
			mnuShowPhrasesWithMissingKtRenderings.Tag = PhraseTranslationHelper.KeyTermFilterType.WithoutRenderings;
			m_lblAnswerLabel.Tag = m_lblAnswerLabel.Text.Trim();
			m_lblCommentLabel.Tag = m_lblCommentLabel.Text.Trim();
			lblFilterIndicator.Tag = lblFilterIndicator.Text;
			lblRemainingWork.Tag = lblRemainingWork.Text;

			Location = settings.Location;
			WindowState = settings.DefaultWindowState;
			if (MinimumSize.Height <= settings.DialogSize.Height &&
				MinimumSize.Width <= settings.DialogSize.Width)
			{
				Size = settings.DialogSize;
			}
			MatchWholeWords = !settings.MatchPartialWords;
			ShowToolbar = settings.ShowToolbar;
			GenTemplateSettings = settings.GenTemplateSettings;
			ReceiveScrRefs = settings.ReceiveScrRefs;
			ShowAnswersAndComments = settings.ShowAnswersAndComments;
			MaximumHeightOfKeyTermsPane = settings.MaximumHeightOfKeyTermsPane;

			DataGridViewCellStyle translationCellStyle = new DataGridViewCellStyle();
			translationCellStyle.Font = vernFont;
			m_colTranslation.DefaultCellStyle = translationCellStyle;
			if (fVernIsRtoL)
				m_colTranslation.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

			dataGridUns.RowTemplate.MinimumHeight = dataGridUns.RowTemplate.Height = m_normalRowHeight =
				(int)Math.Ceiling(vernFont.Height * CreateGraphics().DpiY / 72) + 2;
			Margin = new Padding(Margin.Left, toolStrip1.Height, Margin.Right, Margin.Bottom);

			m_questionsFilename = Path.Combine(s_unsDataFolder, Path.ChangeExtension(Path.GetFileName(settings.QuestionsFile), "xml"));
			string alternativesFilename = Path.Combine(Path.GetDirectoryName(settings.QuestionsFile) ?? string.Empty,
				Path.ChangeExtension(Path.GetFileNameWithoutExtension(settings.QuestionsFile) + " - AlternateFormOverrides", "xml"));
			m_keyTermRulesFilename = Path.Combine(Path.GetDirectoryName(settings.QuestionsFile) ?? string.Empty, "keyTermRules.xml");
			FileInfo finfoXmlQuestions = new FileInfo(m_questionsFilename);
			FileInfo finfoSfmQuestions = new FileInfo(settings.QuestionsFile);
			FileInfo finfoAlternatives = new FileInfo(alternativesFilename);

			if (!finfoXmlQuestions.Exists ||
				(finfoSfmQuestions.Exists && finfoXmlQuestions.CreationTimeUtc < finfoSfmQuestions.CreationTimeUtc) ||
				(finfoSfmQuestions.Exists && finfoAlternatives.Exists && finfoXmlQuestions.CreationTimeUtc < finfoAlternatives.CreationTimeUtc))
			{
				if (!finfoSfmQuestions.Exists)
					MessageBox.Show(Properties.Resources.kstidFileNotFound + settings.QuestionsFile, Text);
				if (!finfoAlternatives.Exists)
					alternativesFilename = null;
				QuestionSfmFileAccessor.Generate(settings.QuestionsFile, alternativesFilename, m_questionsFilename);
			}

			m_translationsFile = Path.Combine(s_unsDataFolder, string.Format("Translations of Checking Questions - {0}.xml", projectName));
			m_phraseCustomizationsFile = Path.Combine(s_unsDataFolder, string.Format("Question Customizations - {0}.xml", projectName));
			m_phraseSubstitutionsFile = Path.Combine(s_unsDataFolder, string.Format("Phrase substitutions - {0}.xml", projectName));
			m_phraseSubstitutions = XmlSerializationHelper.LoadOrCreateList<Substitution>(m_phraseSubstitutionsFile, true);
			KeyTermMatch.RenderingInfoFile = Path.Combine(s_unsDataFolder, string.Format("Key term rendering info - {0}.xml", projectName));

			LoadTranslations(splashScreen);

			// Now apply settings that have filtering or other side-effects
			CheckedKeyTermFilterType = settings.KeyTermFilterType;
			SendScrRefs = settings.SendScrRefs;

			splashScreen.Close();
		}
Ejemplo n.º 2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Loads the translations.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void LoadTranslations(TxlSplashScreen splashScreen)
		{
			if (splashScreen != null)
				splashScreen.Message = Properties.Resources.kstidSplashMsgLoadingQuestions;
			Exception e;
			KeyTermRules rules = XmlSerializationHelper.DeserializeFromFile<KeyTermRules>(m_keyTermRulesFilename, out e);
			if (e != null)
				MessageBox.Show(e.ToString(), Text);

			List<PhraseCustomization> customizations = null;
			if (File.Exists(m_phraseCustomizationsFile))
			{
				customizations = XmlSerializationHelper.DeserializeFromFile<List<PhraseCustomization>>(m_phraseCustomizationsFile, out e);
				if (e != null)
					MessageBox.Show(e.ToString());
			}

			QuestionProvider qp = new QuestionProvider(m_questionsFilename, customizations);
			m_helper = new PhraseTranslationHelper(qp, m_keyTerms, rules, m_phraseSubstitutions);
			m_helper.KeyTermRenderingRulesFile = Path.Combine(s_unsDataFolder, string.Format("Term rendering selection rules - {0}.xml", m_projectName));
			m_sectionHeadText = qp.SectionHeads;
			m_availableBookIds = qp.AvailableBookIds;
			if (File.Exists(m_translationsFile))
			{
				if (splashScreen != null)
					splashScreen.Message = Properties.Resources.kstidSplashMsgLoadingTranslations;

				List<XmlTranslation> translations = XmlSerializationHelper.DeserializeFromFile<List<XmlTranslation>>(m_translationsFile, out e);
				if (e != null)
					MessageBox.Show(e.ToString());
				else
				{
					foreach (XmlTranslation unsTranslation in translations)
					{
						TranslatablePhrase phrase = m_helper.GetPhrase(unsTranslation.Reference, unsTranslation.PhraseKey);
						if (phrase != null && !phrase.IsExcluded)
							phrase.Translation = unsTranslation.Translation;
					}
				}
			}
			m_helper.ProcessAllTranslations();
			m_helper.TranslationsChanged += m_helper_TranslationsChanged;

			dataGridUns.RowCount = m_helper.Phrases.Count();
		}