(FILECREATED " 5-Jun-86 01:29:53" {QV}<NOTECARDS>1.3K>FGHPATCH054.;3 7878   

      changes to:  (FNS NC.CloseDatabaseFile)
		   (VARS FGHPATCH054COMS)

      previous date: " 5-Jun-86 01:19:26" {QV}<NOTECARDS>1.3K>FGHPATCH054.;1)


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

(PRETTYCOMPRINT FGHPATCH054COMS)

(RPAQQ FGHPATCH054COMS ((* * Part of fix to bug %# 42 -- dirty flg for list and hash cards)
			  (FNS NC.CloseDatabaseFile NC.CheckpointDatabase)))
(* * Part of fix to bug %# 42 -- dirty flg for list and hash cards)

(DEFINEQ

(NC.CloseDatabaseFile
  (LAMBDA (NoteFile)                                         (* fgh: " 5-Jun-86 01:29")
                                                             (* Close the currently open database file.)

          (* * rht 10/23/84: Now gives user option of closing and saving all open cards on the screen.)



          (* * rht 11/8/84: Put RESETLST around NC.CacheTitles call.)



          (* * rht 1/9/85: Clear the NC.UncachingNotCompleted variable when close successfully completes.)



          (* * rht 1/31/85: Added call to checkpoint database. That in turn dumps the next nodeID and next linkID.)



          (* * rht 7/14/85: Replaced the call to reset the main menu with call to NC.ResetMainMenu. Also took out redundant 
	  reset of PSA.Database, since NC.ForceDatabaseClose is doing that.)



          (* * fgh 10/16/85 removed call to CacheTypesAndTitles because uncacheing now done automatically by cache 
	  mechanism.)



          (* * fkr 10/29/85: Now kills caching process from database streamprop.)



          (* * fkr 11/8/85 Updated to handle new NoteFile object and new CardID scheme.)



          (* * kirk 23Jan86 Changed to use NC.AskYesOrNo)



          (* * rht 3/26/86: Now searches for active cards over whole notefile not just among cards up on screen.
	  Uses NC.MapCards.)



          (* * kirk 28Apr86 Now returns NoteFile if successful.)



          (* * fgh 5/2/86 Cleaned up. Ask user to confirm only if there are cards on the screen, not if there are active, but
	  not displayed ones. Added calls to the NC.CloseNoteFileFns before and after the closeing.)



          (* * fgh 6/4/86 Added extra args to call to NC.CheckpointDatabase to prevent double saving of cards.)



          (* * fgh 6/4/86 Fixed so that shrunken cards are counted as open when asking for confirmation when there are open 
	  cards on screen.)


    (PROG ((Stream (fetch (NoteFile Stream) of NoteFile))
	     CardTotal ActiveCards)

          (* * Make sure NF is open)


	    (if (OR (NULL (STREAMP Stream))
			(NOT (OPENP Stream)))
		then (NC.PrintMsg NIL T (fetch (NoteFile FullFileName) of NoteFile)
				      " is not an open NoteFile!!!"
				      (CHARACTER 13))
		       (RETURN NIL))

          (* * Look for cards on the screen. If there are active cards ask the user if they still want to close.)


	    (if (AND (for Window in (OPENWINDOWS)
			    thereis (LET (Card)
				           (AND (SETQ Card
						    (OR (NC.CardFromWindow Window)
							  (AND (WINDOWP (WINDOWPROP
									      Window
									      (QUOTE ICONFOR)))
								 (NC.CardFromWindow
								   (WINDOWPROP Window (QUOTE
										   ICONFOR))))))
						  (NC.SameNoteFileP NoteFile (fetch (Card 
											 NoteFile)
										  of Card)))))
			 (NULL (NC.AskYesOrNo (CONCAT 
					"There are still cards on the screen from this NoteFile "
							    (fetch (NoteFile FullFileName)
							       of NoteFile)
							    "."
							    (CHARACTER 13)
							    "Want to close and save them? ")
						  " -- "
						  (QUOTE Yes)
						  NIL
						  (NC.AttachPromptWindow
						    (WFROMMENU (fetch (NoteFile Menu)
								    of NoteFile)))
						  NIL NIL)))
		then (RETURN NIL))

          (* * Run through CloseNoteFileFns with param of BEFORE. Exit if any returns DON'T)


	    (if (for Function in NC.CloseNoteFileFns thereis
							    (OR (EQ Function (QUOTE DON'T))
								  (EQ (QUOTE DON'T)
									(APPLY* Function NoteFile
										  (QUOTE BEFORE)))))
		then (RETURN NIL))

          (* * Close all the active cards)


	    (if (SETQ ActiveCards (NC.MapCards NoteFile (FUNCTION (LAMBDA (Card)
							 Card))
						     (FUNCTION NC.ActiveCardP)))
		then (NC.PrintMsg NIL T "Closing and saving active cards ... ")
		       (RESETLST (RESETSAVE NC.ForceSourcesFlg NIL)
				   (RESETSAVE NC.ForceFilingFlg NIL)
				   (RESETSAVE NC.ForceTitlesFlg NIL)
				   (for Card in ActiveCards bind Window
				      do (NC.QuitCard Card T NIL T)
					   (if (SETQ Window (NC.FetchWindow Card))
					       then (bind (Process ←(WINDOWPROP Window
										      (QUOTE 
											  PROCESS)))
							 until (OR (NULL Process)
								       (PROCESS.FINISHEDP Process))
							 do (BLOCK)))))
		       (NC.PrintMsg NIL NIL "Done." (CHARACTER 13)))

          (* * Delete the types and titles caching process if still alive.)


	    (DEL.PROCESS (fetch (NoteFile CachingProcess) of NoteFile))

          (* * Checkpoint, then close the file)


	    (NC.PrintMsg NIL T "Closing Notefile ... " (CHARACTER 13))
	    (NC.CheckpointDatabase NoteFile NIL T)
	    (NC.ResetNoteFileInterface NoteFile)
	    (NC.ForceDatabaseClose NoteFile)
	    (NC.PrintMsg NIL T (fetch (NoteFile FullFileName) of NoteFile)
			   " closed.")

          (* * Run through CloseNoteFileFns with param of AFTER. Stop if any returns DON'T)


	    (for Function in NC.CloseNoteFileFns thereis (EQ (QUOTE DON'T)
								     (APPLY* Function NoteFile
									       (QUOTE AFTER))))

          (* * Return the NF)


	    (RETURN NoteFile))))

(NC.CheckpointDatabase
  (LAMBDA (NoteFile QuietFlg Don'tSaveDirtyCardsFlg)         (* fgh: " 5-Jun-86 01:12")

          (* * First save to the database any cards currently dirty. Copy the index array back into the file and set the 
	  LastChkptPtr to the end of the file.)



          (* * rht 11/12/85: Now calls NC.PutHashArray to do the hard work.)



          (* * fgh 6/4/86 Added Don'tSaveDirtyCardsFlg to prevent double passes through active cards at close time)


    (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
	  (FullFileName (fetch (NoteFile FullFileName) of NoteFile))
	  OperationMsg)
         (SETQ OperationMsg (CONCAT "Checkpointing notefile " (FILENAMEFIELD FullFileName
										   (QUOTE NAME))
					(CHARACTER 13)))
         (if (OR (NULL (STREAMP Stream))
		     (NOT (OPENP Stream)))
	     then (NC.PrintMsg NIL T FullFileName " is not an open NoteFile!!!" (CHARACTER
				     13))
	   else (OR QuietFlg (NC.PrintMsg NIL T "Checkpointing notefile " FullFileName " ..."))
		  (if (NULL Don'tSaveDirtyCardsFlg)
		      then (NC.SaveDirtyCards NoteFile))
                                                             (* Put out the new ChkptPtr to the file.)
		  (NC.PutHashArray NoteFile QuietFlg "Checkpointing notefile ")
		  (replace (NoteFile CheckptPtr) of NoteFile with (GETEOFPTR Stream))
		  (NC.PutNoteFileHeader NoteFile)
		  (OR QuietFlg (NC.PrintMsg NIL T OperationMsg "Done." (CHARACTER 13)))))))
)
(PUTPROPS FGHPATCH054 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (566 7796 (NC.CloseDatabaseFile 576 . 6185) (NC.CheckpointDatabase 6187 . 7794)))))
STOP