Exemple #1
0
		/// <summary>
		/// Create a new entry based upon the state of the Dialog.
		/// </summary>
		public void CreateNewEntry()
		{
			bool okToClose = LexFormNotEmpty();
			if (!okToClose)
				throw new ArgumentException("lexical form field should not be empty.");
			Cursor = Cursors.WaitCursor;
			// We don't want the parser to see the new entry till we get done.
			// Note (from RandyR): This probably won't do what you think,
			// because it won't shut down the connection the parser has,
			// so there could still be timeouts or locks.
			// It probably would be a good idea if the parser didn't get excited about reloading,
			// until the entry is completely done being created here, however.
			ParserScheduler parser = null;
			if (ParserFactory.HasParser(m_cache.ServerName, m_cache.DatabaseName,
				m_cache.LangProject.Name.AnalysisDefaultWritingSystem))
			{
				// Getting the parser can fail with an internal error message something like
				//	Object '/8b9d17e1_bb1e_4fb3_b84a_1ac50b02c4ed/gm6vzmwmfhwbcnsyu085vinz_105.rem' has been disconnected or does not exist at the server
				// See LT-8704
				try
				{
					parser = ParserFactory.GetDefaultParser(m_cache.ServerName, m_cache.DatabaseName,
						m_cache.LangProject.Name.AnalysisDefaultWritingSystem);
					if (parser.IsPaused)
						parser = null; // nothing to do when closed
					else
						if (!parser.AttemptToPause())
							Debug.Fail("Could not pause parser.");
				}
				catch
				{
					parser = null;
					Debug.WriteLine("UpdateRealFromSandbox(): ParserFactory.GetDefaultParser() threw an error?!");
				}
			}

			ILexEntry entry = LexEntry.CreateEntry(m_cache, m_morphType, BestTssForm, Gloss,
				m_msaGroupBox.DummyMSA);
			m_entryID = entry.Hvo;
			m_fNewlyCreated = true;
			ILexSense sense = entry.SensesOS.FirstItem;
			m_hvoNewSense = sense.Hvo;
			if (msLexicalForm != null)
			{
				// Save the other writing systems.
				for (int i = 0; i < msLexicalForm.NumberOfWritingSystems; i++)
				{
					int ws;
					ITsString tss = msLexicalForm.ValueAndWs(i, out ws);
					if (tss != null && tss.Text != null)
						entry.SetLexemeFormAlt(ws, tss);
				}
			}
			if (msGloss != null)
			{
				// Save the other writing systems.
				for (int i = 0; i < msGloss.NumberOfWritingSystems; i++)
				{
					int ws;
					ITsString tss = msGloss.ValueAndWs(i, out ws);

					m_cache.MainCacheAccessor.SetMultiStringAlt(sense.Hvo, (int)LexSense.LexSenseTags.kflidGloss, ws, tss);
				}
			}

			HandleAnyFeatures(entry);

			if (m_fComplexForm)
			{
				ILexEntryRef ler = new LexEntryRef();
				entry.EntryRefsOS.Append(ler);
				if (m_complexType != null)
					ler.ComplexEntryTypesRS.Append(m_complexType);
				ler.RefType = 1;
				// This is not wanted anywhere (at the moment).  See LT-10289.
				//string toolName = m_mediator.PropertyTable.GetStringProperty("currentContentControl", null);
				//if (toolName != "lexiconEdit")
				//{
				//    using (LinkEntryOrSenseDlg dlg = new LinkEntryOrSenseDlg())
				//    {
				//        dlg.SetDlgInfo(m_cache, m_mediator, entry);
				//        dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense");
				//        if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
				//        {
				//            ler.ComponentLexemesRS.Append(dlg.SelectedID);
				//            ler.PrimaryLexemesRS.Append(dlg.SelectedID);
				//        }
				//    }
				//}
			}
			// If we paused the parser, restart it now.
			if (parser != null)
				parser.Resume();

			// Not redrawing the list in the GUI and not finding later, so added the following to cause
			// the display to update and find the item.  (LT-3101,2983)
			// The following section was copied from InsertEntryDlgListener::OnDialogInsertItemInVector.
			// Begin copied code

			// Note: This call will cause the RecordClerk to reload,
			// since it won't know anything about the new entry
			int hvoLexDb = m_cache.LangProject.LexDbOAHvo;
			int tagEntries = (int)FDO.Ling.LexDb.LexDbTags.kflidEntries;
			int ihvo = 0;
			ISilDataAccess sda = m_cache.MainCacheAccessor;
			int chvo = sda.get_VecSize(hvoLexDb, tagEntries);
			for (; ihvo < chvo && sda.get_VecItem(hvoLexDb, tagEntries, ihvo) != m_entryID; ihvo++)
				;
			Debug.Assert(ihvo < chvo); // We should find the new entry!
			sda.PropChanged(null,
				(int)PropChangeType.kpctNotifyAll,
				hvoLexDb,
				tagEntries,
				ihvo, // The position it is in the current version of the property.
				1, // inserted 1
				0); // deleted 0

			// End copied code

			Cursor = Cursors.Default;
		}
		/// <summary>
		/// The user selected an item; now we actually need a LexEntryRef.
		/// </summary>
		/// <param name="hvoNew"></param>
		private void AddItem(int hvoNew)
		{
			CheckDisposed();

			bool fForVariant = XmlUtils.GetOptionalBooleanAttributeValue(m_configurationNode, "forVariant", false);
			string sUndo, sRedo;
			if (fForVariant)
			{
				sUndo = LexEdStrings.ksUndoVariantOf;
				sRedo = LexEdStrings.ksRedoVariantOf;
			}
			else
			{
				sUndo = LexEdStrings.ksUndoAddComponent;
				sRedo = LexEdStrings.ksRedoAddComponent;
			}
			using (new UndoRedoTaskHelper(m_obj.Cache, sUndo, sRedo))
			{
				ILexEntry ent = m_obj as ILexEntry;
				// The slice this is part of should only be displayed for lex entries with no EntryRefs.
				Debug.Assert(ent.EntryRefsOS.Count == 0);

				// Adapted from part of DtMenuHandler.AddNewLexEntryRef.
				ILexEntryRef ler = new LexEntryRef();
				ent.EntryRefsOS.Append(ler);
				if (fForVariant)
				{
					ler.VariantEntryTypesRS.Append(ent.Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS[0].Hvo);
					ler.RefType = LexEntryRef.krtVariant;
					ler.HideMinorEntry = 0;
				}
				else
				{
					//ler.ComplexEntryTypesRS.Append(ent.Cache.LangProject.LexDbOA.ComplexEntryTypesOA.PossibilitiesOS[0].Hvo);
					ler.RefType = LexEntryRef.krtComplexForm;
					ler.HideMinorEntry = 1;
					ler.PrimaryLexemesRS.Append(hvoNew);
					ent.ChangeRootToStem();
				}
				ler.ComponentLexemesRS.Append(hvoNew);
				// No automatic propchanged for new objects, need to let the view see it.
				// At that point our slice will be disposed, so don't do anything after this.
				ent.Cache.PropChanged(ent.Hvo, (int)LexEntry.LexEntryTags.kflidEntryRefs, 0, 1, 0);
			}
		}
		/// <summary>
		/// Override method to handle launching of a chooser for selecting lexical entries.
		/// </summary>
		protected override void HandleChooser()
		{
			string displayWs = "analysis vernacular";
			string postDialogMessageTrigger = null;

			if (m_configurationNode != null)
			{
				XmlNode node = m_configurationNode.SelectSingleNode("deParams");
				if (node != null)
				{
					displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower();
					postDialogMessageTrigger = XmlUtils.GetAttributeValue(node, "postChangeMessageTrigger", null);
				}
			}
			Set<int> candidates = m_obj.ReferenceTargetCandidates(m_flid);
			ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, candidates,
				m_displayNameProperty, displayWs);

			using (MorphTypeChooser chooser = GetChooser(labels))
			{
				bool fMadeMorphTypeChange = false;
				ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, m_obj.OwnerHVO);
				chooser.InitializeExtras(m_configurationNode, Mediator);
				chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);
				int hvoType = m_cache.GetObjProperty(m_obj.Hvo, m_flid);
				chooser.MakeSelection(hvoType);
				// LT-4433 changed the Alternate Forms to choose between Stem and Affix automatically
				// when inserting.  Thus, we need the check box in that environment as well.
				//if (m_obj.OwningFlid != (int)LexEntry.LexEntryTags.kflidLexemeForm)
				//    chooser.ShowAllTypesCheckBoxVisible = false;
				if (chooser.ShowDialog() == DialogResult.OK)
				{
					ObjectLabel selected = chooser.ChosenOne;
					int hvoOriginal = TargetHvo;
					string sUndo = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeUndo", m_ksPath);
					string sRedo = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeRedo", m_ksPath);

					bool fRemoveComponents = false;
					if (selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphRoot))
						|| selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphBoundRoot)))
					{
						// changing to root...not allowed to have complex forms.
						foreach (LexEntryRef ler in entry.EntryRefsOS)
						{
							if (ler.RefType == LexEntryRef.krtComplexForm)
							{
								fRemoveComponents = true;
								// If there are no components we will delete without asking...but must then check for more
								// complex forms that DO have components.
								if (ler.ComponentLexemesRS.Count > 0)
								{
									if (MessageBox.Show(FindForm(), DetailControlsStrings.ksRootNoComponentsMessage,
										DetailControlsStrings.ksRootNoComponentsCaption, MessageBoxButtons.YesNo,
										MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0, FwApp.App.HelpFile,
										HelpNavigator.Topic, "khtRootCannotHaveComponents") != DialogResult.Yes)
									{
										return;
									}
									break;
								}
							}
						}
					}

					using (new UndoRedoTaskHelper(entry.Cache, sUndo, sRedo))
					{
						if (fRemoveComponents)
						{
							Set<int> delObjs = new Set<int>();
							foreach (LexEntryRef ler in entry.EntryRefsOS)
							{
								if (ler.RefType == LexEntryRef.krtComplexForm)
									delObjs.Add(ler.Hvo);
							}
							CmObject.DeleteObjects(delObjs, m_cache);
						}

						if (IsStemType(hvoOriginal) || m_obj is MoStemAllomorph)
						{
							if (IsStemType(selected.Hvo))
							{
								TargetHvo = selected.Hvo;
							}
							else
							{
								//have to switch from stem to affix
								fMadeMorphTypeChange = ChangeStemToAffix(entry, selected.Hvo, sUndo, sRedo);
							}
						}
						else
						{
							// original is affix variety
							if (IsStemType(selected.Hvo))
							{
								//have to switch from affix to stem
								fMadeMorphTypeChange = ChangeAffixToStem(entry, selected.Hvo, sUndo, sRedo);
							}
							else
							{
								TargetHvo = selected.Hvo;
							}
						}
						if (selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphPhrase)))
						{
							ILexEntryRef ler = new LexEntryRef();
							entry.EntryRefsOS.Append(ler);
							ler.RefType = LexEntryRef.krtComplexForm;
							ler.HideMinorEntry = 1;
							// No automatic propchanged for new objects, need to let the view see it.
							// At that point our slice will be disposed, so don't do anything after this.
							entry.Cache.PropChanged(entry.Hvo, (int) LexEntry.LexEntryTags.kflidEntryRefs, 0, 1, 0);
						}
					}
				}
			}
		}