/// <summary> /// Make the necessary Free Translation annotation comments for the specified group /// of roughly matching segments. In general, we transfer corresponding material from /// the BT segment to the FT annotation of the main paragraph segment, with any left-over /// paragraph segments blank, and any left-over BT segments added to the end of the /// last FT segment. As a special case, if some FTs at the end of the list already have the /// exact text of corresponding BT ones (counting from the end of the lists), we assume that /// those pairs correspond, even if not in corresponding positions counting from the start, /// and don't change them. This helps preserve alignment when something may merge or split /// a segment in the base text after much of it is annotated. /// </summary> /// <param name="igroup"></param> private void MakeSegmentBtsForGroup(int igroup) { SegGroup group = m_segGroups[igroup]; // Discard any items at the end of both lists which already match exactly. Leave at least one in each group. DiscardMatchingSegsAtEnd(group); // The remaining (often all) segments are transferred one-for-one. (We don't need to check for // exactly matching ones at the start, because in that case, copying will be a no-op.) for (int iParaSeg = 0; iParaSeg < group.ParaSegs.Count; iParaSeg++) { int hvoFt = m_cache.GetObjProperty(group.ParaSegs[iParaSeg], kflidFT); // We may assume hvoFt is non-zero, because LoadSegmentFreeTranslations ensures every segment has one. CmIndirectAnnotation ft = CmObject.CreateFromDBObject(m_cache, hvoFt) as CmIndirectAnnotation; if (iParaSeg >= group.BtSegs.Count) { // no more Bt segments, make the annotation FT empty (in case set previously). // But don't overwrite if unchanged, since PropChanged can do a good deal of work // and sometimes destroy selections we want to preserve. if (ft.Comment.GetAlternative(m_wsBt).Length != 0) { ft.Comment.SetAlternative("", m_wsBt); } continue; } ITsString tssFt = group.BtSegs[iParaSeg].Text; tssFt = InsertOrphanBtFromPreviousGroup(igroup, iParaSeg, tssFt); tssFt = AppendLeftoverBtToLastSeg(group, iParaSeg, tssFt); // But don't overwrite if unchanged, since PropChanged can do a good deal of work // and sometimes destroy selections we want to preserve. if (!ft.Comment.GetAlternativeTss(m_wsBt).Equals(tssFt)) { ft.Comment.SetAlternative(tssFt, m_wsBt); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Finds or creates an annotation. /// </summary> /// <param name="info">The information about a annotation being imported.</param> /// <param name="annotatedObjGuid">The annotated obj GUID.</param> /// <returns> /// The annotation (whether created or found) /// </returns> /// ------------------------------------------------------------------------------------ public static ScrScriptureNote FindOrCreateAnnotation(ScrAnnotationInfo info, Guid annotatedObjGuid) { ScrScriptureNote ann; // If an identical note is not found... if (!s_existingAnnotations.TryGetValue(info.Key, out ann)) { using (new SuppressSubTasks(s_scr.Cache)) { int hvo = s_scr.Cache.GetIdFromGuid(annotatedObjGuid); ICmObject annotatedObj = hvo <= 0 ? null : CmObject.CreateFromDBObject(s_scr.Cache, hvo); ann = (ScrScriptureNote)s_annotationList.InsertImportedNote( info.startReference, info.endReference, annotatedObj, annotatedObj, info.guidAnnotationType, null); } if (s_scr.Cache.ActionHandlerAccessor != null) { s_scr.Cache.ActionHandlerAccessor.AddAction(new UndoImportObjectAction(ann)); } ann.BeginOffset = ann.EndOffset = info.ichOffset; if (ann.CitedText != null) { ann.EndOffset += ann.CitedText.Length; } } return(ann); }
public void SetRoot(int hvo) { CheckDisposed(); if (hvo != 0) { ICmObject co = CmObject.CreateFromDBObject(Cache, hvo); if (Scripture.IsResponsibleFor(co as StText)) { m_hvoRoot = hvo; // StText (i.e. Scripture) } else { m_hvoRoot = co.OwnerHVO; // Text (i.e. non-scripture). Editable. } SetupVc(); } else { m_hvoRoot = 0; ReadOnlyView = true; if (m_vc != null) { m_vc.IsScripture = false; m_vc.Editable = false; } } ChangeOrMakeRoot(m_hvoRoot, m_vc, TitleContentsVc.kfragRoot, m_styleSheet); }
/// <summary> /// extracts the variant and component from the dialog, depending upon whether we're /// called from an "Insert Variant" or "Variant Of..." context. /// </summary> /// <param name="variant"></param> /// <param name="componentLexeme"></param> private void GetVariantAndComponentAndSelectedEntryType(out ILexEntry variant, out IVariantComponentLexeme componentLexeme, out ILexEntryType selectedEntryType) { variant = null; componentLexeme = null; if (m_fBackRefToVariant) { // in "Insert Variant" contexts, // we're calling the dialog from the component lexeme, so consider SelectedID as the variant. componentLexeme = m_startingEntry; variant = LexEntry.CreateFromDBObject(m_cache, SelectedID); } else { // in "Variant of..." contexts, // we're calling the dialog from the variant, so consider SelectedID the componentLexeme. variant = m_startingEntry; componentLexeme = CmObject.CreateFromDBObject(m_cache, SelectedID) as IVariantComponentLexeme; } if (m_fGetVariantEntryTypeFromTreeCombo) { selectedEntryType = LexEntryType.CreateFromDBObject(m_cache, SelectedVariantEntryTypeHvo); } else { selectedEntryType = null; } }
/// <summary> /// Check for and deal with moves that should not be allowed. /// Previously the only disallowed move was one that reorganized a chart template that is in use. /// This is not the optimum place to 'know' about this, but I (JohnT) am not sure where is. /// Now we are disallowing certain moves within the TextMarkup Tags list too, so I (GordonM) have /// refactored a bit. /// Review: Should these be pulled out to the PossibilityTreeBarHandler subclass? /// </summary> /// <param name="hvoMove"></param> /// <param name="hvoDest"></param> /// <returns>true if a problem was reported and the move should be cancelled.</returns> private bool CheckAndReportForbiddenMove(int hvoMove, int hvoDest) { FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache"); CmPossibility movingPossItem = CmObject.CreateFromDBObject(cache, hvoMove) as CmPossibility; if (movingPossItem != null) { ICmPossibility rootPoss = movingPossItem.MainPossibility; int hvoRootItem = rootPoss.Hvo; int hvoPossList = rootPoss.OwningList.Hvo; // If we get here hvoPossList is a possibility list and hvoRootItem is a top level item in that list // and movingPossItem is, or is a subpossibility of, that top level item. // 1. Check to see if hvoRootItem is a chart template containing our target. // If so, hvoPossList is owned in the chart templates property. if (cache.GetOwningFlidOfObject(hvoPossList) == (int)DsDiscourseData.DsDiscourseDataTags.kflidConstChartTempl) { return(CheckAndReportBadDiscourseTemplateMove(cache, movingPossItem, hvoRootItem, hvoPossList, hvoDest)); } // 2. Check to see if hvoRootItem is a TextMarkup TagList containing our target (i.e. a Tag type). // If so, hvoPossList is owned in the text markup tags property. if (cache.GetOwningFlidOfObject(hvoPossList) == (int)LangProject.LangProjectTags.kflidTextMarkupTags) { return(CheckAndReportBadTagListMove(cache, movingPossItem, hvoRootItem, hvoPossList, hvoDest)); } } return(false); // not detecting problems with moving other kinds of things. }
protected override void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { m_cache.BeginUndoTask(LexTextControls.ksUndoInsertInflectionFeature, LexTextControls.ksRedoInsertInflectionFeature); int clsid; if (m_sClassName == "FsComplexFeature") { // NO: Since this fires a PropChanged, and we do it ourselves later on. // m_selFeatDefn = (FsComplexFeature)m_featureList.Add(new FsComplexFeature()); clsid = FsComplexFeature.kClassId; } else { // NO: Since this fires a PropChanged, and we do it ourselves later on. // m_selFeatDefn = (FsClosedFeature)m_featureList.Add(new FsClosedFeature()); clsid = FsClosedFeature.kClassId; } // CreateObject creates the entry without a PropChanged. int fsysHvo = m_cache.LangProject.MsFeatureSystemOAHvo; int flid = (int)FsFeatureSystem.FsFeatureSystemTags.kflidFeatures; int featureHvo = m_cache.CreateObject(clsid, fsysHvo, flid, 0); // 0 is fine, since the owning prop is not a sequence. m_selFeatDefn = (FsFeatDefn)CmObject.CreateFromDBObject(m_cache, featureHvo, true); m_cache.EndUndoTask(); ForceRecordClerkToReload(fsysHvo, flid, featureHvo); DialogResult = DialogResult.Yes; Close(); }
/// <summary> /// Here we have a reference to IText, which can reference ScrFdo, so unlike the base class /// we can give a meaningful definition to label segment. /// </summary> /// <param name="hvo"></param> /// <returns></returns> protected override bool IsLabelSegment(int hvo) { CmBaseAnnotation seg = (CmBaseAnnotation)CmObject.CreateFromDBObject(Cache, hvo); StTxtPara para = seg.BeginObjectRA as StTxtPara; return(SegmentBreaker.HasLabelText(para.Contents.UnderlyingTsString, seg.BeginOffset, seg.EndOffset)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Checks if the current selection contains only a footnote reference, or is an IP /// associated with only a footnote reference. /// </summary> /// <param name="vwsel">selection to get info from</param> /// <returns>the footnote object, if current selection is on a footnote; /// otherwise null</returns> /// ------------------------------------------------------------------------------------ public IStFootnote GetFootnoteFromMarkerSelection(IVwSelection vwsel) { CheckDisposed(); IStFootnote footnote = null; // if we find a single run with the correct props, we are on an ORC hot link string sGuid = GetOrcHotLinkStrProp(vwsel); if (sGuid == null) { return(null); // not a footnote } // Get the underlying object for the guid. Guid guid = MiscUtils.GetGuidFromObjData(sGuid.Substring(1)); int hvoObj = Cache.GetIdFromGuid(guid); if (hvoObj != 0) { try { ICmObject obj = CmObject.CreateFromDBObject(Cache, hvoObj); footnote = obj as IStFootnote; } catch (NullReferenceException) { return(null); } } return(footnote); }
/// <summary> /// Initialize the combo contents. /// </summary> public void SetupCombo() { CheckDisposed(); ITsStrBldr builder = TsStrBldrClass.Create(); m_fInitializing = true; int wordformHvo = m_owner.GetWordformHvoOfAnalysis(); // Add the analyses, and recursively the other items. foreach (int hvoAnalysis in m_cache.GetVectorProperty(wordformHvo, (int)WfiWordform.WfiWordformTags.kflidAnalyses, false)) { IWfiAnalysis wa = (IWfiAnalysis)CmObject.CreateFromDBObject(m_cache, hvoAnalysis, CmObject.GetTypeFromFullClassName(m_cache, "SIL.FieldWorks.FDO.Ling.WfiAnalysis"), false, false); Opinions o = wa.GetAgentOpinion( m_cache.LangProject.DefaultUserAgent); // skip any analysis the user has disapproved. if (o != Opinions.disapproves) { AddAnalysisItems(hvoAnalysis); AddSeparatorLine(); } } // Add option to clear the analysis altogeter. AddItem(wordformHvo, MakeSimpleString(ITextStrings.ksNewAnalysis), false, WfiWordform.kclsidWfiWordform); // Add option to reset to the default AddItem(0, MakeSimpleString(ITextStrings.ksUseDefaultAnalysis), false); m_fInitializing = false; }
/// <summary> /// Get an array of hvos of a given class out of a vector /// </summary> /// <param name="hvos">The integer array holding a heterogeneous collection of object Hvos</param> /// <param name="classId">the class of objects you want</param> /// <param name="howMany">how many you want</param> /// <returns></returns> /// <example>Get the first LexEntry in the lexicon /// <code> /// GetHvosForFirstNObjectsOfClass(m_fdoCache.LangProject.LexDbOA.EntriesOC, /// LexEntry.kclsidLexEntry, 1)[0]; /// </code></example> protected int[] GetHvosForFirstNObjectsOfClass(int[] hvos, int classId, int howMany) { Assert.IsTrue(howMany > 0); Assert.IsTrue(hvos.Length >= howMany, "Caller asked for " + howMany.ToString() + " objects, but only " + hvos.Length.ToString() + " were available."); List <int> result = new List <int>(howMany); foreach (int hvo in hvos) { ICmObject o = CmObject.CreateFromDBObject(m_fdoCache, hvo); if (o.ClassID == classId) { result.Add(hvo); } if (result.Count == howMany) { break; } } return(result.ToArray()); }
public void DBObjectInstantiation() { CheckDisposed(); // Putting persons in the UsageTypes doesn't really make sense, but for testing purposes // it doesn't matter what we store there as long as it is derived from CmPossibility CmPerson person = new CmPerson(); CmPossibility pos = new CmPossibility(); Cache.LangProject.LexDbOA.UsageTypesOA.PossibilitiesOS.Append(person); Cache.LangProject.LexDbOA.UsageTypesOA.PossibilitiesOS.Append(pos); int khvoAPossibiltyObject = pos.Hvo; int khvoAPersonObject = person.Hvo; Assert.AreEqual("CmPerson", CmPossibility.CreateFromDBObject(Cache, khvoAPersonObject).GetType().Name); Assert.AreEqual("CmPossibility", CmPossibility.CreateFromDBObject(Cache, khvoAPossibiltyObject).GetType().Name); // Now try it not assuming anything about the class type (use the method on CmObject) // CmObject uses a different, less efficient method. Assert.AreEqual("CmPerson", CmObject.CreateFromDBObject(Cache, khvoAPersonObject).GetType().Name); // trying to turn a possibility into a person should throw an exception CmPerson.CreateFromDBObject(Cache, khvoAPossibiltyObject); }
/// <summary> /// Set the item from the chooser. /// </summary> /// <param name="realHvo">ID of the object from the chooser.</param> public void SetObject(int realHvo) { CheckDisposed(); if (realHvo != 0) { m_rootObj = CmObject.CreateFromDBObject(m_fdoCache, realHvo); } else { m_rootObj = null; } if (m_rootb != null) { SetRootBoxObj(); int h2 = m_rootb.Height; if (m_hOld != h2) { m_hOld = h2; if (ViewSizeChanged != null) { ViewSizeChanged(this, new FwViewSizeEventArgs(h2, m_rootb.Width)); } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create and Check an Annotation /// </summary> /// <param name="hvoParaStart">The hvo para start.</param> /// <param name="hvoParaEnd">The hvo para end.</param> /// <param name="startRef">The start ref.</param> /// <param name="endRef">The end ref.</param> /// <param name="startOffset">The start offset.</param> /// <param name="endOffset">The end offset.</param> /// <param name="tssQuote">The text in the quote.</param> /// <param name="sel">selection in main window</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private IScrScriptureNote CreateAndCheckAnnotation(int hvoObjStart, int hvoObjEnd, int startRef, int endRef, int startOffset, int endOffset, string strQuote) { ILangProject lp = Cache.LangProject; CmAnnotationDefn transNoteAnnDefn = new CmAnnotationDefn(Cache, LangProject.kguidAnnTranslatorNote); // Get information from the selection about the location of the annotation. CmObject topObj = (CmObject)CmObject.CreateFromDBObject(m_inMemoryCache.Cache, hvoObjStart); CmObject bottomObj = (CmObject)CmObject.CreateFromDBObject(m_inMemoryCache.Cache, hvoObjEnd); int wsSelector = -1; ITsStrBldr tssBldrQuote = TsStrBldrClass.Create(); tssBldrQuote.Replace(0, 0, strQuote, StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark)); IScrScriptureNote ann = m_notesEditingHelper.InsertNote(transNoteAnnDefn, startRef, endRef, topObj, bottomObj, wsSelector, startOffset, endOffset, tssBldrQuote.GetString()); Assert.IsNotNull(ann); Assert.AreEqual(transNoteAnnDefn.Hvo, ann.AnnotationTypeRAHvo, "Wrong type of note created"); Assert.AreEqual(hvoObjStart, ann.BeginObjectRAHvo, "Wrong paragraph annotated"); Assert.AreEqual(hvoObjEnd, ann.EndObjectRAHvo, "Wrong paragraph annotated"); Assert.AreEqual(startRef, ann.BeginRef, "Should have the correct start para reference"); Assert.AreEqual(endRef, ann.EndRef, "Should have the correct end para reference"); Assert.AreEqual(startOffset, ann.BeginOffset, "Should have the correct starting char offset"); Assert.AreEqual(endOffset, ann.EndOffset, "Should have the correct ending char offset"); Assert.AreEqual(lp.DefaultUserAgent.Hvo, ann.SourceRAHvo, "Wrong agent"); VerifyInitializedText(ann.DiscussionOA, "Discussion"); Assert.AreEqual(tssBldrQuote.Text, ((StTxtPara)ann.QuoteOA.ParagraphsOS[0]).Contents.Text); VerifyInitializedText(ann.RecommendationOA, "Recommendation"); VerifyInitializedText(ann.ResolutionOA, "Resolution"); return(ann); }
void VerifyLabel(int iseg, string label) { int hvoSeg = Cache.GetVectorItem(m_para.Hvo, kflidSegments, iseg); CmBaseAnnotation seg = CmObject.CreateFromDBObject(Cache, hvoSeg, false) as CmBaseAnnotation; Assert.IsTrue(SegmentBreaker.HasLabelText(m_para.Contents.UnderlyingTsString, seg.BeginOffset, seg.EndOffset), label); }
/// <summary> /// Have the main FLEx window jump to the appropriate item /// </summary> /// <param name="hvo">item whose parent will indcate where to jump to</param> public void JumpToToolBasedOnHvo(int hvo) { if (hvo == 0) { return; } string sTool = null; int parentClassId = 0; ICmObject obj = CmObject.CreateFromDBObject(m_cache, hvo); switch (obj.ClassID) { case MoForm.kclsidMoForm: // fall through case MoAffixAllomorph.kclsidMoAffixAllomorph: // fall through case MoStemAllomorph.kclsidMoStemAllomorph: // fall through case MoInflAffMsa.kclsidMoInflAffMsa: // fall through case MoDerivAffMsa.kclsidMoDerivAffMsa: // fall through case MoUnclassifiedAffixMsa.kclsidMoUnclassifiedAffixMsa: // fall through case MoStemMsa.kclsidMoStemMsa: // fall through case MoMorphSynAnalysis.kclsidMoMorphSynAnalysis: case MoAffixProcess.kclsidMoAffixProcess: sTool = "lexiconEdit"; parentClassId = LexEntry.kclsidLexEntry; break; case MoInflAffixSlot.kclsidMoInflAffixSlot: // fall through case MoInflAffixTemplate.kclsidMoInflAffixTemplate: // fall through case PartOfSpeech.kclsidPartOfSpeech: sTool = "posEdit"; parentClassId = PartOfSpeech.kclsidPartOfSpeech; break; // still need to test compound rule ones case MoCoordinateCompound.kclsidMoCoordinateCompound: case MoEndoCompound.kclsidMoEndoCompound: case MoExoCompound.kclsidMoExoCompound: sTool = "compoundRuleAdvancedEdit"; parentClassId = obj.ClassID; break; case PhRegularRule.kclsidPhRegularRule: // fall through case PhMetathesisRule.kclsidPhMetathesisRule: sTool = "PhonologicalRuleEdit"; parentClassId = obj.ClassID; break; } if (parentClassId <= 0) { return; // do nothing } int parentHvo = CmObjectUi.GetParentOfClass(m_cache, hvo, parentClassId); if (parentHvo <= 0) { return; // do nothing } m_mediator.PostMessage("FollowLink", SIL.FieldWorks.FdoUi.FwLink.Create(sTool, m_cache.GetGuidFromId(parentHvo), m_cache.ServerName, m_cache.DatabaseName)); }
/// <summary> /// are there any sub items for this item? /// </summary> /// <returns></returns> public override bool GetHaveSubItems() { // enhance: this is *extremely* inefficient. should store this possibility as a // member variable. ICmPossibility possibility = (ICmPossibility)CmObject.CreateFromDBObject(m_cache, m_hvo); return(possibility.SubPossibilitiesOS.Count > 0); }
protected override void UpdateTimeStampsIfNeeded(int[] hvos) { for (int i = 0; i < hvos.Length; ++i) { ICmObject cmo = CmObject.CreateFromDBObject(m_fdoCache, hvos[i]); (cmo as CmObject).UpdateTimestampForVirtualChange(); } }
private ICmIndirectAnnotation AssertTagExists(int hvoTag, string msgFailure) { if (!Cache.IsValidObject(hvoTag)) { Assert.Fail(msgFailure); } return(CmObject.CreateFromDBObject(Cache, hvoTag) as ICmIndirectAnnotation); }
/// <summary> /// Make one. Everything interesting happens when it is given a root object, however. /// </summary> /// <param name="cache"></param> /// <param name="hvoAnalysis"></param> /// <param name="configurationNode"></param> /// <param name="stringTable"></param> public AnalysisInterlinearRS(FdoCache cache, int hvoAnalysis, XmlNode configurationNode, StringTable stringTable) : base(cache) { m_configurationNode = configurationNode; m_hvoWfiAnalysis = hvoAnalysis; m_wordform = (WfiWordform)CmObject.CreateFromDBObject(m_fdoCache, m_fdoCache.GetOwnerOfObject(m_hvoWfiAnalysis), false); // RightMouseClickedEvent += new FwRightMouseClickEventHandler(InterlinDocChild_RightMouseClickedEvent); }
/// <summary> /// Obain an initial default value from the object's shortname (and convert to appropriate writing /// system). /// </summary> /// <param name="hvo"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="_cda"></param> public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { ICmObject obj = CmObject.CreateFromDBObject(m_cache, hvo); //Enhance JohnT: don't preload everything. string name = obj.ShortName; ITsStrFactory tsf = TsStrFactoryClass.Create(); cda.CacheStringProp(hvo, tag, tsf.MakeString(name, m_ws)); }
/// <summary> /// are there any sub items for this item? /// </summary> /// <returns></returns> public override bool GetHaveSubItems() { m_ic = (IMoInflClass)CmObject.CreateFromDBObject(m_cache, m_hvo); if (m_ic == null) { return(false); } return(m_ic.SubclassesOC.Count > 0); }
private int CreatePhonologicalfeature(out int flid, out int featureHvo) { int fsysHvo = m_cache.LangProject.PhFeatureSystemOAHvo; flid = (int)FsFeatureSystem.FsFeatureSystemTags.kflidFeatures; featureHvo = m_cache.CreateObject(FsClosedFeature.kClassId, fsysHvo, flid, 0); m_selFeatDefn = (FsFeatDefn)CmObject.CreateFromDBObject(m_cache, featureHvo, true); return(fsysHvo); }
/// <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> /// Keys the cm object using. /// </summary> /// <param name="cache">The cache.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public ICmObject KeyCmObjectUsing(FdoCache cache) { // In the common case that there is no path, we can just return our root item, // if we have one. if (PathLength == 0 && m_rootObject != null) { return(m_rootObject); } return(CmObject.CreateFromDBObject(cache, m_hvoItem, false)); }
private void CreateFeatureStructureFromHvoString(XmlDocument doc, string sFSHvo, XmlNode parentNode) { int fsHvo = Convert.ToInt32(sFSHvo); IFsFeatStruc fsFeatStruc = (IFsFeatStruc)CmObject.CreateFromDBObject(m_cache, fsHvo); if (fsFeatStruc != null) { CreateFeatureStructureNodes(doc, parentNode, fsFeatStruc, fsHvo); } }
/// <summary> /// If OK, then make FS have the selected feature value(s). /// JohnT: This is a really ugly kludge, which I have only partly repaired. /// We need the dialog to return with m_fs set to an FsFeatStruc (if OK was clicked), /// since that is what the bulk edit bar wants to copy to MoStemMsas for any items /// it is asked to modify. Also, the new FsFeatStruc needs to be in the ReferenceForms /// (which is what m_owningFlid apparently always is, currently) so that it will become /// one of the items in the combo list and can be selected. However, Andy says this is /// not the intended use of ReferenceForms at all. /// A further ugliness is that we always make a new FsFeatStruc (unless one was passed /// in to one of the SegDlgInfo methods, but AFAIK that override is never used), but /// we then delete it if it turns out to be a duplicate. There is no other straightforward /// way to detect that the current choices in the dialog correspond to an existing item. /// This may cause problems in the new world, where we can't do this "suppress sub tasks" /// trick without losing our Undo stack. /// It may be possible in the new world to create an object without initially giving it an /// owner, and only persist it if it is NOT a duplicate. But even that we don't really want /// to be undoable, nor should it clear the undo stack. Really the list of possible choices /// for the combo should not be separately persisted as model data, but it should be persisted /// somehow... /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MsaInflectionFeatureListDlg_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (DialogResult == DialogResult.OK) { using (new SuppressSubTasks(m_cache)) // making and maybe then deleting the new item for the combo is not undoable { if (m_fs == null) { // Didn't have one to begin with. See whether we want to create one. if (CheckFeatureStructure(m_tvMsaFeatureList.Nodes)) { // The last argument is meaningless since we expect this property to be owning // or collection. int hvoFs = m_cache.CreateObject(FsFeatStruc.kClassId, m_hvoOwner, m_owningFlid, 0); m_fs = (IFsFeatStruc)FsFeatStruc.CreateFromDBObject(m_cache, hvoFs, false); } else { return; // leave it null. } } // clean out any extant features in the feature structure foreach (IFsFeatureSpecification spec in m_fs.FeatureSpecsOC) { m_fs.FeatureSpecsOC.Remove(spec); } UpdateFeatureStructure(m_tvMsaFeatureList.Nodes); // The (usually) newly created one may be a duplicate. If we find a duplicate // delete the one we just made (or were passed) and return the duplicate. int chvo = m_cache.GetVectorSize(m_hvoOwner, m_owningFlid); for (int ihvo = 0; ihvo < chvo; ihvo++) { int hvo = m_cache.GetVectorItem(m_hvoOwner, m_owningFlid, ihvo); if (hvo == m_fs.Hvo) { continue; } IFsFeatStruc fs = CmObject.CreateFromDBObject(m_cache, hvo) as IFsFeatStruc; if (FsFeatStruc.AreEquivalent(fs, m_fs)) { m_fs.DeleteUnderlyingObject(); m_fs = fs; break; } } } } if (m_mediator != null) { m_mediator.PropertyTable.SetProperty("msaInflFeatListDlgLocation", Location); m_mediator.PropertyTable.SetProperty("msaInflFeatListDlgSize", Size); } }
protected void ValidateCmObjectGuidForNode(int hvoExpected, XmlNode nodeExported, string context, out string guidActual) { string msg = "Mismatched {0} in {1}."; ICmObject objExpected = CmObject.CreateFromDBObject(m_cache, hvoExpected); guidActual = XmlUtils.GetOptionalAttributeValue(nodeExported, "guid"); Assert.IsNotNull(guidActual, "Missing guid in " + context); guidActual = guidActual.ToLowerInvariant(); string guidExpected = objExpected.Guid.ToString().ToLowerInvariant(); Assert.AreEqual(guidExpected, guidActual, String.Format(msg, "guid", context)); }
/// <summary> /// Get the name that should be shown for the target object. Eventually this may be overridden by subclasses, /// or we may use reflection to make it configurable. /// This method is not yet used. /// </summary> /// <param name="hvoTarget"></param> /// <returns></returns> private string GetNameOfRefTarget(int hvoTarget) { switch (m_tag) { // case (int)BaseLexSense.LexSenseTags.kflidMorphoSyntaxAnalysis: // // If the object is an MSA, do something special // Debug.Assert(false); // break; default: ICmObject obj = CmObject.CreateFromDBObject(m_cache, hvoTarget); return(obj.ShortName); } }
private string GetChildObjKey(XmlNode layout, int hvo, ManyOnePathSortItem item, int pathIndex, bool sortedFromEnd) { ICmObject childObj = CmObject.CreateFromDBObject(m_cache, hvo); string layoutName = XmlUtils.GetManditoryAttributeValue(layout, "layout"); XmlNode part = XmlVc.GetNodeForPart(hvo, layoutName, true, m_sda, m_layouts); string key = GetKey(part, childObj, item, pathIndex, sortedFromEnd); if (key != null) { return(key); } return(CallSortMethod(childObj, sortedFromEnd)); }
/// <summary> /// Given the string the user typed, generate the best available guess as to which of the options /// he intended. Set hvoNew to 0 (and return tssTyped) if it doesn't match any option. /// It is assumed that he is setting an object in property m_tag of object m_hvoParent. /// </summary> /// <param name="tssTyped"></param> /// <returns></returns> protected virtual ITsString Lookup(ITsString tssTyped, out int hvoNew) { ICmObject obj = CmObject.CreateFromDBObject(m_cache, m_hvoParent); string sTyped = tssTyped == null ? "" : tssTyped.Text; if (sTyped == null) { sTyped = ""; } int cchTyped = sTyped.Length; if (cchTyped == 0) { // Otherwise we'd match the first item and arbitrarily insert it when the user backspaces to // nothing. Seems better to wait till at least one letter is typed to try to match. hvoNew = 0; return(tssTyped); } int ipossibility = -1; foreach (int hvo in obj.ReferenceTargetCandidates(m_tag)) { ipossibility++; string key = null; if (ipossibility < m_shortnames.Count) { key = m_shortnames[ipossibility]; // Use the cache as far as it goes } else { ICmObject item = CmObject.CreateFromDBObject(m_cache, hvo); key = item.ShortName; m_shortnames.Add(key); // extend the cache for next time. } if (sTyped.Length < key.Length && key.Substring(0, cchTyped) == sTyped) { hvoNew = hvo; ITsStrBldr bldr = tssTyped.GetBldr(); bldr.Replace(0, bldr.Length, key, null); // Clear any underlining left over from previous bad value. bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptUnderline, -1, -1); bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptUnderColor, -1, -1); return(bldr.GetString()); // Same ws as input, contents replaced. } } hvoNew = 0; return(tssTyped); }