コード例 #1
0
ファイル: SandboxBase.cs プロジェクト: sillsdev/WorldPad
			internal void CreateNewEntry(bool fCreateNow, out ILexEntry le, out IMoForm allomorph, out ILexSense sense)
			{
				CheckDisposed();

				int hvoMorph = m_caches.DataAccess.get_ObjectProp(m_hvoMorph, ktagSbMorphForm);
				ITsString tssForm = m_caches.DataAccess.get_MultiStringAlt(hvoMorph,
					ktagSbNamedObjName, m_sandbox.RawWordformWs);
				ITsString tssFullForm = m_sandbox.GetFullMorphForm(m_hvoMorph);
				string form = StrFromTss(tssForm);
				string fullForm = StrFromTss(tssFullForm);

				le = null;
				allomorph = null;
				sense = null;
				int entryID = 0;
				int hvoSense = 0;
				FdoCache cache = m_caches.MainCache;
				// If we don't have a form or it isn't in a current vernacular writing system, give up.
				if (tssForm == null || tssForm.Length == 0 ||
					!LangProject.GetAllWritingSystems("all vernacular", m_caches.MainCache, null, 0, 0).Contains(StringUtils.GetWsOfRun(tssForm,0)))
				{
					return;
				}
				ITsString tssHeadWord = null;
				using (InsertEntryDlg dlg = InsertEntryNow.CreateInsertEntryDlg(fCreateNow))
				{
					SetupDlgToCreateEntry(dlg, tssFullForm, cache);
					dlg.ChangeUseSimilarToCreateAllomorph();
					bool fCreatedEntry = false;
					bool fCreateAllomorph = false;
					if (fCreateNow)
					{
						// just create a new entry based on the given information.
						dlg.CreateNewEntry();
					}
					else
					{
						// bring up the dialog so the user can make further decisions.
						Form mainWnd = m_sandbox.FindForm();
						// Making the form active fixes LT-2344 & LT-2345.
						// I'm (RandyR) not sure what adverse impact might show up by doing this.
						mainWnd.Activate();
						dlg.SetHelpTopic("khtpInsertEntryFromInterlinear");
						if (dlg.ShowDialog(mainWnd) == DialogResult.OK)
							fCreateAllomorph = true;
					}
					dlg.GetDialogInfo(out entryID, out fCreatedEntry);
					if (!fCreatedEntry && !fCreateAllomorph)
						return;

					// Get the appropriate MoForm?
					FdoCache mainCache = m_caches.MainCache;
					le = LexEntry.CreateFromDBObject(mainCache, entryID);
					hvoSense = dlg.NewSenseId;
					if (hvoSense > 0)
						sense = new LexSense(mainCache, hvoSense);
					else if (fCreateAllomorph && le.SensesOS.Count > 0)
						sense = le.SensesOS.FirstItem;

					allomorph = le.FindMatchingAllomorph(tssForm);
					if (allomorph == null)
					{
						try
						{
							allomorph = MoForm.MakeMorph(mainCache, le, tssFullForm);
						}
						catch
						{
							// Try it without any reserved markers.
							allomorph = MoForm.MakeMorph(mainCache, le,
								StringUtils.MakeTss(MoForm.EnsureNoMarkers(fullForm, mainCache),
								m_sandbox.RawWordformWs));
						}
					}
					tssHeadWord = le.HeadWord;
					if (allomorph != null)
						UpdateMorphEntry(allomorph.Hvo, entryID, hvoSense);
				}
			}