///// <summary> ///// Return the WfiMorphBundleDefaultSenseHandler for the supplied cache, creating it if needed. ///// </summary> ///// <param name="cda"></param> ///// <returns></returns> //public static WfiMorphBundleDefaultSenseHandler InstallHandler(IVwCacheDa cda) //{ // WfiMorphBundleDefaultSenseHandler vh = (WfiMorphBundleDefaultSenseHandler)cda.GetVirtualHandlerName(kClassName, kFieldName); // if (vh == null) // { // vh = new WfiMorphBundleDefaultSenseHandler(); // vh.Type = (int)CellarModuleDefns.kcptReferenceAtom; // vh.ClassName = kClassName; // vh.FieldName = kFieldName; // cda.InstallVirtual(vh); // } // return vh; //} public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { ISilDataAccess sda = cda as ISilDataAccess; int hvoSense = sda.get_ObjectProp(hvo, (int)WfiMorphBundle.WfiMorphBundleTags.kflidSense); if (hvoSense == 0) { // Try for a default. int hvoMsa = sda.get_ObjectProp(hvo, (int)WfiMorphBundle.WfiMorphBundleTags.kflidMsa); if (hvoMsa != 0) { int hvoEntry = sda.get_ObjectProp(hvoMsa, (int)CmObjectFields.kflidCmObject_Owner); if (hvoEntry != 0) { hvoSense = SenseWithMsa(sda, hvoEntry, (int)LexEntry.LexEntryTags.kflidSenses, hvoMsa); if (hvoSense == 0) { // no sense has right MSA...go for the first sense of any kind. int csense = sda.get_VecSize(hvoEntry, (int)LexEntry.LexEntryTags.kflidSenses); if (csense > 0) hvoSense = sda.get_VecItem(hvoEntry, (int)LexEntry.LexEntryTags.kflidSenses, 0); } } } } cda.CacheObjProp(hvo, tag, hvoSense); }
public SimpleDataParser(IFwMetaDataCache mdc, IVwCacheDa cda) { m_mdc = mdc; m_cda = cda; m_sda = cda as ISilDataAccess; m_wsf = m_sda.WritingSystemFactory; }
public void TestSetup() { RegistryHelper.CompanyName = "SIL"; m_ISilDataAccess = VwCacheDaClass.Create(); ILgWritingSystemFactory wsf = new PalasoWritingSystemManager(); m_ISilDataAccess.WritingSystemFactory = wsf; m_IVwCacheDa = (IVwCacheDa)m_ISilDataAccess; }
/// <summary> /// Loads segments for a paragraph (and dependent dummy annotations such as ) /// </summary> /// <param name="hvoWfi"></param> /// <param name="tag"></param> /// <param name="ws"></param> /// <param name="cda"></param> public override void Load(int hvoPara, int ktagParaSegments, int ws, IVwCacheDa cda) { // The parser will create and cache our segments (and dependent dummy annotations). LoadParagraphInfoToCache(hvoPara); if (m_cache.VwCacheDaAccessor != cda) { int[] segments = m_cache.GetVectorProperty(hvoPara, ktagParaSegments, true); cda.CacheVecProp(hvoPara, ktagParaSegments, segments, segments.Length); } }
/// ------------------------------------------------------------------------------------- /// <summary> /// Default constructor /// </summary> /// ------------------------------------------------------------------------------------- public BulletsPreview() { m_CacheDa = VwCacheDaClass.Create(); m_DataAccess = (ISilDataAccess)m_CacheDa; m_vc = new BulletsPreviewVc(); // So many things blow up so badly if we don't have one of these that I finally decided to just // make one, even though it won't always, perhaps not often, be the one we want. CreateTempWritingSystemFactory(); m_DataAccess.WritingSystemFactory = WritingSystemFactory; VScroll = false; // no vertical scroll bar visible. AutoScroll = false; // not even if the root box is bigger than the window. }
int m_cchPrevMorphemes; // Total length of morphemes before m_imorph. public MorphemeBreaker(CachePair caches, string input, int hvoSbWord, int wsVern, SandboxBase sandbox) { m_caches = caches; m_sda = caches.DataAccess; m_cda = (IVwCacheDa)m_sda; m_input = input; m_hvoSbWord = hvoSbWord; m_cOldMorphs = m_sda.get_VecSize(m_hvoSbWord, ktagSbWordMorphs); ITsStrFactory m_tsf = TsStrFactoryClass.Create(); m_wsVern = wsVern; m_types = m_caches.MainCache.ServiceLocator.GetInstance<IMoMorphTypeRepository>(); m_sandbox = sandbox; }
/// <summary> /// /// </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) { // JohnT: this is often used in sorting and filtering, it is usually way too expensive // to either validate or preload the object. This can cost several queries per item // in a 32K item list! ICmObject obj = CmObject.CreateFromDBObject(m_cache, hvo, false); ITsString tss; if (m_methodInfo != null) { object[] parm = new object[1]; parm[0] = this.WsId(m_cache, hvo, ws); tss = (ITsString)m_methodInfo.Invoke(obj, parm); } else { tss = (ITsString)m_propertyInfo.GetValue(obj, null); } cda.CacheStringProp(hvo, tag, tss); }
/// <summary> /// Load both the semantic domains and the lexical relation information for hvoEntry. /// Returns false (after displaying a dialog) if the entry has no associated domains or /// lexical relations, or none of them are linked to any other entries. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry"></param> /// <param name="domainsOut"></param> /// <param name="lexrelsOut"></param> /// <param name="cdaTemp"></param> /// <param name="owner"></param> /// <returns></returns> static internal bool LoadDomainAndRelationInfo(FdoCache cache, int hvoEntry, out int[] domainsOut, out int[] lexrelsOut, out IVwCacheDa cdaTemp, IWin32Window owner) { bool fHaveSemDomains = LoadDomainInfo(cache, hvoEntry, out domainsOut, out cdaTemp, owner); bool fHaveLexRels = LoadLexicalRelationInfo(cache, hvoEntry, out lexrelsOut, cdaTemp, owner); if (!fHaveSemDomains && !fHaveLexRels) { MessageBox.Show(owner, FdoUiStrings.ksNoSemanticDomainsListedForEntry, FdoUiStrings.ksFindRelatedWords); return false; } if (domainsOut.Length == 0 && lexrelsOut.Length == 0) { MessageBox.Show(owner, FdoUiStrings.ksNoEntriesWithSameSemanticDomain, FdoUiStrings.ksFindRelatedWords); return false; } return true; }
public void HandleCreateMenuItem(object sender, EventArgs ea) { CheckDisposed(); if (!m_cache.VerifyValidObject(m_obj)) { return; } int itemIndex = (((ToolStripItem)(sender)).Owner as ContextMenuStrip).Items.IndexOf((ToolStripItem)sender); int hvoType = m_refTypesAvailable[itemIndex]; bool fReverseRef = m_rgfReversedRefType[itemIndex]; ILexRefType lrt = LexRefType.CreateFromDBObject(m_cache, hvoType); int hvoNew = 0; int hvoFirst = 0; if (fReverseRef) { // When creating a tree Lexical Relation and the user is choosing // the root of the tree, first see if the user selects a lexical entry. // If they do not select anything (hvoFirst==0) return and do not create the slice. hvoFirst = GetRootObjectHvo(lrt); if (hvoFirst == 0) { return; // the user cancelled out of the operation. } if (lrt.MappingType == (int)LexRefType.MappingTypes.kmtSenseTree || lrt.MappingType == (int)LexRefType.MappingTypes.kmtEntryTree || lrt.MappingType == (int)LexRefType.MappingTypes.kmtEntryOrSenseTree) { // Use an existing LexReference if one exists. foreach (ILexReference lr in lrt.MembersOC) { if (lr.TargetsRS.Count > 0 && lr.TargetsRS.HvoArray[0] == hvoFirst) { lr.TargetsRS.Append(m_obj.Hvo); hvoNew = lr.Hvo; break; } } } } else { // Launch the dialog that allows the user to choose a lexical entry. // If they choose an entry, it is returned in hvoFirst so go ahead and // create the lexical relation and add this lexical entry to that relation. hvoFirst = GetChildObjectHvo(lrt); if (hvoFirst == 0) { return; // the user cancelled out of the operation. } } if (hvoNew == 0) { hvoNew = m_cache.CreateObject((int)LexReference.kclsidLexReference, hvoType, (int)LexRefType.LexRefTypeTags.kflidMembers, 0); ILexReference lr = LexReference.CreateFromDBObject(m_cache, hvoNew); if (fReverseRef) { lr.TargetsRS.InsertAt(hvoFirst, 0); lr.TargetsRS.InsertAt(m_obj.Hvo, 1); } else { //When creating a lexical relation slice, //add the current lexical entry to the lexical relation as the first item lr.TargetsRS.InsertAt(m_obj.Hvo, 0); //then also add the lexical entry that the user selected in the chooser dialog. lr.TargetsRS.InsertAt(hvoFirst, 1); } } m_refs.Add(hvoNew); this.ExpandNewNode(); // update the cache through our virtual handler. if (m_vh != null) { IVwCacheDa cda = m_cache.VwCacheDaAccessor; int flid = m_vh.Tag; m_vh.Load(m_obj.Hvo, flid, 0, cda); m_cache.MainCacheAccessor.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_obj.Hvo, flid, 0, 1, 0); } (m_obj as CmObject).UpdateTimestampForVirtualChange(); if (hvoFirst != 0) { ICmObject cmoFirst = CmObject.CreateFromDBObject(m_cache, hvoFirst); (cmoFirst as CmObject).UpdateTimestampForVirtualChange(); } }
/// <summary> /// Load the information about the domains of hvoEntry. Returns false /// if the entry has no associated domains or none of them are linked to any other entries. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry">int ID of the lexical entry</param> /// <param name="hvoSemanticDomainsOut">A list of int IDs of the semantic domains of the lexical entry</param> /// <param name="cdaTemp"></param> /// <returns></returns> static private bool LoadDomainInfo(FdoCache cache, int hvoEntry, out int[] hvoSemanticDomainsOut, out IVwCacheDa cdaTemp) { // REVIEW (SteveMiller): The LINQ below runs slow the first time its run. We should try to // optimize it if possible. var entryRepo = cache.ServiceLocator.GetInstance<ILexEntryRepository>(); var lexEntry = entryRepo.GetObject(hvoEntry); var domains = (from sense in lexEntry.AllSenses from sd in sense.SemanticDomainsRC where (from incoming in sd.ReferringObjects where incoming is ILexSense && incoming.OwnerOfClass<ILexEntry>() != lexEntry select incoming).FirstOrDefault() != null select sd).Distinct().ToArray(); hvoSemanticDomainsOut = ( from sd in domains select sd.Hvo).ToArray(); cdaTemp = VwCacheDaClass.Create(); foreach (var sd in domains) { cdaTemp.CacheStringProp(sd.Hvo, RelatedWordsVc.ktagName, sd.Name.BestVernacularAnalysisAlternative); } cdaTemp.CacheVecProp(hvoEntry, RelatedWordsVc.ktagDomains, hvoSemanticDomainsOut, hvoSemanticDomainsOut.Length); return hvoSemanticDomainsOut.Length > 0; }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; base.Dispose(disposing); if (disposing) { // Cleanup managed stuff here. if (m_vc != null) m_vc.Dispose(); } // Cleanup unmanaged stuff here. m_DataAccess = null; if (m_CacheDa != null) { m_CacheDa.ClearAllData(); if (Marshal.IsComObject(m_CacheDa)) Marshal.ReleaseComObject(m_CacheDa); m_CacheDa = null; } m_owner = null; // It will get disposed on its own, if it hasn't been already. m_vc = null; }
public void Setup() { // Create the following: // - part and layout inventories // - metadata cache // - DataAccess cache // - collection of columns to display. // We want a MetaDataCache that knows about // - LexEntry.Senses, Msas, CitationForm, Bibliography, Etymology // - LexSense.SemanticDomains, SenseType, Status, gloss // - CmPossibility Name, abbr // - MoMorphSynAnalysis // - MoStemMsa // - MoDerivationalMsa string m_sTestPath = Path.Combine(DirectoryFinder.FwSourceDirectory, Path.Combine("Common", Path.Combine("Controls", Path.Combine("XMLViews", Path.Combine("XMLViewsTests", "SampleCm.xml"))))); m_mdc = MetaDataCache.CreateMetaDataCache(m_sTestPath); // We want ISilDataAccess with: // - LexEntry (1) with no senses and one MSA (2) // - LexEntry (4) with one sense (5) and no MSA // - LexEntry (6) with three senses (7, 8, 9) and two MSAs (10, 11) // - sense(5) with no semantic domains // - senses with one SD (7->30, 8->31) // - sense with three SDs, one the same as the first (9->30, 31, 32) // - MoStemMsa (2, 11) // - MoDerivationalMsa (10) m_cda = VwCacheDaClass.Create(); m_sda = m_cda as ISilDataAccess; m_wsManager = new PalasoWritingSystemManager(); m_sda.WritingSystemFactory = m_wsManager; var parser = new SimpleDataParser(m_mdc, m_cda); parser.Parse(Path.Combine(DirectoryFinder.FwSourceDirectory, Path.Combine("Common", Path.Combine("Controls", Path.Combine("XMLViews", Path.Combine("XMLViewsTests", "SampleData.xml")))))); int wsEn = m_wsManager.GetWsFromStr("en"); // These are mainly to check out the parser. Assert.AreEqual(3, m_sda.get_ObjectProp(2, 23011), "part of speech of an MoStemMsa"); Assert.AreEqual(2, m_sda.get_VecItem(1, 2009, 0), "owned msa"); Assert.AreEqual("noun", m_sda.get_MultiStringAlt(3, 7003, wsEn).Text, "got ms property"); Assert.AreEqual(9, m_sda.get_VecItem(6, 2010, 2), "3rd sense"); Assert.AreEqual(31, m_sda.get_VecItem(9, 21016, 1), "2nd semantic domain"); // Columns includes // - CitationForm (string inside span) // - Bibliography (string not in span) // - Sense glosses (string in para in seq, nested in column element) // - Semantic domains (pair of strings in para in seq in seq, using layout refs) // - MSAs (simplified, but polymorphic with one having <choice> and one <obj> to CmPossibility XmlDocument docColumns = new XmlDocument(); docColumns.Load(Path.Combine(DirectoryFinder.FwSourceDirectory, Path.Combine("Common", Path.Combine("Controls", Path.Combine("XMLViews", Path.Combine("XMLViewsTests", "TestColumns.xml")))))); m_columnList = docColumns.DocumentElement.ChildNodes; // Parts just has what those columns need. string partDirectory = Path.Combine(DirectoryFinder.FwSourceDirectory, Path.Combine("Common", Path.Combine("Controls", Path.Combine("XMLViews", "XMLViewsTests")))); Dictionary <string, string[]> keyAttrs = new Dictionary <string, string[]>(); keyAttrs["layout"] = new string[] { "class", "type", "name" }; keyAttrs["group"] = new string[] { "label" }; keyAttrs["part"] = new string[] { "ref" }; // Currently there are no specialized layout files that match. m_layoutInventory = new Inventory(new string[] { partDirectory }, "*.fwlayout", "/LayoutInventory/*", keyAttrs, "TestManyOneBrowse", "ProjectPath"); keyAttrs = new Dictionary <string, string[]>(); keyAttrs["part"] = new string[] { "id" }; m_partInventory = new Inventory(new string[] { partDirectory }, "TestParts.xml", "/PartInventory/bin/*", keyAttrs, "TestManyOneBrowse", "ProjectPath"); m_layouts = new LayoutCache(m_mdc, m_layoutInventory, m_partInventory); }
/// <summary> /// Load the information about the lexical relations that link to hvoEntry. Specifically, we want LexReferences /// that refer to the target Entry (hvoEntry) and also some other lexical entry. /// For each such thing, we store in cdaTemp the name (or, if appropriate, the reverse name) of the /// relationship that hvoEntry has to the other entry(s) in the lex reference, as property RelatedWordsVc.ktagName of /// the LexReference Hvo. Return through relsOut the list of LexReferences that are thus related to hvoEntry. /// Return true if there are any. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry">ID of the lexical entry we're working with</param> /// <param name="relsOut">an array of IDs (HVOs) for related objects</param> /// <param name="cdaTemp"></param> /// <returns>false if the entry has no associated lexical relations, or none of them are linked to any other entries.</returns> // static private bool LoadLexicalRelationInfo(FdoCache cache, int hvoEntry, out int[] relsOut, IVwCacheDa cdaTemp) { var relatedObjectIds = new List<int>(); var entryRepository = cache.ServiceLocator.GetInstance<ILexEntryRepository>(); var lexEntry = entryRepository.GetObject(hvoEntry); var targets = new HashSet<ICmObject>(lexEntry.AllSenses.Cast<ICmObject>()) {lexEntry}; foreach (ILexRefType lexRefType in cache.LanguageProject.LexDbOA.ReferencesOA.ReallyReallyAllPossibilities) { foreach (var lexReference in lexRefType.MembersOC) { // If at least one target is the lex entry or one of its senses. if ((from target in lexReference.TargetsRS where targets.Contains(target) select target).FirstOrDefault() != null && (from target in lexReference.TargetsRS where !targets.Contains(target) select target).FirstOrDefault() != null) { // The name we want to use for our lex reference is either the name or the reverse name // (depending on the direction of the relationship, if relevant) of the owning lex ref type. var lexReferenceName = lexRefType.Name.BestVernacularAnalysisAlternative; if (lexRefType.MappingType == (int)MappingTypes.kmtEntryAsymmetricPair || lexRefType.MappingType == (int)MappingTypes.kmtEntryOrSenseAsymmetricPair || lexRefType.MappingType == (int)MappingTypes.kmtSenseAsymmetricPair || lexRefType.MappingType == (int)MappingTypes.kmtEntryTree || lexRefType.MappingType == (int)MappingTypes.kmtEntryOrSenseTree || lexRefType.MappingType == (int)MappingTypes.kmtSenseTree) { if (lexEntry.OwnOrd == 0 && lexRefType.Name != null) // the original code had a check for name length as well. lexReferenceName = lexRefType.ReverseName.BestVernacularAnalysisAlternative; } cdaTemp.CacheStringProp(lexReference.Hvo, RelatedWordsVc.ktagName, lexReferenceName); relatedObjectIds.Add(lexReference.Hvo); } } } relsOut = relatedObjectIds.ToArray(); return relsOut.Length > 0; }
/// <summary> /// Load the information about the lexical relations that link to hvoEntry. Specifically, we want LexReferences /// that refer to the target Entry (hvoEntry) and also some other lexical entry. /// For each such thing, we store in cdaTemp the name (or, if appropriate, the reverse name) of the /// relationship that hvoEntry has to the other entry(s) in the lex reference, as property RelatedWordsVc.ktagName of /// the LexReference Hvo. Return through relsOut the list of LexReferences that are thus related to hvoEntry. /// Return true if there are any. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry">ID of the lexical entry we're working with</param> /// <param name="relsOut">an array of IDs (HVOs) for related objects</param> /// <param name="cdaTemp"></param> /// <returns>false if the entry has no associated lexical relations, or none of them are linked to any other entries.</returns> // static private bool LoadLexicalRelationInfo(LcmCache cache, int hvoEntry, out int[] relsOut, IVwCacheDa cdaTemp) { var relatedObjectIds = new List <int>(); var entryRepository = cache.ServiceLocator.GetInstance <ILexEntryRepository>(); var lexEntry = entryRepository.GetObject(hvoEntry); var targets = new HashSet <ICmObject>(lexEntry.AllSenses.Cast <ICmObject>()) { lexEntry }; foreach (ILexRefType lexRefType in cache.LanguageProject.LexDbOA.ReferencesOA.ReallyReallyAllPossibilities) { foreach (var lexReference in lexRefType.MembersOC) { // If at least one target is the lex entry or one of its senses. if ((from target in lexReference.TargetsRS where targets.Contains(target) select target).FirstOrDefault() != null && (from target in lexReference.TargetsRS where !targets.Contains(target) select target).FirstOrDefault() != null) { // The name we want to use for our lex reference is either the name or the reverse name // (depending on the direction of the relationship, if relevant) of the owning lex ref type. var lexReferenceName = lexRefType.Name.BestVernacularAnalysisAlternative; if (lexRefType.MappingType == (int)MappingTypes.kmtEntryAsymmetricPair || lexRefType.MappingType == (int)MappingTypes.kmtEntryOrSenseAsymmetricPair || lexRefType.MappingType == (int)MappingTypes.kmtSenseAsymmetricPair || lexRefType.MappingType == (int)MappingTypes.kmtEntryTree || lexRefType.MappingType == (int)MappingTypes.kmtEntryOrSenseTree || lexRefType.MappingType == (int)MappingTypes.kmtSenseTree) { if (lexEntry.OwnOrd == 0 && lexRefType.Name != null) // the original code had a check for name length as well. { lexReferenceName = lexRefType.ReverseName.BestVernacularAnalysisAlternative; } } cdaTemp.CacheStringProp(lexReference.Hvo, RelatedWordsVc.ktagName, lexReferenceName); relatedObjectIds.Add(lexReference.Hvo); } } } relsOut = relatedObjectIds.ToArray(); return(relsOut.Length > 0); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load the data for property tag of object hvo (and the specified writing system, if relevant) /// into the cache. This is the fundamental method you must implement to make a virual hander. /// </summary> /// <param name="hvo">The hvo.</param> /// <param name="tag">The tag.</param> /// <param name="ws">The ws.</param> /// <param name="_cda">The _cda.</param> /// ------------------------------------------------------------------------------------ public abstract void Load(int hvo, int tag, int ws, IVwCacheDa _cda);
protected SimpleRootSiteDataProviderViewBase(RealDataCache rdc) { Cache = rdc; VwCache = rdc; m_hvoRoot = Cache.MakeNewObject(kclsidOwnerless, 0, -1, -1); }
/// <summary> /// Load the information about the domains of hvoEntry. Returns false /// if the entry has no associated domains or none of them are linked to any other entries. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry">int ID of the lexical entry</param> /// <param name="hvoSemanticDomainsOut">A list of int IDs of the semantic domains of the lexical entry</param> /// <param name="cdaTemp"></param> /// <returns></returns> static private bool LoadDomainInfo(LcmCache cache, int hvoEntry, out int[] hvoSemanticDomainsOut, out IVwCacheDa cdaTemp) { // REVIEW (SteveMiller): The LINQ below runs slow the first time its run. We should try to // optimize it if possible. var entryRepo = cache.ServiceLocator.GetInstance <ILexEntryRepository>(); var lexEntry = entryRepo.GetObject(hvoEntry); var domains = (from sense in lexEntry.AllSenses from sd in sense.SemanticDomainsRC where (from incoming in sd.ReferringObjects where incoming is ILexSense && incoming.OwnerOfClass <ILexEntry>() != lexEntry select incoming).FirstOrDefault() != null select sd).Distinct().ToArray(); hvoSemanticDomainsOut = ( from sd in domains select sd.Hvo).ToArray(); cdaTemp = VwCacheDaClass.Create(); cdaTemp.TsStrFactory = TsStringUtils.TsStrFactory; foreach (var sd in domains) { cdaTemp.CacheStringProp(sd.Hvo, RelatedWordsVc.ktagName, sd.Name.BestVernacularAnalysisAlternative); } cdaTemp.CacheVecProp(hvoEntry, RelatedWordsVc.ktagDomains, hvoSemanticDomainsOut, hvoSemanticDomainsOut.Length); return(hvoSemanticDomainsOut.Length > 0); }
/// <summary> /// Load the information about the lexical relations that link to hvoEntry. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry"></param> /// <param name="relsOut"></param> /// <param name="cdaTemp"></param> /// <param name="owner"></param> /// <returns>false if the entry has no associated lexical relations, or none of them are linked to any other entries.</returns> static private bool LoadLexicalRelationInfo(FdoCache cache, int hvoEntry, out int[] relsOut, IVwCacheDa cdaTemp, IWin32Window owner) { string sql1 = string.Format("SELECT DISTINCT tar2.Src, lrt.MappingType, tar.Ord, cn.Txt, cn.Ws, rev.Txt, rev.Ws" + " FROM LexReference_Targets tar" + " LEFT OUTER JOIN LexReference_Targets tar2 ON tar2.Src=tar.Src AND EXISTS (SELECT * FROM CmObject other WHERE other.Id=tar2.Dst AND other.Id != tar.Dst)" + " LEFT OUTER JOIN LexRefType_Members mem ON mem.Dst=tar2.Src" + " LEFT OUTER JOIN LexRefType lrt ON lrt.Id=mem.Src" + " LEFT OUTER JOIN CmPossibility_Name cn ON cn.Obj=mem.Src AND cn.Ws IN ({0}, {1})" + " LEFT OUTER JOIN LexRefType_ReverseName rev ON rev.Obj=mem.Src AND rev.Ws IN ({0}, {1})" + " WHERE tar.Dst = {2} OR tar.Dst IN (SELECT Id FROM fnGetOwnedIds({2}, {3}, {4}))", cache.DefaultVernWs, cache.DefaultAnalWs, hvoEntry, (int)LexEntry.LexEntryTags.kflidSenses, (int)LexSense.LexSenseTags.kflidSenses); IOleDbCommand odc = DbOps.MakeRowSet(cache, sql1, null); bool fGotLexRef = false; // true if we found a lexical relation for the entry or one of its senses try { bool fMoreRows; List <int> rels = new List <int>(); for (odc.NextRow(out fMoreRows); fMoreRows; odc.NextRow(out fMoreRows)) { fGotLexRef = true; int hvoLexRef = DbOps.ReadInt(odc, 0); if (hvoLexRef == 0) { continue; // null row. } if (!((ISilDataAccess)cdaTemp).get_IsPropInCache(hvoLexRef, RelatedWordsVc.ktagName, (int)CellarModuleDefns.kcptString, 0)) { int type = DbOps.ReadInt(odc, 1); int ord = DbOps.ReadInt(odc, 2); ITsString tssName = DbOps.ReadTss2(odc, 3); ITsString tssRevName = DbOps.ReadTss2(odc, 5); if (type == (int)LexRefType.MappingTypes.kmtEntryAsymmetricPair || type == (int)LexRefType.MappingTypes.kmtEntryOrSenseAsymmetricPair || type == (int)LexRefType.MappingTypes.kmtSenseAsymmetricPair) { if (ord != 0 && tssRevName != null && tssRevName.Length > 0) { tssName = tssRevName; } } else if (type == (int)LexRefType.MappingTypes.kmtEntryTree || type == (int)LexRefType.MappingTypes.kmtEntryOrSenseTree || type == (int)LexRefType.MappingTypes.kmtSenseTree) { if (ord != 0 && tssRevName != null && tssRevName.Length > 0) { tssName = tssRevName; } } cdaTemp.CacheStringProp(hvoLexRef, RelatedWordsVc.ktagName, tssName); rels.Add(hvoLexRef); } } relsOut = DbOps.ListToIntArray(rels); } finally { DbOps.ShutdownODC(ref odc); } return(fGotLexRef); }
/// <summary> /// Load the information about the domains of hvoEntry. Returns false /// if the entry has no associated domains or none of them are linked to any other entries. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry"></param> /// <param name="domains"></param> /// <param name="cdaTemp"></param> /// <param name="fMoreRows"></param> /// <param name="owner"></param> /// <returns></returns> static private bool LoadDomainInfo(FdoCache cache, int hvoEntry, out int[] domainsOut, out IVwCacheDa cdaTemp, IWin32Window owner) { // This produces first the Semantic domains of the senses of the entry, // then restricts to those that occur on some other entry, // then looks up the vernacular (or, if none, analysis) name of the domains. The are sorted by // domain name. // We do left outer joins for the last two so we can distinguish the failure // modes "no SDs on senses of initial entry" versus "no other entries in those SDs" string sql1 = string.Format("select lssd2.dst, cn.txt, cn.ws from LexEntry le" + " join LexSense_ ls on ls.owner$ = le.id" + " join LexSense_SemanticDomains lssd on lssd.src = ls.id " + " left outer join LexSense_SemanticDomains lssd2 on lssd2.dst = lssd.dst" + " and exists (select * from CmObject lsother" + " join LexEntry leother on leother.id = lsother.owner$ and lsother.id = lssd2.src and leother.id != le.id)" + " left outer join CmPossibility_Name cn on lssd2.dst = cn.obj and cn.ws" + " in ({0}, {1}) where le.id = {2}" + " group by lssd2.dst, cn.txt, cn.ws" + " order by cn.txt", cache.DefaultVernWs, cache.DefaultAnalWs, hvoEntry); IOleDbCommand odc = DbOps.MakeRowSet(cache, sql1, null); bool fGotSrcDomain = false; // true if we found a semantic domain on some sense of the source entry try { bool fMoreRows; List <int> domains = new List <int>(); cdaTemp = VwCacheDaClass.Create(); for (odc.NextRow(out fMoreRows); fMoreRows; odc.NextRow(out fMoreRows)) { fGotSrcDomain = true; // any row indicates success here. int hvoDomain = DbOps.ReadInt(odc, 0); if (hvoDomain == 0) { continue; // null row, an SD that occurs on no other entry. } if (!((ISilDataAccess)cdaTemp).get_IsPropInCache(hvoDomain, RelatedWordsVc.ktagName, (int)CellarModuleDefns.kcptString, 0)) { ITsString tss = DbOps.ReadTss2(odc, 1); if (tss == null) { tss = FDO.Cellar.CmPossibility.BestAnalysisOrVernName(cache, hvoDomain); } cdaTemp.CacheStringProp(hvoDomain, RelatedWordsVc.ktagName, tss); domains.Add(hvoDomain); } } domainsOut = DbOps.ListToIntArray(domains); } finally { DbOps.ShutdownODC(ref odc); } return(fGotSrcDomain); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a table/row for editing a new object. /// </summary> /// <param name="vwenv">The vwenv.</param> /// <param name="hvo">The hvo.</param> /// ------------------------------------------------------------------------------------ private void AddEditRow(IVwEnv vwenv, int hvo) { // set the border color to gray vwenv.set_IntProperty((int )FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)RGB(BorderColor)); //SystemColors.ControlDark)); // Make a table VwLength[] rglength = m_xbv.GetColWidthInfo(); int colCount = m_columns.Count; if (m_fShowSelected) { colCount++; } VwLength vl100; // Length representing 100%. vl100.unit = rglength[0].unit; vl100.nVal = 1; for (int i = 0; i < colCount; ++i) { Debug.Assert(vl100.unit == rglength[i].unit); vl100.nVal += rglength[i].nVal; } vwenv.OpenTable(colCount, // this many columns vl100, // using 100% of available space 72000 / 96, //0, // no border VwAlignment.kvaLeft, // cells by default left aligned // VwFramePosition.kvfpBelow, //.kvfpBox, //.kvfpVoid, // no frame VwFramePosition.kvfpBelow | VwFramePosition.kvfpRhs, VwRule.kvrlCols, // vertical lines between columns 0, // no space between cells 0, // no padding within cell. false); for (int i = 0; i < colCount; ++i) { vwenv.MakeColumns(1, rglength[i]); } // the table only has a body (no header or footer), and only one row. vwenv.OpenTableBody(); vwenv.OpenTableRow(); IVwCacheDa cda = m_cache.DomainDataByFlid as IVwCacheDa; // Make the cells. if (m_fShowColumnsRTL) { for (int i = m_columns.Count; i > 0; --i) { AddEditCell(vwenv, cda, i); } } else { for (int i = 1; i <= m_columns.Count; ++i) { AddEditCell(vwenv, cda, i); } } vwenv.CloseTableRow(); vwenv.CloseTableBody(); vwenv.CloseTable(); }
/// <summary> /// (uses Tag internally) /// </summary> /// <param name="hvo"></param> /// <param name="ws"></param> /// <param name="_cda"></param> public void Load(int hvo, int ws, IVwCacheDa _cda) { Load(hvo, Tag, ws, _cda); }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; // NB: m_ISilDataAccess and m_IVwCacheDa are the same exact object. switch (GetType().Name) { default: throw new InvalidOperationException("Class of obejct not recognized."); case "IVwCacheDaCppTests": // Not really relevant, as of 12/7.06, since the C++ class was not being used. // It's TextFixture attribute was commented out. if (m_ISilDataAccess != null) { if (m_ISilDataAccess.WritingSystemFactory != null) m_ISilDataAccess.WritingSystemFactory.Shutdown(); if (Marshal.IsComObject(m_ISilDataAccess)) { int n = Marshal.ReleaseComObject(m_ISilDataAccess); Debug.Assert(n == 0); } } break; case "IVwCacheDaCSharpTests": if (disposing) { // Dispose managed resources here. if (m_IVwCacheDa != null) // It has to be IDisposable if it is C# && m_IVwCacheDa is IDisposable) { if (m_ISilDataAccess.WritingSystemFactory != null) m_ISilDataAccess.WritingSystemFactory.Shutdown(); (m_IVwCacheDa as IDisposable).Dispose(); } } break; } // Dispose unmanaged resources here, whether disposing is true or false. m_IVwCacheDa = null; m_ISilDataAccess = null; base.Dispose(disposing); }
/// <summary> /// Clear all text. If fReconstruct is true, also clears the display. /// </summary> public void Clear(bool fReconstruct) { CheckDisposed(); if (m_sda == null) { m_sda = VwCacheDaClass.Create(); if (WritingSystemFactory != null) m_sda.WritingSystemFactory = WritingSystemFactory; m_cd = (IVwCacheDa) m_sda; } else { m_hvoNextPara = khvoFirstPara; m_cd.CacheVecProp(m_hvoRoot, (int)SampleTags.ktagTextParas, new int[0], 0); if (fReconstruct) RootBox.Reconstruct(); } }
private void AddEditCell(IVwEnv vwenv, IVwCacheDa cda, int i) { XmlNode node = m_columns[i - 1]; // Make a cell and embed an editable virtual string for the column. var editable = XmlUtils.GetOptionalBooleanAttributeValue(node, "editable", true); if (!editable) vwenv.set_IntProperty((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, NoEditBackgroundColor); vwenv.OpenTableCell(1, 1); int flid = XMLViewsDataCache.ktagEditColumnBase + i; int ws = WritingSystemServices.GetWritingSystem(m_cache, node, null, m_cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle).Handle; // Paragraph directionality must be set before the paragraph is opened. bool fRTL = IsWsRTL(ws); vwenv.set_IntProperty((int)FwTextPropType.ktptRightToLeft, (int)FwTextPropVar.ktpvEnum, fRTL ? -1 : 0); vwenv.set_IntProperty((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, fRTL ? (int)FwTextAlign.ktalRight : (int)FwTextAlign.ktalLeft); // Fill in the cell with the virtual property. vwenv.OpenParagraph(); vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, editable ? (int)TptEditable.ktptIsEditable : (int)TptEditable.ktptNotEditable); vwenv.AddStringAltMember(flid, ws, this); vwenv.CloseParagraph(); vwenv.CloseTableCell(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Clean up any resources being used. /// </summary> /// ------------------------------------------------------------------------------------ protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; if (disposing) { ShutDownTempWsFactory(); // Must happen before call to base. } base.Dispose(disposing); if (disposing) { if (m_CacheDa != null) m_CacheDa.ClearAllData(); } m_vc = null; m_DataAccess = null; m_wsf = null; if (m_CacheDa != null && Marshal.IsComObject(m_CacheDa)) Marshal.ReleaseComObject(m_CacheDa); m_CacheDa = null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// This may be used to pre-load into the cache the value of property tag (and the /// specified ws, if applicable) for all the objects in the array. This can sometimes /// be more efficient than using Load for each property. This is currently not used /// by the framework, though the plan is that certain code may use it when it is known /// that values will be needed for the same property of several objects. It is always /// safe not to implement it; the worst that happens is that Load is called each time, /// with possibly disappointing performance. /// </summary> /// <param name="chvo">The chvo.</param> /// <param name="_rghvo">The _rghvo.</param> /// <param name="tag">The tag.</param> /// <param name="ws">The ws.</param> /// <param name="_cda">The _cda.</param> /// ------------------------------------------------------------------------------------ public virtual void PreLoad(int chvo, int[] _rghvo, int tag, int ws, IVwCacheDa _cda) { }
public override void Load(int hvo, int tag, int ws, IVwCacheDa cda) { // Value is always an empty string in the specified writing system. ITsStrFactory tsf = TsStrFactoryClass.Create(); ITsString tssEmpty = tsf.MakeString("", m_ws); if (ws == 0) cda.CacheStringProp(hvo, tag, tssEmpty); else cda.CacheStringAlt(hvo, tag, ws, tssEmpty); }
public override void MakeRoot() { CheckDisposed(); base.MakeRoot(); if (m_fdoCache == null || DesignMode) return; // A crude way of making sure the property we want is loaded into the cache. m_sense = LexSense.CreateFromDBObject(m_fdoCache, m_hvoObj); // Review JohnT: why doesn't the base class do this?? m_rootb = VwRootBoxClass.Create(); m_rootb.SetSite(this); if (m_vwCache == null) { m_vwCache = VwCacheDaClass.Create(); m_silCache = (ISilDataAccess)m_vwCache; m_silCache.WritingSystemFactory = m_fdoCache.LanguageWritingSystemFactoryAccessor; } LoadDummyCache(false); // And maybe this too, at least by default? m_rootb.DataAccess = m_silCache; m_vc = new ReversalIndexEntryVc(m_usedIndices, m_fdoCache); // arg4 could be used to supply a stylesheet. m_rootb.SetRootObject(m_hvoObj, m_vc, kFragMainObject, m_rootb.Stylesheet); m_heightView = m_rootb.Height; }
public RelatedWords(FdoCache cache, IVwSelection sel, int hvoEntry, int[] domains, int[] lexrels, IVwCacheDa cdaTemp, IVwStylesheet styleSheet, Mediator mediator, bool hideInsertButton) { m_cache = cache; m_sel = sel; m_hvoEntry = hvoEntry; m_styleSheet = styleSheet; m_mediator = mediator; // // Required for Windows Form Designer support // InitializeComponent(); AccessibleName = GetType().Name; m_btnInsert.Visible = !hideInsertButton; m_cdaTemp = cdaTemp; ISilDataAccess sda = m_cdaTemp as ISilDataAccess; sda.WritingSystemFactory = cache.WritingSystemFactory; SetupForEntry(domains, lexrels); var entry = cache.ServiceLocator.GetInstance<ILexEntryRepository>().GetObject(m_hvoEntry); m_view = new RelatedWordsView(m_cache, m_hvoEntry, entry.HeadWord, m_cdaTemp as ISilDataAccess, cache.ServiceLocator.WritingSystemManager.UserWs); m_view.Width = this.Width - 20; m_view.Height = m_btnClose.Top - 20; m_view.Top = 10; m_view.Left = 10; m_view.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; m_view.BackColor = Color.FromKnownColor(KnownColor.Window); m_view.EditingHelper.DefaultCursor = Cursors.Arrow; m_view.SelChanged += new EventHandler(m_view_SelChanged); this.Controls.Add(m_view); }
public override void MakeRoot() { CheckDisposed(); base.MakeRoot(); if (m_fdoCache == null || DesignMode) return; m_PhoneEnvReferenceVc = new PhoneEnvReferenceVc(m_fdoCache); m_vwCache = VwUndoDaClass.Create(); m_silCache = (ISilDataAccess)m_vwCache; m_silCache.WritingSystemFactory = m_fdoCache.LanguageWritingSystemFactoryAccessor; IActionHandler handler = ActionHandlerClass.Create(); m_silCache.SetActionHandler(handler); // Populate m_vwCache with data. ResynchListToDatabase(); m_rootb = VwRootBoxClass.Create(); m_rootb.SetSite(this); m_rootb.DataAccess = m_silCache; m_rootb.SetRootObject(m_rootObj.Hvo, m_PhoneEnvReferenceVc, kFragEnvironments, null); m_heightView = m_rootb.Height; }
/// <summary> /// Constructor /// </summary> internal InnerFwListBox(FwListBox owner) { m_owner = owner; m_CacheDa = VwCacheDaClass.Create(); m_DataAccess = (ISilDataAccess)m_CacheDa; // So many things blow up so badly if we don't have one of these that I finally decided to just // make one, even though it won't always, perhaps not often, be the one we want. m_wsf = LgWritingSystemFactoryClass.Create(); m_DataAccess.WritingSystemFactory = WritingSystemFactory; this.VScroll = true; this.AutoScroll = true; }
public RelatedWords(FdoCache cache, IVwSelection sel, int hvoEntry, int[] domains, int[] lexrels, IVwCacheDa cdaTemp, IVwStylesheet styleSheet) { m_cache = cache; m_sel = sel; m_hvoEntry = hvoEntry; m_styleSheet = styleSheet; // // Required for Windows Form Designer support // InitializeComponent(); m_cdaTemp = cdaTemp; ISilDataAccess sda = m_cdaTemp as ISilDataAccess; sda.WritingSystemFactory = cache.MainCacheAccessor.WritingSystemFactory; SetupForEntry(domains, lexrels); m_view = new RelatedWordsView(m_hvoEntry, m_cdaTemp as ISilDataAccess, cache.DefaultUserWs); m_view.Width = this.Width - 20; m_view.Height = m_btnClose.Top - 20; m_view.Top = 10; m_view.Left = 10; m_view.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; m_view.BackColor = Color.FromKnownColor(KnownColor.Window); m_view.EditingHelper.DefaultCursor = Cursors.Arrow; m_view.SelChanged += new EventHandler(m_view_SelChanged); this.Controls.Add(m_view); }
/// <summary> /// Load data into the VwCacheDa. /// </summary> public void LoadData(string filename) { ITsStrFactory tsf = (ITsStrFactory) new FwKernelLib.TsStrFactoryClass(); IVwCacheDa cda = (IVwCacheDa)m_sda; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filename); XmlNode book = xmlDoc.SelectSingleNode("book"); int wsAnalysis = m_wsf.get_Engine("en").get_WritingSystem(); // In real life try to get a meaningful one. int wsVern = m_wsf.get_Engine("de").get_WritingSystem(); // Vernacular ws. m_vc.SourceWs = wsAnalysis; m_vc.DestWs = wsVern; MakeStringProp(khvoBook, book, "name", ViewSampleVc.ktagBookName, wsAnalysis, tsf, cda); ITsPropsBldr tpb = (ITsPropsBldr) new FwKernelLib.TsPropsBldrClass(); tpb.SetIntPropValues((int)FwKernelLib.FwTextPropType.ktptWs, (int)FwKernelLib.FwTextPropVar.ktpvDefault, wsAnalysis); tpb.SetStrPropValue((int)FwKernelLib.FwTextPropType.ktptNamedStyle, "verseNumber"); ITsTextProps ttpVStyle = tpb.GetTextProps(); int [] sectionIds = new int[book.ChildNodes.Count]; int isection = 0; foreach (XmlNode section in book.ChildNodes) { int sectionId = m_hvoNextSection++; sectionIds[isection] = sectionId; isection++; MakeStringProp(sectionId, section, "refs", ViewSampleVc.ktagSectionRefs, wsAnalysis, tsf, cda); MakeStringProp(sectionId, section, "title", ViewSampleVc.ktagSectionTitle, wsAnalysis, tsf, cda); int[] paraIds = new int[section.ChildNodes.Count]; int ipara = 0; foreach (XmlNode para in section.ChildNodes) { int paraId = m_hvoNextPara++; paraIds[ipara] = paraId; ipara++; // Construct paragraph contents string ITsStrBldr tsb = (ITsStrBldr) new FwKernelLib.TsStrBldrClass(); foreach (XmlNode item in para.ChildNodes) { int ichLim = tsb.get_Length(); if (item.Name == "v") { string num = GetAttrVal(item, "n"); tsb.Replace(ichLim, ichLim, num, ttpVStyle); } else if (item.Name == "s") { string wsName = GetAttrVal(item, "ws"); int ws = wsName == null ? wsAnalysis : m_wsf.get_Engine(wsName).get_WritingSystem(); tsb.ReplaceTsString(ichLim, ichLim, tsf.MakeString(item.InnerText, ws)); } } // Review: should we assume the default ws analysis? Represent a multistring in the file? // Remember the last ws we encountered in the string? This is just a sample... cda.CacheStringAlt(paraId, ViewSampleVc.ktagParaContents, wsAnalysis, tsb.GetString()); } cda.CacheVecProp(sectionId, ViewSampleVc.ktagSectionParas, paraIds, paraIds.Length); } cda.CacheVecProp(khvoBook, ViewSampleVc.ktagBookSections, sectionIds, sectionIds.Length); }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; base.Dispose(disposing); if (disposing) { if (m_vc != null) m_vc.Dispose(); if (m_usedIndices != null) m_usedIndices.Clear(); } m_sense = null; m_vc = null; if (m_tsf != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(m_tsf); m_tsf = null; m_silCache = null; if (m_vwCache != null) { m_vwCache.ClearAllData(); System.Runtime.InteropServices.Marshal.ReleaseComObject(m_vwCache); m_vwCache = null; } m_usedIndices = null; }
/// <summary> /// This is the real guts of type-ahead. It is called by the client whenever a key is pressed. /// It returns true if it handled the key press, which it does if the current selection /// is in a type-ahead name property. /// </summary> /// <param name="ehelp"></param> /// <param name="e"></param> /// <param name="modifiers"></param> /// <param name="vwGraphics"></param> /// <returns></returns> public virtual bool OnKeyPress(EditingHelper ehelp, KeyPressEventArgs e, Keys modifiers, IVwGraphics vwGraphics) { IVwRootBox rootb = ehelp.Callbacks.EditedRootBox; if (rootb == null) // If we don't have a root box, can't do anything interesting. { return(false); } IVwSelection sel = rootb.Selection; if (sel == null) // nothing interesting to do without a selection, either. { return(false); } ITsString tssA, tssE; int ichA, ichE, hvoObjA, hvoObjE, tagA, tagE, ws; bool fAssocPrev; // Enhance JohnT: what we're really trying to do here is confirm that the selection is // all in one string property. We could readily have a method in the selection interface to tell us that. sel.TextSelInfo(false, out tssA, out ichA, out fAssocPrev, out hvoObjA, out tagA, out ws); if (tagA != m_taTagName) { return(false); // selection not anchored in a type-ahead name property. } sel.TextSelInfo(true, out tssE, out ichE, out fAssocPrev, out hvoObjE, out tagE, out ws); int cch = tssA.Length; // To do our type-ahead trick, both ends of the seleciton must be in the same string property. // Also, we want the selection to extend to the end of the name. // Enhance JohnT: poupu list may not depend on selection extending to end. if (tagE != m_taTagName || hvoObjE != hvoObjA || cch != tssE.Length || Math.Max(ichA, ichE) != cch) { return(false); // not going to attempt type-ahead behavior } // if the key pressed is a backspace or del, prevent smart completion, // otherwise we are likely to put back what the user deleted. // Review JohnT: do arrow keys come through here? What do we do if so? int charT = Convert.ToInt32(e.KeyChar); if (charT == (int)Keys.Back || charT == (int)Keys.Delete) { return(false); // normal key handling will just delete selection. // Review: should backspace delete one more? } // OK, we're in a type-ahead situation. First step is to let normal editing take place. ehelp.OnKeyPress(e, modifiers); e.Handled = true; // Now see what we have. Note that our old selection is no longer valid. sel = rootb.Selection; if (sel == null) { return(true); // can't be smart, but we already did the keypress. } int cvsli = sel.CLevels(false); // CLevels includes the string prop itself, but AllTextSelInfo does not need it. cvsli--; // Get selection information to determine where the user is typing. int ihvoObj; int tagTextProp; int cpropPrevious, ichAnchor, ichEnd, ihvoEnd; ITsTextProps ttp; SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli, out ihvoObj, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd, out ws, out fAssocPrev, out ihvoEnd, out ttp); if (tagTextProp != m_taTagName || ichAnchor != ichEnd || ihvoEnd != -1 || cvsli < 1) { return(true); // something bizarre happened, but keypress is done. } int hvoLeaf = rgvsli[0].hvo; // Get the parent object we will modify. // (This would usually work, but not if the parent object is the root of the whole display, // as in a simple atomic ref type ahead slice. //int hvoParent = rgvsli[1].hvo; // object whose reference property we are setting.) int tagParent, cpropPreviousDummy, ihvo; IVwPropertyStore vps; int hvoParent; sel.PropInfo(false, 1, out hvoParent, out tagParent, out ihvo, out cpropPreviousDummy, out vps); if (hvoParent != m_hvoParent) { return(true); // another bizarre unexpected event. } // This is what the name looks like after the keypress. ITsString tssTyped = m_sda.get_StringProp(hvoLeaf, m_taTagName); // Get the substitute. This is where the actual type-ahead behavior happens. Sets hvoNewRef to 0 if no match. ICmObject objNewRef; ITsString tssLookup = Lookup(tssTyped, out objNewRef); int hvoNewRef = (objNewRef != null) ? objNewRef.Hvo : 0; IVwCacheDa cda = m_sda as IVwCacheDa; if (hvoNewRef == 0 && tssTyped.Length > 0) { // No match...underline string in red squiggle. ITsStrBldr bldr = tssLookup.GetBldr(); bldr.SetIntPropValues(0, tssLookup.Length, (int)FwTextPropType.ktptUnderline, (int)FwTextPropVar.ktpvEnum, (int)FwUnderlineType.kuntSquiggle); bldr.SetIntPropValues(0, tssLookup.Length, (int)FwTextPropType.ktptUnderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Red)); tssLookup = bldr.GetString(); } // Don't rely on sel from here on. if (hvoNewRef != hvoLeaf) { m_hvoTa = hvoNewRef; // Before we replace in the prop, so it gets displayed using special ta prop. switch (m_type) { case CellarPropertyType.ReferenceAtomic: if (m_hvoParent != 0) // I think it always is, except when loss of focus during debugging causes problems. { // If nothing matched, set the real property to null and the fake one to kbaseFakeObj. // Otherwise set both to the indicated object. m_sda.SetObjProp(m_hvoParent, m_tag, hvoNewRef); // Review: do we want to set the real thing yet? m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_tag, 0, 1, 1); if (hvoNewRef == 0) { hvoNewRef = m_hvoTa = kBaseFakeObj; // use in fake so we can display something. } cda.CacheObjProp(m_hvoParent, m_virtualTagObj, hvoNewRef); // Change the fake property m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_virtualTagObj, 0, 1, 1); } break; case CellarPropertyType.ReferenceSequence: case CellarPropertyType.ReferenceCollection: // Several cases, depending on whether we got a match and whether hvoLeaf is the dummy object // 1. match on dummy: insert appropriate real object, change dummy name to empty. // 2. match on non-dummy: replace old object with new // 3: non-match: do nothing. (Even if not looking at the fake object, we'll go on using the // actual object as a base for the fake name, since it's displayed only for the active position.) if (hvoNewRef == 0) { break; // case 3 } if (hvoLeaf == kBaseFakeObj) { // case 1 // The fake object goes back to being an empty name at the end of the list. ITsStrBldr bldr = tssLookup.GetBldr(); bldr.ReplaceTsString(0, bldr.Length, null); // makes an empty string in correct ws. cda.CacheStringProp(kBaseFakeObj, m_taTagName, bldr.GetString()); // Insert the new object before the fake one in fake prop and at end of real seq. // Include the fake object in the replace to get it redisplayed also. cda.CacheReplace(m_hvoParent, m_virtualTagObj, m_ihvoTa, m_ihvoTa + 1, new int[] { hvoNewRef, kBaseFakeObj }, 2); m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_virtualTagObj, m_ihvoTa, 2, 1); m_sda.Replace(m_hvoParent, m_tag, m_ihvoTa, m_ihvoTa, new int[] { hvoNewRef }, 1); m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_tag, m_ihvoTa, 1, 0); } else { // case 2 // Replace the object being edited with the indicated one in both props. cda.CacheReplace(m_hvoParent, m_virtualTagObj, m_ihvoTa, m_ihvoTa + 1, new int[] { hvoNewRef }, 1); m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_virtualTagObj, m_ihvoTa, 1, 1); m_sda.Replace(m_hvoParent, m_tag, m_ihvoTa, m_ihvoTa + 1, new int[] { hvoNewRef }, 1); m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_tag, m_ihvoTa, 1, 1); } break; default: throw new Exception("unsupported property type for type-ahead chooser"); } } cda.CacheStringProp(hvoNewRef, m_taTagName, tssLookup); m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvoNewRef, m_taTagName, 0, tssLookup.Length, tssTyped.Length); // Make a new selection, typically the range that is the bit added to the typed string. // no change is needed to rgvsli because it's the same object index in the same property of the same parent. sel = rootb.MakeTextSelection(ihvoObj, cvsli, rgvsli, m_taTagName, cpropPrevious, ichAnchor, tssLookup.Length, ws, true, -1, null, true); return(true); }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; base.Dispose(disposing); if (disposing) { if (components != null) { components.Dispose(); } if (m_PhoneEnvReferenceVc != null) m_PhoneEnvReferenceVc.Dispose(); } m_validator = null; // TODO: Make m_validator disposable? m_realEnvs.Clear(); m_realEnvs = null; m_rootObj = null; if (m_tsf != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(m_tsf); m_tsf = null; m_silCache = null; if (m_vwCache != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(m_vwCache); m_vwCache = null; m_PhoneEnvReferenceVc = null; }
public RootSiteDataProviderViewBase(ISilDataAccess sda, int hvoRoot) { m_sda = sda; VwCache = sda as IVwCacheDa; m_hvoRoot = hvoRoot; // We don't actually want to show it, but we need to force the view to create the root // box and lay it out so that various test stuff can happen properly. Width = 300; Height = 307 - 25; }
/// <summary> /// Load the information about the lexical relations that link to hvoEntry. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry"></param> /// <param name="relsOut"></param> /// <param name="cdaTemp"></param> /// <param name="owner"></param> /// <returns>false if the entry has no associated lexical relations, or none of them are linked to any other entries.</returns> static private bool LoadLexicalRelationInfo(FdoCache cache, int hvoEntry, out int[] relsOut, IVwCacheDa cdaTemp, IWin32Window owner) { string sql1 = string.Format("SELECT DISTINCT tar2.Src, lrt.MappingType, tar.Ord, cn.Txt, cn.Ws, rev.Txt, rev.Ws" + " FROM LexReference_Targets tar" + " LEFT OUTER JOIN LexReference_Targets tar2 ON tar2.Src=tar.Src AND EXISTS (SELECT * FROM CmObject other WHERE other.Id=tar2.Dst AND other.Id != tar.Dst)" + " LEFT OUTER JOIN LexRefType_Members mem ON mem.Dst=tar2.Src" + " LEFT OUTER JOIN LexRefType lrt ON lrt.Id=mem.Src" + " LEFT OUTER JOIN CmPossibility_Name cn ON cn.Obj=mem.Src AND cn.Ws IN ({0}, {1})" + " LEFT OUTER JOIN LexRefType_ReverseName rev ON rev.Obj=mem.Src AND rev.Ws IN ({0}, {1})" + " WHERE tar.Dst = {2} OR tar.Dst IN (SELECT Id FROM fnGetOwnedIds({2}, {3}, {4}))", cache.DefaultVernWs, cache.DefaultAnalWs, hvoEntry, (int)LexEntry.LexEntryTags.kflidSenses, (int)LexSense.LexSenseTags.kflidSenses); IOleDbCommand odc = DbOps.MakeRowSet(cache, sql1, null); bool fGotLexRef = false; // true if we found a lexical relation for the entry or one of its senses try { bool fMoreRows; List<int> rels = new List<int>(); for (odc.NextRow(out fMoreRows); fMoreRows; odc.NextRow(out fMoreRows)) { fGotLexRef = true; int hvoLexRef = DbOps.ReadInt(odc, 0); if (hvoLexRef == 0) continue; // null row. if (!((ISilDataAccess)cdaTemp).get_IsPropInCache(hvoLexRef, RelatedWordsVc.ktagName, (int)CellarModuleDefns.kcptString, 0)) { int type = DbOps.ReadInt(odc, 1); int ord = DbOps.ReadInt(odc, 2); ITsString tssName = DbOps.ReadTss2(odc, 3); ITsString tssRevName = DbOps.ReadTss2(odc, 5); if (type == (int)LexRefType.MappingTypes.kmtEntryAsymmetricPair || type == (int)LexRefType.MappingTypes.kmtEntryOrSenseAsymmetricPair || type == (int)LexRefType.MappingTypes.kmtSenseAsymmetricPair) { if (ord != 0 && tssRevName != null && tssRevName.Length > 0) tssName = tssRevName; } else if (type == (int)LexRefType.MappingTypes.kmtEntryTree || type == (int)LexRefType.MappingTypes.kmtEntryOrSenseTree || type == (int)LexRefType.MappingTypes.kmtSenseTree) { if (ord != 0 && tssRevName != null && tssRevName.Length > 0) tssName = tssRevName; } cdaTemp.CacheStringProp(hvoLexRef, RelatedWordsVc.ktagName, tssName); rels.Add(hvoLexRef); } } relsOut = DbOps.ListToIntArray(rels); } finally { DbOps.ShutdownODC(ref odc); } return fGotLexRef; }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { // Must not be run more than once. if (IsDisposed) return; if (disposing) { // Cleanup managed stuff here. if (m_cacheDa != null) m_cacheDa.ClearAllData(); } // Cleanup unmanaged stuff here. m_dataAccess = null; if (m_cacheDa != null) { if (Marshal.IsComObject(m_cacheDa)) Marshal.ReleaseComObject(m_cacheDa); m_cacheDa = null; } m_owner = null; // It will get disposed on its own, if it hasn't been already. m_vc = null; base.Dispose(disposing); }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; if( disposing ) { if(components != null) { components.Dispose(); } if (m_view != null && !Controls.Contains(m_view)) m_view.Dispose(); if (m_detailView != null && !Controls.Contains(m_detailView)) m_detailView.Dispose(); } m_sel = null; m_cache = null; m_view = null; m_detailView = null; if (m_cdaTemp != null) { m_cdaTemp.ClearAllData(); Marshal.ReleaseComObject(m_cdaTemp); m_cdaTemp = null; } base.Dispose( disposing ); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Selections the changed. /// </summary> /// <param name="prootb">The prootb.</param> /// <param name="sel">The sel.</param> /// ------------------------------------------------------------------------------------ public override void SelectionChanged(IVwRootBox prootb, IVwSelection sel) { CheckDisposed(); if (m_fInChangeSelectedObjects) { return; } m_fInChangeSelectedObjects = true; try { int cvsli = 0; // Out variables for AllTextSelInfo. int ihvoRoot = 0; int tagTextProp = 0; int cpropPrevious = 0; int ichAnchor = 0; int ichEnd = 0; int ws = 0; bool fAssocPrev = false; int ihvoEnd = 0; ITsTextProps ttpBogus = null; SelLevInfo[] rgvsli = new SelLevInfo[0]; List <int> newSelectedObjects = new List <int>(4); newSelectedObjects.Add(XmlVc.FocusHvo); if (sel != null) { cvsli = sel.CLevels(false) - 1; // Main array of information retrived from sel that made combo. rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli, out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd, out ws, out fAssocPrev, out ihvoEnd, out ttpBogus); for (int i = 0; i < cvsli; i++) { newSelectedObjects.Add(rgvsli[i].hvo); } } ISilDataAccess sda = Cache.MainCacheAccessor; IVwCacheDa cda = Cache.VwCacheDaAccessor; foreach (int hvo in m_selectedObjects) { if (!newSelectedObjects.Contains(hvo)) { cda.CacheIntProp(hvo, m_xmlVc.IsObjectSelectedTag, 0); sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvo, m_xmlVc.IsObjectSelectedTag, 0, 1, 1); } } foreach (int hvo in newSelectedObjects) { if (!m_selectedObjects.Contains(hvo)) { cda.CacheIntProp(hvo, m_xmlVc.IsObjectSelectedTag, 1); sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvo, m_xmlVc.IsObjectSelectedTag, 0, 1, 1); } } m_selectedObjects = newSelectedObjects; if (sel != null && !sel.IsValid) { // we wiped it out by regenerating parts of the display in our PropChanged calls! Restore it if we can. sel = m_rootb.MakeTextSelection(ihvoRoot, cvsli, rgvsli, tagTextProp, cpropPrevious, ichAnchor, ichEnd, ws, fAssocPrev, ihvoEnd, ttpBogus, true); } } finally { m_fInChangeSelectedObjects = false; } base.SelectionChanged(prootb, sel); }
/// <summary> /// Load the information about the domains of hvoEntry. Returns false /// if the entry has no associated domains or none of them are linked to any other entries. /// </summary> /// <param name="cache"></param> /// <param name="hvoEntry"></param> /// <param name="domains"></param> /// <param name="cdaTemp"></param> /// <param name="fMoreRows"></param> /// <param name="owner"></param> /// <returns></returns> static private bool LoadDomainInfo(FdoCache cache, int hvoEntry, out int[] domainsOut, out IVwCacheDa cdaTemp, IWin32Window owner) { // This produces first the Semantic domains of the senses of the entry, // then restricts to those that occur on some other entry, // then looks up the vernacular (or, if none, analysis) name of the domains. The are sorted by // domain name. // We do left outer joins for the last two so we can distinguish the failure // modes "no SDs on senses of initial entry" versus "no other entries in those SDs" string sql1 = string.Format("select lssd2.dst, cn.txt, cn.ws from LexEntry le" + " join LexSense_ ls on ls.owner$ = le.id" + " join LexSense_SemanticDomains lssd on lssd.src = ls.id " + " left outer join LexSense_SemanticDomains lssd2 on lssd2.dst = lssd.dst" + " and exists (select * from CmObject lsother" + " join LexEntry leother on leother.id = lsother.owner$ and lsother.id = lssd2.src and leother.id != le.id)" + " left outer join CmPossibility_Name cn on lssd2.dst = cn.obj and cn.ws" + " in ({0}, {1}) where le.id = {2}" + " group by lssd2.dst, cn.txt, cn.ws" + " order by cn.txt", cache.DefaultVernWs, cache.DefaultAnalWs, hvoEntry); IOleDbCommand odc = DbOps.MakeRowSet(cache, sql1, null); bool fGotSrcDomain = false; // true if we found a semantic domain on some sense of the source entry try { bool fMoreRows; List<int> domains = new List<int>(); cdaTemp = VwCacheDaClass.Create(); for (odc.NextRow(out fMoreRows); fMoreRows; odc.NextRow(out fMoreRows)) { fGotSrcDomain = true; // any row indicates success here. int hvoDomain = DbOps.ReadInt(odc, 0); if (hvoDomain == 0) continue; // null row, an SD that occurs on no other entry. if (!((ISilDataAccess)cdaTemp).get_IsPropInCache(hvoDomain, RelatedWordsVc.ktagName, (int)CellarModuleDefns.kcptString, 0)) { ITsString tss = DbOps.ReadTss2(odc, 1); if (tss == null) { tss = FDO.Cellar.CmPossibility.BestAnalysisOrVernName(cache, hvoDomain); } cdaTemp.CacheStringProp(hvoDomain, RelatedWordsVc.ktagName, tss); domains.Add(hvoDomain); } } domainsOut = DbOps.ListToIntArray(domains); } finally { DbOps.ShutdownODC(ref odc); } return fGotSrcDomain; }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { // Must not be run more than once. if (IsDisposed) return; base.Dispose(disposing); if (disposing) { // Dispose managed resources here. if (m_cd != null) { m_cd.ClearAllData(); if (Marshal.IsComObject(m_cd)) Marshal.ReleaseComObject(m_cd); } } // Dispose unmanaged resources here, whether disposing is true or false. m_svc = null; m_sda = null; m_cd = null; }