Ejemplo n.º 1
0
        /// <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;
                    }
                }
            }
        }