Inheritance: MonoMac.AppKit.NSMenu
Exemple #1
0
		/// <summary>
		/// Set up the submenu items for 'Create' and 'Insert' menus.
		/// </summary>
		protected void SetupContextMenu(Slice slice, SliceTreeNode sliceTreeNode)
		{
			// Get rid of old sub-menu items.
			m_mnuCreate.MenuItems.Clear();

			m_helper = new ContextMenuHelper(sliceTreeNode);
			m_rgcpiCreateOptions = slice.Object.PropsAndClassesOwnedBy;
			// Fill in info about which object will be the new owner.
			for (int index = m_rgcpiCreateOptions.Count; --index >= 0; )
			{
				ClassAndPropInfo cpi = m_rgcpiCreateOptions[index];
				cpi.hvoOwner = slice.Object.Hvo;
			}
			// Drop atomic property options if not empty
			for (int index = m_rgcpiCreateOptions.Count; --index >= 0; )
			{
				ClassAndPropInfo cpi = (ClassAndPropInfo)m_rgcpiCreateOptions[index];
				if (cpi.fieldType == (int)FieldType.kcptOwningAtom)
				{
					FDO.FdoCache cache = slice.ContainingDataTree.Cache;
					if (cache.GetObjProperty(cpi.hvoOwner, (int)(cpi.flid)) != 0)
						m_rgcpiCreateOptions.RemoveAt(index);
				}
			}
			int iBefore = m_rgcpiCreateOptions.Count;
			GetCreateSiblingOptions(slice, m_rgcpiCreateOptions, true);
			bool fSeq = m_rgcpiCreateOptions.Count > iBefore &&
				m_rgcpiCreateOptions[iBefore].fieldType == (int)FieldType.kcptOwningSequence;
			int iAfter = m_rgcpiCreateOptions.Count;
			if (fSeq)
			{
				// In a sequence we make another set of options to insert after the current item.
				GetCreateSiblingOptions(slice, m_rgcpiCreateOptions, false);
			}
			for(int index = 0; index < m_rgcpiCreateOptions.Count; index++)
			{
				ClassAndPropInfo cpi = (ClassAndPropInfo)m_rgcpiCreateOptions[index];
				String format = DetailControlsStrings.ksNewItem;
				if (index >= iAfter)
				{
					format = DetailControlsStrings.ksNewItemAfter; // can't happen if not sequence
				}
				else if (index >= iBefore)
				{
					if (fSeq)
						format = DetailControlsStrings.ksNewItemBefore;
					else // sibling collection
						format = DetailControlsStrings.ksNewItemWithin;
				}
				m_mnuCreate.MenuItems.Add(new MenuItem(
					String.Format(format, new object[] {cpi.signatureClassName, cpi.fieldName}),
					new EventHandler(this.HandleCreateMenuItem)));
			}
			m_mnuCreate.Enabled = m_mnuCreate.MenuItems.Count > 0;
			m_helper.SetupDeleteMenu(m_mnuDelete);
		}
		void CreateHandle ()
		{
			helper = new ContextMenuHelper(this);
			m_view = helper;
		}
Exemple #3
0
		public void HandleCreateMenuItem(object sender, EventArgs ea)
		{
			Slice slice = m_dataEntryForm.CurrentSlice;

			if (slice != null)
			{
				ClassAndPropInfo cpi = (ClassAndPropInfo)m_rgcpiCreateOptions[((MenuItem)sender).Index];
				FDO.FdoCache cache = slice.ContainingDataTree.Cache;
				int hvoOwner = cpi.hvoOwner;
				int ihvoPosition = cpi.ihvoPosition;
				if (ihvoPosition == ClassAndPropInfo.kposNotSet && cpi.fieldType == (int)FieldType.kcptOwningSequence)
				{
					// insert at end of sequence.
					ihvoPosition = cache.GetVectorSize(hvoOwner, (int)cpi.flid);
				} // otherwise we already worked out the position or it doesn't matter
				// Note: ihvoPosition ignored if sequence or atomic.
				int hvoNew = cache.CreateObject((int)(cpi.signatureClsid), hvoOwner, (int)(cpi.flid), ihvoPosition);
				cache.MainCacheAccessor.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvoOwner, (int)(cpi.flid), ihvoPosition, 1, 0);
				m_helper = null; // allow old one to be garbage.
				if (hvoOwner == slice.Object.Hvo && slice.Expansion == DataTree.TreeItemState.ktisCollapsed)
				{
					// We added something to the object of the current slice...almost certainly it
					// will be something that will display under this node...if it is still collapsed,
					// expand it to show the thing inserted.
					slice.TreeNode.ToggleExpansion(slice.IndexInContainer);
				}
				Slice child = slice.ExpandSubItem(hvoNew);
				if (child != null)
					child.FocusSliceOrChild();
			}
		}