private void CheckDeletedEntries() { int hvo = m_cache.GetIdFromGuid(TestFlexChorus.ksguidDelete1); Assert.AreEqual(hvo, 0); hvo = m_cache.GetIdFromGuid(TestFlexChorus.ksguidDelete2); Assert.AreEqual(hvo, 0); }
public BaseFreeformAdder(FdoCache cache) { m_fdoCache = cache; ktagSegFF = StTxtPara.SegmentFreeformAnnotationsFlid(cache); ktagSegFF_literalTranslation = cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation); ktagSegFF_freeTranslation = cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation); ktagSegFF_note = cache.GetIdFromGuid(LangProject.kguidAnnNote); }
private ILexEntry TryToFindMatchingEntry(Guid guid, IdentifyingInfo idInfo, out bool canPrune) { ILexEntry entry = null; if (guid != Guid.Empty) { int hvo = _cache.GetIdFromGuid(guid); if (hvo > 0) { entry = LexEntry.CreateFromDBObject(_cache, hvo); } canPrune = CanSafelyPruneMerge(idInfo, entry); return(entry); } canPrune = false; return(null); }
private bool FollowActiveLink() { try { if (m_lnkActive.TargetGuid != Guid.Empty) { // allow tools to skip loading a record if we're planning to jump to one. // interested tools will need to reset this "JumpToRecord" property after handling OnJumpToRecord. m_mediator.PropertyTable.SetProperty("SuspendLoadingRecordUntilOnJumpToRecord", m_lnkActive.ToolName + "," + m_lnkActive.TargetGuid.ToString(), PropertyTable.SettingsGroup.LocalSettings); } m_mediator.SendMessage("SetToolFromName", m_lnkActive.ToolName); // Note: It can be Guid.Empty in cases where it was never set, // or more likely, when the HVO was set to -1. if (m_lnkActive.TargetGuid != Guid.Empty) { FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache"); // Allow this to happen after the processing of the tool change above by using the Broadcast // method on the mediator, the SendMessage would process it before the above msg and it would // use the wrong RecordList. (LT-3260) m_mediator.BroadcastMessageUntilHandled("JumpToRecord", cache.GetIdFromGuid(m_lnkActive.TargetGuid)); } foreach (Property property in m_lnkActive.PropertyTableEntries) { m_mediator.PropertyTable.SetProperty(property.name, property.value); //TODO: I can't think at the moment of what to do about setting //the persistence or ownership of the property...at the moment the only values we're putting //in there are strings or bools } m_mediator.BroadcastMessageUntilHandled("LinkFollowed", m_lnkActive); } catch (Exception err) { string s; if (err.InnerException != null && err.InnerException.Message != null && err.InnerException.Message.Length > 0) { s = String.Format(xWorksStrings.UnableToFollowLink0, err.InnerException.Message); } else { s = xWorksStrings.UnableToFollowLink; } MessageBox.Show(s, xWorksStrings.FailedJump, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); return(false); } return(true); //we handled this. }
/* * /// <summary> * /// Import a single entry selected out of a Lift file. For test use. * /// </summary> * /// <param name="path"></param> * /// <param name="xpath"></param> * /// <returns>either the entry which was created were merged into</returns> * public LexEntry ImportOneWeSayEntry(string path, string xpath) * { * XmlDocument doc = new XmlDocument(); * doc.Load(path); * return ImportOneEntry(doc.SelectSingleNode(xpath)); * } */ internal ILexEntry MergeInOneEntry(LexEntry wsEntry) { ILexEntry flexEntry = null; Guid guid = wsEntry.Guid; int hvo = _cache.GetIdFromGuid(guid); if (hvo > 0) { flexEntry = FlexEntry.CreateFromDBObject(_cache, hvo); // if (((LexSense)flexEntry.SensesOS[0]).Gloss.AnalysisDefaultWritingSystem != weSayEntry.Gloss) // MergeAnalysisString((flexEntry.SensesOS[0]).Gloss,weSayEntry.Gloss); // MergeVernacularString(flexEntry.LexemeFormOA.Form,weSayEntry.LexicalForm); // MergeVernacularString(((ILexExampleSentence)((LexSense)flexEntry.SensesOS[0]).ExamplesOS[0]).Example,weSayEntry.Example); } else { flexEntry = MakeFwEntryFromWeSayEntry(wsEntry); } return(flexEntry); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes the list of categories based on categories in the specified filter. /// </summary> /// ------------------------------------------------------------------------------------ private bool InitializeFromFilter(FdoCache cache, ICmFilter filter, out List <int> initiallySelectedList) { initiallySelectedList = new List <int>(); if (filter == null || filter.RowsOS.Count == 0 || filter.RowsOS[0].CellsOS.Count == 0) { return(false); } bool fFilterContainsCategories = false; // Get the pairs of class ids and flids. string[] pairs = filter.ColumnInfo.Split('|'); Debug.Assert(filter.RowsOS[0].CellsOS.Count == pairs.Length); for (int i = 0; i < pairs.Length; i++) { ICmCell cell = filter.RowsOS[0].CellsOS[i]; Guid guid; // Get the flid for this cell. string[] pair = pairs[i].Split(','); int flid = 0; int.TryParse(pair[1], out flid); if (flid == (int)ScrScriptureNote.ScrScriptureNoteTags.kflidCategories) { fFilterContainsCategories = true; cell.ParseObjectMatchCriteria(); if (cell.Contents.UnderlyingTsString.RunCount > 1) { guid = StringUtils.GetGuidFromRun(cell.Contents.UnderlyingTsString, 1); initiallySelectedList.Add(cache.GetIdFromGuid(guid)); } } } return(fFilterContainsCategories); }
/// <summary> /// Write the ITsString out. /// </summary> /// <param name="tssPara"></param> /// <param name="cchIndent"></param> /// <remarks>TODO: this maybe should go into a generic method somewhere? /// Except that part of it is specific to XHTML output...</remarks> private void WriteTsStringAsXml(ITsString tssPara, int cchIndent) { // First, build the indentation. StringBuilder bldr = new StringBuilder(); while (cchIndent > 0) { bldr.Append(" "); --cchIndent; } string sIndent = bldr.ToString(); bldr.Append(" "); string sIndent2 = bldr.ToString(); m_writer.WriteLine("{0}<Str>", sIndent); int crun = tssPara.RunCount; string sField = null; for (int irun = 0; irun < crun; ++irun) { TsRunInfo tri; ITsTextProps ttpRun = tssPara.FetchRunInfo(irun, out tri); int ctip = ttpRun.IntPropCount; int ctsp = ttpRun.StrPropCount; string sFieldRun = ttpRun.GetStrPropValue((int)FwTextPropType.ktptFieldName); if (sFieldRun != sField) { if (!String.IsNullOrEmpty(sField)) { m_writer.WriteLine("{0}</Field>", sIndent2); } if (!String.IsNullOrEmpty(sFieldRun)) { m_writer.WriteLine("{0}<Field name=\"{1}\">", sIndent2, sFieldRun); } sField = sFieldRun; sFieldRun = null; } bool fMarkItem; int tpt; string sVal; bool fSkipText = false; int nVar; int nVal = ttpRun.GetIntPropValues((int)FwTextPropType.ktptMarkItem, out nVar); if (nVal == (int)FwTextToggleVal.kttvForceOn && nVar == (int)FwTextPropVar.ktpvEnum) { m_writer.Write("{0}<Item><Run", sIndent2); fMarkItem = true; } else { m_writer.Write("{0}<Run", sIndent2); fMarkItem = false; } for (int itip = 0; itip < ctip; ++itip) { nVal = ttpRun.GetIntProp(itip, out tpt, out nVar); if (tpt == (int)FwTextPropType.ktptWs || tpt == (int)FwTextPropType.ktptBaseWs) { if (nVal != 0) { ILgWritingSystem lgws = LgWritingSystem.CreateFromDBObject(m_cache, nVal); m_writer.Write(" {0}=\"{1}\"", tpt == (int)FwTextPropType.ktptWs ? "ws" : "wsBase", lgws.RFC4646bis); } } else if (tpt != (int)FwTextPropType.ktptMarkItem) { WriteIntTextProp(m_writer, m_cache.LanguageWritingSystemFactoryAccessor, tpt, nVar, nVal); } } string sRun = tssPara.get_RunText(irun); Guid guidFootnote = Guid.Empty; for (int itsp = 0; itsp < ctsp; ++itsp) { sVal = ttpRun.GetStrProp(itsp, out tpt); Debug.Assert(tpt != (int)FwTextPropType.ktptBulNumFontInfo); Debug.Assert(tpt != (int)FwTextPropType.ktptWsStyle); WriteStrTextProp(m_writer, tpt, sVal); if (sRun != null && sRun.Length == 1 && sRun[0] == StringUtils.kchObject) { Debug.Assert(tpt == (int)FwTextPropType.ktptObjData); fSkipText = true; if ((int)sVal[0] == (int)FwObjDataTypes.kodtOwnNameGuidHot) { guidFootnote = MiscUtils.GetGuidFromObjData(sVal.Substring(1)); } } } m_writer.Write(">"); if (!fSkipText) { int cch = tri.ichLim - tri.ichMin; if (cch > 0) { sRun = sRun.Normalize(); m_writer.Write(XmlUtils.MakeSafeXml(sRun)); } } if (fMarkItem) { m_writer.WriteLine("</Run></Item>"); } else { m_writer.WriteLine("</Run>"); } if (guidFootnote != Guid.Empty) { int hvoFootnote = m_cache.GetIdFromGuid(guidFootnote); if (hvoFootnote != 0) { ExportFootnote(new ScrFootnote(m_cache, hvoFootnote)); } } } if (!String.IsNullOrEmpty(sField)) { m_writer.WriteLine("{0}</Field>", sIndent2); } m_writer.WriteLine("{0}</Str>", sIndent); }
private void btnAdd_Click(object sender, EventArgs e) { // Get the checked twfics; List <int> twfics = m_rbv.CheckedItems; if (twfics == null || twfics.Count == 0) { // do nothing. return; } List <int> twficSegments = StTxtPara.TwficSegments(m_cache, twfics); Set <int> uniqueSegments = new Set <int>(twficSegments); FdoObjectSet <CmBaseAnnotation> cbaSegments = new FdoObjectSet <CmBaseAnnotation>(m_cache, uniqueSegments.ToArray(), true); int insertIndex = m_owningSense.ExamplesOS.Count; // by default, insert at the end. int sourceIndex = -1; if (m_les != null) { // we were given a LexExampleSentence, so set our insertion index after the given one. List <int> examples = new List <int>(m_owningSense.ExamplesOS.HvoArray); sourceIndex = examples.IndexOf(m_les.Hvo); insertIndex = sourceIndex + 1; } // Load all the annotations for these twfics. int tagSegFF = StTxtPara.SegmentFreeformAnnotationsFlid(m_cache); Set <int> allAnalWsIds = new Set <int>(m_cache.LangProject.AnalysisWssRC.HvoArray); StTxtPara.LoadSegmentFreeformAnnotationData(m_cache, uniqueSegments, allAnalWsIds); bool fBoolModifiedExisting = false; List <ILexExampleSentence> newExamples = new List <ILexExampleSentence>(); // keep track of how many new objects we created. ILexExampleSentence newLexExample = null; // delay prop changes until all the new examples are added. using (new IgnorePropChanged(m_cache, PropChangedHandling.SuppressView)) { foreach (CmBaseAnnotation cbaSegment in cbaSegments) { if (newExamples.Count == 0 && m_les != null && m_les.Example.BestVernacularAlternative.Text == "***" && (m_les.TranslationsOC == null || m_les.TranslationsOC.Count == 0) && m_les.Reference.Length == 0) { // we were given an empty LexExampleSentence, so use this one for our first new Example. newLexExample = m_les; fBoolModifiedExisting = true; } else { // create a new example sentence. newLexExample = m_owningSense.ExamplesOS.InsertAt(new LexExampleSentence(), insertIndex + newExamples.Count); newExamples.Add(newLexExample); } // copy the segment string into the new LexExampleSentence // Enhance: bold the relevant twfic(s). newLexExample.Example.SetVernacularDefaultWritingSystem(StTxtPara.TssSubstring(cbaSegment).Text); int segDefn_literalTranslation = m_cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation); int segDefn_freeTranslation = m_cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation); int hvoTransType_literalTranslation = m_cache.GetIdFromGuid(LangProject.kguidTranLiteralTranslation); int hvoTransType_freeTranslation = m_cache.GetIdFromGuid(LangProject.kguidTranFreeTranslation); // copy the translation information List <ICmTranslation> newTranslations = new List <ICmTranslation>(); foreach (int freeFormAnnotationId in m_cache.GetVectorProperty(cbaSegment.Hvo, tagSegFF, true)) { int hvoAnnType = m_cache.MainCacheAccessor.get_ObjectProp(freeFormAnnotationId, (int)CmAnnotation.CmAnnotationTags.kflidAnnotationType); // map annotation type to translation type. int hvoTranslationType = 0; if (hvoAnnType == segDefn_literalTranslation) { hvoTranslationType = hvoTransType_literalTranslation; } else if (hvoAnnType == segDefn_freeTranslation) { hvoTranslationType = hvoTransType_freeTranslation; } else { continue; // skip unsupported translation type. } ICmTranslation newTranslation = newLexExample.TranslationsOC.Add(new CmTranslation()); newTranslations.Add(newTranslation); newTranslation.TypeRAHvo = hvoTranslationType; foreach (int analWs in allAnalWsIds) { ITsString tssComment = m_cache.GetMultiStringAlt(freeFormAnnotationId, (int)CmAnnotation.CmAnnotationTags.kflidComment, analWs); if (tssComment.Length > 0) { newTranslation.Translation.SetAlternative(tssComment, analWs); } } } // copy the reference. // Enhance: get the ws from the 'Reference' column spec? // Enhance: AnnotationRefHandler can also m_cache the reference directly to the segment. int iTwfic = twficSegments.IndexOf(cbaSegment.Hvo); newLexExample.Reference.UnderlyingTsString = m_cache.GetTsStringProperty(twfics[iTwfic], m_virtFlidReference); // Need to correctly add Translations (or ghost if none). } } if (fBoolModifiedExisting) { m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_les.Hvo, (int)LexExampleSentence.LexExampleSentenceTags.kflidExample, 0, 1, 1); m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_les.Hvo, (int)LexExampleSentence.LexExampleSentenceTags.kflidReference, 0, 1, 1); //m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_les.Hvo, // (int)LexExampleSentence.LexExampleSentenceTags.kflidTranslations, 0, 1, 1); //m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_owningSense.Hvo, // (int)LexSense.LexSenseTags.kflidExamples, sourceIndex, 1, 1); } m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, m_owningSense.Hvo, (int)LexSense.LexSenseTags.kflidExamples, insertIndex, newExamples.Count, 0); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Find the ID of the CmObject in the database that matches this guid. /// </summary> /// <param name="guid">A GUID that represents an object in the cache.</param> /// <returns>The ID corresponding to the GUID (the Id field), or zero if the /// GUID is invalid.</returns> /// ----------------------------------------------------------------------------------- public int GetIdFromGuid(Guid guid) { return(m_fdoCache.GetIdFromGuid(guid)); }
void link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { RuleInsertType type = (RuleInsertType)e.Link.LinkData; string optStr = GetOptionString(type); using (new UndoRedoTaskHelper(m_cache, string.Format(MEStrings.ksRuleUndoInsert, optStr), string.Format(MEStrings.ksRuleRedoInsert, optStr))) { int data = -1; switch (type) { case RuleInsertType.PHONEME: Set <int> phonemes = new Set <int>(m_cache.LangProject.PhonologicalDataOA.PhonemeSetsOS[0].PhonemesOC.HvoArray); int phonemeHvo = DisplayChooser(MEStrings.ksRulePhonemeOpt, MEStrings.ksRulePhonemeChooserLink, "phonemeEdit", "RulePhonemeFlatList", phonemes); if (phonemeHvo != 0) { data = phonemeHvo; } break; case RuleInsertType.NATURAL_CLASS: Set <int> natClasses = new Set <int>(m_cache.LangProject.PhonologicalDataOA.NaturalClassesOS.HvoArray); int ncHvo = DisplayChooser(MEStrings.ksRuleNCOpt, MEStrings.ksRuleNCChooserLink, "naturalClassedit", "RuleNaturalClassFlatList", natClasses); if (ncHvo != 0) { data = ncHvo; } break; case RuleInsertType.FEATURES: using (PhonologicalFeatureChooserDlg featChooser = new PhonologicalFeatureChooserDlg()) { featChooser.SetDlgInfo(m_cache, m_mediator); if (this.Parent is SIL.FieldWorks.XWorks.MorphologyEditor.RegRuleFormulaControl) { featChooser.SetHelpTopic("khtpChoose-Grammar-PhonFeats-RegRuleFormulaControl"); } else if (this.Parent is SIL.FieldWorks.XWorks.MorphologyEditor.MetaRuleFormulaControl) { featChooser.SetHelpTopic("khtpChoose-Grammar-PhonFeats-MetaRuleFormulaControl"); } else if (this.Parent is SIL.FieldWorks.XWorks.MorphologyEditor.AffixRuleFormulaControl) { featChooser.SetHelpTopic("khtpChoose-LexiconEdit-PhonFeats-AffixRuleFormulaControl"); } DialogResult res = featChooser.ShowDialog(); if (res == DialogResult.OK) { PhNCFeatures featNC = new PhNCFeatures(); m_cache.LangProject.PhonologicalDataOA.NaturalClassesOS.Append(featNC); featNC.Name.UserDefaultWritingSystem = string.Format(MEStrings.ksRuleNCFeatsName, m_ruleName); featNC.FeaturesOA = new FsFeatStruc(); featChooser.FS = featNC.FeaturesOA; featChooser.UpdateFeatureStructure(); featNC.FeaturesOA.NotifyNew(); featNC.NotifyNew(); data = featNC.Hvo; } else if (res != DialogResult.Cancel) { featChooser.HandleJump(); } } break; case RuleInsertType.WORD_BOUNDARY: data = m_cache.GetIdFromGuid(LangProject.kguidPhRuleWordBdry); break; case RuleInsertType.MORPHEME_BOUNDARY: data = m_cache.GetIdFromGuid(LangProject.kguidPhRuleMorphBdry); break; case RuleInsertType.INDEX: // put the clicked index in the data field data = (int)e.Link.Tag; break; default: data = 0; break; } Insert(this, new RuleInsertEventArgs(type, data)); } }