public void kcptUnicodeTests() { var lp = Cache.LanguageProject; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => lp.EthnologueCode = "NEWCode"); // Null to new value should have cvIns be the new length and cvDel be 0. CheckChanges(1, 0, lp.Hvo, LangProjectTags.kflidEthnologueCode, 0, 7, 0); ClearChanges(); m_actionHandler.Undo(); CheckChanges(1, 0, lp.Hvo, LangProjectTags.kflidEthnologueCode, 0, 0, 7); m_actionHandler.Redo(); ClearChanges(); UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => lp.EthnologueCode = "NEWERCode"); // Old value to new value should have cvIns be the new length and cvDel be old value length. CheckChanges(1, 0, lp.Hvo, LangProjectTags.kflidEthnologueCode, 0, 9, 7); ClearChanges(); m_actionHandler.Undo(); CheckChanges(1, 0, lp.Hvo, LangProjectTags.kflidEthnologueCode, 0, 7, 9); m_actionHandler.Redo(); ClearChanges(); UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => lp.EthnologueCode = null); // Old value to null should have cvIns be 0 and cvDel be old value length. CheckChanges(1, 0, lp.Hvo, LangProjectTags.kflidEthnologueCode, 0, 0, 9); ClearChanges(); m_actionHandler.Undo(); CheckChanges(1, 0, lp.Hvo, LangProjectTags.kflidEthnologueCode, 0, 9, 0); m_actionHandler.Redo(); ClearChanges(); }
internal static void AddComplexFormComponents(FdoCache cache, ILexEntry entry, List <ICmObject> list, List <ILexEntryType> types = null) { UndoableUnitOfWorkHelper.Do("undo", "redo", cache.ActionHandlerAccessor, () => { var dummy = cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(); var ler = cache.ServiceLocator.GetInstance <ILexEntryRefFactory>().Create(); dummy.EntryRefsOS.Add(ler); ler.RefType = LexEntryRefTags.krtComplexForm; foreach (var item in list) { ler.ComponentLexemesRS.Add(item); ler.PrimaryLexemesRS.Add(item); } // Change the owner to the real entry: this bypasses the check for circular references in FdoList.Add(). entry.EntryRefsOS.Add(ler); dummy.Delete(); if (types == null) { return; } foreach (var type in types) { ler.ComplexEntryTypesRS.Add(type); } }); }
/// <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(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 { using (var dlg = new LexReferenceDetailsDlg(m_mediator.HelpTopicProvider)) { dlg.ReferenceName = lr.Name.AnalysisDefaultWritingSystem.Text; dlg.ReferenceComment = lr.Comment.AnalysisDefaultWritingSystem.Text; if (dlg.ShowDialog() == DialogResult.OK) { using (UndoableUnitOfWorkHelper helper = new UndoableUnitOfWorkHelper(m_cache.ActionHandlerAccessor, LexEdStrings.ksUndoEditRefSetDetails, LexEdStrings.ksRedoEditRefSetDetails)) { lr.Name.SetAnalysisDefaultWritingSystem(dlg.ReferenceName); lr.Comment.SetAnalysisDefaultWritingSystem(dlg.ReferenceComment); helper.RollBack = false; } } } } }
protected override void HandleChooser() { using (var dlg = new GenDateChooserDlg(m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider"))) { dlg.Text = string.Format(DetailControlsStrings.ksFieldChooserDlgTitle, m_fieldName); GenDate x = (m_cache.DomainDataByFlid as ISilDataAccessManaged).get_GenDateProp(m_obj.Hvo, m_flid); // If we don't yet have a value, make today the default. if (x.IsEmpty) { DateTime now = DateTime.Now; x = new GenDate(GenDate.PrecisionType.Exact, now.Month, now.Day, now.Year, true); } dlg.GenericDate = x; if (dlg.ShowDialog(m_propertyTable.GetValue <IWin32Window>("window")) == DialogResult.OK) { var genDate = dlg.GenericDate; UndoableUnitOfWorkHelper.Do(string.Format(DetailControlsStrings.ksUndoSet, m_fieldName), string.Format(DetailControlsStrings.ksRedoSet, m_fieldName), m_obj, () => { (m_cache.DomainDataByFlid as ISilDataAccessManaged).SetGenDate(m_obj.Hvo, m_flid, genDate); }); m_genDateTextBox.Text = genDate.ToLongString(); } } }
public void MakeContextMenu_CheckedStates_SelMatchesTag() { // Provide hvoTagPoss and SelectedWordforms, create a markup tag and examine it. // Setup the SelectedWordforms property var tempList = new List <AnalysisOccurrence> { m_occurrences[0], m_occurrences[1] }; m_tagChild.SelectedWordforms = tempList; const int itestItem = 1; UndoableUnitOfWorkHelper.Do("UndoTagTest", "RedoTagTest", Cache.ActionHandlerAccessor, () => m_tagChild.CallMakeTextTagInstance(m_possTags[itestItem])); // SUT using (var menu = new ContextMenuStrip()) { m_tagChild.CallMakeContextMenuForTags(menu, m_textMarkupTags); // Verification of SUT; Only one should be checked and that in a submenu var subList = AssertHasMenuWithText(menu.Items, kFTO_RRG_Semantics, 3); Assert.IsNotNull(subList, "No " + kFTO_RRG_Semantics + " menu!?"); var subMenu = subList.DropDownItems; var expectedStates = new bool[subMenu.Count]; expectedStates[itestItem] = true; AssertMenuCheckState(expectedStates, subMenu); } }
public void MoveWordToSameRowLaterColBeforeMtm() { var allParaOccurrences = MakeAnalysesUsedN(1); var row0 = MakeRow("1a"); var cellPart0_1 = MakeWordGroup(row0, 1, allParaOccurrences[0], allParaOccurrences[0]); MakeMovedTextMarker(row0, 4, cellPart0_1, true); EndSetupTask(); // SUT needs own UOW in order to test Undo/Redo IConstChartRow dummy; UndoableUnitOfWorkHelper.Do("TestUndo", "TestRedo", Cache.ActionHandlerAccessor, () => m_logic.MoveToColumn(3, out dummy)); VerifyMoveOccurrenceToSameRowLaterColBeforeMtm(allParaOccurrences, cellPart0_1, 1); // Now test Undo Assert.IsTrue(Cache.ActionHandlerAccessor.CanUndo()); Cache.ActionHandlerAccessor.Undo(); VerifyRow(0, "1a", 2); // removed the new WordGroup. VerifyWordGroup(0, 0, m_allColumns[1], new List <AnalysisOccurrence> { allParaOccurrences[0] }); VerifyMovedText(0, 1, m_allColumns[4], cellPart0_1, true); Assert.AreEqual(2, m_mockRibbon.CSelectFirstCalls); AssertUsedAnalyses(allParaOccurrences, 1); // Verify various PropChanged calls. //VerifyOccurrenceListChange(allParaOccurrences, undoSpy, 1, 2); // 1, 0, 1 would be preferable, but this is also valid and is what currently happens. // And now Redo Assert.IsTrue(Cache.ActionHandlerAccessor.CanRedo()); Cache.ActionHandlerAccessor.Redo(); VerifyMoveOccurrenceToSameRowLaterColBeforeMtm(allParaOccurrences, cellPart0_1, 3); }
public void ChangeRow() { var allParaOccurrences = MakeAnalysesUsedN(3); var row0 = MakeRow("1a"); var row1 = MakeRow("1b"); var cellPart0_1 = MakeWordGroup(row0, 1, allParaOccurrences[0], allParaOccurrences[0]); m_helper.MakeChartMarker(row0, 1, m_helper.GetAMarker()); MakeWordGroup(row1, 1, allParaOccurrences[1], allParaOccurrences[1]); MakeWordGroup(row1, 3, allParaOccurrences[2], allParaOccurrences[2]); var cellPartsToMove = new IConstituentChartCellPart[] { cellPart0_1 }; EndSetupTask(); // SUT needs its own UOW to test Undo/Redo // SUT UndoableUnitOfWorkHelper.Do("TestChangeRow", "TestChangeRow", Cache.ActionHandlerAccessor, () => m_logic.ChangeRow(cellPartsToMove, row0, row1, 0, 1)); VerifyChangeRow(row0, cellPartsToMove, row1, "cellParts should have been moved to new row", 1); // Now test Undo Assert.IsTrue(Cache.ActionHandlerAccessor.CanUndo()); Cache.ActionHandlerAccessor.Undo(); VerifyChangeRow(row1, cellPartsToMove, row0, "cellParts should have been moved back to original row by Undo", 0); // And now Redo Assert.IsTrue(Cache.ActionHandlerAccessor.CanRedo()); Cache.ActionHandlerAccessor.Redo(); VerifyChangeRow(row0, cellPartsToMove, row1, "cellParts should have been moved again to new row by redo", 1); }
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { if (DialogResult == DialogResult.OK) { if (string.IsNullOrEmpty(m_titleTextBox.Text)) { e.Cancel = true; MessageBox.Show(this, LexTextControls.ksFillInTitle, LexTextControls.ksMissingInformation, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } using (new WaitCursor(this)) { UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoCreateRecord, LexTextControls.ksRedoCreateRecord, m_cache.ActionHandlerAccessor, () => { var recFactory = m_cache.ServiceLocator.GetInstance <IRnGenericRecFactory>(); int posHvo = ((HvoTreeNode)m_typeCombo.SelectedNode).Hvo; ICmPossibility type = m_cache.ServiceLocator.GetInstance <ICmPossibilityRepository>().GetObject(posHvo); switch (m_owner.ClassID) { case RnResearchNbkTags.kClassId: m_newRecord = recFactory.Create((IRnResearchNbk)m_owner, m_titleTextBox.Tss, type); break; case RnGenericRecTags.kClassId: m_newRecord = recFactory.Create((IRnGenericRec)m_owner, m_titleTextBox.Tss, type); break; } }); } } base.OnClosing(e); }
public bool OnMergeReversalPOS(object cmd) { LcmCache cache = Cache; var labels = new List<ObjectLabel>(); foreach (IPartOfSpeech pos in MergeOrMoveCandidates) labels.Add(ObjectLabel.CreateObjectLabelOnly(cache, pos, "ShortNameTSS", "best analysis")); using (SimpleListChooser dlg = new SimpleListChooser(cache, null, m_propertyTable.GetValue<IHelpTopicProvider>("HelpTopicProvider"), labels, null, LexEdStrings.ksCategoryToMergeInto, null)) { dlg.SetHelpTopic("khtpMergeCategories"); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var currentPOS = POS; var survivor = (IPartOfSpeech)dlg.ChosenOne.Object; // Pass false to MergeObject, since we really don't want to merge the string info. UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoMergeRevCategory, LexEdStrings.ksRedoMergeRevCategory, cache.ActionHandlerAccessor, ()=> survivor.MergeObject(currentPOS, false)); // Note: PropChanged should happen on the old owner and the new in the 'Add" method call. // Have to jump to a main PartOfSpeech, as RecordClerk doesn't know anything about subcategories. m_mediator.BroadcastMessageUntilHandled("JumpToRecord", survivor.MainPossibility.Hvo); } } return true; }
// The body of OnMacro is isolated so we don't have to fake all the objects needed to get the (typically mock) selection in testing. internal bool DoMacro(object commandObject, IVwSelection sel) { var macro = GetMacro(commandObject); if (macro == null) { return(true); // Paranoia, it should be disabled. } int ichA, hvoA, flid, ws, ichE, start, length; ICmObject obj; if (!SafeToDoMacro(sel, out obj, out flid, out ws, out start, out length) || !macro.Enabled(obj, flid, ws, start, length)) { return(true); } string commandName = macro.CommandName; // We normally let undo and redo be localized independently, but we compromise in the interests of making macros // easier to create. string undo = string.Format(xWorksStrings.ksUndoMacro, commandName); string redo = string.Format(xWorksStrings.ksRedoMacro, commandName); UndoableUnitOfWorkHelper.Do(undo, redo, obj.Cache.ActionHandlerAccessor, () => macro.RunMacro(obj, flid, ws, start, length)); return(true); }
public void showProperties() { CheckDisposed(); var pic = (ICmPicture)Object; var app = (IApp)m_mediator.PropertyTable.GetValue("App"); using (var dlg = new PicturePropertiesDialog(m_cache, pic, m_mediator.HelpTopicProvider, app, true)) { if (dlg.Initialize()) { var stylesheet = FontHeightAdjuster.StyleSheetFromMediator(m_mediator); dlg.UseMultiStringCaption(m_cache, WritingSystemServices.kwsVernAnals, stylesheet); dlg.SetMultilingualCaptionValues(pic.Caption); if (dlg.ShowDialog() == DialogResult.OK) { UndoableUnitOfWorkHelper.Do(DetailControlsStrings.ksUndoUpdatePicture, DetailControlsStrings.ksRedoUpdatePicture, m_obj, () => { string strLocalPictures = CmFolderTags.DefaultPictureFolder; dlg.GetMultilingualCaptionValues(pic.Caption); pic.UpdatePicture(dlg.CurrentFile, null, strLocalPictures, 0); }); InstallPicture(m_picBox); m_lastSize = new Size(0, 0); // forces OnSizeChanged to do something (we need to adjust to new aspect ratio). OnSizeChanged(new EventArgs()); } } } }
/// <summary> /// Handle launching of the MSA editor. /// </summary> protected override void HandleChooser() { using (MsaCreatorDlg dlg = new MsaCreatorDlg()) { IMoMorphSynAnalysis originalMsa = m_obj as IMoMorphSynAnalysis; ILexEntry entry = originalMsa.Owner as ILexEntry; dlg.SetDlgInfo(m_cache, m_persistProvider, m_mediator, m_propertyTable, entry, SandboxGenericMSA.Create(originalMsa), originalMsa.Hvo, true, String.Format(LexEdStrings.ksEditX, Slice.Label)); if (dlg.ShowDialog(FindForm()) == DialogResult.OK) { SandboxGenericMSA sandboxMsa = dlg.SandboxMSA; if (!originalMsa.EqualsMsa(sandboxMsa)) { UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoEditFunction, LexEdStrings.ksRedoEditFunction, entry, () => { originalMsa.UpdateOrReplace(sandboxMsa); }); } } } }
public override void AddToDatabase(FdoCache cache) { if (m_fInDatabase) { return; // It's already in the database, so nothing more can be done. } using (var undoHelper = new UndoableUnitOfWorkHelper( cache.ServiceLocator.GetInstance <IActionHandler>(), MGAStrings.ksUndoCreateInflectionFeature, MGAStrings.ksRedoCreateInflectionFeature)) { m_featDefn = cache.LanguageProject.MsFeatureSystemOA.AddFeatureFromXml(m_node); // Attempt to add feature to category as an inflectable feature var sPosId = XmlUtils.GetOptionalAttributeValue(m_node, "posid"); var node = m_node; while (node.ParentNode != null && sPosId == null) { node = node.ParentNode; sPosId = XmlUtils.GetOptionalAttributeValue(node, "posid"); } foreach (IPartOfSpeech pos in cache.LanguageProject.PartsOfSpeechOA.ReallyReallyAllPossibilities) { if (pos.CatalogSourceId == sPosId) { pos.InflectableFeatsRC.Add(m_featDefn); break; } } undoHelper.RollBack = false; } }
public void OnAddWordGlossesToFreeTrans_ORCs() { ISegment seg = m_para0_0.SegmentsOS[0]; ITsStrBldr strBldr = m_para0_0.Contents.GetBldr(); Guid footnoteGuid = Guid.NewGuid(); TsStringUtils.InsertOrcIntoPara(footnoteGuid, FwObjDataTypes.kodtOwnNameGuidHot, strBldr, 7, 7, Cache.DefaultVernWs); UndoableUnitOfWorkHelper.Do("undo Add ORC", "redo Add ORC", Cache.ActionHandlerAccessor, () => { m_para0_0.Contents = strBldr.GetString(); }); SetUpMocksForOnAddWordGlossesToFreeTransTest(seg); SetUpGlosses(seg, "hope", null, "this", "works"); m_interlinDoc.OnAddWordGlossesToFreeTrans(null); strBldr.Clear(); strBldr.Replace(0, 0, "hope this works.", StyleUtils.CharStyleTextProps(null, Cache.DefaultAnalWs)); TsStringUtils.InsertOrcIntoPara(footnoteGuid, FwObjDataTypes.kodtNameGuidHot, strBldr, 4, 4, Cache.DefaultAnalWs); AssertEx.AreTsStringsEqual(strBldr.GetString(), seg.FreeTranslation.AnalysisDefaultWritingSystem); }
public void MoveFirstOccurrenceToCol1() { var allParaOccurrences = MakeAnalysesUsedN(0); EndSetupTask(); // SUT needs its own UOW to test Undo/Redo // SUT IConstChartRow dummy; UndoableUnitOfWorkHelper.Do("TestUndo", "TestRedo", Cache.ActionHandlerAccessor, () => m_logic.MoveToColumn(1, out dummy)); VerifyMoveFirstOccurrenceToCol1(allParaOccurrences, 1); // Now test Undo Assert.IsTrue(Cache.ActionHandlerAccessor.CanUndo()); Cache.ActionHandlerAccessor.Undo(); Assert.AreEqual(0, m_chart.RowsOS.Count, "no rows after undo MoveFirstToCol1"); Assert.AreEqual(2, m_mockRibbon.CSelectFirstCalls); AssertUsedAnalyses(allParaOccurrences, 0); // Verify various PropChanged calls. //VerifyOccurrenceListChange(allParaOccurrences, undoSpy, 0, 1); // Todo Gordon: With the new architecture, the whole NotifyChangeSpy system is in question // since PropChanged() is no longer used. //undoSpy.AssertHasNotification(m_chart.Hvo, DsConstChartTags.kflidRows, 0, 0, 1); // And now Redo Assert.IsTrue(Cache.ActionHandlerAccessor.CanRedo()); Cache.ActionHandlerAccessor.Redo(); VerifyMoveFirstOccurrenceToCol1(allParaOccurrences, 3); }
public bool OnPromoteReversalSubPOS(object cmd) { Slice slice = m_dataEntryForm.CurrentSlice; Debug.Assert(slice != null, "No slice was current"); if (slice != null) { LcmCache cache = m_dataEntryForm.Cache; var sliceObj = slice.Object as ICmPossibility; var newOwner = sliceObj.Owner.Owner; switch (newOwner.ClassID) { default: throw new ArgumentException("Illegal class."); case PartOfSpeechTags.kClassId: { var pos = (IPartOfSpeech)newOwner; UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoPromote, LexEdStrings.ksRedoPromote, pos.Cache.ActionHandlerAccessor, ()=>pos.SubPossibilitiesOS.Add(sliceObj)); break; } case CmPossibilityListTags.kClassId: { var posList = (ICmPossibilityList)newOwner; UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoPromote, LexEdStrings.ksRedoPromote, posList.Cache.ActionHandlerAccessor, ()=>posList.PossibilitiesOS.Add(sliceObj)); break; } } } return true; }
public void MoveSecondWordToSameCol() { var allParaOccurrences = MakeAnalysesUsedN(1); var row0 = MakeRow("1a"); MakeWordGroup(row0, 1, allParaOccurrences[0], allParaOccurrences[0]); EndSetupTask(); // SUT needs own UOW to test Undo/Redo // SUT IConstChartRow dummy; UndoableUnitOfWorkHelper.Do("TestUndo", "TestRedo", Cache.ActionHandlerAccessor, () => m_logic.MoveToColumn(1, out dummy)); VerifyMoveSecondOccurrenceToSameCol(allParaOccurrences, 1); // Now test Undo Assert.IsTrue(Cache.ActionHandlerAccessor.CanUndo()); Cache.ActionHandlerAccessor.Undo(); VerifyRow(0, "1a", 1); // didn't remove the one we didn't create. VerifyWordGroup(0, 0, m_allColumns[1], new List <AnalysisOccurrence> { allParaOccurrences[0] }); Assert.AreEqual(2, m_mockRibbon.CSelectFirstCalls); AssertUsedAnalyses(allParaOccurrences, 1); // Verify various PropChanged calls. //VerifyOccurrenceListChange(allParaOccurrences, undoSpy, 1, 2); // 1, 0, 1 would be preferable, but this is also valid and is what currently happens. // And now Redo Assert.IsTrue(Cache.ActionHandlerAccessor.CanRedo()); Cache.ActionHandlerAccessor.Redo(); VerifyMoveSecondOccurrenceToSameCol(allParaOccurrences, 3); // 1, 1, 0 would be preferable, but this is also valid and is what currently happens. }
protected override void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoInsertPhonologicalFeature, LexTextControls.ksRedoInsertPhonologicalFeature, m_cache.ActionHandlerAccessor, () => { m_selFeatDefn = m_cache.ServiceLocator.GetInstance <IFsClosedFeatureFactory>().Create(); m_cache.LangProject.PhFeatureSystemOA.FeaturesOC.Add(m_selFeatDefn); // create the two default feature values IFsSymFeatVal symFV; var closed = m_selFeatDefn as IFsClosedFeature; if (closed != null) { var symFeatFactory = m_cache.ServiceLocator.GetInstance <IFsSymFeatValFactory>(); symFV = symFeatFactory.Create(); closed.ValuesOC.Add(symFV); symFV.SimpleInit("+", "positive"); symFV = symFeatFactory.Create(); closed.ValuesOC.Add(symFV); symFV.SimpleInit("-", "negative"); } // end create }); DialogResult = DialogResult.Yes; Close(); }
public void ChangeColumn() { var allParaOccurrences = MakeAnalysesUsedN(1); var row0 = MakeRow("1a"); var cellPart0_1 = MakeWordGroup(row0, 1, allParaOccurrences[0], allParaOccurrences[0]); var cellPart0_1a = m_helper.MakeChartMarker(row0, 1, m_helper.GetAMarker()); var originalColumn = cellPart0_1.ColumnRA; var cellPartsToMove = new IConstituentChartCellPart[] { cellPart0_1, cellPart0_1a }; var newColumn = m_logic.AllMyColumns[2]; var hvoNewCol = newColumn.Hvo; EndSetupTask(); // SUT needs its own UOW to test Undo/Redo UndoableUnitOfWorkHelper.Do("TestChangeColumn", "TestChangeColumn", Cache.ActionHandlerAccessor, () => m_logic.ChangeColumn(cellPartsToMove, newColumn, row0)); VerifyChangeColumn(cellPartsToMove, newColumn, "cellPart should have been moved to new column"); // Now test Undo Assert.IsTrue(Cache.ActionHandlerAccessor.CanUndo()); Cache.ActionHandlerAccessor.Undo(); VerifyChangeColumn(cellPartsToMove, originalColumn, "cellPart should have returned to original column"); // And now Redo Assert.IsTrue(Cache.ActionHandlerAccessor.CanRedo()); Cache.ActionHandlerAccessor.Redo(); VerifyChangeColumn(cellPartsToMove, newColumn, "cellPart should have been moved again to new column"); }
public void MergeWritingSystemWithStyleDefnForToWs_DoesNotConvertStyleDefinition() { CoreWritingSystemDefinition fromWs; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-NO", true, false, out fromWs); CoreWritingSystemDefinition toWs; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-SO", true, false, out toWs); EnsureAnalysisWs(new[] { fromWs, toWs }); var style1 = Cache.ServiceLocator.GetInstance <IStStyleFactory>().Create(); Cache.LangProject.StylesOC.Add(style1); var fontOverrides = new Dictionary <int, FontInfo>(); var fontOverride = new FontInfo(); fontOverride.m_italic.ExplicitValue = true; fontOverrides[fromWs.Handle] = fontOverride; fontOverride = new FontInfo(); fontOverride.m_bold.ExplicitValue = true; fontOverrides[toWs.Handle] = fontOverride; var bldr = TsStringUtils.MakePropsBldr(); BaseStyleInfo.SaveFontOverridesToBuilder(fontOverrides, bldr); style1.Rules = bldr.GetTextProps(); m_actionHandler.EndUndoTask(); UndoableUnitOfWorkHelper.Do("doit", "undoit", m_actionHandler, () => WritingSystemServices.MergeWritingSystems(Cache, fromWs, toWs)); var styleInfo = new BaseStyleInfo(style1); var overrideInfo = styleInfo.OverrideCharacterStyleInfo(toWs.Handle); Assert.IsNotNull(overrideInfo); Assert.That(overrideInfo.Bold.Value, Is.True); Assert.That(overrideInfo.Italic.ValueIsSet, Is.False); }
public void DeleteCellParts() { var allParaOccurrences = MakeAnalysesUsedN(3); var row0 = MakeRow("1a"); MakeWordGroup(row0, 1, allParaOccurrences[0], allParaOccurrences[0]); EndSetupTask(); // SUT needs its own UOW to test Undo/Redo UndoableUnitOfWorkHelper.Do("TestDeleteCellParts", "TestDeleteCellParts", Cache.ActionHandlerAccessor, () => m_logic.DeleteCellParts(row0, 0, 1)); // The above deletes the row too! m_helper.VerifyDeletedHvos(new [] { row0.Hvo }, "Deleting last CellPart should delete row too."); // Now test Undo Assert.IsTrue(Cache.ActionHandlerAccessor.CanUndo()); Cache.ActionHandlerAccessor.Undo(); VerifyRow(0, "1a", 1); Assert.IsNotNull(row0.CellsOS, "Should be a CellPart here."); var cellPartUndo = row0.CellsOS[0] as IConstChartWordGroup; Assert.IsNotNull(cellPartUndo); Assert.AreEqual(allParaOccurrences[0].Analysis.Hvo, cellPartUndo.GetOccurrences()[0].Analysis.Hvo); // And now Redo Assert.IsTrue(Cache.ActionHandlerAccessor.CanRedo()); Cache.ActionHandlerAccessor.Redo(); m_helper.VerifyDeletedHvos(new [] { row0.Hvo }, "Deleting last CellPart should delete row too."); }
void Tag_Item_Click(object sender, EventArgs e) { var item = sender as TagPossibilityMenuItem; if (item == null) { return; } // save current selection info. (e.g. EnsureSelectedWordformsAndSegAreAllReal() can destroy it). var sh = SelectionHelper.Create(this); if (item.Checked) { UndoableUnitOfWorkHelper.Do(ITextStrings.ksUndoDeleteTextTag, ITextStrings.ksRedoDeleteTextTag, Cache.ActionHandlerAccessor, () => RemoveTextTagInstance(item.Possibility)); } else { UndoableUnitOfWorkHelper.Do(ITextStrings.ksUndoAddTextTag, ITextStrings.ksRedoAddTextTag, Cache.ActionHandlerAccessor, () => MakeTextTagInstance(item.Possibility)); } // We might try later to see if we can do without this! Nope. if (sh != null) { sh.RestoreSelectionAndScrollPos(); } }
public void MakeTagAnnotation_With1Wordform() { // Provide hvoTagPoss and SelectedWordforms, create a markup tag and examine it. // Setup the SelectedWordforms property var tempList = new List <AnalysisOccurrence> { m_occurrences[1] }; m_tagChild.SelectedWordforms = tempList; // SUT // Use the last possibility tag in the first list of tags ITextTag ttag = null; var hvoTtag = -1; UndoableUnitOfWorkHelper.Do("UndoTagTest", "RedoTagTest", Cache.ActionHandlerAccessor, () => { ttag = m_tagChild.CallMakeTextTagInstance(m_possTags[m_cposs - 1]); if (ttag != null) { hvoTtag = ttag.Hvo; } }); // Verification AssertTagExists(hvoTtag, "Tag should have been created."); VerifyTextTag(ttag, m_possTags[m_cposs - 1], tempList[0], tempList[0]); }
/// <summary> /// The user selected an item; now we actually need a LexEntryRef. /// </summary> /// <param name="hvoNew"></param> private void AddItem(ICmObject newObj) { CheckDisposed(); bool fForVariant = XmlUtils.GetOptionalBooleanAttributeValue(m_configurationNode, "forVariant", false); string sUndo, sRedo; if (fForVariant) { sUndo = LexEdStrings.ksUndoVariantOf; sRedo = LexEdStrings.ksRedoVariantOf; } else { sUndo = LexEdStrings.ksUndoAddComponent; sRedo = LexEdStrings.ksRedoAddComponent; } try { UndoableUnitOfWorkHelper.Do(sUndo, sRedo, m_obj, () => { ILexEntry ent = m_obj as ILexEntry; // Adapted from part of DtMenuHandler.AddNewLexEntryRef. ILexEntryRef ler = ent.Services.GetInstance <ILexEntryRefFactory>().Create(); ent.EntryRefsOS.Add(ler); if (fForVariant) { // The slice this is part of should only be displayed for lex entries with no VariantEntryRefs. Debug.Assert(ent.VariantEntryRefs.Count() == 0); ler.VariantEntryTypesRS.Add(ent.Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS[0] as ILexEntryType); ler.RefType = LexEntryRefTags.krtVariant; ler.HideMinorEntry = 0; } else { // The slice this is part of should only be displayed for lex entries with no ComplexEntryRefs. Debug.Assert(ent.ComplexFormEntryRefs.Count() == 0); //ler.ComplexEntryTypesRS.Append(ent.Cache.LangProject.LexDbOA.ComplexEntryTypesOA.PossibilitiesOS[0].Hvo); ler.RefType = LexEntryRefTags.krtComplexForm; ler.HideMinorEntry = 0; // LT-10928 // Logic similar to this is in EntrySequenceReferenceLauncher.AddNewObjectsToProperty() // (when LER already exists so slice is not ghost) ler.PrimaryLexemesRS.Add(newObj); // Since it's a new LER, we can't know it to be a derivative, so by default it is visible. // but do NOT do that here, it's now built into the process of adding it to PrimaryLexemes, // and we don't want to do it twice. // ler.ShowComplexFormsInRS.Add(newObj); ent.ChangeRootToStem(); } // Must do this AFTER setting the RefType (so dependent virtual properties can be updated properly) ler.ComponentLexemesRS.Add(newObj); }); } catch (ArgumentException) { MessageBoxes.ReportLexEntryCircularReference((ILexEntry)m_obj, newObj, true); } }
protected override void RemoveObjectFromList(int[] hvosOld, int ihvo, string undoText, string redoText) { if (!Cache.MetaDataCacheAccessor.get_IsVirtual(m_rootFlid)) { base.RemoveObjectFromList(hvosOld, ihvo, undoText, redoText); return; } if (Cache.MetaDataCacheAccessor.GetFieldName(m_rootFlid) != "ComplexFormEntries") { return; } int startHeight = m_rootb.Height; UndoableUnitOfWorkHelper.Do(undoText, redoText, m_rootObj, () => { var complex = m_rootObj.Services.GetInstance <ILexEntryRepository>().GetObject(hvosOld[ihvo]); // the selected object in the list is a complex entry which has this as one of its components. // We want to remove this from its components. var ler = (from item in complex.EntryRefsOS where item.RefType == LexEntryRefTags.krtComplexForm select item). First(); ler.PrimaryLexemesRS.Remove(m_rootObj); ler.ShowComplexFormsInRS.Remove(m_rootObj); ler.ComponentLexemesRS.Remove(m_rootObj); }); if (m_rootb != null) { CheckViewSizeChanged(startHeight, m_rootb.Height); // Redisplay (?) the vector property. m_rootb.SetRootObject(m_rootObj.Hvo, m_VectorReferenceVc, kfragTargetVector, m_rootb.Stylesheet); } }
public void SenseSearch_3WordDefinitionNotUsed() { //Setup const string searchString = "sky, God"; const string expectedNum1 = "1.1"; // bucket1 match 'sky' const string expectedNum2 = "4.9.6"; // bucket1 match 'God', under 'Heaven, Hell' const string expectedNum3 = "8.3.3"; // bucket2 match 'skylight', under 'Light' IEnumerable <ICmSemanticDomain> partialMatches; var entry = CreateLexEntry("waas", searchString); var sense = entry.SensesOS[0]; // This definition is too long and won't be used. If it were used, // the 8.3.3 bucket2 match would become a bucket1 match of 'Light', // And there would be an additional bucket 1 match of '8.3.3.1 Shine'. UndoableUnitOfWorkHelper.Do("Undo def", "Redo def", Cache.ActionHandlerAccessor, () => sense.Definition.SetAnalysisDefaultWritingSystem("God's light shine")); // SUT var result = m_semdomRepo.FindDomainsThatMatchWordsIn(sense, out partialMatches); // Verification var resultList = result.ToList(); var partialsList = partialMatches.ToList(); var cresult = resultList.Count; var cpartials = partialsList.Count; Assert.AreEqual(2, cresult, WRONG_NUMBER_OF_MATCHES); Assert.AreEqual(1, cpartials, WRONG_NUMBER_OF_MATCHES); Assert.AreEqual(expectedNum1, resultList[0].Abbreviation.AnalysisDefaultWritingSystem.Text, WRONG_SEMDOM_NUMBER); Assert.AreEqual(expectedNum2, resultList[1].Abbreviation.AnalysisDefaultWritingSystem.Text, WRONG_SEMDOM_NUMBER); Assert.AreEqual(expectedNum3, partialsList[0].Abbreviation.AnalysisDefaultWritingSystem.Text, WRONG_SEMDOM_NUMBER); }
public bool OnClearSelectedWordParserAnalyses(object dummyObj) { IWfiWordform wf = CurrentWordform; UndoableUnitOfWorkHelper.Do(ParserUIStrings.ksUndoClearParserAnalyses, ParserUIStrings.ksRedoClearParserAnalyses, m_cache.ActionHandlerAccessor, () => { foreach (IWfiAnalysis analysis in wf.AnalysesOC.ToArray()) { ICmAgentEvaluation[] parserEvals = analysis.EvaluationsRC.Where(evaluation => !evaluation.Human).ToArray(); foreach (ICmAgentEvaluation parserEval in parserEvals) { analysis.EvaluationsRC.Remove(parserEval); } if (analysis.EvaluationsRC.Count == 0) { wf.AnalysesOC.Remove(analysis); } wf.Checksum = 0; } }); return(true); //we handled this. }
/// <summary> /// Have the utility do what it does. /// </summary> public void Process() { Debug.Assert(m_dlg != null); var cache = (FdoCache)m_dlg.Mediator.PropertyTable.GetValue("cache"); var homographWsId = cache.LanguageProject.HomographWs; var homographWs = cache.ServiceLocator.WritingSystems.AllWritingSystems.Where(ws => ws.Id == homographWsId); var homographWsLabel = homographWs.First().DisplayLabel; var defaultVernacularWs = cache.LanguageProject.DefaultVernacularWritingSystem; var defaultVernacularWsId = defaultVernacularWs.Id; var changeWs = false; if (homographWsId != defaultVernacularWsId) { var caution = string.Format(LexEdStrings.ksReassignHomographsCaution, homographWsLabel, defaultVernacularWs.DisplayLabel); if (MessageBox.Show(caution, LexEdStrings.ksReassignHomographs, MessageBoxButtons.YesNo) == DialogResult.Yes) { changeWs = true; } } if (changeWs) { UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW( LexEdStrings.ksUndoHomographWs, LexEdStrings.ksRedoHomographWs, cache.ActionHandlerAccessor, () => { cache.LanguageProject.HomographWs = defaultVernacularWsId; }); } cache.LanguageProject.LexDbOA.ResetHomographNumbers(new ProgressBarWrapper(m_dlg.ProgressBar)); }
private void m_tb_LostFocus(object sender, EventArgs e) { try { int i = Convert.ToInt32(m_tb.Text); if (i == m_previousValue) { return; } m_previousValue = i; UndoableUnitOfWorkHelper.Do( String.Format(DetailControlsStrings.ksUndoChangeTo, m_fieldName), String.Format(DetailControlsStrings.ksRedoChangeTo, m_fieldName), Cache.ActionHandlerAccessor, () => m_cache.DomainDataByFlid.SetInt(Object.Hvo, m_flid, i)); } catch (FormatException error) { error.ToString(); // JohnT added because compiler complains not used. MessageBox.Show(DetailControlsStrings.ksEnterNumber); } catch (Exception error) { error.ToString(); // JohnT added because compiler complains not used. MessageBox.Show(DetailControlsStrings.ksInvalidNumber); } // In case the update failed, make sure the box is consistent. m_tb.Text = m_cache.DomainDataByFlid.get_IntProp(Object.Hvo, m_flid).ToString(); }
public void ChangingLangProjDefaultAnalysisWs_ChangesCacheDefaultAnalWs() { using (var cache = LcmCache.CreateCacheWithNewBlankLangProj(new TestProjectId(BackendProviderType.kMemoryOnly, null), "en", "fr", "en", m_ui, m_lcmDirectories, new LcmSettings())) { var wsEn = cache.DefaultAnalWs; Assert.That(cache.LangProject.DefaultAnalysisWritingSystem.Handle, Is.EqualTo(wsEn)); CoreWritingSystemDefinition wsObjGerman = null; UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor, () => { WritingSystemServices.FindOrCreateWritingSystem(cache, TestDirectoryFinder.TemplateDirectory, "de", true, false, out wsObjGerman); Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn)); cache.LangProject.DefaultAnalysisWritingSystem = wsObjGerman; Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsObjGerman.Handle)); }); UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor, () => { cache.LangProject.CurAnalysisWss = "en"; Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn)); }); cache.ActionHandlerAccessor.Undo(); Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsObjGerman.Handle)); cache.ActionHandlerAccessor.Redo(); Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn)); } }