Exemple #1
0
        public void StringProp_EmptyString()
        {
            // Test StringProp
            ITsString tsStringNew = m_ISilDataAccess.get_StringProp(1118, 2228);

            Assert.AreEqual(0, tsStringNew.Length);
        }
Exemple #2
0
        public void StringProp()
        {
            CheckDisposed();
            // Test StringProp
            ITsString tsStringNew = m_ISilDataAccess.get_StringProp(1118, 2228);

            Assert.AreEqual(0, tsStringNew.Length);
            Assert.IsFalse(m_ISilDataAccess.IsDirty());

            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();
            ITsStrBldr   strBldr   = TsStrBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse");
            strBldr.Replace(0, 0, "StringPropTest", propsBldr.GetTextProps());
            ITsString tsString = strBldr.GetString();

            m_ISilDataAccess.SetString(1118, 2228, tsString);
            tsStringNew = m_ISilDataAccess.get_StringProp(1118, 2228);
            Assert.AreEqual(tsString, tsStringNew);
            Assert.IsTrue(m_ISilDataAccess.IsDirty());

            strBldr.Replace(0, 0, "Second", propsBldr.GetTextProps());
            tsString = strBldr.GetString();
            m_ISilDataAccess.SetString(1118, 2228, tsString);
            tsStringNew = m_ISilDataAccess.get_StringProp(1118, 2228);
            Assert.AreEqual(tsString, tsStringNew);
            Assert.IsTrue(m_ISilDataAccess.IsDirty());

            CheckProp(1118, 2228, tsString, CellarModuleDefns.kcptString);
        }
Exemple #3
0
            /// <summary>
            /// This constructor looks up the headword of the slice to get the key length.
            /// </summary>
            public ParaNodeInfo(int flidList, int[] startOffsets, ISilDataAccess sda, int hvoHeadObj, int flid)
            {
                m_flidList = flidList;
                ITsString str = sda.get_StringProp(hvoHeadObj, flid);

                m_keyLength    = str.Length;
                m_startOffsets = startOffsets;
            }
Exemple #4
0
        /// <summary>
        /// Receives a notification that the selection in the root box has changed.
        ///
        /// </summary>
        /// <param name="rootb"></param>
        /// <param name="sel"></param>
        public void SelectionChanged(IVwRootBox rootb, IVwSelection sel)
        {
            CheckDisposed();

            if (m_fInSelectionChanged)
            {
                return;
            }
            try
            {
                m_fInSelectionChanged = true;                 // suppress recursive calls.
                int hvoParent;
                int ihvo;
                int hvoSel = SelectedObject(rootb, sel, out hvoParent, out ihvo);
                if (hvoSel == m_hvoTa && hvoParent == m_hvoParent)
                {
                    return;
                }
                int hvoTaOld = m_hvoTa;
                m_hvoTa = hvoSel;                 // must change before PropChange converting old one back.
                if (hvoTaOld != 0)
                {
                    // Convert current object back to normal name. We replace the object with itself (without actually changing anything)
                    // to force a redisplay, with different results because it is no longer the current object.
                    m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_virtualTagObj, m_ihvoTa, 1, 1);
                }
                if (hvoSel != 0)
                {
                    ParentObject = hvoParent;
                    m_ihvoTa     = ihvo;
                    // Ensure the initial tag name matches the real one.
                    (m_sda as IVwCacheDa).CacheStringProp(hvoSel, m_taTagName, m_sda.get_StringProp(hvoSel, m_snTagName));
                    SwitchTagAndFixSel(m_taTagName, rootb);
                }
                else
                {
                    ParentObject = m_ihvoTa = 0;
                }
            }
            finally
            {
                m_fInSelectionChanged = false;
            }
        }
        /// <summary>
        /// Insert breaks for the text in the indicated range of the indicate StTxtPara
        /// </summary>
        /// <param name="ichMin"></param>
        /// <param name="ichLim"></param>
        /// <param name="hvoPara"></param>
        public void Guess(int ichMin, int ichLim1, int hvoPara)
        {
            Setup(hvoPara);
            ITsString  tss    = m_sda.get_StringProp(hvoPara, (int)StTxtPara.StTxtParaTags.kflidContents);
            ITsStrBldr bldr   = tss.GetBldr();
            int        ichLim = ichLim1;

            if (ichLim1 == -1)
            {
                ichLim = tss.Length;
            }
            string txt    = tss.Text;
            int    offset = 0;                         // offset in tsb caused by previously introduced spaces.

            for (int ichStart = 0; ichStart < ichLim;) // no advance! decide inside loop.
            {
                int cch = Match(ichStart, ichLim, txt);
                if (cch < 0)
                {
                    // no match
                    ichStart++;
                }
                else
                {
                    // match, ensure spaces.

                    if (ichStart > 0 && !SpaceAt(bldr, ichStart + offset - 1))
                    {
                        InsertSpace(bldr, ichStart + offset);
                        offset++;
                    }
                    if (ichStart + cch < ichLim && !SpaceAt(bldr, ichStart + cch + offset))
                    {
                        InsertSpace(bldr, ichStart + cch + offset);
                        offset++;
                    }
                    ichStart += cch;
                }
            }
            if (offset > 0)
            {
                m_sda.SetString(hvoPara, (int)StTxtPara.StTxtParaTags.kflidContents, bldr.GetString());
                m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvoPara,
                                  (int)StTxtPara.StTxtParaTags.kflidContents, 0, 0, 0);
            }
        }
Exemple #6
0
			/// <summary>
			/// This constructor looks up the headword of the slice to get the key length.
			/// </summary>
			public ParaNodeInfo(int flidList, int[] startOffsets, ISilDataAccess sda, int hvoHeadObj, int flid)
			{
				m_flidList = flidList;
				ITsString str = sda.get_StringProp(hvoHeadObj, flid);
				m_keyLength = str.Length;
				m_startOffsets = startOffsets;
			}
Exemple #7
0
        public void LoadData()
        {
            // Get the language project as an FDO object
            ILangProject lp = m_fdoCache.LangProject;

            // Use it to get the HVO of the data notebook, but without making an FDO object
            // and thus loading data.
            Assert.IsTrue(m_sda.get_IsPropInCache(lp.Hvo,
                                                  (int)LangProject.LangProjectTags.kflidResearchNotebook,
                                                  (int)CellarModuleDefns.kcptOwningAtom, 0),
                          "LP notebook loaded by FDO");
            int hvoNotebook = m_fdoCache.GetObjProperty(lp.Hvo,
                                                        (int)LangProject.LangProjectTags.kflidResearchNotebook);

            Assert.IsFalse(m_sda.get_IsPropInCache(hvoNotebook,
                                                   (int)RnResearchNbk.RnResearchNbkTags.kflidRecords,
                                                   (int)CellarModuleDefns.kcptOwningCollection, 0),
                           "Nb records not loaded");
            // Do a simple pre-load to get the records.
            IVwDataSpec dts = VwDataSpecClass.Create();

            // Request loading the title of each record. (Note that currently we must make
            // an entry for each concrete class; making one for the base class does not work.)
            dts.AddField(RnAnalysis.kClassId,
                         (int)RnGenericRec.RnGenericRecTags.kflidTitle,
                         FldType.kftString,
                         m_fdoCache.LanguageWritingSystemFactoryAccessor,
                         0);
            dts.AddField(RnEvent.kClassId,
                         (int)RnGenericRec.RnGenericRecTags.kflidTitle,
                         FldType.kftString,
                         m_fdoCache.LanguageWritingSystemFactoryAccessor,
                         0);
            int[] clsids = new int[1];
            clsids[0] = RnResearchNbk.kClassId;
            int[] hvos = new int[1];
            hvos[0] = hvoNotebook;
            m_da.LoadData(hvos, clsids, hvos.Length, dts, null, true);
            Assert.IsTrue(m_sda.get_IsPropInCache(hvoNotebook,
                                                  (int)RnResearchNbk.RnResearchNbkTags.kflidRecords,
                                                  (int)CellarModuleDefns.kcptOwningCollection, 0),
                          "Nb records are loaded");
            int chvoRecs = m_sda.get_VecSize(hvoNotebook,
                                             (int)RnResearchNbk.RnResearchNbkTags.kflidRecords);

            // Be careful what we assert...don't want it too dependent on the exact data.
            // Should be OK to assume at least a few records.
            Assert.IsTrue(chvoRecs > 4, "at least 4 recs");
            int hvoRec3 = m_sda.get_VecItem(hvoNotebook,
                                            (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, 3);

            Assert.IsTrue(m_sda.get_IsPropInCache(hvoRec3,
                                                  (int)RnGenericRec.RnGenericRecTags.kflidTitle,
                                                  (int)CellarModuleDefns.kcptString, 0),
                          "Got title of rec 3");
            ITsString qtssRec3Title = m_sda.get_StringProp(hvoRec3,
                                                           (int)RnGenericRec.RnGenericRecTags.kflidTitle);
            // Now get the info through FDO
            ICmObject objRec3 = CmObject.CreateFromDBObject(m_fdoCache, hvoRec3);

            Assert.IsTrue(objRec3 is IRnGenericRec, "object of correct type");
            IRnGenericRec grRec3 = (IRnGenericRec)objRec3;

            // I'd prefer to use full ITsString equality test, but not sure how to get
            // a regular ITsString from FDO obj.
            Assert.AreEqual(qtssRec3Title.Text, grRec3.Title.Text,
                            "two ways to retrieve R3 title match");
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="hvo"></param>
 /// <param name="tag"></param>
 /// <returns></returns>
 public ITsString get_StringProp(int hvo, int tag)
 {
     return(m_sda.get_StringProp(hvo, tag));
 }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the flids for basic data (bool, string, int, etc.)
        /// </summary>
        /// <param name="thisFlid">The object type flid.</param>
        /// <param name="flidType">The owning flid type.</param>
        /// <param name="hvoSrc">The hvo of the source object.</param>
        /// <param name="hvoNew">The hvo of the new object.</param>
        /// ------------------------------------------------------------------------------------
        private void HandleBasicOrStringFlid(int thisFlid, int flidType, int hvoSrc, int hvoNew)
        {
            // Basic and String properties are copied
            switch (flidType)
            {
            // Basic Properties follow

            case (int)CellarPropertyType.Binary:
                string flidName = m_mdc.GetFieldName(thisFlid);
                if (flidName == "Rules" || flidName == "StyleRules")
                {
                    CopyBinaryAsTextProps(thisFlid, hvoSrc, hvoNew);
                }
                else
                {
                    CopyBinaryAsBinary(thisFlid, hvoSrc, hvoNew);
                }
                break;

            case (int)CellarPropertyType.Boolean:
                // Copy boolean value
                m_sda.SetBoolean(hvoNew, thisFlid, m_sda.get_BooleanProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.Guid:
                // Copy guid value
                // These are currently used as the ID for an application, or a version number, or a Scripture Check ID)
                m_sda.SetGuid(hvoNew, thisFlid, m_sda.get_GuidProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.GenDate:                     // Fall through, since a GenDate is an int.
            case (int)CellarPropertyType.Integer:
                // Copy integer value
                m_sda.SetInt(hvoNew, thisFlid, m_sda.get_IntProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.Time:
                // Copy time value
                m_sda.SetTime(hvoNew, thisFlid, m_sda.get_TimeProp(hvoSrc, thisFlid));
                break;

            // String Properties follow

            case (int)CellarPropertyType.String:
                // Copy string value
                // Review: Please check these next three!
                m_sda.SetString(hvoNew, thisFlid, m_sda.get_StringProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.Unicode:
                // Copy Unicode string
                m_sda.set_UnicodeProp(hvoNew, thisFlid, m_sda.get_UnicodeProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.MultiString:                     // Fall through
            case (int)CellarPropertyType.MultiUnicode:
                ITsMultiString sMulti = m_sda.get_MultiStringProp(hvoSrc, thisFlid);
                for (int i = 0; i < sMulti.StringCount; i++)
                {
                    int       ws;
                    ITsString tss = sMulti.GetStringFromIndex(i, out ws);
                    m_sda.SetMultiStringAlt(hvoNew, thisFlid, ws, tss);
                }
                break;

            default:
                throw new FDOInvalidFieldTypeException(String.Format("CopyObject: Unsupported field type {0}.", flidType));
            }
        }
Exemple #10
0
		internal static string[] AddStringFromOtherObj(XmlNode frag, int hvoTarget, FdoCache cache, ISilDataAccess sda)
		{
			int flid = XmlVc.GetFlid(frag, hvoTarget, sda);
			ITsStrFactory tsf = cache.TsStrFactory;
			CellarPropertyType itype = (CellarPropertyType)sda.MetaDataCache.GetFieldType(flid);
			if (itype == CellarPropertyType.Unicode)
			{
				return new[] { sda.get_UnicodeProp(hvoTarget, flid) };
			}
			else if (itype == CellarPropertyType.String)
			{
				return new[] { sda.get_StringProp(hvoTarget, flid).Text };
			}
			else // multistring of some type
			{
				int wsid = 0;
				string sep = "";
				if (s_cwsMulti > 1)
				{
					string sLabelWs = XmlUtils.GetOptionalAttributeValue(frag, "ws");
					if (sLabelWs != null && sLabelWs == "current")
					{
						sep = DisplayMultiSep(frag)
							+ DisplayWsLabel(s_qwsCurrent, cache);
						wsid = s_qwsCurrent.Handle;
					}
				}
				if (wsid == 0)
					wsid = WritingSystemServices.GetWritingSystem(cache,
						frag, null, WritingSystemServices.kwsAnal).Handle;
				if (itype == CellarPropertyType.MultiUnicode)
				{
					return new[] { sep, sda.get_MultiStringAlt(hvoTarget, flid, wsid).Text };
				}
				else
				{
					return new[] { sep, sda.get_MultiStringAlt(hvoTarget, flid, wsid).Text };
				}
			}
		}
Exemple #11
0
 /// <summary>
 /// Read a (nonmultilingual) string property.
 /// an empty string, writing system 0, if property not found.
 ///</summary>
 /// <param name='hvo'> </param>
 /// <param name='tag'> </param>
 /// <returns></returns>
 public virtual ITsString get_StringProp(int hvo, int tag)
 {
     return(m_baseSda.get_StringProp(hvo, tag));
 }