(FILECREATED "27-Jun-86 20:34:24" {QV}<NOTECARDS>1.3K>FGHPATCH073.;36 148331 

      changes to:  (FNS NC.CloseDatabaseFile NC.GetSpecialCards NC.ListOfNoteFilesMenu)
		   (VARS FGHPATCH073COMS)

      previous date: "27-Jun-86 19:28:13" {QV}<NOTECARDS>1.3K>FGHPATCH073.;34)


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

(PRETTYCOMPRINT FGHPATCH073COMS)

(RPAQQ FGHPATCH073COMS ((* * fix up attached windows so that they reposition themsleves correctly)
	(FNS NC.PrintMsg NC.AskUser NC.AskYesOrNo NC.ClearMsg NC.ClosePropListEditor 
	     NC.AttachNoteFileName NC.SelectNoteCards NC.GETPROMPTWINDOW NC.ShowInfo 
	     NC.OpenPropListEditor)
	(* * Implementation of locks on card operations -- redefined fns)
	(FNS NC.AssignTitle NC.InsureProperFiling NC.AddLinkToCard NC.AddLinksToCard 
	     NC.AddGlobalLinksToCard NC.AddParents NC.UnfileNoteCard NC.QuitCard NC.MakeFilingLinks 
	     NC.CheckFiling NC.QuitWithoutSaving NC.CardSaveFn NC.DeleteNoteCards NC.DeleteNoteCard)
	(* * Implementation of locks on card operations -- new stuff)
	(FNS NC.PrintOperationInProgressMsg NC.CardOperationsInProgress 
	     NC.TerminateCardOperationInProgress NC.OperationInProgress)
	(MACROS NC.ProtectedCardOperation)
	(* * Implementation of locks on NF operations -- old stuff)
	(FNS NC.CloseDatabaseFile NC.OpenDatabaseFile NC.CheckpointDatabase NC.CopyNoteFile 
	     NC.PutHashArray NC.GetHashArray NC.BuildHashArray NC.CardSaveFn NC.SaveDirtyCards 
	     NC.QuitCard)
	(* * Implementation of locks on NF operations -- new stuff)
	(FNS NC.NoteFileProp)
	(MACROS NC.ProtectedNoteFileOperation)
	(* * Old stuff -- implements new NF menu)
	(FNS NC.NoteFileOperations NC.SetUpNoteFileInterface NC.NoteFileMenuWhenSelectedFn 
	     NC.NoteFileIconButtonEventFn NC.ClosedNoteFileMenuWhenSelectedFn NC.ChooseTopLevelCard 
	     NC.GetSpecialCards)
	(* * Redefined stuff fore NoteCards Icon)
	(FNS NC.DoNoteFileOp NC.ListOfNoteFilesMenu)
	(* * New fns for NCINTERFACE)
	(FNS NC.NoteFileMenuWindowP NC.NoteCardsIconWindowP NC.NoteCardsWindowP)
	(DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS (ADDVARS (NLAMA)
									      (NLAML)
									      (LAMA NC.NoteFileProp 
										    NC.PrintMsg)))))
(* * fix up attached windows so that they reposition themsleves correctly)

(DEFINEQ

(NC.PrintMsg
  (LAMBDA Msgs                                               (* fgh: "27-Jun-86 18:55")

          (* Print the msgs in the specified window. First argument is a window to print msg in, second arg is flag telling 
	  whether to clear first, rest of arguments are simply prin1'ed to the msg window)



          (* * rht 7/24/85: Now checks to be sure that window arg is a notecards window. If not, doesn't use promptwindow, 
	  but prints directly to window.)



          (* * rht 9/11/85: Added call to NC.MoveWindowOntoScreen in case we're crammed near the top of screen.)



          (* * fgh 6/8/86 Now opens prompt window to width that matches longest line in Msg.)



          (* * fgh 6/13/86 Now attaches prompt window to NF menus as well as cards.)



          (* * fgh 6/26/86 Now tries to make the window an appropriate width to hold the whole msg. Height remains a 
	  constant.)


    (LET ((Font (FONTCREATE (QUOTE HELVETICA)
			      10))
	  NoteCardWinFlg PromptWin CachedStream Window MaxWidth)
         (SETQ Window (ARG Msgs 1))

          (* * find the maximun line length in the given arg list. Cached on the main window under the PromptWindowLastNotCR 
	  prop is the length of the previous line if it didn't end in a carriage return. Need to add this to the length of 
	  the first line in this call.)


         (SETQ MaxWidth
	   (APPLY
	     (FUNCTION MAX)
	     (OR (bind (LastNotCR ←(if (AND Window (NULL (ARG Msgs 2)))
					   then (WINDOWPROP Window (QUOTE PromptWindowLastNotCR)
								)))
		      for Msg from 3 to Msgs
		      join 

          (* * Parse each arg into a list of line lengths. Set the LastNotCR to the length of the last line in the arg if the
	  arg does not end in a CR. This will be added to the length of the first line in the next arg whether it be in this 
	  call or the next call to Printmsg.)


			     (if (STREQUAL (ARG Msgs Msg)
					       "")
				 then (LIST 0)
			       else
				(while (SETQ Char (GNC CopyString)) as Ctr from 1
				   bind Char (LastCR ← 0)
					  (CopyString ←(SUBSTRING (ARG Msgs Msg)
								    1))
					  (OriginalString ←(SUBSTRING (ARG Msgs Msg)
									1))
				   when (EQ Char (CHARACTER 13))
				   collect (PROG1 (PLUS (OR LastNotCR 0)
							      (STRINGWIDTH
								(OR (SUBSTRING OriginalString
										   (ADD1 LastCR)
										   (SUB1 Ctr))
								      "")
								Font))
						      (SETQ LastCR Ctr)
						      (SETQ LastNotCR 0))
				   finally

          (* if the last line doesn't end in a CR, save its length as LastNotCR but be sure to put its length on the list 
	  anyway in case this is the last call.)


				    (if (NOT (EQP Ctr LastCR))
					then (SETQ $$VAL
						 (CONS (PLUS (OR LastNotCR 0)
								 (STRINGWIDTH
								   (OR (SUBSTRING OriginalString
										      (ADD1 LastCR)
										      (SUB1 Ctr))
									 "")
								   Font))
							 $$VAL))
					       (SETQ LastNotCR (CAR $$VAL))
				      else (SETQ LastNotCR))))
		      finally                              (* Cache the last linelength if it didn't end in a CR,
							     we'll need it to add to the first line next time.)
				(if Window
				    then (WINDOWPROP Window (QUOTE PromptWindowLastNotCR)
							 LastNotCR)))
		   0)))
         (if (IGREATERP Msgs 2)
	     then 

          (* * Figure out the prompt window)


		    (SETQ NoteCardWinFlg (NC.NoteCardsWindowP Window))
		    (COND
		      ((NOT (WINDOWP Window))
			(SETQ PromptWin PROMPTWINDOW))
		      (NoteCardWinFlg (SETQ PromptWin (NC.AttachPromptWindow Window NIL NIL NIL T)
					))
		      (T (SETQ PromptWin Window)))

          (* * If requested, reset all the width cahces.)


		    (if (AND PromptWin (ARG Msgs 2))
			then (WINDOWPROP PromptWin (QUOTE OldMaxWidth)
					     0))

          (* * Set window width to the max width of the current max width and the cached max width from previous lines since 
	  the last clear)


		    (WINDOWPROP PromptWin (QUOTE OldMaxWidth)
				  (SETQ MaxWidth (MAX MaxWidth (OR (WINDOWPROP PromptWin
										       (QUOTE
											 OldMaxWidth))
									 0))))

          (* * Actual width of window is this maxwidth, except that if window is open, don't make it smaller.)


		    (if NoteCardWinFlg
			then (NC.AttachPromptWindow Window (if (OPENWP PromptWin)
								   then (MAX MaxWidth
										 (WINDOWPROP
										   PromptWin
										   (QUOTE WIDTH)))
								 else MaxWidth))
			       (NC.MoveWindowOntoScreen Window))

          (* * Print the msg.)


		    (RESETLST (OR NoteCardWinFlg (RESETSAVE (TTYDISPLAYSTREAM PromptWin)))
				(RESETSAVE NIL (BQUOTE (DSPFONT , (DSPFONT Font PromptWin)
								      , PromptWin)))
				(if (ARG Msgs 2)
				    then (CLEARW PromptWin))
				(LINELENGTH 1000 PromptWin)
				(for Msg from 3 to Msgs collect (PRIN1 (ARG Msgs Msg)
										 PromptWin))))
     PromptWin)))

(NC.AskUser
  (LAMBDA (Msg Prompt FirstTry ClearFirstFlg MainWindow DontCloseAtEndFlg DontClearAtEndFlg 
	       PROMPTFORWORDFlg)                             (* fgh: "27-Jun-86 16:39")
                                                             (* Get a response from the user -
							     using the promptwindow attached to MainWindow)

          (* * rht 9/16/84: Added DontClearAtEndFlg which if non-nil prevents the call to NC.ClearMsg.)



          (* * rht 5/22/85: Now uses TTYIN instead of PROMPTFORWORD so that people can edit their answer.)



          (* * rht 5/30/85: Added PROMPTFORWORDFlg so callers doing yes/no questions can get old style PROMPTFORWORD 
	  functionality.)



          (* * rht 8/6/85: Wrapped TTYIN with NLSETQ so wouldn't break if CR inadvertantly inserted in string.)



          (* * fgh 5/22/86 Added handling of COPYBYBKSYSBUF so that user can shift select into prompt windows being called 
	  from TEdit main windows.)



          (* * fgh 6/27/86 Added ERROR! is problems under TTYIN NLSETQ. Allows other process to kill the askuser process.)


    (LET (AskWindow TextObj)
         (SETQ AskWindow (NC.PrintMsg MainWindow ClearFirstFlg Msg))
         (TTY.PROCESS (THIS.PROCESS))
         (RESETLST 

          (* * If MainWindow is a TEdit window, make sur we can shift select into the prompt window.)


		     (if (SETQ TextObj (WINDOWPROP MainWindow (QUOTE TEXTOBJ)))
			 then (RESETSAVE (TEXTPROP TextObj (QUOTE COPYBYBKSYSBUF)
							 T)
					     (BQUOTE (TEXTPROP , TextObj COPYBYBKSYSBUF ,
								   (TEXTPROP TextObj (QUOTE
										 COPYBYBKSYSBUF))))))

          (* * Go ahead and ask)


		     (PROG1 (if PROMPTFORWORDFlg
				  then (PROMPTFORWORD Prompt FirstTry 
						      "To type a ?, type CTRL-V followed by a ?."
							  AskWindow NIL NIL (CHARCODE (EOL)))
				else (RESETFORM (TTYDISPLAYSTREAM AskWindow)
						    (CAR (OR (NLSETQ
								   (TTYIN (MKLIST (OR Prompt "")
										      )
									    NIL NIL
									    (QUOTE (STRING NORAISE))
									    NIL NIL
									    (AND FirstTry
										   (LIST FirstTry)))
								   )
								 (ERROR!)))))

          (* * Setting the PromptWindow PROCESS to NIL is to break a circularity caused by TEXTOBJ -> PROMPTWINDOW -> PROCESS
	  -> TEXTSTREAM -> TEXTOBJ)


			      (WINDOWPROP AskWindow (QUOTE PROCESS)
					    NIL)
			      (OR DontClearAtEndFlg (NC.ClearMsg MainWindow (NULL 
										DontCloseAtEndFlg)))))
      )))

(NC.AskYesOrNo
  (LAMBDA (Msg Prompt FirstTry ClearFirstFlg MainWindow DontCloseAtEndFlg DontClearAtEndFlg)
                                                             (* fgh: " 9-Jun-86 23:13")

          (* * Get a Yes or No response from the user via keyboard or mouse. Return T if Yes answer and NIL otherwise.)



          (* * kirk 3Feb86 tried unsuccessfully to put a RESETLST RESETSAVE around menu so aborts would close it.)



          (* * fgh 6/8/86 Now uses NC.AttachPromptWindow in place of GETPROMPTWINDOW)


    (LET (Menu MenuWindow PromptWin)

          (* * Determine and open the prompt window if necessary)


         (SETQ PromptWin (NC.PrintMsg MainWindow ClearFirstFlg Msg))

          (* * Attach a yes/no menu to the prompt window)


         (SETQ MenuWindow (ATTACHMENU (SETQ Menu (create
					      MENU
					      ITEMS ←(QUOTE (Yes No))
					      WHENSELECTEDFN ←(FUNCTION (LAMBDA (Item Menu Button)
						  (TTY.PROCESS (WINDOWPROP (MAINWINDOW
										 (WFROMMENU Menu))
									       (QUOTE PROCESS)))
						  (BKSYSBUF (CONCAT Item (CHARACTER 13)))))
					      MENUFONT ←(FONTCREATE (QUOTE HELVETICA)
								      14
								      (QUOTE BOLD))
					      MENUBORDERSIZE ← 1
					      ITEMHEIGHT ← 20
					      ITEMWIDTH ←(TIMES 2 (STRINGWIDTH
								    "Yes"
								    (FONTCREATE (QUOTE HELVETICA)
										  14
										  (QUOTE BOLD))))))
					  PromptWin
					  (COND
					    ((EQ PromptWin PROMPTWINDOW)
					      (QUOTE BOTTOM))
					    (T (QUOTE TOP)))
					  (QUOTE LEFT)))

          (* * print msg in prompt window and wait for user repsonse)


         (NC.YesP (PROG1 (NC.AskUser "" Prompt FirstTry NIL MainWindow T DontClearAtEndFlg T)
			     (DELETEMENU Menu T)
			     (DETACHWINDOW MenuWindow)
			     (if (OR DontCloseAtEndFlg (EQ PromptWin PROMPTWINDOW))
			       else (CLOSEW PromptWin)))))))

(NC.ClearMsg
  (LAMBDA (MainWindow ClosePromptWindowFlg)                  (* fgh: "27-Jun-86 14:29")
                                                             (* Clear and optionally close the promnpt window for 
							     MainWindow)

          (* * rht 9/10/85: Fixed so closes instead of removing prompt window and clears whether prompt win gets closed or 
	  not.)



          (* * rht 11/7/85: Now checks if MainWindow is a NC window. If so, clears its promptwindow. If not, clears 
	  MainWindow itself.)



          (* * fgh 5/1/86 Fix to above fix. If clearing MainWindow, still need to check the ClosePromptWindowFlg.
	  Don't close the main window if this flag in NIL.)



          (* * fgh 6/8/86 Added call to REPOSITIONATTACHEDWINDOWS)



          (* * fgh 6/13/86 Now uses prompt window for NF menus as well as cards.)



          (* * fgh 6/27/86 Updated to match window width changes in NC.PrintMsg)


    (LET (PromptWindow)
         (if (WINDOWP MainWindow)
	     then (if (NC.NoteCardsWindowP MainWindow)
			then (SETQ PromptWindow (NC.GETPROMPTWINDOW MainWindow NIL NIL T))
			       (if (OPENWP PromptWindow)
				   then (CLEARW PromptWindow))
			       (WINDOWPROP PromptWindow (QUOTE MaxLineWidth)
					     NIL)
			       (WINDOWPROP PromptWindow (QUOTE LastLineLength)
					     NIL)
			       (WINDOWPROP PromptWindow (QUOTE OldMaxWidth)
					     0)
			       (WINDOWPROP MainWindow (QUOTE PromptWindowLastNotCR)
					     NIL)
			       (if ClosePromptWindowFlg
				   then (CLOSEW PromptWindow)
					  (REPOSITIONATTACHEDWINDOWS MainWindow))
		      else (CLEARW MainWindow)
			     (if ClosePromptWindowFlg
				 then (CLOSEW MainWindow)))
	   else (CLRPROMPT)))))

(NC.ClosePropListEditor
  (LAMBDA (Window SaveFlg)                                   (* fgh: " 9-Jun-86 00:39")

          (* Close the prop list editor, saving or not saving the edited prop list as specified by the SaveFlg or by the user
	  if SaveFlg is NIL)



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



          (* * fgh 6/8/86 Added call to RAPOSITIONATTACHEDWINDOWS)


    (PROG (TextObj Answered OldPropList NewPropList MainWindow)
	    (SETQ MainWindow (WINDOWPROP Window (QUOTE MAINWINDOW)))
	    (DETACHWINDOW Window)
	    (SETQ TextObj (WINDOWPROP Window (QUOTE TEXTOBJ)))
	    (SETQ OldPropList (WINDOWPROP Window (QUOTE PROPERTYLIST.BEING.EDITED)))
	    (AND TextObj (COND
		     ((EQ SaveFlg (QUOTE Save))
		       (SETQ NewPropList (NC.ExtractPropList Window))
		       (NC.ProcessEditedPropList NewPropList OldPropList (NC.CoerceToCard 
										       MainWindow)))
		     ((EQ SaveFlg (QUOTE NoSave)))
		     ((EQ (WINDOWPROP Window (QUOTE PropListEditor))
			    (QUOTE ShowOnly)))
		     (T (until Answered do (SELECTQ (MENU
							    (OR (AND (BOUNDP (QUOTE 
									      NC.SavePropEditMenu))
									 (type? MENU 
									      NC.SavePropEditMenu)
									 NC.SavePropEditMenu)
								  (SETQ NC.SavePropEditMenu
								    (create MENU
									      ITEMS ←(QUOTE
										(Save% Changes 
										  Cancel% Changes))
									      TITLE ← 
									      "Property Edits?"
									      CENTERFLG ← T))))
							  (Save% Changes (SETQ NewPropList
									   (NC.ExtractPropList
									     Window))
									 (NC.ProcessEditedPropList
									   NewPropList OldPropList
									   (NC.CoerceToCard 
										       MainWindow))
									 (SETQ Answered T))
							  (Cancel% Changes (SETQ Answered T))
							  NIL)))))
	    (WINDOWPROP Window (QUOTE TEDIT.MENU)
			  NIL)
	    (WINDOWPROP Window (QUOTE TEDIT.PROPS)
			  NIL)
	    (WINDOWPROP Window (QUOTE PropListEditor)
			  NIL)
	    (WINDOWDELPROP Window (QUOTE CLOSEFN)
			     (FUNCTION NC.ClosePropListEditor))
	    (COND
	      (TextObj (replace (TEXTOBJ \DIRTY) of TextObj with NIL)
		       (\TEDIT.QUIT (CAR (MKLIST (fetch (TEXTOBJ \WINDOW) of TextObj))))
		       (until (fetch (TEXTOBJ EDITFINISHEDFLG) of TextObj) do (BLOCK))))
	    (ADD.PROCESS (BQUOTE (PROGN (until (NULL (OPENWP , Window)) do (BLOCK))
					      (REPOSITIONATTACHEDWINDOWS , MainWindow)))))))

(NC.AttachNoteFileName
  (LAMBDA (CardWindow OffFlg)                                (* fgh: "13-Jun-86 12:16")

          (* * Attach an indicator of the NoteFile for this Card to the Card)



          (* * fgh 5/29/86 Changed collection of old attached windows to prevent NILs in collection result.)



          (* * fgh 6/13/86 Put detachment and reattachment of previous attached windows into a RESETLST.
	  Added FREEATTACHEDWINDOW as the CLOSEFN of the indicator window. Added code to reset PASSTOMAINWINDOW COMS of the 
	  previously attachwed windows. Changed MINSIZE of indicator window to allow small fonts. Added a REPAINTFN to the 
	  indicator window.)


    (LET ((Card (NC.CardFromWindow CardWindow))
	  AttachedWindows FileName Window)
         (if (NC.CardP Card)
	     then
	      (SETQ AttachedWindows (ATTACHEDWINDOWS CardWindow))
	      (if OffFlg
		  then (CLOSEW (for window in AttachedWindows thereis (WINDOWPROP
										  window
										  (QUOTE 
										NoteFileIndicator))))
			 (REPOSITIONATTACHEDWINDOWS CardWindow)
		else (TOTOPW CardWindow)
		       (if (SETQ Window (for window in AttachedWindows
					       thereis (WINDOWPROP window (QUOTE 
										NoteFileIndicator))))
			   then 

          (* * There already is an indicator window, open and redisplay it.)


				  (OR (OPENWP Window)
					(OPENW Window))
				  (REDISPLAYW Window)
			 else

          (* * No existing indicator window, make one.)


			  (RESETLST

          (* * First arrange to have other attached windows removed and then replaced after the indicator window is made.)


			    (RESETSAVE NIL
					 (BQUOTE (, (FUNCTION (LAMBDA (DescriptionList)
                                                             (* Reattach windows according to information in a 
							     description list.)
							  (for windowDescription in 
										  DescriptionList
							     do (ATTACHWINDOW (CAR 
										windowDescription)
										  CardWindow
										  (CAADR 
										windowDescription)
										  (CADADR 
										windowDescription))
								  (WINDOWPROP (CAR 
										windowDescription)
										(QUOTE 
										   PASSTOMAINCOMS)
										(CADDR 
										windowDescription)))))
						      ,
						      (bind WA for window in AttachedWindows
							 when (EQ (QUOTE TOP)
								      (CAR (SETQ WA
									       (WINDOWPROP
										 window
										 (QUOTE 
										    WHEREATTACHED)))))
							 collect 
                                                             (* Detach attached windows at the top of the main 
							     window and retuirn a list describing their 
							     attachment.)
								   (PROG1
								     (LIST window WA
									     (WINDOWPROP
									       window
									       (QUOTE 
										   PASSTOMAINCOMS)))
								     (DETACHWINDOW window))))))

          (* * Make the indicator window.)


			    (LET (NoteFile FileName YSize IndicatorWindow)
			         (SETQ NoteFile (fetch (Card NoteFile) of Card))
			         (SETQ FileName (NC.MakeNoteFileNameIndicator NoteFile))
			         (SETQ YSize (HEIGHTIFWINDOW (OR (FONTPROP 
									 NC.NoteFileIndicatorFont
										   (QUOTE HEIGHT))
								       20)))
			         (SETQ IndicatorWindow (CREATEW (CREATEREGION 0 0 100 YSize)
								    NIL T))
			         (WINDOWPROP IndicatorWindow (QUOTE MAXSIZE)
					       (CONS 1000 YSize))
			         (WINDOWPROP IndicatorWindow (QUOTE MINSIZE)
					       (CONS 20 YSize))
			         (ATTACHWINDOW IndicatorWindow CardWindow (QUOTE TOP)
						 (QUOTE JUSTIFY)
						 (QUOTE LOCALCLOSE))
			         (WINDOWPROP IndicatorWindow (QUOTE BUTTONEVENTFN)
					       (FUNCTION (LAMBDA (window)
						   (INVERTW window)
						   (NC.SetUpNoteFileInterface
						     (fetch (Card NoteFile)
							of (NC.CardFromWindow (MAINWINDOW
										    window))))
						   (INVERTW window))))
			         (WINDOWPROP IndicatorWindow (QUOTE FileName)
					       FileName)
			         (WINDOWPROP IndicatorWindow (QUOTE REPAINTFN)
					       (FUNCTION (LAMBDA (Window Region)
						   (CLEARW Window)
						   (PRIN1 (WINDOWPROP Window (QUOTE FileName))
							    Window))))
			         (DSPFONT NC.NoteFileIndicatorFont IndicatorWindow)
			         (PRIN1 FileName IndicatorWindow)
			         (OPENW IndicatorWindow)
			         (WINDOWPROP IndicatorWindow (QUOTE NoteFileIndicator)
					       (QUOTE Showing))))))))))

(NC.SelectNoteCards
  (LAMBDA (SingleCardFlg SelectionPredicate Menu InstigatingCardOrWindow ReturnLinksFlg Msg 
			 CheckForCancelFlg)                  (* fgh: " 9-Jun-86 19:30")

          (* Select a set of note cards or a single note card, depending on SingleCardFlg. Works by interpreting all mouse 
	  presses until a card has been chosen (if SingleCardFlg is T) or until the Done button has been pressed 
	  (if SingleCardFlg is NIL). If the mouse press occus within a Title bar of a notecard, add that note card to the 
	  selected list. Otherwise, if you are pointing into a note card, call the BUTTONEVENTFN for that note card.
	  The Selection in Progress flag has been set, so all note card BUTTONEVENTFNs should know to ignore all presses 
	  except those that occur on link icons. Link icon presses should simply add the desination of that link to the 
	  selected note cards list.)



          (* * rht 8/1/84: Changed second RESETSAVE call to give NC.ClearMsg a NIL argument.)



          (* * rht 1/9/85: Fixed so now prints name of selected item even it's a link.)



          (* * rht 2/15/85: Now can backspace over last selection chosen. Added new arg Msg so that when we reprint the list,
	  we can reprint the message as well.)



          (* * rht 3/23/85: Added the CheckForCancelFlg arg, which if non-nil causes Cancel to be handled differently then 
	  Done after no selections. Namely, Cancel will return the atom CANCELLED whereas Done with no selections returns 
	  NIL. If CheckForCancelFlg is NIL then NIL is returned in both cases.)



          (* * fgh 11/14/85 Updated to handle Card and NoteFile objects.)



          (* * rht 11/18/85: Fixed so able to select when InstigatingNoteFile is NIL.)



          (* * fgh 12/20/85 Totally rewritten for 1.3 selection mechanism. Based on COPYINSERT now rather than on takingf 
	  over the mouse process.)



          (* * fgh 1/15/86 Added call to SPAWN.MOUSE in case this is called under the mouse process)



          (* * kirk 25Apr86 Changed to use SessionIcon (NC.NoteCardsIconWindow) rather than PROMPTWINDOW if no Instigating 
	  window is supplied.)


    (RESETLST (LET (Window Card ButtonEventFn InstigatingWindow InstigatingCard InstigatingNoteFile 
			     MenuWindow PromptWindow CopyInsertEvent SelectedCards 
			     PromptWindowProcess)
		     (OR SelectionPredicate (SETQ SelectionPredicate (FUNCTION TRUE)))
		     (COND
		       ((NC.CardP InstigatingCardOrWindow)
			 (SETQ InstigatingWindow (NC.FetchWindow InstigatingCardOrWindow))
			 (SETQ PromptWindow (NC.AttachPromptWindow InstigatingWindow)))
		       ((WINDOWP InstigatingCardOrWindow)
			 (SETQ InstigatingWindow InstigatingCardOrWindow)
			 (SETQ PromptWindow (NC.AttachPromptWindow InstigatingWindow)))
		       (T (SETQ InstigatingWindow (SETQ PromptWindow (NC.AttachPromptWindow
				NC.NoteCardsIconWindow)))))
		     (SETQ InstigatingCard (NC.CoerceToCard InstigatingCardOrWindow))
		     (SETQ InstigatingNoteFile (AND InstigatingCard (fetch (Card NoteFile)
									   of InstigatingCard)))
		     (NC.PrintMsg InstigatingWindow T (COND
				      (Msg (CONCAT Msg (CHARACTER 13)))
				      (T ""))
				    "Items selected:  ")

          (* * if we are running under the mouse process, start up a new mouse process)


		     (AND (EQ (QUOTE MOUSE)
				  (PROCESSPROP (THIS.PROCESS)
						 (QUOTE NAME)))
			    (SPAWN.MOUSE))

          (* * Set up the prompt window for proper use by the CopyInsertFn)


		     (WINDOWPROP PromptWindow (QUOTE COPYINSERTFN)
				   (FUNCTION NC.SelectNoteCardsCopyInsertFn))
		     (WINDOWPROP PromptWindow (QUOTE CopyInsertEvent)
				   (SETQ CopyInsertEvent (CREATE.EVENT (QUOTE CopyInsertEvent)))
				   )
		     (RESETSAVE (WINDOWPROP PromptWindow (QUOTE SelectedCards)
						NIL)
				  (BQUOTE (WINDOWPROP , PromptWindow (QUOTE SelectedCards)
							  NIL)))
		     (RESETSAVE (WINDOWPROP PromptWindow (QUOTE SelectingCards)
						T)
				  (BQUOTE (WINDOWPROP , PromptWindow SelectingCards NIL)))

          (* * Make the process behind the prompt window includiong control for a blibnking cursor)


		     (WINDOWPROP PromptWindow (QUOTE PROCESS)
				   (SETQ PromptWindowProcess
				     (ADD.PROCESS (QUOTE (PROG NIL (BLOCK)
								     (TTYDISPLAYSTREAM
								       (PROCESSPROP (THIS.PROCESS)
										      (QUOTE WINDOW)
										      ))
								     XXXX
								     (BIN)
								     (BLOCK)
								     (GO XXXX)))
						    (QUOTE WINDOW)
						    PromptWindow
						    (QUOTE NAME)
						    (QUOTE SelectNoteCardsProc)
						    (QUOTE TTYENTRYFN)
						    (FUNCTION (LAMBDA (Process)
							(PROCESSPROP Process (QUOTE OldCaret)
								       (CARET CROSSHAIRS))
							(ECHOMODE)))
						    (QUOTE TTYEXITFN)
						    (FUNCTION (LAMBDA (Process)
							(CARET (PROCESSPROP Process (QUOTE
										  OldCaret)))
							(ECHOMODE T))))))
		     (RESETSAVE NIL (BQUOTE (DEL.PROCESS , PromptWindowProcess)))

          (* * Insure the prompt window is cleared on the way out)


		     (RESETSAVE NIL (BQUOTE (PROGN (AND (HASTTYWINDOWP , 
									      PromptWindowProcess)
								(TTY.PROCESS T))
							 (NC.ClearMsg , InstigatingWindow T))))

          (* * Set up the menu above the prompt window)

                                                             (* fix in case MENUPOSITION is set incorrectly in menu
							     passed down)
		     (replace (MENU MENUPOSITION) of Menu
			with (CONSTANT (create POSITION
						     XCOORD ← 0
						     YCOORD ← 0)))
		     (RESETSAVE (ATTACHMENU Menu PromptWindow (if InstigatingWindow
								      then (QUOTE TOP)
								    else (QUOTE BOTTOM))
						(QUOTE LEFT))
				  (BQUOTE (PROGN (DETACHWINDOW (WFROMMENU , Menu))
						     (DELETEMENU , Menu T))))

          (* * If there is an instigating window, make sure it and all its attachments are visible on the screen.)


		     (if InstigatingWindow
			 then (NC.MoveWindowOntoScreen InstigatingWindow))

          (* * Give the prompt window the tty process)


		     (TTY.PROCESS (WINDOWPROP PromptWindow (QUOTE PROCESS)))

          (* * Loop as long as necessary)


		     (until (OR (EQ SelectedCards (QUOTE CANCELLED))
				    (AND SingleCardFlg SelectedCards)
				    (EQ (CAR SelectedCards)
					  (QUOTE DONE)))
			do (

          (* * Wait for the user to respond by copy inserting something into the prompt window)


			      (until (EQ CopyInsertEvent (AWAIT.EVENT CopyInsertEvent))
				 do NIL)

          (* * Get the latest selection list)


			      (SETQ SelectedCards (WINDOWPROP PromptWindow (QUOTE SelectedCards)
								  ))
			      (RESETLST 

          (* * Turn off the caret)


					  (RESETSAVE (TTY.PROCESS (THIS.PROCESS)))

          (* * If the last thing wasn't a done or cancel, process the new selection)


					  (COND
					    ((AND (NEQ (CAR SelectedCards)
							   (QUOTE DONE))
						    (NEQ SelectedCards (QUOTE CANCELLED))
						    (NEQ (CAR SelectedCards)
							   (QUOTE *New% Card*)))

          (* * Check to make sure that the selection is valid)


					      (COND
						((EQ (CAR SelectedCards)
						       (QUOTE *Undo% Selection*))
                                                             (* Chop off two elements from the list -
							     the indicator and the previous item.)
						  (WINDOWPROP PromptWindow (QUOTE SelectedCards)
								(SETQ SelectedCards (CDDR 
										    SelectedCards)))
						  (NC.ClearMsg InstigatingWindow NIL))
						((AND InstigatingNoteFile (CAR SelectedCards)
							(NOT (NC.SameNoteFileP
								 (fetch (Card NoteFile)
								    of (CAR SelectedCards))
								 InstigatingNoteFile)))
                                                             (* This card not from the same NoteFile)
						  (NC.PrintMsg InstigatingWindow T 
								 "Cannot link across NoteFiles."
								 (CHARACTER 13))
						  (WINDOWPROP PromptWindow (QUOTE SelectedCards)
								(SETQ SelectedCards (CDR 
										    SelectedCards))))
						((NULL (APPLY* SelectionPredicate (CAR 
										    SelectedCards)))
                                                             (* Does this card match the slection predicate)
						  (NC.PrintMsg InstigatingWindow T 
								 "*** Invalid selection. ***"
								 (CHARACTER 13))
						  (WINDOWPROP PromptWindow (QUOTE SelectedCards)
								(SETQ SelectedCards (CDR 
										    SelectedCards))))
						(T           (* A valid selection.)
						   (NC.ClearMsg InstigatingWindow NIL)))

          (* * Print the results in the prompt window)


					      (NC.PrintMsg InstigatingWindow NIL
							     (COND
							       (Msg (CONCAT Msg (CHARACTER 13)))
							       (T ""))
							     "Items selected:  ")
					      (for Card in (REVERSE SelectedCards)
						 do (NC.PrintMsg InstigatingWindow NIL
								     (NC.RetrieveTitle Card)
								     ",  ")))))))

          (* * Return the result)


		     (PROG1 (COND
				((EQ SelectedCards (QUOTE CANCELLED))
				  (COND
				    (CheckForCancelFlg (QUOTE CANCELLED))
				    (T NIL)))
				(SingleCardFlg (if (EQ (CAR SelectedCards)
							   (QUOTE DONE))
						   then NIL
						 else (CAR SelectedCards)))
				(T (if (EQ (CAR SelectedCards)
					       (QUOTE DONE))
				       then (DREVERSE (CDR SelectedCards))
				     else (DREVERSE SelectedCards))))
			      (WINDOWPROP PromptWindow (QUOTE SelectedCards)
					    NIL))))))

(NC.GETPROMPTWINDOW
  (LAMBDA (MAINWINDOW %#LINES FONT DONTCREATE MINWIDTH)    (* fgh: "13-Jun-86 18:40")

          (* makes sure that MAINWINDOW has an attached promptwindow and returns it. If one already exists, it is shaped to 
	  be at least %#LINES high. If FONT is NIL, the font of the main window is used for the promptwindow.)



          (* * fgh 6/6/86 Adapted from system GETPROMPTWINDOW. Added MINWIDTH arg.)


    (PROG ((PWINDOWPROP (WINDOWPROP MAINWINDOW (QUOTE PROMPTWINDOW)))
	     (PWINDOWMINWIDTH (WINDOWPROP MAINWINDOW (QUOTE PROMPTWINDOWMINWIDTH)))
	     PWINDOW WIDTH HEIGHT OBSCUREDHEIGHT PWINDOW.PWINDOW)
	    (COND
	      (DONTCREATE (RETURN (CAR PWINDOWPROP)))
	      (PWINDOWPROP (SETQ PWINDOW (CAR PWINDOWPROP))
			   (COND
			     ((NOT (OPENWP PWINDOW))
			       (ATTACHWINDOW PWINDOW MAINWINDOW (QUOTE TOP)
					       (QUOTE LEFT)
					       (QUOTE LOCALCLOSE))))
			   (if (SETQ PWINDOW.PWINDOW (WINDOWPROP PWINDOW (QUOTE PROMPTWINDOW))
				   )
			       then                        (* This prompt window has a prompt window of its own.
							     Close and detach it.)
				      (FREEATTACHEDWINDOW (CAR PWINDOW.PWINDOW))
				      (CLOSEW (CAR PWINDOW.PWINDOW)))
			   (WINDOWPROP PWINDOW (QUOTE MAXSIZE)
					 (CONS 64000 64000))
			   (WINDOWPROP PWINDOW (QUOTE MINSIZE)
					 (CONS 1 1))
			   (SETQ HEIGHT (HEIGHTIFWINDOW (TIMES (OR %#LINES (CDR PWINDOWPROP)
									   1)
								     (FONTPROP (DSPFONT NIL 
											  PWINDOW)
										 (QUOTE HEIGHT)))))
			   (SETQ WIDTH (MAX (WIDTHIFWINDOW (OR MINWIDTH PWINDOWMINWIDTH 1))
						(fetch (REGION WIDTH) of (WINDOWPROP
									       MAINWINDOW
									       (QUOTE REGION)))))
			   (COND
			     ((OR (NOT (EQP HEIGHT (fetch (REGION HEIGHT)
							    of (WINDOWPROP PWINDOW (QUOTE
										 REGION)))))
				    (NOT (EQP WIDTH (fetch (REGION WIDTH)
							   of (WINDOWPROP PWINDOW (QUOTE REGION)
									      )))))
                                                             (* Window exists, but not right size.)
			       (SHAPEW PWINDOW (create REGION using (WINDOWPROP PWINDOW
											(QUOTE
											  REGION))
									  HEIGHT ← HEIGHT WIDTH ← 
									  WIDTH))
			       (RPLACD PWINDOWPROP %#LINES)
                                                             (* Fall through to check visibility)
			       )))
	      (T (SETQ PWINDOW (CREATEW (create REGION
						      LEFT ← 0
						      BOTTOM ← 0
						      WIDTH ←(MAX (OR MINWIDTH 1)
								    (fetch (REGION WIDTH)
								       of (WINDOWPROP
									      MAINWINDOW
									      (QUOTE REGION))))
						      HEIGHT ←(SETQ HEIGHT
							(HEIGHTIFWINDOW
							  (TIMES (OR %#LINES (SETQ %#LINES 1))
								   (FONTPROP (OR FONT
										     (SETQ FONT
										       (DSPFONT
											 NIL 
										       MAINWINDOW)))
									       (QUOTE HEIGHT))))))
					    NIL NIL T))
		 (DSPSCROLL T PWINDOW)
		 (DSPFONT FONT PWINDOW)
		 (WINDOWPROP PWINDOW (QUOTE PAGEFULLFN)
			       (QUOTE NILL))
		 (ATTACHWINDOW PWINDOW MAINWINDOW (QUOTE TOP)
				 (QUOTE LEFT)
				 (QUOTE LOCALCLOSE))
		 (WINDOWPROP MAINWINDOW (QUOTE PROMPTWINDOW)
			       (CONS PWINDOW %#LINES))
		 (WINDOWPROP PWINDOW (QUOTE OPENFN)
			       (FUNCTION \PROMPTWINDOW.OPENFN))))
	    (COND
	      ((ILESSP (SETQ OBSCUREDHEIGHT (IDIFFERENCE SCREENHEIGHT
							       (fetch (REGION TOP)
								  of (WINDOWPROP PWINDOW
										     (QUOTE REGION))
									)))
			 0)                                  (* Promptwindow off screen at top, so slip window 
							     group down to make it visible)
		(RELMOVEW MAINWINDOW (create POSITION
						 XCOORD ← 0
						 YCOORD ← OBSCUREDHEIGHT))))
	    (WINDOWPROP PWINDOW (QUOTE MINSIZE)
			  (CONS 1 HEIGHT))
	    (WINDOWPROP PWINDOW (QUOTE MAXSIZE)
			  (CONS 64000 HEIGHT))
	    (WINDOWPROP MAINWINDOW (QUOTE PROMPTWINDOWMINWIDTH)
			  (OR MINWIDTH 1))
	    (OPENW PWINDOW)
	    (RETURN PWINDOW))))

(NC.ShowInfo
  (LAMBDA (Window)                                           (* fgh: "13-Jun-86 12:39")

          (* * Bring up an inspector on certain attribute/value pairs of this card. The default ones are card part dates and 
	  Updates.)



          (* * Need a hook so that users can provide other attribute/value pairs for given card types.)



          (* * kirk: 1May86 added NC.AttachNoteFileName)



          (* * fgh 6/13/86 Now places and sizes window with less visual nnoise.)


    (LET ((Card (NC.CoerceToCard Window))
	  (Attributes (QUOTE (CardUID ItemDate TitleDate LinksDate PropsDate Updates)))
	  Region AttributesAndValues InfoWindow)
         (NC.AttachNoteFileName Window)
         (SETQ Region (WINDOWREGION Window))
         (for window in (ATTACHEDWINDOWS Window) when (WINDOWPROP window (QUOTE ShowInfo))
	    do (CLOSEW Window))                          (* close any previous info window)
         (SETQ AttributesAndValues (LIST (QUOTE CardUID)
					     (fetch (Card UID) of Card)
					     (QUOTE ItemDate)
					     (NC.FetchItemDate Card)
					     (QUOTE TitleDate)
					     (NC.FetchTitleDate Card)
					     (QUOTE LinksDate)
					     (NC.FetchLinksDate Card)
					     (QUOTE PropsDate)
					     (NC.FetchPropListDate Card)
					     (QUOTE Updates)
					     (LISTGET (NC.FetchPropList Card)
							(QUOTE Updates))))
         (SETQ InfoWindow (INSPECTW.CREATE AttributesAndValues Attributes (FUNCTION LISTGET)
					       NIL "Can't set values of these attributes." NIL NIL 
					       "Card attributes"
					       NIL
					       (CREATEW (CREATEREGION (fetch (POSITION XCOORD)
									     of 
									     NC.OffScreenPosition)
									  (fetch (POSITION YCOORD)
									     of 
									     NC.OffScreenPosition)
									  (fetch (REGION WIDTH)
									     of Region)
									  50)
							  NIL NIL)))
         (SHAPEW InfoWindow (create REGION
				 using (WINDOWPROP InfoWindow (QUOTE REGION))
					 HEIGHT ←(HEIGHTIFWINDOW (fetch (REGION HEIGHT)
								      of (WINDOWPROP
									     InfoWindow
									     (QUOTE EXTENT)))
								   T)))
         (ATTACHWINDOW InfoWindow Window (QUOTE TOP)
			 (QUOTE JUSTIFY)
			 (QUOTE LOCALCLOSE))
         (NC.MoveWindowOntoScreen Window)
         (REDISPLAYW InfoWindow)
         (WINDOWPROP InfoWindow (QUOTE ShowInfo)
		       (QUOTE Showing))
         (WINDOWADDPROP InfoWindow (QUOTE CLOSEFN)
			  (FUNCTION FREEATTACHEDWINDOW)
			  T))))

(NC.OpenPropListEditor
  (LAMBDA (WindowOrTextStream PropList Title ShowOnlyFlg MakeImageObjFlg)
                                                             (* fgh: "12-Jun-86 17:56")
                                                             (* Open a property list editor above the card 
							     specified by TextStream , which is either a TextStream
							     or a Window)
    (PROG ((Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))
	     (SystemProperties (QUOTE (ID Updates ItemDate LinksDate PropsDate TitleDate)))
	     EditWindow CardUID)                             (* Make sure there is no prop list editor already 
							     there)
	    (AND (NC.PropListEditorOpenP Window)
		   (RETURN))
	    (SETQ CardUID (fetch (Card UID) of (NC.CoerceToCard Window)))
                                                             (* FOR each prop/value pair with LISTP value.
							     Make a series of individual prop/value pairs 
							     corresponding to the elements of the LISTP)
	    (SETQ PropList (for Item on PropList by (CDDR Item)
				join (COND
					 ((NLISTP (CADR Item))
					   (LIST (create PropListItem
							     PropertyName ←(CAR Item)
							     Value ←(CADR Item)
							     OriginalListFlg ← NIL
							     AllowEditFlg ← NIL
							     AllowSelectFlg ← NIL
							     ButtonFn ← NIL)))
					 (T (for Element in (CADR Item)
					       collect (create PropListItem
								   PropertyName ←(CAR Item)
								   Value ← Element
								   OriginalListFlg ← T
								   AllowEditFlg ← NIL
								   AllowSelectFlg ← NIL
								   ButtonFn ← NIL))))))
                                                             (* If specified, translate all NOTECARDLINK values 
							     into Image Objects for display.)
	    (AND MakeImageObjFlg (for Item in PropList bind LinkIcon
				      when (type? Link (fetch (PropListItem Value)
							      of Item))
				      do (replace (PropListItem Value) of Item
					      with (SETQ LinkIcon (NC.MakeLinkIcon
							 (fetch (PropListItem Value) of Item)))
						     (IMAGEOBJPROP LinkIcon (QUOTE 
									     InsidePropListEditor)
								     T))))
                                                             (* Indicate which properties can be edited by user.)
	    (for Item in PropList do (COND
					     ((FMEMB (fetch (PropListItem PropertyName)
							  of Item)
						       SystemProperties)
					       (replace (PropListItem AllowEditFlg) of Item
						  with T)
					       (replace (PropListItem AllowSelectFlg) of Item
						  with T))
					     (ShowOnlyFlg (replace (PropListItem AllowEditFlg)
							     of Item with NIL)
							  (replace (PropListItem AllowSelectFlg)
							     of Item with T))
					     (T (replace (PropListItem AllowEditFlg) of Item
						   with NIL)
						(replace (PropListItem AllowSelectFlg)
						   of Item with NIL))))
                                                             (* Call the prop list editor)
	    (ATTACHWINDOW (SETQ EditWindow (CREATEW (CREATEREGION 1000 2000 100 100)
							  (OR Title "Edit Property List")
							  NIL T))
			    Window
			    (QUOTE TOP)
			    (QUOTE JUSTIFY)
			    (QUOTE LOCALCLOSE))
	    (WINDOWADDPROP EditWindow (QUOTE CLOSEFN)
			     (FUNCTION FREEATTACHEDWINDOW)
			     T)
	    (WINDOWADDPROP EditWindow (QUOTE CLOSEFN)
			     (FUNCTION NC.ClosePropListEditor)
			     T)
	    (WINDOWPROP EditWindow (QUOTE PropListEditor)
			  (COND
			    (ShowOnlyFlg (QUOTE ShowOnly))
			    (T T)))
	    (NC.EditPropList PropList EditWindow ShowOnlyFlg)
	    (RETURN EditWindow))))
)
(* * Implementation of locks on card operations -- redefined fns)

(DEFINEQ

(NC.AssignTitle
  (LAMBDA (CardIdentifier NoClearMsgFlg NewTitle)            (* fgh: "27-Jun-86 16:25")

          (* * Change the title of the card specified by the WindowOrTextStreamOrID)



          (* * rht 2/1/85: Changed from NC.PutTitle to NC.SetTitleDirtyFlg, unless card is not active.
	  We shouldn't be writing to the notefile until save time.)



          (* * fgh 11/11/85: Added support for CardID, CardInfo and noteFile objects. Also entered call to Nc.StoreTitle.)



          (* * fgh 6/9/86 Added code to check to make sure that another operation is not in progress on this card when this 
	  fn is called.)



          (* * fgh 6/13/86 Now spawns mouse in case called under MOUSE process.)



          (* * fgh 6/27/86 returns T if completed okay.)


    (ALLOW.BUTTON.EVENTS)
    (LET ((Card (NC.CoerceToCard CardIdentifier))
	  ContainingCard OldTitle Window OperationInProgress)
         (SETQ Window (NC.FetchWindow Card))
         (if (AND (NULL NewTitle)
		      (SETQ OperationInProgress (NC.OperationInProgress Card)))
	     then 

          (* * Another interaction operation is in progress on this card and we have to interact with the user.
	  Can't do.)


		    (NC.PrintOperationInProgressMsg Window "Assign Title" OperationInProgress)
	   else (NC.ProtectedCardOperation Card AssignTitle
					     (COND
					       ((SETQ NewTitle
						   (OR (STRINGP NewTitle)
							 (AND NewTitle (OR (LITATOM NewTitle)
									       (NUMBERP NewTitle))
								(MKSTRING NewTitle))
							 (NC.AskUser
							   (CONCAT "Enter the title for this card"
								     (CHARACTER 13))
							   "-->  "
							   (COND
							     ((AND (STREQUAL (SETQ OldTitle
										   (NC.RetrieveTitle
										     Card))
										 "Untitled")
								     (NC.FetchNewCardFlg Card))
							       NIL)
							     (T OldTitle))
							   (NULL NoClearMsgFlg)
							   Window)))
						 (NC.SetTitle Card NewTitle)
						 (COND
						   ((NC.ActiveCardP Card)
						     (NC.SetTitleDirtyFlg Card T))
						   (T (NC.PutTitle Card)
						      (NC.SetTitleDirtyFlg Card NIL)))
						 (AND (WINDOWP Window)
							(WINDOWPROP Window (QUOTE TITLE)
								      NewTitle))
						 (for FromLink in (NC.RetrieveFromLinks Card)
						    do (AND (NC.ActiveCardP
								  (SETQ ContainingCard
								    (fetch (Link SourceCard)
								       of FromLink)))
								(WINDOWP (NC.FetchWindow 
										   ContainingCard))
								(NC.UpdateLinkImages ContainingCard 
										       Card)))))))
     T)))

(NC.InsureProperFiling
  (LAMBDA (Card)                                             (* fgh: "27-Jun-86 16:28")
                                                             (* Called when any type of note card is being quitted 
							     from, i.e., closed)

          (* * rht 12/9/84: Moved check of the NC.ForceFiling flag into NC.CheckContentsHooks.)



          (* * fgh 11/12/85 Updated to handle Card and NoteFile objects.)



          (* * fgh 6/27/86 Changed format to allow being killed by ERROR!)


    (COND
      ((NULL (NC.FetchBeingDeletedFlg Card))
	(if (NC.CheckTitle Card)
	    then (if (OR (NULL NC.ForceSourcesFlg)
			       (NC.CheckSources Card))
		       then (NC.CheckFiling Card)))))))

(NC.AddLinkToCard
  (LAMBDA (CardIdentifier LinkOrLinkLabel DestinationCard)   (* fgh: "13-Jun-86 17:12")

          (* * Add a link to card designated by CardIdentifier. Rest of args can be NIL. Currently, this dispatches on card 
	  type. Should eventually call something like an InsertLinkFn.)



          (* * fgh 6/9/86 Added code to check to make sure that another operation is not in progress on this card when this 
	  fn is called.)


    (LET ((Card (NC.CoerceToCard CardIdentifier))
	  CardType Window OperationInProgress)
         (SETQ Window (NC.FetchWindow Card))
         (if (AND (NULL LinkOrLinkLabel)
		      (NULL DestinationCard)
		      (SETQ OperationInProgress (NC.OperationInProgress Card)))
	     then 

          (* * Another interaction operation is in progress on this card and we have to interact with the user.
	  Can't do.)


		    (NC.PrintOperationInProgressMsg Window "Insert Link" OperationInProgress)
	   else 

          (* * Add the link)


		  (NC.ProtectedCardOperation Card InsertLink (SETQ CardType (NC.FetchType Card))
					     (OR LinkOrLinkLabel (SETQ LinkOrLinkLabel
						     (NC.AskLinkLabel Window NIL NIL T T)))
					     (AND LinkOrLinkLabel (COND
						      ((NC.IsSubTypeOfP CardType (QUOTE Text))
							(NC.InsertLinkInText (NC.FetchSubstance
										 Card)
									       LinkOrLinkLabel 
									       DestinationCard Card))
						      ((NC.IsSubTypeOfP CardType (QUOTE Graph))
							(NC.AddLinkToGraphCard Window 
										 LinkOrLinkLabel 
										 DestinationCard))
						      ((NC.IsSubTypeOfP CardType (QUOTE Sketch))
							(NC.AddLinkToSketchCard Window 
										  LinkOrLinkLabel 
										  DestinationCard)))))
	       ))))

(NC.AddLinksToCard
  (LAMBDA (CardIdentifier LinkLabel DestinationCards)        (* fgh: "13-Jun-86 17:12")

          (* * Adds multiple links to card designated by CardIdentifier. Rest of args can be NIL.)



          (* * fgh 6/9/86 Added Checks to make sure other interaction operation not in porgress.)


    (LET ((SourceCard (NC.CoerceToCard CardIdentifier))
	  CardType Window OperationInProgress)
         (SETQ Window (NC.FetchWindow SourceCard))
         (if (AND (NULL LinkLabel)
		      (NULL DestinationCards)
		      (SETQ OperationInProgress (NC.OperationInProgress SourceCard)))
	     then 

          (* * Another interaction operation is in progress on this card and we have to interact with the user.
	  Can't do.)


		    (NC.PrintOperationInProgressMsg Window "Insert Links" OperationInProgress)
	   else (NC.ProtectedCardOperation SourceCard InsertLinks (SETQ CardType (NC.FetchType
						 SourceCard))
					     (OR LinkLabel (SETQ LinkLabel
						     (NC.AskLinkLabel Window NIL NIL T T)))
					     (if LinkLabel
						 then
						  (OR DestinationCards
							(SETQ DestinationCards
							  (NC.SelectNoteCards
							    NIL
							    (FUNCTION (LAMBDA (SourceCard)
								(COND
								  ((NOT (NC.SameCardP SourceCard 
										       SourceCard))
								    T)
								  (T (NC.PrintMsg (NC.FetchWindow
										      SourceCard)
										    T 
							    "A Card/Box cannot point to itself. "
										    (CHARACTER
										      13)
										    
									     "Selection ignored."
										    (CHARACTER
										      13))
								     NIL))))
							    NC.SelectingMultipleCardsMenu SourceCard 
							    NIL 
					     "Please select the Cards or Boxes to be pointed to.")))
						  (NC.ClearMsg Window T)
						  (for DestinationCard in DestinationCards
						     do (NC.AddLinkToCard CardIdentifier 
									      LinkLabel 
									      DestinationCard))))))))

(NC.AddGlobalLinksToCard
  (LAMBDA (CardIdentifier SingleLinkFlg)                     (* fgh: "13-Jun-86 17:12")

          (* * Called from card's menu to add some global links.)



          (* * rht 11/24/85: Fixed bugs. It was calling NC.CoerceToID.)



          (* * fgh 6/9/86 Added chack for other interaction operations already in progress.)


    (LET (Window SourceCard DestinationCards Label OperationInProgress)
         (SETQ SourceCard (NC.CoerceToCard CardIdentifier))
         (SETQ Window (NC.FetchWindow SourceCard))
         (if (SETQ OperationInProgress (NC.OperationInProgress SourceCard))
	     then 

          (* * Another interaction operation is in progress on this card and we have to interact with the user.
	  Can't do.)


		    (NC.PrintOperationInProgressMsg Window "Add Global Link(s)" OperationInProgress)
	   else (NC.ProtectedCardOperation SourceCard Add% Global% Link%(s%)
					     (SETQ Label (NC.AskLinkLabel Window NIL NIL T T))
					     (AND Label
						    (if SingleLinkFlg
							then (NC.MakeGlobalLink Window Label NIL 
										    SourceCard)
							       (NC.ClearMsg Window T)
						      else
						       (SETQ DestinationCards
							 (NC.SelectNoteCards
							   NIL
							   (FUNCTION (LAMBDA (Card)
							       (COND
								 ((NEQ Card SourceCard)
								   T)
								 (T (NC.PrintMsg Window T 
							    "A Card/Box cannot point to itself. "
										   (CHARACTER
										     13)
										   
									     "Selection ignored."
										   (CHARACTER
										     13))
								    NIL))))
							   NC.SelectingMultipleCardsMenu SourceCard 
							   NIL 
					     "Please select the Cards or Boxes to be pointed to."))
						       (NC.ClearMsg Window T)
						       (for DestinationCard in DestinationCards
							  do (NC.MakeGlobalLink Window Label 
										  DestinationCard 
										    SourceCard))))))))
)

(NC.AddParents
  (LAMBDA (WindowOrTextStream)                               (* fgh: "13-Jun-86 17:11")

          (* Add a subtopic link from a contents card specified by the user to the contents card specified by 
	  WindowOrTextStream. But first check to make sure that this would not introduce any circularities in the contents 
	  lattice.)



          (* * rht 12/8/84: Massive shaving. Now calls NC.MakeChildLink to do the tough work.)



          (* * rht 10/3/85: No longer prints final, annoying, slow-to-disappear message in prompt window if nothing 
	  selected.)



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



          (* * fgh 6/9/86 Added code to check to make sure that another operation is not in progress on this card when this 
	  fn is called.)


    (LET (Card NewParents (Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))
	       OperationInProgress)
         (SETQ Card (NC.CoerceToCard Window))
         (if (SETQ OperationInProgress (NC.OperationInProgress Card))
	     then 

          (* * Another interaction operation is in progress on this card and we have to interact with the user.
	  Can't do.)


		    (NC.PrintOperationInProgressMsg Window "Designate FileBoxes" 
						      OperationInProgress)
	   else (NC.ProtectedCardOperation Card Designate% FileBoxes
					     (SETQ NewParents (NC.SelectNoteCards
						 NIL
						 (FUNCTION NC.FileBoxP)
						 NC.SelectingParentsMenu Card NIL 
						 " Please select the new parent FileBox(es)."))
					     (AND NewParents Card
						    (for ParentCard in NewParents bind OneHook
						       when (NC.MakeChildLink Card ParentCard 
										  Window)
						       do (SETQ OneHook T) finally
										(RETURN OneHook)))))
      )))

(NC.UnfileNoteCard
  (LAMBDA (WindowOrTextStream)                               (* fgh: "13-Jun-86 17:13")
                                                             (* Take a notecard out of a file box.
							     Called fom title bar menu.)

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



          (* * fgh 6/9/86 Added code to check to make sure that another operation is not in progress on this card when this 
	  fn is called.)


    (LET (Links Card Window EditWindow FileBoxes OperationInProgress)
         (SETQ Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))
         (SETQ Card (NC.CoerceToCard Window))
         (if (SETQ OperationInProgress (NC.OperationInProgress Card))
	     then 

          (* * Another interaction operation is in progress on this card and we have to interact with the user.
	  Can't do.)


		    (NC.PrintOperationInProgressMsg Window "Unfile" OperationInProgress)
	   else (NC.ProtectedCardOperation Card Unfile (SETQ Links
					       (bind SourceCard for Link in (NC.FetchFromLinks
										    Card)
						  when (EQ (fetch (Link Label) of Link)
							       NC.FiledCardLinkLabel)
						  collect (create Link
							       copying Link DisplayMode ←(create
									   LINKDISPLAYMODE
											      
											  copying
											       (
											    fetch
												 (Link
												   
										      DisplayMode)
												  of
												   
											     Link)
											       
										     SHOWTITLEFLG ←(
											    QUOTE
												 
											   SOURCE)))))
					     (SETQ EditWindow (NC.OpenPropListEditor
						 WindowOrTextStream
						 (LIST (QUOTE FileBoxes)
							 Links)
						 "List of File Boxes" T T))
					     (BLOCK)
					     (SETQ FileBoxes
					       (NC.SelectNoteCards
						 NIL
						 (FUNCTION (LAMBDA (LinkOrCard)
						     (COND
						       ((LISTP LinkOrCard)
							 (NC.FileBoxP (fetch (Link SourceCard)
									   of LinkOrCard)))
						       (T (NC.FileBoxP LinkOrCard)))))
						 NC.SelectingParentsMenu Card T 
				"Please select the file box(es) from which to remove this card. "))
					     (NC.ClosePropListEditor EditWindow (QUOTE NoSave))
					     (DISMISS)
					     (NC.ClearMsg Window T)
					     (for Box in FileBoxes
						do (NC.DelReferencesToCard
						       (COND
							 ((type? Link Box)
							   (fetch (Link SourceCard) of Box))
							 (T Box))
						       Card))
					     (for Link in Links
						when (OR (for Card in FileBoxes
								thereis (NC.SameCardP
									    (fetch (Link SourceCard)
									       of Link)
									    Card))
							     (for OtherLink in FileBoxes
								thereis (NC.SameLinkP Link 
											OtherLink)))
						do (NC.DelToLink Link)
						     (NC.DelFromLink Link)))))))

(NC.QuitCard
  (LAMBDA (CardIdentifier CallCloseWFlg DontSaveFlg DontRecacheFlg DontCheckOpInProgressFlg 
			  InterestedWindow OperationMsg)     (* fgh: "27-Jun-86 18:08")

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


    (PROG ((Card (NC.CoerceToCard CardIdentifier))
	     Window OperationInProgress)
	    (SETQ Window (NC.FetchWindow 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 (COND
		    ((EQ (NC.InsureProperFiling Card)
			   (QUOTE CANCELLED))
		      (RETURN (QUOTE DON'T)))))

          (* * Otherwise go ahead an quit)


	    (RETURN (NC.ProtectedCardOperation Card Close% Card
						 (PROG NIL
						         (COND
							   ((AND Window NC.CloseCardsOffScreenFlg)
							     (COND
							       ((NOT (NC.FetchSavedRegion Card))
								 (NC.SetSavedRegion
								   Card
								   (WINDOWPROP Window (QUOTE
										   REGION)))))
							     (MOVEW Window 1500 1500)))
						         (OR DontSaveFlg
							       (NC.CardSaveFn Card 
									NC.CloseCardsOffScreenFlg NIL 
										InterestedWindow 
										OperationMsg))
						         (AND Window (WINDOWDELPROP
								  Window
								  (QUOTE CLOSEFN)
								  (FUNCTION NC.QuitCard)))
						         (RETURN (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.MakeFilingLinks
  (LAMBDA (Card Msg)                                         (* fgh: " 9-Jun-86 21:19")
                                                             (* Hooks card specified by Card to all of the current 
							     contents cards by a Contents link)

          (* * rht 8/1/84: Changed the NC.PrintMsg2 call for "No FileBox has been specified." to use NIL as second arg rather
	  than T. This prevents erasure of previous error messages.)



          (* * rht 12/8/84: Massive rewrite. Now calls NC.MakeChildLink. And always orphanizes if no parent specified.
	  This is because it's currently called only by NC.InsureProperFiling.)



          (* * rht 6/25/85: Now returns NewParents and checks if CANCELLED comes back from NC.SelectNoteCards so can abort 
	  the calling operation.)



          (* * Fgh 11/15/85 Adapted from and intended to replace NC.MakeContentsHooks)



          (* * fgh 8/6/86 Updated to use NC.AttachPromptWindow and added Msg arg)


    (PROG (OneHook (Window (NC.FetchWindow Card))
		     NewParents)
	    (SETQ NewParents (NC.SelectNoteCards NIL (FUNCTION NC.FileBoxP)
						     NC.SelectingContentsMenu Card NIL
						     (CONCAT (OR Msg "")
							       
						  "Please select the Boxes to file this card in."
							       (CHARACTER 13)
							       
				       "'Done' with no selections files it in the ToBeFiled box.")
						     T))
	    (COND
	      ((NOT (OR (EQ NewParents (QUOTE CANCELLED))
			    (AND NewParents (for ParentCard in NewParents bind OneHook
						 when (NC.MakeChildLink Card ParentCard Window)
						 do (SETQ OneHook T) finally (RETURN OneHook))
				   )))
		(NC.PrintMsg Window NIL "No FileBox has been specified." (CHARACTER 13)
			       "This card will be filed in the ToBeFiled Box."
			       (CHARACTER 13))
		(NC.HookToOrphanCard Card (fetch (NoteFile ToBeFiledCard)
					       of (fetch (Card NoteFile) of Card)))
		(COND
		  ((NC.AttachPromptWindow Window NIL NIL NIL T)
		    (SPAWN.MOUSE)
		    (DISMISS 2000)
		    (NC.ClearMsg Window T)))))
	    (RETURN NewParents))))

(NC.CheckFiling
  (LAMBDA (Card)                                             (* fgh: "13-Jun-86 14:16")
                                                             (* Check to make sure this card has a contents hook of
							     some sort. If not, hook it up to a contents card.)

          (* * rht 12/8/84: Now checks whether both cards *and* fileboxes have been filed.)



          (* * rht 12/9/84: Now files in orphan filebox if NC.ForceFiling flag is off, without bothering the user.)



          (* * rht 2/9/85: Added call to NC.CardNeedsFilingP)



          (* * fgh 11/12/85 Updated to handle Card and NoteFile objects.)



          (* * fgh 6/9/86 Updated to set operation in progress indicator.)


    (LET (OperationInProgress)
         (COND
	   ((NC.CardNeedsFilingP Card)
	     (NC.ProtectedCardOperation Card Filing (COND
					  (NC.ForceFilingFlg (NC.MakeFilingLinks
							       Card
							       (CONCAT "This card (" (
									   NC.RetrieveTitle Card)
									 
							 ") is not currently filed in a FileBox."
									 (CHARACTER 13))))
					  (T (NC.PrintMsg (NC.FetchWindow Card)
							    T "This card (" (NC.RetrieveTitle
							      Card)
							    ") is not currently filed in a FileBox."
							    (CHARACTER 13)
							    
						    "It is being filed in the ToBeFiled FileBox."
							    (CHARACTER 13))
					     (NC.HookToOrphanCard Card (fetch (NoteFile 
										    ToBeFiledCard)
									    of (fetch
										   (Card NoteFile)
										    of Card)))))))))
    ))

(NC.QuitWithoutSaving
  (LAMBDA (CardIdentifier)                                   (* fgh: "27-Jun-86 18:11")

          (* Quit from a note card without saving its contents on the database. But must make sure that any updates that 
	  would have been done to this card even if it had been on the database are carried out on the old image currently on
	  the database)



          (* * rht 2/1/85: Now only writes out links if it has to. Also resets dirty flags and calls normal quit procedure.
	  I think we've still got possible problems with recently changed titles, both ours and those of cards we point to.)



          (* * rht 2/3/85: Now handles title changes properly. Also fixed so that changes to from links will force links to 
	  be written.)



          (* * rht 2/9/85: Now accepts IDs as arg.)



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



          (* * fgh 6/4/86 No longer asks for confirmation if no changes have been made.)


    (LET (Window Card FromLinks ToLinks DeletedLinks Process TextObj MadeNewLinksP ChangedFromLinksP 
		 OldFromLinks OldToLinks OperationInProgress)
         (SETQ Card (NC.CoerceToCard CardIdentifier))
         (SETQ Window (NC.FetchWindow Card))
         (if (SETQ OperationInProgress (NC.OperationInProgress Card))
	     then 

          (* * Another interaction operation is in progress on this card and we have to interact with the user.
	  Can't do.)


		    (NC.PrintOperationInProgressMsg Window "Close w/o Saving" OperationInProgress)
	   else (NC.ProtectedCardOperation Card Close% wo% Saving (SETQ FromLinks (
						 NC.FetchFromLinks Card))
					     (SETQ ToLinks (NC.FetchToLinks Card))
					     (COND
					       ((OR (NULL (OR (NC.CardDirtyP Card)
								    (NC.FetchLinksDirtyFlg Card)
								    (NC.FetchTitleDirtyFlg Card)
								    (NC.FetchPropListDirtyFlg
								      Card)))
						      (NC.AskYesOrNo 
						   "Are you sure you want to flush your changes?"
								       " -- " "Yes" T Window NIL NIL))

          (* * EIther no changes have been made or the user has confirmed.)


						 (COND
						   ((NC.CardP (NC.GetNoteCard Card))
                                                             (* If from links have changed then we'll have to write
							     the new ones out.)
						     (SETQ OldFromLinks (NC.FetchFromLinks Card))
						     (COND
						       ((NOT (NC.SameLinksP FromLinks 
										OldFromLinks))
							 (NC.SetFromLinks Card FromLinks)
							 (SETQ ChangedFromLinksP T)))
                                                             (* Delete the back links from all links that are not 
							     in the old to link set.)
						     (SETQ OldToLinks (NC.FetchToLinks Card))
						     (for ToLink in ToLinks
							when
							 (NOT (for Link in OldToLinks
								   bind (ToLinkID
									    ←(fetch (Link UID)
										of ToLink))
								   thereis
								    (EQ ToLinkID
									  (fetch (Link UID)
									     of Link))
								   eachtime (BLOCK)))
							do (NC.DelFromLink ToLink T)
							     (SETQ MadeNewLinksP T))
                                                             (* Check to make sure none of the old To links point 
							     to a deleted card. If so, replace with a deleted 
							     marker.)
						     (SETQ DeletedLinks
						       (bind DestinationCard for Link
							  in OldToLinks
							  when (PROGN (SETQ DestinationCard
									    (fetch (Link 
										  DestinationCard)
									       of Link))
									  (AND (NOT (
										   NC.ActiveCardP
											  
										  DestinationCard))
										 (EQ (QUOTE
											 DELETED)
										       (
										   NC.FetchStatus
											 
										  DestinationCard))))
							  eachtime (BLOCK)
							  collect (NC.DelReferencesToCard Card 
										  DestinationCard)
								    Link))
						     (NC.SetToLinks Card (LDIFFERENCE OldToLinks 
										     DeletedLinks))
                                                             (* Mark links dirty if we had to delete any to links 
							     or if the from links changed.)
						     (NC.SetLinksDirtyFlg Card (OR DeletedLinks 
										ChangedFromLinksP))
                                                             (* Mark the substance dirty if had to delete any to 
							     links.)
						     (COND
						       (DeletedLinks (NC.MarkCardDirty Card))
						       (T (NC.MarkCardDirty Card (QUOTE RESET))))
						     (NC.SetPropListDirtyFlg Card NIL)
						     (COND
						       ((NC.FetchTitleDirtyFlg Card)

          (* If we've changed title and any of the cards pointing to this one are up on the screen, then we need to update 
	  their images.)


							 (for FromLink in OldFromLinks
							    bind SourceCard eachtime (BLOCK)
							    when
							     (AND (NC.ActiveCardP
								      (SETQ SourceCard
									(fetch (Link SourceCard)
									   of FromLink)))
								    (WINDOWP (NC.FetchWindow
										 SourceCard)))
							    do (NC.UpdateLinkImages SourceCard 
											Card))
							 (NC.SetTitleDirtyFlg Card NIL)))
						     (NC.QuitCard Card T T NIL T))
						   (T        (* If the card has never been written to the database 
							     quit w/o saving is equivalent to deleting the card.)
						      (NC.PrintMsg Window T 
								"This card has never been saved."
								     (CHARACTER 13)
								     
							  "It will be deleted from the database."
								     (CHARACTER 13))
						      (NC.DeleteNoteCards Card NIL T))))))))))

(NC.CardSaveFn
  (LAMBDA (WindowOrID QuietFlg DontCheckForOpsInProgressFlg InterestedWindow OperationMsg)
                                                             (* fgh: "27-Jun-86 18:32")

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


    (LET ((Card (NC.CoerceToCard WindowOrID))
	  Window OldRegion NewRegion DoneAPutP OperationInProgress)
         (SETQ Window (NC.FetchWindow Card))
         (SETQ InterestedWindow (OR Window InterestedWindow))
         (if (AND (NULL DontCheckForOpsInProgressFlg)
		      (SETQ OperationInProgress (NC.OperationInProgress Card))
		      (NEQ OperationInProgress (QUOTE Close% Card)))
	     then (NC.PrintOperationInProgressMsg Window "Save Card" OperationInProgress)
	   else (NC.ProtectedCardOperation
		    Card Save% Card (OR QuietFlg (NC.PrintMsg InterestedWindow T
								  (OR OperationMsg "")
								  (NC.FetchTitle Card)
								  ": Checking ... "))
		    (COND
		      ((OR (NC.CardDirtyP Card)
			     (NC.FetchNewCardFlg Card))
			(OR QuietFlg (NC.PrintMsg InterestedWindow NIL "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 NIL "Saving "))
			(OR QuietFlg (NC.PrintMsg InterestedWindow NIL "region, "))
			(NC.PutRegion Card)
			(SETQ DoneAPutP T)))
		    (COND
		      ((NC.FetchTitleDirtyFlg Card)
			(OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL "Saving "))
			(OR QuietFlg (NC.PrintMsg InterestedWindow NIL "title, "))
			(NC.PutTitle Card)
			(SETQ DoneAPutP T)))
		    (COND
		      ((NC.FetchPropListDirtyFlg Card)
			(OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL "Saving "))
			(OR QuietFlg (NC.PrintMsg InterestedWindow NIL "proplist, "))
			(NC.PutPropList Card)
			(SETQ DoneAPutP T)))
		    (COND
		      ((NC.FetchLinksDirtyFlg Card)
			(OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL "Saving "))
			(OR QuietFlg (NC.PrintMsg InterestedWindow NIL "links, "))
			(NC.PutLinks Card)
			(SETQ DoneAPutP T)))
		    (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL (CHARACTER 13)
							    "Nothing changed. "))
                                                             (* It's not a new card anymore.)
		    (NC.SetNewCardFlg Card NIL)
		    (OR QuietFlg (PROGN (NC.PrintMsg InterestedWindow NIL "Done." (CHARACTER
							     13))
					    (if (AND Window (NEQ Window InterestedWindow))
						then (NC.ClearMsg InterestedWindow T)))))))))

(NC.DeleteNoteCards
  (LAMBDA (CardIdentifiers NoCheckFlg DontClearFlg InterestedWindow)
                                                             (* fgh: "13-Jun-86 17:14")
                                                             (* Delete note cards. If no card specified then get a 
							     list of note cards to be deleted.
							     Then delete these cards.)

          (* * fgh 11/11/85: Updated to handle new Card objects. Also split off main work of deleteing a single note card 
	  into NC.DeleteNoteCard function.)



          (* * kirk 21Feb86 Added InterestedWindow)



          (* * kirk 29Apr86 Now returns CardIdentifiers)



          (* * fgh 6/9/86 Added checks to see if other operations are in progress)


    (OR CardIdentifiers (SETQ CardIdentifiers (NC.SelectNoteCards NIL NIL 
									NC.DeleteSelectingMenu
									(AND InterestedWindow
									       (
									    NC.AttachPromptWindow
										 InterestedWindow))
									NIL 
						    "Please select the Note Cards to be deleted.")))
    (bind Card OperationInProgress for CardIdentifier in (MKLIST CardIdentifiers)
       do (SETQ Card (NC.CoerceToCard CardIdentifier))
	    (COND
	      ((NULL Card))
	      ((NC.TopLevelCardP Card)
		(NC.PrintMsg (NC.FetchWindow Card)
			       T "You cannot delete this FileBox." (CHARACTER 13))
		(DISMISS 1000)
		(NC.ClearMsg (NC.FetchWindow Card)
			       T))
	      (T (if (SETQ OperationInProgress (NC.OperationInProgress Card))
		     then (NC.PrintOperationInProgressMsg (NC.FetchWindow Card)
							      "Delete Card(s)" OperationInProgress)
		   else (NC.ProtectedCardOperation Card Delete% Card%(s%)
						     (AND (OR NoCheckFlg
								  (PROG1 (NC.AskYesOrNo
									     
							  "Are you sure you want to delete this?"
									     " -- " "Yes"
									     (NULL DontClearFlg)
									     (NC.FetchWindow Card)
									     NIL NIL)
									   (NC.ClearMsg)))
							    (NC.DeleteNoteCard Card)))))))
    CardIdentifiers))

(NC.DeleteNoteCard
  (LAMBDA (Card)                                             (* fgh: "27-Jun-86 18:07")

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


    (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
		(RESETSAVE NIL (BQUOTE (NC.SetBeingDeletedFlg , Card NIL)))
		(WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
			      (LET (ToLinks FromLinks Window)
			           (NC.SetBeingDeletedFlg Card T)
			           (SETQ ToLinks (NC.RetrieveToLinks Card))
			           (SETQ FromLinks (NC.RetrieveFromLinks Card))
			           (NC.SetToLinks Card NIL)
			           (NC.SetFromLinks Card NIL)
			           (for ToLink in ToLinks do (NC.DelFromLink ToLink))
			           (for FromLink in FromLinks
				      do (NC.DelToLink FromLink)
					   (NC.DelReferencesToCard (fetch (Link SourceCard)
									of FromLink)
								     Card))
			           (NC.SetStatus Card (QUOTE DELETED))
			           (COND
				     ((NC.ActiveCardP Card)
				       (NC.TurnOffDirtyFlgs Card)
				       (SETQ Window (NC.FetchWindow Card))
				       (AND Window (NC.GreyCard Card))
				       (NC.CloseAllPropListEditors Card)
				       (NC.QuitCard Card T T NIL T)))
			           (NC.SetNewCardFlg Card NIL)
			           (NC.DeactivateCard Card T))))))
)
(* * Implementation of locks on card operations -- new stuff)

(DEFINEQ

(NC.PrintOperationInProgressMsg
  (LAMBDA (Window Operation OperationInProgress)             (* fgh: "13-Jun-86 18:44")

          (* * Notify the user that they are attempting to do an operation while another operation is in progress.
	  Use a prompt window above the card's promptwindow because the card's prompt window is probably being used for the 
	  operation.)



          (* * fgh 6/9/86 First created.)


    (LET (PWindow)
         (if (OPENWP (SETQ PWindow (NC.AttachPromptWindow Window NIL NIL NIL T)))
	     then (SETQ PWindow (NC.AttachPromptWindow PWindow 1 30 NIL NIL))
	   else (SETQ PWindow (NC.AttachPromptWindow (NC.AttachPromptWindow Window NIL 15 NIL)
							   1 30 NIL NIL)))
         (NC.PrintMsg PWindow T "## Can't " Operation (CHARACTER 13)
			"## " OperationInProgress " in progress.")
         (REPOSITIONATTACHEDWINDOWS Window))))

(NC.CardOperationsInProgress
  (LAMBDA (NoteFile AskAndTerminateFlg)                      (* fgh: "27-Jun-86 16:36")

          (* * Check if any cards have operations in progress. If so, either return their processes or Ask the user if they 
	  should be terminated and termionate them, depending on AskAndTerminateFlg. If the user say no terminations, then 
	  return the LITATOM ABORT.)



          (* * fgh 6/13/86 First created)


    (LET (FoundOpInProgress)
         (NC.MapCards NoteFile
			(FUNCTION (LAMBDA (Card Process)
			    (if (PROCESSP Process)
				then 

          (* This card has an operation in progress. If this is the first one found, ask the Ask the user if operations in 
	  progress should be killed.)


				       (if (NULL AskAndTerminateFlg)
					   then            (* Just Return a lst of proceses)
						  Process
					 else              (* ask the user what to do.)
					  (if (AND (NOT FoundOpInProgress)
						       (NOT (NC.AskYesOrNo
								(CONCAT 
						   "There are cards with operations in progress."
									  (CHARACTER 13)
									  
						     "Do you want to terminate these operations?"
									  (CHARACTER 13))
								"-->"
								(QUOTE Yes)
								T
								(WFROMMENU (fetch (NoteFile
											Menu)
										of NoteFile)))))
					      then         (* User doesn't want to kill active operations.
							     Get out of close.)
						     (RETFROM (FUNCTION NC.MapCards)
								(QUOTE ABORT))
					    else           (* Okay, kill the operation in progress.
							     And allow a list of terminated processes to be 
							     returned.)
						   (SETQ FoundOpInProgress T)
						   (NC.TerminateCardOperationInProgress Card)
						   Process)))))
			(FUNCTION (LAMBDA (Card)
			    (NC.FetchUserDataProp Card (QUOTE ProcessInProgress))))))))

(NC.TerminateCardOperationInProgress
  (LAMBDA (Card)                                             (* fgh: "27-Jun-86 19:26")

          (* * Terminate the operation in progress for card, if any.)



          (* * fgh 6/13/86 First created.)


    (LET (Process)
         (if (PROCESSP (SETQ Process (NC.FetchUserDataProp Card (QUOTE ProcessInProgress))))
	     then (PROCESS.EVAL Process (QUOTE (ERROR!)))
		    (until (NULL (NC.FetchUserDataProp Card (QUOTE ProcessInProgress)))
		       do (BLOCK))))))

(NC.OperationInProgress
  (LAMBDA (Card)                                             (* fgh: "25-Jun-86 19:55")

          (* * Return the process for the operation in prgress on Card, if any)



          (* * fgh 6/13/86 First created.)


    (OR (AND (PROCESSP (NC.FetchUserDataProp Card (QUOTE ProcessInProgress)))
		 (NC.FetchUserDataProp Card (QUOTE OperationInProgress)))
	  (AND (PROCESSP (NC.NoteFileProp (fetch (Card NoteFile) of Card)
						(QUOTE ProcessInProgress)))
		 (NC.NoteFileProp (fetch (Card NoteFile) of Card)
				    (QUOTE OperationInProgress))))))
)
(DECLARE: EVAL@COMPILE 
(DEFMACRO NC.ProtectedCardOperation (Card Operation &REST Body)
	  (BQUOTE (RESETLST (RESETSAVE (NC.SetUserDataProp Card (QUOTE OperationInProgress)
							   (QUOTE , Operation))
				       (BQUOTE (NC.SetUserDataProp , Card OperationInProgress ,
								   (NC.FetchUserDataProp
								     Card
								     (QUOTE OperationInProgress)))))
			    (RESETSAVE (NC.SetUserDataProp Card (QUOTE ProcessInProgress)
							   (THIS.PROCESS))
				       (BQUOTE (NC.SetUserDataProp , Card ProcessInProgress ,
								   (NC.FetchUserDataProp
								     Card
								     (QUOTE ProcessInProgress)))))
			    ,@ Body)))
)
(* * Implementation of locks on NF operations -- old stuff)

(DEFINEQ

(NC.CloseDatabaseFile
  (LAMBDA (NoteFile InterestedWindow Don'tCheckOperationInProgressFlg)
                                                             (* fgh: "27-Jun-86 20:28")
                                                             (* 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.)


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


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


		        (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 (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)
						       (if (SETQ Window (NC.FetchWindow Card))
							   then (bind (Process
									    ←(WINDOWPROP
									      Window
									      (QUOTE PROCESS)))
								     until (OR (NULL Process)
										   (
										PROCESS.FINISHEDP
										     Process))
								     do (BLOCK)))))
				   (NC.PrintMsg InterestedWindow NIL "Done." (CHARACTER 13)))

          (* * Checkpoint, then close the file)


		        (NC.PrintMsg InterestedWindow T OperationMsg)
		        (NC.CheckpointDatabase NoteFile NIL 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.OpenDatabaseFile
  (LAMBDA (NoteFileOrFileName Access Don'tCacheTypesAndTitlesFlg QuietFlg Don'tCreateFlg 
			      Convertw/oConfirmFlg Don'tCreateArrayFlg Don'tTruncateFlg 
			      Don'tCreateInterfaceFlg Don'tGetSpecialCardsFlg InterestedWindow 
			      Don'tCheckOperationInProgressFlg MenuPosition)
                                                             (* fgh: "27-Jun-86 16:03")

          (* * Open an already existing NoteFile and return a NoteFile object)



          (* * rht 8/7/84: For nonexistent files, asks user whether to create unless Don'tCreateFlg is non-nil.)



          (* * rht 1/9/85: Checks NC.UncachingNotCompleted global var. If non-nil, then previous notefile died unnaturally, 
	  so we first clear junk off the IDs.)



          (* * rht 8/6/85: Added Don'tTruncateFlg, which, if on, prevents the check for truncation.)



          (* * fgh 10/16/85 Updated to use new cacheing scheme.)



          (* * kirk 10/29/85: Now does cacheing of types and titles as background process.)



          (* * fkr 11/8/85: Converted from Streams to NoteFile object.)



          (* * kirk 30Nov85 Added a check for correct version number.)



          (* * rht 12/6/85: Moved Kirk's above patch to NC.CheckForNeededConversion and modified somewhat.
	  Added check for plausible header.)



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



          (* * fgh 1/13/86: Fixed bug with returning File Name with embedded call to CreateDatabaseFile.
	  Now just calls OpenDatabaseFile recursively using result of CreateDatabaseFile.)



          (* * fgh 1/16/86 Folded the cacheing of the special cards into BuildHashArray instead of making it a separate 
	  function after the hash array is already read in.)



          (* * kirk 20Jan86 Added NC.AskYesOrNo and InterestedWindow for prompt)



          (* * fgh 5/2/86 Implemented before and after opening hooks using NC.OpenNoteFileFns global variable.)



          (* * fgh 6/8/86 Added code to insure that two files with SameUIDP would never be open at once.)



          (* * fgh 6/25/86 Added contention locks -- NC.ProtectedNoteFileOperation, Don'tCheckOperationInProgressFlg etc.)



          (* * fgh 6/27/86 Added MenuPsotion arg to pass to SetUpNoteFileInterface)


    (PROG (NoteFile FileName Name Stream NewStream Card CardTotal)
	    (OR Access (SETQ Access (QUOTE BOTH)))
	    (SETQ FileName (COND
		((type? NoteFile NoteFileOrFileName)
		  (SETQ NoteFile NoteFileOrFileName)
		  (fetch (NoteFile FullFileName) of NoteFileOrFileName))
		(T NoteFileOrFileName)))
	    (if (NOT (OR FileName (SETQ FileName (NC.DatabaseFileName 
								      "Name of NoteFile to open:"
										" -- " T NIL NIL 
										InterestedWindow))))
		then (RETURN NIL))                       (* Use existing notefile object if there is one for 
							     this file name.)
	    (OR (type? NoteFile NoteFile)
		  (SETQ NoteFile (OR (NC.NoteFileFromFileName FileName)
					 (create NoteFile))))

          (* * If there is no interested window, see if the menu window can be used.)


	    (if (AND (NULL InterestedWindow)
			 (fetch (NoteFile Menu) of NoteFile))
		then (SETQ InterestedWindow (WFROMMENU (fetch (NoteFile Menu) of NoteFile)))
		  )

          (* * If this is an open NoteFIle, just bring up its menu.)


	    (if (NC.NoteFileOpenP NoteFile)
		then (NC.SetUpNoteFileInterface NoteFile MenuPosition)
		       (RETURN NIL))

          (* * Check to make sure the file is not already open.)


	    (if (OPENP FileName)
		then                                       (* need a better check here to bring up or create 
							     notefile icon if needed)
		       (NC.PrintMsg InterestedWindow T FileName " is an already open file."
				      (CHARACTER 13))
		       (RETURN NIL))

          (* * 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 Open% NoteFile)
							 (NC.NoteFileProp NoteFile (QUOTE 
									      OperationInProgress)))
		       (RETURN NIL))

          (* * Run rest of function with contention lock.)


	    (RETURN (NC.ProtectedNoteFileOperation
			NoteFile Open% NoteFile
			(PROG NIL
			        (if (NOT (SETQ Name (INFILEP FileName)))
				    then (COND
					     (Don'tCreateFlg (NC.PrintMsg InterestedWindow T 
									"Couldn't find NoteFile "
									    FileName "."
									    (CHARACTER 13))
							     (RETURN NIL))
					     ((NC.AskYesOrNo (CONCAT "Unable to find NoteFile " 
									 FileName "." (CHARACTER
									   13)
									 
						   "Want to create a new NoteFile by that name? ")
							       " -- " "Yes" T InterestedWindow)
					       (SETQ NoteFile (NC.CreateDatabaseFile FileName NIL 
									       "Opening NoteFile"
											 T))
					       (if (NOT (type? NoteFile NoteFile))
						   then (NC.PrintMsg InterestedWindow T 
								     "Unable to create Notefile "
									 FileName "." (CHARACTER
									   13))
							  (RETURN NIL)
						 else (RETURN (NC.OpenDatabaseFile NoteFile 
											 Access 
								      Don'tCacheTypesAndTitlesFlg 
											 QuietFlg 
										   Don'tCreateFlg 
									     Convertw/oConfirmFlg 
									      Don'tCreateArrayFlg 
										 Don'tTruncateFlg 
									  Don'tCreateInterfaceFlg 
									  Don'tGetSpecialCardsFlg 
										 InterestedWindow T)))
					       )
					     (T (RETURN NIL))))

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


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

          (* * Open the file)


			        (OR QuietFlg (NC.PrintMsg InterestedWindow T "Opening NoteFile " 
							      Name " . . ." (CHARACTER 13)))
			        (if (NULL (SETQ Stream
						(CAR (ERSETQ (OPENSTREAM Name Access
									       (QUOTE OLD)
									       (QUOTE
										 ((TYPE BINARY))))))))
				    then (NC.PrintMsg InterestedWindow T "Couldn't open " 
							  FileName "." (CHARACTER 13))
					   (RETURN NIL))
			        (replace (NoteFile Stream) of NoteFile with Stream)
			        (replace (NoteFile FullFileName) of NoteFile with (FULLNAME
											  Stream))
			        (NC.SetMonitor NoteFile (CREATE.MONITORLOCK (MKATOM
										  (CONCAT Name 
											  ":LOCK"))))
			        (NC.GetNoteFileHeader NoteFile)

          (* * Make sure there is no other open NF with this UID.)


			        (LET (NF)
				     (if (AND (SETQ NF (GETHASH (fetch (NoteFile UID)
									   of NoteFile)
									NC.NoteFilesHashArray))
						  (NEQ (fetch (NoteFile FullFileName)
							    of NoteFile)
							 (fetch (NoteFile FullFileName)
							    of NF))
						  (NC.NoteFileOpenP NF))
					 then (FLASHW PROMPTWINDOW)
						(NC.PrintMsg InterestedWindow T "Couldn't open " 
							       FileName (CHARACTER 13)
							       "because "
							       (fetch (NoteFile FullFileName)
								  of NF)
							       " is already open "
							       (CHARACTER 13)
							       "and has the same UID.")
						(if (STREAMP (fetch (NoteFile Stream)
								    of NoteFile))
						    then (CLOSEF? (fetch (NoteFile Stream)
									 of NoteFile)))
						(replace (NoteFile Stream) of NoteFile
						   with NIL)
						(RETURN NIL)))

          (* * See if notefile is out of date. If so, convert to current version.)


			        (if (NOT (NC.CheckForNeededConversion NoteFile 
									    Convertw/oConfirmFlg))
				    then (CLOSEF (fetch (NoteFile Stream) of NoteFile))
					   (NC.PrintMsg InterestedWindow T "Open cancelled.")
					   (RETURN NIL))   (* See if notefile header seems reasonable.
							     If not, bail out.)
			        (if (NOT (NC.PlausibleNoteFileHeaderP NoteFile))
				    then (NC.PrintMsg InterestedWindow NIL 
				       "Notefile has bad header.  Please see a NoteCards wizard."
							  (CHARACTER 13)
							  "Open cancelled.")
					   (RETURN NIL))
			        (COND
				  ((NULL Don'tTruncateFlg)
                                                             (* Can either bail out entirely or run inspector and 
							     then bail out.)
				    (SELECTQ (SETQ NewStream (NC.CheckForNeededTruncation
						   NoteFile Access))
					       (ABORT (CLOSEF Stream)
						      (NC.PrintMsg InterestedWindow T 
								     "Open cancelled.")
						      (RETURN NIL))
					       (ABORTANDINSPECT (CLOSEF Stream)
								(NC.ScavengerPhase1 Name)
								(RETURN NIL))
					       NIL)
				    (AND (STREAMP NewStream)
					   (replace (NoteFile Stream) of NoteFile with 
											NewStream))))

          (* * Stash the notefile in the global notefiles hash array.)


			        (NC.StoreNoteFile NoteFile)

          (* * Build the hash array and cache the special cards if necessary)


			        (OR Don'tCreateArrayFlg (NC.BuildHashArray NoteFile QuietFlg 
									  Don'tGetSpecialCardsFlg 
									       InterestedWindow
									       (CONCAT
										 "Opening NoteFile " 
										 Name (CHARACTER
										   13))))
			        (OR Don'tGetSpecialCardsFlg (NC.GetSpecialCards
					NoteFile QuietFlg InterestedWindow (CONCAT 
									      "Opening NoteFile "
										     Name
										     (CHARACTER
										       13))))

          (* * Make sure the NF can't be closed by CLOSEALL)


			        (WHENCLOSE (fetch (NoteFile Stream) of NoteFile)
					     (QUOTE CLOSEALL)
					     (QUOTE NO))
			        (COND
				  ((NULL Don'tCacheTypesAndTitlesFlg)
                                                             (* Cache all of the titles in this database)
				    (replace (NoteFile CachingProcess) of NoteFile
				       with (ADD.PROCESS (LIST (FUNCTION 
								       NC.CacheTypesAndTitles)
								     NoteFile)))))
			        (COND
				  ((NULL Don'tCreateInterfaceFlg)
                                                             (* Make an interface menu for this notefile.)
				    (NC.SetUpNoteFileInterface NoteFile MenuPosition)))
			        (AND (NULL QuietFlg)
				       (NC.PrintMsg InterestedWindow T "Opened " (FULLNAME Stream)
						      (CHARACTER 13))
				       (NC.ClearMsg InterestedWindow T))
			        (SETQ NC.LastNoteFileOpened NoteFile)

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


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

          (* * return the opened NF)


			        (RETURN NoteFile)))))))

(NC.CheckpointDatabase
  (LAMBDA (NoteFile QuietFlg Don'tSaveDirtyCardsFlg Don'tCheckOperationInProgressFlg 
		    Don'tCheckCardOperationsInProgressFlg InterestedWindow OperationMsg)
                                                             (* fgh: "27-Jun-86 16:09")

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



          (* * fgh 6/13/86 Changed printouts to NF menu. Added check for operations in progress.)



          (* * fgh 6/25/86 Put in contention lock and NC.ProtectedNoteFileOperation Added Don'tCheckOperationInProgressFlg 
	  Don'tCheckCardOperationsInProgressFlg & InterestedWindow args.)


    (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
	  (FullFileName (fetch (NoteFile FullFileName) of NoteFile)))
         (OR InterestedWindow (SETQ InterestedWindow (WFROMMENU (fetch (NoteFile Menu)
									 of NoteFile))))
         (SETQ OperationMsg (OR OperationMsg (CONCAT "Checkpointing Notefile " FullFileName
							   (CHARACTER 13))))
         (if (AND (NULL Don'tCheckOperationInProgressFlg)
		      (PROCESSP (NC.NoteFileProp NoteFile (QUOTE ProcessInProgress))))
	     then 

          (* * Another operation is in progress on this NF.)


		    (NC.PrintOperationInProgressMsg InterestedWindow (QUOTE Checkpoint% NoteFile)
						      (NC.NoteFileProp NoteFile (QUOTE 
									      OperationInProgress)))
	   elseif (NULL (NC.NoteFileOpenP NoteFile))
	     then 

          (* * This NF is not open.)


		    (NC.PrintMsg InterestedWindow T FullFileName " is not an open NoteFile!!!"
				   (CHARACTER 13))
	   else 

          (* * Okay checkpoint under a contention lock.)


		  (NC.ProtectedNoteFileOperation NoteFile Checkpoint% NoteFile
						 (OR QuietFlg (RESETSAVE NIL
									     (BQUOTE (NC.ClearMsg
											 , 
										 InterestedWindow T)))
						       )
						 (if (OR Don'tCheckCardOperationsInProgressFlg
							     (PROGN (OR QuietFlg
									    (NC.PrintMsg
									      InterestedWindow T 
									      OperationMsg 
						      "Checking for card operations in progress."
									      (CHARACTER 13)))
								      (NULL (SETQ OpsInProgress
										(
								      NC.CardOperationsInProgress
										  NoteFile))))
							     (NC.AskYesOrNo (CONCAT 
							 "There are card operations in progress."
											(CHARACTER
											  13)
											
								 "Do you want to terminate them?"
											(CHARACTER
											  13))
									      "-->"
									      (QUOTE Yes)
									      T InterestedWindow))
						     then (OR QuietFlg
								  (NC.PrintMsg InterestedWindow T 
										 OperationMsg " ..."))
							    (if (NULL Don'tSaveDirtyCardsFlg)
								then (NC.SaveDirtyCards NoteFile 
											    T 
										 InterestedWindow 
										     OperationMsg))
                                                             (* Put out the new ChkptPtr to the file.)
							    (NC.PutHashArray NoteFile QuietFlg 
									       OperationMsg NIL 
									       InterestedWindow)
							    (replace (NoteFile CheckptPtr)
							       of NoteFile with (GETEOFPTR
										      Stream))
							    (NC.PutNoteFileHeader NoteFile)
							    (OR QuietFlg
								  (PROGN (NC.PrintMsg
									     InterestedWindow T 
									     OperationMsg "Done."
									     (CHARACTER 13))
									   (DISMISS 250)
									   (NC.ClearMsg 
										 InterestedWindow T)))
						       ))))))

(NC.CopyNoteFile
  (LAMBDA (FromNoteFileOrName ToFileName Window)             (* fgh: "26-Jun-86 23:51")

          (* * Copy a notefile. Ask user for names of FromNoteFileOrName and ToFileName.)



          (* * fkr 11/8/85: Ripped out PSA.Database check. Now takes FromNoteFileOrName and ToFileName args.)



          (* * kirk 19May86 Fixed to work from NoteFile menu)



          (* * fgh 6/24/86 Fixed bug where would not work if NULL FromNoteFileOrName)


    (PROG (FullFromFileName Result (MsgWindow Window))
	    (if (type? NoteFile FromNoteFileOrName)
		then (SETQ FullFromFileName (fetch (NoteFile FullFileName) of 
									       FromNoteFileOrName))
		       (SETQ MsgWindow (OR (WFROMMENU (fetch (NoteFile Menu) of 
									       FromNoteFileOrName))
					       Window))
	      else (OR FromNoteFileOrName (SETQ FromNoteFileOrName
			     (NC.DatabaseFileName "Name of NoteFile to be copied:" " -- " T NIL NIL 
						    MsgWindow))
			   (RETURN))
		     (SETQ FullFromFileName (FULLNAME FromNoteFileOrName))
		     (if (SETQ NoteFile (NC.NoteFileFromFileName FullFromFileName))
			 then (SETQ MsgWindow (OR (WFROMMENU (fetch (NoteFile Menu)
									of NoteFile))
							Window))))
	    (if (OPENP FullFromFileName)
		then (NC.PrintMsg MsgWindow T "Can't copy an open notefile." (CHARACTER 13))
		       (RETURN NIL))
	    (OR ToFileName (SETQ ToFileName (NC.DatabaseFileName "Name of target of copy:" 
								       " -- "
								       T NIL NIL MsgWindow))
		  (RETURN))
	    (COND
	      ((AND FullFromFileName ToFileName)
		(NC.PrintMsg MsgWindow T "Copying " FullFromFileName " to " ToFileName " ...")
		(COND
		  ((SETQ Result (COPYFILE FullFromFileName ToFileName))
		    (NC.PrintMsg MsgWindow T FullFromFileName " copied to " Result "."
				   (CHARACTER 13))
		    (SETQ NC.DatabaseFileNameSuggestion (PACKFILENAME (QUOTE VERSION)
									  NIL
									  (QUOTE BODY)
									  Result)))))
	      ((NULL FullFromFileName)
		(NC.PrintMsg MsgWindow T "Can't open file for copy: " FromNoteFileOrName
			       (CHARACTER 13)))))))

(NC.PutHashArray
  (LAMBDA (NoteFile QuietFlg OperationMsg AllActiveCardsFlg InterestedWindow)
                                                             (* fgh: "27-Jun-86 15:01")

          (* * Write down the hash array's contents to the notefile.)



          (* * kirk 27Nov85 Added AllActiveCardsFlg for use by the compactor.)



          (* * fgh 6/13/86 Changed msgs to NF menu)



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


    (LET ((CardTotal (SUB1 (fetch (NoteFile NextIndexNum) of NoteFile)))
	  (Num 0))
         (OR InterestedWindow (SETQ InterestedWindow (WFROMMENU (fetch (NoteFile Menu)
									 of NoteFile))))
         (OR QuietFlg (NC.PrintMsg InterestedWindow T OperationMsg "Processing item number " 1 
				       " out of "
				       CardTotal "." (CHARACTER 13)))
         (NC.MapCards NoteFile
			(FUNCTION (LAMBDA (Card)
			    (OR QuietFlg
				  (PROGN (SETQ Num (ADD1 Num))
					   (AND (ZEROP (IREMAINDER Num 100))
						  (NC.PrintMsg InterestedWindow T OperationMsg 
								 "Processing item number "
								 Num " out of " CardTotal "."
								 (CHARACTER 13)))))
			    (AND (if AllActiveCardsFlg
				       then (EQ (fetch (Card Status) of Card)
						    (QUOTE ACTIVE))
				     else (fetch (Card IndexDirtyFlg) of Card))
				   (NC.PutIndexEntry Card))))))))

(NC.GetHashArray
  (LAMBDA (NoteFile QuietFlg OperationMsg Don'tGetSpecialCardsFlg InterestedWindow)
                                                             (* fgh: "27-Jun-86 15:22")

          (* * Fill NoteFile's hash array by reading from the index on NoteFile.)



          (* * rht 12/6/85: Fixed to build free list of IndexNum's.)



          (* * rht 12/7/85: Minor addition of print statement in front of loop.)



          (* * fgh 1/16/86 Now special cards are stashed on the NF object as they are read in rather than in a separate 
	  operation later on.)



          (* * rht 2/26/86: Added extra special Registry card.)



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


    (OR OperationMsg (SETQ OperationMsg ""))
    (WITH.MONITOR (NC.FetchMonitor NoteFile)
		  (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
			(CardTotal (SUB1 (fetch (NoteFile NextIndexNum) of NoteFile)))
			IndexNumsFreeList)
		       (OR QuietFlg (NC.PrintMsg InterestedWindow T OperationMsg 
						     "Reading in hash array: item number "
						     1 " out of " CardTotal "." (CHARACTER 13)))
		       (SETFILEPTR Stream (CONSTANT (fetch (NoteFileVersion NoteFileHeaderSize)
							   of (NC.FetchCurrentVersionObject))))
		       (OR QuietFlg (NC.PrintMsg InterestedWindow T OperationMsg 
						     "Reading in hash array: item number "
						     1 " out of " CardTotal "." (CHARACTER 13)))
		       (for IndexNum from 1 to CardTotal bind Card eachtime (BLOCK)
			  do (OR QuietFlg (AND (ZEROP (REMAINDER IndexNum 100))
						     (NC.PrintMsg InterestedWindow T OperationMsg 
							    "Reading in hash array: item number "
								    IndexNum " out of " CardTotal "."
								    (CHARACTER 13))))
			       (SETQ Card (NC.ReadIndexEntry NoteFile))
			       (if (EQ (fetch (Card Status) of Card)
					   (QUOTE FREE))
				   then (push IndexNumsFreeList IndexNum))

          (* * Stash the special cards on the NF object)


			       (AND (NULL Don'tGetSpecialCardsFlg)
				      (LESSP IndexNum 6)
				      (SELECTQ IndexNum
						 (1 (replace (NoteFile TableOfContentsCard)
						       of NoteFile with Card))
						 (2 (replace (NoteFile OrphansCard) of NoteFile
						       with Card))
						 (3 (replace (NoteFile ToBeFiledCard) of NoteFile
						       with Card))
						 (4 (replace (NoteFile LinkLabelsCard)
						       of NoteFile with Card))
						 (5 (replace (NoteFile RegistryCard) of NoteFile
						       with Card))
						 NIL)))
		       (replace (NoteFile IndexNumsFreeList) of NoteFile with IndexNumsFreeList)
		    ))))

(NC.BuildHashArray
  (LAMBDA (NoteFile QuietFlg Don'tGetSpecialCardsFlg InterestedWindow OperationsMsg)
                                                             (* fgh: "27-Jun-86 15:22")

          (* * Create a hash array and fill it from the index array on NoteFile.)



          (* * fgh 1/16/86 Added Don'tGetSpecialCardsFlg parameter to pass to NC.GetHashArray)



          (* * fgh 6/27/86 Added InterestedWindow & OperationsMsg Args.)


    (replace (NoteFile HashArray) of NoteFile with (NC.CreateUIDHashArray
							   (fetch (NoteFile HashArraySize)
							      of NoteFile)))
    (NC.GetHashArray NoteFile QuietFlg OperationsMsg Don'tGetSpecialCardsFlg InterestedWindow)))

(NC.CardSaveFn
  (LAMBDA (WindowOrID QuietFlg DontCheckForOpsInProgressFlg InterestedWindow OperationMsg)
                                                             (* fgh: "27-Jun-86 18:32")

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


    (LET ((Card (NC.CoerceToCard WindowOrID))
	  Window OldRegion NewRegion DoneAPutP OperationInProgress)
         (SETQ Window (NC.FetchWindow Card))
         (SETQ InterestedWindow (OR Window InterestedWindow))
         (if (AND (NULL DontCheckForOpsInProgressFlg)
		      (SETQ OperationInProgress (NC.OperationInProgress Card))
		      (NEQ OperationInProgress (QUOTE Close% Card)))
	     then (NC.PrintOperationInProgressMsg Window "Save Card" OperationInProgress)
	   else (NC.ProtectedCardOperation
		    Card Save% Card (OR QuietFlg (NC.PrintMsg InterestedWindow T
								  (OR OperationMsg "")
								  (NC.FetchTitle Card)
								  ": Checking ... "))
		    (COND
		      ((OR (NC.CardDirtyP Card)
			     (NC.FetchNewCardFlg Card))
			(OR QuietFlg (NC.PrintMsg InterestedWindow NIL "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 NIL "Saving "))
			(OR QuietFlg (NC.PrintMsg InterestedWindow NIL "region, "))
			(NC.PutRegion Card)
			(SETQ DoneAPutP T)))
		    (COND
		      ((NC.FetchTitleDirtyFlg Card)
			(OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL "Saving "))
			(OR QuietFlg (NC.PrintMsg InterestedWindow NIL "title, "))
			(NC.PutTitle Card)
			(SETQ DoneAPutP T)))
		    (COND
		      ((NC.FetchPropListDirtyFlg Card)
			(OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL "Saving "))
			(OR QuietFlg (NC.PrintMsg InterestedWindow NIL "proplist, "))
			(NC.PutPropList Card)
			(SETQ DoneAPutP T)))
		    (COND
		      ((NC.FetchLinksDirtyFlg Card)
			(OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL "Saving "))
			(OR QuietFlg (NC.PrintMsg InterestedWindow NIL "links, "))
			(NC.PutLinks Card)
			(SETQ DoneAPutP T)))
		    (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL (CHARACTER 13)
							    "Nothing changed. "))
                                                             (* It's not a new card anymore.)
		    (NC.SetNewCardFlg Card NIL)
		    (OR QuietFlg (PROGN (NC.PrintMsg InterestedWindow NIL "Done." (CHARACTER
							     13))
					    (if (AND Window (NEQ Window InterestedWindow))
						then (NC.ClearMsg InterestedWindow T)))))))))

(NC.SaveDirtyCards
  (LAMBDA (NoteFile TerminateOperationsInProgressFlg InterestedWindow OperationMsg)
                                                             (* fgh: "27-Jun-86 15:40")

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


    (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 NIL T InterestedWindow OperationMsg)))
         (for Win in ShrunkenCardWins eachtime (BLOCK) do (SHRINKW Win)))))

(NC.QuitCard
  (LAMBDA (CardIdentifier CallCloseWFlg DontSaveFlg DontRecacheFlg DontCheckOpInProgressFlg 
			  InterestedWindow OperationMsg)     (* fgh: "27-Jun-86 18:08")

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


    (PROG ((Card (NC.CoerceToCard CardIdentifier))
	     Window OperationInProgress)
	    (SETQ Window (NC.FetchWindow 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 (COND
		    ((EQ (NC.InsureProperFiling Card)
			   (QUOTE CANCELLED))
		      (RETURN (QUOTE DON'T)))))

          (* * Otherwise go ahead an quit)


	    (RETURN (NC.ProtectedCardOperation Card Close% Card
						 (PROG NIL
						         (COND
							   ((AND Window NC.CloseCardsOffScreenFlg)
							     (COND
							       ((NOT (NC.FetchSavedRegion Card))
								 (NC.SetSavedRegion
								   Card
								   (WINDOWPROP Window (QUOTE
										   REGION)))))
							     (MOVEW Window 1500 1500)))
						         (OR DontSaveFlg
							       (NC.CardSaveFn Card 
									NC.CloseCardsOffScreenFlg NIL 
										InterestedWindow 
										OperationMsg))
						         (AND Window (WINDOWDELPROP
								  Window
								  (QUOTE CLOSEFN)
								  (FUNCTION NC.QuitCard)))
						         (RETURN (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))))))))))
)
(* * Implementation of locks on NF operations -- new stuff)

(DEFINEQ

(NC.NoteFileProp
  (LAMBDA X                                                  (* fgh: "27-Jun-86 17:06")

          (* * Set or fetch a user data prop from a NF.)



          (* * fgh 6/25/86 First created.)


    (LET ((UserDataPropList (fetch (NoteFile UserProps) of (ARG X 1))))
         (if (GREATERP X 2)
	     then (COND
		      ((LISTP UserDataPropList)
			(LISTPUT UserDataPropList (ARG X 2)
				   (ARG X 3)))
		      (T (replace (NoteFile UserProps) of (ARG X 1)
			    with (LIST (ARG X 2)
					   (ARG X 3)))))
	   else (AND (LISTP UserDataPropList)
			 (LISTGET UserDataPropList (ARG X 2)))))))
)
(DECLARE: EVAL@COMPILE 
(DEFMACRO NC.ProtectedNoteFileOperation (NoteFile Operation &REST Body)
	  (BQUOTE (RESETLST (RESETSAVE (NC.NoteFileProp NoteFile (QUOTE OperationInProgress)
							(QUOTE , Operation))
				       (BQUOTE (NC.NoteFileProp , NoteFile OperationInProgress ,
								(NC.NoteFileProp NoteFile
										 (QUOTE 
									      OperationInProgress)))))
			    (RESETSAVE (NC.NoteFileProp NoteFile (QUOTE ProcessInProgress)
							(THIS.PROCESS))
				       (BQUOTE (NC.NoteFileProp , NoteFile ProcessInProgress ,
								(NC.NoteFileProp NoteFile
										 (QUOTE 
										ProcessInProgress)))))
			    ,@ Body)))
)
(* * Old stuff -- implements new NF menu)

(DEFINEQ

(NC.NoteFileOperations
  (LAMBDA (NoteFile)                                         (* fgh: "27-Jun-86 18:00")
                                                             (* Ask usere to choose which database operation.
							     Called from main menu whenselected fn.)

          (* * fgh 11/14/85 Updated to handle NoteFile object and per NoteFile menus.)



          (* * kirk 14Jan86 Added Close/Delete cards and changed the format)



          (* * fgh 6/13/86 Now sets BusyOperation of NF menu to something interesting.)


    (LET ((NoteFileMenu (fetch (NoteFile Menu) of NoteFile))
	  (Font NC.MenuFont)
	  (FullFileName (fetch (NoteFile FullFileName) of NoteFile))
	  NoteFileMenuWindow Menu)
         (SPAWN.MOUSE)
         (SETQ NoteFileMenuWindow (WFROMMENU NoteFileMenu))
         (OR (SETQ Menu (WINDOWPROP NoteFileMenuWindow (QUOTE DatabaseOperationsMenu)))
	       (WINDOWPROP NoteFileMenuWindow (QUOTE DatabaseOperationsMenu)
			     (SETQ Menu
			       (create MENU
					 ITEMS ←(BQUOTE ((Open (NC.OpenDatabaseFile , NoteFile)
								 "Opens this NoteFile.")
							   (Checkpoint (NC.CheckpointDatabase
									 , NoteFile)
								       
						"Checkpoint this NoteFile, saving changed cards.")
							   (Close (NC.CloseDatabaseFile , NoteFile)
								  "Closes this NoteFile.")
							   (Abort (NC.AbortSession , NoteFile)
								  
					     "Close NF, deleteing changes since last checkpoint.")
							   (Compact (NC.CompactNoteFile , NoteFile)
								    
							  "Compacts a NoteFile to a target file."
								    (SUBITEMS (
Compact% To% Target% File (NC.CompactNoteFile , NoteFile)
			  "Compacts this NoteFile to a target file.")
									      (Compact% In% Place
										(NC.CompactNoteFile
										  , NoteFile NIL T)
										
							       "Compacts this NoteFile in place.")))
							   (Inspect&Repair
							     (NC.InspectAndRepairNoteFile , 
											 NoteFile)
							     
						 "Inspects and optionally repairs this NoteFile."
							     (SUBITEMS (Read% Substances
									 (
								      NC.InspectAndRepairNoteFile
									   , NoteFile T)
									 
"Inspects and optionally repairs a Notefile, but reads every substance.  This slows it WAY down.")))
							   (Copy (NC.CopyNoteFile , NoteFile)
								 
							 "Copies this notefile to a target file.")
							   (Rename (NC.RenameNoteFile , NoteFile)
								   "Rename this NoteFile")
							   (Delete (NC.DeleteDatabaseFile
								     (QUOTE , (PACKFILENAME
										(QUOTE VERSION)
										NIL
										(QUOTE BODY)
										FullFileName))
								     NoteFileMenuWindow)
								   
						   "Deletes the oldest version of this NoteFile.")))
					 CHANGEOFFSETFLG ←(QUOTE Y)
					 MENUOFFSET ←(CONS -1 0)
					 CENTERFLG ← NIL
					 TITLE ← "NoteFile Ops"
					 MENUTITLEFONT ← Font
					 MENUFONT ← Font
					 ITEMHEIGHT ←(IPLUS (FONTPROP Font (QUOTE HEIGHT))
							      1)
					 WHENSELECTEDFN ←(FUNCTION (LAMBDA (Item Menu Button)
					     (WINDOWPROP (WFROMMENU (fetch (NoteFile Menu)
									   of (GETMENUPROP
										  Menu
										  (QUOTE NoteFile)))
									)
							   (QUOTE BusyOperation)
							   (CAR Item))
					     (DEFAULTWHENSELECTEDFN Item Menu Button)))))))
         (PUTMENUPROP Menu (QUOTE NoteFile)
			NoteFile)
         (MENU Menu))))

(NC.SetUpNoteFileInterface
  (LAMBDA (NoteFile Position)                                (* fgh: "27-Jun-86 17:12")

          (* * Create the NoteCards control menu for a NoteFile)



          (* * kirk 13Jan85 Decreased the size of the NoteFile Menu)



          (* * fgh 1/22/86 Fixed the ghost box size when position menu.)



          (* * rht 5/6/86: Now restores the menu's WhenSelectedFn and ungrays its items if already existed.)



          (* * fgh 6/27/86 Added position argument)


    (LET ((Font (FONTCREATE (QUOTE HELVETICA)
			      10
			      (QUOTE BOLD)))
	  (TitleFont (FONTCREATE (QUOTE HELVETICA)
				   12
				   (QUOTE BOLD)))
	  NoteFileMenuWindow NoteFileMenu FullFileName)      (* Main Menu)
         (SETQ FullFileName (fetch (NoteFile FullFileName) of NoteFile))
         (if (SETQ NoteFileMenu (fetch (NoteFile Menu) of NoteFile))
	     then (for Item in (fetch (MENU ITEMS) of NoteFileMenu)
		       do (SHADEITEM Item NoteFileMenu WHITESHADE))
		    (replace (MENU WHENSELECTEDFN) of NoteFileMenu
		       with (FUNCTION NC.NoteFileMenuWhenSelectedFn))
	   else (PROGN (SETQ NoteFileMenu (create MENU
							  ITEMS ←(QUOTE ((NewCards NIL 
		       "Create a new Text card (left button) or other card type (middle button).")
									    (Show% Box NIL 
							"Bring up one of the standard FileBoxes.")))
							  WHENSELECTEDFN ←(FUNCTION 
							    NC.NoteFileMenuWhenSelectedFn)
							  CENTERFLG ← T
							  MENUBORDERSIZE ← 1
							  MENUOUTLINESIZE ← 2
							  MENUCOLUMNS ← 2
							  MENUFONT ← Font
							  TITLE ←(FILENAMEFIELD FullFileName
										  (QUOTE NAME))
							  ITEMHEIGHT ←(IPLUS 6 (FONTPROP
										 Font
										 (QUOTE HEIGHT)))
							  ITEMWIDTH ←(IPLUS (STRINGWIDTH
										(QUOTE NewCards)
										Font)
									      10)
							  MENUTITLEFONT ← TitleFont))
			   (replace (MENU MENUPOSITION) of NoteFileMenu
			      with (OR (POSITIONP Position)
					   (GETBOXPOSITION (fetch (MENU IMAGEWIDTH)
								of NoteFileMenu)
							     (fetch (MENU IMAGEHEIGHT)
								of NoteFileMenu)
							     NIL NIL NIL 
					    "Please indicate location for NoteFile control menu.")))))
         (if (WINDOWP (SETQ NoteFileMenuWindow (WFROMMENU NoteFileMenu)))
	     then (FLASHWINDOW NoteFileMenuWindow)
	   else (SETQ NoteFileMenuWindow (ADDMENU NoteFileMenu NIL (GETMENUPROP NoteFileMenu
											(QUOTE
											  OldPosition)
											))))
         (WINDOWPROP NoteFileMenuWindow (QUOTE NoteFile)
		       NoteFile)
         (replace (NoteFile Menu) of NoteFile with NoteFileMenu)
         (WINDOWPROP NoteFileMenuWindow (QUOTE RESHAPEFN)
		       (QUOTE DON'T))
         (WINDOWPROP NoteFileMenuWindow (QUOTE BUTTONEVENTFN)
		       (FUNCTION NC.NoteFileIconButtonEventFn))
         (WINDOWPROP NoteFileMenuWindow (QUOTE SHRINKFN)
		       (QUOTE DON'T))
         (WINDOWADDPROP NoteFileMenuWindow (QUOTE CLOSEFN)
			  (FUNCTION (LAMBDA (Window)
			      (PUTMENUPROP (CAR (WINDOWPROP Window (QUOTE MENU)))
					     (QUOTE OldPosition)
					     (WINDOWPOSITION Window)))))
         (NC.MoveWindowOntoScreen NoteFileMenuWindow))))

(NC.NoteFileMenuWhenSelectedFn
  (LAMBDA (Item Menu Button)                                 (* fgh: "27-Jun-86 17:18")
                                                             (* Function called when one of the items in the top 
							     level menu is chosen.)

          (* * fgh 11/14/85 Updated to handle NoteFile object and per NoteFile menus.)



          (* * kirk 18Jun86 Adopted to new smaller NoteFile icon)



          (* * fgh 6/26/86 Added lock to prevent conflicting operations.)


    (LET ((Window (WFROMMENU Menu))
	  NoteFile)
         (SETQ NoteFile (WINDOWPROP Window (QUOTE NoteFile)))
         (RESETLST (RESETSAVE (SHADEITEM Item Menu GRAYSHADE)
				  (LIST (QUOTE SHADEITEM)
					  Item Menu WHITESHADE))
		     (if (NULL (NC.NoteFileOpenP NoteFile))
			 then (NC.PrintMsg Window T "Can't." (CHARACTER 13)
					       (fetch (NoteFile FullFileName) of NoteFile)
					       " is not open."
					       (CHARACTER 13))
		       elseif (PROCESSP (NC.NoteFileProp NoteFile (QUOTE ProcessInProgress)))
			 then (NC.PrintOperationInProgressMsg Window (CAR Item)
								  (NC.NoteFileProp NoteFile
										     (QUOTE 
									      OperationInProgress)))
				NIL
		       else (SELECTQ (CAR Item)
					 (NewCards (COND
						     ((EQ Button (QUOTE LEFT))
						       (NC.MakeNoteCard NC.DefaultCardType NoteFile)
						       )
						     (T (NC.MakeNoteCard NIL NoteFile))))
					 (Show% Box (COND
						      ((EQ Button (QUOTE LEFT))
							(NC.EditNoteCard (fetch (NoteFile 
									      TableOfContentsCard)
									      of NoteFile)))
						      (T (NC.ChooseTopLevelCard NoteFile))))
					 NIL))))))

(NC.NoteFileIconButtonEventFn
  (LAMBDA (Window)                                           (* fgh: "27-Jun-86 17:55")

          (* * Bring up NoteFile Menues)


    (LET (NoteFile Menu)
         (TOTOPW Window)
         (if (GREATERP 19 (LASTMOUSEY Window))
	     then (APPLY* (WINDOWPROP Window (QUOTE CURSORMOVEDFN))
			      Window)
	   else                                            (* title bar)
		  (SETQ NoteFile (WINDOWPROP Window (QUOTE NoteFile)))
		  (if (LASTMOUSESTATE MIDDLE)
		      then (MENU (OR (WINDOWPROP Window (QUOTE NameMenu))
					   (PROGN
					     (WINDOWPROP
					       Window
					       (QUOTE NameMenu)
					       (SETQ Menu (create
						   MENU
						   ITEMS ←(LIST (LIST (fetch (NoteFile 
										     FullFileName)
									     of NoteFile)
									  NIL
									  (fetch (NoteFile 
										     FullFileName)
									     of NoteFile)))
						   TITLE ← NIL)))
					     Menu)))
		    else (COND
			     ((NULL (WINDOWPROP Window (QUOTE BusyOperation)))
			       (RESETLST (RESETSAVE (WINDOWPROP Window (QUOTE BusyOperation)
								      "Operation")
							(BQUOTE (WINDOWPROP , Window 
										BusyOperation NIL)))
					   (NC.NoteFileOperations NoteFile)))
			     (T (NC.PrintMsg NIL NIL (CHARACTER 13)
					       (WINDOWPROP Window (QUOTE BusyOperation))
					       " in progress.  Please wait."))))))))

(NC.ClosedNoteFileMenuWhenSelectedFn
  (LAMBDA (Item Menu Button)                                 (* fgh: "27-Jun-86 17:20")

          (* * This WhenSelectedFn called for menu of a closed notefile. Just prints a message.)


    (LET ((NoteFile (WINDOWPROP (WFROMMENU Menu)
				  (QUOTE NoteFile))))
         (AND (type? NoteFile NoteFile)
		(NC.PrintMsg (WFROMMENU Menu)
			       T
			       (fetch (NoteFile FullFileName) of NoteFile)
			       " is not an open notefile.")
		(DISMISS 1000)
		(NC.ClearMsg (WFROMMENU Menu)
			       T)))))

(NC.ChooseTopLevelCard
  (LAMBDA (NoteFile)                                         (* fgh: "27-Jun-86 18:03")

          (* Let the user choose one of the top level cards. Top level cards are specified by globalvar NC.TopLevelCards 
	  which is a list of IDs)



          (* * fgh 11/14/85 Updated to handle NoteFile object and per NoteFile menus.)



          (* * kirk 6May86 Deleted SETQ of undeclared Menu var in the last expression)


    (LET ((NoteFileMenu (fetch (NoteFile Menu) of NoteFile))
	  Menu W Z)
         (SETQ Menu (create MENU
				ITEMS ←(for Card in (NC.FetchTopLevelCards NoteFile)
					  collect (LIST (NC.RetrieveTitle Card)
							    Card))
				CENTERFLG ← T
				MENUFONT ←(FONTCREATE (QUOTE HELVETICA)
							10
							(QUOTE BOLD))
				WHENSELECTEDFN ←(FUNCTION (LAMBDA (Item Button Menu)
				    (NC.EditNoteCard (CADR Item))))
				TITLE ← "FileBox?"))
         (SETQ W (MENUITEMREGION (CAR (NTH (fetch (MENU ITEMS) of NoteFileMenu)
						   2))
				     NoteFileMenu))
         (SETQ Z (WINDOWPROP (WFROMMENU NoteFileMenu)
				 (QUOTE REGION)))
         (replace (MENU MENUPOSITION) of Menu with (create
							     POSITION
							     XCOORD ←(IPLUS (fetch (REGION LEFT)
										 of W)
									      (fetch (REGION LEFT)
										 of Z))
							     YCOORD ←(IPLUS
							       (fetch (REGION TOP) of W)
							       (fetch (REGION BOTTOM) of Z)
							       (IMINUS (fetch (MENU IMAGEHEIGHT)
									    of Menu)))))
         (MENU Menu))))

(NC.GetSpecialCards
  (LAMBDA (NoteFile QuiteFlg InterestedWindow OperationMsg)
                                                             (* fgh: "27-Jun-86 20:29")

          (* * fgh 1/16/86 Activate but don't display the special cards. This essentially caches them for fast access.)



          (* * fgh 6/27/86 Added InterestedWindow & OperationMsg args.)


    (OR QuiteFlg (NC.PrintMsg InterestedWindow T OperationMsg "Loading top level cards ..."
				  (CHARACTER 13)))
    (NCP.ActivateCards (LIST (fetch (NoteFile TableOfContentsCard) of NoteFile)
				 (fetch (NoteFile OrphansCard) of NoteFile)
				 (fetch (NoteFile ToBeFiledCard) of NoteFile)
				 (fetch (NoteFile LinkLabelsCard) of NoteFile)
				 (fetch (NoteFile RegistryCard) of NoteFile)))))
)
(* * Redefined stuff fore NoteCards Icon)

(DEFINEQ

(NC.DoNoteFileOp
  (LAMBDA (Op)                                               (* fgh: "27-Jun-86 20:16")

          (* * Do a NoteFile op chosen from NC icon menu)


    (SELECTQ Op
	       (Open% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu T NIL NC.NoteCardsIconWindow
									 (QUOTE Open% NoteFile))))
				    (if (NULL NoteFile)
					then NIL
				      else (if (EQ NoteFile (QUOTE NEW))
						 then (SETQ NoteFile NIL))
					     (NC.OpenDatabaseFile NoteFile NIL NIL NIL NIL NIL NIL 
								    NIL NIL NIL 
								    NC.NoteCardsIconWindow))))
	       (Checkpoint% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu NIL T 
									   NC.NoteCardsIconWindow
									       (QUOTE 
									     Checkpoint% NoteFile))))
				          (if NoteFile
					      then (NC.CheckpointDatabase NoteFile NIL NIL NIL 
									      NIL 
									   NC.NoteCardsIconWindow))))
	       (Close% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu NIL T 
									  NC.NoteCardsIconWindow
									  (QUOTE Close% NoteFile))))
				     (if NoteFile
					 then (NC.CloseDatabaseFile NoteFile 
									NC.NoteCardsIconWindow))))
	       (Abort% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu NIL T 
									  NC.NoteCardsIconWindow
									  (QUOTE Abort% NoteFile))))
				     (if NoteFile
					 then (NC.AbortSession NoteFile))))
	       (Compact% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu T NIL 
									   NC.NoteCardsIconWindow
									    (QUOTE 
										Compact% NoteFile))))
				       (if (NULL NoteFile)
					   then NIL
					 else (if (EQ NoteFile (QUOTE NEW))
						    then (SETQ NoteFile NIL))
						(NC.CompactNoteFile NoteFile NIL NIL 
								      NC.NoteCardsIconWindow))))
	       (Compact% In% Place (LET ((NoteFile (NC.ListOfNoteFilesMenu T NIL 
									   NC.NoteCardsIconWindow
									     (QUOTE 
										Compact% NoteFile))))
				        (if (NULL NoteFile)
					    then NIL
					  else (if (EQ NoteFile (QUOTE NEW))
						     then (SETQ NoteFile NIL))
						 (NC.CompactNoteFile NoteFile NIL T 
								       NC.NoteCardsIconWindow))))
	       (Inspect&Repair% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu T NIL 
									   NC.NoteCardsIconWindow
										   (QUOTE 
									 Inspect&Repair% NoteFile))))
					      (if (NULL NoteFile)
						  then NIL
						else (if (EQ NoteFile (QUOTE NEW))
							   then (SETQ NoteFile NIL))
						       (NC.ScavengerPhase1 NoteFile))))
	       (Read% Substances (LET ((NoteFile (NC.ListOfNoteFilesMenu T NIL 
									   NC.NoteCardsIconWindow
									   (QUOTE 
									 Inspect&Repair% NoteFile))))
				      (if (NULL NoteFile)
					  then NIL
					else (if (EQ NoteFile (QUOTE NEW))
						   then (SETQ NoteFile NIL))
					       (NC.ScavengerPhase1 NoteFile T))))
	       (Copy% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu T (QUOTE CLOSED)
									 NC.NoteCardsIconWindow
									 (QUOTE Copy% NoteFile))))
				    (if (NULL NoteFile)
					then NIL
				      else (if (EQ NoteFile (QUOTE NEW))
						 then (SETQ NoteFile NIL))
					     (NC.CopyNoteFile NoteFile NIL NC.NoteCardsIconWindow)))
			       )
	       (Rename% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu T (QUOTE CLOSED)
									   (QUOTE Rename% NoteFile))
						 ))
				      (if (NULL NoteFile)
					  then NIL
					else (if (EQ NoteFile (QUOTE NEW))
						   then (SETQ NoteFile NIL))
					       (NC.RenameNoteFile NoteFile NIL NC.NoteCardsIconWindow)
					    )))
	       (Delete% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu T (QUOTE CLOSED)
									   (QUOTE Delete% NoteFile))
						 ))
				      (if (NULL NoteFile)
					  then NIL
					else (if (EQ NoteFile (QUOTE NEW))
						   then (SETQ NoteFile NIL))
					       (NC.DeleteDatabaseFile NoteFile 
									NC.NoteCardsIconWindow))))
	       (Create% NoteFile (NC.CreateDatabaseFile NIL NIL NIL NIL NIL NIL 
							  NC.NoteCardsIconWindow))
	       NIL)))

(NC.ListOfNoteFilesMenu
  (LAMBDA (IncludeNewNoteFileFlg ShowOnlyOpenNFsFlg InterestedWindow Operation)
                                                             (* fgh: "27-Jun-86 20:26")

          (* * Bring up a menu of all notefiles found in the notefiles hash array. Also allow user to open a new notefile.)



          (* * kirk 23Jan86 Added AskYesOrNo and InterestedWindow parameter)



          (* * fgh 6/8/86 Added check to make sure NoteFile is open if it has a menu on the screen. Needed to handle case of 
	  liongering NF menus.)



          (* * fgh 6/24/86 Changed to be a general function rather than one specific for opening. Now just returns the chosen
	  name. Also, added IncludeNewNoteFileFlg and ShowOnlyOpenNFsFlg. Removed InterestedWindow arg.)



          (* * fgh 6/27/86 Added InterestedWindow & Operation args and call to NC.DatabaseFileName.)


    (LET (Menu NoteFileMenu FileName RootName Items Result)
         (SETQ Items
	   (BQUOTE (,@(for NoteFile in (NC.ListOfNoteFiles) bind Stream FileName
			   when (OR (AND (EQ ShowOnlyOpenNFsFlg (QUOTE CLOSED))
					       (NULL (NC.NoteFileOpenP NoteFile)))
					(NULL ShowOnlyOpenNFsFlg)
					(NC.NoteFileOpenP NoteFile))
			   collect (LIST (CONCAT
					       (if (NC.NoteFileOpenP NoteFile)
						   then (if (WINDOWP
								  (WFROMMENU (fetch (NoteFile
											  Menu)
										  of NoteFile)))
							      then "* "
							    else "$ ")
						 else "  ")
					       (SUBSTRING (SETQ RootName
							      (FILENAMEFIELD (SETQ FileName
										 (fetch
										   (NoteFile 
										     FullFileName)
										    of NoteFile))
									       (QUOTE NAME)))
							    1
							    (MIN 20 (NCHARS RootName))))
					     NoteFile
					     (CONCAT "Open NoteFile " FileName 
						       " or bring up its menu.")))
		       ,@(if IncludeNewNoteFileFlg
			     then (LIST (QUOTE ("-- Other NoteFile --" (QUOTE NEW)
									     
				    "Open some other notefile - you'll be prompted for the name.")))
			   else NIL))))
         (SETQ Result (if (NULL Items)
			    then NIL
			  elseif (AND (EQ (LENGTH Items)
						1)
					  (EQUAL (CADAR Items)
						   (QUOTE (QUOTE NEW))))
			    then (QUOTE NEW)
			  else (MENU (create MENU
						   ITEMS ← Items
						   TITLE ←(OR Operation "NoteFiles")
						   MENUFONT ← NC.MenuFont))))
         (if (EQ Result (QUOTE NEW))
	     then (SETQ Result (NC.DatabaseFileName (CONCAT "Name of NoteFile to "
								    (SUBSTRING Operation 1 -9)
								    (CHARACTER 13))
							  " -- " T T NIL InterestedWindow)))
     Result)))
)
(* * New fns for NCINTERFACE)

(DEFINEQ

(NC.NoteFileMenuWindowP
  (LAMBDA (Window)                                           (* fgh: "13-Jun-86 15:01")

          (* * IS Window a NoteFile menu?)



          (* * fgh 6/13/86 First created.)


    (WINDOWPROP Window (QUOTE NoteFile))))

(NC.NoteCardsIconWindowP
  (LAMBDA (Window)                                           (* fgh: "25-Jun-86 19:43")

          (* * Is this the NC session icon window?)



          (* * fgh 6/25/86 First created.)


    (EQ Window NC.NoteCardsIconWindow)))

(NC.NoteCardsWindowP
  (LAMBDA (Window)                                           (* fgh: "25-Jun-86 19:47")

          (* * Is this some sort of NoteCards window?)


    (OR (NC.CoerceToCard Window)
	  (NC.NoteFileMenuWindowP Window)
	  (NC.NoteCardsIconWindowP Window))))
)
(DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA )

(ADDTOVAR NLAML )

(ADDTOVAR LAMA NC.NoteFileProp NC.PrintMsg)
)
(PUTPROPS FGHPATCH073 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (2312 43684 (NC.PrintMsg 2322 . 7801) (NC.AskUser 7803 . 10489) (NC.AskYesOrNo 10491 . 
12547) (NC.ClearMsg 12549 . 14428) (NC.ClosePropListEditor 14430 . 17161) (NC.AttachNoteFileName 17163
 . 22069) (NC.SelectNoteCards 22071 . 32479) (NC.GETPROMPTWINDOW 32481 . 36944) (NC.ShowInfo 36946 . 
39691) (NC.OpenPropListEditor 39693 . 43682)) (43757 79560 (NC.AssignTitle 43767 . 46549) (
NC.InsureProperFiling 46551 . 47340) (NC.AddLinkToCard 47342 . 49203) (NC.AddLinksToCard 49205 . 51292
) (NC.AddGlobalLinksToCard 51294 . 53343) (NC.AddParents 53345 . 55223) (NC.UnfileNoteCard 55225 . 
58331) (NC.QuitCard 58333 . 61772) (NC.MakeFilingLinks 61774 . 64043) (NC.CheckFiling 64045 . 65679) (
NC.QuitWithoutSaving 65681 . 71771) (NC.CardSaveFn 71773 . 75934) (NC.DeleteNoteCards 75936 . 78113) (
NC.DeleteNoteCard 78115 . 79558)) (79629 83822 (NC.PrintOperationInProgressMsg 79639 . 80582) (
NC.CardOperationsInProgress 80584 . 82579) (NC.TerminateCardOperationInProgress 82581 . 83162) (
NC.OperationInProgress 83164 . 83820)) (84532 124762 (NC.CloseDatabaseFile 84542 . 92240) (
NC.OpenDatabaseFile 92242 . 104084) (NC.CheckpointDatabase 104086 . 108124) (NC.CopyNoteFile 108126 . 
110428) (NC.PutHashArray 110430 . 111906) (NC.GetHashArray 111908 . 114785) (NC.BuildHashArray 114787
 . 115526) (NC.CardSaveFn 115528 . 119689) (NC.SaveDirtyCards 119691 . 121319) (NC.QuitCard 121321 . 
124760)) (124829 125557 (NC.NoteFileProp 124839 . 125555)) (126244 139847 (NC.NoteFileOperations 
126254 . 129794) (NC.SetUpNoteFileInterface 129796 . 133300) (NC.NoteFileMenuWhenSelectedFn 133302 . 
135142) (NC.NoteFileIconButtonEventFn 135144 . 136703) (NC.ClosedNoteFileMenuWhenSelectedFn 136705 . 
137307) (NC.ChooseTopLevelCard 137309 . 139005) (NC.GetSpecialCards 139007 . 139845)) (139896 147192 (
NC.DoNoteFileOp 139906 . 144280) (NC.ListOfNoteFilesMenu 144282 . 147190)) (147229 148090 (
NC.NoteFileMenuWindowP 147239 . 147509) (NC.NoteCardsIconWindowP 147511 . 147785) (NC.NoteCardsWindowP
 147787 . 148088)))))
STOP