コード例 #1
0
        public void MultiStringAlt()
        {
            CheckDisposed();
            ITsString tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7);

            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, "Test", propsBldr.GetTextProps());
            ITsString tsString = strBldr.GetString();

            m_ISilDataAccess.SetMultiStringAlt(1117, 2227, 7, tsString);
            tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7);
            Assert.AreEqual(tsString, tsStringNew);
            Assert.IsTrue(m_ISilDataAccess.IsDirty());

            strBldr.Replace(0, 0, "SecondTest", propsBldr.GetTextProps());
            tsString = strBldr.GetString();
            m_ISilDataAccess.SetMultiStringAlt(1117, 2227, 7, tsString);
            tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7);
            Assert.AreEqual(tsString, tsStringNew);
            Assert.IsTrue(m_ISilDataAccess.IsDirty());

            tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 8);
            Assert.AreEqual(0, tsStringNew.Length);
            Assert.IsTrue(m_ISilDataAccess.IsDirty());

            CheckProp(1117, 2227, tsString, CellarModuleDefns.kcptMultiString);
        }
コード例 #2
0
ファイル: ViewSampleView.cs プロジェクト: vkarthim/FieldWorks
        /// <summary>
        /// This is a demonstration of one way to handle special tricks as the user types.
        /// This is an oversimplified way of forcing numbers to be treated as verse numbers...
        /// for example, it will cause '5000' in the 'feeding of the 5000' to be treated as a verse number.
        /// </summary>
        /// <param name="vwselNew"></param>
        protected override void HandleSelectionChange(IVwSelection vwselNew)
        {
            base.HandleSelectionChange(vwselNew);
            if (vwselNew == null)
            {
                return;                 // Not sure whether this happens, but best to be sure.
            }
            int       ichSel, hvoObj, tag, ws;
            bool      fAssocPrev;
            ITsString tss;

            vwselNew.TextSelInfo(false, out tss, out ichSel, out fAssocPrev, out hvoObj, out tag, out ws);

            string text = tss.get_Text();

            if (text == null)
            {
                return;                 // empty string.
            }
            ITsStrBldr tsb = null;

            for (int ich = 0; ich < text.Length; ++ich)
            {
                if (Char.IsDigit(text[ich]))
                {
                    ITsTextProps ttp       = tss.get_PropertiesAt(ich);
                    string       styleName = ttp.GetStrPropValue((int)FwKernelLib.FwTextPropType.ktptNamedStyle);
                    if (styleName != "verseNumber")
                    {
                        // We'll change just this one character. We could make this more efficient for dealing with
                        // long strings of digits, but it's unlikely we'll ever have to deal with more than one.
                        if (tsb == null)
                        {
                            tsb = tss.GetBldr();
                        }
                        tsb.SetStrPropValue(ich, ich + 1, (int)FwKernelLib.FwTextPropType.ktptNamedStyle, "verseNumber");
                    }
                }
            }
            if (tsb != null)
            {
                ISilDataAccess sda = m_rootb.get_DataAccess();
                // In this sample the only string is a multistring. If in doubt, we could test for ws == 0 to
                // see whether it is a simple string.
                sda.SetMultiStringAlt(hvoObj, tag, ws, tsb.GetString());
                sda.PropChanged(null, (int)FwViews.PropChangeType.kpctNotifyAll, hvoObj, tag, 0, tss.get_Length(), tss.get_Length());
            }
        }
コード例 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="hvo"></param>
 /// <param name="tag"></param>
 /// <param name="ws"></param>
 /// <param name="_tss"></param>
 public void SetMultiStringAlt(int hvo, int tag, int ws, ITsString _tss)
 {
     VerifyUpdate(hvo, tag);
     m_sda.SetMultiStringAlt(hvo, tag, ws, _tss);
 }
コード例 #4
0
            int MakeRealObject(ITsString tssTyped)
            {
                // Figure whether owning atomic or owning collection or owning sequence. Throw if none.
                // Unless we're making an unowned IText for a Notebook Record.
                ISilDataAccess     sdaReal    = m_fdoCache.DomainDataByFlid;
                IFwMetaDataCache   mdc        = sdaReal.MetaDataCache;
                CellarPropertyType typeOwning =
                    (CellarPropertyType)(mdc.GetFieldType(m_flidEmptyProp) & (int)CellarPropertyTypeFilter.VirtualMask);
                // Make a new object of the specified class in the specified property.
                int ord = 0;

                switch (typeOwning)
                {
                default:
                    if (m_flidEmptyProp != RnGenericRecTags.kflidText)
                    {
                        throw new Exception("ghost string property must be owning object property");
                    }
                    break;

                case CellarPropertyType.OwningAtomic:
                    ord = -2;
                    break;

                case CellarPropertyType.OwningCollection:
                    ord = -1;
                    break;

                case CellarPropertyType.OwningSequence:
                    // ord = 0 set above (inserting the first and only object at position 0).
                    break;
                }
                string sClassRaw    = mdc.GetClassName(m_clidDst);
                string sClass       = m_mediator.StringTbl.GetString(sClassRaw, "ClassNames");
                string sUndo        = String.Format(DetailControlsStrings.ksUndoCreate0, sClass);
                string sRedo        = String.Format(DetailControlsStrings.ksRedoCreate0, sClass);
                int    hvoNewObj    = 0;
                int    hvoStringObj = 0;

                UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(sUndo, sRedo, m_fdoCache.ServiceLocator.GetInstance <IActionHandler>(), () =>
                {
                    // Special case: if we just created a Text in RnGenericRecord, and we want to show the contents
                    // of an StTxtPara, make the intermediate objects
                    if (m_flidEmptyProp == RnGenericRecTags.kflidText)
                    {
                        var servLoc     = Cache.ServiceLocator;
                        var text        = servLoc.GetInstance <ITextFactory>().Create();
                        var stText      = servLoc.GetInstance <IStTextFactory>().Create();
                        text.ContentsOA = stText;
                        var para        = servLoc.GetInstance <IStTxtParaFactory>().Create();
                        stText.ParagraphsOS.Add(para);
                        hvoNewObj    = text.Hvo;
                        hvoStringObj = para.Hvo;
                        // Set the RnGenericRec's Text property to reference the new text
                        sdaReal.SetObjProp(m_hvoObj, m_flidEmptyProp, hvoNewObj);
                    }
                    else
                    {
                        hvoNewObj = hvoStringObj = sdaReal.MakeNewObject(m_clidDst, m_hvoObj, m_flidEmptyProp, ord);
                    }

                    // Set its property m_flidStringProp to tssTyped. If it is multilingual, choose based on ghostWs.
                    var typeString = (CellarPropertyType)(mdc.GetFieldType(m_flidStringProp) &
                                                          (int)CellarPropertyTypeFilter.VirtualMask);
                    switch (typeString)
                    {
                    default:
                        throw new Exception("ghost property must store strings!");

                    case CellarPropertyType.MultiString:
                    case CellarPropertyType.MultiUnicode:
                        sdaReal.SetMultiStringAlt(hvoStringObj, m_flidStringProp, m_wsToCreate, tssTyped);
                        break;

                    case CellarPropertyType.String:
                        sdaReal.SetString(hvoStringObj, m_flidStringProp, tssTyped);
                        break;
                    }

                    string ghostInitMethod = XmlUtils.GetOptionalAttributeValue(m_nodeObjProp, "ghostInitMethod");
                    if (ghostInitMethod != null)
                    {
                        var obj      = m_fdoCache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(hvoNewObj);
                        Type objType = obj.GetType();
                        System.Reflection.MethodInfo mi = objType.GetMethod(ghostInitMethod);
                        mi.Invoke(obj, null);
                    }
                });
                return(hvoNewObj);
            }
コード例 #5
0
        /// ------------------------------------------------------------------------------------
        /// <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));
            }
        }
コード例 #6
0
 internal void SetValue(int ws, ITsString tss)
 {
     m_sda.SetMultiStringAlt(khvoRoot, kflid, ws, tss);
 }
コード例 #7
0
 /// <summary>
 /// Change one alternative of a multilingual string property of an object.
 /// The caller should also call PropChanged to notify interested parties,
 /// except where the change is being made to a newly created object.
 ///</summary>
 /// <param name='hvo'> </param>
 /// <param name='tag'> </param>
 /// <param name='ws'> </param>
 /// <param name='_tss'> </param>
 public virtual void SetMultiStringAlt(int hvo, int tag, int ws, ITsString _tss)
 {
     m_baseSda.SetMultiStringAlt(hvo, tag, ws, _tss);
 }
コード例 #8
0
            int MakeRealObject(ITsString tssTyped)
            {
                // Figure whether owning atomic or owning collection or owning sequence. Throw if none.
                IFwMetaDataCache mdc   = m_fdoCache.MetaDataCacheAccessor;
                FieldType        iType = m_fdoCache.GetFieldType(m_flidEmptyProp);

                iType &= FieldType.kcptVirtualMask;
                ISilDataAccess sdaReal = m_fdoCache.MainCacheAccessor;
                // Make a new object of the specified class in the specified property.
                int ord = 0;

                switch (iType)
                {
                default:
                    throw new Exception("ghost string property must be owning object property");

                case FieldType.kcptOwningAtom:
                    ord = -2;
                    break;

                case FieldType.kcptOwningCollection:
                    ord = -1;
                    break;

                case FieldType.kcptOwningSequence:
                    // ord = 0 set above (inserting the first and only object at position 0).
                    break;
                }
                string sClassRaw = mdc.GetClassName((uint)m_clidDst);
                string sClass    = m_mediator.StringTbl.GetString(sClassRaw, "ClassNames");
                string sUndo     = String.Format(DetailControlsStrings.ksUndoCreate0, sClass);
                string sRedo     = String.Format(DetailControlsStrings.ksRedoCreate0, sClass);

                sdaReal.BeginUndoTask(sUndo, sRedo);
                int hvoNewObj = sdaReal.MakeNewObject((int)m_clidDst, m_hvoObj, m_flidEmptyProp, ord);
                // Set its property m_flidStringProp to tssTyped. If it is multilingual, choose based on ghostWs.
                FieldType iTypeString = m_fdoCache.GetFieldType(m_flidStringProp);

                iTypeString &= FieldType.kcptVirtualMask;
                switch (iTypeString)
                {
                default:
                    throw new Exception("ghost property must store strings!");

                case FieldType.kcptMultiString:
                case FieldType.kcptMultiBigString:
                case FieldType.kcptMultiUnicode:
                case FieldType.kcptMultiBigUnicode:
                    sdaReal.SetMultiStringAlt(hvoNewObj, m_flidStringProp, m_wsToCreate, tssTyped);
                    break;

                case FieldType.kcptString:
                case FieldType.kcptBigString:
                    sdaReal.SetString(hvoNewObj, m_flidStringProp, tssTyped);
                    break;
                }

                string ghostInitMethod = XmlUtils.GetOptionalAttributeValue(m_nodeObjProp, "ghostInitMethod");

                if (ghostInitMethod != null)
                {
                    ICmObject obj     = CmObject.CreateFromDBObject(m_fdoCache, hvoNewObj);
                    Type      objType = obj.GetType();
                    System.Reflection.MethodInfo mi = objType.GetMethod(ghostInitMethod);
                    mi.Invoke(obj, null);
                }
                // Issue PropChanged for the addition of the new object. (could destroy this).
                sdaReal.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoObj, m_flidEmptyProp, 0, 1, 0);
                sdaReal.EndUndoTask();
                return(hvoNewObj);
            }