(FILECREATED "16-Jan-87 20:43:53" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH181.;1 6092   

      changes to:  (VARS RHTPATCH181COMS))


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

(PRETTYCOMPRINT RHTPATCH181COMS)

(RPAQQ RHTPATCH181COMS ((* * Fix to half of bug #6: call to MarkCardDeletedFn is now after call to 
			     NC.QuitCard in NC.DeleteNoteCard.)
			  (* * Change to NCCARDS)
			  (FNS NC.DeleteNoteCard)))
(* * Fix to half of bug #6: call to MarkCardDeletedFn is now after call to NC.QuitCard in 
NC.DeleteNoteCard.)

(* * Change to NCCARDS)

(DEFINEQ

(NC.DeleteNoteCard
  (LAMBDA (Card)                                             (* rht: "16-Jan-87 20:39")

          (* * Delete a single note card from a NoteFile)



          (* * rht 8/11/86 Now calls NC.DeleteReferencesToCardFromShowLinks to smash any link icons in show links menus 
	  pointing to this card.)



          (* * kef 7/28/86: Added code to obtain all of the write locks deemed necessary.)



          (* * kef 7/30/86: Modified to check for Client's concept of whether he owns the write lock or not, thus deciding 
	  whether or not to setup the release of the write lock afterwards.)



          (* * kef 7/31/86: Added the nesting of the obtaining writelocks with deactivating the card.)



          (* * fgh 8/30/86 Translated APPLY* to NC.ApplyFn. Made cosmetic changes in FOR loop concewrning WriteLocks.)



          (* * rht 1/16/87: Moved call to MarkCardDeletedFn after call to NC.QuitCard.)


    (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
		(RESETSAVE NIL (BQUOTE (NC.SetBeingDeletedFlg , Card NIL)))
		(WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
			      (LET ((WriteLocks (for CardPart
						   in (QUOTE (SUBSTANCE TITLE TOLINKS FROMLINKS 
									    GLOBALTOLINKS PROPLIST))
						   collect (CONS Card CardPart)))
				    ToLinks FromLinks Window BusyPart PromptWindow)
			           (NC.SetBeingDeletedFlg Card T)
			           (SETQ ToLinks (NC.RetrieveToLinks Card))
			           (SETQ FromLinks (NC.RetrieveFromLinks Card))
			           (for ToLink in ToLinks
				      do (NCONC WriteLocks (for CardPart
								  in (QUOTE (TOLINKS FROMLINKS 
										    GLOBALTOLINKS))
								  collect
								   (CONS (fetch (Link 
										  DestinationCard)
									      of ToLink)
									   CardPart))))
			           (for FromLink in FromLinks
				      do (NCONC WriteLocks (for CardPart
								  in (QUOTE (SUBSTANCE TOLINKS 
											FROMLINKS 
										    GLOBALTOLINKS))
								  collect
								   (CONS (fetch (Link SourceCard)
									      of FromLink)
									   CardPart))))

          (* * The for... loop that follows is the condition that we can obtain all of the write locks on all of the card 
	  parts collected in WriteLocks. If we obtain a writelock, setup a RESETSAVE to release it upon exit.
	  Then finally, if we do obtain a write lock, return T so that the for loop's "always" condition is satisfied.
	  If we don't obtain a write lock for a given card part, save that one as a variable so we can report it to the user.
	  Then return NIL, so that the for loop's "always" condition is not satisfied, and we bump out of the for loop.)


			           (NC.PrintMsg (SETQ PromptWindow (NC.AttachPromptWindow
						      (NC.FetchWindow Card)))
						  T "Collecting write locks...")
			           (COND
				     ((for WriteLock in WriteLocks bind WLCard WLCardPart
					 when (NC.ValidCardP (SETQ WLCard (CAR WriteLock)))
					 always (SETQ WLCardPart (CDR WriteLock))
						  (COND
						    ((NC.ApplyFn ObtainWritePermissionFn WLCard 
								 WLCardPart)
						      (RESETSAVE NIL
								   (BQUOTE
								     (APPLY* , (fetch
										 (Card 
									 ReleaseWritePermissionFn)
										    of WLCard)
									       , WLCard , WLCardPart))
								   )
						      T)
						    (T (SETQ BusyPart WriteLock)
						       NIL)))

          (* * Call off to the MarkCardDeletedFn specific to the NoteFile.)


				       (RESETSAVE (for CardPart
						       in (QUOTE (SUBSTANCE TOLINKS GLOBALTOLINKS 
										PROPLIST))
						       do (NC.ApplyFn ObtainWritePermissionFn Card 
									CardPart))
						    (BQUOTE (NC.DeactivateCard , Card T)))
				       (NC.ApplyFn MarkCardDeletedFn Card)
				       (NC.SetToLinks Card NIL)
				       (NC.SetFromLinks Card NIL)
				       (NC.PrintMsg PromptWindow NIL 
						      "Removing links to and from other cards...")
				       (for ToLink in ToLinks when (NC.ValidLinkP ToLink)
					  do (NC.DelFromLink ToLink)
					       (NC.DelReferencesToCardFromShowLinks
						 (fetch (Link DestinationCard) of ToLink)
						 ToLink))
				       (for FromLink in FromLinks when (NC.ValidLinkP 
											 FromLink)
					  do (NC.DelToLink FromLink)
					       (NC.DelReferencesToCard (fetch (Link SourceCard)
									    of FromLink)
									 Card)
					       (NC.DelReferencesToCardFromShowLinks
						 (fetch (Link SourceCard) of FromLink)
						 FromLink))
				       (NC.PrintMsg PromptWindow NIL "..done.")
				       (if (NC.ActiveCardP Card)
					   then (NC.TurnOffDirtyFlgs Card)
						  (SETQ Window (NC.FetchWindow Card))
						  (AND Window (NC.GreyCard Card))
						  (NC.CloseAllPropListEditors Card)
						  (NC.QuitCard Card T T NIL T))
				       (NC.ApplyFn MarkCardDeletedFn Card)
				       (NC.SetNewCardFlg Card NIL))
				     (T (NC.CardPartBusy (CAR BusyPart)
							   (CDR BusyPart)
							   PromptWindow))))))))
)
(PUTPROPS RHTPATCH181 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (589 6010 (NC.DeleteNoteCard 599 . 6008)))))
STOP