/// <summary> /// This method is called when a user selects Delete Relation on a Lexical Relation slice. /// For: Pair relation (eg. Antonym) /// tree relation (parts/whole when deleting a Parts slice) /// </summary> /// <param name="hvo"></param> public void DeleteReference(int hvo) { CheckDisposed(); if (hvo <= 0) { throw new ConfigurationException("Slice:GetObjectHvoForMenusToOperateOn is either messed up or should not have been called, because it could not find the object to be deleted.", m_configurationNode); } else { Form mainWindow = (Form)Mediator.PropertyTable.GetValue("window"); mainWindow.Cursor = Cursors.WaitCursor; using (ConfirmDeleteObjectDlg dlg = new ConfirmDeleteObjectDlg()) { CmObjectUi ui = CmObjectUi.MakeUi(m_cache, hvo); ILexReference lr = LexReference.CreateFromDBObject(m_cache, hvo); //We need this to determine which kind of relation we are deleting LexRefType lrtOwner = (LexRefType)CmObject.CreateFromDBObject(m_cache, lr.OwnerHVO); int analWs = m_cache.DefaultAnalWs; int userWs = m_cache.DefaultUserWs; ITsIncStrBldr tisb = TsIncStrBldrClass.Create(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); switch ((LexRefType.MappingTypes)lrtOwner.MappingType) { case LexRefType.MappingTypes.kmtSenseTree: case LexRefType.MappingTypes.kmtEntryTree: case LexRefType.MappingTypes.kmtEntryOrSenseTree: tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(String.Format(LexEdStrings.ksDeleteLexTree, "\x2028")); dlg.SetDlgInfo(ui, m_cache, Mediator, tisb.GetString()); break; default: dlg.SetDlgInfo(ui, m_cache, Mediator); break; } if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { lr.DeleteUnderlyingObject(); //Update the display because we have removed this slice from the Lexical entry. UpdateForDelete(hvo); mainWindow.Cursor = Cursors.Default; } else //If the user selected Cancel in the delete dialog do nothing { mainWindow.Cursor = Cursors.Default; return; } } } }
/// <summary> /// This method is called when a user selects "Edit Reference Set Details" for a Lexical Relation slice. /// </summary> /// <param name="hvo"></param> public void EditReferenceDetails(int hvo) { CheckDisposed(); if (hvo <= 0) { throw new ConfigurationException("Slice:GetObjectHvoForMenusToOperateOn is either messed up or should not have been called, because it could not find the object to be deleted.", m_configurationNode); } else { ILexReference lr = LexReference.CreateFromDBObject(m_cache, hvo); using (LexReferenceDetailsDlg dlg = new LexReferenceDetailsDlg()) { dlg.ReferenceName = lr.Name.AnalysisDefaultWritingSystem; dlg.ReferenceComment = lr.Comment.AnalysisDefaultWritingSystem.Text; if (dlg.ShowDialog() == DialogResult.OK) { lr.Name.AnalysisDefaultWritingSystem = dlg.ReferenceName; lr.Comment.SetAnalysisDefaultWritingSystem(dlg.ReferenceComment); } } } }
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(); } }
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 = ""; }