private bool RunMergeEntryDialog(object argument, bool fLoseNoTextData) { ICmObject obj = m_mediator.PropertyTable.GetValue("ActiveClerkSelectedObject") as ICmObject; Debug.Assert(obj != null); if (obj == null) { return(false); // should never happen, but nothing we can do if it does! } FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache"); Debug.Assert(cache != null); Debug.Assert(cache == obj.Cache); ILexEntry currentEntry = obj as ILexEntry; if (currentEntry == null) { int hvoEntry = cache.GetOwnerOfObjectOfClass(obj.Hvo, LexEntry.kclsidLexEntry); if (hvoEntry != 0) { currentEntry = LexEntry.CreateFromDBObject(cache, hvoEntry); } } Debug.Assert(currentEntry != null); if (currentEntry == null) { return(false); } using (MergeEntryDlg dlg = new MergeEntryDlg()) { Debug.Assert(argument != null && argument is XCore.Command); dlg.SetDlgInfo(cache, m_mediator, currentEntry); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { int entryID = dlg.SelectedID; ILexEntry survivor = LexEntry.CreateFromDBObject(cache, entryID); Debug.Assert(survivor != currentEntry); cache.BeginUndoTask(SIL.FieldWorks.LexText.Controls.LexTextControls.ksUndoMergeEntry, SIL.FieldWorks.LexText.Controls.LexTextControls.ksRedoMergeEntry); // If lexeme forms differ, make the source lexeme form an allomorph of the target entry. if (survivor.LexemeFormOA.Form.VernacularDefaultWritingSystem != currentEntry.LexemeFormOA.Form.VernacularDefaultWritingSystem) { survivor.AlternateFormsOS.Append(currentEntry.LexemeFormOA.Hvo); } survivor.MergeObject(currentEntry, fLoseNoTextData); cache.EndUndoTask(); survivor.DateModified = DateTime.Now; MessageBox.Show(null, SIL.FieldWorks.LexText.Controls.LexTextControls.ksEntriesHaveBeenMerged, SIL.FieldWorks.LexText.Controls.LexTextControls.ksMergeReport, MessageBoxButtons.OK, MessageBoxIcon.Information); m_mediator.SendMessage("JumpToRecord", entryID); } } return(true); }
private bool RunMergeEntryDialog(object argument, bool fLoseNoTextData) { ICmObject obj = m_mediator.PropertyTable.GetValue("ActiveClerkSelectedObject") as ICmObject; Debug.Assert(obj != null); if (obj == null) { return(false); // should never happen, but nothing we can do if it does! } FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache"); Debug.Assert(cache != null); Debug.Assert(cache == obj.Cache); ILexEntry currentEntry = obj as ILexEntry; if (currentEntry == null) { currentEntry = obj.OwnerOfClass(LexEntryTags.kClassId) as ILexEntry; } Debug.Assert(currentEntry != null); if (currentEntry == null) { return(false); } using (MergeEntryDlg dlg = new MergeEntryDlg()) { Debug.Assert(argument != null && argument is Command); dlg.SetDlgInfo(cache, m_mediator, currentEntry); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var survivor = dlg.SelectedObject as ILexEntry; Debug.Assert(survivor != currentEntry); UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoMergeEntry, LexTextControls.ksRedoMergeEntry, cache.ActionHandlerAccessor, () => { survivor.MergeObject(currentEntry, fLoseNoTextData); survivor.DateModified = DateTime.Now; }); MessageBox.Show(null, LexTextControls.ksEntriesHaveBeenMerged, LexTextControls.ksMergeReport, MessageBoxButtons.OK, MessageBoxIcon.Information); m_mediator.SendMessage("JumpToRecord", survivor.Hvo); } } return(true); }
private bool RunMergeEntryDialog(object argument, bool fLoseNoTextData) { ICmObject obj = m_mediator.PropertyTable.GetValue("ActiveClerkSelectedObject") as ICmObject; Debug.Assert(obj != null); if (obj == null) return false; // should never happen, but nothing we can do if it does! FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache"); Debug.Assert(cache != null); Debug.Assert(cache == obj.Cache); ILexEntry currentEntry = obj as ILexEntry; if (currentEntry == null) { currentEntry = obj.OwnerOfClass(LexEntryTags.kClassId) as ILexEntry; } Debug.Assert(currentEntry != null); if (currentEntry == null) return false; using (MergeEntryDlg dlg = new MergeEntryDlg()) { Debug.Assert(argument != null && argument is Command); dlg.SetDlgInfo(cache, m_mediator, currentEntry); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var survivor = dlg.SelectedObject as ILexEntry; Debug.Assert(survivor != currentEntry); UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoMergeEntry, LexTextControls.ksRedoMergeEntry, cache.ActionHandlerAccessor, () => { survivor.MergeObject(currentEntry, fLoseNoTextData); survivor.DateModified = DateTime.Now; }); MessageBox.Show(null, LexTextControls.ksEntriesHaveBeenMerged, LexTextControls.ksMergeReport, MessageBoxButtons.OK, MessageBoxIcon.Information); m_mediator.SendMessage("JumpToRecord", survivor.Hvo); } } return true; }
private bool RunMergeEntryDialog(object argument, bool fLoseNoTextData) { ICmObject obj = m_mediator.PropertyTable.GetValue("ActiveClerkSelectedObject") as ICmObject; Debug.Assert(obj != null); if (obj == null) return false; // should never happen, but nothing we can do if it does! FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache"); Debug.Assert(cache != null); Debug.Assert(cache == obj.Cache); ILexEntry currentEntry = obj as ILexEntry; if (currentEntry == null) { int hvoEntry = cache.GetOwnerOfObjectOfClass(obj.Hvo, LexEntry.kclsidLexEntry); if (hvoEntry != 0) currentEntry = LexEntry.CreateFromDBObject(cache, hvoEntry); } Debug.Assert(currentEntry != null); if (currentEntry == null) return false; using (MergeEntryDlg dlg = new MergeEntryDlg()) { Debug.Assert(argument != null && argument is XCore.Command); dlg.SetDlgInfo(cache, m_mediator, currentEntry); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { int entryID = dlg.SelectedID; ILexEntry survivor = LexEntry.CreateFromDBObject(cache, entryID); Debug.Assert(survivor != currentEntry); cache.BeginUndoTask(SIL.FieldWorks.LexText.Controls.LexTextControls.ksUndoMergeEntry, SIL.FieldWorks.LexText.Controls.LexTextControls.ksRedoMergeEntry); // If lexeme forms differ, make the source lexeme form an allomorph of the target entry. if (survivor.LexemeFormOA.Form.VernacularDefaultWritingSystem != currentEntry.LexemeFormOA.Form.VernacularDefaultWritingSystem) { survivor.AlternateFormsOS.Append(currentEntry.LexemeFormOA.Hvo); } survivor.MergeObject(currentEntry, fLoseNoTextData); cache.EndUndoTask(); survivor.DateModified = DateTime.Now; MessageBox.Show(null, SIL.FieldWorks.LexText.Controls.LexTextControls.ksEntriesHaveBeenMerged, SIL.FieldWorks.LexText.Controls.LexTextControls.ksMergeReport, MessageBoxButtons.OK, MessageBoxIcon.Information); m_mediator.SendMessage("JumpToRecord", entryID); } } return true; }