(FILECREATED "12-Aug-86 01:15:24" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH088.;8 71999  

      changes to:  (VARS RHTPATCH088COMS)
		   (FNS NC.ClosePropListEditor NC.OpenPropListEditor NC.EditPropList 
			NC.PropListEditorOpenP NC.ShowLinks NC.FileBoxCollectChildren 
			NC.LinkIconWhenCopiedFn NC.DumpNoteCardToDoc NC.DumpFileBoxToDoc 
			NC.DumpExportableCardToDoc NC.LinkIconWhenDeletedFn NC.DelReferencesToCard 
			NC.CloseAllPropListEditors NC.DeleteNoteCard)

      previous date: "11-Aug-86 17:09:02" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH088.;1)


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

(PRETTYCOMPRINT RHTPATCH088COMS)

(RPAQQ RHTPATCH088COMS ((* * Change to NCLINKS)
			  (FNS NC.LinkIconWhenDeletedFn NC.DelReferencesToCard 
			       NC.LinkIconWhenCopiedFn NC.LinkIconWhenMovedFn NC.AddToLink 
			       NC.CachedAddToLink)
			  (* * Change to NCCARDS)
			  (FNS NC.DeleteNoteCard NC.CloseAllPropListEditors NC.ClosePropListEditor 
			       NC.OpenPropListEditor NC.PropListEditorOpenP NC.EditPropList 
			       NC.ShowLinks)
			  (* * Change to NCDOCUMENTCARD)
			  (FNS NC.DumpNoteCardToDoc NC.MakeDocument NC.DumpFileBoxToDoc 
			       NC.DumpExportableCardToDoc)
			  (* * Change to NCFILEBOXCARD)
			  (FNS NC.FileBoxCollectChildren)))
(* * Change to NCLINKS)

(DEFINEQ

(NC.LinkIconWhenDeletedFn
  (LAMBDA (ImageObject Stream)                               (* rht: "11-Aug-86 21:53")

          (* * When deleting a link icon image object from a card, make sure the link information on the source and 
	  destinmation cards get updated. When deleting a link image object from a prop list editor, just inform the user 
	  that this is a useless operation.)



          (* * rht 11/19/84: Now handles the case when a move is in progress. True if the old link is cached on the ImageObj.
	  Also changed so that SourceID is computed from ImageObject rather than from Stream. Similarly for the window.)



          (* * kirk 14Nov85: deleted use of PSA.Database)



          (* * fgh 5/2/86 Added code to handle deleting of links from ShowLinks editors.)



          (* * fgh 6/4/86 Added KLUDGE to take care of case when this is called under TEDIT.UNDO.MOVE)



          (* * rht 7/4/86: Now checks for readonly cards. Also passes checks for deleting from orphan card when calling 
	  NC.DeleteLink.)



          (* * fgh 7/14/86 Now deletes link icon directly, rather than depending on DeleteLink to do it.
	  Sets the Don'tDeleteLinkIconFlg in the call to DeleteLink to do so.)



          (* * rht 8/11/86: Now computes InsideShowLinksP and lets that determine value of Don'tDelLinkIcon flg in call to 
	  NC.DeleteLink.)


    (LET ((Link (NC.FetchLinkFromLinkIcon ImageObject))
	  LinkType OldLink StkPtr SourceCard InsideShowLinksP)
         (if (NC.CheckForNotReadOnly (fetch (Link SourceCard) of Link)
					 NIL "Can't delete links in ")
	     then (COND
		      ((IMAGEOBJPROP ImageObject (QUOTE LinkBeingMovedWithinCard))
                                                             (* TEdit is trying to delete the old link imageobj 
							     after moving within a card.)
			(IMAGEOBJPROP ImageObject (QUOTE LinkBeingMovedWithinCard)
					NIL))
		      ((SETQ OldLink (IMAGEOBJPROP ImageObject (QUOTE LinkBeingMoved)))
			(NC.DelFromLink OldLink)
			(NC.DelToLink OldLink)
			(replace (Link UID) of OldLink with -1)
			(IMAGEOBJPROP ImageObject (QUOTE LinkBeingMoved)
					NIL))
		      ((SETQ StkPtr (STKPOS (QUOTE TEDIT.UNDO.MOVE)))

          (* * Called from TEDIT.UNDO.MOVE, don't relly want to delete the links. KLUDGE because TEDIT will not call the 
	  LinkIconInsertFn later on.)


			(RELSTK StkPtr)
			NIL)
		      (T 

          (* * if this is reversed source/dest {i.e., a From link} inside the show links editor, then return it to its 
	  original direction)


			 (if (AND (SETQ InsideShowLinksP (IMAGEOBJPROP ImageObject
									       (QUOTE 
									     InsidePropListEditor)))
				      (LISTGET (fetch (Link UserData) of Link)
						 (QUOTE Reversed)))
			     then (SETQ Link (create Link using Link SourceCard ←(fetch
									  (Link DestinationCard)
											    of
											     Link)
									DestinationCard ←(fetch
									  (Link SourceCard)
											    of
											     Link))))

          (* * Then just delete the link)


			 (NC.CheckForOrphanDelete (SETQ SourceCard (fetch (Link SourceCard)
									  of Link))
						    (fetch (Link DestinationCard) of Link))
			 (NC.DeleteLink Link (NC.SameCardP SourceCard (fetch (NoteFile 
										      OrphansCard)
									     of
									      (fetch (Card NoteFile)
										 of SourceCard)))
					  (NOT InsideShowLinksP))
			 (create IMAGEOBJ smashing ImageObject OBJECTDATUM ←(fetch
							 (IMAGEOBJ OBJECTDATUM) of 
									NC.DeletedLinkImageObject)
						       IMAGEOBJPLIST ←(fetch (IMAGEOBJ 
										    IMAGEOBJPLIST)
									 of 
									NC.DeletedLinkImageObject)
						       IMAGEOBJFNS ←(fetch (IMAGEOBJ IMAGEOBJFNS)
								       of NC.DeletedLinkImageObject)
				   )
			 (replace (Link UID) of Link with -1)))
	   else (ERROR!)))))

(NC.DelReferencesToCard
  (LAMBDA (SourceCard LinkOrDestinationCard)                 (* rht: "11-Aug-86 20:16")
                                                             (* The card specified by DestinationID is being 
							     deleted. Remove all references to it from the card 
							     specified by SourceCard)

          (* * kirk: 13Nov85: deleted use of DatabaseStream)



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



          (* * rht 8/11/86: Added ShrunkenFlg so that SourceCard is reshrunk afterwards if necessary.)


    (LET ((ShrunkenFlg (NC.GetShrunkenWin SourceCard))
	  NoteCardType Substance)
         (if (NC.ActiveCardP SourceCard)
	     then (SETQ NoteCardType (NC.RetrieveType SourceCard))
		    (SETQ Substance (NC.FetchSubstance SourceCard))
		    (NC.ApplyFn DeleteLinksFn SourceCard LinkOrDestinationCard)
	   else (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of SourceCard))
				(if (NC.ValidCardP (NC.GetNoteCard SourceCard))
				    then (SETQ NoteCardType (NC.RetrieveType SourceCard))
					   (SETQ Substance (NC.FetchSubstance SourceCard))
					   (NC.ApplyFn DeleteLinksFn SourceCard LinkOrDestinationCard)
					   (NC.PutMainCardData SourceCard)
					   (NC.DeactivateCard SourceCard))))
         (NC.DelReferencesToCardFromGlobalList SourceCard LinkOrDestinationCard)
         (AND ShrunkenFlg (SHRINKW (NC.FetchWindow SourceCard))))))

(NC.LinkIconWhenCopiedFn
  (LAMBDA (ImageObject ToWindowStream FromTextStream ToTextStream)
                                                             (* rht: "11-Aug-86 22:04")

          (* * Called when copying a link icon from FromTextStream to ToWindowStream. Sets the necessary link information up 
	  for card corresponding to ToWindowStream.)



          (* * rht 11/18/84: Major hacking. Now checks for all sorts of illegal cases. Either goes ahead with copy, converts 
	  link type to "Unspecified", or deletes the new "invisible" link. The latter will change when imageobj fns can 
	  return DON'T.)



          (* * rht 12/12/84: now does RETFROM instead of adding processes to delete imageobj's. This is cleaner, but still 
	  ugly.)



          (* * rht 3/25/85: Fixed to handle copies within a sketch card. That is indicated by nullity of the two textstream 
	  args.)



          (* * rht 3/24/86: Changed call to NC.CoerceToID to NC.CoerceToCard)



          (* * fgh 6/30/86 Now ERROR! out of attempt to copy between NoteFiles)



          (* * rht 7/14/86: Reversed order of tests for WINDOWP and TEXTSTREAMP in computation of NewSourceCard.)



          (* * rht 8/11/86: Now only resets NewSourceCard if it was NIL so that copies to a sketch will work.)


    (PROG ((Link (NC.FetchLinkFromLinkIcon ImageObject))
	     (ImageObjectCopy (IMAGEOBJPROP ImageObject (QUOTE ImageObjectCopy)))
	     (InTEditCopyFlg (COND
			       ((STKPOS (QUOTE TEDIT.COPY))
				 T)))
	     (Window (AND ToWindowStream (WFROMDS ToWindowStream T)))
	     SourceCard DestinationCard NewSourceCard NewLabel NewDisplayMode OldDisplayMode Label 
	     InsertPos)
	    (SETQ Label (fetch (Link Label) of Link))
	    (SETQ SourceCard (fetch (Link SourceCard) of Link))
	    (SETQ DestinationCard (fetch (Link DestinationCard) of Link))
	    (SETQ OldDisplayMode (fetch (Link DisplayMode) of Link))
	    (SETQ NewSourceCard (COND
		((TEXTSTREAMP ToTextStream)
		  (NC.CoerceToCard ToTextStream))
		((WINDOWP Window)
		  (NC.CoerceToCard Window))))
	    (COND
	      ((AND (NULL NewSourceCard)
		      (NULL FromTextStream)
		      (NULL ToTextStream))                 (* We must be moving within a sketch.)
		(SETQ NewSourceCard SourceCard))
	      ((TEXTSTREAMP ToTextStream)                  (* If it's a text copy, then compute position to 
							     insert link at.)
		(SETQ InsertPos (NC.CharPosFromTextObject (TEXTOBJ ToTextStream)))))

          (* * If we are copying across NoteFiles, then its an error)


	    (if (AND NewSourceCard (NOT (NC.SameNoteFileP (fetch (Card NoteFile)
								     of SourceCard)
								  (fetch (Card NoteFile)
								     of NewSourceCard))))
		then (NC.PrintMsg Window T 
				      "Cannot copy links between cards from different NoteFiles."
				      (CHARACTER 13)
				      "Copy aborted."
				      (CHARACTER 13))
		       (ERROR!))
	    (COND
	      ((NULL NewSourceCard)                        (* Trying to copy to a non NoteCard stream)
		(NC.PrintMsg Window NIL (CONCAT "Tried to copy a NoteCards link icon" 
						    " to a non-NoteCards stream."
						    (CHARACTER 13)))
		(NC.CoerceToExternalPutLinkIcon ImageObjectCopy SourceCard DestinationCard Label)
		(RETURN NIL))
	      ((NULL (NC.LinksSupportedP NewSourceCard (QUOTE (Local))))
		(NC.PrintMsg Window NIL (CONCAT "Tried to copy a NoteCards link icon" 
						    " to a NoteCard that"
						    " does not support links!!."
						    (CHARACTER 13)
						    "Tsk. Tsk."
						    (CHARACTER 13)))
		(COND
		  (InTEditCopyFlg (RETFROM (QUOTE TEDIT.COPY)
					     NIL T))
		  (T (RETURN (QUOTE DON'T)))))
	      ((AND (FMEMB Label (QUOTE (FiledCard SubBox)))
		      (NEQ (NC.RetrieveType NewSourceCard)
			     (QUOTE FileBox)))             (* Copy from filebox to non-filebox.)
		(NC.PrintMsg NIL NIL (CONCAT 
				       "Tried to copy filedcard or subbox link to a non-filebox."
						 (CHARACTER 13)
						 "Link type of copy set to 'Unspecified'."
						 (CHARACTER 13)))
		(SETQ NewLabel NC.UnspecifiedLinkLabel)
		(SETQ NewDisplayMode (create LINKDISPLAYMODE
					  copying OldDisplayMode SHOWTITLEFLG ← T SHOWLINKTYPEFLG ← 
						    T)))
	      ((AND (NEQ (NC.RetrieveType SourceCard)
			     (QUOTE FileBox))
		      (EQ (NC.RetrieveType NewSourceCard)
			    (QUOTE FileBox)))              (* Copy from non-filebox to filebox.)
		(NC.PrintMsg NIL NIL (CONCAT "Can't copy links from non-filebox to filebox."
						 (CHARACTER 13)
						 "Try using 'PutCardsHere'."
						 (CHARACTER 13)))
		(COND
		  (InTEditCopyFlg (RETFROM (QUOTE TEDIT.COPY)
					     NIL T))
		  (T (RETURN (QUOTE DON'T)))))
	      ((AND (FMEMB Label (QUOTE (FiledCard SubBox)))
		      (EQ NewSourceCard SourceCard))       (* Copy within same filebox.)
		(NC.PrintMsg NIL NIL (CONCAT 
					  "Can't copy links within a FileBox.  Try move instead."
						 (CHARACTER 13)))
		(COND
		  (InTEditCopyFlg (RETFROM (QUOTE TEDIT.COPY)
					     NIL T))
		  (T (RETURN (QUOTE DON'T)))))
	      ((AND (EQ (NC.RetrieveType NewSourceCard)
			    (QUOTE FileBox))
		      (for Link1 in (NC.FetchToLinks NewSourceCard)
			 thereis (AND (NC.ChildLinkP Link1)
					  (EQ DestinationCard (fetch (Link DestinationCard)
								   of Link1)))))
                                                             (* Copy to a filebox already containing this child.)
		(NC.PrintMsg NIL NIL (CONCAT (NC.RetrieveTitle DestinationCard)
						 " not copied: already appears as a child of "
						 (NC.RetrieveTitle NewSourceCard)
						 (CHARACTER 13)))
		(COND
		  (InTEditCopyFlg (RETFROM (QUOTE TEDIT.COPY)
					     NIL T))
		  (T (RETURN (QUOTE DON'T)))))
	      ((AND (EQ Label (QUOTE SubBox))
		      (OR (EQ NewSourceCard DestinationCard)
			    (NOT (NC.NotDaughterP DestinationCard NewSourceCard
						      (FUNCTION NC.ChildLinkP)))))
                                                             (* Copy to a filebox causes a cycle.)
		(NC.PrintMsg NIL NIL (CONCAT "Couldn't copy " Link " because of subbox cycle."
						 (CHARACTER 13)))
		(COND
		  (InTEditCopyFlg (RETFROM (QUOTE TEDIT.COPY)
					     NIL T))
		  (T (RETURN (QUOTE DON'T)))))
	      ((AND (FMEMB Label NC.SystemLinkLabels)
		      (NOT (FMEMB Label (QUOTE (FiledCard SubBox))))
		      (NEQ NewSourceCard SourceCard))      (* Copy of system link outside of own card.)
		(NC.PrintMsg NIL NIL (CONCAT "Tried to copy system link." (CHARACTER 13)
						 "Link type of copy set to 'Unspecified'."
						 (CHARACTER 13)))
		(SETQ NewLabel NC.UnspecifiedLinkLabel)
		(SETQ NewDisplayMode (create LINKDISPLAYMODE
					  copying OldDisplayMode SHOWTITLEFLG ← T SHOWLINKTYPEFLG ← 
						    T))))
	    (NC.FillInLinkIcon ImageObjectCopy (OR NewLabel Label)
				 DestinationCard NewSourceCard (OR NewDisplayMode OldDisplayMode)
				 (NC.LinkAtCharPos InsertPos ToTextStream))
	    (IMAGEOBJPROP ImageObject (QUOTE ImageObjectCopy)
			    NIL))))

(NC.LinkIconWhenMovedFn
  (LAMBDA (ImageObject ToWindowStream FromTextStream ToTextStream)
                                                             (* rht: "11-Aug-86 21:53")

          (* * Called when moving a link icon from FromTextStream to ToWindowStream. Sets the necessary link information up 
	  for card corresponding to ToWindowStream.)



          (* * rht 11/18/84: Major hacking. Now checks for all sorts of illegal cases. Either goes ahead with move, converts 
	  link type to "Unspecified", or deletes the new "invisible" link. The code is very similar to 
	  NC.LinkIconWhenCopiedFn except that within-filebox moves are allowed. Also when aborting a move, we must insert a 
	  copy of the link back to take the place of the deleted original. This will all change when imageobj fns can return 
	  DON'T.)



          (* * rht 12/12/84: Now just RETFROM's rather than doing the addprocess stuff. Should be cleaner, but still ugly.)



          (* * kirk 15Nov85: deleted use of PSA.Database)



          (* * rht 3/24/86: Changed call to NC.CoerceToID to NC.CoerceToCard)



          (* * kirk 24Mar86: added Dave Newman patch to avoid duplicate links in sketch cards)



          (* * rht 7/14/86: Reversed order of tests for WINDOWP and TEXTSTREAMP in computation of NewSourceCard.)



          (* * rht 8/11/86: Now only resets NewSourceCard if it was NIL so that moves to a sketch will work.
	  Now checks if SourceCard = NewSourceCard in which case we're moving within a card. Don't make a new link in that 
	  case.)


    (LET (Label (Link (NC.FetchLinkFromLinkIcon ImageObject))
		SourceCard DestinationCard NewSourceCard NewLabel NewDisplayMode OldDisplayMode
		(Window (AND ToWindowStream (WFROMDS ToWindowStream T)))
		InsertPos)
         (SETQ Label (fetch (Link Label) of Link))
         (SETQ NewSourceCard (COND
	     ((TEXTSTREAMP ToTextStream)
	       (NC.CoerceToCard ToTextStream))
	     ((WINDOWP Window)
	       (NC.CoerceToCard Window))))
         (SETQ SourceCard (fetch (Link SourceCard) of Link))
         (SETQ DestinationCard (fetch (Link DestinationCard) of Link))
         (SETQ OldDisplayMode (fetch (Link DisplayMode) of Link))

          (* * If we are copying across NoteFiles, then it's an error)


         (if (AND NewSourceCard (NOT (NC.SameNoteFileP (fetch (Card NoteFile) of 
										       SourceCard)
							       (fetch (Card NoteFile) of 
										    NewSourceCard))))
	     then (NC.PrintMsg Window T 
				   "Cannot move links between cards from different NoteFiles."
				   (CHARACTER 13)
				   "Move aborted."
				   (CHARACTER 13))
		    (ERROR!))
         (COND
	   ((AND (NULL NewSourceCard)
		   (NULL FromTextStream)
		   (NULL ToTextStream))                    (* We must be moving within a sketch.)
	     (SETQ NewSourceCard SourceCard))
	   ((TEXTSTREAMP ToTextStream)                     (* If it's a text copy, then compute position to 
							     insert link at.)
	     (SETQ InsertPos (NC.CharPosFromTextObject (TEXTOBJ ToTextStream)))))
         (COND
	   ((NULL NewSourceCard)                           (* Trying to copy to a non NoteCard stream)
	     (NC.PrintMsg Window NIL (CONCAT "Tried to move a NoteCards link icon" 
						 " to a non-NoteCards stream!!."
						 (CHARACTER 13)
						 "Tsk. Tsk."
						 (CHARACTER 13)))
	     (RETFROM (QUOTE TEDIT.MOVE)
			NIL T))
	   ((NULL (NC.LinksSupportedP NewSourceCard (QUOTE (Local))))
	     (NC.PrintMsg Window NIL (CONCAT "Tried to move a NoteCards link icon" 
						 " to a NoteCard that"
						 " does not support links!!."
						 (CHARACTER 13)
						 "Tsk. Tsk."
						 (CHARACTER 13)))
	     (RETFROM (QUOTE TEDIT.MOVE)
			NIL T))
	   ((AND (FMEMB Label (QUOTE (FiledCard SubBox)))
		   (NEQ (NC.RetrieveType NewSourceCard)
			  (QUOTE FileBox)))                (* Move from filebox to non-filebox.)
	     (NC.PrintMsg NIL NIL (CONCAT 
				       "Tried to move filedcard or subbox link to a non-filebox."
					      (CHARACTER 13)
					      "Link type of copy set to 'Unspecified'."
					      (CHARACTER 13)))
	     (SETQ NewLabel NC.UnspecifiedLinkLabel)
	     (SETQ NewDisplayMode (create LINKDISPLAYMODE
				       copying OldDisplayMode SHOWTITLEFLG ← T SHOWLINKTYPEFLG ← T))
	     )
	   ((AND (NEQ (NC.RetrieveType SourceCard)
			  (QUOTE FileBox))
		   (EQ (NC.RetrieveType NewSourceCard)
			 (QUOTE FileBox)))                 (* Move from non-filebox to filebox.)
	     (NC.PrintMsg NIL NIL (CONCAT "Can't move links from non-filebox to filebox."
					      (CHARACTER 13)
					      "Try using PutCardsHere."
					      (CHARACTER 13)))
	     (RETFROM (QUOTE TEDIT.MOVE)
			NIL T))
	   ((AND (EQ (NC.RetrieveType NewSourceCard)
			 (QUOTE FileBox))
		   (NEQ NewSourceCard SourceCard)
		   (for Link1 in (NC.FetchToLinks NewSourceCard)
		      thereis (AND (NC.ChildLinkP Link1)
				       (EQ DestinationCard (fetch (Link DestinationCard)
								of Link1)))))
                                                             (* Move to a filebox already containing this child.)
	     (NC.PrintMsg NIL NIL (CONCAT (NC.RetrieveTitle DestinationCard)
					      " not moved: already appears as a child of "
					      (NC.RetrieveTitle NewSourceCard)
					      (CHARACTER 13)))
	     (RETFROM (QUOTE TEDIT.MOVE)
			NIL T))
	   ((AND (EQ Label (QUOTE SubBox))
		   (NEQ NewSourceCard SourceCard)
		   (OR (EQ NewSourceCard DestinationCard)
			 (NOT (NC.NotDaughterP DestinationCard NewSourceCard
						   (FUNCTION NC.ChildLinkP)))))
                                                             (* Move to a filebox causes a cycle.)
	     (NC.PrintMsg NIL NIL (CONCAT "Couldn't move " Link " because of subbox cycle."
					      (CHARACTER 13)))
	     (RETFROM (QUOTE TEDIT.MOVE)
			NIL T))
	   ((AND (FMEMB Label NC.SystemLinkLabels)
		   (NOT (FMEMB Label (QUOTE (FiledCard SubBox))))
		   (NEQ NewSourceCard SourceCard))         (* Move of system link outside of own card.)
	     (NC.PrintMsg NIL NIL (CONCAT "Tried to copy system link." (CHARACTER 13)
					      "Link type of copy set to 'Unspecified'."
					      (CHARACTER 13)))
	     (SETQ NewLabel NC.UnspecifiedLinkLabel)
	     (SETQ NewDisplayMode (create LINKDISPLAYMODE
				       copying OldDisplayMode SHOWTITLEFLG ← T SHOWLINKTYPEFLG ← T))
	     ))
         (if (EQ SourceCard NewSourceCard)
	     then                                          (* Moving within a card, so just reposition Link in 
							     ToLinks list.)
		    (AND (NC.TEditBasedP SourceCard)
			   (IMAGEOBJPROP ImageObject (QUOTE LinkBeingMovedWithinCard)
					   Link))
		    (NC.AddToLink Link (NC.LinkAtCharPos InsertPos ToTextStream)
				    T)
	   else (IMAGEOBJPROP ImageObject (QUOTE LinkBeingMoved)
				  Link)
		  (NC.FillInLinkIcon ImageObject (OR NewLabel Label)
				       DestinationCard NewSourceCard (OR NewDisplayMode 
									   OldDisplayMode)
				       (NC.LinkAtCharPos InsertPos ToTextStream))))))

(NC.AddToLink
  (LAMBDA (Link LinkToInsertAfter BeingMovedFlg)             (* rht: "11-Aug-86 21:39")

          (* * Add Link to the ToLinks of the source card)



          (* * rht 3/26/85: Added LinkToInsertAfter arg which is either NIL, ATEND, or a link after which to insert new link.
	  If NIL, then insert at front of list. If ATEND then insert at end.)



          (* * kirk: 13Nov85: deleted second parameter (DatabaseSTream) and changed to call NC.CachedAddToLink.)



          (* * rht 2/14/86: Now calls NC.UncacheLinks instead of two calls to NC.SetToLinks and NC.SetFromLinks.)



          (* * rht 8/11/86: Added BeingMovedFlg. If non-nil, then delete instance of Link from ToLinks before inserting it in
	  new spot.)


    (LET ((SourceCard (fetch (Link SourceCard) of Link)))
         (COND
	   ((NC.ActiveCardP SourceCard)
	     (NC.CachedAddToLink Link SourceCard LinkToInsertAfter BeingMovedFlg))
	   (T (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of SourceCard))
			    (NC.GetLinks SourceCard)
			    (NC.CachedAddToLink Link SourceCard LinkToInsertAfter BeingMovedFlg)
			    (NC.PutLinks SourceCard)
			    (NC.UncacheLinks SourceCard)))))
    Link))

(NC.CachedAddToLink
  (LAMBDA (Link SourceCard LinkToInsertAfter BeingMovedFlg)
                                                             (* rht: "11-Aug-86 21:39")

          (* * Add Link to the cached ToLinks of the source card)



          (* * rht 3/26/85: Added LinkToInsertAfter arg which is either NIL, ATEND, or a link after which to insert new link.
	  If NIL, then insert at front of list. If ATEND then insert at end.)



          (* * kirk: 13Nov85: changed to use NoteFile instead of DatabaseStream)



          (* * kirk 15Nov85: deleted use of LinkID)



          (* * rht 8/11/86: Added BeingMovedFlg. If non-nil, then delete instance of Link from ToLinks before inserting it in
	  new spot.)


    (LET ((ToLinks (NC.FetchToLinks SourceCard)))
         (if BeingMovedFlg
	     then                                          (* Look for and delete old instance of the link.)
		    (if (NC.SameLinkP Link (CAR ToLinks))
			then (NC.SetToLinks SourceCard (SETQ ToLinks (CDR ToLinks)))
		      else (for RestOfToLinks on ToLinks thereis (NC.SameLinkP
									   Link
									   (CADR RestOfToLinks))
				finally (RPLACD RestOfToLinks (CDDR RestOfToLinks)))))
         (COND
	   ((AND ToLinks (type? Link LinkToInsertAfter))
                                                             (* Destructively insert after a given link.)
	     (for RestOfToLinks on ToLinks thereis (NC.SameLinkP LinkToInsertAfter
									 (CAR RestOfToLinks))
		finally (COND
			    (RestOfToLinks (RPLACD RestOfToLinks (CONS Link (CDR RestOfToLinks))
						     ))
			    (T (NC.SetToLinks SourceCard (NCONC1 ToLinks Link))))))
	   ((EQ LinkToInsertAfter (QUOTE ATEND))         (* Destructively insert at the end.)
	     (NC.SetToLinks SourceCard (NCONC1 ToLinks Link)))
	   (T                                                (* Stick it at the front.)
	      (NC.SetToLinks SourceCard (CONS Link ToLinks))))
         (NC.SetLinksDirtyFlg SourceCard T)
     Link)))
)
(* * Change to NCCARDS)

(DEFINEQ

(NC.DeleteNoteCard
  (LAMBDA (Card)                                             (* rht: "11-Aug-86 17:47")

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



          (* * rht 8/11/86: Now calls NC.DelReferencesToCardFromShowLinks to smash any link icons in show links menus 
	  pointing to this card.)


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

(NC.CloseAllPropListEditors
  (LAMBDA (Card)                                             (* rht: "11-Aug-86 19:11")
                                                             (* Force all prop list editors open on card ID to 
							     close without saving changes.)

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



          (* * rht 8/11/86: Now makes sure that proplist window gets closed.)


    (for AttachedWindow in (ALLATTACHEDWINDOWS (NC.FetchWindow Card))
       when (WINDOWPROP AttachedWindow (QUOTE PropListEditor)) eachtime (BLOCK)
       do (NC.ClosePropListEditor AttachedWindow (QUOTE NoSave))
	    (AND (OPENWP AttachedWindow)
		   (CLOSEW AttachedWindow)))))

(NC.ClosePropListEditor
  (LAMBDA (Window SaveFlg)                                   (* rht: "12-Aug-86 01:04")

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



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



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



          (* * rht 8/12/86: Now calls TEXTOBJ to get TextObj from Window.)


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

(NC.OpenPropListEditor
  (LAMBDA (WindowOrTextStream PropList Title ShowOnlyFlg MakeImageObjFlg ShowLinksFlg)
                                                             (* rht: "12-Aug-86 01:13")
                                                             (* Open a property list editor above the card 
							     specified by TextStream , which is either a TextStream
							     or a Window)

          (* * rht 8/11/86: Now takes ShowLinksFlg arg and passes to NC.PropListEditorOpenP so that we don't bail out if 
	  there's an open proplist not of our type.)


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

(NC.PropListEditorOpenP
  (LAMBDA (Window ShowLinksFlg)                              (* rht: "12-Aug-86 00:08")
                                                             (* Is there a prop list editor opened on this window?)

          (* * rht 8/11/86: Now doesn't return NIL unless there's an open proplist editor of our type.)


    (for AttachedWindow in (ALLATTACHEDWINDOWS Window)
       thereis (AND (WINDOWPROP AttachedWindow (QUOTE PropListEditor))
			(LET ((ShowLinks (WINDOWPROP AttachedWindow (QUOTE ShowLinks))))
                                                             (* Check that ShowLinksFlg iff ShowLinks.)
			     (OR (AND ShowLinksFlg ShowLinks)
				   (AND (NULL ShowLinksFlg)
					  (NULL ShowLinks))))))))

(NC.EditPropList
  (LAMBDA (propList window showOnlyFlg)                      (* rht: "12-Aug-86 01:12")

          (* * propList is a list of RECORDS of type PropListItem)



          (* * Edit a property list using the TEDIT menu-based editor. The var window is the window to use.
	  If none supplied, get one from user.)



          (* * rht 4/11/86: Now stashes length of propList on WINDOWPROP.)



          (* * rht 8/12/86: Moved code to add NC.ClosePropListEditor on CLOSEFN from NC.OpenPropListEditor to here so that it
	  can before TEDIT.DEACTIVATE.WINDOW on the CLOSEFN list.)


    (PROG (menuStream textObj editW button (font (FONTCREATE (QUOTE HELVETICA)
								 8))
			(CH# 1)
			(ENDCH# 1))                          (* Init the editList and the propFnsList)
                                                             (* Create a TEDITMenu that reflects the structure of 
							     the proplist)
	    (SETQ menuStream
	      (\TEXTMENU.DOC.CREATE
		(for X in propList
		   join (NCONC (LIST (LIST (QUOTE MB.BUTTON)
						   (MKSTRING (fetch (PropListItem PropertyName)
								  of X))
						   (OR (fetch (PropListItem ButtonFn)
							    of X)
							 (FUNCTION NC.EditPropButtonFN))))
				   (COND
				     ((NOT (IMAGEOBJP (fetch (PropListItem Value) of X)))
				       (COND
					 ((fetch (PropListItem AllowEditFlg) of X)
					   (LIST (LIST (QUOTE MB.TEXT)
							   (CONCAT (CHARACTER 9)
								     "  ["
								     (MKSTRING (fetch
										   (PropListItem
										     Value)
										    of X))
								     "]"
								     (CHARACTER 13))
							   font)))
					 (T (LIST (LIST (QUOTE MB.TEXT)
							    (CHARACTER 9)
							    font)
						    (LIST (QUOTE MB.INSERT)
							    (MKSTRING (fetch (PropListItem Value)
									   of X)))
						    (LIST (QUOTE MB.TEXT)
							    (CHARACTER 13)
							    font)))))
				     (T (LIST (LIST (QUOTE MB.TEXT)
							(CHARACTER 9)
							font)
						(LIST (QUOTE MB.INSERT))
						(LIST (QUOTE MB.TEXT)
							(CHARACTER 13)
							font))))))))
	    (SETQ textObj (TEXTOBJ menuStream))          (* Go back and insert the ImageObjects into their 
							     value fields.)
	    (SETQ CH# 0)
	    (for prop in propList when (OR (IMAGEOBJP (fetch (PropListItem Value)
								   of prop))
						   (NULL (fetch (PropListItem AllowEditFlg)
							      of prop)))
	       do (MBUTTON.FIND.NEXT.FIELD textObj (SETQ CH# (ADD1 CH#)))
		    (SETQ CH# (fetch CH# of (fetch SCRATCHSEL of textObj)))
		    (COND
		      ((IMAGEOBJP (CADR prop))
			(TEDIT.INSERT.OBJECT (fetch (PropListItem Value) of prop)
					       menuStream CH#))))
	    (SETQ CH# 0)
	    (for prop in propList
	       do (SETQ button (MBUTTON.FIND.NEXT.BUTTON textObj (ADD1 CH#)))
		    (SETQ CH# (CDR button))              (* If the buttonProtect flag is on, protect the 
							     button)
		    (AND (fetch (PropListItem AllowSelectFlg) of prop)
			   (IMAGEOBJPROP (CAR button)
					   (QUOTE EditPropListNoDelete)
					   T)))              (* Set up window and window title)
	    (SETQ editW (COND
		(window window)
		(T (CREATEW (GETREGION)
			      "Edit Property List"))))       (* Point to the proplist being edited so we can update
							     it when this menu is closed.
							     (See NC.CloseEditPropListWindow))
	    (WINDOWPROP editW (QUOTE PROPERTYLIST.BEING.EDITED)
			  propList)
	    (WINDOWPROP editW (QUOTE PROPERTYLIST.LENGTH)
			  (LENGTH propList))               (* Set the right margin to very-far-away.
							     Prevents stuff from wrapping around)
	    (TEDIT.PARALOOKS textObj (QUOTE (RIGHTMARGIN 1000 TABS (50 (80 . LEFT))))
			       1
			       (GETFILEINFO menuStream (QUOTE LENGTH)))
                                                             (* Set the first tab so the fields will line up 
							     correctly)
                                                             (* Set selection to the top -- make it look pretty)
	    (replace (SELECTION SET) of (fetch (TEXTOBJ SEL) of textObj) with NIL)
	    (TEDIT menuStream editW NIL (LIST
		       (QUOTE MENU)
		       (create MENU
				 ITEMS ←(COND
				   (showOnlyFlg (QUOTE (("Quit" (NC.ClosePropListEditor
								    W
								    (QUOTE NoSave))
								  "Quit from pointer list display.")))
						)
				   (T (QUOTE (("Add New Property" (NC.AddPropToPropList W)
								    
					       "Add a new property to this card's property list.")
						 ("Delete Selected Property" (NC.DelPropFromList
									       W)
									     
				       "Delete selected property from this card's property list.")
						 ("Quit w/o Saving Changes" (NC.ClosePropListEditor
									      W
									      (QUOTE NoSave))
									    
					   "Quit from property list edit. Changes are not saved.")
						 ("Quit - Saving Changes" (NC.ClosePropListEditor
									    W
									    (QUOTE Save))
									  
						  "Quit from property list editor. Save changes.")))))
				 )))
	    (WINDOWADDPROP editW (QUOTE CLOSEFN)
			     (FUNCTION NC.ClosePropListEditor)
			     T))))

(NC.ShowLinks
  (LAMBDA (TextStream)                                       (* rht: "12-Aug-86 00:00")
                                                             (* Open an inspector for the links for note card 
							     specified by TextStream above the window for the note 
							     card.)

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



          (* * fgh 5/2/86 Included calls to NC.InsureLinkDisplayMode to handle litatom link display modes.
	  Added InsdiePropListEditor and Reverse indicators to UserData field of Links in show links editor.
	  Also added ShowLinks property onto the editor window so other functions can detect that a window is a show links 
	  window.)



          (* * rht 8/11/86: Now passes non-nil ShowLinksFlg to NC.OpenPropListEditor.)


    (LET (Links EditWindow (Card (NC.CoerceToCard (WINDOW.FROM.TEDIT.THING TextStream))))
         (SETQ Links (NCONC (for Link in (NC.FetchToLinks Card)
				   join (LIST (COND
						    ((EQ (fetch (Link AnchorMode) of Link)
							   (QUOTE GlobalGlobal))
						      "Global TO")
						    (T "TO"))
						  (LIST (create Link
							     using
							      Link DisplayMode ←(create 
										  LINKDISPLAYMODE
										   copying
										    (
									 NC.InsureLinkDisplayMode
										      (fetch
											(Link 
										      DisplayMode)
											 of Link))
										    SHOWTITLEFLG ← T 
										  SHOWLINKTYPEFLG ← T)
							      UserData ←(QUOTE (InsidePropListEditor
										   T))))))
				(for Link in (NC.FetchFromLinks Card)
				   join (LIST "FROM"
						  (LIST (create Link
							     using
							      Link DisplayMode ←(create 
										  LINKDISPLAYMODE
										   copying
										    (
									 NC.InsureLinkDisplayMode
										      (fetch
											(Link 
										      DisplayMode)
											 of Link))
										    SHOWTITLEFLG ← T 
										  SHOWLINKTYPEFLG ← T)
							      SourceCard ←(fetch (Link 
										  DestinationCard)
									     of Link)
							      DestinationCard ←(fetch (Link 
										       SourceCard)
										  of Link)
							      UserData ←(QUOTE (InsidePropListEditor
										   T Reversed T)))))))
	   )
         (WINDOWPROP (SETQ EditWindow (NC.OpenPropListEditor TextStream Links "List of Links" T 
								   T T))
		       (QUOTE ShowLinks)
		       T)
     EditWindow)))
)
(* * Change to NCDOCUMENTCARD)

(DEFINEQ

(NC.DumpNoteCardToDoc
  (LAMBDA (Card DocCard DocStream SectionNum BoxNum HeadingsFromFileboxes TitlesFromNoteCards 
		BuildBackLinks CopyEmbeddedLinks ExpandEmbeddedLinks)
                                                             (* rht: "11-Aug-86 20:36")

          (* * Dump the CardID notecard to the document card DocStream.)



          (* * rht 8/25/85: Fixed to handle sketch and graph 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.)



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



          (* * rht 8/11/86: Added ShrunkenFlg so that Card is reshrunk afterwards if necessary.)


    (PROG ((CardStream (NC.FetchSubstance Card))
	     (DocObj (TEXTOBJ DocStream))
	     ShrunkenFlg CardObj OldLoc)
	    (SETQ CardObj (TEXTOBJ CardStream))
	    (NC.AddCRIfNeeded DocStream)
	    (SETQ OldLoc (fetch (TEXTOBJ TEXTLEN) of DocObj))
	    (AND (NEQ TitlesFromNoteCards (QUOTE NONE))
		   (NC.AppendStringToStream DocStream (CONCAT (NC.RetrieveTitle Card))
					      (EQ TitlesFromNoteCards (QUOTE Bold))))
	    (AND (FMEMB BuildBackLinks (QUOTE (ToCards ToCardsBoxes)))
		   (NCP.LocalGlobalLink NC.DocBackPtrLinkLabel DocCard Card (QUOTE END)
					  (QUOTE Icon)))
	    (COND
	      ((GREATERP (fetch (TEXTOBJ TEXTLEN) of DocObj)
			   OldLoc)
		(NC.AddCRIfNeeded DocStream)
		(NC.ChangeParaLeading DocStream)))
	    (COND
	      ((NC.FetchUserDataProp Card (QUOTE SeenBefore))
		(NC.PrintMsg NIL NIL (NC.RetrieveTitle Card)
			       " only expanded once in this cycle."
			       (CHARACTER 13))
		(RETURN)))
	    (SETQ ShrunkenFlg (NC.GetShrunkenWin Card))
	    (NC.SetUserDataProp DocCard (QUOTE SeenCards)
				  (CONS Card (NC.FetchUserDataProp DocCard (QUOTE SeenCards))))
	    (NC.SetUserDataProp Card (QUOTE SeenBefore)
				  T)

          (* * Step through list of notecard imageobjs in the card we're working on and either expand or copy or ignore each 
	  according to values of ExpandEmbeddedLinks and CopyEmbeddedLinks.)


	    (for Object in (TEDIT.LIST.OF.OBJECTS CardObj (FUNCTION NC.LinkIconImageObjP))
	       bind LinkSpec LinkLabel ToCard ToCardType (LastLoc ← 1)
		      (CurLoc ← 0)
		      ActiveP ExpandP CopyP AlreadyExpanded
	       eachtime (BLOCK)
	       do ((SETQ LinkSpec (NC.FetchLinkFromLinkIcon (CAR Object)))
		     (SETQ LinkLabel (fetch (Link Label) of LinkSpec))
		     (SETQ CurLoc (CADR Object))         (* Copy over any text between this obj and the last.)
		     (COND
		       ((ILESSP LastLoc CurLoc)
			 (TEDIT.COPY (TEDIT.SETSEL CardStream LastLoc (IDIFFERENCE CurLoc 
											 LastLoc))
				       (TEDIT.SETSEL DocStream (fetch TEXTLEN of DocObj)
						       1
						       (QUOTE RIGHT)))))
		     (SETQ LastLoc (ADD1 CurLoc))
		     (SETQ CopyP (OR (EQ CopyEmbeddedLinks (QUOTE ALL))
					 (AND (LISTP CopyEmbeddedLinks)
						(FMEMB LinkLabel CopyEmbeddedLinks))))
		     (SETQ ExpandP (OR (EQ ExpandEmbeddedLinks (QUOTE ALL))
					   (AND (LISTP ExpandEmbeddedLinks)
						  (FMEMB LinkLabel ExpandEmbeddedLinks))))
		     (COND
		       ((AND (SETQ AlreadyExpanded (NC.FetchUserDataProp (SETQ ToCard
										 (fetch
										   (Link 
										  DestinationCard)
										    of LinkSpec))
									       (QUOTE SeenBefore)))
			       ExpandP)
			 (NC.PrintMsg NIL NIL (NC.RetrieveTitle ToCard)
					" only expanded once in this cycle."
					(CHARACTER 13))))
		     (COND
		       ((OR CopyP (AND ExpandP AlreadyExpanded))
                                                             (* Copy this link.)
			 (TEDIT.COPY (TEDIT.SETSEL CardStream CurLoc 1)
				       (TEDIT.SETSEL DocStream (ADD1 (fetch TEXTLEN
									    of DocObj))
						       0
						       (QUOTE RIGHT)))))
		     (COND
		       ((AND ExpandP (NOT AlreadyExpanded))
                                                             (* Expand this link. Check type and make recursive 
							     call.)
			 (SETQ ActiveP (NC.ActiveCardP ToCard))
			 (SETQ ToCardType (NC.RetrieveType ToCard))
			 (COND
			   ((EQ ToCardType (QUOTE FileBox))
			     (OR ActiveP (NC.GetNoteCard ToCard))
			     (NC.DumpFileBoxToDoc ToCard DocCard DocStream
						    (COND
						      ((EQUAL SectionNum "")
							(CONCAT BoxNum))
						      (T (CONCAT SectionNum "." BoxNum)))
						    HeadingsFromFileboxes TitlesFromNoteCards 
						    BuildBackLinks CopyEmbeddedLinks 
						    ExpandEmbeddedLinks)
			     (SETQ BoxNum (ADD1 BoxNum))
			     (OR ActiveP (NC.DeactivateCard ToCard)))
			   (T (COND
				((NC.TEditBasedP ToCardType)
				  (OR ActiveP (NC.GetNoteCard ToCard))
				  (SETQ BoxNum
				    (NC.DumpNoteCardToDoc ToCard DocCard DocStream SectionNum 
							    BoxNum HeadingsFromFileboxes 
							    TitlesFromNoteCards BuildBackLinks 
							    CopyEmbeddedLinks ExpandEmbeddedLinks))
				  (OR ActiveP (NC.DeactivateCard ToCard)))
				((OR (NCP.SketchBasedP ToCardType)
				       (NCP.GraphBasedP ToCardType)
				       (GETPROP ToCardType (QUOTE ExportSubstanceFn)))
				  (OR ActiveP (NC.GetNoteCard ToCard))
				  (SETQ BoxNum
				    (NC.DumpExportableCardToDoc ToCard DocCard DocStream SectionNum 
								  BoxNum HeadingsFromFileboxes 
								  TitlesFromNoteCards BuildBackLinks 
								  CopyEmbeddedLinks 
								  ExpandEmbeddedLinks ToCardType))
				  (OR ActiveP (NC.DeactivateCard ToCard)))
				(T (NC.PrintMsg NIL NIL "Ignoring non-exportable card "
						  (NC.RetrieveTitle ToCard)
						  (CHARACTER 13)))))))))
	       finally (COND
			   ((ILESSP CurLoc (fetch TEXTLEN of CardObj))
			     (TEDIT.COPY (TEDIT.SETSEL CardStream LastLoc
							   (IDIFFERENCE (fetch TEXTLEN
									     of CardObj)
									  CurLoc))
					   (TEDIT.SETSEL DocStream (ADD1 (fetch TEXTLEN
										of DocObj))
							   0
							   (QUOTE RIGHT)))))
			 (TEDIT.SETSEL DocStream (ADD1 (fetch TEXTLEN of DocObj))
					 0
					 (QUOTE RIGHT)))
	    (NC.SetUserDataProp Card (QUOTE SeenBefore)
				  NIL)
	    (AND ShrunkenFlg (SHRINKW (NC.FetchWindow Card)))
	    (RETURN BoxNum))))

(NC.MakeDocument
  (LAMBDA (Card Title NoDisplayFlg CardIdentifier)           (* rht: "11-Aug-86 20:32")

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


    (PROG (RootCard RootTitle DocWindow DocCard DocWindowOrCard DocStream HeadingsFromFileboxes 
		      TitlesFromNoteCards BuildBackLinks CopyEmbeddedLinks ExpandEmbeddedLinks 
		      InspectWin WasActive RootType RootSubstanceType)
	    (OR NoDisplayFlg (SPAWN.MOUSE))
	    (SETQ DocWindowOrCard (NC.MakeNoteCard (QUOTE Text)
						       NoteFile "Document" NoDisplayFlg NIL Card))
	    (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 NIL 
			"Please select the Note Card or File Box the document should start from.")))
	    (if (NOT RootCard)
		then (NC.DeleteNoteCards Card 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)
		       (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)
			(OR (SETQ WasActive (NC.ActiveCardP RootCard))
			      (NC.GetNoteCard RootCard))
			(SETQ RootType (NC.RetrieveType RootCard))
			(if (EQ RootType (QUOTE FileBox))
			    then (NC.DumpFileBoxToDoc RootCard DocCard DocStream "" 
							  HeadingsFromFileboxes TitlesFromNoteCards 
							  BuildBackLinks CopyEmbeddedLinks 
							  ExpandEmbeddedLinks)
			  else (COND
				   ((NC.TEditBasedP RootType)
				     (NC.DumpNoteCardToDoc RootCard DocCard DocStream "" 1 
							     HeadingsFromFileboxes 
							     TitlesFromNoteCards BuildBackLinks 
							     CopyEmbeddedLinks ExpandEmbeddedLinks))
				   ((OR (NCP.SketchBasedP RootType)
					  (NCP.GraphBasedP RootType)
					  (GETPROP RootType (QUOTE ExportSubstanceFn)))
				     (NC.DumpExportableCardToDoc RootCard DocCard DocStream "" 1 
								   HeadingsFromFileboxes 
								   TitlesFromNoteCards BuildBackLinks 
								   CopyEmbeddedLinks 
								   ExpandEmbeddedLinks RootType))
				   (T (NC.PrintMsg NIL NIL 
						  "Can't make document from non-exportable card "
						     (NC.RetrieveTitle RootCard)
						     (CHARACTER 13)))))
			(OR WasActive (NC.DeactivateCard RootCard))
			(NC.PrintMsg DocWindow NIL "Done!"))
	    (COND
	      ((NOT NoDisplayFlg)
		(BLOCK 250)
		(NC.ClearMsg DocWindow T)))
	    (RETURN DocWindowOrCard))))

(NC.DumpFileBoxToDoc
  (LAMBDA (FileBoxCard DocCard DocStream CurSection HeadingsFromFileboxes TitlesFromNoteCards 
		       BuildBackLinks CopyEmbeddedLinks ExpandEmbeddedLinks)
                                                             (* rht: "11-Aug-86 20:35")

          (* * Dump the contents of FileboxID to DocStream by recursively dumping all of its children.
	  Keep track of the section numbers in case HeadingsFromFileboxes = Numbered. Insert back pointers to the source 
	  cards and/or boxes depending on value of BuildBackpointers. Embedded links (or some subset of them) may be copied 
	  or expanded depending on the values of CopyEmbeddedLinks and ExpandEmbeddedLinks.)



          (* * rht 8/25/85: Fixed to handle sketch and graph 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.)



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



          (* * rht 8/11/86: Added ShrunkenFlg so that FileBoxCard is reshrunk afterwards if necessary.)


    (PROG ((DocObject (TEXTOBJ DocStream))
	     ShrunkenFlg OldLoc)
	    (NC.AddCRIfNeeded DocStream)
	    (SETQ OldLoc (fetch (TEXTOBJ TEXTLEN) of DocObject))
	    (COND
	      ((AND (EQ HeadingsFromFileboxes (QUOTE NumberedBold))
		      (NOT (ZEROP (NCHARS CurSection))))
		(NC.AppendStringToStream DocStream (CONCAT CurSection " ")
					   T)))
	    (AND (NEQ HeadingsFromFileboxes (QUOTE NONE))
		   (NC.AppendStringToStream DocStream (CONCAT (NC.RetrieveTitle FileBoxCard))
					      T))
	    (AND (FMEMB BuildBackLinks (QUOTE (ToBoxes ToCardsBoxes)))
		   (NCP.LocalGlobalLink NC.DocBackPtrLinkLabel DocCard FileBoxCard (QUOTE END)
					  (QUOTE Icon)))
	    (COND
	      ((GREATERP (fetch (TEXTOBJ TEXTLEN) of DocObject)
			   OldLoc)
		(NC.AddCRIfNeeded DocStream)
		(NC.ChangeParaLeading DocStream)))
	    (COND
	      ((NC.FetchUserDataProp FileBoxCard (QUOTE SeenBefore))
		(NC.PrintMsg NIL NIL (NC.RetrieveTitle FileBoxCard)
			       " only expanded once in this cycle.")
		(RETURN)))
	    (SETQ ShrunkenFlg (NC.GetShrunkenWin FileBoxCard))
	    (NC.SetUserDataProp DocCard (QUOTE SeenCards)
				  (CONS FileBoxCard (NC.FetchUserDataProp DocCard (QUOTE 
											SeenCards))))
	    (NC.SetUserDataProp FileBoxCard (QUOTE SeenBefore)
				  T)
	    (for Link in (NC.FetchToLinksInOrder FileBoxCard) bind ChildCard ActiveP Type
									   (SubSectionNum ← 1)
	       eachtime (BLOCK) when (FMEMB (fetch (Link Label) of Link)
						    (BQUOTE (, NC.FiledCardLinkLabel , 
								 NC.SubBoxLinkLabel)))
	       do (SETQ ChildCard (fetch (Link DestinationCard) of Link))
		    (SETQ ActiveP (NC.ActiveCardP ChildCard))
		    (COND
		      ((EQ (SETQ Type (NC.RetrieveType ChildCard))
			     (QUOTE FileBox))
			(OR ActiveP (NC.GetNoteCard ChildCard))
			(NC.DumpFileBoxToDoc ChildCard DocCard DocStream
					       (COND
						 ((EQUAL "" CurSection)
						   (CONCAT SubSectionNum))
						 (T (CONCAT CurSection "." SubSectionNum)))
					       HeadingsFromFileboxes TitlesFromNoteCards 
					       BuildBackLinks CopyEmbeddedLinks ExpandEmbeddedLinks)
			(SETQ SubSectionNum (ADD1 SubSectionNum))
			(OR ActiveP (NC.DeactivateCard ChildCard)))
		      (T (COND
			   ((NC.TEditBasedP Type)
			     (OR ActiveP (NC.GetNoteCard ChildCard))
			     (SETQ SubSectionNum
			       (NC.DumpNoteCardToDoc ChildCard DocCard DocStream CurSection 
						       SubSectionNum HeadingsFromFileboxes 
						       TitlesFromNoteCards BuildBackLinks 
						       CopyEmbeddedLinks ExpandEmbeddedLinks))
			     (OR ActiveP (NC.DeactivateCard ChildCard)))
			   ((OR (NCP.SketchBasedP Type)
				  (NCP.GraphBasedP Type)
				  (GETPROP Type (QUOTE ExportSubstanceFn)))
			     (OR ActiveP (NC.GetNoteCard ChildCard))
			     (SETQ SubSectionNum
			       (NC.DumpExportableCardToDoc ChildCard DocCard DocStream CurSection 
							     SubSectionNum HeadingsFromFileboxes 
							     TitlesFromNoteCards BuildBackLinks 
							     CopyEmbeddedLinks ExpandEmbeddedLinks 
							     Type))
			     (OR ActiveP (NC.DeactivateCard ChildCard)))
			   (T (NC.PrintMsg NIL NIL "Ignoring non-exportable card " (
					       NC.RetrieveTitle ChildCard)
					     (CHARACTER 13)))))))
	    (NC.SetUserDataProp FileBoxCard (QUOTE SeenBefore)
				  NIL)
	    (AND ShrunkenFlg (SHRINKW (NC.FetchWindow FileBoxCard))))))

(NC.DumpExportableCardToDoc
  (LAMBDA (Card DocCard DocStream SectionNum BoxNum HeadingsFromFileboxes TitlesFromNoteCards 
		BuildBackLinks CopyEmbeddedLinks ExpandEmbeddedLinks CardType)
                                                             (* rht: "11-Aug-86 20:41")

          (* * Dump the CardID sketch or graph card to the document card DocStream.)



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



          (* * fgh 11/17/85 Updated to handle card objects and removal of SubstanceTypes.)



          (* * rht 7/31/86: Now can handle other card types than Graph or Sketch based ones, but they must have an 
	  appropriate fn on the ExportSubstanceFn property of the atom. That fn should return either an imageobj or a 
	  textstream.)



          (* * rht 8/11/86: Added ShrunkenFlg so that Card is reshrunk afterwards if necessary.)


    (PROG ((CardStream (NC.FetchSubstance Card))
	     (DocObj (TEXTOBJ DocStream))
	     ShrunkenFlg OldLoc ThingToInsert)
	    (NC.AddCRIfNeeded DocStream)
	    (SETQ OldLoc (fetch (TEXTOBJ TEXTLEN) of DocObj))
	    (AND (NEQ TitlesFromNoteCards (QUOTE NONE))
		   (NC.AppendStringToStream DocStream (CONCAT (NC.RetrieveTitle Card))
					      (EQ TitlesFromNoteCards (QUOTE Bold))))
	    (AND (FMEMB BuildBackLinks (QUOTE (ToCards ToCardsBoxes)))
		   (NCP.LocalGlobalLink NC.DocBackPtrLinkLabel DocCard Card (QUOTE END)
					  (create LINKDISPLAYMODE
						    ATTACHBITMAPFLG ← T)))
	    (COND
	      ((GREATERP (fetch (TEXTOBJ TEXTLEN) of DocObj)
			   OldLoc)
		(NC.AddCRIfNeeded DocStream)
		(NC.ChangeParaLeading DocStream)))
	    (COND
	      ((NC.FetchUserDataProp Card (QUOTE SeenBefore))
		(NC.PrintMsg NIL NIL (NC.RetrieveTitle Card)
			       " only expanded once in this cycle."
			       (CHARACTER 13))
		(RETURN)))
	    (SETQ ShrunkenFlg (NC.GetShrunkenWin Card))
	    (NC.SetUserDataProp DocCard (QUOTE SeenCards)
				  (CONS Card (NC.FetchUserDataProp DocCard (QUOTE SeenCards))))
	    (NC.SetUserDataProp Card (QUOTE SeenBefore)
				  T)

          (* * Stick an imageobj made from the card into the document. Also might be a textstream computed by the card type's
	  ExportSubstanceFn.)


	    (SETQ ThingToInsert (COND
		((NCP.GraphBasedP CardType)
		  (GRAPHEROBJ CardStream))
		((NCP.SketchBasedP CardType)
		  (MAKE.IMAGE.OBJECT.OF.SKETCH CardStream (NC.FetchRegionViewed Card)
						 (NC.FetchScale Card)))
		((LET ((ExportSubstanceFn (GETPROP CardType (QUOTE ExportSubstanceFn))))
		      (AND ExportSubstanceFn (APPLY* ExportSubstanceFn CardStream))))))
	    (AND CardStream (COND
		     ((IMAGEOBJP ThingToInsert)
		       (TEDIT.INSERT.OBJECT ThingToInsert DocStream))
		     ((TEXTSTREAMP ThingToInsert)
		       (TEDIT.INCLUDE DocStream ThingToInsert))))

          (* * Step through list of notecard imageobjs in the card we're working on and either expand or copy or ignore each 
	  according to values of ExpandEmbeddedLinks and CopyEmbeddedLinks.)


	    (for Link in (CAR (NC.CollectReferences Card NIL NIL NIL))
	       bind LinkLabel ToCard ToCardType ActiveFlg ExpandFlg CopyFlg AlreadyExpanded
	       eachtime (BLOCK)
	       do (SETQ LinkLabel (fetch (Link Label) of Link))
		    (SETQ CopyFlg (OR (EQ CopyEmbeddedLinks (QUOTE ALL))
					  (AND (LISTP CopyEmbeddedLinks)
						 (FMEMB LinkLabel CopyEmbeddedLinks))))
		    (SETQ ExpandFlg (OR (EQ ExpandEmbeddedLinks (QUOTE ALL))
					    (AND (LISTP ExpandEmbeddedLinks)
						   (FMEMB LinkLabel ExpandEmbeddedLinks))))
		    (COND
		      ((AND (SETQ AlreadyExpanded (NC.FetchUserDataProp (SETQ ToCard
										(fetch
										  (Link 
										  DestinationCard)
										   of Link))
									      (QUOTE SeenBefore)))
			      ExpandFlg)
			(NC.PrintMsg NIL NIL (NC.RetrieveTitle ToCard)
				       " only expanded once in this cycle."
				       (CHARACTER 13))))
		    (COND
		      ((OR CopyFlg (AND ExpandFlg AlreadyExpanded))
                                                             (* Copy this link.)
			(NCP.LocalGlobalLink LinkLabel DocCard ToCard (QUOTE END))))
		    (COND
		      ((AND ExpandFlg (NOT AlreadyExpanded))
                                                             (* Expand this link. Check type and make recursive 
							     call.)
			(SETQ ActiveFlg (NC.ActiveCardP ToCard))
			(SETQ ToCardType (NC.RetrieveType ToCard))
			(COND
			  ((EQ ToCardType (QUOTE FileBox))
			    (OR ActiveFlg (NC.GetNoteCard ToCard))
			    (NC.DumpFileBoxToDoc ToCard DocCard DocStream
						   (COND
						     ((EQUAL SectionNum "")
						       (CONCAT BoxNum))
						     (T (CONCAT SectionNum "." BoxNum)))
						   HeadingsFromFileboxes TitlesFromNoteCards 
						   BuildBackLinks CopyEmbeddedLinks 
						   ExpandEmbeddedLinks)
			    (SETQ BoxNum (ADD1 BoxNum))
			    (OR ActiveFlg (NC.DeactivateCard ToCard)))
			  (T (COND
			       ((NC.TEditBasedP ToCardType)
				 (OR ActiveFlg (NC.GetNoteCard ToCard))
				 (SETQ BoxNum
				   (NC.DumpNoteCardToDoc ToCard DocCard DocStream SectionNum BoxNum 
							   HeadingsFromFileboxes TitlesFromNoteCards 
							   BuildBackLinks CopyEmbeddedLinks 
							   ExpandEmbeddedLinks))
				 (OR ActiveFlg (NC.DeactivateCard DocCard)))
			       ((OR (NCP.SketchBasedP ToCardType)
				      (NCP.GraphBasedP ToCardType)
				      (GETPROP ToCardType (QUOTE ExportSubstanceFn)))
				 (OR ActiveFlg (NC.GetNoteCard ToCard))
				 (SETQ BoxNum
				   (NC.DumpExportableCardToDoc ToCard DocCard DocStream SectionNum 
								 BoxNum HeadingsFromFileboxes 
								 TitlesFromNoteCards BuildBackLinks 
								 CopyEmbeddedLinks 
								 ExpandEmbeddedLinks ToCardType))
				 (OR ActiveFlg (NC.DeactivateCard ToCard)))
			       (T (NC.PrintMsg NIL NIL "Ignoring non-exportable card "
						 (NC.RetrieveTitle ToCard)
						 (CHARACTER 13))))))))
	       finally (TEDIT.SETSEL DocStream (ADD1 (fetch TEXTLEN of DocObj))
					 0
					 (QUOTE RIGHT)))
	    (NC.SetUserDataProp Card (QUOTE SeenBefore)
				  NIL)
	    (AND ShrunkenFlg (SHRINKW (NC.FetchWindow Card)))
	    (RETURN BoxNum))))
)
(* * Change to NCFILEBOXCARD)

(DEFINEQ

(NC.FileBoxCollectChildren
  (LAMBDA (WindowOrTextStream Card NewChildren NoDisplayFlg)
                                                             (* rht: "12-Aug-86 00:23")

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


    (LET (Window ReturnVal OperationInProgress)
         (COND
	   (WindowOrTextStream (SETQ Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))))
         (OR Card (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 "Put Cards Here" 
								 OperationInProgress)
		      else (NC.ProtectedCardOperation Card Put% Cards% Here
							(OR NewChildren
							      (SETQ NewChildren
								(NC.SelectNoteCards NIL NIL 
								  NC.SelectingFileBoxChildrenMenu 
										      Card NIL 
								   " Please select new children.")))
							(COND
							  ((NULL (AND NewChildren Card
									  (for NewChild
									     in NewChildren
									     bind OneHook
									     when (
										 NC.MakeChildLink
										      NewChild Card 
										      Window)
									     do (SETQ OneHook T)
									     finally (RETURN
											 OneHook))))
							    (OR NoDisplayFlg (NC.PrintMsg
								    Window NIL 
						  "No appropriate NoteCards or FileBoxes chosen."
								    (CHARACTER 13)
								    "Hence no children added."
								    (CHARACTER 13)))
							    (SETQ ReturnVal NIL))
							  (T (SETQ ReturnVal Card)))
							(AND Window (GETPROMPTWINDOW Window NIL 
											 NIL T)
							       (PROG1 (DISMISS 1000)
									(NC.ClearMsg Window T))))))
     ReturnVal)))
)
(PUTPROPS RHTPATCH088 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1315 25799 (NC.LinkIconWhenDeletedFn 1325 . 5488) (NC.DelReferencesToCard 5490 . 7024) 
(NC.LinkIconWhenCopiedFn 7026 . 14695) (NC.LinkIconWhenMovedFn 14697 . 22340) (NC.AddToLink 22342 . 
23615) (NC.CachedAddToLink 23617 . 25797)) (25830 44532 (NC.DeleteNoteCard 25840 . 27760) (
NC.CloseAllPropListEditors 27762 . 28547) (NC.ClosePropListEditor 28549 . 31362) (
NC.OpenPropListEditor 31364 . 35446) (NC.PropListEditorOpenP 35448 . 36260) (NC.EditPropList 36262 . 
41928) (NC.ShowLinks 41930 . 44530)) (44570 69155 (NC.DumpNoteCardToDoc 44580 . 51454) (
NC.MakeDocument 51456 . 57483) (NC.DumpFileBoxToDoc 57485 . 62405) (NC.DumpExportableCardToDoc 62407
 . 69153)) (69192 71917 (NC.FileBoxCollectChildren 69202 . 71915)))))
STOP