(FILECREATED "13-Jul-86 17:46:18" {QV}<NOTECARDS>1.3K>RHTPATCH065.;2 29653  

      changes to:  (FNS NC.CreateDatabaseFile NC.EditNoteCard)
		   (VARS RHTPATCH065COMS)

      previous date: "13-Jul-86 16:31:04" {QV}<NOTECARDS>1.3K>RHTPATCH065.;1)


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

(PRETTYCOMPRINT RHTPATCH065COMS)

(RPAQQ RHTPATCH065COMS ((* * Some minor interface level changes.)
			  (* * Changes to NCDATABASE)
			  (FNS NC.CreateDatabaseFile NC.CloseDatabaseFile NC.AbortSession 
			       NC.DeleteNoteFile NC.DeleteDatabaseFile)
			  (* * Changes to NCCARDS)
			  (FNS NC.AbortCard NC.QuitCard NC.EditNoteCard)))
(* * Some minor interface level changes.)

(* * Changes to NCDATABASE)

(DEFINEQ

(NC.CreateDatabaseFile
  (LAMBDA (FileName HashArraySize CallingOperationMsg OmitFinalNoteFlg StartingNextFreeIndex 
		    NoSpecialCardsFlg InterestedWindow QuietFlg)
                                                             (* rht: "13-Jul-86 16:00")

          (* * Create a NoteCards database on file FileName. Just creates an index HashArraySize entries long, then writes 
	  out the Root and Orphan cards)



          (* * rht 8/7/84: Added OmitFinalNoteFlg flag parameter to prevent the final message. Changed parameter name from 
	  NC.IndexSizeInEntries to HashArraySize since the fomer is a global.)



          (* * rht 1/30/85: Reserved 3 bytes of the remaining 8 to hold pointer to last checkpointed EOFPTR.)



          (* * rht 3/21/85: Added the StartingNextFreeIndex argument which if non-nil, gives a NextID Num to be filled in to 
	  the file before returning. This is useful when compacting.)



          (* * fkr 11/8/85: Added check that OPENSTREAM succeeded. Added call to NC.CreateNoteFileObject in which lots of 
	  work is now being done.)



          (* * fgh 11/17/85 Wrapped whole thing in ERSETQ to close file if somethinghappens during the create.)



          (* * kirk 26Dec85 Added NoSpecialCardsFlg flag for use by Compact to target file.)



          (* * rht 1/8/86: Now reuses old notefile object if there is one for this file name.)



          (* * rht 7/13/86: Added QuietFlg arg.)


    (LET (Stream NoteFile)
         (OR (CAR (ERSETQ (PROG NIL
				        (SETQ CallingOperationMsg (COND
					    (CallingOperationMsg (CONCAT CallingOperationMsg
									   (CHARACTER 13)))
					    (T "")))
				        (AND (NULL FileName)
					       (NULL (SETQ FileName
							 (NC.DatabaseFileName 
						"What is the name of the NoteFile to be created?"
										" -- " T T NIL 
										InterestedWindow)))
					       (RETURN (QUOTE CANCELLED)))
				        (OR (FIXP HashArraySize)
					      (SETQ HashArraySize NC.DefaultIndexSizeInEntries))
				        (COND
					  ((NULL (SETQ Stream
						     (CAR (ERSETQ (OPENSTREAM
									FileName
									(QUOTE BOTH)
									(QUOTE NEW)
									(QUOTE ((TYPE BINARY))))))))
					    (NC.PrintMsg NIL T "Can't open file: " FileName
							   (CHARACTER 13)
							   "Create cancelled."
							   (CHARACTER 13))
					    (RETURN (QUOTE CANCELLED))))
				        (OR QuietFlg (NC.PrintMsg NIL T CallingOperationMsg 
								      "Creating NoteFile "
								      (FULLNAME Stream)
								      ".  Please wait...  "))
				        (SETQ NoteFile (OR (NC.NoteFileFromFileName FileName)
							       (create NoteFile)))
				        (create NoteFile
					   smashing NoteFile UID ←(NC.MakeUID)
						      Stream ← Stream FullFileName ←(FULLNAME
							Stream)
						      HashArray ←(HASHARRAY HashArraySize)
						      HashArraySize ← HashArraySize NextIndexNum ←(
							OR (FIXP StartingNextFreeIndex)
							     (CONSTANT (ADD1 (fetch
										   (NoteFileVersion
										     
									    NumberOfReservedCards)
										    of (
								     NC.FetchCurrentVersionObject)))
									 ))
						      Version ← NC.VersionNumber NextLinkNum ← 1 
						      CheckptPtr ←(NC.TotalIndexSize HashArraySize)
						      MonitorLock ←(CREATE.MONITORLOCK
							(QUOTE Creating)))
                                                             (* Write the header down to the file.)
				        (NC.PutNoteFileHeader NoteFile)
				        (for CTR from 1 to HashArraySize eachtime (BLOCK)
					   do (OR QuietFlg (AND (ZEROP (IREMAINDER CTR 1000)
									       )
								      (NC.PrintMsg NIL T 
									      CallingOperationMsg 
									     "Creating NoteFile."
										     (CHARACTER
										       13)
										     
									       "Processing item "
										     CTR " out of " 
										    HashArraySize "."
										     (CHARACTER
										       13))))
						(NC.WriteStatus Stream (QUOTE FREE))
						(SETFILEPTR
						  Stream
						  (PLUS (GETFILEPTR Stream)
							  (CONSTANT (SUB1 (fetch (
NoteFileVersion NoteFileIndexWidth) of (NC.FetchCurrentVersionObject)))))))
				        (OR QuietFlg (NC.PrintMsg NIL T CallingOperationMsg 
								      "Creating NoteFile "
								      (FULLNAME Stream)
								      ".  Please wait...  "))
                                                             (* Move NextIndexNum back to the beginning so that 
							     special cards will have the correct index nums.)
				        (replace (NoteFile NextIndexNum) of NoteFile
					   with 1)
				        (OR NoSpecialCardsFlg (NC.InitializeSpecialCards NoteFile)
					      )
				        (NC.CheckpointDatabase NoteFile T)
				        (NC.ForceDatabaseClose NoteFile)
				        (SETQ NC.DatabaseFileNameSuggestion (PACKFILENAME
					    (QUOTE VERSION)
					    NIL
					    (QUOTE BODY)
					    (FULLNAME FileName)))
				        (OR QuietFlg (COND
						(OmitFinalNoteFlg (NC.PrintMsg NIL NIL "  Done!"
										 (CHARACTER 13)))
						(T (NC.PrintMsg NIL NIL "  Done!" (CHARACTER
								    13)
								  "Note that the NoteFile must still" 
								  " be opened before it is used."
								  (CHARACTER 13)))))
				        (RETURN NoteFile))))
	       (CLOSEF Stream (DELFILE (FULLNAME Stream)))
	       (QUOTE CANCELLED)))))

(NC.CloseDatabaseFile
  (LAMBDA (NoteFile InterestedWindow Don'tCheckOperationInProgressFlg QuietFlg)
                                                             (* rht: "13-Jul-86 16:18")
                                                             (* 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.)



          (* * fgh 6/13/86 Now checks for card operations in progress and kills them if necessary.)



          (* * fgh 6/25/86 Added NC.ProtectedNoteFileOperation macro call. Added Don'tCheckOperationInProgressFlg args.)



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



          (* * rht 7/13/86: Added QuietFlg arg. Note that this will cause open cards on the screen to be closed and saved 
	  without asking user for confirmation.)


    (if (NC.ReadOnlyNoteFileP NoteFile)
	then (NC.AbortSession NoteFile InterestedWindow)
      else
       (ALLOW.BUTTON.EVENTS)
       (PROG ((Stream (fetch (NoteFile Stream) of NoteFile))
		(OperationMsg (CONCAT "Closing NoteFile " (fetch (NoteFile FullFileName)
							       of NoteFile)
					(CHARACTER 13)))
		ActiveCards MenuWindow CardTotal)

          (* * Check to see if this NoteFile is busy doing something else)


	       (if (AND (NULL Don'tCheckOperationInProgressFlg)
			    (PROCESSP (NC.NoteFileProp NoteFile (QUOTE ProcessInProgress))))
		   then (NC.PrintOperationInProgressMsg InterestedWindow (QUOTE Close% NoteFile)
							    (NC.NoteFileProp NoteFile (QUOTE
										 OperationInProgress))
							    )
			  (RETURN NIL))

          (* * Make sure NF is open)


	       (if (NULL (NC.NoteFileOpenP NoteFile))
		   then (NC.PrintMsg InterestedWindow T (fetch (NoteFile FullFileName)
							       of NoteFile)
					 " is not an open NoteFile!!!"
					 (CHARACTER 13))
			  (RETURN NIL))

          (* * Do the rest under an operation in progress lock.)


	       (RETURN
		 (NC.ProtectedNoteFileOperation
		   NoteFile Close% NoteFile
		   (PROG NIL

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


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

          (* * Notify the user that closing is in progress.)


		           (OR InterestedWindow (SETQ InterestedWindow
				   (WFROMMENU (fetch (NoteFile Menu) of NoteFile))))
		           (RESETSAVE NIL (BQUOTE (NC.ClearMsg , InterestedWindow T)))

          (* * See if any cards have operations in progress. If so, kill them after confirming with user.)


		           (OR QuietFlg (NC.PrintMsg InterestedWindow T OperationMsg 
						   "Checking for card operations in progress ..."
							 (CHARACTER 13)))
		           (if (EQ (QUOTE ABORT)
				       (NC.CardOperationsInProgress NoteFile T))
			       then (RETURN NIL))
		           (NC.ClearMsg InterestedWindow 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 QuietFlg)
				    (NULL (NC.AskYesOrNo (CONCAT 
					     "There are still cards on the screen from NoteFile "
								       (fetch (NoteFile 
										     FullFileName)
									  of NoteFile)
								       "."
								       (CHARACTER 13)
								       
								  "Want to close and save them? ")
							     " -- "
							     (QUOTE Yes)
							     NIL InterestedWindow 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)


		           (OR QuietFlg (NC.PrintMsg InterestedWindow T OperationMsg 
							 "Checking for active cards ..."
							 (CHARACTER 13)))
		           (if (SETQ ActiveCards (NC.MapCards NoteFile (FUNCTION (LAMBDA (
									  Card)
									Card))
								    (FUNCTION NC.ActiveCardP)))
			       then (OR QuietFlg (NC.PrintMsg InterestedWindow T OperationMsg 
							   "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 T 
									 InterestedWindow 
									 OperationMsg QuietFlg)
							  (if (SETQ Window (NC.FetchWindow
								    Card))
							      then
							       (bind (Process ←(WINDOWPROP
										  Window
										  (QUOTE PROCESS)))
								  until (OR (NULL Process)
										(PROCESS.FINISHEDP
										  Process))
								  do (BLOCK)))))
				      (OR QuietFlg (NC.PrintMsg InterestedWindow NIL "Done."
								    (CHARACTER 13))))

          (* * Checkpoint, then close the file)


		           (OR QuietFlg (NC.PrintMsg InterestedWindow T OperationMsg))
		           (NC.CheckpointDatabase NoteFile QuietFlg T T T InterestedWindow 
						    OperationMsg)
		           (NC.ResetNoteFileInterface NoteFile)
		           (NC.ForceDatabaseClose NoteFile)
		           (NC.ClearMsg InterestedWindow T)

          (* * 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.AbortSession
  (LAMBDA (NoteFile InterestedWindow Don'tConfirmFlg QuietFlg)
                                                             (* rht: "13-Jul-86 16:18")

          (* * Kill the current notecards session. Work lost since last checkpoint.)



          (* * 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 & rht 10/16/85 Update with new cacheing mechanism.)



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



          (* * kirk 20Jan86 Added Don'tCloseFlg to leave NoteFile open after done deleting changes.)



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



          (* * rht 7/2/86: No longer bugs you if no changes were made since last checkpoint. Removed Don'tCloseFlg arg and 
	  added InterestedWindow arg.)



          (* * rht 7/6/86: Now clears InterestedWindow of final truncating message.)



          (* * rht 7/13/86: Added Don'tConfirmFlg and QuietFlg args. Note that Don'tConfirmFlg non-nil stops questioning of 
	  user as to losing all changes.)


    (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
	  (FullFileName (fetch (NoteFile FullFileName) of NoteFile))
	  (LastChkptPtr (fetch (NoteFile CheckptPtr) of NoteFile))
	  EndPtr CardTotal NewBytes)
         (if (AND (STREAMP Stream)
		      (OPENP Stream))
	     then (OR InterestedWindow (SETQ InterestedWindow (WFROMMENU (fetch
										   (NoteFile Menu)
										    of NoteFile))))
		    (SETQ EndPtr (GETEOFPTR Stream))
		    (SETQ NewBytes (IDIFFERENCE EndPtr LastChkptPtr))
		    (if (OR (ZEROP NewBytes)
				Don'tConfirmFlg
				(NC.AskYesOrNo (CONCAT "Do you wish to lose all changes since"
							   (CHARACTER 13)
							   "the last checkpoint (" NewBytes 
							   " bytes) of "
							   FullFileName)
						 "--" "Yes" NIL InterestedWindow NIL T))
			then
			 (LET ((CardNumber 0)
			       (CardTotal (fetch (NoteFile HashArraySize) of NoteFile)))
			      (NC.MapCards
				NoteFile
				(FUNCTION (LAMBDA (Card)
				    (LET (Win)
				         (SETQ CardNumber (ADD1 CardNumber))
				         (OR QuietFlg (COND
						 ((ZEROP (IREMAINDER CardNumber 100))
						   (NC.PrintMsg InterestedWindow T 
								"Quitting from active cards ... "
								  (CHARACTER 13)
								  "Processing item number " 
								  CardNumber " out of " CardTotal "."
								  (CHARACTER 13)))))
				         (COND
					   ((NC.ActiveCardP Card)
					     (SETQ Win (NC.FetchWindow Card))
					     (NC.AbortCard Card QuietFlg)
					     (COND
					       (Win (bind (Process ←(WINDOWPROP Win (QUOTE
										      PROCESS)))
						       until (OR (NULL Process)
								     (PROCESS.FINISHEDP Process))
						       do (BLOCK))
						    (CLOSEW Win))))))))))
			 (COND
			   ((LESSP LastChkptPtr EndPtr)
			     (OR QuietFlg (NC.PrintMsg InterestedWindow T "Truncating file " 
							   FullFileName " ..."))
			     (COND
			       ((NOT (SETFILEINFO FullFileName (QUOTE LENGTH)
						      LastChkptPtr))
				 (NC.PrintMsg InterestedWindow NIL "Couldn't truncate " 
						FullFileName "." (CHARACTER 13))))))
			 (NC.ResetNoteFileInterface NoteFile)
			 (NC.ForceDatabaseClose NoteFile))
		    (NC.ClearMsg InterestedWindow T)
	   else (NC.PrintMsg InterestedWindow T FullFileName " is not an open NoteFile!!!"
				 (CHARACTER 13))))))

(NC.DeleteNoteFile
  (LAMBDA (NoteFile InterestedWindow Don'tConfirmFlg QuietFlg)
                                                             (* rht: "13-Jul-86 16:22")

          (* * rht 7/13/86: Added Don'tConfirmFlg and QuietFlg args.)


    (NC.DeleteDatabaseFile NoteFile InterestedWindow Don'tConfirmFlg QuietFlg)))

(NC.DeleteDatabaseFile
  (LAMBDA (FileNameOrNoteFile InterestedWindow Don'tConfirmFlg QuietFlg)
                                                             (* rht: "13-Jul-86 16:21")
                                                             (* Delete file FileName)

          (* * rht 8/7/84: If delete happens, clear NC.DatabaseFileNameSuggestion.)



          (* * rht 3/17/85: Fixed for case when user specifies version number of file to delete.)



          (* * fkr 11/8/85: Ripped out PSA.Database check. Added check for file open.)



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



          (* * fgh 6/24/86 Added ability to pass down NoteFile object as well as file name. Added code to remove NF from NFs 
	  hash array and remove the menu on the screen.)



          (* * rht 7/2/86: No longer prints completed message with DISMISS. Now returns non-nil if successful.
	  Accepts Don'tConfirmFlg arg.)



          (* * fgh 7/5/86 Added call to RemoveAccessToNoteFile.)



          (* * rht 7/13/86: Added QuietFlg arg.)


    (PROG ((FileName (if (type? NoteFile FileNameOrNoteFile)
			   then (fetch (NoteFile FullFileName) of FileNameOrNoteFile)
			 else FileNameOrNoteFile))
	     FullFileName)                                   (* Make sure no open databases)
                                                             (* Get file name)
	    (AND (NULL FileName)
		   (NULL (SETQ FileName (NC.DatabaseFileName "Name of Notefile to be deleted:" 
								   " -- "
								   T NIL NIL InterestedWindow)))
		   (RETURN NIL))                           (* make sure to be deleted file exists)
	    (SETQ FullFileName (if (FILENAMEFIELD FileName (QUOTE VERSION))
				     then (FULLNAME FileName)
				   else (CAR (FILDIR-EARLIEST FileName))))
	    (COND
	      ((NULL FullFileName)
		(NC.PrintMsg (NC.AttachPromptWindow InterestedWindow)
			       T FileName " does not exist." (CHARACTER 13)
			       "Delete cancelled."
			       (CHARACTER 13))
		(RETURN)))

          (* * Can't delete an open file.)


	    (if (OPENP FullFileName)
		then (NC.PrintMsg (NC.AttachPromptWindow InterestedWindow)
				      T FileName " is an open file." (CHARACTER 13)
				      "Delete cancelled."
				      (CHARACTER 13))
		       (RETURN))                           (* Ask user to confirm twice.)
	    (OR Don'tConfirmFlg (COND
		    ((NOT (NC.AskYesOrNo (CONCAT "Are you sure you want to delete "
						       (CHARACTER 13)
						       FullFileName "?" (CHARACTER 13))
					     " -- " "No" T (NC.AttachPromptWindow InterestedWindow)
					     (NOT InterestedWindow)))
		      (OR QuietFlg (NC.PrintMsg (NC.AttachPromptWindow InterestedWindow)
						    T FullFileName " not deleted." (CHARACTER
						      13)))
		      (RETURN))))
	    (OR QuietFlg (NC.PrintMsg (NC.AttachPromptWindow InterestedWindow)
					  T "Deleteing " FullFileName (CHARACTER 13)))
	    (DISMISS 1000)
	    (OR Don'tConfirmFlg (COND
		    ((NOT (NC.AskYesOrNo (CONCAT "Are you still sure you want to delete "
						       (CHARACTER 13)
						       FullFileName "?" (CHARACTER 13))
					     " -- " "No" T (NC.AttachPromptWindow InterestedWindow)
					     (NOT InterestedWindow)))
		      (OR QuietFlg (NC.PrintMsg (NC.AttachPromptWindow InterestedWindow)
						    T FullFileName " not deleted." (CHARACTER
						      13)))
		      (RETURN))))

          (* * Remove this NF from NoteFiles hash array. array and close down any menu)


	    (NC.RemoveAccessToNoteFile FullFileName)

          (* * Delete the file)


	    (SETQ FullFileName (DELFILE FullFileName))
	    (SETQ NC.DatabaseFileNameSuggestion NIL)
	    (NC.ClearMsg InterestedWindow T)
	    (RETURN FullFileName))))
)
(* * Changes to NCCARDS)

(DEFINEQ

(NC.AbortCard
  (LAMBDA (Card QuietFlg)                                    (* rht: "13-Jul-86 16:16")

          (* * Kill this card's process and its window.)



          (* * fgh 11/13/85 Updated to handle Card object.)



          (* * rht 7/6/86: Now passes non-nil Don'tRecacheFlg to NC.QuitCard.)



          (* * rht 7/13/86: Now takes QuietFlg and passes to NC.QuitCard.)


    (NC.QuitCard Card NIL T T NIL NIL NIL QuietFlg)))

(NC.QuitCard
  (LAMBDA (CardIdentifier CallCloseWFlg DontSaveFlg DontRecacheFlg DontCheckOpInProgressFlg 
			  InterestedWindow OperationMsg QuietFlg)
                                                             (* rht: "13-Jul-86 16:27")

          (* * Force note card specified by ID to quit or stop)



          (* * rht 2/9/85: New arg DontSaveFlg prevents NC.CardSaveFn from being called. Used when aborting a card.
	  This is NOT equivalent to NC.QuitWithoutSaving.)



          (* * rht 6/25/85: Now moves card off screen before saving if NC.CloseCardsOffScreenFlg is non-nil.)



          (* * rht 6/25/85: Brought the insure proper filing check back here from NC.CardSaveFn. Bails out if user cancelled 
	  operation inside of NC.InsureProperFiling)



          (* * fgh 11/11/85: Updated to handle CardID and CardInfo objects.)



          (* * fgh 1/16/86 Put in code to insure that if one of the TopLevelCards is quit then it is reactivated immedialtely
	  to make sure it stays cached for fast access.)



          (* * fgh 2/5/86 Added call to NC.ApplyFn)



          (* * fgh 5/2/86 Added DontRecacheFlg arg)



          (* * fgh 6/9/86 Added code to check to make sure other operations are not in progress. And DontCheckOpInProgressFlg
	  arg to match)



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



          (* * rht 7/2/86: Now bails out if notefile is readonly, user confirms, but we're supposed to write down changes.)



          (* * rht 7/13/86: Now takes QuietFlg arg.)


    (PROG ((Card (NC.CoerceToCard CardIdentifier))
	     Window OperationInProgress ReadOnlyCardFlg)
	    (SETQ Window (NC.FetchWindow Card))
	    (OR InterestedWindow (SETQ InterestedWindow Window))
	    (SETQ ReadOnlyCardFlg (NC.ReadOnlyCardP Card))
                                                             (* The window not being open should mean that it's 
							     shrunken. If so, expand it.)
	    (COND
	      ((AND Window (NOT (OPENWP Window)))
		(EXPANDW Window)))

          (* * if in the middle of some other operation, get out of here.)


	    (if (AND (NULL DontCheckOpInProgressFlg)
			 (SETQ OperationInProgress (NC.OperationInProgress Card)))
		then (NC.PrintOperationInProgressMsg Window "Close Card" OperationInProgress)
		       (RETURN NIL))

          (* * if proper filing says don't quit then get out)


	    (OR DontSaveFlg ReadOnlyCardFlg (COND
		    ((EQ (NC.InsureProperFiling Card)
			   (QUOTE CANCELLED))
		      (RETURN (QUOTE DON'T)))))

          (* * If card is readonly but we've made changes that we're supposed to save, then get user confirmation and bail 
	  out.)


	    (if (AND (NOT DontSaveFlg)
			 ReadOnlyCardFlg
			 (NC.CardSomehowDirtyP Card)
			 (NULL QuietFlg)
			 (NOT (PROGN (NC.PrintMsg InterestedWindow T 
					       "Card has been changed, but notefile is readonly."
							(CHARACTER 13))
					 (NC.AskYesOrNo "Want to quit anyway, flushing changes? " 
							  NIL (QUOTE Yes)
							  NIL InterestedWindow))))
		then (RETURN (QUOTE DON'T)))

          (* * Otherwise go ahead and quit)


	    (RETURN (NC.ProtectedCardOperation Card Close% Card (COND
						   ((AND Window NC.CloseCardsOffScreenFlg)
						     (COND
						       ((NOT (NC.FetchSavedRegion Card))
							 (NC.SetSavedRegion Card
									      (WINDOWPROP
										Window
										(QUOTE REGION)))))
						     (MOVEW Window 1500 1500)))
						 (OR DontSaveFlg (if ReadOnlyCardFlg
								       then (NC.TurnOffDirtyFlgs
										Card)
								     else (NC.CardSaveFn
									      Card
									      (OR 
									NC.CloseCardsOffScreenFlg 
										    QuietFlg)
									      NIL InterestedWindow 
									      OperationMsg)))
						 (AND Window (WINDOWDELPROP
							  Window
							  (QUOTE CLOSEFN)
							  (FUNCTION NC.QuitCard)))
						 (PROG1 (NC.ApplyFn QuitFn Card)
							  (AND CallCloseWFlg Window (CLOSEW
								   Window))

          (* * if this is one of the top level cards, then make sure it stays cached)


							  (if (AND (NC.TopLevelCardP Card)
								       (NULL DontRecacheFlg))
							      then (NCP.ActivateCards Card))))))))

(NC.EditNoteCard
  (LAMBDA (Card Region/Position TypeSpecificArgs)            (* rht: "13-Jul-86 16:30")

          (* * Bring the already created NoteCard specified by ID onto the screen at Region or Position specified by 
	  Region/Position)



          (* * fgh 11/11/85: Updated to handle new Card object.)



          (* * fgh 2/5/86 Added call to NC.ApplyFn)



          (* * kirk 15May86 Added call to NC.AttachNoteFileName)



          (* * rht 7/13/86: Added TypeSpecificArgs arg.)


    (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
		(LET (NoteCardType Window Substance)
		     (COND
		       ((NC.ActiveCardP Card)
			 (SETQ Substance (NC.FetchSubstance Card)))
		       (T (NC.GetNoteCard Card)
			  (SETQ Substance (NC.FetchSubstance Card))))
		     (SETQ NoteCardType (NC.RetrieveType Card))
		     (COND
		       ((WINDOWP (SETQ Window (NC.ApplyFn EditFn Card Substance Region/Position 
							      TypeSpecificArgs)))
			 (WINDOWADDPROP Window (QUOTE CLOSEFN)
					  (FUNCTION NC.QuitCard)
					  (QUOTE FIRST))
			 (WINDOWPROP Window (QUOTE NoteCardObject)
				       Card)
			 (WINDOWPROP Window (QUOTE OldCopyButtonEventFn)
				       (WINDOWPROP Window (QUOTE COPYBUTTONEVENTFN)
						     (FUNCTION NC.CopyButtonEventFn)))
			 (if NC.ShowNoteFileOnCards
			     then (NC.AttachNoteFileName Window))))
		 Window))))
)
(PUTPROPS RHTPATCH065 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (747 23038 (NC.CreateDatabaseFile 757 . 6520) (NC.CloseDatabaseFile 6522 . 14834) (
NC.AbortSession 14836 . 18624) (NC.DeleteNoteFile 18626 . 18965) (NC.DeleteDatabaseFile 18967 . 23036)
) (23070 29571 (NC.AbortCard 23080 . 23546) (NC.QuitCard 23548 . 28079) (NC.EditNoteCard 28081 . 29569
)))))
STOP