(FILECREATED "26-Mar-87 19:45:15" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH229.;1 16724  

      changes to:  (VARS RHTPATCH229COMS)
		   (FNS NC.MakeFilingLinks NC.CheckFiling))


(* Copyright (c) 1987 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT RHTPATCH229COMS)

(RPAQQ RHTPATCH229COMS ((* * Fixes bug #488 (item 4)
			     also reported by John Tang, but unnumbered. CrossFilelinks were being 
			     orphanized at deletion. Also fixes bug #345: cross-file links weirdness.)
			  (* * Change to NCLINKS)
			  (FNS NC.DeleteFromLink NC.DeleteToLink NC.LinkIconWhenDeletedFn 
			       NC.MakeFilingLinks)
			  (* * Change to NCCARDS)
			  (FNS NC.DeleteNoteCard NC.CardNeedsFilingP NC.CheckFiling)))
(* * Fixes bug #488 (item 4) also reported by John Tang, but unnumbered. CrossFilelinks were 
being orphanized at deletion. Also fixes bug #345: cross-file links weirdness.)

(* * Change to NCLINKS)

(DEFINEQ

(NC.DeleteFromLink
  (LAMBDA (Link NoOrphanHookFlg)                             (* rht: "26-Mar-87 18:43")

          (* * This is part of what used to be the innards of NC.DeleteLink.)



          (* * rht 3/26/87: Changed to call NC.DeleteNoteCardInternal with QuietFlg on.)


    (AND (NC.ValidLinkP Link)
	   (LET ((DestinationCard (fetch (Link DestinationCard) of Link)))
	        (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of DestinationCard))
			      (NC.DelFromLink Link NoOrphanHookFlg)
			      (NC.DelReferencesToCardFromShowLinks DestinationCard Link)

          (* * Delete cross file link cards when their links are deleted.)


			      (if (NC.CrossFileLinkCardP DestinationCard)
				  then (NC.DeleteNoteCardInternal DestinationCard T)))))))

(NC.DeleteToLink
  (LAMBDA (Link Don'tDelLinkIconFlg)                         (* rht: "26-Mar-87 19:15")

          (* * This is part of what used to be the innards of NC.DeleteLink.)



          (* * rht 3/26/87: Changed to call NC.DeleteNoteCardInternal with QuietFlg on.)


    (AND (NC.ValidLinkP Link)
	   (LET ((SourceCard (fetch (Link SourceCard) of Link)))
	        (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of SourceCard))
			      (OR Don'tDelLinkIconFlg (NC.DelReferencesToCard SourceCard Link))
			      (NC.DelToLink Link)
			      (NC.DelReferencesToCardFromShowLinks SourceCard Link)

          (* * Delete cross file link cards when their links are deleted.)


			      (if (NC.CrossFileLinkCardP SourceCard)
				  then (NC.DeleteNoteCardInternal SourceCard T)))))))

(NC.LinkIconWhenDeletedFn
  (LAMBDA (ImageObject Stream)                               (* rht: "26-Mar-87 19:10")

          (* * When deleting a link icon image object from a card, make sure the link information on the source and 
	  destinmation cards get updated. When deleting a link image object from a prop list editor, just inform the user 
	  that this is a useless operation.)



          (* * rht 11/19/84: Now handles the case when a move is in progress. True if the old link is cached on the ImageObj.
	  Also changed so that SourceID is computed from ImageObject rather than from Stream. Similarly for the window.)



          (* * kirk 14Nov85: deleted use of PSA.Database)



          (* * fgh 5/2/86 Added code to handle deleting of links from ShowLinks editors.)



          (* * fgh 6/4/86 Added KLUDGE to take care of case when this is called under TEDIT.UNDO.MOVE)



          (* * rht 7/4/86: Now checks for readonly cards. Also passes checks for deleting from orphan card when calling 
	  NC.DeleteLink.)



          (* * fgh 7/14/86 Now deletes link icon directly, rather than depending on DeleteLink to do it.
	  Sets the Don'tDeleteLinkIconFlg in the call to DeleteLink to do so.)



          (* * rht 8/11/86: Now computes InsideShowLinksP and lets that determine value of Don'tDelLinkIcon flg in call to 
	  NC.DeleteLink.)



          (* * rht&pmi 12/8/86: Now checks whether we're called by TEDIT.MOVE. If so, don't cause orphan hook under 
	  NC.DelFromLink.)



          (* * rht 3/26/87: Now passes non-nil NoOrphanHookFlg to NC.DeleteLink in case we're deleting a cross-file link.)


    (DECLARE (GLOBALVARS NC.DeletedLinkImageObject))
    (LET ((Link (NC.FetchLinkFromLinkIcon ImageObject))
	  LinkType OldLink StkPtr SourceCard DestinationCard InsideShowLinksP)
         (COND
	   ((NC.CheckForNotReadOnly (fetch (Link SourceCard) of Link)
				      NIL "Can't delete links in ")
	     (COND
	       ((IMAGEOBJPROP ImageObject (QUOTE LinkBeingMovedWithinCard))
                                                             (* TEdit is trying to delete the old link imageobj 
							     after moving within a card.)
		 (IMAGEOBJPROP ImageObject (QUOTE LinkBeingMovedWithinCard)
				 NIL))
	       ((SETQ OldLink (IMAGEOBJPROP ImageObject (QUOTE LinkBeingMoved)))
                                                             (* Pass non-nil NoOrphanHookFlg arg to NC.DelFromLink 
							     if we are under a TEDIT.MOVE call.)
		 (NC.DelFromLink OldLink (RELSTK (STKPOS (QUOTE TEDIT.MOVE))))
		 (NC.DelToLink OldLink)
		 (replace (Link UID) of OldLink with -1)
		 (IMAGEOBJPROP ImageObject (QUOTE LinkBeingMoved)
				 NIL))
	       ((SETQ StkPtr (STKPOS (QUOTE TEDIT.UNDO.MOVE)))

          (* * Called from TEDIT.UNDO.MOVE, don't relly want to delete the links. KLUDGE because TEDIT will not call the 
	  LinkIconInsertFn later on.)


		 (RELSTK StkPtr)
		 NIL)
	       (T 

          (* * if this is reversed source/dest {i.e., a From link} inside the show links editor, then return it to its 
	  original direction)


		  (COND
		    ((AND (SETQ InsideShowLinksP (IMAGEOBJPROP ImageObject (QUOTE 
									     InsidePropListEditor)))
			    (LISTGET (fetch (Link UserData) of Link)
				       (QUOTE Reversed)))
		      (SETQ Link (create Link using Link SourceCard ←(fetch (Link 
										  DestinationCard)
									      of Link)
							  DestinationCard ←(fetch (Link SourceCard)
									      of Link)))))

          (* * Then just delete the link)


		  (NC.CheckForOrphanDelete (SETQ SourceCard (fetch (Link SourceCard)
								   of Link))
					     (SETQ DestinationCard (fetch (Link DestinationCard)
									of Link)))
		  (NC.DeleteLink Link (OR (NC.SameCardP SourceCard (fetch (NoteFile 
										      OrphansCard)
									    of (fetch
										   (Card NoteFile)
										    of SourceCard)))
					      (NC.CrossFileLinkCardP DestinationCard)
					      (NC.CrossFileLinkCardP SourceCard))
				   (NOT InsideShowLinksP))
		  (create IMAGEOBJ smashing ImageObject OBJECTDATUM ←(fetch (IMAGEOBJ 
										      OBJECTDATUM)
									    of 
									NC.DeletedLinkImageObject)
						IMAGEOBJPLIST ←(fetch (IMAGEOBJ IMAGEOBJPLIST)
								  of NC.DeletedLinkImageObject)
						IMAGEOBJFNS ←(fetch (IMAGEOBJ IMAGEOBJFNS)
								of NC.DeletedLinkImageObject))
		  (replace (Link UID) of Link with -1))))
	   (T (ERROR!))))))

(NC.MakeFilingLinks
  (LAMBDA (Card Msg InterestedWindow)                        (* rht: "26-Mar-87 19:40")
                                                             (* Hooks card specified by Card to all of the current 
							     contents cards by a Contents link)

          (* * rht 8/1/84: Changed the NC.PrintMsg2 call for "No FileBox has been specified." to use NIL as second arg rather
	  than T. This prevents erasure of previous error messages.)



          (* * rht 12/8/84: Massive rewrite. Now calls NC.MakeChildLink. And always orphanizes if no parent specified.
	  This is because it's currently called only by NC.InsureProperFiling.)



          (* * rht 6/25/85: Now returns NewParents and checks if CANCELLED comes back from NC.SelectNoteCards so can abort 
	  the calling operation.)



          (* * Fgh 11/15/85 Adapted from and intended to replace NC.MakeContentsHooks)



          (* * fgh 8/6/86 Updated to use NC.AttachPromptWindow and added Msg arg)



          (* * pmi 12/5/86: Modified message to NC.SelectNoteCards to mention SHIFT-selection.)



          (* * pmi 12/12/86: Removed obsolete ReturnLinksFlg argument in call to NC.SelectNoteCards.)



          (* * rg 2/19/87 Make sure NewParents always has the real value)



          (* * rg 3/18/87 added NC.CardSelectionOperation wrapper)



          (* * rht 3/23/87: Changed so that message will fit on one less line.)



          (* * rht 3/23/87: Now takes InterestedWindow arg.)



          (* * Rht 3/24/87: Now calls NC.CoerceToInterestedWindow)



          (* * rht 3/26/87: No longer allows selection of boxes in foreign notefiles.)


    (DECLARE (GLOBALVARS NC.SelectingContentsMenu))
    (NC.CardSelectionOperation (PROG ((NoteFile (fetch (Card NoteFile) of Card))
					OneHook NewParents)
				       (OR InterestedWindow (SETQ InterestedWindow (
						 NC.CoerceToInterestedWindow Card)))
				       (SETQ NewParents
					 (NC.SelectNoteCards NIL
							       (FUNCTION (LAMBDA (SelectedCard)
								   (AND (NC.FileBoxP SelectedCard)
									  (NC.SameNoteFileP
									    NoteFile
									    (fetch (Card NoteFile)
									       of SelectedCard)))))
							       NC.SelectingContentsMenu Card
							       (CONCAT (OR Msg "")
									 
						"('Done' with no selections files in ToBeFiled.)")
							       T))
				       (COND
					 ((NOT (OR (EQ NewParents (QUOTE CANCELLED))
						       (AND NewParents
							      (for ParentCard in NewParents
								 bind OneHook
								 when (NC.MakeChildLink Card 
										       ParentCard 
										 InterestedWindow)
								 do (SETQ OneHook T)
								 finally (RETURN OneHook)))))
					   (NC.PrintMsg InterestedWindow NIL 
							  "No FileBox has been specified."
							  (CHARACTER 13)
							  
						  "This card will be filed in the ToBeFiled Box."
							  (CHARACTER 13))
					   (SETQ NewParents (NC.HookToOrphanCard
					       Card
					       (fetch (NoteFile ToBeFiledCard) of NoteFile)))
					   (COND
					     ((NC.AttachPromptWindow InterestedWindow NIL NIL NIL T)
					       (SPAWN.MOUSE)
					       (DISMISS 2000)
					       (NC.ClearMsg InterestedWindow T)))))
				       (RETURN NewParents)))))
)
(* * Change to NCCARDS)

(DEFINEQ

(NC.DeleteNoteCard
  (LAMBDA (CardIdentifier DontClearFlg NoConfirmFlg QuietFlg InterestedWindow)
                                                             (* rht: "26-Mar-87 18:47")

          (* * User interface level fn to delete a single note card from a NoteFile)



          (* * rht 3/25/87: Added a bunch of new args. Fixed InterestedWindow stuff.)



          (* * 3/26/87: Now clears InterestedWindow when done.)


    (LET ((Card (NC.CoerceToCard CardIdentifier)))
         (if (NC.ValidCardP Card)
	     then (OR InterestedWindow (SETQ InterestedWindow (NC.CoerceToInterestedWindow
			      Card)))
		    (NC.ProtectedCardOperation Card "Delete Note Card" InterestedWindow
					       (AND (if (NC.TopLevelCardP Card)
							  then (NC.PrintMsg InterestedWindow T 
								"You cannot delete this FileBox."
										(CHARACTER 13))
								 (DISMISS 1000)
								 (NC.ClearMsg InterestedWindow T)
								 NIL
							else T)
						      (NC.CheckForNotReadOnly Card InterestedWindow 
								     "Can't delete cards from a ")
						      (OR NoConfirmFlg
							    (PROG1 (NC.AskYesOrNo 
							  "Are you sure you want to delete this?"
										      " -- " "Yes"
										      (NULL 
										     DontClearFlg)
										      
										 InterestedWindow NIL 
										      NIL)
								     (NC.ClearMsg InterestedWindow 
										    T)))
						      (PROGN 

          (* * Mark UID of card about to be deleted.)


							       (NC.UIDPutProp (fetch
										  (Card UID)
										   of Card)
										(QUOTE 
									      AboutToBeDeletedFlg)
										T)

          (* * Sever all links into and out of Card)


							       (NC.SeverAllLinks (LIST Card)
										   QuietFlg 
										 InterestedWindow)

          (* * Now delete the card)


							       (PROG1 (NC.DeleteNoteCardInternal
									  Card QuietFlg 
									  InterestedWindow)
									(OR QuietFlg
									      (NC.ClearMsg 
										 InterestedWindow T)))
							       )))))))

(NC.CardNeedsFilingP
  (LAMBDA (Card)                                             (* rht: "26-Mar-87 19:30")

          (* * Returns non-nil if this card is filed in some not currently filed anywhere unless it's a top level card.
	  Assumes card is active.)



          (* * fgh 11/12/85 Updated to handle Card objects.)



          (* * rht 10/6/86: Now checks for card types that don't have to be filed. Also makes sure that there's at least one 
	  filing link that's within this notefile.)



          (* * rht 12/8/86: Now checks for individual cards that don't require filing.)



          (* * rg 12/18/86: Added check of FilingLinkTypeFlg prop.)



          (* * rht 3/26/87: Fixed check for crossfilelink card.)


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (AND (NOT (NC.TopLevelCardP Card))
		(NC.ForceFilingForCardTypeP (NC.FetchType Card))
		(NOT (NCP.CardProp Card (QUOTE Don'tRequireFilingFlg)))
		(for Link in (NC.FetchFromLinks Card)
		   never (AND (OR (FMEMB (fetch (Link Label) of Link)
						 (QUOTE (FiledCard SubBox)))
					(GETPROP (fetch (Link Label) of Link)
						   (QUOTE FilingLinkTypeFlg)))
				  (NOT (NC.CrossFileLinkCardP (fetch (Link SourceCard)
								     of Link)))))))))

(NC.CheckFiling
  (LAMBDA (Card InterestedWindow)                            (* rht: "26-Mar-87 19:43")
                                                             (* Check to make sure this card has a contents hook of
							     some sort. If not, hook it up to a contents card.)

          (* * rht 12/8/84: Now checks whether both cards *and* fileboxes have been filed.)



          (* * rht 12/9/84: Now files in orphan filebox if NC.ForceFiling flag is off, without bothering the user.)



          (* * rht 2/9/85: Added call to NC.CardNeedsFilingP)



          (* * fgh 11/12/85 Updated to handle Card and NoteFile objects.)



          (* * fgh 6/9/86 Updated to set operation in progress indicator.)



          (* * rg 1/28/87 Make sure we always return a useful value)



          (* * rg 3/4/87 rewritten for new version of NC.ProtectedCardOperation)



          (* * rht 3/23/87: Now takes InterestedWindow arg.)



          (* * Rht 3/24/87: Now calls NC.CoerceToInterestedWindow)



          (* * rht 3/26/87: Changed msg slightly.)


    (NC.ProtectedCardOperation Card "Filing" NIL (COND
				 ((NC.CardNeedsFilingP Card)
				   (OR InterestedWindow (SETQ InterestedWindow (
					     NC.CoerceToInterestedWindow Card)))
				   (COND
				     (NC.ForceFilingFlg (NC.MakeFilingLinks Card
									      (CONCAT "This card ("
											(
										 NC.RetrieveTitle
											  Card)
											
					") is not currently filed in a FileBox in this notefile."
											(CHARACTER
											  13))
									      InterestedWindow))
				     (T (NC.PrintMsg InterestedWindow T "This card (" (
							 NC.RetrieveTitle Card)
						       ") is not currently filed in a FileBox."
						       (CHARACTER 13)
						       "It is being filed in the ToBeFiled FileBox."
						       (CHARACTER 13))
					(NC.HookToOrphanCard Card (fetch (NoteFile ToBeFiledCard)
								       of (fetch (Card NoteFile)
									       of Card))))))
				 (T T)))))
)
(PUTPROPS RHTPATCH229 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (932 10935 (NC.DeleteFromLink 942 . 1784) (NC.DeleteToLink 1786 . 2661) (
NC.LinkIconWhenDeletedFn 2663 . 7463) (NC.MakeFilingLinks 7465 . 10933)) (10966 16642 (
NC.DeleteNoteCard 10976 . 13137) (NC.CardNeedsFilingP 13139 . 14525) (NC.CheckFiling 14527 . 16640))))
)
STOP