/// <summary> /// Handle launching of the MSA editor. /// </summary> protected override void HandleChooser() { using (MsaCreatorDlg dlg = new MsaCreatorDlg()) { IMoMorphSynAnalysis originalMsa = m_obj as IMoMorphSynAnalysis; ILexEntry entry = originalMsa.Owner as ILexEntry; dlg.SetDlgInfo(m_cache, m_persistProvider, m_mediator, m_propertyTable, entry, SandboxGenericMSA.Create(originalMsa), originalMsa.Hvo, true, String.Format(LexEdStrings.ksEditX, Slice.Label)); if (dlg.ShowDialog(FindForm()) == DialogResult.OK) { SandboxGenericMSA sandboxMsa = dlg.SandboxMSA; if (!originalMsa.EqualsMsa(sandboxMsa)) { UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoEditFunction, LexEdStrings.ksRedoEditFunction, entry, () => { originalMsa.UpdateOrReplace(sandboxMsa); }); } } } }
private bool EditExistingMsa() { PopupTree pt = GetPopupTree(); // Force the PopupTree to Hide() to trigger popupTree_PopupTreeClosed(). // This will effectively revert the list selection to a previous confirmed state. // Whatever happens below, we don't want to actually leave the "Modify ..." node selected! // This is at least required if the user selects "Cancel" from the dialog below. if (m_sense.MorphoSyntaxAnalysisRA != null) { pt.SelectObj(m_sense.MorphoSyntaxAnalysisRA.Hvo); } #if __MonoCS__ // If Popup tree is shown whilest the dialog is shown, the first click on the dialog is consumed by the // Popup tree, (and closes it down). On .NET the PopupTree appears to be automatically closed. pt.HideForm(); #endif SandboxGenericMSA dummyMsa = SandboxGenericMSA.Create(m_sense.MorphoSyntaxAnalysisRA); using (MsaCreatorDlg dlg = new MsaCreatorDlg()) { dlg.SetDlgInfo(Cache, m_persistProvider, m_mediator, m_sense.Entry, dummyMsa, m_sense.MorphoSyntaxAnalysisRA.Hvo, true, m_sEditGramFunc); if (dlg.ShowDialog(ParentForm) == DialogResult.OK) { Cache.DomainDataByFlid.BeginUndoTask(String.Format(LexTextControls.ksUndoSetX, FieldName), String.Format(LexTextControls.ksRedoSetX, FieldName)); m_sense.SandboxMSA = dlg.SandboxMSA; Cache.DomainDataByFlid.EndUndoTask(); LoadPopupTree(m_sense.MorphoSyntaxAnalysisRA.Hvo); return(true); } } return(false); }
/// <summary> /// Helper /// </summary> private LexEntryComponents SetupComponentsForEntryCreation(out int germanWsId, out ILexEntryFactory lexFactory, out ITsString tssGermanGloss) { germanWsId = Cache.WritingSystemFactory.GetWsFromStr("de"); Cache.LangProject.AnalysisWritingSystems.Add( Cache.WritingSystemFactory.get_EngineOrNull(germanWsId) as IWritingSystem); lexFactory = Cache.ServiceLocator.GetInstance<ILexEntryFactory>(); tssGermanGloss = Cache.TsStrFactory.MakeString("da", germanWsId); var tssVernacForm = Cache.TsStrFactory.MakeString("bunk", Cache.WritingSystemFactory.GetWsFromStr(Cache.LangProject.DefaultVernacularWritingSystem.Id)); var msa = new SandboxGenericMSA { MainPOS = Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS.Where( pos => pos.Name.AnalysisDefaultWritingSystem.Text == "noun") .Cast<IPartOfSpeech>() .FirstOrDefault(), MsaType = MsaType.kStem }; var lexEntryComponents = new LexEntryComponents() { GlossAlternatives = new List<ITsString>() { tssGermanGloss }, LexemeFormAlternatives = new List<ITsString>() { tssVernacForm }, MSA = msa, MorphType = Cache.LangProject.LexDbOA.MorphTypesOA.PossibilitiesOS.Where( mt => mt.Name.AnalysisDefaultWritingSystem.Text == "stem") .Cast<IMoMorphType>() .FirstOrDefault() }; return lexEntryComponents; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the lexeme to the lexicon. /// </summary> /// <exception cref="ArgumentException">if matching lexeme is already in lexicon</exception> /// ------------------------------------------------------------------------------------ public void AddLexeme(LexicalEntry lexeme) { LexicalProviderManager.ResetLexicalProviderTimer(); Logger.WriteEvent("Adding new lexeme from an external application: " + lexeme.LexicalForm); NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => { string sForm = lexeme.LexicalForm; switch (lexeme.Type) { case LexemeType.Word: ITsString tss = TsStringUtils.MakeTss(lexeme.LexicalForm, m_cache.DefaultVernWs); m_cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(tss); break; default: { SandboxGenericMSA msa = new SandboxGenericMSA(); msa.MsaType = (lexeme.Type == LexemeType.Stem) ? MsaType.kStem : MsaType.kUnclassified; IMoMorphType morphType = GetMorphTypeForLexemeType(lexeme.Type); ITsString tssForm = TsStringUtils.MakeTss(sForm, m_cache.DefaultVernWs); m_cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(morphType, tssForm, null, msa); break; } } }); }
private ILexEntry CreateSimpleEntry(string form, string gloss) { var lexAlt = TsStringUtils.MakeTss(form, m_wsVern); var glossAlt = TsStringUtils.MakeTss(gloss, m_wsAnalysis); var msa = new SandboxGenericMSA { MainPOS = m_noun, MsaType = MsaType.kStem }; var leComp = new LexEntryComponents { MSA = msa, MorphType = m_stem }; leComp.GlossAlternatives.Add(glossAlt); leComp.LexemeFormAlternatives.Add(lexAlt); var entry = m_leFact.Create(leComp); return entry; }
void LaunchChooseFromMasterCategoryListOnIdle(object sender, EventArgs e) { Application.Idle -= LaunchChooseFromMasterCategoryListOnIdle; // now being handled // now launch the dialog using (MasterCategoryListDlg dlg = new MasterCategoryListDlg()) { dlg.SetDlginfo(CategoryList, m_mediator, m_propertyTable, false, null); switch (dlg.ShowDialog(m_parentOfPopupMgr)) { case DialogResult.OK: var sandboxMsa = new SandboxGenericMSA(); sandboxMsa.MainPOS = dlg.SelectedPOS; sandboxMsa.MsaType = m_sense.GetDesiredMsaType(); UndoableUnitOfWorkHelper.Do(String.Format(LexTextControls.ksUndoSetX, FieldName), String.Format(LexTextControls.ksRedoSetX, FieldName), m_sense, () => { m_sense.SandboxMSA = sandboxMsa; }); // Under certain circumstances (LT-11548) 'this' was disposed during the EndUndotask above! // That's why we're now launching this on idle. // Here's hoping we can get away without doing this! (It doesn't seem to make a difference.) //LoadPopupTree(m_sense.MorphoSyntaxAnalysisRA.Hvo); // everything should be setup with new node selected, so return. break; case DialogResult.Yes: // represents a click on the link to create a new Grammar Category. // Post a message so that we jump to Grammar(area)/Categories tool. // Do this before we close any parent dialog in case // the parent wants to check to see if such a Jump is pending. // NOTE: We use PostMessage here, rather than SendMessage which // disposes of the PopupTree before we and/or our parents might // be finished using it (cf. LT-2563). m_mediator.PostMessage("FollowLink", new FwLinkArgs("posEdit", dlg.SelectedPOS.Guid)); if (m_parentOfPopupMgr != null && m_parentOfPopupMgr.Modal) { // Close the dlg that opened the master POS dlg, // since its hotlink was used to close it, // and a new POS has been created. m_parentOfPopupMgr.DialogResult = DialogResult.Cancel; m_parentOfPopupMgr.Close(); } break; default: // NOTE: If the user has selected "Cancel", then don't change // our m_lastConfirmedNode to the "More..." node. Keep it // the value set by popupTree_PopupTreeClosed() when we // called pt.Hide() above. (cf. comments in LT-2522) break; } } }
protected ILexSense AddSenseToEntry(List <ICmObject> addList, ILexEntry le, string gloss, IPartOfSpeech catPoss) { var msa = new SandboxGenericMSA(); msa.MainPOS = catPoss; var sense = m_senseFact.Create(le, msa, gloss); addList.Add(sense); return(sense); }
/// <summary> /// Create a new sense and add it to the given entry. /// </summary> /// <param name="entry"></param> /// <param name="sandboxMSA"></param> /// <param name="gloss"></param> /// <returns></returns> public ILexSense Create(ILexEntry entry, SandboxGenericMSA sandboxMSA, ITsString gloss) { var sense = new LexSense(); entry.SensesOS.Add(sense); sense.SandboxMSA = sandboxMSA; if (gloss != null) { sense.Gloss.set_String(gloss.get_WritingSystemAt(0), gloss); } return sense; }
protected ILexSense AddSubSenseToSense(List <ICmObject> addList, ILexSense ls, string gloss, IPartOfSpeech catPoss) { var msa = new SandboxGenericMSA(); msa.MainPOS = catPoss; var sense = m_senseFact.Create(new Guid(), ls); sense.SandboxMSA = msa; sense.Gloss.set_String(Cache.DefaultAnalWs, gloss); addList.Add(sense); return(sense); }
/// <summary> /// Create a new sense and add it to the given entry. /// </summary> /// <param name="entry"></param> /// <param name="sandboxMSA"></param> /// <param name="gloss">string form of gloss, will be put in DefaultAnalysis ws</param> /// <returns></returns> public ILexSense Create(ILexEntry entry, SandboxGenericMSA sandboxMSA, string gloss) { // Handle gloss. if (!string.IsNullOrEmpty(gloss)) { var defAnalWs = entry.Cache.DefaultAnalWs; var gls = entry.Cache.TsStrFactory.MakeString(gloss, defAnalWs); return Create(entry, sandboxMSA, gls); } return Create(entry, sandboxMSA, (ITsString)null); }
private void CreateEmptyMsa() { SandboxGenericMSA dummyMsa = new SandboxGenericMSA(); dummyMsa.MsaType = m_sense.GetDesiredMsaType(); // To make it fully 'not sure' we must discard knowledge of affix type. if (dummyMsa.MsaType == MsaType.kInfl || dummyMsa.MsaType == MsaType.kDeriv) { dummyMsa.MsaType = MsaType.kUnclassified; } UndoableUnitOfWorkHelper.Do(string.Format(LexTextControls.ksUndoSetX, FieldName), string.Format(LexTextControls.ksRedoSetX, FieldName), m_sense, () => { m_sense.SandboxMSA = dummyMsa; }); }
private ILexEntry CreateSimpleEntry(string form, string gloss) { var lexAlt = TsStringUtils.MakeString(form, m_wsVern); var glossAlt = TsStringUtils.MakeString(gloss, m_wsAnalysis); var msa = new SandboxGenericMSA { MainPOS = m_noun, MsaType = MsaType.kStem }; var leComp = new LexEntryComponents { MSA = msa, MorphType = m_stem }; leComp.GlossAlternatives.Add(glossAlt); leComp.LexemeFormAlternatives.Add(lexAlt); var entry = m_leFact.Create(leComp); return(entry); }
protected ILexEntry AddLexeme(List <ICmObject> addList, string lexForm, IMoMorphType morphTypePoss, string gloss, IPartOfSpeech categoryPoss) { var msa = new SandboxGenericMSA { MainPOS = categoryPoss }; var comp = new LexEntryComponents { MorphType = morphTypePoss, MSA = msa }; comp.GlossAlternatives.Add(m_tssFact.MakeString(gloss, Cache.DefaultAnalWs)); comp.LexemeFormAlternatives.Add(m_tssFact.MakeString(lexForm, Cache.DefaultVernWs)); var entry = m_entryFact.Create(comp); addList.Add(entry); return(entry); }
public void SetSandboxMSA() { var servLoc = Cache.ServiceLocator; var le = servLoc.GetInstance <ILexEntryFactory>().Create(); var ls = servLoc.GetInstance <ILexSenseFactory>().Create(); le.SensesOS.Add(ls); var msaOld = servLoc.GetInstance <IMoStemMsaFactory>().Create(); le.MorphoSyntaxAnalysesOC.Add(msaOld); ls.MorphoSyntaxAnalysisRA = msaOld; msaOld.MsFeaturesOA = servLoc.GetInstance <IFsFeatStrucFactory>().Create(); msaOld.MsFeaturesOA.FeatureSpecsOC.Add(servLoc.GetInstance <IFsOpenValueFactory>().Create()); var newMsa = new SandboxGenericMSA(); ((LexSense)ls).SandboxMSA = newMsa; Assert.That(((IMoStemMsa)ls.MorphoSyntaxAnalysisRA).MsFeaturesOA, Is.Not.Null); Assert.That(ls.MorphoSyntaxAnalysisRA, Is.Not.EqualTo(msaOld)); // Check that we can use it to set an MSA that matches an existing one. This should result // in the two senses havingt the same MSA and the unused one being deleted (but not // a crash trying to delete it twice--LT-11195) var sense2 = servLoc.GetInstance <ILexSenseFactory>().Create(); le.SensesOS.Add(sense2); sense2.MorphoSyntaxAnalysisRA = ls.MorphoSyntaxAnalysisRA; newMsa = new SandboxGenericMSA(); var posList = Cache.LangProject.PartsOfSpeechOA; if (posList == null) { posList = servLoc.GetInstance <ICmPossibilityListFactory>().Create(); Cache.LangProject.PartsOfSpeechOA = posList; } var newPos = servLoc.GetInstance <IPartOfSpeechFactory>().Create(); posList.PossibilitiesOS.Add(newPos); newMsa.MainPOS = newPos; ls.SandboxMSA = newMsa; Assert.That(le.MorphoSyntaxAnalysesOC.Count, Is.EqualTo(2)); sense2.SandboxMSA = newMsa; Assert.That(sense2.MorphoSyntaxAnalysisRA, Is.EqualTo(ls.MorphoSyntaxAnalysisRA)); Assert.That(le.MorphoSyntaxAnalysesOC.Count, Is.EqualTo(1)); }
protected ILexEntry AddVariantLexeme(List <ICmObject> addList, IVariantComponentLexeme origLe, string lexForm, IMoMorphType morphTypePoss, string gloss, IPartOfSpeech categoryPoss, ILexEntryType varType) { Assert.IsNotNull(varType, "Need a variant entry type!"); var msa = new SandboxGenericMSA { MainPOS = categoryPoss }; var comp = new LexEntryComponents { MorphType = morphTypePoss, MSA = msa }; comp.GlossAlternatives.Add(m_tssFact.MakeString(gloss, Cache.DefaultAnalWs)); comp.LexemeFormAlternatives.Add(m_tssFact.MakeString(lexForm, Cache.DefaultVernWs)); var entry = m_entryFact.Create(comp); entry.MakeVariantOf(origLe, varType); addList.Add(entry); return(entry); }
private void SetupForLexSenseFactoryCreate(out int germanWsId, out ITsString tssGermanGloss, out ILexEntry entry, out ILexSenseFactory lexSenseFactory, out SandboxGenericMSA msa) { germanWsId = Cache.WritingSystemFactory.GetWsFromStr("de"); Cache.LangProject.AnalysisWritingSystems.Add( Cache.WritingSystemFactory.get_EngineOrNull(germanWsId) as IWritingSystem); var lexFactory = Cache.ServiceLocator.GetInstance<ILexEntryFactory>(); tssGermanGloss = Cache.TsStrFactory.MakeString("da", germanWsId); entry = lexFactory.Create(); lexSenseFactory = Cache.ServiceLocator.GetInstance<ILexSenseFactory>(); msa = new SandboxGenericMSA { MainPOS = Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS.Where( pos => pos.Name.AnalysisDefaultWritingSystem.Text == "noun") .Cast<IPartOfSpeech>() .FirstOrDefault(), MsaType = MsaType.kStem }; }
private void SetupForLexSenseFactoryCreate(out int germanWsId, out ITsString tssGermanGloss, out ILexEntry entry, out ILexSenseFactory lexSenseFactory, out SandboxGenericMSA msa) { germanWsId = Cache.WritingSystemFactory.GetWsFromStr("de"); Cache.LangProject.AnalysisWritingSystems.Add( Cache.WritingSystemFactory.get_EngineOrNull(germanWsId) as CoreWritingSystemDefinition); var lexFactory = Cache.ServiceLocator.GetInstance <ILexEntryFactory>(); tssGermanGloss = TsStringUtils.MakeString("da", germanWsId); entry = lexFactory.Create(); lexSenseFactory = Cache.ServiceLocator.GetInstance <ILexSenseFactory>(); msa = new SandboxGenericMSA { MainPOS = Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS.Where( pos => pos.Name.AnalysisDefaultWritingSystem.Text == "noun") .Cast <IPartOfSpeech>() .FirstOrDefault(), MsaType = MsaType.kStem }; }
/// <summary> /// Helper /// </summary> private LexEntryComponents SetupComponentsForEntryCreation(out int germanWsId, out ILexEntryFactory lexFactory, out ITsString tssGermanGloss) { germanWsId = Cache.WritingSystemFactory.GetWsFromStr("de"); Cache.LangProject.AnalysisWritingSystems.Add( Cache.WritingSystemFactory.get_EngineOrNull(germanWsId) as IWritingSystem); lexFactory = Cache.ServiceLocator.GetInstance <ILexEntryFactory>(); tssGermanGloss = Cache.TsStrFactory.MakeString("da", germanWsId); var tssVernacForm = Cache.TsStrFactory.MakeString("bunk", Cache.WritingSystemFactory.GetWsFromStr(Cache.LangProject.DefaultVernacularWritingSystem.Id)); var msa = new SandboxGenericMSA { MainPOS = Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS.Where( pos => pos.Name.AnalysisDefaultWritingSystem.Text == "noun") .Cast <IPartOfSpeech>() .FirstOrDefault(), MsaType = MsaType.kStem }; var lexEntryComponents = new LexEntryComponents() { GlossAlternatives = new List <ITsString>() { tssGermanGloss }, LexemeFormAlternatives = new List <ITsString>() { tssVernacForm }, MSA = msa, MorphType = Cache.LangProject.LexDbOA.MorphTypesOA.PossibilitiesOS.Where( mt => mt.Name.AnalysisDefaultWritingSystem.Text == "stem") .Cast <IMoMorphType>() .FirstOrDefault() }; return(lexEntryComponents); }
internal ILexEntry CreateEntry(LexemeKey key) { CreateEntryIndexIfNeeded(); ITsString tss = TsStringUtils.MakeString(key.LexicalForm.Normalize(NormalizationForm.FormD), DefaultVernWs); var msa = new SandboxGenericMSA { MsaType = (key.Type == LexemeType.Stem) ? MsaType.kStem : MsaType.kUnclassified }; ILexEntry entry = m_cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(GetMorphTypeForLexemeType(key.Type), tss, (ITsString)null, msa); m_homographNumbers.GetOrCreateValue(entry).Number = key.Homograph; var homographKey = new LexemeKey(key.Type, key.LexicalForm); SortedSet <ILexEntry> entries; if (!m_entryIndex.TryGetValue(homographKey, out entries)) { entries = new SortedSet <ILexEntry>(m_entryComparer); m_entryIndex[homographKey] = entries; } entries.Add(entry); return(entry); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new entry. /// </summary> /// <param name="morphType">Type of the morph.</param> /// <param name="tssLexemeForm">The TSS lexeme form.</param> /// <param name="gloss">The gloss.</param> /// <param name="sandboxMSA">The dummy MSA.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public ILexEntry Create(IMoMorphType morphType, ITsString tssLexemeForm, ITsString gloss, SandboxGenericMSA sandboxMSA) { var entry = Create(); var sense = m_cache.ServiceLocator.GetInstance<ILexSenseFactory>().Create(entry, sandboxMSA, gloss); if (morphType.Guid == MoMorphTypeTags.kguidMorphCircumfix) { m_cache.ServiceLocator.GetInstance<IMoAffixAllomorphFactory>().CreateCircumfix( entry, sense, tssLexemeForm, morphType); } else { #pragma warning disable 168 var allomorph = MoForm.CreateAllomorph(entry, sense.MorphoSyntaxAnalysisRA, tssLexemeForm, morphType, true); #pragma warning restore 168 } // (We don't want a citation form by default. See LT-7220.) return entry; }
/// <summary> /// This is invoked (using reflection) by an XmlRDEBrowseView when the user presses /// "Enter" in an RDE view that is displaying lexeme form and definition. /// (Maybe also on loss of focus, switch domain, etc?) /// It creates a new entry, lexeme form, and sense that are linked to the specified domain. /// Typically, later, a call to RDEMergeSense will be made to see whether this /// new entry should be merged into some existing sense. /// </summary> /// <param name="hvoDomain">database id of the semantic domain</param> /// <param name="columns"></param> /// <param name="rgtss"></param> /// <param name="stringTbl"></param> public int RDENewSense(int hvoDomain, List<XmlNode> columns, ITsString[] rgtss, StringTable stringTbl) { Debug.Assert(hvoDomain != 0); Debug.Assert(rgtss.Length == columns.Count); // Make a new sense in a new entry. ILexEntry le = m_cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create(); IMoForm morph = null; // create a LexSense that has the given definition and semantic domain // Needs to be LexSense, since later calls use non-interface methods. LexSense ls = Create() as LexSense; le.SensesOS.Add(ls); #pragma warning disable 219 ILgWritingSystemFactory wsf = m_cache.WritingSystemFactory; #pragma warning restore 219 // go through each column and store the appropriate information. for (int i = 0; i < columns.Count; ++i) { // Review: Currently we key off the column labels to determine which columns // correspond to CitationForm and which correspond to Definition. // Ideally we'd like to get at the flids used to build the column display strings. // Instead of passing in only ITsStrings, we could pass in a structure containing // an index of strings with any corresponding flids. Here we'd expect strings // based upon either LexemeForm.Form or LexSense.Definition. We could probably // do this as part of the solution to handling duplicate columns in LT-3763. XmlNode column = columns[i] as XmlNode; string columnLabel = XmlUtils.GetManditoryAttributeValue(column, "label"); ITsTextProps ttp = rgtss[i].get_PropertiesAt(0); int var; int ws = ttp.GetIntPropValues((int) FwTextPropType.ktptWs, out var); Debug.Assert(ws != 0); ITsString tssStr = rgtss[i]; string trimmedForm = tssStr.Text; if (trimmedForm == null) continue; // no point in setting empty field, and MakeMorph may blow up trimmedForm = trimmedForm.Trim(); if (trimmedForm.Length == 0) continue; // Note: the four column labels we check for should NOT be localized, as we are comparing with // the label that appears in the original XML configuration file. Localization is not applied // to that file, but using it as a base, we look up the localized string to display in the tool. if (columnLabel.StartsWith(@"Word (Lexeme Form)")) { if (morph == null) morph = MakeMorphRde(le, tssStr, ws, trimmedForm); else { // The type of MoForm has been determined by a previous column, but in any case, we don't want // morpheme break characters in the lexeme form. morph.Form.set_String(ws, MorphServices.EnsureNoMarkers(trimmedForm, m_cache)); } Debug.Assert(le.LexemeFormOA != null); } else if (columnLabel.StartsWith(@"Word (Citation Form)")) { if (morph == null) { morph = MakeMorphRde(le, tssStr, ws, trimmedForm); // We'll set the value based on all the nice logic in MakeMorph for trimming morpheme-type indicators le.CitationForm.set_String(ws, morph.Form.get_String(ws)); morph.Form.set_String(ws, ""); // and this isn't really the lexeme form, so leave that empty. } else { // The type of MoForm has been determined by a previous column, but in any case, we don't want // morpheme break characters in the citation form. le.CitationForm.set_String(ws, MorphServices.EnsureNoMarkers(trimmedForm, m_cache)); } } else if (columnLabel.StartsWith(@"Meaning (Definition)")) { if (trimmedForm != "") ls.Definition.set_String(ws, trimmedForm); } else if (columnLabel.StartsWith(@"Meaning (Gloss)")) { if (trimmedForm != "") ls.Gloss.set_String(ws, trimmedForm); } else if (!HandleTransduceColum(ls, column, ws, tssStr)) { Debug.Fail("column (" + columnLabel + ") not supported."); } } if (morph == null) morph = le.LexemeFormOA = new MoStemAllomorph(); ls.SemanticDomainsRC.Add(m_cache.ServiceLocator.GetObject(hvoDomain) as CmSemanticDomain); if (le.MorphoSyntaxAnalysesOC.Count == 0) { // Commonly, it's a new entry with no MSAs; make sure it has at least one. // This way of doing it allows a good bit of code to be shared with the normal // creation path, as if the user made a stem but didn't fill in any grammatical // information. SandboxGenericMSA dummyMsa = new SandboxGenericMSA(); if (morph != null && morph is IMoAffixForm) dummyMsa.MsaType = MsaType.kUnclassified; else dummyMsa.MsaType = MsaType.kStem; ls.SandboxMSA = dummyMsa; } // We don't want a partial MSA created, so don't bother doing anything // about setting ls.MorphoSyntaxAnalysisRA return ls.Hvo; }
/// <summary> /// Initialize the dialog before showing it. /// </summary> /// <param name="cache"></param> /// <param name="entry"></param> /// <param name="titleForEdit">Edit title appropriate to the button's context.</param> public void SetDlgInfo(FdoCache cache, IPersistenceProvider persistProvider, Mediator mediator, ILexEntry entry, SandboxGenericMSA sandboxMsa, int hvoOriginalMsa, bool useForEdit, string titleForEdit) { CheckDisposed(); Debug.Assert(m_cache == null); MsaType msaType = sandboxMsa.MsaType; m_cache = cache; m_mediator = mediator; if (useForEdit) { // Change the window title and the OK button text. Text = titleForEdit; s_helpTopic = "khtpEditGrammaticalFunction"; btnOk.Text = LexText.Controls.LexTextControls.ks_OK; } helpProvider.HelpNamespace = mediator.HelpTopicProvider.HelpFile; helpProvider.SetHelpKeyword(this, mediator.HelpTopicProvider.GetHelpString(s_helpTopic)); helpProvider.SetHelpNavigator(this, HelpNavigator.Topic); // Set font, writing system factory, and code for the edit box. float fntSize = label1.Font.Size * 2.0F; IWritingSystem defVernWs = m_cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem; m_fwtbCitationForm.Font = new Font(defVernWs.DefaultFontName, fntSize); m_fwtbCitationForm.WritingSystemFactory = m_cache.WritingSystemFactory; m_fwtbCitationForm.WritingSystemCode = defVernWs.Handle; m_fwtbCitationForm.AdjustForStyleSheet(this, null, mediator); m_fwtbCitationForm.AdjustStringHeight = false; m_fwtbCitationForm.Tss = entry.HeadWord; m_fwtbCitationForm.HasBorder = false; m_fwtbSenses.Font = new Font(defVernWs.DefaultFontName, fntSize); m_fwtbSenses.WritingSystemFactory = m_cache.WritingSystemFactory; m_fwtbSenses.WritingSystemCode = defVernWs.Handle; m_fwtbSenses.AdjustForStyleSheet(this, null, mediator); m_fwtbSenses.AdjustStringHeight = false; ITsIncStrBldr tisb = TsIncStrBldrClass.Create(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_cache.DefaultAnalWs); var msaRepository = m_cache.ServiceLocator.GetInstance<IMoMorphSynAnalysisRepository>(); if (hvoOriginalMsa != 0) { foreach (var sense in entry.AllSenses) { if (sense.MorphoSyntaxAnalysisRA != null) { if (sense.MorphoSyntaxAnalysisRA == msaRepository.GetObject(hvoOriginalMsa)) { if (tisb.Text != null) tisb.Append(", "); // REVIEW: IS LOCALIZATION NEEDED FOR BUILDING THIS LIST? tisb.AppendTsString(sense.ShortNameTSS); } } } } m_fwtbSenses.Tss = tisb.GetString(); m_fwtbSenses.HasBorder = false; m_msaGroupBox.Initialize(m_cache, m_mediator, this, sandboxMsa); int oldHeight = m_msaGroupBox.Height; int newHeight = Math.Max(oldHeight, m_msaGroupBox.PreferredHeight); int delta = newHeight - oldHeight; if (delta > 0) { m_msaGroupBox.AdjustInternalControlsAndGrow(); Debug.Assert(m_msaGroupBox.Height == m_msaGroupBox.PreferredHeight); FontHeightAdjuster.GrowDialogAndAdjustControls(this, delta, m_msaGroupBox); } if (mediator != null) { // Reset window location. // Get location to the stored values, if any. object locWnd = m_mediator.PropertyTable.GetValue("msaCreatorDlgLocation"); // JohnT: this dialog can't be resized. So it doesn't make sense to // remember a size. If we do, we need to override OnLoad (as in SimpleListChooser) // to prevent the dialog growing every time at 120 dpi. But such an override // makes it too small to show all the controls at the default size. // It's better just to use the default size until it's resizeable for some reason. //m_mediator.PropertyTable.GetValue("msaCreatorDlgSize"); object szWnd = this.Size; if (locWnd != null && szWnd != null) { Rectangle rect = new Rectangle((Point)locWnd, (Size)szWnd); ScreenUtils.EnsureVisibleRect(ref rect); DesktopBounds = rect; StartPosition = FormStartPosition.Manual; } } }
/// <summary> /// Initialize the dialog before showing it. /// </summary> /// <param name="cache"></param> /// <param name="entry"></param> /// <param name="titleForEdit">Edit title appropriate to the button's context.</param> public void SetDlgInfo(FdoCache cache, IPersistenceProvider persistProvider, Mediator mediator, ILexEntry entry, SandboxGenericMSA sandboxMsa, int hvoOriginalMsa, bool useForEdit, string titleForEdit) { CheckDisposed(); Debug.Assert(m_cache == null); MsaType msaType = sandboxMsa.MsaType; m_cache = cache; m_mediator = mediator; if (useForEdit) { // Change the window title and the OK button text. Text = titleForEdit; s_helpTopic = "khtpEditGrammaticalFunction"; btnOk.Text = LexText.Controls.LexTextControls.ks_OK; } helpProvider.HelpNamespace = mediator.HelpTopicProvider.HelpFile; helpProvider.SetHelpKeyword(this, mediator.HelpTopicProvider.GetHelpString(s_helpTopic)); helpProvider.SetHelpNavigator(this, HelpNavigator.Topic); // Set font, writing system factory, and code for the edit box. float fntSize = label1.Font.Size * 2.0F; IWritingSystem defVernWs = m_cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem; m_fwtbCitationForm.Font = new Font(defVernWs.DefaultFontName, fntSize); m_fwtbCitationForm.WritingSystemFactory = m_cache.WritingSystemFactory; m_fwtbCitationForm.WritingSystemCode = defVernWs.Handle; m_fwtbCitationForm.AdjustForStyleSheet(this, null, mediator); m_fwtbCitationForm.AdjustStringHeight = false; m_fwtbCitationForm.Tss = entry.HeadWord; m_fwtbCitationForm.HasBorder = false; m_fwtbSenses.Font = new Font(defVernWs.DefaultFontName, fntSize); m_fwtbSenses.WritingSystemFactory = m_cache.WritingSystemFactory; m_fwtbSenses.WritingSystemCode = defVernWs.Handle; m_fwtbSenses.AdjustForStyleSheet(this, null, mediator); m_fwtbSenses.AdjustStringHeight = false; ITsIncStrBldr tisb = TsIncStrBldrClass.Create(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_cache.DefaultAnalWs); var msaRepository = m_cache.ServiceLocator.GetInstance <IMoMorphSynAnalysisRepository>(); if (hvoOriginalMsa != 0) { foreach (var sense in entry.AllSenses) { if (sense.MorphoSyntaxAnalysisRA != null) { if (sense.MorphoSyntaxAnalysisRA == msaRepository.GetObject(hvoOriginalMsa)) { if (tisb.Text != null) { tisb.Append(", "); // REVIEW: IS LOCALIZATION NEEDED FOR BUILDING THIS LIST? } tisb.AppendTsString(sense.ShortNameTSS); } } } } m_fwtbSenses.Tss = tisb.GetString(); m_fwtbSenses.HasBorder = false; m_msaGroupBox.Initialize(m_cache, m_mediator, this, sandboxMsa); int oldHeight = m_msaGroupBox.Height; int newHeight = Math.Max(oldHeight, m_msaGroupBox.PreferredHeight); int delta = newHeight - oldHeight; if (delta > 0) { m_msaGroupBox.AdjustInternalControlsAndGrow(); Debug.Assert(m_msaGroupBox.Height == m_msaGroupBox.PreferredHeight); FontHeightAdjuster.GrowDialogAndAdjustControls(this, delta, m_msaGroupBox); } if (mediator != null) { // Reset window location. // Get location to the stored values, if any. object locWnd = m_mediator.PropertyTable.GetValue("msaCreatorDlgLocation"); // JohnT: this dialog can't be resized. So it doesn't make sense to // remember a size. If we do, we need to override OnLoad (as in SimpleListChooser) // to prevent the dialog growing every time at 120 dpi. But such an override // makes it too small to show all the controls at the default size. // It's better just to use the default size until it's resizeable for some reason. //m_mediator.PropertyTable.GetValue("msaCreatorDlgSize"); object szWnd = this.Size; if (locWnd != null && szWnd != null) { Rectangle rect = new Rectangle((Point)locWnd, (Size)szWnd); ScreenUtils.EnsureVisibleRect(ref rect); DesktopBounds = rect; StartPosition = FormStartPosition.Manual; } } }
/// <summary> /// Create a new MoUnclassifiedAffixMsa, based on the given sandbox MSA. /// </summary> /// <param name="entry">The entry.</param> /// <param name="sandboxMsa">The sandbox msa.</param> /// <returns></returns> public IMoUnclassifiedAffixMsa Create(ILexEntry entry, SandboxGenericMSA sandboxMsa) { Debug.Assert(sandboxMsa.MsaType == MsaType.kUnclassified); var uncMsa = new MoUnclassifiedAffixMsa(); entry.MorphoSyntaxAnalysesOC.Add(uncMsa); if (sandboxMsa.MainPOS != null) uncMsa.PartOfSpeechRA = sandboxMsa.MainPOS; return uncMsa; }
/// <summary> /// Update an extant MSA to the new values in the sandbox MSA, /// or make a new MSA with the values in the sandbox msa. /// </summary> /// <param name="sandboxMsa"></param> /// <returns></returns> public override IMoMorphSynAnalysis UpdateOrReplace(SandboxGenericMSA sandboxMsa) { if (sandboxMsa.MsaType == MsaType.kInfl) { if (PartOfSpeechRA != sandboxMsa.MainPOS) PartOfSpeechRA = sandboxMsa.MainPOS; if (sandboxMsa.Slot != null && !SlotsRC.Contains(sandboxMsa.Slot)) SlotsRC.Add(sandboxMsa.Slot); // Remove any slots that are not legal for the current POS. IEnumerable<IMoInflAffixSlot> allSlots; if (PartOfSpeechRA == null) allSlots = Enumerable.Empty<IMoInflAffixSlot>(); else allSlots = PartOfSpeechRA.AllAffixSlots; foreach (IMoInflAffixSlot slot in SlotsRC.ToArray()) { if (!allSlots.Contains(slot)) SlotsRC.Remove(slot); } return this; } return base.UpdateOrReplace(sandboxMsa); }
/// <summary> /// Determines whether the specified Sandbox MSA is equal to the current MSA. /// </summary> /// <param name="msa">The MoStemMsa to compare with the current MoStemMsa.</param> /// <returns>true if the specified MoStemMsa is equal to the current MoStemMsa; otherwise, false.</returns> public override bool EqualsMsa(SandboxGenericMSA msa) { // This is the behavior defined by Object.Equals(). if (msa == null) return false; // Make sure that we can cast this object to a MoStemMsa. if (msa.MsaType != MsaType.kInfl) return false; if (PartOfSpeechRA != msa.MainPOS) return false; // Can't set these two from the dialog, if non-null, we are not equal. if (FromProdRestrictRC.Count != 0) return false; if (InflFeatsOA != null && !InflFeatsOA.IsEmpty) return false; // TODO: Add checks for other properties, when we support using them. if (msa.Slot == null) return (SlotsRC.Count == 0); else return SlotsRC.Count == 1 && SlotsRC.Contains(msa.Slot); }
/// <summary> /// Determines whether the specified Sandbox MSA is equal to the current MSA. /// </summary> /// <param name="msa">The MoStemMsa to compare with the current MoStemMsa.</param> /// <returns>true if the specified MoStemMsa is equal to the current MoStemMsa; otherwise, false.</returns> public override bool EqualsMsa(SandboxGenericMSA msa) { // This is the behavior defined by Object.Equals(). if (msa == null) return false; // Make sure that we can cast this object to a MoStemMsa. if (msa.MsaType != MsaType.kStem) return false; // The dummy generic currently can't have any of these, so if this does, they don't match. if (InflectionClassRA != null || (MsFeaturesOA != null && !MsFeaturesOA.IsEmpty) || (ProdRestrictRC.Count != 0) || (FromPartsOfSpeechRC.Count != 0)) return false; // TODO: Add checks for other properties, when we support using them. return PartOfSpeechRA == msa.MainPOS; }
/// <summary> /// Creates a new LexEntry with the given fields /// </summary> /// <param name="morphType"></param> /// <param name="tssLexemeForm"></param> /// <param name="gloss">string for gloss, placed in DefaultAnalysis ws</param> /// <param name="sandboxMSA"></param> /// <returns></returns> public ILexEntry Create(IMoMorphType morphType, ITsString tssLexemeForm, string gloss, SandboxGenericMSA sandboxMSA) { int writingSystem = m_cache.WritingSystemFactory.GetWsFromStr(m_cache.LangProject.DefaultAnalysisWritingSystem.Id); var tssGloss = m_cache.TsStrFactory.MakeString(gloss, writingSystem); return Create(morphType, tssLexemeForm, tssGloss, sandboxMSA); }
/// <summary> /// Create a new MoDerivAffMsa, based on the given sandbox MSA. /// </summary> /// <param name="entry">The entry.</param> /// <param name="sandboxMsa">The sandbox msa.</param> /// <returns></returns> public IMoDerivAffMsa Create(ILexEntry entry, SandboxGenericMSA sandboxMsa) { Debug.Assert(sandboxMsa.MsaType == MsaType.kDeriv); var derivMsa = new MoDerivAffMsa(); entry.MorphoSyntaxAnalysesOC.Add(derivMsa); if (sandboxMsa.MainPOS != null) derivMsa.FromPartOfSpeechRA = sandboxMsa.MainPOS; if (sandboxMsa.SecondaryPOS != null) derivMsa.ToPartOfSpeechRA = sandboxMsa.SecondaryPOS; return derivMsa; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the lexeme to the lexicon. /// </summary> /// <exception cref="ArgumentException">if matching lexeme is already in lexicon</exception> /// ------------------------------------------------------------------------------------ public void AddLexeme(LexicalEntry lexeme) { LexicalProviderManager.ResetLexicalProviderTimer(); Logger.WriteEvent("Adding new lexeme from an external application: " + lexeme.LexicalForm); NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => { string sForm = lexeme.LexicalForm; switch(lexeme.Type) { case LexemeType.Word: ITsString tss = TsStringUtils.MakeTss(lexeme.LexicalForm, m_cache.DefaultVernWs); m_cache.ServiceLocator.GetInstance<IWfiWordformFactory>().Create(tss); break; default: { SandboxGenericMSA msa = new SandboxGenericMSA(); msa.MsaType = (lexeme.Type == LexemeType.Stem) ? MsaType.kStem : MsaType.kUnclassified; IMoMorphType morphType = GetMorphTypeForLexemeType(lexeme.Type); ITsString tssForm = TsStringUtils.MakeTss(sForm, m_cache.DefaultVernWs); m_cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create(morphType, tssForm, (ITsString) null, msa); break; } } }); }
private bool AddNewMsa() { PopupTree pt = GetPopupTree(); // Force the PopupTree to Hide() to trigger popupTree_PopupTreeClosed(). // This will effectively revert the list selection to a previous confirmed state. // Whatever happens below, we don't want to actually leave the "Specify ..." node selected! // This is at least required if the user selects "Cancel" from the dialog below. if (m_sense.MorphoSyntaxAnalysisRA != null) pt.SelectObj(m_sense.MorphoSyntaxAnalysisRA.Hvo); #if __MonoCS__ // If Popup tree is shown whilest the dialog is shown, the first click on the dialog is consumed by the // Popup tree, (and closes it down). On .NET the PopupTree appears to be automatically closed. pt.HideForm(); #endif using (MsaCreatorDlg dlg = new MsaCreatorDlg()) { SandboxGenericMSA dummyMsa = new SandboxGenericMSA(); dummyMsa.MsaType = m_sense.GetDesiredMsaType(); dlg.SetDlgInfo(Cache, m_persistProvider, m_mediator, m_sense.Entry, dummyMsa, 0, false, null); if (dlg.ShowDialog(ParentForm) == DialogResult.OK) { Cache.DomainDataByFlid.BeginUndoTask(String.Format(LexTextControls.ksUndoSetX, FieldName), String.Format(LexTextControls.ksRedoSetX, FieldName)); m_sense.SandboxMSA = dlg.SandboxMSA; Cache.DomainDataByFlid.EndUndoTask(); LoadPopupTree(m_sense.MorphoSyntaxAnalysisRA.Hvo); return true; } } return false; }
/// <summary> /// Create a new MoStemMsa, based on the given sandbox MSA. /// </summary> /// <param name="entry">The entry.</param> /// <param name="sandboxMsa">The sandbox msa.</param> /// <returns></returns> public IMoStemMsa Create(ILexEntry entry, SandboxGenericMSA sandboxMsa) { Debug.Assert(sandboxMsa.MsaType == MsaType.kRoot || sandboxMsa.MsaType == MsaType.kStem); var stemMsa = new MoStemMsa(); entry.MorphoSyntaxAnalysesOC.Add(stemMsa); if (sandboxMsa.MainPOS != null) stemMsa.PartOfSpeechRA = sandboxMsa.MainPOS; return stemMsa; }
/// <summary> /// Initialize the control. /// </summary> /// <param name="cache"></param> /// <param name="mediator"></param> /// <param name="parentForm"></param> public void Initialize(FdoCache cache, Mediator mediator, Form parentForm, SandboxGenericMSA sandboxMSA) { CheckDisposed(); m_parentForm = parentForm; m_mediator = mediator; m_tsf = cache.TsStrFactory; m_cache = cache; IVwStylesheet stylesheet = FontHeightAdjuster.StyleSheetFromMediator(mediator); int defUserWs = m_cache.ServiceLocator.WritingSystemManager.UserWs; IWritingSystem defAnalWs = m_cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem; string defAnalWsFont = defAnalWs.DefaultFontName; m_fwcbAffixTypes.WritingSystemFactory = m_cache.WritingSystemFactory; m_fwcbAffixTypes.WritingSystemCode = defAnalWs.Handle; m_fwcbAffixTypes.Items.Add(m_tsf.MakeString(LexTextControls.ksNotSure, defUserWs)); m_fwcbAffixTypes.Items.Add(m_tsf.MakeString(LexTextControls.ksInflectional, defUserWs)); m_fwcbAffixTypes.Items.Add(m_tsf.MakeString(LexTextControls.ksDerivational, defUserWs)); m_fwcbAffixTypes.StyleSheet = stylesheet; m_fwcbAffixTypes.AdjustStringHeight = false; m_fwcbSlots.Font = new Font(defAnalWsFont, 10); m_fwcbSlots.WritingSystemFactory = m_cache.WritingSystemFactory; m_fwcbSlots.WritingSystemCode = defAnalWs.Handle; m_fwcbSlots.StyleSheet = stylesheet; m_fwcbSlots.AdjustStringHeight = false; m_tcMainPOS.Font = new Font(defAnalWsFont, 10); m_tcMainPOS.WritingSystemFactory = m_cache.WritingSystemFactory; m_tcMainPOS.WritingSystemCode = defAnalWs.Handle; m_tcMainPOS.StyleSheet = stylesheet; m_tcMainPOS.AdjustStringHeight = false; m_tcSecondaryPOS.Font = new Font(defAnalWsFont, 10); m_tcSecondaryPOS.WritingSystemFactory = m_cache.WritingSystemFactory; m_tcSecondaryPOS.WritingSystemCode = defAnalWs.Handle; m_tcSecondaryPOS.StyleSheet = stylesheet; m_tcSecondaryPOS.AdjustStringHeight = false; m_selectedMainPOS = sandboxMSA.MainPOS; m_fwcbAffixTypes.SelectedIndex = 0; m_fwcbAffixTypes.SelectedIndexChanged += HandleComboMSATypesChange; m_mainPOSPopupTreeManager = new POSPopupTreeManager(m_tcMainPOS, m_cache, m_cache.LanguageProject.PartsOfSpeechOA, defAnalWs.Handle, false, m_mediator, m_parentForm); m_mainPOSPopupTreeManager.NotSureIsAny = true; m_mainPOSPopupTreeManager.LoadPopupTree(m_selectedMainPOS != null ? m_selectedMainPOS.Hvo : 0); m_mainPOSPopupTreeManager.AfterSelect += m_mainPOSPopupTreeManager_AfterSelect; m_fwcbSlots.SelectedIndexChanged += HandleComboSlotChange; m_secPOSPopupTreeManager = new POSPopupTreeManager(m_tcSecondaryPOS, m_cache, m_cache.LanguageProject.PartsOfSpeechOA, defAnalWs.Handle, false, m_mediator, m_parentForm); m_secPOSPopupTreeManager.NotSureIsAny = true; // only used for affixes. m_selectedSecondaryPOS = sandboxMSA.SecondaryPOS; m_secPOSPopupTreeManager.LoadPopupTree(m_selectedSecondaryPOS != null ? m_selectedSecondaryPOS.Hvo : 0); m_secPOSPopupTreeManager.AfterSelect += m_secPOSPopupTreeManager_AfterSelect; // Relocate the m_tcSecondaryPOS control to overlay the m_fwcbSlots. // In the designer, they are offset to see them, and edit them. // In running code they are in the same spot, but only one is visible at a time. m_tcSecondaryPOS.Location = m_fwcbSlots.Location; if (m_selectedMainPOS != null && sandboxMSA.MsaType == MsaType.kInfl) { // This fixes LT-4677, LT-6048, and LT-6201. ResetSlotCombo(); } MSAType = sandboxMSA.MsaType; }
/// <summary> /// Initialize the control. /// </summary> /// <param name="cache"></param> /// <param name="mediator"></param> /// <param name="parentForm"></param> public void Initialize(FdoCache cache, Mediator mediator, Form parentForm, SandboxGenericMSA sandboxMSA) { CheckDisposed(); m_parentForm = parentForm; m_mediator = mediator; m_tsf = cache.TsStrFactory; m_cache = cache; IVwStylesheet stylesheet = FontHeightAdjuster.StyleSheetFromMediator(mediator); int defUserWs = m_cache.ServiceLocator.WritingSystemManager.UserWs; IWritingSystem defAnalWs = m_cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem; string defAnalWsFont = defAnalWs.DefaultFontName; m_fwcbAffixTypes.WritingSystemFactory = m_cache.WritingSystemFactory; m_fwcbAffixTypes.WritingSystemCode = defAnalWs.Handle; m_fwcbAffixTypes.Items.Add(m_tsf.MakeString(LexTextControls.ksNotSure, defUserWs)); m_fwcbAffixTypes.Items.Add(m_tsf.MakeString(LexTextControls.ksInflectional, defUserWs)); m_fwcbAffixTypes.Items.Add(m_tsf.MakeString(LexTextControls.ksDerivational, defUserWs)); m_fwcbAffixTypes.StyleSheet = stylesheet; m_fwcbAffixTypes.AdjustStringHeight = false; m_fwcbSlots.Font = new Font(defAnalWsFont, 10); m_fwcbSlots.WritingSystemFactory = m_cache.WritingSystemFactory; m_fwcbSlots.WritingSystemCode = defAnalWs.Handle; m_fwcbSlots.StyleSheet = stylesheet; m_fwcbSlots.AdjustStringHeight = false; m_tcMainPOS.Font = new Font(defAnalWsFont, 10); m_tcMainPOS.WritingSystemFactory = m_cache.WritingSystemFactory; m_tcMainPOS.WritingSystemCode = defAnalWs.Handle; m_tcMainPOS.StyleSheet = stylesheet; m_tcMainPOS.AdjustStringHeight = false; m_tcSecondaryPOS.Font = new Font(defAnalWsFont, 10); m_tcSecondaryPOS.WritingSystemFactory = m_cache.WritingSystemFactory; m_tcSecondaryPOS.WritingSystemCode = defAnalWs.Handle; m_tcSecondaryPOS.StyleSheet = stylesheet; m_tcSecondaryPOS.AdjustStringHeight = false; m_selectedMainPOS = sandboxMSA.MainPOS; m_fwcbAffixTypes.SelectedIndex = 0; m_fwcbAffixTypes.SelectedIndexChanged += HandleComboMSATypesChange; m_mainPOSPopupTreeManager = new POSPopupTreeManager(m_tcMainPOS, m_cache, m_cache.LanguageProject.PartsOfSpeechOA, defAnalWs.Handle, false, m_mediator, m_parentForm); m_mainPOSPopupTreeManager.NotSureIsAny = true; m_mainPOSPopupTreeManager.LoadPopupTree(m_selectedMainPOS != null ? m_selectedMainPOS.Hvo : 0); m_mainPOSPopupTreeManager.AfterSelect += m_mainPOSPopupTreeManager_AfterSelect; m_fwcbSlots.SelectedIndexChanged += HandleComboSlotChange; m_secPOSPopupTreeManager = new POSPopupTreeManager(m_tcSecondaryPOS, m_cache, m_cache.LanguageProject.PartsOfSpeechOA, defAnalWs.Handle, false, m_mediator, m_parentForm); m_secPOSPopupTreeManager.NotSureIsAny = true; // only used for affixes. m_selectedSecondaryPOS = sandboxMSA.SecondaryPOS; m_secPOSPopupTreeManager.LoadPopupTree(m_selectedSecondaryPOS != null ? m_selectedSecondaryPOS.Hvo : 0); m_secPOSPopupTreeManager.AfterSelect += m_secPOSPopupTreeManager_AfterSelect; // Relocate the m_tcSecondaryPOS control to overlay the m_fwcbSlots. // In the designer, they are offset to see them, and edit them. // In running code they are in the same spot, but only one is visible at a time. m_tcSecondaryPOS.Location = m_fwcbSlots.Location; if (m_selectedMainPOS != null && sandboxMSA.MsaType == MsaType.kInfl) { // This fixes LT-4677, LT-6048, and LT-6201. ResetSlotCombo(); } MSAType = sandboxMSA.MsaType; }
/// <summary> /// Update an extant MSA to the new values in the dummy MSA, /// or make a new MSA with the values in the dummy msa. /// </summary> /// <param name="sandboxMsa"></param> /// <returns></returns> public override IMoMorphSynAnalysis UpdateOrReplace(SandboxGenericMSA sandboxMsa) { if (sandboxMsa.MsaType == MsaType.kUnclassified) { if (PartOfSpeechRA != sandboxMsa.MainPOS) PartOfSpeechRA = sandboxMsa.MainPOS; return this; } return base.UpdateOrReplace(sandboxMsa); }
private void m_MSAPopupTreeManager_AfterSelect(object sender, TreeViewEventArgs e) { // unless we get a mouse click or simulated mouse click (e.g. by ENTER or TAB), // do not treat as an actual selection. if (m_handlingMessage || e.Action != TreeViewAction.ByMouse) { return; } HvoTreeNode htn = e.Node as HvoTreeNode; if (htn == null) { return; } // Don't try changing values on a deleted object! See LT-8656 and LT-9119. if (!m_obj.IsValidObject) { return; } int hvoSel = htn.Hvo; // if hvoSel is negative, then MSAPopupTreeManager's AfterSelect has handled it, // except possibly for refresh. if (hvoSel < 0) { ContainingDataTree.RefreshList(false); return; } var sense = m_obj as ILexSense; // Setting sense.DummyMSA can cause the DataTree to want to refresh. Don't // let this happen until after we're through! See LT-9713 and LT-9714. bool fOldDoNotRefresh = ContainingDataTree.DoNotRefresh; try { m_handlingMessage = true; if (hvoSel > 0) { ICmObject obj = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(hvoSel); if (obj.ClassID == PartOfSpeechTags.kClassId) { ContainingDataTree.DoNotRefresh = true; var sandoxMSA = new SandboxGenericMSA(); sandoxMSA.MsaType = sense.GetDesiredMsaType(); sandoxMSA.MainPOS = obj as IPartOfSpeech; var stemMsa = sense.MorphoSyntaxAnalysisRA as IMoStemMsa; if (stemMsa != null) { sandoxMSA.FromPartsOfSpeech = stemMsa.FromPartsOfSpeechRC; } UndoableUnitOfWorkHelper.Do(String.Format(DetailControlsStrings.ksUndoSet, m_fieldName), String.Format(DetailControlsStrings.ksRedoSet, m_fieldName), sense, () => { sense.SandboxMSA = sandoxMSA; }); } else if (sense.MorphoSyntaxAnalysisRA != obj) { ContainingDataTree.DoNotRefresh = true; UndoableUnitOfWorkHelper.Do(String.Format(DetailControlsStrings.ksUndoSet, m_fieldName), String.Format(DetailControlsStrings.ksRedoSet, m_fieldName), sense, () => { sense.MorphoSyntaxAnalysisRA = obj as IMoMorphSynAnalysis; }); } } } finally { m_handlingMessage = false; // We still can't refresh the data at this point without causing a crash due to // a pending Windows message. See LT-9713 and LT-9714. if (ContainingDataTree.DoNotRefresh != fOldDoNotRefresh) { Mediator.BroadcastMessage("DelayedRefreshList", fOldDoNotRefresh); } } }
/// <summary> /// Update an extant MSA to the new values in the sandbox MSA, /// or make a new MSA with the values in the sandbox msa. /// </summary> /// <param name="sandboxMsa">The sandbox msa.</param> /// <returns></returns> /// <remarks> /// Subclasses should override this method to do same-class updates, /// but then call this method to handle class changing activities. /// </remarks> public virtual IMoMorphSynAnalysis UpdateOrReplace(SandboxGenericMSA sandboxMsa) { ILexEntry le = Owner as ILexEntry; foreach (MoMorphSynAnalysis msa in le.MorphoSyntaxAnalysesOC) { // Check other extant MSAs to see if they match the updated one. if (msa != this && msa.EqualsMsa(sandboxMsa)) { msa.MergeObject(this); return msa; } } // Make a new MSA. IMoMorphSynAnalysis newMsa = null; switch (sandboxMsa.MsaType) { default: throw new ApplicationException("Cannot create any other kind of MSA here."); case MsaType.kRoot: // Fall through. case MsaType.kStem: newMsa = Services.GetInstance<IMoStemMsaFactory>().Create(le, sandboxMsa); break; case MsaType.kDeriv: newMsa = Services.GetInstance<IMoDerivAffMsaFactory>().Create(le, sandboxMsa); break; case MsaType.kInfl: newMsa = Services.GetInstance<IMoInflAffMsaFactory>().Create(le, sandboxMsa); break; case MsaType.kUnclassified: newMsa = Services.GetInstance<IMoUnclassifiedAffixMsaFactory>().Create(le, sandboxMsa); break; } newMsa.SwitchReferences(this); return newMsa; }
private ILexEntry AddEntry(Guid morphType, string lexemeForm, string gloss, SandboxGenericMSA msa) { return Cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create( Cache.ServiceLocator.GetInstance<IMoMorphTypeRepository>().GetObject(morphType), Cache.TsStrFactory.MakeString(lexemeForm, Cache.DefaultVernWs), gloss, msa); }
/// <summary> /// Determines whether the specified Sandbox MSA is equal to the current MSA. /// </summary> /// <param name="msa">The MoDerivAffMsa to compare with the current MoDerivAffMsa.</param> /// <returns>true if the specified MoDerivAffMsa is equal to the current MoDerivAffMsa; otherwise, false.</returns> public override bool EqualsMsa(SandboxGenericMSA msa) { // This is the behavior defined by Object.Equals(). if (msa == null) return false; if (msa.MsaType != MsaType.kDeriv) return false; // Check the two properties we get from the DLG match, and the others we care about are missing. return FromPartOfSpeechRA == msa.MainPOS && ToPartOfSpeechRA == msa.SecondaryPOS && FromInflectionClassRA == null && FromStemNameRA == null && ToInflectionClassRA == null && FromProdRestrictRC.Count == 0 && ToProdRestrictRC.Count == 0 && (ToMsFeaturesOA == null) && (FromMsFeaturesOA == null); }
/// <summary> /// Update an extant MSA to the new values in the sandbox MSA, /// or make a new MSA with the values in the sandbox msa. /// </summary> /// <param name="sandboxMsa"></param> /// <returns></returns> public override IMoMorphSynAnalysis UpdateOrReplace(SandboxGenericMSA sandboxMsa) { if (sandboxMsa.MsaType == MsaType.kDeriv) { if (FromPartOfSpeechRA != sandboxMsa.MainPOS) FromPartOfSpeechRA = sandboxMsa.MainPOS; if (ToPartOfSpeechRA != sandboxMsa.SecondaryPOS) ToPartOfSpeechRA = sandboxMsa.SecondaryPOS; return this; } return base.UpdateOrReplace(sandboxMsa); }
/// <summary> /// Create a new MoInflAffMsa, based on the given sandbox MSA. /// </summary> /// <param name="entry">The entry.</param> /// <param name="sandboxMsa">The sandbox msa.</param> /// <returns></returns> public IMoInflAffMsa Create(ILexEntry entry, SandboxGenericMSA sandboxMsa) { Debug.Assert(sandboxMsa.MsaType == MsaType.kInfl); var inflMsa = new MoInflAffMsa(); entry.MorphoSyntaxAnalysesOC.Add(inflMsa); if (sandboxMsa.MainPOS != null) inflMsa.PartOfSpeechRA = sandboxMsa.MainPOS; if (sandboxMsa.Slot != null) inflMsa.SlotsRC.Add(sandboxMsa.Slot); return inflMsa; }
/// <summary> /// Determines whether the specified Sandbox MSA is equal to the current MSA. /// </summary> /// <param name="msa">The MoUnclassifiedAffixMsa to compare with the current MoUnclassifiedAffixMsa.</param> /// <returns>true if the specified MoUnclassifiedAffixMsa is equal to the current MoUnclassifiedAffixMsa; otherwise, false.</returns> public override bool EqualsMsa(SandboxGenericMSA msa) { throw new NotImplementedException("'EqualsMsa' not implemneted on class MoDerivStepMsa."); }
/// <summary> /// Creates an entry with a form in default vernacular and a sense with a gloss in default analysis. /// </summary> /// <param name="entryFullForm">entry form including any markers</param> /// <param name="senseGloss"></param> /// <param name="msa"></param> /// <returns></returns> public ILexEntry Create(string entryFullForm, string senseGloss, SandboxGenericMSA msa) { ITsString tssFullForm = TsStringUtils.MakeTss(entryFullForm, m_cache.DefaultVernWs); // create a sense with a matching gloss var entryComponents = MorphServices.BuildEntryComponents(m_cache, tssFullForm); entryComponents.MSA = msa; entryComponents.GlossAlternatives.Add(TsStringUtils.MakeTss(senseGloss, m_cache.DefaultAnalWs)); return m_cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create(entryComponents); }
private void CreateEmptyMsa() { SandboxGenericMSA dummyMsa = new SandboxGenericMSA(); dummyMsa.MsaType = m_sense.GetDesiredMsaType(); // To make it fully 'not sure' we must discard knowledge of affix type. if (dummyMsa.MsaType == MsaType.kInfl || dummyMsa.MsaType == MsaType.kDeriv) dummyMsa.MsaType = MsaType.kUnclassified; UndoableUnitOfWorkHelper.Do(string.Format(LexTextControls.ksUndoSetX, FieldName), string.Format(LexTextControls.ksRedoSetX, FieldName), m_sense, () => { m_sense.SandboxMSA = dummyMsa; }); }
/// <summary> /// Determines whether the specified Sandbox MSA is equal to the current MSA. /// </summary> /// <param name="msa">The MoUnclassifiedAffixMsa to compare with the current MoUnclassifiedAffixMsa.</param> /// <returns>true if the specified MoUnclassifiedAffixMsa is equal to the current MoUnclassifiedAffixMsa; otherwise, false.</returns> public override bool EqualsMsa(SandboxGenericMSA msa) { // This is the behavior defined by Object.Equals(). if (msa == null) return false; // Make sure that we can cast this object to a MoStemMsa. if (msa.MsaType != MsaType.kUnclassified) return false; // TODO: Add checks for other properties, when we support using them. return PartOfSpeechRA == msa.MainPOS; }
void LaunchChooseFromMasterCategoryListOnIdle(object sender, EventArgs e) { Application.Idle -= LaunchChooseFromMasterCategoryListOnIdle; // now being handled // now launch the dialog using (MasterCategoryListDlg dlg = new MasterCategoryListDlg()) { dlg.SetDlginfo(CategoryList, m_mediator, false, null); switch (dlg.ShowDialog(m_parentOfPopupMgr)) { case DialogResult.OK: var sandboxMsa = new SandboxGenericMSA(); sandboxMsa.MainPOS = dlg.SelectedPOS; sandboxMsa.MsaType = m_sense.GetDesiredMsaType(); UndoableUnitOfWorkHelper.Do(String.Format(LexTextControls.ksUndoSetX, FieldName), String.Format(LexTextControls.ksRedoSetX, FieldName), m_sense, () => { m_sense.SandboxMSA = sandboxMsa; }); // Under certain circumstances (LT-11548) 'this' was disposed during the EndUndotask above! // That's why we're now launching this on idle. // Here's hoping we can get away without doing this! (It doesn't seem to make a difference.) //LoadPopupTree(m_sense.MorphoSyntaxAnalysisRA.Hvo); // everything should be setup with new node selected, so return. break; case DialogResult.Yes: // represents a click on the link to create a new Grammar Category. // Post a message so that we jump to Grammar(area)/Categories tool. // Do this before we close any parent dialog in case // the parent wants to check to see if such a Jump is pending. // NOTE: We use PostMessage here, rather than SendMessage which // disposes of the PopupTree before we and/or our parents might // be finished using it (cf. LT-2563). m_mediator.PostMessage("FollowLink", new FwLinkArgs("posEdit", dlg.SelectedPOS.Guid)); if (m_parentOfPopupMgr != null && m_parentOfPopupMgr.Modal) { // Close the dlg that opened the master POS dlg, // since its hotlink was used to close it, // and a new POS has been created. m_parentOfPopupMgr.DialogResult = DialogResult.Cancel; m_parentOfPopupMgr.Close(); } break; default: // NOTE: If the user has selected "Cancel", then don't change // our m_lastConfirmedNode to the "More..." node. Keep it // the value set by popupTree_PopupTreeClosed() when we // called pt.Hide() above. (cf. comments in LT-2522) break; } } }
/// <summary> /// Determines whether the specified sandbox MSA is equal to the current MSA. /// </summary> /// <param name="msa">The MoStemMsa to compare with the current MoStemMsa.</param> /// <returns>true if the specified MoStemMsa is equal to the current MoStemMsa; otherwise, false.</returns> public abstract bool EqualsMsa(SandboxGenericMSA msa);