Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the CellValueNeeded event of the gridInspector control.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void OnCellValueNeeded(DataGridViewCellValueEventArgs e)
        {
            e.Value = null;
            base.OnCellValueNeeded(e);

            if (e.Value != null || m_list == null || m_list.Count <= e.RowIndex)
            {
                return;
            }

            IInspectorObject io = m_list[e.RowIndex];

            if (io == null)
            {
                e.Value = "null";
            }
            else
            {
                if (e.ColumnIndex == 0)
                {
                    e.Value = io.DisplayName;
                }
                else if (e.ColumnIndex == 1)
                {
                    e.Value = io.DisplayValue;
                }
                else
                {
                    e.Value = io.DisplayType;
                }
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the Click event of the m_tsbShowObjInNewWnd control.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void m_tsbShowObjInNewWnd_Click(object sender, EventArgs e)
        {
            InspectorWnd wnd = m_dockPanel.ActiveContent as InspectorWnd;

            if (wnd == null)
            {
                return;
            }

            IInspectorObject io = wnd.CurrentInspectorObject;

            if (io == null || io.Object == null)
            {
                return;
            }

            string text = io.DisplayName;

            if (text.StartsWith("[") && text.EndsWith("]"))
            {
                text = text.Trim('[', ']');
                int i;
                if (int.TryParse(text, out i))
                {
                    text = null;
                }
            }

            if (text != null && text != io.DisplayType)
            {
                text += (": " + io.DisplayType);
            }

            m_InspectorWnd = ShowNewInspectorWindow(io.Object, text);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the Opening event of the grid's context menu.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected virtual void HandleOpenObjectInNewWindowContextMenuClick(object sender, CancelEventArgs e)
        {
            InspectorWnd wnd = m_dockPanel.ActiveContent as InspectorWnd;

            if (wnd != null)
            {
                IInspectorObject io = wnd.CurrentInspectorObject;
                cmnuShowInNewWindow.Enabled = (io != null && io.Object != null);
            }
        }
Example #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.DataGridView.CellClick"/> event.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void OnCellClick(DataGridViewCellEventArgs e)
        {
            base.OnCellClick(e);

            if (e.ColumnIndex != 0)
            {
                return;
            }

            IInspectorObject io        = m_list[e.RowIndex];
            Rectangle        rc        = GetCellDisplayRectangle(0, e.RowIndex, true);
            Rectangle        rcHotSpot = GetExpandCollapseRect(rc, io.Level);

            if (rcHotSpot.Contains(PointToClient(MousePosition)))
            {
                ToggleExpand(e.RowIndex);
            }
        }
Example #5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create the reference collectiomn list for ther custom reference collection.,
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected virtual List<IInspectorObject> GetInspectorObjectsForCustomRC(object obj, IInspectorObject ioParent, int level)
		{
			List<IInspectorObject> list = new List<IInspectorObject>();
			int n = 0;
			int hvoNum = 0;
			;
			if (obj == null)
				return null;

			// Inspectors for custom reference collections are supposed to be configured with
			// obj being an array of the HVOs.
			var collection = obj as ICollection;

			if (collection == null)
			{
				MessageBox.Show("Custom Reference collection not properly configured with array of HVOs");
				return null;
			}
			// Just like an ordinary reference collection, we want to make one inspector for each
			// item in the collection, where the first argument to CreateInspectorObject is the
			// cmObject. Keep this code in sync with BaseGetInspectorObjects.
			foreach (int hvoItem in collection)
			{
				hvoNum = Int32.Parse(hvoItem.ToString());
				var objItem = m_cache.ServiceLocator.GetObject(hvoNum);
					IInspectorObject io = CreateInspectorObject(objItem, obj, ioParent, level);
					io.DisplayName = string.Format("[{0}]", n++);
					list.Add(io);
			}
			return list;
		}
Example #6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Condenses the 'Run' information for MultiUnicodeAccessor entries because
		/// there will only be 1 run,
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected virtual List<IInspectorObject> GetInspectorObjectsForUniRuns(ITsString obj, IInspectorObject ioParent, int level)
		{
			List<IInspectorObject> list = new List<IInspectorObject>();

			if (obj != null)
			{
				IInspectorObject ino = CreateInspectorObject(obj, ioParent.OwningObject, ioParent, level);

				ino.DisplayName = "Writing System";
				ino.DisplayValue = obj.get_WritingSystemAt(0).ToString();
				ino.HasChildren = false;
				list.Add(ino);

				TsStringRunInfo tss = new TsStringRunInfo(0, obj, m_cache);

				ino = CreateInspectorObject(tss, obj, ioParent, level);

				ino.DisplayName = "Text";
				ino.DisplayValue = tss.Text;
				ino.HasChildren = false;
				list.Add(ino);
			}
			return list;
		}
Example #7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets a list of IInspectorObject objects representing all the properties for the
		/// specified object, which is assumed to be at the specified level.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected virtual List<IInspectorObject> GetInspectorObjectsForValues(object obj, IInspectorObject ioParent, int level)
		{
			if (ioParent != null)
				obj = ioParent.Object;

			List<IInspectorObject> list = new List<IInspectorObject>();

			IMultiAccessorBase multiStr = ioParent.OwningObject as IMultiAccessorBase;
			if (multiStr != null)
			{
				foreach (int ws in multiStr.AvailableWritingSystemIds)
				{
					IWritingSystem wsObj = m_cache.ServiceLocator.WritingSystemManager.Get(ws);
					IInspectorObject ino = CreateInspectorObject(multiStr.get_String(ws), obj, ioParent, level);
					ino.DisplayName = wsObj.DisplayLabel;
					list.Add(ino);
				}
				return list;
			}

			PropertyInfo[] props = GetPropsForObj(obj);
			foreach (PropertyInfo pi in props)
			{
				try
				{
					object propObj = pi.GetValue(obj, null);
					list.Add(CreateInspectorObject(pi, propObj, obj, ioParent, level));
				}
				catch (Exception e)
				{
					list.Add(CreateExceptionInspectorObject(e, obj, pi.Name, level, ioParent));
				}
			}

			list.Sort(CompareInspectorObjectNames);
			return list;
		}
Example #8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the inspector objects for the specified TextProps.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private List<IInspectorObject> GetInspectorObjectsForTextProps(TextProps txp,
			IInspectorObject ioParent, int level)
		{
			int saveIntPropCount = 0, saveStrPropCount = 0;

			//IInspectorObject ioParent = txp as IInspectorObject;
			if (ioParent != null)
				txp = ioParent.Object as TextProps;

			List<IInspectorObject> list = new List<IInspectorObject>();
			IInspectorObject io;
			ICollection txp1 = txp as ICollection;

			if (txp1 != null)
			{
				int i = 0;
				foreach (object item in txp1)
				{
					io = CreateInspectorObject(item, txp, ioParent, level);
					io.DisplayName = string.Format("[{0}]", i++);
					list.Add(io);
				}

				return list;
			}

			PropertyInfo[] props = GetPropsForObj(txp);
			foreach (PropertyInfo pi in props)
			{
				if (pi.Name != "IntProps" && pi.Name != "StrProps" && pi.Name != "IntPropCount" && pi.Name != "StrPropCount")
					continue;
				else
					switch (pi.Name)
					{
						case "IntProps":
							object propObj = pi.GetValue(txp, null);
							io = CreateInspectorObject(pi, propObj, txp, ioParent, level);
							io.DisplayValue = "Count = " + saveIntPropCount.ToString();
							io.HasChildren = (saveIntPropCount > 0);
							list.Add(io);
							break;
						case "StrProps":
							object propObj1 = pi.GetValue(txp, null);
							io = CreateInspectorObject(pi, propObj1, txp, ioParent, level);
							io.DisplayValue = "Count = " + saveStrPropCount.ToString();
							io.HasChildren = (saveStrPropCount > 0);
							list.Add(io);
							break;
						case "StrPropCount":
							saveStrPropCount = (int)pi.GetValue(txp, null);
							break;
						case "IntPropCount":
							saveIntPropCount = (int)pi.GetValue(txp, null);
							break;
					}
			}

			list.Sort(CompareInspectorObjectNames);
			return list;
		}
Example #9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the inspector objects for the specified TsString.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private List<IInspectorObject> GetInspectorObjectsForTsString(ITsString tss,
			IInspectorObject ioParent, int level)
		{
			List<IInspectorObject> list = new List<IInspectorObject>();

			int runCount = tss.RunCount;

			List<TsStringRunInfo> tssriList = new List<TsStringRunInfo>();
			for (int i = 0; i < runCount; i++)
				tssriList.Add(new TsStringRunInfo(i, tss, m_cache));

			IInspectorObject io = CreateInspectorObject(tssriList, tss, ioParent, level);

			io.DisplayName = "Runs";
			io.DisplayValue = FormatCountString(tssriList.Count);
			io.HasChildren = (tssriList.Count > 0);
			list.Add(io);

			if (ObjectBrowser.m_virtualFlag == true)
			{
				io = CreateInspectorObject(tss.Length, tss, ioParent, level);

				io.DisplayName = "Length";
				list.Add(io);

				io = CreateInspectorObject(tss.Text, tss, ioParent, level);

				io.DisplayName = "Text";
				list.Add(io);
			}

			return list;
		}
Example #10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the CellPainting event of the dataGridView1 control.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
        {
            base.OnCellPainting(e);

            if (e.Handled || e.RowIndex < 0 || e.ColumnIndex < 0 || m_list == null ||
                m_list.Count == 0 || m_list[e.RowIndex] == null)
            {
                return;
            }

            e.Handled = true;

            // Paint everything but the focus rectangle, foreground and background.
            // I'm not sure what's left, but just in case...
            DataGridViewPaintParts parts = e.PaintParts;

            parts &= ~DataGridViewPaintParts.Focus;
            parts &= ~DataGridViewPaintParts.Background;
            parts &= ~DataGridViewPaintParts.ContentForeground;
            e.Paint(e.CellBounds, parts);
            e.PaintBackground(e.CellBounds, false);

            IInspectorObject io             = m_list[e.RowIndex];
            Rectangle        rcText         = e.CellBounds;
            Rectangle        rcHotSpot      = Rectangle.Empty;
            bool             isSelected     = ((e.State & DataGridViewElementStates.Selected) > 0);
            bool             isInBlock      = (!isSelected && e.RowIndex >= m_firstRowInShadind && e.RowIndex <= m_lastRowInShading);
            bool             isIndentedCell = (e.ColumnIndex == 0);

            if (isIndentedCell)
            {
                // Calculate the location and size of the rectangle into which text will be drawn.
                // Adjust the text rectangle to account for the +/- image and the proper indent level.
                rcHotSpot = GetExpandCollapseRect(e.CellBounds, io.Level);
                int dx = ((rcHotSpot.Right - rcText.X) + 5);
                rcText.X     += dx;
                rcText.Width -= dx;
            }

            // Draw the background color for the cell.
            using (SolidBrush br = new SolidBrush(DefaultCellStyle.BackColor))
            {
                if (isSelected)
                {
                    br.Color = DefaultCellStyle.SelectionBackColor;
                }
                else if (isInBlock && m_clrShading != Color.Empty)
                {
                    br.Color = m_clrShading;
                }

                e.Graphics.FillRectangle(br, rcText);
            }

            Color           clrFore = (isSelected ? e.CellStyle.SelectionForeColor : e.CellStyle.ForeColor);
            TextFormatFlags flags   = TextFormatFlags.Left | TextFormatFlags.VerticalCenter |
                                      TextFormatFlags.EndEllipsis | TextFormatFlags.SingleLine;

            TextRenderer.DrawText(e.Graphics, e.FormattedValue as string,
                                  e.CellStyle.Font, rcText, clrFore, flags);

            DrawBorders(e, isIndentedCell,
                        (isInBlock && m_clrShading != Color.Empty ? m_clrShading : GridColor),
                        (isInBlock ? rcText.X: rcHotSpot.X));

            if (!isIndentedCell)
            {
                return;
            }

            DrawTreeLines(e, rcHotSpot, io.Level);

            if (io.HasChildren)
            {
                // Draw the expand or collapse (+/-) image.
                e.Graphics.DrawImage(m_list.IsExpanded(e.RowIndex) ?
                                     Properties.Resources.kimidCollapse : Properties.Resources.kimidExpand, rcHotSpot);
            }
        }
Example #11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Process lines that have a DateTime type.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private List<IInspectorObject> GetInspectorObjectForDateTime(DateTime tmpObj,
			IInspectorObject ioParent, int level)
		{
			List<IInspectorObject> list = new List<IInspectorObject>();

			IInspectorObject io = CreateInspectorObject(tmpObj, null, ioParent, level);
			//io.DisplayName = tmpObj.;
			//io.DisplayValue = FormatCountString(allStrings.Count);
			io.HasChildren = false;
			list.Add(io);

			return list;
		}
Example #12
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the inspector objects for the specified repository object;
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private List<IInspectorObject> GetInspectorObjectsForRepository(object obj,
			IInspectorObject ioParent, int level)
		{
			int i = 0;
			List<IInspectorObject> list = new List<IInspectorObject>();
			foreach (object instance in GetRepositoryInstances(obj))
			{
				IInspectorObject io = CreateInspectorObject(instance, obj, ioParent, level);

				if (ObjectBrowser.m_virtualFlag == false && obj.ToString().IndexOf("LexSenseRepository") > 0)
				{
					ILexSense tmpObj = io.Object as ILexSense;
					io.DisplayValue = tmpObj.FullReferenceName.Text;
					io.DisplayName = string.Format("[{0}]: {1}", i++, GetObjectOnly(tmpObj.ToString()));
				}
				else if (ObjectBrowser.m_virtualFlag == false && obj.ToString().IndexOf("LexEntryRepository") > 0 )
				{
					ILexEntry tmpObj = io.Object as ILexEntry;
					io.DisplayValue = tmpObj.HeadWord.Text;
					io.DisplayName = string.Format("[{0}]: {1}", i++, GetObjectOnly(tmpObj.ToString()));
				}
				else
					io.DisplayName = string.Format("[{0}]", i++);

				list.Add(io);
			}

			i = IndexOf(obj);
			if (i >= 0)
			{
				this[i].DisplayValue = FormatCountString(list.Count);
				this[i].HasChildren = (list.Count > 0);
			}

			return list;
		}
Example #13
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Refreshes the view.
        /// This overload specifies the type of action that triggered this method.
        /// This is needed because the key changes during adds, updates, and moves.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void RefreshView(string type)
        {
            int mFirstDisplayIndex = 0, mCurrentDisplayIndex = 0;

            // Get the object that's displayed in the first visible row of the grid.
            mFirstDisplayIndex = gridInspector.FirstDisplayedScrollingRowIndex;

            // Get the current, selected row in the grid.
            IInspectorObject currSelectedObj = gridInspector.CurrentObject;

            // If type is "Up", "Down", or "Delete", use parent as the selected/current row.
            // If so, then save a reference to the selected object's parent object.
            if (type == "Up" || type == "Down" || type == "Delete" && (currSelectedObj != null))
            {
                currSelectedObj = currSelectedObj.ParentInspectorObject;
            }

            if (currSelectedObj != null)
            {
                for (int i = 0; i < m_list.Count; i++)
                {
                    if (m_list[i].Key == currSelectedObj.Key)
                    {
                        mCurrentDisplayIndex = i;
                        break;
                    }
                }
            }


            // Save all the expanded objects.
            List <int> expandedObjects = new List <int>();

            for (int i = 0; i < m_list.Count; i++)
            {
                if (m_list.IsExpanded(i))
                {
                    expandedObjects.Add(i);
                }
            }
            if (type == "Add")
            {
                expandedObjects.Add(mCurrentDisplayIndex);
            }

            m_list.Initialize(m_list.TopLevelObject);

            // Now that the list is rebuilt, go through the list of objects that
            // were previously expanded and expand them again.
            int firstRow = 0;
            int currRow  = 0;
            int irow     = 0;

            for (irow = 0; irow < m_list.Count; irow++)
            {
                IInspectorObject io = m_list[irow];
                int index           = expandedObjects.IndexOf(irow);
                if (index >= 0)
                {
                    m_list.ExpandObject(irow);
                    expandedObjects.RemoveAt(index);
                }

                if (irow == mFirstDisplayIndex)
                {
                    firstRow = irow;
                }

                if (irow == mCurrentDisplayIndex)
                {
                    currRow = irow;
                }
            }

            gridInspector.SuspendLayout();
            gridInspector.List = m_list;
            gridInspector.FirstDisplayedScrollingRowIndex = firstRow;
            gridInspector.CurrentCell = gridInspector[0, currRow];
            gridInspector.ResumeLayout();
        }
Example #14
0
        ///// ------------------------------------------------------------------------------------
        ///// <summary>
        ///// Handles the KeyPress event of the tstxtSearch control.
        ///// </summary>
        ///// <param name="sender">The source of the event.</param>
        ///// <param name="e">The <see cref="System.Windows.Forms.KeyPressEventArgs"/> instance containing the event data.</param>
        ///// ------------------------------------------------------------------------------------
        //private void tstxtSearch_KeyPress(object sender, KeyPressEventArgs e)
        //{
        //    if (e.KeyChar != (char)Keys.Enter)
        //        return;

        //    Guid guid = new Guid(tstxtSearch.Text.Trim());
        //    int i = m_list.GotoGuid(guid);
        //    if (i >= 0)
        //    {
        //        gridInspector.RowCount = m_list.Count;
        //        gridInspector.Invalidate();
        //        gridInspector.CurrentCell = gridInspector[0, i];
        //    }
        //}

        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Refreshes the view.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void RefreshView()
        {
            // Get the object that's displayed in the first visible row of the grid.
            IInspectorObject firstDisplayedObj =
                m_list[gridInspector.FirstDisplayedScrollingRowIndex];

            // Get the current, selected row in the grid.
            IInspectorObject currSelectedObj = gridInspector.CurrentObject;

            if (currSelectedObj != null && WillObjDisappearOnRefresh != null)
            {
                // Check if the selected object will disappear after refreshing the grid.
                // If so, then save a reference to the selected object's parent object.
                if (WillObjDisappearOnRefresh(this, currSelectedObj))
                {
                    currSelectedObj = m_list.GetParent(gridInspector.CurrentCellAddress.Y);
                }
            }

            int keyFirstDisplayedObj = (firstDisplayedObj != null ? firstDisplayedObj.Key : -1);
            int keyCurrSelectedObj   = (currSelectedObj != null ? currSelectedObj.Key : -1);

            // Save all the expanded objects.
            List <int> expandedObjects = new List <int>();

            for (int i = 0; i < m_list.Count; i++)
            {
                if (m_list.IsExpanded(i))
                {
                    expandedObjects.Add(m_list[i].Key);
                }
            }

            m_list.Initialize(m_list.TopLevelObject);

            // Now that the list is rebuilt, go through the list of objects that
            // were previously expanded and expand them again.
            int firstRow = 0;
            int currRow  = 0;
            int irow     = 0;

            while (++irow < m_list.Count)
            {
                IInspectorObject io = m_list[irow];
                int key             = io.Key;
                int index           = expandedObjects.IndexOf(key);
                if (index >= 0)
                {
                    m_list.ExpandObject(irow);
                    expandedObjects.RemoveAt(index);
                }

                if (key == keyFirstDisplayedObj)
                {
                    firstRow = irow;
                }

                if (key == keyCurrSelectedObj)
                {
                    currRow = irow;
                }
            }

            gridInspector.SuspendLayout();
            gridInspector.List = m_list;
            gridInspector.FirstDisplayedScrollingRowIndex = firstRow;
            gridInspector.CurrentCell = gridInspector[0, currRow];
            gridInspector.ResumeLayout();
        }
Example #15
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create InspectorObjects for the custom fields for the current object.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private IInspectorObject CreateCustomInspectorObject(object obj, IInspectorObject ParentIo,
								 int level, CustomFields cf)
		{
			ICmObject to = obj as ICmObject;
			var mdc = m_cache.ServiceLocator.GetInstance<IFwMetaDataCacheManaged>();
			ICmPossibility fColl = null;
			int mws = 0;
			var iValue = "";
			string className = mdc.GetClassName(cf.ClassID);
			int Flid = cf.FieldID;
			IInspectorObject io = null;
			if (obj != null)
			{
				switch (cf.Type)
				{
					case "ITsString":
						ITsString oValue = m_cache.DomainDataByFlid.get_StringProp(to.Hvo, Flid);
						io = base.CreateInspectorObject(null, oValue, obj, ParentIo, level);
						iValue = oValue.Text;
						io.HasChildren = false;
						io.DisplayName = cf.Name;
						break;
					case "System.Int32":
						int sValue = m_cache.DomainDataByFlid.get_IntProp(to.Hvo, Flid);
						io = base.CreateInspectorObject(null, sValue, obj, ParentIo, level);
						iValue = sValue.ToString();
						io.HasChildren = false;
						io.DisplayName = cf.Name;
						break;
					case "SIL.FieldWorks.Common.FwUtils.GenDate":
						// tried get_TimeProp, get_UnknowbProp, get_Prop
						GenDate genObj = ((ISilDataAccessManaged)m_cache.DomainDataByFlid).get_GenDateProp(to.Hvo, Flid);
						io = base.CreateInspectorObject(null, genObj, obj, ParentIo, level);
						iValue = genObj.ToString();
						io.HasChildren = true;
						io.DisplayName = cf.Name;
						break;
					case "FdoReferenceCollection<ICmPossibility>":	// ReferenceCollection
						int count = m_cache.DomainDataByFlid.get_VecSize(to.Hvo, Flid);
						iValue = "Count = " + count.ToString();
						var objects = ((ISilDataAccessManaged) m_cache.DomainDataByFlid).VecProp(to.Hvo, Flid);
						objects.Initialize();
						//int rcHvo = m_cache.DomainDataByFlid.get_ObjectProp(to.Hvo, Flid);
						//IFdoReferenceCollection<ICmPossibility> RCObj = (rcHvo == 0? null: (IFdoReferenceCollection<ICmPossibility>)m_cache.ServiceLocator.GetObject(rcHvo));
						io = base.CreateInspectorObject(null, objects, obj, ParentIo, level);
						io.HasChildren = (count > 0? true: false);
						io.DisplayName = cf.Name+ "RC";
						break;
					case "ICmPossibility":	// ReferenceAtomic
						int rValue = m_cache.DomainDataByFlid.get_ObjectProp(to.Hvo, Flid);
						ICmPossibility posObj = (rValue == 0? null: (ICmPossibility)m_cache.ServiceLocator.GetObject(rValue));
						io = base.CreateInspectorObject(null, posObj, obj, ParentIo, level);
						iValue = (posObj == null? "null": posObj.NameHierarchyString);
						io.HasChildren = (posObj == null? false: true);
						io.DisplayName = cf.Name+ "RA";
						break;
					case "IStText":	//    multi-paragraph text (OA) StText)
						int mValue = m_cache.DomainDataByFlid.get_ObjectProp(to.Hvo, Flid);
						IStText paraObj = (mValue == 0? null: (IStText)m_cache.ServiceLocator.GetObject(mValue));
						io = base.CreateInspectorObject(null, paraObj, obj, ParentIo, level);
						iValue = (paraObj == null? "null": "StText: " + paraObj.Hvo.ToString());
						io.HasChildren = (mValue > 0? true: false);
						io.DisplayName = cf.Name + "OA";
						break;
					default:
						MessageBox.Show(string.Format("The type of the custom field is {0}", cf.Type));
						break;
				}
			}

			io.DisplayType = cf.Type;
			io.DisplayValue = (iValue ?? "null");
			io.Flid = cf.FieldID;

			return io;
		}
Example #16
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets an inspector object for the specified property info., checking for various
		/// FDO interface types.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override IInspectorObject CreateInspectorObject(PropertyInfo pi,
			object obj, object owningObj, IInspectorObject ioParent, int level)
		{
			IInspectorObject io = base.CreateInspectorObject(pi, obj, owningObj, ioParent, level);

			if (pi == null && io != null)
				io.DisplayType = StripOffFDONamespace(io.DisplayType);

			else if (pi != null && io == null)
				io.DisplayType = pi.PropertyType.Name;

			else if (pi != null && io != null)
				io.DisplayType = (io.DisplayType == "System.__ComObject" ?
				pi.PropertyType.Name : StripOffFDONamespace(io.DisplayType));

			if (obj == null)
				return io;

			if (obj is char)
			{
				io.DisplayValue = string.Format("'{0}'   (U+{1:X4})", io.DisplayValue, (int)((char)obj));
				return io;
			}

			if (obj is IFdoVector)
			{
				MethodInfo mi = obj.GetType().GetMethod("ToArray");
				try
				{
					ICmObject[] array = mi.Invoke(obj, null) as ICmObject[];
					io.Object = array;
					io.DisplayValue = FormatCountString(array.Length);
					io.HasChildren = (array.Length > 0);
				}
				catch (Exception e)
				{
					io = CreateExceptionInspectorObject(e, obj, pi.Name, level, ioParent);
				}
			}
			else if (obj is ICollection<ICmObject>)
			{
				var array = ((ICollection<ICmObject>)obj).ToArray();
				io.Object = array;
				io.DisplayValue = FormatCountString(array.Length);
				io.HasChildren = array.Length > 0;
			}

			string fmtAppend = "{0}, {{{1}}}";
			string fmtReplace = "{0}";
			string fmtStrReplace = "\"{0}\"";

			if (obj is ICmFilter)
			{
				ICmFilter filter = (ICmFilter)obj;
				io.DisplayValue = string.Format(fmtAppend, io.DisplayValue, filter.Name);
			}
			else if (obj is IMultiAccessorBase)
			{
				IMultiAccessorBase str = (IMultiAccessorBase)obj;
				io.DisplayValue = string.Format(fmtReplace,
					str.AnalysisDefaultWritingSystem.Text);
			}
			else if (obj is ITsString)
			{
				ITsString str = (ITsString)obj;
				io.DisplayValue = string.Format(fmtStrReplace, str.Text);
				io.HasChildren = true;
			}
			else if (obj is ITsTextProps)
			{
				io.Object = new TextProps(obj as ITsTextProps, m_cache);
				io.DisplayValue = string.Empty;
				io.HasChildren = true;
			}
			else if (obj is IPhNCSegments)
			{
				IPhNCSegments seg = (IPhNCSegments)obj;
				io.DisplayValue = string.Format(fmtAppend, io.DisplayValue,
					seg.Name.AnalysisDefaultWritingSystem.Text);
			}
			else if (obj is IPhEnvironment)
			{
				IPhEnvironment env = (IPhEnvironment)obj;
				io.DisplayValue = string.Format("{0}, {{Name: {1}, Pattern: {2}}}",
					io.DisplayValue, env.Name.AnalysisDefaultWritingSystem.Text,
					env.StringRepresentation.Text);
			}
			else if (obj is IMoEndoCompound)
			{
				IMoEndoCompound moendo = (IMoEndoCompound)obj;
				io.DisplayValue = string.Format(fmtAppend, io.DisplayValue,
					moendo.Name.AnalysisDefaultWritingSystem.Text);
			}
			else if (obj.GetType().GetInterface("IRepository`1") != null)
			{
				io.DisplayName = io.DisplayType;
			}

			return io;
		}
Example #17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the inspector objects for the specified MultiString.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private List<IInspectorObject> GetInspectorObjectsForMultiString(IMultiAccessorBase msa,
			IInspectorObject ioParent, int level)
		{
			List<IInspectorObject> list = new List<IInspectorObject>();
			int ws;

			if (ObjectBrowser.m_virtualFlag == false)
				list = GetMultiStringInspectorObjects(msa, ioParent, level);
			else
				list = BaseGetInspectorObjects(msa, level);

			Dictionary<int, string> allStrings = new Dictionary<int, string>();
			try
			{
				// Put this in a try/catch because VirtualStringAccessor
				// didn't implement StringCount when this was written.
				for (int i = 0; i < msa.StringCount; i++)
				{
					ITsString tss = msa.GetStringFromIndex(i, out ws);
					allStrings[ws] = tss.Text;
				}
			}
			catch { }

			if (ObjectBrowser.m_virtualFlag == true)
			{
				IInspectorObject io = CreateInspectorObject(allStrings, msa, ioParent, level);
				io.DisplayName = "AllStrings";
				io.DisplayValue = FormatCountString(allStrings.Count);
				io.HasChildren = (allStrings.Count > 0);
				list.Insert(0, io);
				list.Sort((x, y) => x.DisplayName.CompareTo(y.DisplayName));
			}
			return list;
		}
Example #18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets a list of IInspectorObject objects (same as base), but includes s lot of
		/// specifics if you choose not to see virtual fields.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private List<IInspectorObject> GetMultiStringInspectorObjects(object obj, IInspectorObject ioParent, int level)
		{
			if (ioParent != null)
				obj = ioParent.Object;

			List<IInspectorObject> list = new List<IInspectorObject>();

			ICollection collection = obj as ICollection;
			if (collection != null)
			{
				int i = 0;
				foreach (object item in collection)
				{
					IInspectorObject io = CreateInspectorObject(item, obj, ioParent, level);

					io.DisplayName = string.Format("[{0}]", i++);
					list.Add(io);
				}

				return list;
			}

			PropertyInfo[] props = GetPropsForObj(obj);
			foreach (PropertyInfo pi in props)
			{
				try
				{
					object propObj = pi.GetValue(obj, null);
					IInspectorObject Itmp = CreateInspectorObject(pi, propObj, obj, ioParent, level);

					if ((obj.ToString().IndexOf("MultiUnicodeAccessor") > 0 && Itmp.DisplayName != "Values") ||
						(obj.ToString().IndexOf("MultiStringAccessor") > 0  && Itmp.DisplayName != "Values"))
						continue;
					else
					{
						ICollection Itmp4 = Itmp.Object as ICollection;
						if (Itmp4 != null)
						{
							Itmp.DisplayValue = "Count = " + Itmp4.Count;
							Itmp.HasChildren = (Itmp4.Count > 0);
						}
					}
					list.Add(Itmp);
				}
				catch (Exception e)
				{
					continue;
				}
			}

			list.Sort(CompareInspectorObjectNames);
			return list;
		}
Example #19
0
 /// <summary>
 /// Displays the specified object and all its public properties in the
 /// inspector.
 /// </summary>
 /// <param name="obj">The object to display.</param>
 public void Show(IInspectorObject obj)
 {
     Grid.SelectedObject = obj;
 }