Exemple #1
0
        private void MoveItem(object sender, TreeNode destNode, TreeNode sourceItem)
        {
            int                hvoMove = (int)sourceItem.Tag;
            int                hvoDest;
            int                flidDest;
            FdoCache           cache     = (FdoCache)m_mediator.PropertyTable.GetValue("cache");
            string             moveLabel = sourceItem.Text;
            TreeNodeCollection newSiblings;
            TreeView           tree = sender as TreeView;

            if (destNode == null)
            {
                for (hvoDest = cache.GetOwnerOfObject(hvoMove); hvoDest != 0; hvoDest = cache.GetOwnerOfObject(hvoDest))
                {
                    if (cache.GetClassOfObject(hvoDest) == CmPossibilityList.kclsidCmPossibilityList)
                    {
                        break;
                    }
                }
                if (hvoDest == 0)
                {
                    return;
                }
                flidDest    = (int)CmPossibilityList.CmPossibilityListTags.kflidPossibilities;
                newSiblings = tree.Nodes;
            }
            else
            {
                hvoDest     = (int)destNode.Tag;
                flidDest    = (int)CmPossibility.CmPossibilityTags.kflidSubPossibilities;
                newSiblings = destNode.Nodes;
            }
            if (CheckAndReportForbiddenMove(hvoMove, hvoDest))
            {
                return;
            }
            int hvoOldOwner = cache.GetOwnerOfObject(hvoMove);

            if (hvoOldOwner == hvoDest)
            {
                return;                 // nothing to do.
            }
            int flidSrc  = cache.GetOwningFlidOfObject(hvoMove);
            int srcIndex = cache.GetObjIndex(hvoOldOwner, flidSrc, hvoMove);
            int ihvoDest = 0;

            for (; ihvoDest < newSiblings.Count; ihvoDest++)
            {
                if (newSiblings[ihvoDest].Text.CompareTo(moveLabel) > 0)                 // Enhance JohnT: use ICU comparison...
                {
                    break;
                }
            }
            using (new RecordClerk.ListUpdateHelper(m_list, tree.TopLevelControl))
                using (UndoRedoTaskHelper urth = new UndoRedoTaskHelper(cache, xWorksStrings.UndoMoveItem, xWorksStrings.RedoMoveItem))
                {
                    // Note: use MoveOwningSequence off FdoCache, so we get propchanges that can be picked up by SyncWatcher (CLE-76)
                    // (Hopefully the propchanges won't cause too much intermediant flicker,
                    // before ListUpdateHelper calls ReloadList())
                    cache.MoveOwningSequence(hvoOldOwner, flidSrc, srcIndex, srcIndex, hvoDest, flidDest, ihvoDest);
                    ICmObject obj = CmObject.CreateFromDBObject(cache, hvoMove);
                    obj.MoveSideEffects(hvoOldOwner);
                }
        }
		private void MoveItem(object sender, TreeNode destNode, TreeNode sourceItem)
		{
			int hvoMove = (int)sourceItem.Tag;
			int hvoDest;
			int flidDest;
			FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache");
			string moveLabel = sourceItem.Text;
			TreeNodeCollection newSiblings;
			TreeView tree = sender as TreeView;
			if (destNode == null)
			{
				for (hvoDest = cache.GetOwnerOfObject(hvoMove); hvoDest != 0; hvoDest = cache.GetOwnerOfObject(hvoDest))
				{
					if (cache.GetClassOfObject(hvoDest) == CmPossibilityList.kclsidCmPossibilityList)
						break;
				}
				if (hvoDest == 0)
					return;
				flidDest = (int)CmPossibilityList.CmPossibilityListTags.kflidPossibilities;
				newSiblings = tree.Nodes;
			}
			else
			{
				hvoDest = (int)destNode.Tag;
				flidDest = (int)CmPossibility.CmPossibilityTags.kflidSubPossibilities;
				newSiblings = destNode.Nodes;
			}
			if (CheckAndReportForbiddenMove(hvoMove, hvoDest))
				return;
			int hvoOldOwner = cache.GetOwnerOfObject(hvoMove);
			if (hvoOldOwner == hvoDest)
				return; // nothing to do.
			int flidSrc = cache.GetOwningFlidOfObject(hvoMove);
			int srcIndex = cache.GetObjIndex(hvoOldOwner, flidSrc, hvoMove);
			int ihvoDest = 0;
			for (; ihvoDest < newSiblings.Count; ihvoDest++)
			{
				if (newSiblings[ihvoDest].Text.CompareTo(moveLabel) > 0) // Enhance JohnT: use ICU comparison...
					break;
			}
			using (new RecordClerk.ListUpdateHelper(m_list, tree.TopLevelControl))
			using (UndoRedoTaskHelper urth = new UndoRedoTaskHelper(cache, xWorksStrings.UndoMoveItem, xWorksStrings.RedoMoveItem))
			{
				// Note: use MoveOwningSequence off FdoCache, so we get propchanges that can be picked up by SyncWatcher (CLE-76)
				// (Hopefully the propchanges won't cause too much intermediant flicker,
				// before ListUpdateHelper calls ReloadList())
				cache.MoveOwningSequence(hvoOldOwner, flidSrc, srcIndex, srcIndex, hvoDest, flidDest, ihvoDest);
				ICmObject obj = CmObject.CreateFromDBObject(cache, hvoMove);
				obj.MoveSideEffects(hvoOldOwner);
			}
		}
		/// <summary>
		/// Create an object from the current data entry row.
		/// </summary>
		/// <param name="rgtss"></param>
		/// <param name="fAddItems"></param>
		/// <returns></returns>
		private int CreateObjectFromEntryRow(ITsString[] rgtss, bool fAddItems)
		{
			int newObjHvo = 0;
			// Conceptual model class.
			string sUndo = String.Format(XMLViewsStrings.ksUndoNewEntryX, rgtss[0].Text);
			string sRedo = String.Format(XMLViewsStrings.ksRedoNewEntryX, rgtss[0].Text);
			try
			{
				using (UndoRedoTaskHelper urth = new UndoRedoTaskHelper(Cache, sUndo, sRedo))
				{
					newObjHvo = CreateObjectFromEntryRow(rgtss);
					CreateObjectFromEntryRowUndoAction undoRedoAction = new CreateObjectFromEntryRowUndoAction(this, newObjHvo, fAddItems);
					urth.AddAction(undoRedoAction);
					undoRedoAction.DoIt();
				}
			}
			catch (Exception error)
			{
				throw new RuntimeConfigurationException(String.Format(
					"XmlBrowseRDEView.ProcessRDEKeyPress() could not invoke the static {0} method of the class {1}",
					RDEVc.EditRowSaveMethod, RDEVc.EditRowClass), error);
			}
			return newObjHvo;
		}