/// <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(ILexReference lr) { CheckDisposed(); if (lr == null) { 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 { var mainWindow = m_propertyTable.GetValue <Form>("window"); using (new WaitCursor(mainWindow)) { using (var dlg = new ConfirmDeleteObjectDlg(m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider"))) { var ui = CmObjectUi.MakeUi(m_cache, lr.Hvo); ui.Mediator = Mediator; ui.PropTable = m_propertyTable; //We need this to determine which kind of relation we are deleting var lrtOwner = lr.Owner as ILexRefType; var userWs = m_cache.WritingSystemFactory.UserWs; var tisb = TsStringUtils.MakeIncStrBldr(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); switch ((LexRefTypeTags.MappingTypes)lrtOwner.MappingType) { case LexRefTypeTags.MappingTypes.kmtSenseTree: case LexRefTypeTags.MappingTypes.kmtEntryTree: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree: case LexRefTypeTags.MappingTypes.kmtSenseUnidirectional: case LexRefTypeTags.MappingTypes.kmtEntryUnidirectional: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseUnidirectional: tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(String.Format(LexEdStrings.ksDeleteLexTree, StringUtils.kChHardLB)); dlg.SetDlgInfo(ui, m_cache, Mediator, m_propertyTable, tisb.GetString()); break; default: dlg.SetDlgInfo(ui, m_cache, Mediator, m_propertyTable); break; } if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoDeleteRelation, LexEdStrings.ksRedoDeleteRelation, m_obj, () => { m_cache.DomainDataByFlid.DeleteObj(lr.Hvo); }); //Update the display because we have removed this slice from the Lexical entry. UpdateForDelete(lr); } } } } }
/// <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; } } } }
public void DeleteReversalIndex(IReversalIndex ri) { CheckDisposed(); Form mainWindow = (Form)m_mediator.PropertyTable.GetValue("window"); mainWindow.Cursor = Cursors.WaitCursor; using (ConfirmDeleteObjectDlg dlg = new ConfirmDeleteObjectDlg()) { SIL.FieldWorks.FdoUi.CmObjectUi ui = new SIL.FieldWorks.FdoUi.CmObjectUi(ri); dlg.SetDlgInfo(ui, m_cache, m_mediator); dlg.TopMessage = LexEdStrings.ksDeletingThisRevIndex; dlg.BottomQuestion = LexEdStrings.ksReallyWantToDeleteRevIndex; if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { ReallyDeleteReversalIndex(ri); } } mainWindow.Cursor = Cursors.Default; }
public void DeleteReversalIndex(IReversalIndex ri) { CheckDisposed(); var mainWindow = (Form)m_mediator.PropertyTable.GetValue("window"); using (new WaitCursor(mainWindow)) { using (var dlg = new ConfirmDeleteObjectDlg(m_mediator.HelpTopicProvider)) { var ui = new CmObjectUi(ri); dlg.SetDlgInfo(ui, Cache, m_mediator); dlg.TopMessage = LexEdStrings.ksDeletingThisRevIndex; dlg.BottomQuestion = LexEdStrings.ksReallyWantToDeleteRevIndex; if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { ReallyDeleteReversalIndex(ri); } } } }
/// <summary> /// This method is called when a user selects Delete Relation on a Lexical Relation slice. /// For: sequence relations (eg. Calendar) /// collection relations (eg. Synonym) /// tree relation (parts/whole when deleting a Whole slice) /// </summary> /// <param name="hvo"></param> public void DeleteFromReference(ILexReference lr) { CheckDisposed(); if (lr == null) { 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 { var mainWindow = (Form)Mediator.PropertyTable.GetValue("window"); using (new WaitCursor(mainWindow)) { using (var dlg = new ConfirmDeleteObjectDlg(m_mediator.HelpTopicProvider)) { var ui = CmObjectUi.MakeUi(m_cache, lr.Hvo); //We need this to determine which kind of relation we are deleting var lrtOwner = (ILexRefType)lr.Owner; var analWs = lrtOwner.Services.WritingSystems.DefaultAnalysisWritingSystem.Handle; var userWs = m_cache.WritingSystemFactory.UserWs; var tisb = TsIncStrBldrClass.Create(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); switch ((LexRefTypeTags.MappingTypes)lrtOwner.MappingType) { case LexRefTypeTags.MappingTypes.kmtSenseSequence: case LexRefTypeTags.MappingTypes.kmtEntrySequence: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseSequence: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseCollection: case LexRefTypeTags.MappingTypes.kmtEntryCollection: case LexRefTypeTags.MappingTypes.kmtSenseCollection: if (lr.TargetsRS.Count > 2) { tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(String.Format(LexEdStrings.ksDeleteSequenceCollectionA, StringUtils.kChHardLB.ToString())); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, analWs); tisb.Append(lrtOwner.ShortName); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(LexEdStrings.ksDeleteSequenceCollectionB); dlg.SetDlgInfo(ui, m_cache, Mediator, tisb.GetString()); } else { dlg.SetDlgInfo(ui, m_cache, Mediator); } break; default: dlg.SetDlgInfo(ui, m_cache, Mediator); break; } if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoDeleteRelation, LexEdStrings.ksRedoDeleteRelation, m_obj, () => { //If the user selected Yes, then we need to delete 'this' sense or entry lr.TargetsRS.Remove(m_obj); }); //Update the display because we have removed this slice from the Lexical entry. UpdateForDelete(lr); } } } } }
public bool OnDeleteRecord(object commandObject) { CheckDisposed(); // Don't handle this message if you're not the primary clerk. This allows, for // example, XmlBrowseRDEView.cs to handle the message instead. // Note from RandyR: One of these days we should probably subclass this object, and perhaps the record list more. // The "reversalEntries" clerk wants to handle the message, even though it isn't the primary clerk. // The m_shouldHandleDeletion member was also added, so the "reversalEntries" clerk's primary clerk // would not handle the message, and delete an entire reversal index. if (ShouldNotHandleDeletionMessage) return false; // It may be null: // 1. if the objects are bing deleted using the keys, // 2. the last one has been deleted, and // 3. the user keeps pressing the del key. // It looks like the command is not being disabled at all or fast enough. if (CurrentObjectHvo == 0) return true; // Don't allow an object to be deleted if it shouldn't be deleted. if (!CanDelete()) { ReportCannotDelete(); return true; } //when we are doing an automated test, we don't know how to click the "yes" button, so //look into the property table to see if there is a property controlling what we should do. var doingAutomatedTest = m_mediator.PropertyTable.GetBoolProperty("DoingAutomatedTest", false); ICmObject thingToDelete = GetObjectToDelete(CurrentObject); using (var dlg = new ConfirmDeleteObjectDlg(m_mediator.HelpTopicProvider)) { using (CmObjectUi uiObj = CmObjectUi.MakeUi(thingToDelete)) { string cannotDeleteMsg; if (uiObj.CanDelete(out cannotDeleteMsg)) dlg.SetDlgInfo(uiObj, Cache, m_mediator); else dlg.SetDlgInfo(uiObj, Cache, m_mediator, Cache.TsStrFactory.MakeString(cannotDeleteMsg, Cache.DefaultUserWs)); } var window = (Form) m_mediator.PropertyTable.GetValue("window"); if (doingAutomatedTest || DialogResult.Yes == dlg.ShowDialog(window)) { using (new WaitCursor(window)) { using (ProgressState state = FwXWindow.CreatePredictiveProgressState(m_mediator, "Delete record")) { state.SetMilestone(xWorksStrings.DeletingTheObject); state.Breath(); // We will certainly switch records, but we're going to suppress the usual Save after we // switch, so the user can at least Undo one level, the actual deletion. But Undoing // that may not get us back to the current record, so we'd better not allow anything // that's already on the stack to be undone. SaveOnChangeRecord(); m_suppressSaveOnChangeRecord = true; try { var cmd = (Command) commandObject; UndoableUnitOfWorkHelper.Do(cmd.UndoText, cmd.RedoText, Cache.ActionHandlerAccessor, () => m_list.DeleteCurrentObject(state, thingToDelete)); } finally { m_suppressSaveOnChangeRecord = false; } } } } } return true; //we handled this, no need to ask anyone else. }
/// <summary> /// Delete the object, after showing a confirmation dialog. /// Return true if deleted, false, if cancelled. /// </summary> public bool DeleteUnderlyingObject() { CheckDisposed(); ICmObject cmo = GetCurrentCmObject(); if (cmo != null && m_obj != null && cmo.Hvo == m_obj.Hvo) { object command = this; if (m_command != null) command = m_command; m_mediator.SendMessage("DeleteRecord", command); } else { var mainWindow = (Form) m_mediator.PropertyTable.GetValue("window"); using (new WaitCursor(mainWindow)) { using (var dlg = new ConfirmDeleteObjectDlg(m_mediator.HelpTopicProvider)) { string cannotDeleteMsg; if (CanDelete(out cannotDeleteMsg)) dlg.SetDlgInfo(this, m_cache, Mediator); else dlg.SetDlgInfo(this, m_cache, Mediator, m_cache.TsStrFactory.MakeString(cannotDeleteMsg, m_cache.DefaultUserWs)); if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { ReallyDeleteUnderlyingObject(); return true; // deleted it } } } } return false; // didn't delete it. }
/// <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(ILexReference lr) { CheckDisposed(); if (lr == null) { 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 { var mainWindow = Mediator.PropertyTable.GetValue("window") as Form; using (new WaitCursor(mainWindow)) { using (var dlg = new ConfirmDeleteObjectDlg(m_mediator.HelpTopicProvider)) { var ui = CmObjectUi.MakeUi(m_cache, lr.Hvo); //We need this to determine which kind of relation we are deleting var lrtOwner = lr.Owner as ILexRefType; var userWs = m_cache.WritingSystemFactory.UserWs; var tisb = TsIncStrBldrClass.Create(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); switch ((LexRefTypeTags.MappingTypes)lrtOwner.MappingType) { case LexRefTypeTags.MappingTypes.kmtSenseTree: case LexRefTypeTags.MappingTypes.kmtEntryTree: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree: tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(String.Format(LexEdStrings.ksDeleteLexTree, StringUtils.kChHardLB)); dlg.SetDlgInfo(ui, m_cache, Mediator, tisb.GetString() ); break; default: dlg.SetDlgInfo(ui, m_cache, Mediator); break; } if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoDeleteRelation, LexEdStrings.ksRedoDeleteRelation, m_obj, () => { m_cache.DomainDataByFlid.DeleteObj(lr.Hvo); }); //Update the display because we have removed this slice from the Lexical entry. UpdateForDelete(lr); } } } } }
/// <summary> /// This method is called when a user selects Delete Relation on a Lexical Relation slice. /// For: sequence relations (eg. Calendar) /// collection relations (eg. Synonym) /// tree relation (parts/whole when deleting a Whole slice) /// </summary> /// <param name="hvo"></param> public void DeleteFromReference(ILexReference lr) { CheckDisposed(); if (lr == null) { 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 { var mainWindow = (Form) Mediator.PropertyTable.GetValue("window"); using (new WaitCursor(mainWindow)) { using (var dlg = new ConfirmDeleteObjectDlg(m_mediator.HelpTopicProvider)) { var ui = CmObjectUi.MakeUi(m_cache, lr.Hvo); //We need this to determine which kind of relation we are deleting var lrtOwner = (ILexRefType) lr.Owner; var analWs = lrtOwner.Services.WritingSystems.DefaultAnalysisWritingSystem.Handle; var userWs = m_cache.WritingSystemFactory.UserWs; var tisb = TsIncStrBldrClass.Create(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); switch ((LexRefTypeTags.MappingTypes)lrtOwner.MappingType) { case LexRefTypeTags.MappingTypes.kmtSenseSequence: case LexRefTypeTags.MappingTypes.kmtEntrySequence: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseSequence: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseCollection: case LexRefTypeTags.MappingTypes.kmtEntryCollection: case LexRefTypeTags.MappingTypes.kmtSenseCollection: if (lr.TargetsRS.Count > 2) { tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(String.Format(LexEdStrings.ksDeleteSequenceCollectionA, StringUtils.kChHardLB.ToString())); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, analWs); tisb.Append(lrtOwner.ShortName); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(LexEdStrings.ksDeleteSequenceCollectionB); dlg.SetDlgInfo(ui, m_cache, Mediator, tisb.GetString()); } else { dlg.SetDlgInfo(ui, m_cache, Mediator); } break; default: dlg.SetDlgInfo(ui, m_cache, Mediator); break; } if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoDeleteRelation, LexEdStrings.ksRedoDeleteRelation, m_obj, () => { //If the user selected Yes, then we need to delete 'this' sense or entry lr.TargetsRS.Remove(m_obj); }); //Update the display because we have removed this slice from the Lexical entry. UpdateForDelete(lr); } } } } }
public void DeleteReversalIndex(IReversalIndex ri) { CheckDisposed(); var mainWindow = (Form)m_mediator.PropertyTable.GetValue("window"); using (new WaitCursor(mainWindow)) { using (var dlg = new ConfirmDeleteObjectDlg(m_mediator.HelpTopicProvider)) { var ui = new CmObjectUi(ri); dlg.SetDlgInfo(ui, Cache, m_mediator); dlg.TopMessage = LexEdStrings.ksDeletingThisRevIndex; dlg.BottomQuestion = LexEdStrings.ksReallyWantToDeleteRevIndex; if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) ReallyDeleteReversalIndex(ri); } } }