(FILECREATED "30-Mar-87 17:30:08" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH231.;3 12518  

      changes to:  (VARS RHTPATCH231COMS)
		   (FNS NC.CardSaveFn NC.EvaluateListCardSubstance)

      previous date: "30-Mar-87 15:02:50" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH231.;1)


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

(PRETTYCOMPRINT RHTPATCH231COMS)

(RPAQQ RHTPATCH231COMS ((FILES (FROM NOTECARDSNEXT)
				 PMIPATCH024)
			  (* * Fixes various minor interface things. Also changes NC.CardSaveFn so 
			     that messages are only printed if some card part actually changed.)
			  (* * Change to NCTABLETOP)
			  (* * Note that this change should be on top of Peggy's PMIPATCH024)
			  (FNS NCTableTop.NoteFileWhenOpenedFn)
			  (* * Change to NCDATABASE)
			  (FNS NC.SaveDirtyCards NC.CloseListOfActiveCards)
			  (* * Change to NCLISTCARD)
			  (FNS NC.EvaluateListCardSubstance)
			  (* * Change to NCCARDS)
			  (FNS NC.CardSaveFn)))
(FILESLOAD (FROM NOTECARDSNEXT)
	   PMIPATCH024)
(* * Fixes various minor interface things. Also changes NC.CardSaveFn so that messages are 
only printed if some card part actually changed.)

(* * Change to NCTABLETOP)

(* * Note that this change should be on top of Peggy's PMIPATCH024)

(DEFINEQ

(NCTableTop.NoteFileWhenOpenedFn
  (LAMBDA (NoteFile)                                         (* rht: "30-Mar-87 17:24")

          (* * Look for the TableTop card left from previous closing. If there is one, then bring it up.)


    (LET ((TableTopCard (NCP.LookupCardByName (QUOTE NoteFileTableTop)
						NoteFile)))
         (if (NCP.ValidCardP TableTopCard)
	     then (OR (NC.ActiveCardP TableTopCard)
			  (NCP.CacheCards TableTopCard))
		    (if (NC.FetchSubstance TableTopCard)
			then (NCTableTop.BringUpTableTop TableTopCard) 
                                                             (* Smash substance so this table top won't be brought 
							     up next time notefile is opened.)
			       (NCTableTop.RemakeTableTop TableTopCard NIL))))))
)
(* * Change to NCDATABASE)

(DEFINEQ

(NC.SaveDirtyCards
  (LAMBDA (NoteFile TerminateOperationsInProgressFlg InterestedWindow OperationMsg QuietFlg)
                                                             (* rht: "30-Mar-87 14:45")

          (* * Save every card that is both active and dirty to the notefile.)



          (* * rht 9/21/85: Now records cards that were shrunken and reshrinks after checkpoint is completed.)



          (* * fgh 10/15/85 Put in stuff to make using cache array efficient)



          (* * rht 10/20/85: Now uses NC.GetShrunkenWin to find if card's win is shrunken, rather than looking at all open 
	  windows on the screen.)



          (* * rht 11/13/85: Updated to handle new NoteFile and Card formats.)



          (* * fgh 6/13/86 Added TerminateOperationsInProgressFlg OperationMsg & InterestedWindow arg and associated action.)



          (* * kirk/rht 9/10/86 Added QuietFlg)



          (* * rht 3/30/87: Now passes NIL InterestedWindow arg to NC.CardSaveFn so that card's prompt window will be used if
	  possible.)


    (LET (ShrunkenCardWins ActiveCards)
         (NC.MapCards NoteFile (FUNCTION (LAMBDA (Card)
			  (if (NC.ActiveCardP Card)
			      then (push ActiveCards Card))
			  (if (NC.GetShrunkenWin Card)
			      then (push ShrunkenCardWins (NC.FetchWindow Card))))))
         (RESETLST (RESETSAVE NC.ForceSourcesFlg NIL)
		     (RESETSAVE NC.ForceTitlesFlg NIL)
		     (for Card in ActiveCards eachtime (BLOCK)
			do (AND TerminateOperationsInProgressFlg (
				      NC.TerminateCardOperationInProgress Card))
			     (NC.CardSaveFn Card QuietFlg NIL OperationMsg)))
         (for Win in ShrunkenCardWins eachtime (BLOCK) do (SHRINKW Win)))))

(NC.CloseListOfActiveCards
  (LAMBDA (ActiveCards InterestedWindow QuietFlg)            (* rht: "30-Mar-87 14:49")

          (* * Close a list of active cards.)



          (* * rg 3/4/87 added NC.ProtectedSessionOperation wrapper)



          (* * rg 3/12/87 Oops. REMOVED NC.ProtectedSessionOperation wrapper)



          (* * rht 3/30/87: Now passes NIL InterestedWindow arg to NC.QuitCard so it will try to use card's prompt window.)


    (for Card in ActiveCards bind Window
       do (for CardPart in (QUOTE (SUBSTANCE TOLINKS GLOBALTOLINKS PROPLIST))
	       do (OR (NC.ApplyFn ObtainWritePermissionFn Card CardPart)
			  (until (NC.ApplyFn ObtainWritePermissionFn Card CardPart)
			     do (OR QuietFlg (NC.PrintMsg InterestedWindow T
								(CONCAT 
						    "Waiting to obtain write permission for the "
									  CardPart " on card "
									  (NC.FetchTitle Card)
									  "...")))
				  (BLOCK)
			     finally (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "done.")))))
	    (NC.QuitCard Card T NIL T NIL NIL QuietFlg)
	    (if (SETQ Window (NC.FetchWindow Card))
		then (bind (Process ←(WINDOWPROP Window (QUOTE PROCESS)))
			  until (OR (NULL Process)
					(PROCESS.FINISHEDP Process))
			  do (BLOCK))))))
)
(* * Change to NCLISTCARD)

(DEFINEQ

(NC.EvaluateListCardSubstance
  (LAMBDA (Card Message)                                     (* rht: "30-Mar-87 14:55")

          (* * Evaluate the contents of a list card.)


    (if Message
	then (NC.PrintMsg (NC.CoerceToInterestedWindow Card)
			      NIL Message))
    (ERSETQ (for Item in (NCP.CardSubstance Card) do (ERRORSET Item)))))
)
(* * Change to NCCARDS)

(DEFINEQ

(NC.CardSaveFn
  (LAMBDA (WindowOrID QuietFlg InterestedWindow OperationMsg)
                                                             (* rht: "30-Mar-87 17:07")

          (* * 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.)


    (LET ((Card (NC.CoerceToCard WindowOrID))
	  Window OldRegion NewRegion DoneAPutP)
         (SETQ Window (NC.FetchWindow Card))
         (OR InterestedWindow (SETQ InterestedWindow (NC.CoerceToInterestedWindow Card)))
         (NC.ProtectedCardOperation
	   Card "Save Card" InterestedWindow (LET ((WhenSavedFn (GETPROP (NC.FetchType Card)
									   (QUOTE WhenSavedFn))))
					          (AND WhenSavedFn (APPLY* WhenSavedFn 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.)
		      (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 RHTPATCH231 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1268 2110 (NCTableTop.NoteFileWhenOpenedFn 1278 . 2108)) (2144 5382 (NC.SaveDirtyCards 
2154 . 3989) (NC.CloseListOfActiveCards 3991 . 5380)) (5416 5820 (NC.EvaluateListCardSubstance 5426 . 
5818)) (5851 12436 (NC.CardSaveFn 5861 . 12434)))))
STOP