(FILECREATED "12-Dec-86 15:44:50" {QV}<NOTECARDS>1.3K>NEXT>PMIPATCH012.;1 82651  

      changes to:  (VARS PMIPATCH012COMS)
		   (FNS NC.SelectNoteCards))


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

(PRETTYCOMPRINT PMIPATCH012COMS)

(RPAQQ PMIPATCH012COMS ((* * Fixes bug %#45: Remove obsolete argument ReturnLinksFlg in 
			     NC.SelectNoteCards.)
			  (* * Changes to NCINTERFACE)
			  (FNS NC.SelectNoteCards NC.CloseNoteCards NC.CopyStructure 
			       NC.CloseStructure NC.DeleteStructure)
			  (* * Change to NCPROGINT)
			  (FNS NCP.SelectCards)
			  (* * Changes to NCCARDS)
			  (FNS NC.AddParents NC.DeleteNoteCards NC.DetermineSources NC.UnfileNoteCard)
			  (* * Changes to NCLINKS)
			  (FNS NC.MakeLink NC.MakeFilingLinks NC.AddGlobalLinksToCard 
			       NC.AddLinksToCard)
			  (* * Change to NCDATABASE)
			  (FNS NC.CopyCards)
			  (* * Change to NCFILEBOXCARD)
			  (FNS NC.FileBoxCollectChildren)
			  (* * Changes to NCBROWSERCARD)
			  (FNS NC.MakeBrowserCard NC.UpdateBrowserCard NC.BrowserAddNode)
			  (* * Change to NCDOCUMENTCARD)
			  (FNS NC.MakeDocument)))
(* * Fixes bug %#45: Remove obsolete argument ReturnLinksFlg in NC.SelectNoteCards.)

(* * Changes to NCINTERFACE)

(DEFINEQ

(NC.SelectNoteCards
  (LAMBDA (SingleCardFlg SelectionPredicate Menu InstigatingCardOrWindow Msg CheckForCancelFlg)
                                                             (* pmi: "12-Dec-86 14:09")

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



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


    (RESETLST (LET (Window Card ButtonEventFn InstigatingWindow InstigatingCard InstigatingNoteFile 
			     MenuWindow PromptWindow CopyInsertEvent SelectedCards 
			     PromptWindowProcess OldTTYProcess)
		     (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 shift-selected:  ")
		     (SETQ OldTTYProcess (TTY.PROCESS))

          (* * 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
								  (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)))
		     (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))
						((OR (NOT (NC.ValidCardP (CAR 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)
								 ",  ")
						  (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))))))

(NC.CloseNoteCards
  (LAMBDA (CardIdOrCardList NoCheckFlg DontClearFlg InterestedWindow)
                                                             (* pmi: "12-Dec-86 14:06")

          (* * Close note acrds on the screen)



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



          (* * kirk 21Feb86 Added InterestedWindow)



          (* * fgh 6/27/86 Fixed call to NC.SelectNoteCards to use just InterestedWindow)



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


    (LET (Cards Window)
         (SETQ Cards (COND
	     ((LISTP CardIdOrCardList))
	     (CardIdOrCardList (NC.CoerceToCard CardIdOrCardList))
	     (T (NC.SelectNoteCards NIL NIL NC.DeleteSelectingMenu InterestedWindow 
				      "Please shift-select the cards to be closed."))))
         (SPAWN.MOUSE)
         (for Card in (MKLIST Cards) do (COND
						  ((AND (NC.ActiveCardP Card)
							  (SETQ Window (NC.FetchWindow Card)))
						    (COND
						      ((NEQ (NC.QuitCard Card T)
							      (QUOTE DON'T))
							(while (OPENWP Window) do (BLOCK))))))
		))))

(NC.CopyStructure
  (LAMBDA (RootCard DestinationFileBox TraversalSpecs InterestedWindow QuietFlg)
                                                             (* pmi: "12-Dec-86 14:10")

          (* * Copy a NoteCard structure into a filebox)



          (* * kirk 13/7/86: Placed TraversalSpecs after RootCard selection and changed prompt message)



          (* * rht 9/2/86: Threw away CheckFlg arg. Wasn't being used. Changed to call NCP.CollectCards instead of outdated 
	  NC.CollectCards. Changed arg named ToPosition to DestinationFileBox. Also changed FromCard to RootCard.
	  Passes two link types to NC.AskTraversalSpecs.)



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


    (OR RootCard (SETQ RootCard (NC.SelectNoteCards T NIL NC.SelectingCardMenu NIL 
						    "Shift-select the root card of the structure"))
	  (ERROR!))
    (OR TraversalSpecs (SETQ TraversalSpecs (NC.AskTraversalSpecs RootCard (QUOTE
									  (SubBox FiledCard))))
	  (ERROR!))
    (OR DestinationFileBox (SETQ DestinationFileBox (NC.SelectNoteCards T
									      (FUNCTION (LAMBDA (
										    Card)
										  (NC.FileBoxP
										    Card T)))
									      NC.SelectingCardMenu 
									      NIL 
					     "Shift-select the FileBox to contain the structure."))
	  (ERROR!))
    (NC.CopyCards (NCP.CollectCards RootCard (fetch (TRAVERSALSPECS LinkTypes) of 
										   TraversalSpecs)
					(fetch (TRAVERSALSPECS Depth) of TraversalSpecs))
		    DestinationFileBox RootCard QuietFlg InterestedWindow)))

(NC.CloseStructure
  (LAMBDA (RootCard TraversalSpecs InterestedWindow QuietFlg)
                                                             (* pmi: "12-Dec-86 14:11")

          (* * rht 9/2/86: Replaced call to outdated NC.CollectCards with NCP.CollectCards. Threw away useless NoCheckFlg and
	  Don'tClearFlg args.)



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


    (OR RootCard (SETQ RootCard (NC.SelectNoteCards T NIL NC.SelectingCardMenu NIL 
						    "Shift-select the root card of the structure"))
	  (ERROR!))
    (OR QuietFlg (NC.PrintMsg InterestedWindow T "Collecting cards to close ..."))
    (OR TraversalSpecs (SETQ TraversalSpecs (NC.AskTraversalSpecs RootCard (QUOTE
									  (SubBox FiledCard)))))
    (NC.CloseNoteCards (NCP.CollectCards RootCard (fetch (TRAVERSALSPECS LinkTypes)
							 of TraversalSpecs)
					     (fetch (TRAVERSALSPECS Depth) of TraversalSpecs))
			 NIL NIL InterestedWindow)
    (OR QuietFlg (NC.ClearMsg InterestedWindow T))
    RootCard))

(NC.DeleteStructure
  (LAMBDA (RootCard TraversalSpecs InterestedWindow QuietFlg Don'tPutToBeDeletedCardsFlg)
                                                             (* pmi: "12-Dec-86 14:11")

          (* * rht 8/29/86: Reorganized and changed to call NCP.CollectCards which is more efficient than the old 
	  NCP.ComputeTransitiveClosure. Also now takes QuietFlg and Don'tPutToBeDeletedCardsFlg args.
	  Threw away Don'tClearFlg.)



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


    (OR RootCard (SETQ RootCard (NC.SelectNoteCards T NIL NC.SelectingCardMenu NIL 
						    "Shift-select the root card of the structure"))
	  (ERROR!))
    (OR TraversalSpecs (SETQ TraversalSpecs (NC.AskTraversalSpecs RootCard (QUOTE
									  (SubBox FiledCard)))))
    (OR QuietFlg (NC.PrintMsg InterestedWindow T "Collecting cards to delete ..."))
    (AND RootCard TraversalSpecs (NC.DeleteNoteCards (NCP.CollectCards RootCard
									     (fetch (TRAVERSALSPECS
											LinkTypes)
										of TraversalSpecs)
									     (fetch (TRAVERSALSPECS
											Depth)
										of TraversalSpecs))
							 T NIL InterestedWindow QuietFlg NIL 
							 Don'tPutToBeDeletedCardsFlg))
    RootCard))
)
(* * Change to NCPROGINT)

(DEFINEQ

(NCP.SelectCards
  (LAMBDA (InstigatingCardOrWindow SingleCardFlg SelectionPredicate Msg CheckForCancelFlg)
                                                             (* pmi: "12-Dec-86 14:20")

          (* * Return a list of cards selected. A menu pops up near the prompt window with "DONE" and "CANCEL" buttons.
	  User selects by clicking in card's title bar.)



          (* * rht 11/18/85: Updated to handle new notefile and card object formats. Now takes optional extra args and passes
	  to NC.SelectNoteCards.)



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


    (NC.SelectNoteCards SingleCardFlg SelectionPredicate (if SingleCardFlg
							       then NC.SelectingCardMenu
							     else NC.SelectingCardsMenu)
			  InstigatingCardOrWindow Msg CheckForCancelFlg)))
)
(* * Changes to NCCARDS)

(DEFINEQ

(NC.AddParents
  (LAMBDA (WindowOrTextStream)                               (* pmi: "12-Dec-86 12:58")

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



          (* * rht 7/5/86: Now checks for readonly cards.)



          (* * rht&pmi 11/24/86: Surrounded call to NC.MakeChildLink with NC.ActivateCardAndDo so that ParentCard will be 
	  active for duration of the call.)



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


    (LET (Card NewParents (Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))
	       OperationInProgress)
         (SETQ Card (NC.CoerceToCard Window))
         (if (NC.CheckForNotReadOnly Card Window "Can't do filing in ")
	     then (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 
					       " Please shift-select the new parent FileBox(es)."))
							(AND NewParents Card
							       (for ParentCard in NewParents
								  bind OneHook
								  when (NC.ActivateCardAndDo
									   ParentCard
									   (NC.MakeChildLink Card 
										       ParentCard 
											   Window))
								  do (SETQ OneHook T)
								  finally (RETURN OneHook)))))))))

(NC.DeleteNoteCards
  (LAMBDA (CardIdentifiers NoIndividualConfirmFlg DontClearFlg InterestedWindow QuietFlg 
			   NoGroupConfirmFlg Don'tPutToBeDeletedCardsFlg)
                                                             (* pmi: "12-Dec-86 12:59")
                                                             (* 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)



          (* * rht 7/4/86: Now checks that card is not read-only.)



          (* * kirk 18Aug86 Added main window for windowless cards.)



          (* * rht 8/29/86: Reorganized and added call to NC.SeverAllLinks to make deleting more efficient.
	  Added QuietFlg, NoGroupConfirmFlg and Don'tPutToBeDeletedCardsFlg args.)



          (* * rht 9/5/86: Now forces NoGroupConfirmFlg to be non-nil if NoIndividualConfirmFlg is NIL and only one card to 
	  delete.)



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


    (OR CardIdentifiers (SETQ CardIdentifiers (NC.SelectNoteCards NIL NIL 
									NC.DeleteSelectingMenu 
									InterestedWindow 
					      "Please shift-select the Note Cards to be deleted.")))

          (* * Kludge in case args are nil, say, when we're called from a card's menu.)


    (if (AND (NULL NoIndividualConfirmFlg)
		 (NULL NoGroupConfirmFlg)
		 (EQ (LENGTH (MKLIST CardIdentifiers))
		       1))
	then (SETQ NoGroupConfirmFlg T)
	       (SETQ QuietFlg T))

          (* * First collect cards that are deletable.)


    (LET ((CardsToDelete (for CardIdentifier in (MKLIST CardIdentifiers) bind Card
			    eachtime (BLOCK)
			    when (AND (SETQ Card (NC.CoerceToCard CardIdentifier))
					  (if (NOT (NC.TopLevelCardP Card))
					    else (NC.PrintMsg (NC.FetchWindow Card)
								  T "You cannot delete this FileBox."
								  (CHARACTER 13))
						   (DISMISS 1000)
						   (NC.ClearMsg (NC.FetchWindow Card)
								  T)
						   NIL)
					  (NC.CheckForNotReadOnly Card (NC.FetchWindow Card)
								    "Can't delete cards from a ")
					  (OR NoIndividualConfirmFlg
						(PROG1 (NC.AskYesOrNo 
							  "Are you sure you want to delete this?"
									  " -- " "Yes" (NULL 
										     DontClearFlg)
									  (OR (NC.FetchWindow
										  Card)
										InterestedWindow)
									  NIL NIL)
							 (NC.ClearMsg))))
			    collect Card))
	  (NumSpecified (LENGTH (MKLIST CardIdentifiers)))
	  NumToDelete)
         (SETQ NumToDelete (LENGTH CardsToDelete))
         (if (AND (GREATERP NumToDelete 0)
		      (if (EQUAL NumToDelete NumSpecified)
			  then (OR NoGroupConfirmFlg (PROG1 (NC.AskYesOrNo
								    (CONCAT "You've specified " 
									      NumToDelete 
									      " cards to delete."
									      (CHARACTER 13)
									      
							 "Are you sure you want to delete them? ")
								    NIL "Yes" (NULL DontClearFlg)
								    InterestedWindow)
								  (NC.ClearMsg)))
			else (PROG1 (NC.AskYesOrNo (CONCAT "Out of " NumSpecified 
								   " cards specified, "
								   (DIFFERENCE NumSpecified 
										 NumToDelete)
								   " are not deletable."
								   (CHARACTER 13)
								   "Want to delete the remaining " 
								   NumToDelete " cards? ")
							 NIL "Yes" (NULL DontClearFlg)
							 InterestedWindow)
					(NC.ClearMsg))))
	     then 

          (* * Mark UIDs of cards about to be deleted.)


		    (for Card in CardsToDelete do (NC.UIDPutProp (fetch (Card UID)
									    of Card)
									 (QUOTE AboutToBeDeletedFlg)
									 T))

          (* * Sever all links into and out of CardsToDelete)


		    (NC.SeverAllLinks CardsToDelete QuietFlg InterestedWindow 
					Don'tPutToBeDeletedCardsFlg)

          (* * Now delete the cards one at a time.)


		    (OR QuietFlg (NC.PrintMsg InterestedWindow T "Deleting cards: 1 out of " 
						  NumToDelete " ..."))
		    (for Card in CardsToDelete as i from 1 eachtime (BLOCK)
		       do (LET ((OperationInProgress (NC.OperationInProgress Card)))
			         (OR QuietFlg (if (ZEROP (REMAINDER i 10))
						    then (NC.PrintMsg InterestedWindow T 
									  "Deleting cards: "
									  i " out of " NumToDelete 
									  " ...")))
			         (if OperationInProgress
				     then (NC.PrintOperationInProgressMsg (NC.FetchWindow
										Card)
									      "Delete Card(s)" 
									      OperationInProgress)
				   else (NC.ProtectedCardOperation Card Delete% Card%(s%)
								     (NC.DeleteNoteCard Card)))))
		    (OR QuietFlg (NC.ClearMsg InterestedWindow T))
		    CardIdentifiers))))

(NC.DetermineSources
  (LAMBDA (Card NoSourceOptionFlg)                           (* pmi: "12-Dec-86 12:59")
                                                             (* Returns a list of source cards according to the 
							     following rule: Ask the user.)

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



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


    (LET (Selections (Window (NC.FetchWindow Card)))
         (NC.PrintMsg Window NIL "Shift-select source(s) for this card." (CHARACTER 13)
			"NoSource" " to indicate no source." (CHARACTER 13))
         (SETQ Selections (NC.SelectNoteCards NIL NIL NC.SelectingSourcesMenu Card
						  (CONCAT "Shift-select source(s) for this card."
							    (CHARACTER 13)
							    " NoSource to indicate no source.")))
         (NC.ClearMsg Window)
     Selections)))

(NC.UnfileNoteCard
  (LAMBDA (WindowOrTextStream)                               (* pmi: "12-Dec-86 13:01")
                                                             (* 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.)



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


    (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 
			  "Please shift-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)))))))
)
(* * Changes to NCLINKS)

(DEFINEQ

(NC.MakeLink
  (LAMBDA (Window LinkLabel DestinationCard SourceCard DisplayMode AnchorMode Message NoDisplayFlg 
		  LinkToInsertAfter CrossFileLinksMode)      (* pmi: "12-Dec-86 14:14")

          (* * Make a link from (OR Window SourceCard) to DestinationCard with linklabel of LinkLabel)



          (* * rht 1/12/85: If need to create a new card, then now shows card type menu near window of SourceID.)



          (* * rht 1/13/85: Added extra args Message and NoDisplayFlg.)



          (* * rht 3/26/85: Added LinkToInsertAfter arg which should be NIL or a link to insert the new To link after.
	  If NIL, then insert at front of ToLinks.)



          (* * kirk 9/23/85: took out GETPROMPTWINDOW call for asknotecardtype)



          (* * kirk: 14Nov85: changed NC.CoerceToID to to NC.CoerceToCard)



          (* * fgh 11/16/85 Changed from PROG to LET and used COND to contyrol returnmed value.)



          (* * fgh 2/5/86 Changed call DefaultLinkDisplayMode to FetchLinkDisplayMode)



          (* * fgh 6/5/86 Now calls AskLinkLabel if LinkLabel arg is NIL)



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



          (* * kef 7/17/86: Added calls to grab the write permission on the appropriate card parts.)



          (* * kef 7/22/86: Saves the links on the Destination Card now right away, while still holding onto the FROMLINKS 
	  write lock.)



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



          (* * rht 9/29/86: Tossed Ken's call to NC.PutFromLinks; It was the cause of too many nasty breaks.
	  Also made syntactic fixes.)



          (* * rht 10/4/86: Now handles cross file links. New arg CrossFileLinksMode determines whether cross-file link will 
	  be two-way, i.e. will destination card know it's being linked to.)



          (* * rht 11/10/86: Now creates new crossfile link if Destination card is a CrossFileLink card that we didn't just 
	  create.)



          (* * rht 11/14/86: Now checks if non-nil DestinationCard before trying to do cross-filelink stuff.)



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



          (* * rht 12/9/86: Throws out JustCreatedFlg marker stuff.)



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


    (DECLARE (GLOBALVARS NC.SelectingSingleCardMenu NC.NewCrossFileLinksTwoWayFlg))
    (OR SourceCard (SETQ SourceCard (NC.CoerceToCard Window)))
    (AND (NC.CheckForNotReadOnly SourceCard Window "Can't make links in ")
	   (LET (Link Type)
	        (OR Window (SETQ Window (NC.FetchWindow SourceCard)))
	        (OR Message (SETQ Message "Please shift-select the Card or Box to be linked to."))
	        (OR LinkLabel (SETQ LinkLabel (NC.AskLinkLabel Window NIL NIL T NIL)))
	        (OR DestinationCard (SETQ DestinationCard
			(NC.SelectNoteCards T (FUNCTION (LAMBDA (Card)
						  (COND
						    ((NOT (NC.SameCardP Card SourceCard))
						      T)
						    (T (NC.PrintMsg Window T 
							     "A Card/Box cannot link to itself. "
								      (CHARACTER 13)
								      "Selection ignored."
								      (CHARACTER 13))
						       NIL))))
					      NC.SelectingSingleCardMenu SourceCard Message)))
	        (if (EQ DestinationCard (QUOTE *New% Card*))
		    then (SETQ DestinationCard (AND (SETQ Type (NC.AskNoteCardType
							      (WINDOWREGION Window)))
							  (NC.CoerceToCard
							    (NC.MakeNoteCard Type
									       (fetch (Card 
											 NoteFile)
										  of SourceCard)
									       NIL NoDisplayFlg)))))

          (* * If we're trying to link to a CrossFileLink card, then check whether card was just created.
	  If so, then it's the first link, otherwise we make a new CrossFileLink.)


	        (if (AND DestinationCard (NC.CrossFileLinkCardP DestinationCard))
		    then (SETQ DestinationCard (NC.GetCrossFileLinkDestCard DestinationCard))
			   (NC.SetUserDataProp DestinationCard (QUOTE JustCreatedFlg)
						 NIL))
	        (if DestinationCard
		    then (NC.IfCardPartNotBusy
			     DestinationCard
			     (QUOTE FROMLINKS)
			     (NC.IfCardPartNotBusy SourceCard (QUOTE TOLINKS)

          (* * If have cross-file link, then make two new crossfilelink cards, one per notefile. Make global link over there 
	  from crossfilelink card to DestinationCard and local link here from SourceCard to crossfilelink card.)


						   (if (NOT (NC.SameNoteFileP
								  (fetch (Card NoteFile)
								     of SourceCard)
								  (fetch (Card NoteFile)
								     of DestinationCard)))
						       then
							(LET ((CrossFileLinksTwoWayFlg
								(OR (EQ CrossFileLinksMode
									    (QUOTE TWOWAY))
								      (AND (NULL 
									       CrossFileLinksMode)
									     
								    NC.NewCrossFileLinksTwoWayFlg))))
							     (if CrossFileLinksTwoWayFlg
								 then (NC.MakeGlobalLink
									  Window LinkLabel 
									  DestinationCard
									  (
								       NC.CreateCrossFileLinkCard
									    DestinationCard 
									    SourceCard T)
									  DisplayMode))
							     (SETQ DestinationCard
							       (NC.CreateCrossFileLinkCard 
										       SourceCard 
										  DestinationCard 
									  CrossFileLinksTwoWayFlg))))
						   (SETQ Link (create Link
									  UID ←(NC.MakeUID)
									  SourceCard ← SourceCard
									  DestinationCard ← 
									  DestinationCard
									  AnchorMode ← AnchorMode
									  Label ← LinkLabel
									  DisplayMode ←(OR
									    DisplayMode
									    (NC.FetchLinkDisplayMode
									      SourceCard))))
						   (NC.AddToLink Link LinkToInsertAfter)
						   (NC.AddFromLink Link)
						   Link))
		  else NIL)))))

(NC.MakeFilingLinks
  (LAMBDA (Card Msg)                                         (* pmi: "12-Dec-86 14:15")
                                                             (* 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.)


    (PROG (OneHook (Window (NC.FetchWindow Card))
		     NewParents)
	    (SETQ NewParents (NC.SelectNoteCards NIL (FUNCTION NC.FileBoxP)
						     NC.SelectingContentsMenu Card
						     (CONCAT (OR Msg "")
							       
					    "Please shift-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.AddGlobalLinksToCard
  (LAMBDA (CardIdentifier SingleLinkFlg)                     (* pmi: "12-Dec-86 14:16")

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



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


    (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 
				       "Please shift-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.AddLinksToCard
  (LAMBDA (CardIdentifier LinkLabel DestinationCards)        (* pmi: "12-Dec-86 14:17")

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



          (* * rht 9/23/86: Fixed bug in function passed to NC.SelectNoteCards.)



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


    (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 (SelectedCard)
								(COND
								  ((NOT (NC.SameCardP 
										     SelectedCard 
										       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 
				       "Please shift-select the Cards or Boxes to be pointed to.")))
						  (NC.ClearMsg Window T)
						  (for DestinationCard in DestinationCards
						     do (NC.AddLinkToCard CardIdentifier 
									      LinkLabel 
									      DestinationCard))))))))
)
(* * Change to NCDATABASE)

(DEFINEQ

(NC.CopyCards
  (LAMBDA (Cards DestNoteFileOrFileBox RootCards QuietFlg InterestedWindow)
                                                             (* pmi: "12-Dec-86 13:59")

          (* * Create copies of cards in Cards. If DestNoteFileOrFileBox is a notefile, then destination will be the contents
	  box in that notefile, else the FileBox's notefile. RootCards should be NIL or a subset of Cards.
	  If NIL, then file all Cards in the dest filebox. Otherwise, just file RootCards in that filebox and assume others 
	  are linked somehow to the RootCards. Links between cards in Cards are copied, but links from or to outside cards 
	  aren't.)



          (* * Currently all Cards must be in same notefile, but this perhaps could be relaxed if could prevent possibility 
	  of two cards in different notefiles having the same UID.)



          (* * kirk 24Apr86 Added calls to select cards if none provided)



          (* * rht 9/2/86: Added InterestedWindow arg.)



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


    (LET (NumCards SourceNoteFile DestNoteFile BoxToFileIn TempStream CardHashArray LinksHashArray 
		   CurrentLinkLabels NewLinkLabels NewCardsAndLocsOnStream)

          (* * Make sure the arguments are valid.)


         (if (NULL Cards)
	     then (if (NULL (SETQ Cards (NC.SelectNoteCards NIL NIL NC.SelectingCardsMenu 
								      NIL 
					     "Shift-select from the same NoteFile cards to copy:")))
			then (ERROR!)))
         (SETQ Cards (MKLIST Cards))
         (SETQ NumCards (LENGTH Cards))                  (* All Cards to copy must live in same notefile.)
         (SETQ SourceNoteFile (fetch (Card NoteFile) of (CAR Cards)))
         (if (NOT (AND (type? NoteFile SourceNoteFile)
			     (OPENP (fetch (NoteFile Stream) of SourceNoteFile))))
	     then (NC.ReportError "NC.CopyCards" (CONCAT (fetch (NoteFile FullFileName)
								  of SourceNoteFile)
							       " not an open notefile.")))
         (if (NOT (for Card in Cards always (NC.SameNoteFileP (fetch (Card NoteFile)
									     of Card)
									  SourceNoteFile)))
	     then (NC.ReportError "NC.CopyCards" 
				      "All cards in Cards arg don't live in the same notefile."))
                                                             (* Compute dest notefile and dest filebox.)
         (if (NOT DestNoteFileOrFileBox)
	     then (if (EQ (QUOTE CANCELLED)
				(SETQ DestNoteFileOrFileBox (NC.SelectNoteCards T NIL 
									     NC.SelectingCardMenu NIL 
					       "Shift-select the FileBox to contain these cards."
										    T)))
			then (ERROR!)))
         (if (type? NoteFile DestNoteFileOrFileBox)
	     then (SETQ DestNoteFile DestNoteFileOrFileBox)
		    (SETQ BoxToFileIn (fetch (NoteFile TableOfContentsCard) of DestNoteFile))
	   elseif (NCP.FileBoxP DestNoteFileOrFileBox)
	     then (SETQ BoxToFileIn DestNoteFileOrFileBox)
		    (SETQ DestNoteFile (fetch (Card NoteFile) of BoxToFileIn))
	   else (NC.ReportError "NC.CopyCards" (CONCAT "Arg not notefile or filebox: " 
							     DestNoteFileOrFileBox)))
         (if (NOT (AND (type? NoteFile DestNoteFile)
			     (OPENP (fetch (NoteFile Stream) of DestNoteFile))))
	     then (NC.ReportError "NC.CopyCards" (CONCAT (fetch (NoteFile FullFileName)
								  of DestNoteFile)
							       " not an open notefile.")))
         (if (LDIFFERENCE (SETQ RootCards (MKLIST RootCards))
			      Cards)
	     then (NC.ReportError "NC.CopyCards" 
				      "RootCards argument not subset of Cards argument."))
         (if (NULL RootCards)
	     then (SETQ RootCards Cards))

          (* * Now get to work.)


         (SETQ TempStream (OPENSTREAM (QUOTE {NODIRCORE})
					  (QUOTE BOTH)))
         (SETQ CurrentLinkLabels (NC.RetrieveLinkLabels DestNoteFile))
         (SETQ NewLinkLabels (TCONC NIL))
         (SETQ LinksHashArray (HASHARRAY NC.CopyCardsLinksHashArraySize NIL
					     (FUNCTION NC.MakeHashKey)
					     (FUNCTION NC.SameUIDP)))
         (SETQ CardHashArray (HASHARRAY NumCards NIL (FUNCTION NC.MakeHashKeyFromCard)
					    (FUNCTION NC.SameCardP)))

          (* * Create new cards in DestNoteFile for each card. Make these cards by copying original cards to a temp stream.
	  Keep track of UID mappings between original cards and card copies using CardHashArray.)


         (OR QuietFlg (NC.PrintMsg InterestedWindow T "Copying cards: creating empty copies."
				       (CHARACTER 13)
				       "Processing item " 1 " out of " NumCards "..." (CHARACTER
					 13)))
         (SETQ NewCardsAndLocsOnStream
	   (for Card in Cards as i from 1 bind NewCard WasActiveFlg HadStatusNILFlg 
							 IndexLocs
	      eachtime (BLOCK)
	      collect (OR QuietFlg (if (ZEROP (REMAINDER i 100))
					   then (NC.PrintMsg InterestedWindow T 
							  "Copying cards: creating empty copies."
								 (CHARACTER 13)
								 "Processing item " i " out of " 
								 NumCards "..." (CHARACTER 13))))
			(if (NOT (SETQ WasActiveFlg (NC.ActiveCardP Card)))
			    then (NC.GetNoteCard Card))
			(if (SETQ HadStatusNILFlg (NULL (fetch (Card Status) of Card)))
			    then                           (* Have to have Status slot ACTIVE in order that Put 
							     to stream won't break.)
				   (replace (Card Status) of Card with (QUOTE ACTIVE)))
			(SETQ IndexLocs (NC.PutNoteCardToStream Card NIL T TempStream))
			(if HadStatusNILFlg
			    then (replace (Card Status) of Card with NIL))
			(if (NOT WasActiveFlg)
			    then (NC.DeactivateCard Card))
                                                             (* Make new empty card for copy.)
			(SETQ NewCard (NC.GetNewCard DestNoteFile)) 
                                                             (* Map old cards to card copies.)
			(PUTHASH Card NewCard CardHashArray)
			(CONS NewCard IndexLocs)))

          (* * For each card, get it off the temp stream, fix its links, fix browser info if necessary, and write it down to 
	  the dest notefile.)


         (SETFILEPTR TempStream 0)
         (OR QuietFlg (NC.PrintMsg InterestedWindow T 
				       "Copying cards: fixing links and browser cards."
				       (CHARACTER 13)
				       "Processing item " 1 " out of " NumCards "..." (CHARACTER
					 13)))
         (for NewCardAndLocsOnStream in NewCardsAndLocsOnStream as i from 1 eachtime
										     (BLOCK)
	    do (OR QuietFlg (if (ZEROP (REMAINDER i 100))
				    then (NC.PrintMsg InterestedWindow T 
						 "Copying cards: fixing links and browser cards."
							  (CHARACTER 13)
							  "Processing item " i " out of " NumCards 
							  "..."
							  (CHARACTER 13))))
		 (LET ((NewCard (CAR NewCardAndLocsOnStream))
		       (IndexLocs (CDR NewCardAndLocsOnStream)))
                                                             (* Have to make status active for Get fns to work.)
		      (NC.SetStatus NewCard (QUOTE ACTIVE))
		      (NC.GetNoteCardFromStream NewCard TempStream IndexLocs)
		      (NC.FixUpLinksInCardCopy NewCard CardHashArray LinksHashArray 
						 CurrentLinkLabels NewLinkLabels)
		      (if (NC.IsSubTypeOfP (NC.FetchType NewCard)
					       (QUOTE Browser))
			  then (NC.FixUpBrowserCardCopy NewCard CardHashArray))
		      (NC.PutNoteCard NewCard)))

          (* * Link RootCards under filebox in DestNotefile.)


         (OR QuietFlg (NC.PrintMsg InterestedWindow T "Copying cards: filing " (LENGTH 
											RootCards)
				       " new cards in "
				       (NC.FetchTitle BoxToFileIn)
				       "..."
				       (CHARACTER 13)))
         (NC.FileBoxCollectChildren NIL BoxToFileIn (for RootCard in RootCards eachtime
										      (BLOCK)
							 collect (GETHASH RootCard CardHashArray))
				      T)

          (* * Put out any new link labels to the dest notefile.)


         (AND (SETQ NewLinkLabels (CDAR NewLinkLabels))
		(NC.StoreLinkLabels DestNoteFile (APPEND NewLinkLabels CurrentLinkLabels)))
         (OR QuietFlg (NC.ClearMsg InterestedWindow T))
     Cards)))
)
(* * Change to NCFILEBOXCARD)

(DEFINEQ

(NC.FileBoxCollectChildren
  (LAMBDA (WindowOrTextStream Card NewChildren NoDisplayFlg)
                                                             (* pmi: "12-Dec-86 14:05")

          (* * Ask user for new children (either cards or fileboxes) for this filebox. Check to make sure that no 
	  circularities are introduced. This code is sort of the inverse of the NC.AddParents code and thus looks quite 
	  similar.)



          (* * rht 10/29/84: Added NoDisplayFlg to prevent error message when no appropriate elements exist.
	  Also now returns ID if at least one child was added, NIL otherwise.)



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



          (* * rht 7/5/86: Now checks for readonly cards.)



          (* * rht 8/11/86: Added code to check to make sure that another operation is not in progress on this card when this
	  fn is called.)



          (* * rht 10/17/86: Made successful filing operations NOT do dismiss.)



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


    (OR Card (SETQ Card (NC.CoerceToCard WindowOrTextStream)))
    (LET ((Window (NC.FetchWindow Card))
	  OperationInProgress)
         (if (NC.CheckForNotReadOnly Card Window "Can't do filing in ")
	     then (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 "Put Cards Here" 
								 OperationInProgress)
		      else (NC.ProtectedCardOperation Card Put% Cards% Here
							(OR NewChildren
							      (SETQ NewChildren
								(NC.SelectNoteCards NIL NIL 
								  NC.SelectingFileBoxChildrenMenu 
										      Card 
							     " Please shift-select new children.")))
							(COND
							  ((AND NewChildren Card
								  (for NewChild in NewChildren
								     bind OneHook
								     when (NC.MakeChildLink
									      NewChild Card Window)
								     do (SETQ OneHook T)
								     finally (RETURN OneHook)))
							    Card)
							  ((NULL NoDisplayFlg)
							    (NC.PrintMsg Window NIL 
						  "No appropriate NoteCards or FileBoxes chosen."
									   (CHARACTER 13)
									   "Hence no children added."
									   (CHARACTER 13))
							    (DISMISS 1000)
							    (NC.ClearMsg Window T)
							    NIL)
							  (T NIL))))))))
)
(* * Changes to NCBROWSERCARD)

(DEFINEQ

(NC.MakeBrowserCard
  (LAMBDA (Card Title NoDisplayFlg ParamList)                (* pmi: "12-Dec-86 12:54")

          (* Make a browser card with id Card using root at RootID and the link following predictae specified by Predicate.
	  IF Root and/or ListOfLinkLabels not specified, ask the user.)



          (* * rht 8/3/84: Changed to call NC.AskLinkLabel with its ReverseLinkLabel parameter set to T.)



          (* * fgh 10/2/84 Changed Link Icons to be image objects in NodeLabel of Graph Npodes rather than annotations on 
	  graph nodes.)



          (* * rht 10/19/84: Fixed setting up of browser card's prop list in case NoDisplayFlg is T so we have no Window.
	  Now NC.MakeLinksLegend returns the label pairs.)



          (* * rht 11/27/84: Removed the WINDOWADDPROP call to put NC.GraphCardCloseFn on the CLOSEFN of the window.
	  This causes trouble. NC.QuitCard will get put on by NC.MakeNoteCard and that's enough.)



          (* * rht 1/3/85: Now puts a dummy region of the right size if the NoDisplayFlg is on.)



          (* * rht 1/15/85: Put hooks for AddNode, AddLink, etc. so editing graph edits underlying structure.)



          (* * rht 2/14/85: Added VerticalFlg and made BrowserSpecs get put on browser's proplist in all cases.)



          (* * rht 4/1/85: Now calls NC.AskBrowserSpecs with additional Don'tAskFlg in case of call from Programmer's 
	  interface.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 2/7/86: Now gets browser format, etc. via fetch/set fns.)



          (* * rht 5/6/86: Took out call to NC.SetupTitleBarMenu.)



          (* * rht 5/8/86: Added calls to rig title bar properly.)



          (* * rht 7/10/86: Now passes ListOfLinkLabels to NC.AskBrowserSpecs.)



          (* * rht 9/19/86: Mod to above fix. Now calls NC.MakeNewCardWindow a new fn that creates window and hangs Card off 
	  windowprop.)



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



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


    (DECLARE (GLOBALVARS NC.SubBoxLinkLabel NC.BrowserContentsLinkLabel NC.SpecialBrowserSpecsFlg 
			     NC.*Graph*BrowserFormat))
    (PROG ((RootCards (MKLIST (LISTGET ParamList (QUOTE ROOTCARDS))))
	     (ListOfLinkLabels (LISTGET ParamList (QUOTE LINKTYPES)))
	     (BrowserFormat (LISTGET ParamList (QUOTE FORMAT)))
	     (Depth (LISTGET ParamList (QUOTE DEPTH)))
	     (CardType (NC.RetrieveType Card))
	     Lattice RootNodes Window Graph SpecialBrowserSpecs BrowserSpecs DropVirtualNodesFlg)
	    (NC.ActivateCard Card)
	    (COND
	      ((NULL NoDisplayFlg)
		(SETQ Window (NC.MakeNewCardWindow Card (OR Title "Untitled")))
		(WINDOWADDPROP Window (QUOTE SHRINKFN)
				 (FUNCTION NC.GraphCardShrinkFn))))
	    (if (NULL RootCards)
		then (SETQ RootCards (if NoDisplayFlg
					     then (LIST NIL)
					   else (NC.SelectNoteCards NIL NIL 
								    NC.SelectingBrowserSourceMenu 
									Window 
		      "Please shift-select the Cards and/or Boxes the browser should start from."
									T))))
	    (COND
	      ((EQ RootCards (QUOTE CANCELLED))
		(NC.DeactivateCard Card)
		(CLOSEW Window)
		(RETURN)))
	    (NC.HoldTTYProcess)
	    (SETQ BrowserSpecs (NC.AskBrowserSpecs Window Card ListOfLinkLabels Depth BrowserFormat 
						     T (if (OR ParamList NoDisplayFlg)
							   then (QUOTE DONTASK))))
	    (COND
	      ((NULL BrowserSpecs)
		(NC.DeactivateCard Card)
		(CLOSEW Window)
		(RETURN)))
	    (SETQ ListOfLinkLabels (CAR BrowserSpecs))
	    (SETQ Depth (CADR BrowserSpecs))
	    (SETQ BrowserFormat (CADDR BrowserSpecs))    (* If user wants *GRAPH* format, i.e. virtual nodes 
							     eliminated, then set the flag)
	    (if (FMEMB NC.*Graph*BrowserFormat BrowserFormat)
		then (SETQ DropVirtualNodesFlg T))
	    (SETQ SpecialBrowserSpecs (COND
		(NC.SpecialBrowserSpecsFlg (NC.AskSpecialBrowserSpecs Window))
		(T (create SPECIALBROWSERSPECS))))
	    (OR NoDisplayFlg (NC.PrintMsg Window T (CHARACTER 13)
					      "Computing browser graph. Please wait. ..."))
                                                             (* Create new browser hash array)
	    (NC.GetBrowserHashArray Card)                    (* Compute lattice breakdth-first starting from 
							     roots.)
	    (SETQ Lattice (NC.GrowLinkLattice RootCards NIL ListOfLinkLabels Card Depth))
	    (SETQ RootNodes (for RootCard in RootCards collect (NC.GetBrowserNodeID Card 
											 RootCard)))
	    (OR NoDisplayFlg (WINDOWPROP Window (QUOTE NoteCardObject)
					     Card))

          (* * Link destination id information stored in NodeLabel field into a LinkIcon for display)


	    (for Node in Lattice bind NodeID eachtime (BLOCK)
	       do (replace (GRAPHNODE NODELABEL) of Node
		       with (NC.MakeLinkIcon (NC.MakeLink Window NC.BrowserContentsLinkLabel
								(fetch (GRAPHNODE NODELABEL)
								   of Node)
								Card NIL)))
                                                             (* Untouch each graph node so that next Recompute will
							     put fresh values on proplist.)
		    (SETQ NodeID (fetch (GRAPHNODE NODEID) of Node))
		    (NC.GraphNodeIDRemProp (NC.CoerceToGraphNodeID NodeID)
					   (QUOTE TouchedFlg))
		    (NC.GraphNodeIDRemProp (NC.CoerceToGraphNodeID NodeID)
					   (QUOTE VisitedFlg)))
	    (SETQ Graph (if (AND Lattice RootNodes)
			      then (LAYOUTGRAPH Lattice RootNodes (SUBST (QUOTE LATTICE)
									       
									  NC.*Graph*BrowserFormat 
									       BrowserFormat)
						    (fetch (SPECIALBROWSERSPECS Font) of 
									      SpecialBrowserSpecs)
						    (fetch (SPECIALBROWSERSPECS MotherD)
						       of SpecialBrowserSpecs)
						    (fetch (SPECIALBROWSERSPECS PersonalD)
						       of SpecialBrowserSpecs)
						    (fetch (SPECIALBROWSERSPECS FamilyD)
						       of SpecialBrowserSpecs))
			    else (create GRAPH)))
	    (NC.SetBrowserLinksLegend Card (NC.MakeLinksLegend Graph Window DropVirtualNodesFlg))
	    (OR NoDisplayFlg (NC.PrintMsg Window NIL "Done!"))
	    (NC.SetSubstance Card Graph)
	    (NC.SetBrowserLinkLabels Card (OR ListOfLinkLabels (LIST NC.SubBoxLinkLabel)))
	    (NC.SetBrowserRoots Card RootCards)
	    (NC.SetBrowserFormat Card BrowserFormat)
	    (NC.SetBrowserDepth Card Depth)
	    (NC.SetSpecialBrowserSpecs Card SpecialBrowserSpecs)
	    (COND
	      (NoDisplayFlg (RETURN Card)))
	    (WINDOWPROP Window (QUOTE GRAPH)
			  Graph)
	    (NC.InstallTitleBarLeftMenu Window CardType)
	    (NC.InstallTitleBarMiddleMenu Window CardType)
	    (NC.RelayoutBrowserCard Window)
	    (RETURN Window))))

(NC.UpdateBrowserCard
  (LAMBDA (Window DontCheckOpInProgressFlg)                  (* pmi: "12-Dec-86 12:55")

          (* * rht 10/14/84: Added call to DETACHALLWINDOWS to close any existing links legend window and prompt window.
	  Also added call to NC.MakeLinksLegend to make a new attached legend menu.)



          (* * rht 1/15/85: Put hooks for AddNode, AddLink, etc. so editing graph edits underlying structure.)



          (* * rht 2/14/85: Added ability to respecify roots and link labels before recomputing graph.)



          (* * rht 3/8/85: Modified to use new browser props stored on card's proplist as of release 1.2.)



          (* * rht 3/17/85: Now takes OnlyLayoutFlg argument. If set, then don't recompute lattice or ask about root nodes.)



          (* * rht 11/17/85: updated to handle new card and notefile objects.)



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



          (* * rht 2/7/86: Now gets and sets browser format, etc. via fetch/set fns.)



          (* * rht 3/7/86: Now only closes the Links legend menu attached window.)



          (* * rht 6/10/86: Moved code to delete links legend menu and code to make new browser hash array to after 
	  questioning user about respecifying roots.)



          (* * rht 11/1/86: Added NC.ProtectedCardOperation wrapper and check for ops in progress.)



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


    (LET ((Card (NC.CoerceToCard Window))
	  OperationInProgress)

          (* * 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 (QUOTE Recompute% Browser% Card)
						      OperationInProgress)
		    NIL
	   else (NC.ProtectedCardOperation
		    Card Recompute% Browser% Card
		    (PROG (LinkLabels RootCards RootNodes Lattice LinkIcon Graph GraphNodes 
					NodeLabel BrowserSpecs BrowserFormat DropVirtualNodesFlg 
					Depth SpecialBrowserSpecs OldLabelNodes OldRootCards)
			    (SETQ RootCards (NC.FetchBrowserRoots Card))
			    (SETQ LinkLabels (NC.FetchBrowserLinkLabels Card))
			    (SETQ BrowserFormat (OR (NC.FetchBrowserFormat Card)
							(QUOTE (LATTICE))))
                                                             (* If user wants *GRAPH* format, i.e. virtual nodes 
							     eliminated, then set the flag)
			    (if (FMEMB NC.*Graph*BrowserFormat BrowserFormat)
				then (SETQ DropVirtualNodesFlg T))
			    (SETQ Depth (OR (NC.FetchBrowserDepth Card)
						999999))
			    (SETQ SpecialBrowserSpecs (OR (NC.FetchSpecialBrowserSpecs Card)
							      (create SPECIALBROWSERSPECS)))
			    (SETQ GraphNodes (fetch (GRAPH GRAPHNODES)
						  of (SETQ Graph (WINDOWPROP Window
										   (QUOTE GRAPH)))))
                                                             (* Get new roots.)
			    (if (OR (NULL RootCards)
					(NC.AskYesOrNo "Want to respecify roots? " "--" "No" T 
							 Window T NIL))
				then (NC.BrowserFlipRoots Window Card GraphNodes (SETQ 
							      OldRootCards RootCards))
				       (SETQ RootCards (NC.SelectNoteCards NIL NIL 
								    NC.SelectingBrowserSourceMenu 
									       Window
									       (CONCAT
										 
		      "Please shift-select the Cards and/or Boxes the browser should start from."
										 (CHARACTER 13)
										 
							       "(Current roots are highlighted.)")
									       T))
				       (NC.BrowserFlipRoots Window Card GraphNodes OldRootCards)
				       (COND
					 ((EQ RootCards (QUOTE CANCELLED))
					   (RETURN))))     (* Get rid of the links legend menu attached window.)
			    (for Win in (ATTACHEDWINDOWS Window) when (WINDOWPROP
										Win
										(QUOTE 
										  LINKSLEGENDWINP))
			       do (DETACHWINDOW Win)
				    (CLOSEW Win))          (* Smash the current hash array, putting a fresh one 
							     in its place.)
			    (NC.GetBrowserHashArray Card)
			    (NC.PrintMsg Window T (CHARACTER 13)
					   "Computing browser graph. Please wait. ...")
                                                             (* Compute lattice breadth-first from the roots.)
			    (SETQ Lattice (NC.GrowLinkLattice RootCards NIL LinkLabels Card Depth))
			    (SETQ RootNodes (for RootCard in RootCards collect (
NC.GetBrowserNodeID Card RootCard)))
			    (NC.SetPropListDirtyFlg Card T)
                                                             (* Remove all links that are in the old browser graph 
							     but not in the new one)
			    (for Node in GraphNodes bind NodeID Link
			       eachtime (BLOCK)
					  (SETQ NodeID (fetch (GRAPHNODE NODEID) of Node))
			       unless (FASSOC (OR (CAR NodeID)
							NodeID)
						  Lattice)
			       do (if (NC.LinkIconImageObjP (SETQ LinkIcon
								    (fetch (GRAPHNODE NODELABEL)
								       of Node)))
					then (NC.DeleteLink (NC.FetchLinkFromLinkIcon LinkIcon)
								T T)
				      else                 (* Collect the label nodes from the old browser.)
					     (SETQ OldLabelNodes (CONS Node OldLabelNodes))))
                                                             (* Create Links for all nodes in the new browser graph
							     but not in the old one.)
			    (for Node in Lattice bind NodeID OldNode eachtime (BLOCK)
			       do (SETQ NodeID (fetch (GRAPHNODE NODEID) of Node))
				    (COND
				      ((SETQ OldNode (FASSOC NodeID GraphNodes))
					(replace (GRAPHNODE NODELABEL) of Node
					   with (fetch (GRAPHNODE NODELABEL) of OldNode)))
				      (T (replace (GRAPHNODE NODELABEL) of Node
					    with (NC.MakeLinkIcon (NC.MakeLink
									Window 
								      NC.BrowserContentsLinkLabel
									(fetch (GRAPHNODE NODELABEL)
									   of Node)
									Card)))))
                                                             (* Untouch each graph node so that next Recompute will
							     put fresh values on proplist.)
				    (NC.GraphNodeIDRemProp NodeID (QUOTE TouchedFlg))
				    (NC.GraphNodeIDRemProp NodeID (QUOTE VisitedFlg)))
                                                             (* Throw in the label nodes from the old browser.)
			    (SETQ Lattice (NCONC Lattice OldLabelNodes))
                                                             (* For each old label node, take away nonexistent 
							     fromnodes and save the label nodes that no longer have
							     any from nodes.)
			    (for OldLabelNode in OldLabelNodes eachtime (BLOCK)
			       do (replace (GRAPHNODE FROMNODES) of OldLabelNode
				       with (for FromNodeID in (fetch (GRAPHNODE FROMNODES)
									of OldLabelNode)
						 bind FromNode eachtime (BLOCK)
						 when (SETQ FromNode (FASSOC FromNodeID Lattice)
							  )
						 collect 
                                                             (* If the From node isn't a label node, then add to 
							     its Tonode list.)
							   (if (NC.LinkIconImageObjP
								   (fetch (GRAPHNODE NODELABEL)
								      of FromNode))
							       then
								(replace (GRAPHNODE TONODES)
								   of FromNode
								   with (CONS
									    (fetch (GRAPHNODE
										       NODEID)
									       of OldLabelNode)
									    (fetch (GRAPHNODE
										       TONODES)
									       of FromNode))))
							   FromNodeID))
                                                             (* For the old label node's ToNodes, just need to 
							     remove any for ToNodes that no longer exist.)
				    (replace (GRAPHNODE TONODES) of OldLabelNode
				       with (for ToNodeID in (fetch (GRAPHNODE TONODES)
								      of OldLabelNode)
						 bind ToNode eachtime (BLOCK)
						 when (SETQ ToNode (FASSOC ToNodeID Lattice))
						 collect 
                                                             (* If the To node isn't a label node, then add to its 
							     FromNode list.)
							   (if (NC.LinkIconImageObjP
								   (fetch (GRAPHNODE NODELABEL)
								      of ToNode))
							       then
								(replace (GRAPHNODE FROMNODES)
								   of ToNode
								   with (CONS
									    (fetch (GRAPHNODE
										       NODEID)
									       of OldLabelNode)
									    (fetch (GRAPHNODE
										       FROMNODES)
									       of ToNode))))
							   ToNodeID)))
                                                             (* Layout graph, including as roots any non-virtual 
							     nodes with no from nodes to avoid disconnected 
							     graphs.)
			    (SETQ Graph (if (AND Lattice RootNodes)
					      then (LAYOUTGRAPH
						       Lattice
						       (for Node in Lattice bind NodeID
							  eachtime (BLOCK)
								     (SETQ NodeID
								       (OR (NC.CoerceToGraphNodeID
									       Node)
									     (fetch (GRAPHNODE
											NODEID)
										of Node)))
							  when (OR (FMEMB NodeID RootNodes)
								       (NULL (fetch (GRAPHNODE
											  FROMNODES)
										  of Node)))
							  collect NodeID)
						       (SUBST (QUOTE LATTICE)
								NC.*Graph*BrowserFormat BrowserFormat)
						       (fetch (SPECIALBROWSERSPECS Font)
							  of SpecialBrowserSpecs)
						       (fetch (SPECIALBROWSERSPECS MotherD)
							  of SpecialBrowserSpecs)
						       (fetch (SPECIALBROWSERSPECS PersonalD)
							  of SpecialBrowserSpecs)
						       (fetch (SPECIALBROWSERSPECS FamilyD)
							  of SpecialBrowserSpecs))
					    else (create GRAPH)))
                                                             (* Build links legend and fix up TONODES in the 
							     graph.)
			    (NC.SetBrowserLinksLegend Card (NC.MakeLinksLegend Graph Window 
									      DropVirtualNodesFlg))
			    (NC.SetBrowserRoots Card RootCards)
			    (NC.SetBrowserDepth Card Depth)
			    (WINDOWPROP Window (QUOTE GRAPH)
					  Graph)
			    (NC.RelayoutBrowserCard Window T)))))))

(NC.BrowserAddNode
  (LAMBDA (Graph Window)                                     (* pmi: "12-Dec-86 12:55")

          (* * Called by grapher when user creates a new node. Returns new node or nil.)



          (* * rht 11/17/85: updated to handle new card and notefile formats.)



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



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


    (DECLARE (GLOBALVARS NC.BrowserContentsLinkLabel))
    (PROG ((GraphCard (NC.CoerceToCard Window))
	     Link GraphNodeID Card)                          (* Get user to select an existing card.
							     Not allowed to create a new one.)
	    (SETQ Card (NC.SelectNoteCards T (FUNCTION (LAMBDA (SelectedCard)
						   (COND
						     ((NOT (NC.SameCardP SelectedCard GraphCard))
						       T)
						     (T (NC.PrintMsg Window T 
							      "The browser can't link to itself."
								       (CHARACTER 13)
								       "Selection ignored."
								       (CHARACTER 13))
							NIL))))
					       NC.SelectingCardMenu GraphCard 
					      "Shift-select a card or box to include in browser."))
	    (if (NULL Card)
		then (RETURN NIL))                       (* Make link from browser to new card.)
	    (SETQ Link (NC.MakeLink Window NC.BrowserContentsLinkLabel Card GraphCard NIL NIL NIL 
					T))                  (* Check that it doesn't already exist.
							     If not, create a browser node.)
	    (COND
	      (Link                                          (* Create hash array if haven't already.)
		    (NC.GetBrowserHashArray GraphCard Graph)
		    (SETQ GraphNodeID (NC.GetBrowserNodeID GraphCard (SETQ Card
							       (fetch (Link DestinationCard)
								  of Link))))
		    (COND
		      ((for Node in (fetch (GRAPH GRAPHNODES) of Graph)
			  thereis (EQ GraphNodeID (NC.CoerceToGraphNodeID Node)))
			(NC.PrintMsg Window T "Node for card '" (NC.RetrieveTitle Card)
				       "' already in graph.")
			(NCP.DeleteLinks Link)
			(RETURN NIL)))
		    (NC.MarkCardDirty GraphCard)
		    (RETURN (NODECREATE GraphNodeID (NC.MakeLinkIcon Link)
					    (CURSORPOSITION NIL Window))))))))
)
(* * Change to NCDOCUMENTCARD)

(DEFINEQ

(NC.MakeDocument
  (LAMBDA (Card Title NoDisplayFlg CardIdentifier)           (* pmi: "12-Dec-86 14:03")

          (* * Called from a filebox's title bar. Makes a document by smashing all the descendant cards's text together.
	  Ask user if wants numbered section headings and titles. The former are made from FileBox titles, the latter from 
	  notecard titles. Delete embedded links at the end if the user desires.)



          (* * rht 10/22/84: Hacked to be callable from Programmer's interface.)



          (* * rht 11/17/84: Checks for cancel when choosing rootID and also when setting parameters.)



          (* * rht 8/25/85: Now dumps sketch and graph cards as well as text cards.)



          (* * rht 9/16/85: Now handles cr's around titles using para leading.)



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



          (* * kirk 27Jun86 Moved NC.RetrieveTitle call so does not break when user Cancels)



          (* * rht 7/31/86: Now checks for card types having ExportSubstanceFn prop.)



          (* * kirk 8/22/86 Fix of free use of NoteFile var)



          (* * rht 10/15/86: Integrated markM's changes and fixed box numbering.)



          (* * rht 11/17/86: Now calls NC.ApplySupersFn rather than NC.MakeNoteCard.)



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


    (PROG (RootCard RootTitle DocWindow DocCard DocWindowOrCard DocStream HeadingsFromFileboxes 
		      TitlesFromNoteCards BuildBackLinks CopyEmbeddedLinks ExpandEmbeddedLinks 
		      InspectWin RootSubstanceType)
	    (OR NoDisplayFlg (SPAWN.MOUSE))
	    (SETQ DocWindowOrCard (NC.ApplySupersFn MakeFn Card "Document" NoDisplayFlg))
	    (if NoDisplayFlg
		then (SETQ DocWindow NIL)
		       (SETQ DocCard DocWindowOrCard)
	      else (SETQ DocWindow DocWindowOrCard)
		     (SETQ DocCard (NC.CoerceToCard DocWindow)))
                                                             (* NC.MakeNoteCard either returned an Card or a window
							     depending on NoDisplayFlg.)
	    (SETQ RootCard (OR (NC.CoerceToCard CardIdentifier)
				   (NC.SelectNoteCards T NIL NC.SelectingCardMenu DocWindow 
		  "Please shift-select the Note Card or File Box the document should start from.")))
	    (if (NOT RootCard)
		then (NC.DeleteNoteCards Card T NIL NIL T T)
		       (RETURN NIL))
	    (SETQ RootTitle (NC.RetrieveTitle RootCard))
	    (NC.SetTitle DocCard (CONCAT "Document from %"" RootTitle "%""))
	    (AND DocWindow (WINDOWPROP DocWindow (QUOTE TITLE)
					   (NC.RetrieveTitle DocCard)))
	    (SETQ DocStream (NC.FetchSubstance DocCard))

          (* * Get MakeDocument parameters from user via inspector window.)


	    (if (NOT NoDisplayFlg)
		then (SETQ InspectWin (NC.BuildMakeDocInspector DocWindow))
		       (TOTOPW InspectWin)
		       (for while (OPENWP InspectWin) do (BLOCK)))
	    (if (EQ (GETPROP (QUOTE NC.MakeDocParameters)
				   (QUOTE --DONE--))
			(QUOTE QUIT))
		then (PUTPROP (QUOTE NC.MakeDocParameters)
				  (QUOTE --DONE--)
				  (QUOTE --CANCEL--))
		       (NC.DeleteNoteCards Card T NIL NIL T T)
		       (RETURN NIL))
	    (SETQ HeadingsFromFileboxes (GETPROP (QUOTE NC.MakeDocParameters)
						     (QUOTE HeadingsFromFileboxes)))
	    (SETQ TitlesFromNoteCards (GETPROP (QUOTE NC.MakeDocParameters)
						   (QUOTE TitlesFromNoteCards)))
	    (SETQ BuildBackLinks (GETPROP (QUOTE NC.MakeDocParameters)
					      (QUOTE BuildBackLinks)))
	    (SETQ CopyEmbeddedLinks (GETPROP (QUOTE NC.MakeDocParameters)
						 (QUOTE CopyEmbeddedLinks)))
	    (SETQ ExpandEmbeddedLinks (GETPROP (QUOTE NC.MakeDocParameters)
						   (QUOTE ExpandEmbeddedLinks)))

          (* * Call recursive routine to dump filebox.)


	    (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
			(NC.PrintMsg DocWindow NIL "Collecting text from descendant cards ... ")

          (* * Clean up the SeenBefore markers placed on the cards and boxes just copied.)


			(RESETSAVE NIL (QUOTE (PROGN (for Card in (NC.FetchUserDataProp
									      DocCard
									      (QUOTE SeenCards))
							      do (NC.SetUserDataProp
								     Card
								     (QUOTE SeenBefore)
								     NIL))
							   (NC.SetUserDataProp DocCard
										 (QUOTE SeenCards)
										 NIL))))

          (* * Unbelievably kludgy hack to get around Intermezzo TEdit bug. Just insert and delete a CR.)


			(TEDIT.INSERT DocStream NC.CRString 1)
			(TEDIT.DELETE DocStream 1 1)
			(NC.DumpCardToDoc RootCard DocCard DocStream 0 0 HeadingsFromFileboxes 
					  TitlesFromNoteCards BuildBackLinks CopyEmbeddedLinks 
					  ExpandEmbeddedLinks)
			(NC.PrintMsg DocWindow NIL "Done!"))
	    (COND
	      ((NOT NoDisplayFlg)
		(BLOCK 250)
		(NC.ClearMsg DocWindow T)))
	    (RETURN DocWindowOrCard))))
)
(PUTPROPS PMIPATCH012 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1253 17941 (NC.SelectNoteCards 1263 . 12429) (NC.CloseNoteCards 12431 . 13765) (
NC.CopyStructure 13767 . 15453) (NC.CloseStructure 15455 . 16594) (NC.DeleteStructure 16596 . 17939)) 
(17974 18868 (NCP.SelectCards 17984 . 18866)) (18900 31358 (NC.AddParents 18910 . 21427) (
NC.DeleteNoteCards 21429 . 26959) (NC.DetermineSources 26961 . 28031) (NC.UnfileNoteCard 28033 . 31356
)) (31390 44679 (NC.MakeLink 31400 . 37536) (NC.MakeFilingLinks 37538 . 40022) (
NC.AddGlobalLinksToCard 40024 . 42277) (NC.AddLinksToCard 42279 . 44677)) (44713 53602 (NC.CopyCards 
44723 . 53600)) (53639 56376 (NC.FileBoxCollectChildren 53649 . 56374)) (56414 77166 (
NC.MakeBrowserCard 56424 . 63727) (NC.UpdateBrowserCard 63729 . 74713) (NC.BrowserAddNode 74715 . 
77164)) (77204 82569 (NC.MakeDocument 77214 . 82567)))))
STOP