/// <summary> /// Override method to handle launching of a chooser for selecting lexical entries. /// </summary> protected override void HandleChooser() { ILexRefType lrt = LexRefType.CreateFromDBObject(m_cache, m_obj.OwnerHVO); LexRefType.MappingTypes type = (LexRefType.MappingTypes)lrt.MappingType; BaseGoDlg dlg = null; switch (type) { case LexRefType.MappingTypes.kmtSensePair: case LexRefType.MappingTypes.kmtSenseAsymmetricPair: // Sense pair with different Forward/Reverse names dlg = new LinkEntryOrSenseDlg(); (dlg as LinkEntryOrSenseDlg).SelectSensesOnly = true; break; case LexRefType.MappingTypes.kmtEntryPair: case LexRefType.MappingTypes.kmtEntryAsymmetricPair: // Entry pair with different Forward/Reverse names dlg = new GoDlg(); break; case LexRefType.MappingTypes.kmtEntryOrSensePair: case LexRefType.MappingTypes.kmtEntryOrSenseAsymmetricPair: // Entry or sense pair with different Forward/Reverse dlg = new LinkEntryOrSenseDlg(); (dlg as LinkEntryOrSenseDlg).SelectSensesOnly = false; break; } Debug.Assert(dlg != null); WindowParams wp = new WindowParams(); //on creating Pair Lexical Relation have an Add button and Add in the title bar if (TargetHvo == 0) { wp.m_title = String.Format(LexEdStrings.ksIdentifyXEntry, lrt.Name.AnalysisDefaultWritingSystem); wp.m_btnText = LexEdStrings.ks_Add; } else //Otherwise we are Replacing the item { wp.m_title = String.Format(LexEdStrings.ksReplaceXEntry); wp.m_btnText = LexEdStrings.ks_Replace; } wp.m_label = LexEdStrings.ksFind_; dlg.SetDlgInfo(m_cache, wp, m_mediator); dlg.SetHelpTopic("khtpChooseLexicalRelationAdd"); if (dlg.ShowDialog(FindForm()) == DialogResult.OK) { TargetHvo = dlg.SelectedID; } dlg.Dispose(); }
/// <summary> /// Override method to handle launching of a chooser for selecting lexical entries. /// </summary> protected override void HandleChooser() { ILexRefType lrt = LexRefType.CreateFromDBObject(m_cache, m_obj.OwnerHVO); LexRefType.MappingTypes type = (LexRefType.MappingTypes)lrt.MappingType; BaseGoDlg dlg = null; string sTitle = ""; switch (type) { case LexRefType.MappingTypes.kmtSenseCollection: dlg = new LinkEntryOrSenseDlg(); (dlg as LinkEntryOrSenseDlg).SelectSensesOnly = true; sTitle = String.Format(LexEdStrings.ksIdentifyXSense, lrt.Name.BestAnalysisAlternative.Text); break; case LexRefType.MappingTypes.kmtEntryCollection: dlg = new GoDlg(); sTitle = String.Format(LexEdStrings.ksIdentifyXLexEntry, lrt.Name.BestAnalysisAlternative.Text); break; case LexRefType.MappingTypes.kmtEntryOrSenseCollection: dlg = new LinkEntryOrSenseDlg(); sTitle = String.Format(LexEdStrings.ksIdentifyXLexEntryOrSense, lrt.Name.BestAnalysisAlternative.Text); break; } Debug.Assert(dlg != null); WindowParams wp = new WindowParams(); wp.m_title = sTitle; wp.m_label = LexEdStrings.ksFind_; wp.m_btnText = LexEdStrings.ks_Add; //for collection relation of items always have an Add button dlg.SetDlgInfo(m_cache, wp, m_mediator); dlg.SetHelpTopic("khtpChooseLexicalRelationAdd"); if (dlg.ShowDialog(FindForm()) == DialogResult.OK) { AddItem(dlg.SelectedID); } dlg.Dispose(); }
/// <summary> /// Override method to handle launching of a chooser for selecting lexical entries. /// </summary> protected override void HandleChooser() { ILexRefType lrt = LexRefType.CreateFromDBObject(m_cache, m_obj.OwnerHVO); int type = lrt.MappingType; BaseGoDlg dlg = null; switch ((LexRefType.MappingTypes)type) { case LexRefType.MappingTypes.kmtSenseTree: dlg = new LinkEntryOrSenseDlg(); (dlg as LinkEntryOrSenseDlg).SelectSensesOnly = true; break; case LexRefType.MappingTypes.kmtEntryTree: dlg = new GoDlg(); break; case LexRefType.MappingTypes.kmtEntryOrSenseTree: dlg = new LinkEntryOrSenseDlg(); break; } Debug.Assert(dlg != null); WindowParams wp = new WindowParams(); //This method is only called when we are Replacing the //tree root of a Whole/Part lexical relation wp.m_title = String.Format(LexEdStrings.ksReplaceXEntry); wp.m_btnText = LexEdStrings.ks_Replace; wp.m_label = LexEdStrings.ksFind_; dlg.SetDlgInfo(m_cache, wp, m_mediator); dlg.SetHelpTopic("khtpChooseLexicalRelationAdd"); if (dlg.ShowDialog(FindForm()) == DialogResult.OK) { TargetHvo = dlg.SelectedID; } dlg.Dispose(); }
/// <summary> /// Override method to handle launching of a chooser for selecting lexical entries. /// </summary> protected override void HandleChooser() { ILexRefType lrt = LexRefType.CreateFromDBObject(m_cache, m_obj.OwnerHVO); int type = lrt.MappingType; BaseGoDlg dlg = null; switch ((LexRefType.MappingTypes)type) { case LexRefType.MappingTypes.kmtSenseTree: dlg = new LinkEntryOrSenseDlg(); (dlg as LinkEntryOrSenseDlg).SelectSensesOnly = true; break; case LexRefType.MappingTypes.kmtEntryTree: dlg = new GoDlg(); break; case LexRefType.MappingTypes.kmtEntryOrSenseTree: dlg = new LinkEntryOrSenseDlg(); break; } Debug.Assert(dlg != null); WindowParams wp = new WindowParams(); wp.m_title = String.Format(LexEdStrings.ksIdentifyXEntry, lrt.Name.AnalysisDefaultWritingSystem); wp.m_label = LexEdStrings.ksFind_; wp.m_btnText = LexEdStrings.ks_Add; //for parts of a whole always have an Add button dlg.SetDlgInfo(m_cache, wp, m_mediator); dlg.SetHelpTopic("khtpChooseLexicalRelationAdd"); if (dlg.ShowDialog(FindForm()) == DialogResult.OK) { AddItem(dlg.SelectedID); } dlg.Dispose(); }
public void HandleCreateMenuItem(object sender, EventArgs ea) { CheckDisposed(); if (!m_cache.VerifyValidObject(m_obj)) { return; } int itemIndex = (((ToolStripItem)(sender)).Owner as ContextMenuStrip).Items.IndexOf((ToolStripItem)sender); int hvoType = m_refTypesAvailable[itemIndex]; bool fReverseRef = m_rgfReversedRefType[itemIndex]; ILexRefType lrt = LexRefType.CreateFromDBObject(m_cache, hvoType); int hvoNew = 0; int hvoFirst = 0; if (fReverseRef) { // When creating a tree Lexical Relation and the user is choosing // the root of the tree, first see if the user selects a lexical entry. // If they do not select anything (hvoFirst==0) return and do not create the slice. hvoFirst = GetRootObjectHvo(lrt); if (hvoFirst == 0) { return; // the user cancelled out of the operation. } if (lrt.MappingType == (int)LexRefType.MappingTypes.kmtSenseTree || lrt.MappingType == (int)LexRefType.MappingTypes.kmtEntryTree || lrt.MappingType == (int)LexRefType.MappingTypes.kmtEntryOrSenseTree) { // Use an existing LexReference if one exists. foreach (ILexReference lr in lrt.MembersOC) { if (lr.TargetsRS.Count > 0 && lr.TargetsRS.HvoArray[0] == hvoFirst) { lr.TargetsRS.Append(m_obj.Hvo); hvoNew = lr.Hvo; break; } } } } else { // Launch the dialog that allows the user to choose a lexical entry. // If they choose an entry, it is returned in hvoFirst so go ahead and // create the lexical relation and add this lexical entry to that relation. hvoFirst = GetChildObjectHvo(lrt); if (hvoFirst == 0) { return; // the user cancelled out of the operation. } } if (hvoNew == 0) { hvoNew = m_cache.CreateObject((int)LexReference.kclsidLexReference, hvoType, (int)LexRefType.LexRefTypeTags.kflidMembers, 0); ILexReference lr = LexReference.CreateFromDBObject(m_cache, hvoNew); if (fReverseRef) { lr.TargetsRS.InsertAt(hvoFirst, 0); lr.TargetsRS.InsertAt(m_obj.Hvo, 1); } else { //When creating a lexical relation slice, //add the current lexical entry to the lexical relation as the first item lr.TargetsRS.InsertAt(m_obj.Hvo, 0); //then also add the lexical entry that the user selected in the chooser dialog. lr.TargetsRS.InsertAt(hvoFirst, 1); } } m_refs.Add(hvoNew); this.ExpandNewNode(); // update the cache through our virtual handler. if (m_vh != null) { IVwCacheDa cda = m_cache.VwCacheDaAccessor; int flid = m_vh.Tag; m_vh.Load(m_obj.Hvo, flid, 0, cda); m_cache.MainCacheAccessor.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_obj.Hvo, flid, 0, 1, 0); } (m_obj as CmObject).UpdateTimestampForVirtualChange(); if (hvoFirst != 0) { ICmObject cmoFirst = CmObject.CreateFromDBObject(m_cache, hvoFirst); (cmoFirst as CmObject).UpdateTimestampForVirtualChange(); } }
protected System.Windows.Forms.ContextMenuStrip SetupContextMenuStrip() { System.Windows.Forms.ContextMenuStrip contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(); int[] refTypes = m_cache.LangProject.LexDbOA.ReferencesOA.PossibilitiesOS.HvoArray; m_refTypesAvailable.Clear(); m_rgfReversedRefType.Clear(); string formatName = Mediator.StringTbl.GetString("InsertSymmetricReference", "LexiconTools"); string formatNameWithReverse = Mediator.StringTbl.GetString("InsertAsymmetricReference", "LexiconTools"); for (int i = 0; i < refTypes.Length; i++) { ILexRefType lrt = LexRefType.CreateFromDBObject(m_cache, refTypes[i]); if (m_obj is ILexEntry) { switch ((LexRefType.MappingTypes)lrt.MappingType) { case LexRefType.MappingTypes.kmtSenseCollection: case LexRefType.MappingTypes.kmtSensePair: case LexRefType.MappingTypes.kmtSenseTree: case LexRefType.MappingTypes.kmtSenseSequence: case LexRefType.MappingTypes.kmtSenseAsymmetricPair: continue; default: break; } } else { switch ((LexRefType.MappingTypes)lrt.MappingType) { case LexRefType.MappingTypes.kmtEntryCollection: case LexRefType.MappingTypes.kmtEntryPair: case LexRefType.MappingTypes.kmtEntryTree: case LexRefType.MappingTypes.kmtEntrySequence: case LexRefType.MappingTypes.kmtEntryAsymmetricPair: continue; default: break; } } string label = ""; string label2 = ""; string reverseName = LexRefType.BestAnalysisOrVernReverseName(lrt.Cache, lrt.Hvo).Text; // replaces lrt.ReverseName.AnalysisDefaultWritingSystem; if (reverseName == null || reverseName == string.Empty) { reverseName = LexEdStrings.ksStars; } string name = lrt.ShortName; if (name == null || name == string.Empty) { name = LexEdStrings.ksStars; } switch ((LexRefType.MappingTypes)lrt.MappingType) { case LexRefType.MappingTypes.kmtSenseCollection: case LexRefType.MappingTypes.kmtSensePair: case LexRefType.MappingTypes.kmtSenseSequence: case LexRefType.MappingTypes.kmtEntryCollection: case LexRefType.MappingTypes.kmtEntryPair: case LexRefType.MappingTypes.kmtEntrySequence: case LexRefType.MappingTypes.kmtEntryOrSenseCollection: case LexRefType.MappingTypes.kmtEntryOrSensePair: case LexRefType.MappingTypes.kmtEntryOrSenseSequence: label = string.Format(formatName, name); break; case LexRefType.MappingTypes.kmtSenseTree: case LexRefType.MappingTypes.kmtEntryTree: case LexRefType.MappingTypes.kmtEntryOrSenseTree: case LexRefType.MappingTypes.kmtSenseAsymmetricPair: case LexRefType.MappingTypes.kmtEntryAsymmetricPair: case LexRefType.MappingTypes.kmtEntryOrSenseAsymmetricPair: label = string.Format(formatNameWithReverse, name, reverseName); label2 = string.Format(formatNameWithReverse, reverseName, name); break; } int iInsert = contextMenuStrip.Items.Count; //This block of code commented out was set up to sort the items alphabetically. // Find the index to insert the menu items in sorted order. This is a simple // linear search of the existing items in the menu, which could be improved to // a binary search if this is a slowdown. I don't expect that to happen for // expected number of different lexical relation types. //for (int idx = 0; idx < contextMenuStrip.Items.Count; ++idx) //{ // if (String.Compare(label, contextMenuStrip.Items[idx].Text) < 0) // { // iInsert = idx; // break; // } //} // We could use the following method for inputing items if we want to go back to having them sorted. // This would also require making sure MergeIndex has the correct value when referenced in // HandleCreateMenuItem() //contextMenuStrip.Items.Insert(iInsert, new ToolStripMenuItem(label2, null, new EventHandler(this.HandleCreateMenuItem))); contextMenuStrip.Items.Add(new ToolStripMenuItem(label, null, new EventHandler(this.HandleCreateMenuItem))); m_refTypesAvailable.Insert(iInsert, refTypes[i]); m_rgfReversedRefType.Insert(iInsert, false); if (label2.Length > 0) { iInsert = contextMenuStrip.Items.Count; //This block of code commented out was set up to sort the items alphabetically //for (int idx = 0; idx < contextMenuStrip.Items.Count; ++idx) //{ // if (String.Compare(label2, contextMenuStrip.Items[idx].Text) < 0) // { // iInsert = idx; // break; // } //} // We could use the following method for inputing items if we want to go back to having them sorted. // This would also require making sure MergeIndex has the correct value when referenced in // HandleCreateMenuItem() //contextMenuStrip.Items.Insert(iInsert, new ToolStripMenuItem(label2, null, new EventHandler(this.HandleCreateMenuItem))); contextMenuStrip.Items.Add(new ToolStripMenuItem(label2, null, new EventHandler(this.HandleCreateMenuItem))); m_refTypesAvailable.Insert(iInsert, refTypes[i]); m_rgfReversedRefType.Insert(iInsert, true); } } AddFinalContextMenuStripOptions(contextMenuStrip); return(contextMenuStrip); }
private void GenerateChildNode(int iChild, XmlNode node, XmlNode caller, int indent, ref int insPos, ArrayList path, ObjSeqHashMap reuseMap) { ILexReference lr = LexReference.CreateFromDBObject(m_cache, (int)m_refs[iChild]); ILexRefType lrt = LexRefType.CreateFromDBObject(m_cache, lr.OwnerHVO); string sLabel = lrt.ShortName; if (sLabel == null || sLabel == string.Empty) { sLabel = lrt.Abbreviation.BestAnalysisAlternative.Text; } bool fTreeRoot = true; ISilDataAccess sda = m_cache.MainCacheAccessor; int chvoTargets = sda.get_VecSize(lr.Hvo, (int)LexReference.LexReferenceTags.kflidTargets); // change the label for a Tree relationship. switch ((LexRefType.MappingTypes)lrt.MappingType) { case LexRefType.MappingTypes.kmtSenseTree: case LexRefType.MappingTypes.kmtEntryTree: case LexRefType.MappingTypes.kmtEntryOrSenseTree: case LexRefType.MappingTypes.kmtSenseAsymmetricPair: // Sense Pair with different Forward/Reverse names case LexRefType.MappingTypes.kmtEntryAsymmetricPair: // Entry Pair with different Forward/Reverse names case LexRefType.MappingTypes.kmtEntryOrSenseAsymmetricPair: // Entry or sense Pair with different Forward/Reverse names //int chvo = sda.get_VecSize(lr.Hvo, (int)LexReference.LexReferenceTags.kflidTargets); if (chvoTargets > 0) { int hvoFirst = sda.get_VecItem(lr.Hvo, (int)LexReference.LexReferenceTags.kflidTargets, 0); if (hvoFirst != m_obj.Hvo) { sLabel = lrt.ReverseName.BestAnalysisAlternative.Text; if (sLabel == null || sLabel == string.Empty) { sLabel = lrt.ReverseAbbreviation.BestAnalysisAlternative.Text; } fTreeRoot = false; } } break; } if (sLabel == null || sLabel == string.Empty) { sLabel = LexEdStrings.ksStars; } string sXml = "<slice label=\"" + sLabel + "\" field=\"Targets\"" + " editor=\"Custom\" assemblyPath=\"LexEdDll.dll\""; //string sMenu = "mnuDataTree-DeleteFromLexSenseReference"; we used to have distinct strings in the menu string sMenu = "mnuDataTree-DeleteAddLexReference"; // generate Xml for a specific slice matching this reference switch ((LexRefType.MappingTypes)lrt.MappingType) { case LexRefType.MappingTypes.kmtSenseCollection: sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceCollectionSlice\""; break; case LexRefType.MappingTypes.kmtSensePair: case LexRefType.MappingTypes.kmtSenseAsymmetricPair: // Sense Pair with different Forward/Reverse names case LexRefType.MappingTypes.kmtEntryPair: case LexRefType.MappingTypes.kmtEntryAsymmetricPair: // Entry Pair with different Forward/Reverse names case LexRefType.MappingTypes.kmtEntryOrSensePair: case LexRefType.MappingTypes.kmtEntryOrSenseAsymmetricPair: // Entry or sense Pair with different forward/Reverse names sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferencePairSlice\""; sMenu = "mnuDataTree-DeleteReplaceLexReference"; break; case LexRefType.MappingTypes.kmtSenseTree: if (fTreeRoot) { sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceTreeBranchesSlice\""; sMenu = "mnuDataTree-DeleteAddLexReference"; } else { sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceTreeRootSlice\""; sMenu = "mnuDataTree-DeleteReplaceLexReference"; } break; case LexRefType.MappingTypes.kmtSenseSequence: case LexRefType.MappingTypes.kmtEntrySequence: case LexRefType.MappingTypes.kmtEntryOrSenseSequence: sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceSequenceSlice\""; break; case LexRefType.MappingTypes.kmtEntryCollection: sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceCollectionSlice\""; //sMenu = "mnuDataTree-DeleteFromLexEntryReference"; we used to have distinct strings in the menu sMenu = "mnuDataTree-DeleteAddLexReference"; break; case LexRefType.MappingTypes.kmtEntryTree: //sMenu = "mnuDataTree-DeleteFromLexEntryReference"; we used to have distinct strings in the menu sMenu = "mnuDataTree-DeleteAddLexReference"; if (fTreeRoot) { sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceTreeBranchesSlice\""; sMenu = "mnuDataTree-DeleteAddLexReference"; } else { sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceTreeRootSlice\""; sMenu = "mnuDataTree-DeleteReplaceLexReference"; } break; case LexRefType.MappingTypes.kmtEntryOrSenseCollection: sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceCollectionSlice\""; if (m_obj is LexEntry) { //sMenu = "mnuDataTree-DeleteFromLexEntryReference"; we used to have distinct strings in the menu sMenu = "mnuDataTree-DeleteAddLexReference"; } break; case LexRefType.MappingTypes.kmtEntryOrSenseTree: if (m_obj is LexEntry) { //sMenu = "mnuDataTree-DeleteFromLexEntryReference"; we used to have distinct strings in the menu sMenu = "mnuDataTree-DeleteAddLexReference"; } if (fTreeRoot) { sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceTreeBranchesSlice\""; sMenu = "mnuDataTree-DeleteAddLexReference"; } else { sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceTreeRootSlice\""; } break; } sXml += " mappingType=\"" + lrt.MappingType + "\" hvoDisplayParent=\"" + m_obj.Hvo + "\"" + " menu=\"" + sMenu + "\"><deParams displayProperty=\"HeadWord\"/></slice>"; node.InnerXml = sXml; int firstNewSliceIndex = insPos; CreateIndentedNodes(caller, lr, indent, ref insPos, path, reuseMap, node); for (int islice = firstNewSliceIndex; islice < insPos; islice++) { Slice child = Parent.Controls[islice] as Slice; if (child is ILexReferenceSlice) { (child as ILexReferenceSlice).MasterSlice = this; } } node.InnerXml = ""; }