(FILECREATED "25-Mar-87 11:29:53" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH222.;3 38767  

      changes to:  (FNS NC.QuitCard NC.AssignTitle NC.CardSaveFn NC.SelectNoteCards 
			NC.CoerceToInterestedWindow)
		   (VARS RHTPATCH222COMS)

      previous date: "24-Mar-87 15:24:01" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH222.;1)


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

(PRETTYCOMPRINT RHTPATCH222COMS)

(RPAQQ RHTPATCH222COMS ((* * Some hacking of the InterestedWindow stuff. Everyone who needs to 
			     compute an InterestedWindow should now call NC.CoerceToInterestedWindow.)
			  (* * New function for NCUTILITIES)
			  (FNS NC.CoerceToInterestedWindow)
			  (* * Changes to NCINTERFACE)
			  (FNS NC.SelectNoteCards)
			  (* * Changes to NCCARDS)
			  (FNS NC.QuitCard NC.AssignTitle NC.CheckFiling NC.CardSaveFn)
			  (* * Changes to NCLINKS)
			  (FNS NC.MakeFilingLinks)))
(* * Some hacking of the InterestedWindow stuff. Everyone who needs to compute an 
InterestedWindow should now call NC.CoerceToInterestedWindow.)

(* * New function for NCUTILITIES)

(DEFINEQ

(NC.CoerceToInterestedWindow
  (LAMBDA (WinOrCardOrNoteFile)                              (* rht: "24-Mar-87 14:14")

          (* * Try to return a window that can be used for NC.PrintMsg, NC.AskUser, etc. If arg is an open win, use that.
	  If displayed card, then use its window. If notefile, then use its notefile icon if open. Last hope is to use the 
	  session icon if open. Returning nil means that main prompt window will have to be used.)


    (DECLARE (GLOBALVARS NC.NoteCardsIconWindow))
    (LET (Card NoteFile)
         (COND
	   ((OPENWP WinOrCardOrNoteFile)
	     WinOrCardOrNoteFile)
	   ((AND (type? NoteFile WinOrCardOrNoteFile)
		   (OPENWP (NCP.NoteFileIconWindow WinOrCardOrNoteFile))))
	   ((AND (NC.CardP (SETQ Card (CAR (NLSETQ (NC.CoerceToCard WinOrCardOrNoteFile)))
				 ))
		   (OPENWP (NC.FetchWindow Card))))
	   ((AND (NC.CardP Card)
		   (SETQ NoteFile (fetch (Card NoteFile) of Card))
		   (OPENWP (NCP.NoteFileIconWindow NoteFile))))
	   ((OPENWP NC.NoteCardsIconWindow))
	   (T NIL)))))
)
(* * Changes to NCINTERFACE)

(DEFINEQ

(NC.SelectNoteCards
  (LAMBDA (SingleCardFlg SelectionPredicate Menu InstigatingCardOrWindow Msg CheckForCancelFlg)
                                                             (* rht: "24-Mar-87 15:38")

          (* 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. This function should always be called from inside of an NC.CardSelectionOperation 
	  wrapper.)



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



          (* * fgh 7/5/86 Added code to put CRs into printout of selected cards in order to keep prompt window from getting 
	  infinitely wide to accomdate the printout.)



          (* * rht 10/5/86: Now allows choice of cards from remote notefile.)



          (* * rht 10/18/86: Give TTY process to process that originally had it if possible.)



          (* * rht & pmi 11/14/86: Now checks for valid card before testing SelectionPredicate.)



          (* * pmi 12/5/86 Modified prompt messages to mention SHIFT-selection.)



          (* * pmi 12/12/86: Removed obsolete ReturnLinksFlg argument.)



          (* * rg 3/18/87 reworked for NC.CardSelectionOperation: added NAMED-RESETSAVE forms for Card locking.)



          (* * 3/23/87: Changed to call REMOVEWINDOW instead of DETACHWINDOW before deleting the attached menu.
	  Also changed so that menu is attached to InstigatingWindow rather than to PromptWindow. This makes it possible for 
	  windows to "slide down" when selection ends.)



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


    (DECLARE (USEDFREE NC.SelectNoteCardsResetVar))
    (LET (Window Card ButtonEventFn InstigatingWindow InstigatingCard InstigatingNoteFile MenuWindow 
		 PromptWindow CopyInsertEvent SelectedCards PromptWindowProcess OldTTYProcess 
		 OpInProgress ResetItems TTYResetVar InternalResetVar)
         (NAMED-RESETLST
	   InternalResetVar
	   (OR SelectionPredicate (SETQ SelectionPredicate (FUNCTION TRUE)))
	   (SETQ PromptWindow (OR (NC.AttachPromptWindow (SETQ InstigatingWindow
								 (NC.CoerceToInterestedWindow
								   InstigatingCardOrWindow)))
				      PROMPTWINDOW))
	   (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 shift-selected:  ")
	   (SETQ OldTTYProcess (TTY.PROCESS))

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


	   (ALLOW.BUTTON.EVENTS)

          (* * 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))))
	   (NAMED-RESETSAVE InternalResetVar (WINDOWPROP PromptWindow (QUOTE SelectedCards)
							     NIL)
			      (BQUOTE (WINDOWPROP , PromptWindow (QUOTE SelectedCards)
						      NIL)))
	   (NAMED-RESETSAVE InternalResetVar (WINDOWPROP PromptWindow (QUOTE SelectingCards)
							     T)
			      (BQUOTE (WINDOWPROP , PromptWindow SelectingCards NIL)))
	   (NAMED-RESETSAVE InternalResetVar (WINDOWPROP PromptWindow (QUOTE SelectCardsMonitor)
							     (CREATE.MONITORLOCK (QUOTE 
										      SelectCards)))
			      (BQUOTE (WINDOWPROP , PromptWindow SelectCards 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))))))
	   (NAMED-RESETSAVE InternalResetVar NIL (BQUOTE (DEL.PROCESS , PromptWindowProcess)))

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


	   (NAMED-RESETSAVE InternalResetVar NIL
			      (BQUOTE (PROGN (AND (HASTTYWINDOWP , PromptWindowProcess)
							(TTY.PROCESS (if (AND (PROCESSP
										      , OldTTYProcess)
										    (HASTTYWINDOWP
										      , OldTTYProcess)
										    )
									   then , OldTTYProcess
									 else 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)))
	   (NAMED-RESETSAVE InternalResetVar (PROGN (ATTACHMENU
							  Menu
							  (OR InstigatingWindow PROMPTWINDOW)
							  (if InstigatingWindow
							      then (QUOTE TOP)
							    else (QUOTE BOTTOM))
							  (if (AND (WINDOWP InstigatingWindow)
								       (WINDOWP PromptWindow))
							      then (CDR (WINDOWPROP
									      PromptWindow
									      (QUOTE WHEREATTACHED))
									    )
							    else (QUOTE LEFT)))
							(WINDOWPROP (WFROMMENU Menu)
								      (QUOTE SelectionPromptWindow)
								      PromptWindow))
			      (BQUOTE (PROGN (REMOVEWINDOW (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)


	   (WITH.MONITOR
	     (WINDOWPROP PromptWindow (QUOTE SelectCardsMonitor))
	     (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 (NOT (EQ SelectedCards (WINDOWPROP PromptWindow (QUOTE 
										    SelectedCards))))
		     do (MONITOR.AWAIT.EVENT (WINDOWPROP PromptWindow (QUOTE 
									       SelectCardsMonitor))
						 CopyInsertEvent))

          (* * Get the latest selection list)


		  (SETQ SelectedCards (WINDOWPROP PromptWindow (QUOTE SelectedCards)))
		  (NAMED-RESETLST
		    TTYResetVar

          (* * Turn off the caret)


		    (NAMED-RESETSAVE TTYResetVar (TTY.PROCESS (THIS.PROCESS)))

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


		    (SETQ Card (CAR SelectedCards))
		    (WITH.MONITOR
		      NC.LockLock
		      (COND
			((AND (NEQ Card (QUOTE DONE))
				(NEQ SelectedCards (QUOTE CANCELLED))
				(NEQ Card (QUOTE *New% Card*)))

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


			  (COND
			    ((EQ Card (QUOTE *Undo% Selection*))
                                                             (* Chop off two elements from the list -
							     the indicator and the previous item.)
			      (SETQ Card (CADR SelectedCards))
			      (WINDOWPROP PromptWindow (QUOTE SelectedCards)
					    (SETQ SelectedCards (CDDR SelectedCards)))
                                                             (* now get our hands off of all the locks we've 
							     acquired for this card)
			      (NAMED-RESETUNSAVE NC.SelectNoteCardsResetVar (NC.FetchUserDataProp
						     Card
						     (QUOTE ResetItems)))
			      (NC.SetUserDataProp Card (QUOTE ResetItems)
						    NIL)
			      (NC.ClearMsg InstigatingWindow NIL))
			    ((OR (NOT (NC.ValidCardP Card))
				   (NULL (APPLY* SelectionPredicate Card)))
                                                             (* Does this card match the slection predicate)
			      (NC.PrintMsg InstigatingWindow T "*** Invalid selection. ***"
					     (CHARACTER 13))
			      (WINDOWPROP PromptWindow (QUOTE SelectedCards)
					    (SETQ SelectedCards (CDR SelectedCards))))
			    ((SETQ OpInProgress (NC.CardCheckOpInProgress Card))
			      (NC.PrintOperationInProgressMsg InstigatingWindow "Select Card" 
								OpInProgress)
			      (DISMISS 1000)
			      (WINDOWPROP PromptWindow (QUOTE SelectedCards)
					    (SETQ SelectedCards (CDR SelectedCards)))
			      (NC.ClearMsg InstigatingWindow NIL))
			    (T                               (* A valid selection.)
			       (NC.ClearMsg InstigatingWindow NIL)
			       (SETQ ResetItems NIL)
			       (SETQ ResetItems (CONS (NAMED-RESETSAVE 
								       NC.SelectNoteCardsResetVar
									     (NC.SetUserDataProp
									       Card
									       (QUOTE 
										ProcessInProgress)
									       (THIS.PROCESS))
									     (BQUOTE (
									       NC.SetUserDataProp
											 , Card 
										ProcessInProgress NIL)
										       ))
							  ResetItems))
			       (SETQ ResetItems (CONS (NAMED-RESETSAVE 
								       NC.SelectNoteCardsResetVar
									     (NC.SetUserDataProp
									       Card
									       (QUOTE 
									      OperationInProgress)
									       "Select Card")
									     (BQUOTE (
									       NC.SetUserDataProp
											 , Card 
									      OperationInProgress NIL)
										       ))
							  ResetItems))
			       (SETQ ResetItems
				 (CONS (NAMED-RESETSAVE NC.SelectNoteCardsResetVar
							    (NC.NoteFileProp
							      (fetch (Card NoteFile) of Card)
							      (QUOTE CardProcessInProgressList)
							      (CONS (THIS.PROCESS)
								      (NC.NoteFileProp
									(fetch (Card NoteFile)
									   of Card)
									(QUOTE 
									CardProcessInProgressList))))
							    (BQUOTE (NC.ResetCardProcessInProgress
									,
									(fetch (Card NoteFile)
									   of Card))))
					 ResetItems))
			       (SETQ ResetItems (CONS (NAMED-RESETSAVE
							    NC.SelectNoteCardsResetVar
							    (SETQ NC.CardBusyList (CONS (
										     THIS.PROCESS)
											    
										  NC.CardBusyList))
							    (QUOTE (SETQ NC.CardBusyList
									     (DREMOVE (
										     THIS.PROCESS)
											
										  NC.CardBusyList))))
							  ResetItems))
			       (NAMED-RESETSAVE InternalResetVar (NC.SetUserDataProp
						    Card
						    (QUOTE ResetItems)
						    ResetItems)
						  (BQUOTE (NC.SetUserDataProp , Card ResetItems 
										  NIL)))))

          (* * Print the results in the prompt window)


			  (NC.PrintMsg InstigatingWindow NIL (COND
					   (Msg (CONCAT Msg (CHARACTER 13)))
					   (T ""))
					 "Items selected:  ")
			  (for ThisCard in (REVERSE SelectedCards)
			     do (NC.PrintMsg InstigatingWindow NIL (NC.RetrieveTitle ThisCard)
						 ",  ")
				  (if (AND InstigatingWindow (GREATERP
						 (DSPXPOSITION NIL PromptWindow)
						 (TIMES 1.25 (WINDOWPROP InstigatingWindow
									     (QUOTE WIDTH)))))
				      then (NC.PrintMsg InstigatingWindow NIL (CHARACTER 13)))))
			))))))

          (* * 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))))))
)
(* * Changes to NCCARDS)

(DEFINEQ

(NC.QuitCard
  (LAMBDA (CardIdentifier CallCloseWFlg DontSaveFlg DontRecacheFlg InterestedWindow OperationMsg 
			  QuietFlg Don'tDeactivateFlg)       (* rht: "25-Mar-87 10:23")

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



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



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



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



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



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



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



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



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



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



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



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



          (* * rht 7/14/86: Call NC.DeactivateCard from here instead of in card type QuitFn. Take a Don'tDeactivateFlg as 
	  well.)



          (* * rht 10/7/86: Now removes DELETEME imageobj's from card substance.)



          (* * rht 11/2/86: Now returns DON'T if operation in progress.)



          (* * rht 11/13/86: Now closes open proplist editor if any before saving.)



          (* * rg 3/4/87 rewritten to use new NC.ProtectedCardOperation, removed DontCheckOpInProgressFlg arg)



          (* * rht 3/24/87: Now calls NC.CoerceToInterestedWindow and passes InterestedWindow to NC.InsureProperFiling.)


    (DECLARE (GLOBALVARS NC.RemoveDELETEMEImageObjsFromCardFlg))
    (LET ((Card (NC.CoerceToCard CardIdentifier))
	  Window ReadOnlyCardFlg)
         (SETQ Window (NC.FetchWindow Card))
         (OR InterestedWindow (SETQ InterestedWindow (NC.CoerceToInterestedWindow Card)))
         (NC.ProtectedCardOperation
	   Card "Close Card" InterestedWindow
	   (PROG NIL
	           (SETQ ReadOnlyCardFlg (NC.ReadOnlyCardP Card))
                                                             (* The window not being open should mean that it's 
							     shrunken. If so, expand it.)
	           (COND
		     ((AND Window (NOT (OPENWP Window)))
		       (EXPANDW Window)))

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


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

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


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

          (* * Otherwise go ahead and quit)


	           (RETURN (PROGN                        (* Close open proplist editor if any.)
				      (AND Window (LET ((PropListEditorWindow (
									   NC.PropListEditorOpenP
										  Window)))
						         (AND PropListEditorWindow (CLOSEW 
									     PropListEditorWindow))))
				      (COND
					((AND Window NC.CloseCardsOffScreenFlg)
					  (COND
					    ((NOT (NC.FetchSavedRegion Card))
					      (NC.SetSavedRegion Card (WINDOWPROP Window
										      (QUOTE REGION)
										      ))))
					  (MOVEW Window 1500 1500)))
				      (OR DontSaveFlg (if ReadOnlyCardFlg
							    then (NC.TurnOffDirtyFlgs Card)
							  else
							   (AND 
							    NC.RemoveDELETEMEImageObjsFromCardFlg
								  (
							       NC.RemoveDELETEMEImageObjsFromCard
								    Card
								    (FUNCTION NC.DELETEMEImageObjP))
								  )
							   (NC.CardSaveFn Card (OR 
									NC.CloseCardsOffScreenFlg 
										       QuietFlg)
									    InterestedWindow 
									    OperationMsg)))
				      (AND Window (WINDOWDELPROP Window (QUOTE CLOSEFN)
								     (FUNCTION NC.QuitCard)))
				      (PROG1 (NC.ApplyFn QuitFn Card)
					       (AND CallCloseWFlg Window
						      (PROGN (WINDOWPROP Window (QUOTE 
										   NoteCardObject)
									     NIL)
							       (CLOSEW Window)))
					       (OR Don'tDeactivateFlg (NC.DeactivateCard Card))

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


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

(NC.AssignTitle
  (LAMBDA (CardIdentifier NoClearMsgFlg NewTitle InterestedWindow)
                                                             (* rht: "25-Mar-87 11: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.)



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



          (* * kef 7/16/86: Added obtain write permission.)



          (* * kef 7/24/86: Doesn't release the write lock if this is a new card.)



          (* * kef 7/30/86: Modified to check for Client's concept of whether he owns the write lock or not, thus deciding 
	  whether or not to setup the release of the write lock afterwards.)



          (* * fgh 8/30/86 Converted to use NC.IfCardPartNotBusy.)



          (* * rg 3/3/87 Enlarged scope of NC.ProtectedCardOperation)



          (* * rht 3/23/87: Now takes InterestedWindow arg.)



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


    (ALLOW.BUTTON.EVENTS)
    (LET ((Card (NC.CoerceToCard CardIdentifier))
	  ContainingCard OldTitle Window)
         (NC.ProtectedCardOperation Card "Assign Title" NIL
				    (NC.IfCardPartNotBusy
				      Card
				      (QUOTE TITLE)
				      (OR InterestedWindow (SETQ InterestedWindow (
						NC.CoerceToInterestedWindow Card)))
				      (if (NC.CheckForNotReadOnly Card InterestedWindow 
							      "Can't change titles for cards in ")
					  then (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)
							       InterestedWindow)))
						     (NC.SetTitle Card NewTitle)

          (* * Now do a PutTitle so that anyone else coming along will pick up on the new title. The only exception is if 
	  this card hasn't been written to the NoteFile yet, which is true when the NewCardFlg is T. In that case, we can't 
	  put the title down yet, so just mark it dirty.)


						     (COND
						       ((fetch (Card NewCardFlg) of Card)
							 (NC.SetTitleDirtyFlg Card T))
						       (T (NC.PutTitle Card)
							  (NC.SetTitleDirtyFlg Card NIL)))
						     (AND (WINDOWP (SETQ Window (
									   NC.FetchWindow Card)))
							    (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))
					else NIL))))))

(NC.CheckFiling
  (LAMBDA (Card InterestedWindow)                            (* rht: "24-Mar-87 15:20")
                                                             (* 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.)



          (* * rg 1/28/87 Make sure we always return a useful value)



          (* * rg 3/4/87 rewritten for new version of NC.ProtectedCardOperation)



          (* * rht 3/23/87: Now takes InterestedWindow arg.)



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


    (NC.ProtectedCardOperation Card "Filing" NIL (COND
				 ((NC.CardNeedsFilingP Card)
				   (OR InterestedWindow (SETQ InterestedWindow (
					     NC.CoerceToInterestedWindow Card)))
				   (COND
				     (NC.ForceFilingFlg (NC.MakeFilingLinks Card
									      (CONCAT "This card ("
											(
										 NC.RetrieveTitle
											  Card)
											
							 ") is not currently filed in a FileBox."
											(CHARACTER
											  13))
									      InterestedWindow))
				     (T (NC.PrintMsg InterestedWindow 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))))))
				 (T T)))))

(NC.CardSaveFn
  (LAMBDA (WindowOrID QuietFlg InterestedWindow OperationMsg)
                                                             (* rht: "25-Mar-87 11:28")

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



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



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



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



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



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



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



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



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



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



          (* * kef 7/30/86: Modified to check for Client's concept of whether he owns the write lock or not, thus deciding 
	  whether or not to setup the release of the write lock afterwards.)



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



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



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



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



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



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


    (LET ((Card (NC.CoerceToCard WindowOrID))
	  Window OldRegion NewRegion DoneAPutP)
         (SETQ Window (NC.FetchWindow Card))
         (OR InterestedWindow (SETQ InterestedWindow (NC.CoerceToInterestedWindow Card)))
         (NC.ProtectedCardOperation
	   Card "Save Card" InterestedWindow (LET ((WhenSavedFn (GETPROP (NC.FetchType Card)
									   (QUOTE WhenSavedFn))))
					          (AND WhenSavedFn (APPLY* WhenSavedFn Card)))
	   (if (NC.CheckForNotReadOnly Card InterestedWindow "Can't save cards in ")
	       then (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, "))
                                                             (* Make sure that we have the FROMLINKS of this card.
							     Only necessary because all of the LINKS are written 
							     together.)
			  (RESETLST (until (NC.ApplyFn ObtainWritePermissionFn Card (QUOTE
							     FROMLINKS))
					 do (BLOCK)
					      (NC.PrintMsg InterestedWindow NIL 
						     "waiting for FROMLINKS write permission...."))
				      (RESETSAVE NIL (BQUOTE (APPLY* , (fetch (Card 
									 ReleaseWritePermissionFn)
										of Card)
									   , Card FROMLINKS)))
				      (NC.PutLinks Card)
				      (SETQ DoneAPutP T))))
		      (OR DoneAPutP QuietFlg (NC.PrintMsg InterestedWindow NIL (CHARACTER
								13)
							      "Nothing changed. "))
                                                             (* It's not a new card anymore.)
		      (COND
			((NC.FetchNewCardFlg Card)

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


			  (NC.ApplyFn ReleaseWritePermissionFn Card (QUOTE FROMLINKS))
			  (NC.ApplyFn ReleaseWritePermissionFn Card (QUOTE TITLE))
			  (NC.SetNewCardFlg Card NIL)))
		      (OR QuietFlg (PROGN (NC.PrintMsg InterestedWindow NIL "Done."
							     (CHARACTER 13))
					      (NC.ClearMsg InterestedWindow T))))))))
)
(* * Changes to NCLINKS)

(DEFINEQ

(NC.MakeFilingLinks
  (LAMBDA (Card Msg InterestedWindow)                        (* rht: "24-Mar-87 15:20")
                                                             (* 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)



          (* * pmi 12/5/86: Modified message to NC.SelectNoteCards to mention SHIFT-selection.)



          (* * pmi 12/12/86: Removed obsolete ReturnLinksFlg argument in call to NC.SelectNoteCards.)



          (* * rg 2/19/87 Make sure NewParents always has the real value)



          (* * rg 3/18/87 added NC.CardSelectionOperation wrapper)



          (* * rht 3/23/87: Changed so that message will fit on one less line.)



          (* * rht 3/23/87: Now takes InterestedWindow arg.)



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


    (DECLARE (GLOBALVARS NC.SelectingContentsMenu))
    (NC.CardSelectionOperation (PROG (OneHook NewParents)
				       (OR InterestedWindow (SETQ InterestedWindow (
						 NC.CoerceToInterestedWindow Card)))
				       (SETQ NewParents (NC.SelectNoteCards
					   NIL
					   (FUNCTION NC.FileBoxP)
					   NC.SelectingContentsMenu Card (CONCAT (OR Msg "")
										   
						"('Done' with no selections files in ToBeFiled.)")
					   T))
				       (COND
					 ((NOT (OR (EQ NewParents (QUOTE CANCELLED))
						       (AND NewParents
							      (for ParentCard in NewParents
								 bind OneHook
								 when (NC.MakeChildLink Card 
										       ParentCard 
										 InterestedWindow)
								 do (SETQ OneHook T)
								 finally (RETURN OneHook)))))
					   (NC.PrintMsg InterestedWindow NIL 
							  "No FileBox has been specified."
							  (CHARACTER 13)
							  
						  "This card will be filed in the ToBeFiled Box."
							  (CHARACTER 13))
					   (SETQ NewParents (NC.HookToOrphanCard
					       Card
					       (fetch (NoteFile ToBeFiledCard)
						  of (fetch (Card NoteFile) of Card))))
					   (COND
					     ((NC.AttachPromptWindow InterestedWindow NIL NIL NIL T)
					       (SPAWN.MOUSE)
					       (DISMISS 2000)
					       (NC.ClearMsg InterestedWindow T)))))
				       (RETURN NewParents)))))
)
(PUTPROPS RHTPATCH222 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1098 2248 (NC.CoerceToInterestedWindow 1108 . 2246)) (2284 17361 (NC.SelectNoteCards 
2294 . 17359)) (17393 35508 (NC.QuitCard 17403 . 23132) (NC.AssignTitle 23134 . 27116) (NC.CheckFiling
 27118 . 29159) (NC.CardSaveFn 29161 . 35506)) (35540 38685 (NC.MakeFilingLinks 35550 . 38683)))))
STOP