Example #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();
		}
Example #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// This method implements the Translate UNS Questions menu item. It is called using
		/// reflection by xCore, not directly. See TeTMDefinition.xml, look for
		/// CmdUnsQuestions.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected bool OnUnsQuestions(object args)
		{
			if (m_transceleratorWindow != null)
			{
				m_transceleratorWindow.Activate();
				return true;
			}

			using (new WaitCursor(this))
			{
				List<IKeyTerm> keyTerms = new List<IKeyTerm>();
				foreach (ICmPossibility keyTerm in Cache.LanguageProject.KeyTermsList.PossibilitiesOS)
					AddKtLeafNodes(keyTerms, keyTerm);

				IWritingSystem vernWs = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem;
				IWritingSystem defaultWs = Cache.ServiceLocator.WritingSystemManager.UserWritingSystem;

				ComprehensionCheckingSettings ccSettings;
				try
				{
					using (RegistryKey key = m_app.ProjectSpecificSettingsKey.OpenSubKey(kComprehensionCheckingToolSubKey))
					{
						ccSettings = ComprehensionCheckingSettings.LoadFromString(
							(string)key.GetValue(kCCSettings, string.Empty));
					}
					if (string.IsNullOrEmpty(ccSettings.QuestionsFile))
						ccSettings.QuestionsFile = Path.Combine(FwDirectoryFinder.TeFolder, "QTTallBooks.sfm");
				}
				catch
				{
					ccSettings = new ComprehensionCheckingSettings(Path.Combine(FwDirectoryFinder.TeFolder, "QTTallBooks.sfm"));
				}
				ScrReference start, end;
				m_bookFilter.GetRefRangeForContiguousBooks(out start, out end);

				m_transceleratorWindow = new UNSQuestionsDialog(Cache.ProjectId.Name, keyTerms,
					m_StyleSheet.GetUiFontForWritingSystem(Cache.DefaultVernWs, 0), vernWs.IcuLocale,
					vernWs.RightToLeftScript, Path.Combine(ScrTextCollection.SettingsDirectory ?? @"c:\My Paratext Projects", "cms"), ccSettings,
					App.ApplicationName, start, end,
					vern => ((IWritingSystemDefinition)(vern ? vernWs : defaultWs)).LocalKeyboard.Activate(),
					() => ShowHelp.ShowHelpTopic(m_app, "khtpNoHelpTopic"),
					LookupTerm); // TODO: Come up with a Help topic

				m_transceleratorWindow.GetAvailableBooks = () => m_bookFilter.BookIds;
				m_transceleratorWindow.Closed += SaveComprehensionCheckingSettings;
			}
			m_transceleratorWindow.Show();

			return true;
		}