コード例 #1
0
			/// <summary>
			///
			/// </summary>
			/// <returns>string of new morph breaks</returns>
			internal string EditMorphBreaks()
			{
				string sMorphs = null;
				using (var dlg = new EditMorphBreaksDlg(((IxWindow)m_sandbox.FindForm()).Mediator.HelpTopicProvider))
				{
					ITsString tssWord = m_sandbox.SbWordForm(m_sandbox.RawWordformWs);
					sMorphs = m_sandbox.SandboxEditMonitor.BuildCurrentMorphsString();
					dlg.Initialize(tssWord, sMorphs, m_caches.MainCache.MainCacheAccessor.WritingSystemFactory,
						m_caches.MainCache, m_sandbox.Mediator.StringTbl, m_sandbox.StyleSheet);
					Form mainWnd = m_sandbox.FindForm();
					// Making the form active fixes problems like LT-2619.
					// I'm (RandyR) not sure what adverse impact might show up by doing this.
					mainWnd.Activate();
					if (dlg.ShowDialog(mainWnd) == DialogResult.OK)
						sMorphs = dlg.GetMorphs();
					else
						sMorphs = null;
				}
				return sMorphs;
			}
コード例 #2
0
		/// <summary>
		///
		/// </summary>
		/// <param name="argument">The xCore Command object.</param>
		/// <returns>true</returns>
		public bool OnAddApprovedAnalysis(object argument)
		{
			var mainWnd = (FwXWindow)m_dataEntryForm.FindForm();
			using (EditMorphBreaksDlg dlg = new EditMorphBreaksDlg(mainWnd.Mediator.HelpTopicProvider))
			{
				IWfiWordform wf = Wordform;
				if (wf == null)
					return true;
				ITsString tssWord = Wordform.Form.BestVernacularAlternative;
				string morphs = tssWord.Text;
				var cache = Cache;
				dlg.Initialize(tssWord, morphs, cache.MainCacheAccessor.WritingSystemFactory,
					cache, m_dataEntryForm.Mediator.StringTbl, m_dataEntryForm.StyleSheet);
				// Making the form active fixes problems like LT-2619.
				// I'm (RandyR) not sure what adverse impact might show up by doing this.
				mainWnd.Activate();
				if (dlg.ShowDialog(mainWnd) == DialogResult.OK)
				{
					morphs = dlg.GetMorphs().Trim();
					if (morphs.Length == 0)
						return true;

					string[] prefixMarkers = MorphServices.PrefixMarkers(cache);
					string[] postfixMarkers = MorphServices.PostfixMarkers(cache);

					List<string> allMarkers = new List<string>();
					foreach (string s in prefixMarkers)
					{
						allMarkers.Add(s);
					}

					foreach (string s in postfixMarkers)
					{
						if (!allMarkers.Contains(s))
							allMarkers.Add(s);
					}
					allMarkers.Add(" ");

					string[] breakMarkers = new string[allMarkers.Count];
					for (int i = 0; i < allMarkers.Count; ++i)
						breakMarkers[i] = allMarkers[i];

					string fullForm = SandboxBase.MorphemeBreaker.DoBasicFinding(morphs, breakMarkers, prefixMarkers, postfixMarkers);

					var command = (Command) argument;
					UndoableUnitOfWorkHelper.Do(command.UndoText, command.RedoText, cache.ActionHandlerAccessor,
						() =>
							{
								IWfiAnalysis newAnalysis = Cache.ServiceLocator.GetInstance<IWfiAnalysisFactory>().Create();
								Wordform.AnalysesOC.Add(newAnalysis);
								newAnalysis.ApprovalStatusIcon = 1; // Make it human approved.
								int vernWS = TsStringUtils.GetWsAtOffset(tssWord, 0);
								foreach (string morph in fullForm.Split(Unicode.SpaceChars))
								{
									if (morph != null && morph.Length != 0)
									{
										IWfiMorphBundle mb = cache.ServiceLocator.GetInstance<IWfiMorphBundleFactory>().Create();
										newAnalysis.MorphBundlesOS.Add(mb);
										mb.Form.set_String(vernWS, Cache.TsStrFactory.MakeString(morph, vernWS));
									}
								}
							});
				}
			}
			return true;
		}
コード例 #3
0
		/// <summary>
		///
		/// </summary>
		/// <param name="argument">The xCore Command object.</param>
		/// <returns>true</returns>
		public bool OnAddApprovedAnalysis(object argument)
		{
			using (EditMorphBreaksDlg dlg = new EditMorphBreaksDlg())
			{
				IWfiWordform wf = Wordform;
				if (wf == null)
					return true;
				ITsString tssWord = Wordform.Form.BestVernacularAlternative;
				string morphs = tssWord.Text;
				FdoCache cache = Cache;
				dlg.Initialize(tssWord, morphs, cache.MainCacheAccessor.WritingSystemFactory,
					cache, m_dataEntryForm.Mediator.StringTbl, m_dataEntryForm.StyleSheet);
				Form mainWnd = m_dataEntryForm.FindForm();
				// Making the form active fixes problems like LT-2619.
				// I'm (RandyR) not sure what adverse impact might show up by doing this.
				mainWnd.Activate();
				if (dlg.ShowDialog(mainWnd) == DialogResult.OK)
				{
					morphs = dlg.GetMorphs().Trim();
					if (morphs.Length == 0)
						return true;

					string[] prefixMarkers = MoMorphType.PrefixMarkers(cache);
					string[] postfixMarkers = MoMorphType.PostfixMarkers(cache);

					List<string> allMarkers = new List<string>();
					foreach (string s in prefixMarkers)
					{
						allMarkers.Add(s);
					}

					foreach (string s in postfixMarkers)
					{
						if (!allMarkers.Contains(s))
							allMarkers.Add(s);
					}
					allMarkers.Add(" ");

					string[] breakMarkers = new string[allMarkers.Count];
					for (int i = 0; i < allMarkers.Count; ++i)
						breakMarkers[i] = allMarkers[i];

					string fullForm = SandboxBase.MorphemeBreaker.DoBasicFinding(morphs, breakMarkers, prefixMarkers, postfixMarkers);

					using (UndoRedoCommandHelper undoRedoTask = new UndoRedoCommandHelper(Cache,
						argument as Command))
					{
						IWfiAnalysis newAnalysis = Wordform.AnalysesOC.Add(new WfiAnalysis());
						newAnalysis.ApprovalStatusIcon = 1; // Make it human approved.
						int vernWS = StringUtils.GetWsAtOffset(tssWord, 0);
						foreach (string morph in fullForm.Split(Unicode.SpaceChars))
						{
							if (morph != null && morph.Length != 0)
							{
								IWfiMorphBundle mb = newAnalysis.MorphBundlesOS.Append(new WfiMorphBundle());
								mb.Form.SetAlternative(morph, vernWS);
							}
						}
						int outlineFlid = BaseVirtualHandler.GetInstalledHandlerTag(cache, "WfiAnalysis", "HumanApprovedNumber");
						foreach (int haaHvo in Wordform.HumanApprovedAnalyses)
						{
							// Do PropChanged for the outline number for all of them.
							// This fixes LT-5007, as the older ones kept their old number,
							// which could have been a duplicate number.
							cache.PropChanged(
								null,
								PropChangeType.kpctNotifyAll,
								haaHvo,
								outlineFlid,
								0, 0, 0);
						}
						cache.PropChanged(
							null,
							PropChangeType.kpctNotifyAll,
							Wordform.Hvo,
							BaseVirtualHandler.GetInstalledHandlerTag(cache, "WfiWordform", "HumanApprovedAnalyses"),
							0, 1, 0);
					}
				}
			}

			return true;
		}