Пример #1
0
        private void CreateVirtualProperties()
        {
            m_virtualName = m_fieldName + "_" + "TypeAhead";
            IVwCacheDa        cda = m_sda as IVwCacheDa;
            IVwVirtualHandler vh  = cda.GetVirtualHandlerName(m_className, m_virtualName);

            if (vh == null)
            {
                // Need to create virtual property.
                switch (m_type)
                {
                case (int)CellarModuleDefns.kcptReferenceAtom:
                    vh           = new TypeAheadAtomVh(m_tag);
                    vh.ClassName = m_className;
                    vh.FieldName = m_virtualName;
                    vh.Type      = m_type;
                    cda.InstallVirtual(vh);
                    break;

                case (int)CellarModuleDefns.kcptReferenceSequence:
                case (int)CellarModuleDefns.kcptReferenceCollection:
                    vh           = new TypeAheadSeqVh(m_tag);
                    vh.ClassName = m_className;
                    vh.FieldName = m_virtualName;
                    vh.Type      = (int)CellarModuleDefns.kcptReferenceSequence;
                    cda.InstallVirtual(vh);
                    break;

                default:
                    throw new Exception("unsupported property type for type-ahead chooser");
                }
            }
            m_virtualTagObj = vh.Tag;

            // Make the virtual handler for type-ahead names if it doesn't already exist.
            vh = cda.GetVirtualHandlerName("CmObject", kstrTaName);
            if (vh == null)
            {
                vh           = new TypeAheadShortNameStringVh(m_cache);
                vh.ClassName = m_className;
                vh.FieldName = kstrTaName;
                vh.Type      = (int)CellarModuleDefns.kcptString;
                cda.InstallVirtual(vh);
            }
            m_taTagName = vh.Tag;
            // And the general-purpose Shortname one.
            vh = cda.GetVirtualHandlerName("CmObject", kstrSnName);
            if (vh == null)
            {
                vh           = new TypeAheadShortNameStringVh(m_cache);
                vh.ClassName = m_className;
                vh.FieldName = kstrSnName;
                vh.Type      = (int)CellarModuleDefns.kcptString;
                cda.InstallVirtual(vh);
            }
            m_snTagName = vh.Tag;
        }
Пример #2
0
        private void AddEditCell(IVwEnv vwenv, IVwCacheDa cda, int i)
        {
            string  sField = ksEditColumnBaseName + i;
            XmlNode node   = m_columns[i - 1] as XmlNode;

            // Make a cell and embed an editable virtual string for the column.
            vwenv.OpenTableCell(1, 1);
            // Initialize the virtual property.
            IVwVirtualHandler vh = cda.GetVirtualHandlerName(EditRowModelClass, sField);

            Debug.Assert(vh != null);
            int flid = (int)m_mdc.GetFieldId(EditRowModelClass, sField, false);
            int ws   = LangProject.GetWritingSystem(node, m_cache, null, m_cache.DefaultAnalWs);

            // 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);

            vh.Load(khvoNewItem, flid, ws, cda);
            // Fill in the cell with the virtual property.
            vwenv.OpenParagraph();
            vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
                                  (int)FwTextPropVar.ktpvEnum,
                                  (int)TptEditable.ktptIsEditable);
            vwenv.AddStringAltMember(flid, ws, this);
            vwenv.CloseParagraph();
            vwenv.CloseTableCell();
        }
Пример #3
0
 protected virtual void ReallyDeleteReversalIndex(IReversalIndex ri)
 {
     try
     {
         Debug.Assert(ri.Hvo == m_list.OwningObject.Hvo);
         m_list.ListModificationInProgress = true;                       // can't reload deleted list! (LT-5353)
         // Clear out any virtual data stored in the cache for this reversal index.
         IVwCacheDa        cda = m_cache.MainCacheAccessor as IVwCacheDa;
         IVwVirtualHandler vh  = cda.GetVirtualHandlerName("LexSense",
                                                           LexSenseReversalEntriesTextHandler.StandardFieldName);
         if (vh != null)
         {
             int wsDel = ri.WritingSystemRAHvo;
             IEnumerator <IReversalIndexEntry> erie = ri.EntriesOC.GetEnumerator();
             while (erie.MoveNext())
             {
                 foreach (LinkedObjectInfo loi in erie.Current.BackReferences)
                 {
                     if (loi.RelObjClass == (int)LexSense.kClassId)
                     {
                         vh.Load(loi.RelObjId, vh.Tag, wsDel, cda);
                     }
                 }
             }
         }
         m_cache.BeginUndoTask(LexEdStrings.ksUndoDelete, LexEdStrings.ksRedoDelete);
         int cobjOld = m_cache.LangProject.LexDbOA.ReversalIndexesOC.Count;
         ri.DeleteUnderlyingObject();
         int cobjNew;
         int hvoIdxNew = ReversalIndexAfterDeletion(m_cache, out cobjNew);
         m_cache.EndUndoTask();
         SetReversalIndexHvo(hvoIdxNew);
         // Without this, switching to the ReversalEntries tool can crash if it was
         // displaying data from the deleted reversal entry.
         m_cache.PropChanged(null, PropChangeType.kpctNotifyAll,
                             m_cache.LangProject.LexDbOAHvo,
                             (int)LexDb.LexDbTags.kflidReversalIndexes,
                             0, cobjNew, cobjOld);
     }
     finally
     {
         m_list.ListModificationInProgress = false;
     }
     // Can't do this until ListModificationInProgress flag is cleared because it
     // redisplays everything after reloading the list: if the list isn't actually
     // reloaded, it tries to display a deleted object -- CRASH!
     ChangeOwningObjectIfPossible();
     // Without this, stale data can still display in the BulkEditSenses tool if you
     // recreate the deleted reversal index.
     m_mediator.SendMessage("MasterRefresh", null);
 }
Пример #4
0
        /// <summary>
        /// Override method to add suitable control.
        /// </summary>
        public override void FinishInit()
        {
            CheckDisposed();
            Debug.Assert(m_cache != null);
            Debug.Assert(m_configurationNode != null);

            string     className = m_cache.MetaDataCacheAccessor.GetClassName((uint)m_obj.ClassID);
            string     fieldName = XmlUtils.GetManditoryAttributeValue(m_configurationNode, "field");
            IVwCacheDa cda       = m_cache.VwCacheDaAccessor;

            m_vh = cda.GetVirtualHandlerName(className, fieldName) as BaseLexReferencesVirtualHandler;
            Debug.Assert(m_vh != null, "We should have a virtual handler installed for " +
                         className + "." + fieldName);

            base.FinishInit();
        }
Пример #5
0
        /// <summary>
        /// Looks for a node called "virtuals" and under it collects nodes of type "virtual",
        /// each having at least "modelclass", "virtualfield", "assemblyPath", and "class".
        /// Here 'class' is the name of the C# class that implements the VH, while 'modelclass'
        /// is the name of the virtual property. The node is passed to the VH as a constructor
        /// argument, so other attributes may be required.
        /// </summary>
        /// <returns>the list of installed virtual handlers</returns>
        public static List <IVwVirtualHandler> InstallVirtuals(XmlNode virtualsNode, FdoCache cache, bool okToFail)
        {
            List <IVwVirtualHandler> installedHandlers = new List <IVwVirtualHandler>();

            foreach (XmlNode virtualNode in virtualsNode.SelectNodes("virtual"))
            {
                IVwCacheDa        cda = cache.MainCacheAccessor as IVwCacheDa;
                IVwVirtualHandler vh  = cda.GetVirtualHandlerName(
                    XmlUtils.GetManditoryAttributeValue(virtualNode, "modelclass"),
                    XmlUtils.GetManditoryAttributeValue(virtualNode, "virtualfield"));
                if (vh != null && vh is BaseVirtualHandler)
                {
                    // already exists, hope it's the same one. Make sure its cache is valid.
                    (vh as BaseVirtualHandler).Reinitialize(virtualNode, cache);
                    installedHandlers.Add(vh);
                    continue;
                }

                try
                {
                    vh = (IVwVirtualHandler)DynamicLoader.CreateObject(
                        virtualNode.SelectSingleNode("dynamicloaderinfo"),
                        new object[] { virtualNode, cache });
                }
                catch (Exception err)
                {
                    if (!okToFail)
                    {
                        throw err;
                    }
                    // Otherwise we're in some special test situation or really just want the IText ones
                    // and we ignore the problem.
                    continue;
                }
                try
                {
                    cda.InstallVirtual(vh);
                }
                catch (Exception err)
                {
                    Debug.WriteLine(err.Message);
                    throw err;
                }
                installedHandlers.Add(vh);
            }
            return(installedHandlers);
        }
Пример #6
0
            public override void MakeRoot()
            {
                CheckDisposed();

                base.MakeRoot();

                if (DesignMode)
                {
                    return;
                }

                m_fdoCache.CreateDummyID(out m_hvoRoot);
                // Pretend it is of our expected destination class. Very few things should care about this,
                // but it allows IsValidObject to return true for it, which is important when reconstructing
                // the root box, as happens during Refresh.
                m_fdoCache.VwCacheDaAccessor.CacheIntProp(m_hvoRoot,
                                                          (int)CmObjectFields.kflidCmObject_Class, (int)m_clidDst);

                // Review JohnT: why doesn't the base class do this??
                m_rootb = VwRootBoxClass.Create();
                m_rootb.SetSite(this);

                m_sda = m_fdoCache.MainCacheAccessor;
                IVwCacheDa cda = m_sda as IVwCacheDa;

                IVwVirtualHandler vh = cda.GetVirtualHandlerName(GhostStringVirtualHandler.GhostClassName,
                                                                 GhostStringVirtualHandler.FieldNameForWs(m_wsToCreate));

                if (vh == null)
                {
                    vh = new GhostStringVirtualHandler(m_wsToCreate);
                    cda.InstallVirtual(vh);
                }
                m_flidGhost        = vh.Tag;
                m_rootb.DataAccess = m_sda;

                m_vc = new GhostStringSliceVc(m_flidGhost);

                // arg3 is a meaningless initial fragment, since this VC only displays one thing.
                m_rootb.SetRootObject(m_hvoRoot, m_vc, 1, m_styleSheet);
            }
Пример #7
0
        /// <summary>
        /// This will install a virtual handler for getting and setting temporary strings in each column.
        /// </summary>
        private void InstallVirtualHandlersForColumns()
        {
            // handle editableRow attributes
            Debug.Assert(m_xbv != null);
            FdoCache cache = m_xbv.Cache;

            Debug.Assert(cache != null);
            IVwCacheDa cda = cache.MainCacheAccessor as IVwCacheDa;

            // install a handler for each column
            for (int i = 1; i <= m_columns.Count; ++i)
            {
                string            sField = ksEditColumnBaseName + i;
                IVwVirtualHandler vh     = cda.GetVirtualHandlerName(
                    EditRowModelClass, sField);
                if (vh == null)
                {
                    MultiStringVirtualHandler msvh =
                        new MultiStringVirtualHandler(EditRowModelClass, sField);
                    cda.InstallVirtual(msvh);
                }
            }
        }
Пример #8
0
		private void AddEditCell(IVwEnv vwenv, IVwCacheDa cda, int i)
		{
			string sField = ksEditColumnBaseName + i;
			XmlNode node = m_columns[i - 1] as XmlNode;
			// Make a cell and embed an editable virtual string for the column.
			vwenv.OpenTableCell(1, 1);
			// Initialize the virtual property.
			IVwVirtualHandler vh = cda.GetVirtualHandlerName(EditRowModelClass, sField);
			Debug.Assert(vh != null);
			int flid = (int)m_mdc.GetFieldId(EditRowModelClass, sField, false);
			int ws = LangProject.GetWritingSystem(node, m_cache, null, m_cache.DefaultAnalWs);

			// 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);

			vh.Load(khvoNewItem, flid, ws, cda);
			// Fill in the cell with the virtual property.
			vwenv.OpenParagraph();
			vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
				(int)FwTextPropVar.ktpvEnum,
				(int)TptEditable.ktptIsEditable);
			vwenv.AddStringAltMember(flid, ws, this);
			vwenv.CloseParagraph();
			vwenv.CloseTableCell();
		}
Пример #9
0
		/// <summary>
		/// Return the VirtualHandler for the supplied cache, creating it if needed.
		/// </summary>
		/// <param name="cda"></param>
		/// <returns></returns>
		public static ObjectSelectedVirtualHandler InstallHandler(IVwCacheDa cda)
		{
			ObjectSelectedVirtualHandler vh = (ObjectSelectedVirtualHandler)cda.GetVirtualHandlerName(className, fieldName);
			if (vh == null)
			{
				vh = new ObjectSelectedVirtualHandler();
				vh.Type = (int)CellarModuleDefns.kcptInteger;
				vh.ClassName = className;
				vh.FieldName = fieldName;
				cda.InstallVirtual(vh);
			}
			return vh;
		}
Пример #10
0
		/// <summary>
		/// Return the MeVirtualHandler for the supplied cache, creating it if needed.
		/// </summary>
		/// <param name="cda"></param>
		/// <param name="className">name of class to define prop for</param>
		/// <param name="fieldName">field name for virtual prop</param>
		/// <param name="cpt">type of property, from CellarModuleDefns</param>
		/// <returns></returns>
		public static DummyVirtualHandler InstallDummyHandler(IVwCacheDa cda, string className, string fieldName, int cpt)
		{
			DummyVirtualHandler vh = (DummyVirtualHandler)cda.GetVirtualHandlerName(className, fieldName);
			if (vh == null)
			{
				vh = new DummyVirtualHandler();
				vh.Type = cpt;
				vh.ClassName = className;
				vh.FieldName = fieldName;
				cda.InstallVirtual(vh);
			}
			return vh;
		}
Пример #11
0
		/// <summary>
		/// Return the MeVirtualHandler for the supplied cache, creating it if needed.
		/// </summary>
		/// <param name="cda"></param>
		/// <returns></returns>
		public static MeVirtualHandler InstallMe(IVwCacheDa cda)
		{
			MeVirtualHandler vh = (MeVirtualHandler)cda.GetVirtualHandlerName("CmObject", "Me");
			if (vh == null)
			{
				vh = new MeVirtualHandler();
				cda.InstallVirtual(vh);
			}
			return vh;
		}