/// <summary> /// Handle launching of the MSA editor. /// </summary> protected override void HandleChooser() { using (MsaCreatorDlg dlg = new MsaCreatorDlg()) { MoMorphSynAnalysis originalMsa = m_obj as MoMorphSynAnalysis; ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, originalMsa.OwnerHVO); dlg.SetDlgInfo(m_cache, m_persistProvider, m_mediator, entry, DummyGenericMSA.Create(originalMsa), originalMsa.Hvo, true, String.Format(LexEdStrings.ksEditX, Slice.Label)); if (dlg.ShowDialog(FindForm()) == DialogResult.OK) { DummyGenericMSA dummyMsa = dlg.DummyMSA; if (!originalMsa.EqualsMsa(dummyMsa)) { m_cache.BeginUndoTask(LexEdStrings.ksUndoEditFunction, LexEdStrings.ksRedoEditFunction); // The UpdateOrReplace call may end up disposing this. So any variables we // need after it must be copied to the stack. FdoCache cache = m_cache; Slice parent = Slice; IMoMorphSynAnalysis newMsa = originalMsa.UpdateOrReplace(dummyMsa); cache.EndUndoTask(); } } } }
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. pt.Hide(); DummyGenericMSA dummyMsa = DummyGenericMSA.Create(m_sense.MorphoSyntaxAnalysisRA); using (MsaCreatorDlg dlg = new MsaCreatorDlg()) { dlg.SetDlgInfo(Cache, m_persistProvider, m_mediator, m_sense.Entry, dummyMsa, m_sense.MorphoSyntaxAnalysisRAHvo, true, m_sEditGramFunc); if (dlg.ShowDialog(ParentForm) == DialogResult.OK) { Cache.BeginUndoTask(String.Format(LexTextControls.ksUndoSetX, FieldName), String.Format(LexTextControls.ksRedoSetX, FieldName)); (m_sense as LexSense).DummyMSA = dlg.DummyMSA; Cache.EndUndoTask(); LoadPopupTree(m_sense.MorphoSyntaxAnalysisRAHvo); return true; } } return false; }
private bool ChooseFromMasterCategoryList() { 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 "More..." node selected! // This is at least required if the user selects "Cancel" from the dialog below. pt.Hide(); using (MasterCategoryListDlg dlg = new MasterCategoryListDlg()) { dlg.SetDlginfo(List, m_mediator, false, null); switch (dlg.ShowDialog(ParentForm)) { case DialogResult.OK: DummyGenericMSA dummyMSA = new DummyGenericMSA(); dummyMSA.MainPOS = dlg.SelectedPOS.Hvo; dummyMSA.MsaType = m_sense.GetDesiredMsaType(); Cache.BeginUndoTask(String.Format(LexTextControls.ksUndoSetX, FieldName), String.Format(LexTextControls.ksRedoSetX, FieldName)); (m_sense as LexSense).DummyMSA = dummyMSA; Cache.EndUndoTask(); LoadPopupTree(m_sense.MorphoSyntaxAnalysisRAHvo); // everything should be setup with new node selected, so return. return true; case DialogResult.Yes: // 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", SIL.FieldWorks.FdoUi.FwLink.Create("posEdit", Cache.GetGuidFromId(dlg.SelectedPOS.Hvo), Cache.ServerName, Cache.DatabaseName)); if (ParentForm != null && ParentForm.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. ParentForm.DialogResult = DialogResult.Cancel; ParentForm.Close(); } return false; 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) return false; } } }
private void CreateEmptyMsa() { DummyGenericMSA dummyMsa = new DummyGenericMSA(); 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; Cache.BeginUndoTask(String.Format(LexTextControls.ksUndoSetX, FieldName), String.Format(LexTextControls.ksRedoSetX, FieldName)); (m_sense as LexSense).DummyMSA = dummyMsa; Cache.EndUndoTask(); }
private void SetupLexEntryAndSense(string formLexEntry, string senseGloss, string partOfSpeech, out ILexEntry lexEntry1_Entry, out ILexSense lexEntry1_Sense1) { ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs); int clsidForm; // create a sense with a matching gloss DummyGenericMSA dummyMsa = new DummyGenericMSA(); int hvoSenseMsaPos = m_sandbox.GetComboItemHvo(InterlinLineChoices.kflidWordPos, 0, partOfSpeech); dummyMsa.MainPOS = hvoSenseMsaPos; lexEntry1_Entry = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, senseGloss, dummyMsa); lexEntry1_Sense1 = lexEntry1_Entry.SensesOS[0]; }
/// <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, DummyGenericMSA dummyMSA) { CheckDisposed(); m_parentForm = parentForm; m_mediator = mediator; m_tsf = TsStrFactoryClass.Create(); m_cache = cache; IVwStylesheet stylesheet = FontHeightAdjuster.StyleSheetFromMediator(mediator); m_fwcbAffixTypes.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor; m_fwcbAffixTypes.WritingSystemCode = m_cache.LangProject.DefaultAnalysisWritingSystem; m_fwcbAffixTypes.Items.Add(m_tsf.MakeString(LexTextControls.ksNotSure, m_cache.LangProject.DefaultUserWritingSystem)); m_fwcbAffixTypes.Items.Add(m_tsf.MakeString(LexTextControls.ksInflectional, m_cache.LangProject.DefaultUserWritingSystem)); m_fwcbAffixTypes.Items.Add(m_tsf.MakeString(LexTextControls.ksDerivational, m_cache.LangProject.DefaultUserWritingSystem)); m_fwcbAffixTypes.StyleSheet = stylesheet; m_fwcbAffixTypes.AdjustStringHeight = false; m_fwcbSlots.Font = new System.Drawing.Font(cache.LangProject.DefaultAnalysisWritingSystemFont, 10); m_fwcbSlots.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor; m_fwcbSlots.WritingSystemCode = m_cache.LangProject.DefaultAnalysisWritingSystem; m_fwcbSlots.StyleSheet = stylesheet; m_fwcbSlots.AdjustStringHeight = false; m_tcMainPOS.Font = new System.Drawing.Font(cache.LangProject.DefaultAnalysisWritingSystemFont, 10); m_tcMainPOS.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor; m_tcMainPOS.WritingSystemCode = m_cache.LangProject.DefaultAnalysisWritingSystem; m_tcMainPOS.StyleSheet = stylesheet; m_tcMainPOS.AdjustStringHeight = false; m_tcSecondaryPOS.Font = new System.Drawing.Font(cache.LangProject.DefaultAnalysisWritingSystemFont, 10); m_tcSecondaryPOS.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor; m_tcSecondaryPOS.WritingSystemCode = m_cache.LangProject.DefaultAnalysisWritingSystem; m_tcSecondaryPOS.StyleSheet = stylesheet; m_tcSecondaryPOS.AdjustStringHeight = false; m_selectedMainPOSHvo = dummyMSA.MainPOS; m_fwcbAffixTypes.SelectedIndex = 0; m_fwcbAffixTypes.SelectedIndexChanged += new EventHandler( HandleComboMSATypesChange); m_mainPOSPopupTreeManager = new POSPopupTreeManager(m_tcMainPOS, m_cache, m_cache.LangProject.PartsOfSpeechOA, m_cache.LangProject.DefaultAnalysisWritingSystem, false, m_mediator, m_parentForm); m_mainPOSPopupTreeManager.NotSureIsAny = true; m_mainPOSPopupTreeManager.LoadPopupTree(m_selectedMainPOSHvo); m_mainPOSPopupTreeManager.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(m_mainPOSPopupTreeManager_AfterSelect); m_fwcbSlots.SelectedIndexChanged += new EventHandler( HandleComboSlotChange); m_secPOSPopupTreeManager = new POSPopupTreeManager(m_tcSecondaryPOS, m_cache, m_cache.LangProject.PartsOfSpeechOA, m_cache.LangProject.DefaultAnalysisWritingSystem, false, m_mediator, m_parentForm); m_secPOSPopupTreeManager.NotSureIsAny = true; // only used for affixes. m_selectedSecondaryPOSHvo = dummyMSA.SecondaryPOS; m_secPOSPopupTreeManager.LoadPopupTree(m_selectedSecondaryPOSHvo); m_secPOSPopupTreeManager.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(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_selectedMainPOSHvo > 0 && dummyMSA.MsaType == MsaType.kInfl) { // This fixes LT-4677, LT-6048, and LT-6201. ResetSlotCombo(); } MSAType = dummyMSA.MsaType; }
/// <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, DummyGenericMSA dummyMsa, int hvoOriginalMsa, bool useForEdit, string titleForEdit) { CheckDisposed(); Debug.Assert(m_cache == null); MsaType msaType = dummyMsa.MsaType; m_cache = cache; m_mediator = mediator; if (useForEdit) { // Change the window title and the OK button text. Text = titleForEdit; s_helpTopic = "khtpEditGrammaticalFunction"; this.helpProvider.SetHelpKeyword(this, FwApp.App.GetHelpString(s_helpTopic, 0)); btnOk.Text = LexText.Controls.LexTextControls.ks_OK; } // Set font, writing system factory, and code for the edit box. float fntSize = label1.Font.Size * 2.0F; m_fwtbCitationForm.Font = new Font(m_cache.LangProject.DefaultVernacularWritingSystemFont, fntSize); m_fwtbCitationForm.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor; m_fwtbCitationForm.WritingSystemCode = m_cache.LangProject.DefaultVernacularWritingSystem; m_fwtbCitationForm.AdjustForStyleSheet(this, null, mediator); m_fwtbCitationForm.AdjustStringHeight = false; m_fwtbCitationForm.Tss = entry.HeadWord; m_fwtbCitationForm.HasBorder = false; m_fwtbSenses.Font = new Font(m_cache.LangProject.DefaultVernacularWritingSystemFont, fntSize); m_fwtbSenses.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor; m_fwtbSenses.WritingSystemCode = m_cache.LangProject.DefaultVernacularWritingSystem; m_fwtbSenses.AdjustForStyleSheet(this, null, mediator); m_fwtbSenses.AdjustStringHeight = false; string sSenses = string.Empty; ITsIncStrBldr tisb = TsIncStrBldrClass.Create(); foreach (ILexSense sense in entry.AllSenses) { if (sense.MorphoSyntaxAnalysisRA != null) { if (sense.MorphoSyntaxAnalysisRAHvo == 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, dummyMsa); 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; } } }
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_cache.VerifyValidObject(m_obj)) { 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; } LexSense sense = m_obj as LexSense; // 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; int clidSel = 0; if (hvoSel > 0) { clidSel = m_cache.GetClassOfObject(hvoSel); } bool didChange = false; if (clidSel == PartOfSpeech.kclsidPartOfSpeech) { ContainingDataTree.DoNotRefresh = true; m_cache.BeginUndoTask( String.Format(DetailControlsStrings.ksUndoSet, m_fieldName), String.Format(DetailControlsStrings.ksRedoSet, m_fieldName)); DummyGenericMSA dummyMSA = new DummyGenericMSA(); dummyMSA.MsaType = sense.GetDesiredMsaType(); dummyMSA.MainPOS = hvoSel; MoStemMsa stemMsa = sense.MorphoSyntaxAnalysisRA as MoStemMsa; if (stemMsa != null) { dummyMSA.FromPartsOfSpeech = stemMsa.FromPartsOfSpeechRC; } sense.DummyMSA = dummyMSA; didChange = true; } else if (sense.MorphoSyntaxAnalysisRAHvo != hvoSel) { ContainingDataTree.DoNotRefresh = true; m_cache.BeginUndoTask( String.Format(DetailControlsStrings.ksUndoSet, m_fieldName), String.Format(DetailControlsStrings.ksRedoSet, m_fieldName)); sense.MorphoSyntaxAnalysisRAHvo = hvoSel; didChange = true; } if (didChange) { m_cache.EndUndoTask(); } if (!ContainingDataTree.RefreshListNeeded) { m_MSAPopupTreeManager.LoadPopupTree(sense.MorphoSyntaxAnalysisRAHvo); // Don't refresh the datatree unless the popup has actually been loaded. // It could be setting the selection in the process of loading! See LT-9191. if (m_MSAPopupTreeManager.IsTreeLoaded) { ContainingDataTree.RefreshList(false); } } } 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); } } }