(FILECREATED "20-May-87 13:55:32" {QV}<NOTECARDS>1.3K>NEXT>RGPATCH043.;1 7725   

      changes to:  (VARS RGPATCH043COMS)
		   (FNS NC.CardSaveFn))


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

(PRETTYCOMPRINT RGPATCH043COMS)

(RPAQQ RGPATCH043COMS ((* * rg 5/20/87 now does FORCEOUTPUT after saving. Only an interim solution 
			    for local notefiles, we need a new protocol operation for the remote 
			    case.)
			 (* * changes to NCCARDS)
			 (FNS NC.CardSaveFn)))
(* * rg 5/20/87 now does FORCEOUTPUT after saving. Only an interim solution for local 
notefiles, we need a new protocol operation for the remote case.)

(* * changes to NCCARDS)

(DEFINEQ

(NC.CardSaveFn
  [LAMBDA (WindowOrID QuietFlg InterestedWindow OperationMsg)
                                                             (* Randy.Gobbel "20-May-87 13:48")

          (* * rht 2/1/85: New function for saving ANY kind of card. All strangenesses are handled in NC.CardDirtyP and 
	  NC.MarkCardDirty. Added print statements to show what is being saved. Lets NC.CardDirtyP take care of proper dirty 
	  checks.)



          (* * rht 2/8/85: Added InsureFilingFlg)



          (* * rht 6/25/85: Pulled out InsureFilingFlg. That check now done upstairs in NC.QuitCard.)



          (* * rht 9/20/85: Added QuietFlg.)



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



          (* * kirk 29Jan86 replaced call on undefined NC.UpdateRegionData with NC.PutRegion)



          (* * fgh 6/13/86 Added operations in progress code and DontCheckForOpsInProgressFlg arg.)



          (* * fgh 6/26/86 Added InterestedWindow & OperationMsg arg.)



          (* * rht 7/4/86: Added check for readonly notefile.)



          (* * kef 7/22/86: Added something to obtain the write permission on the FROMLINKS if the links have been changed.
	  FROMLINKS aren't ordinarily obtained at edit time like the rest of the links are.)



          (* * 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/30/86: Added a check to see if the NewCardFlg was on, then release TITLE and FROMLINKS writelocks.
	  This is needed since ordinary deactivation of cards won't do this; i.e., only new cards have their TITLE and 
	  FROMLINKS also writelocked.)



          (* * fgh 8/30/86 Changed APPLY* to NC.ApplyFn where possible.)



          (* * rht&pmi 11/21/86: Now calls WhenSavedFn for card type if any.)



          (* * rg 3/4/87 rewritten for new NC.ProtectedCardOperation, removed DontCheckForOpsInProgressFlg)



          (* * rht 3/23/87: Fixed weirdness with InterestedWindow/Window.)



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



          (* * rht 3/30/87: No longer prints messages if nothing got written down.)



          (* * rg 3/31/87 fiddled w/ InterestedWindow stuff)



          (* * rg 5/20/87 added FORCEOUTPUT on stream after all writes done. WARNING! THIS IS A KLUDGE, AND WILL ONLY WORK 
	  FOR OLD-FASHIONED LOCAL NOTEFILES. For remote notefiles, we really need to add another operation to the protocol.)


    (LET ((Card (NC.CoerceToCard WindowOrID))
	  Window OldRegion NewRegion DoneAPutP)
         (NC.ProtectedCardOperation
	   Card "Save Card" InterestedWindow (LET [(WhenSavedFn (GETPROP (NC.FetchType Card)
									   (QUOTE WhenSavedFn]
					          (AND WhenSavedFn (APPLY* WhenSavedFn Card)))
	   (SETQ Window (NC.FetchWindow Card))
	   (OR InterestedWindow (SETQ InterestedWindow (NC.CoerceToInterestedWindow Card)))
	   (if (NC.CheckForNotReadOnly Card InterestedWindow "Can't save cards in ")
	       then (COND
			((OR (NC.CardDirtyP Card)
			       (NC.FetchNewCardFlg Card))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow T (OR OperationMsg "")
							(NC.FetchTitle Card)
							": Saving ... "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "substance, "))
			  (NC.PutMainCardData Card T)
			  (SETQ DoneAPutP T)
			  (NC.MarkCardDirty Card (QUOTE RESET)))
			([AND (NOT (NC.FetchBeingDeletedFlg Card))
				Window
				(OR [NOT (EQUAL (fetch (REGION WIDTH) of (SETQ OldRegion
										     (NC.FetchRegion
										       Card)))
						      (fetch (REGION WIDTH)
							 of (SETQ NewRegion (WINDOWPROP
								  Window
								  (QUOTE REGION]
				      (NOT (EQUAL (fetch (REGION HEIGHT) of OldRegion)
						      (fetch (REGION HEIGHT) of NewRegion]
			  (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow T
								  (OR OperationMsg "")
								  (NC.FetchTitle Card)
								  ": Saving ... "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "region, "))
			  (NC.PutRegion Card)
			  (SETQ DoneAPutP T)))
		      (COND
			((NC.FetchTitleDirtyFlg Card)
			  (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow T
								  (OR OperationMsg "")
								  (NC.FetchTitle Card)
								  ": Saving ... "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "title, "))
			  (NC.PutTitle Card)
			  (SETQ DoneAPutP T)))
		      (COND
			((NC.FetchPropListDirtyFlg Card)
			  (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow T
								  (OR OperationMsg "")
								  (NC.FetchTitle Card)
								  ": Saving ... "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "proplist, "))
			  (NC.PutPropList Card)
			  (SETQ DoneAPutP T)))
		      [COND
			((NC.FetchLinksDirtyFlg Card)
			  (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow T
								  (OR OperationMsg "")
								  (NC.FetchTitle Card)
								  ": Saving ... "))
			  (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "links, "))
                                                             (* Make sure that we have the FROMLINKS of this card.
							     Only necessary because all of the LINKS are written 
							     together.)
			  (RESETLST (until (NC.ApplyFn ObtainWritePermissionFn Card (QUOTE
							     FROMLINKS))
					 do (BLOCK)
					      (NC.PrintMsg InterestedWindow NIL 
						     "waiting for FROMLINKS write permission...."))
				      (RESETSAVE NIL (BQUOTE (APPLY* , (fetch (Card 
									 ReleaseWritePermissionFn)
										of Card)
									   , Card FROMLINKS)))
				      (NC.PutLinks Card)
				      (SETQ DoneAPutP T]   (* It's not a new card anymore.)
		      (FORCEOUTPUT (fetch (NoteFile Stream) of (fetch (Card NoteFile)
									of Card))
				     T)
		      (COND
			((NC.FetchNewCardFlg Card)

          (* If a new card, then make sure we release the FROMLINKS and TITLE. Necessary because DeactivateCard normally 
	  doesn't do this, because the FROMLINKS and TITLE aren't ordinarily owned on an active card.)


			  (NC.ApplyFn ReleaseWritePermissionFn Card (QUOTE FROMLINKS))
			  (NC.ApplyFn ReleaseWritePermissionFn Card (QUOTE TITLE))
			  (NC.SetNewCardFlg Card NIL)))
		      (OR QuietFlg (if DoneAPutP
					 then (NC.PrintMsg InterestedWindow NIL "Done."
							       (CHARACTER 13))
						(NC.ClearMsg InterestedWindow T])
)
(PUTPROPS RGPATCH043 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (697 7644 (NC.CardSaveFn 707 . 7642)))))
STOP