(FILECREATED " 1-May-86 21:10:52" {QV}<NOTECARDS>1.3K>RHTPATCH039.;12 35827  

      changes to:  (VARS RHTPATCH039COMS)
		   (FNS NC.ResetNoteFileInterface NC.ForceDatabaseClose NC.MakeTEditPropsList 
			NC.DelReferencesToCardFromText NC.DeleteLinkIconSketchElement 
			NC.DelReferencesToCardFromGraph NC.DelReferencesToCardFromBrowser 
			NC.TextCardShrinkFn NC.DelTEditProcesses NC.GraphRemoveNode 
			NC.GraphDeleteLinkFn NC.BrowserRemoveNode NC.GraphDeleteNodeFn 
			NC.DelBrowserContentsLink)

      previous date: "30-Apr-86 11:23:48" {QV}<NOTECARDS>1.3K>RHTPATCH039.;1)


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

(PRETTYCOMPRINT RHTPATCH039COMS)

(RPAQQ RHTPATCH039COMS ((* * Add the GLOBALVAR NC.UseDeletedLinkIconIndicatorsFlg to each of 
			     NCTEXTCARD, NCSKETCHCARD, NCGRAPHCARD, NCBROWSERCARD)
			  (* * Add the GLOBALVARs NC.DelTEditProcessAtShrinkFlg and 
			     NC.UserSpecifiedTEditProps to NCTEXTCARD)
			  (* * Add the GLOBALVAR NC.NoteFileMenuLingerFlg to NCINTERFACE)
			  (* * New function for NCTEXTCARD)
			  (FNS NC.DelTEditProcesses)
			  (* * Changes to functions in NCTEXTCARD)
			  (FNS NC.DelReferencesToCardFromText NC.TextCardShrinkFn 
			       NC.MakeTEditPropsList)
			  (* * Changes to functions in NCLINKS)
			  (FNS NC.DeleteLinkIconSketchElement)
			  (* * Changes to functions in NCINTERFACE)
			  (FNS NC.SetupTitleBarMenu NC.ResetNoteFileInterface)
			  (* * Changes to functions in NCDATABASE)
			  (FNS NC.ForceDatabaseClose)
			  (* * Changes to functions in NCGRAPHCARD)
			  (FNS NC.DelReferencesToCardFromGraph NC.GraphDeleteNodeFn 
			       NC.GraphDeleteLinkFn)
			  (* * Changes to functions in NCBROWSERCARD)
			  (FNS NC.GraphRemoveNode NC.BrowserRemoveNode 
			       NC.DelReferencesToCardFromBrowser NC.DelBrowserContentsLink 
			       NC.ComputeBrowserSavedLinkingInfo NC.GetBrowserHashArray 
			       NC.BrowserCreateCard NC.BringUpBrowserCard)
			  (* * PLEASE MOVE THE FUNCTION NC.GraphRemoveNode FROM NCBROWSERCARD TO 
			     NCGRAPHCARD.)))
(* * Add the GLOBALVAR NC.UseDeletedLinkIconIndicatorsFlg to each of NCTEXTCARD, NCSKETCHCARD,
 NCGRAPHCARD, NCBROWSERCARD)

(* * Add the GLOBALVARs NC.DelTEditProcessAtShrinkFlg and NC.UserSpecifiedTEditProps to 
NCTEXTCARD)

(* * Add the GLOBALVAR NC.NoteFileMenuLingerFlg to NCINTERFACE)

(* * New function for NCTEXTCARD)

(DEFINEQ

(NC.DelTEditProcesses
  (LAMBDA (Window)                                           (* rht: "30-Apr-86 20:13")

          (* * Kill any TEdit processes running on Window and its attached windows. Notice recursive call to handle attached 
	  windows of attached windows.)


    (LET (Process)
         (if (PROCESSP (SETQ Process (WINDOWPROP Window (QUOTE PROCESS))))
	     then (DEL.PROCESS Process))
         (for AttachedWin in (ATTACHEDWINDOWS Window) do (NC.DelTEditProcesses AttachedWin))
      )))
)
(* * Changes to functions in NCTEXTCARD)

(DEFINEQ

(NC.DelReferencesToCardFromText
  (LAMBDA (SourceCard LinkOrDestinationCard)                 (* rht: " 1-May-86 17:25")
                                                             (* Delete all IMAGEOBJECTS in textstream specified by 
							     Substance that are Link Icons whose DESTINATIONID is 
							     eq to Destination ID)

          (* * rht 9/12/85: Fixed so restores old selection after putting in deleted link icon.)



          (* * kirk: 14Nov85: changed EQs to NC.Sames. Deleted use of LinkID.)



          (* * rht 4/30/86: Now only inserts NC.DeletedLinkImageObject if NC.UseDeletedLinkIconIndicators is non-nil.)


    (LET ((LinkFlg (type? Link LinkOrDestinationCard))
	  DestinationCard Substance)
         (COND
	   (LinkFlg (OR (NC.CardP SourceCard)
			  (SETQ SourceCard (fetch (Link SourceCard) of LinkOrDestinationCard))))
	   (T (SETQ DestinationCard LinkOrDestinationCard)))
         (SETQ Substance (NC.FetchSubstance SourceCard))
         (for Link in (TEDIT.LIST.OF.OBJECTS (TEXTOBJ Substance)
						   (FUNCTION NC.LinkIconImageObjP))
	    bind OldSel when (COND
				   (LinkFlg (NC.SameLinkP LinkOrDestinationCard
							    (NC.FetchLinkFromLinkIcon (CAR Link)))
					    )
				   (T (NC.SameCardP DestinationCard (fetch (Link DestinationCard)
									 of (
									 NC.FetchLinkFromLinkIcon
										(CAR Link))))))
	    do (replace (IMAGEOBJ IMAGEOBJFNS) of (CAR Link) with NC.NoDeleteImageFns) 
                                                             (* WHENDELETEDFN taken care of earlier in delete 
							     cycle)
		 (SETQ OldSel (TEDIT.GETSEL Substance))
		 (TEDIT.DELETE Substance (CADR Link)
				 1)
		 (AND NC.UseDeletedLinkIconIndicatorsFlg (TEDIT.INSERT.OBJECT 
									NC.DeletedLinkImageObject 
										  Substance
										  (CADR Link)))
		 (TEDIT.SETSEL Substance OldSel)))))

(NC.TextCardShrinkFn
  (LAMBDA (W)                                                (* rht: "30-Apr-86 20:06")

          (* * This is in order to get the right title on the TEdit icon. This is a kludgy finesse around TEdit's shrunken 
	  icon title facility.)



          (* * rht 4/30/86: Now optionally kills TEdit process at shrink time.)


    (LET ((OldIconTitle (WINDOWPROP W (QUOTE NoteCardsIconTitle)))
	  (Icon (WINDOWPROP W (QUOTE ICON)))
	  (Card (NC.CoerceToCard W))
	  IconTitle)
         (if (NULL Icon)
	     then (APPLY* (WINDOWPROP W (QUOTE ICONFN))
			      W)
		    (SETQ Icon (WINDOWPROP W (QUOTE ICON))))
         (if (NOT (EQUAL OldIconTitle (SETQ IconTitle (CONCAT "NC: " (NC.RetrieveTitle
									  Card)))))
	     then (ICONTITLE IconTitle NIL NIL Icon)
		    (WINDOWPROP W (QUOTE NoteCardsIconTitle)
				  IconTitle))
         (if NC.DelTEditProcessAtShrinkFlg
	     then (NC.DelTEditProcesses W)))))

(NC.MakeTEditPropsList
  (LAMBDA (TEditWindow)                                      (* rht: " 1-May-86 20:43")

          (* * Create the props list to hand to all TEdit and OPENTEXTSTREAM calls)



          (* * rht 9/10/85: Now takes a TEditWindow arg so can compute a prompt window.)



          (* * 5/1/86: Now appends NC-specific props in front of TEdit props specified as global param by user.)


    (APPEND (LIST (QUOTE FONT)
		      NC.DefaultFont
		      (QUOTE TITLEMENUFN)
		      (FUNCTION NC.TEditMenuFn)
		      (QUOTE PUTFN)
		      (FUNCTION NC.TEditPutFn)
		      (QUOTE GETFN)
		      (FUNCTION NC.TEditGetFn)
		      (QUOTE QUITFN)
		      (LIST (FUNCTION NC.QuitCard)
			      (FUNCTION (LAMBDA NIL
				  (QUOTE DON'T))))
		      (QUOTE PROMPTWINDOW)
		      (AND TEditWindow (NC.GetPromptWindow TEditWindow)))
	      NC.UserSpecifiedTEditProps)))
)
(* * Changes to functions in NCLINKS)

(DEFINEQ

(NC.DeleteLinkIconSketchElement
  (LAMBDA (SketchElement CardID)                             (* rht: " 1-May-86 17:25")

          (* * This replaces the link icon for SketchElement from SketchWin with deleted link icon.)



          (* * rht 4/30/86: Changed to simply delete the link icon if NC.UseDeletedLinkIconIndicators is NIL)


    (LET ((Position (SKETCH.POSITION.OF.ELEMENT SketchElement))
	  (SketchSubstance (NC.FetchSubstance CardID))
	  (LinkIcon (SKETCH.IMAGEOBJ.OF.ELEMENT SketchElement))
	  (Window (NC.FetchWindow CardID))
	  Scale)
         (if NC.UseDeletedLinkIconIndicatorsFlg
	     then (SETQ Scale (if Window
				      then (SKETCHW.SCALE Window)
				    else (NC.FetchScale CardID)))
		    (create IMAGEOBJ smashing LinkIcon OBJECTDATUM ←(IMAGEOBJPROP 
									NC.DeletedLinkImageObject
											(QUOTE
											  OBJECTDATUM)
											)
						  IMAGEOBJFNS ← NC.DeletedLinkImageFns)
		    (AND Window (SKETCH.ELEMENT.CHANGED SketchSubstance SketchElement Window))
	   else (SKETCH.DELETE.ELEMENT SketchElement SketchSubstance T)))))
)
(* * Changes to functions in NCINTERFACE)

(DEFINEQ

(NC.SetupTitleBarMenu
  (LAMBDA (Window Card NoteCardType)                         (* rht: " 7-Apr-86 18:54")
                                                             (* Setup the title bar menu for the window Window 
							     pertaining to Card specified by ID)

          (* * rht 1/3/85: Now takes optional NoteCardType arg in case need to override the ID's type.
	  Like when ID is of type that inherits from Browser. Also changed "pointer" to "link" everywhere.)



          (* * rht 1/12/85: Added menu for StructEdit type. Just the same except has no InsertLink operation.
	  This needs to be cleaned up and interfaced to Types mechanism.)



          (* * rht 1/15/85: Added "Relayout" item to the browser title bar middle button menu, and made graph and structedit 
	  cards contain only that item on their middle button menus.)



          (* * rht 5/22/85: Took out structedit and structeditbrowser junk.)



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



          (* * rht 4/7/86: Now finds menu items on card type's slots.)


    (OR NoteCardType (SETQ NoteCardType (NC.RetrieveType Card)))
    (OR (EQ (WINDOWPROP Window (QUOTE BUTTONEVENTFN))
		(FUNCTION NC.TitleBarButtonEventFn))
	  (WINDOWPROP Window (QUOTE OLDBUTTONEVENTFN)
			(WINDOWPROP Window (QUOTE BUTTONEVENTFN)
				      (FUNCTION NC.TitleBarButtonEventFn))))
    (WINDOWPROP Window (QUOTE TitleBarLeftButtonMenu)
		  (create MENU
			    ITEMS ←(NC.GetCardTypeField LeftButtonMenuItems NoteCardType)
			    CENTERFLG ← T
			    MENUFONT ←(FONTCREATE (QUOTE HELVETICA)
						    10
						    (QUOTE BOLD))))
    (WINDOWPROP Window (QUOTE TitleBarMiddleButtonMenu)
		  (create MENU
			    ITEMS ←(NC.GetCardTypeField MiddleButtonMenuItems NoteCardType)
			    CENTERFLG ← T
			    MENUFONT ←(FONTCREATE (QUOTE HELVETICA)
						    10
						    (QUOTE BOLD))))))

(NC.ResetNoteFileInterface
  (LAMBDA (NoteFile)                                         (* rht: " 1-May-86 20:53")

          (* * Close up the control menu for a NoteFile)



          (* * rht 5/1/86: Now does nothing if NC.NoteFileMenuLingerFlg is non-nil.)


    (OR NC.NoteFileMenuLingerFlg (LET ((Menu (fetch (NoteFile Menu) of NoteFile))
					 Window)
				        (COND
					  (Menu (SETQ Window (WFROMMENU Menu))
						(WINDOWPROP Window (QUOTE NoteFile)
							      NIL)
						(replace (NoteFile Menu) of NoteFile
						   with NIL)
						(WINDOWPROP Window (QUOTE CLOSEFN)
							      NIL)
						(DELETEMENU Menu T)))))))
)
(* * Changes to functions in NCDATABASE)

(DEFINEQ

(NC.ForceDatabaseClose
  (LAMBDA (NoteFile Don'tMenuFlg)                            (* rht: " 1-May-86 21:05")

          (* * Really close the database, i.e.. bypass the ADVISE on CLOSEF that prevents closing of the database.)



          (* * rht 1/10/85: Note new kludgey call to \UPDATEOF recommended by Tayloe to avoid truncation problems.)



          (* * rht 2/5/85: Added resetting of NC.UncachingNotCompleted here so it will happen after compact, repair, etc.)



          (* * rht 7/9/85: Added resetting of NC.LinkLabelsDate.)



          (* * rht 11/10/85: Updated to incorporate new NoteFile scheme.)



          (* * kirk 31Dec85: added Don'tMenuFlg)



          (* * rht 1/8/86: Now smashes old notefile object to remove cycles. Don't you love interlisp gc'er?)



          (* * rht 5/1/86: Save Menu on notefile object when smashing.)


    (CLOSEF (fetch (NoteFile Stream) of NoteFile))     (* Smash the cardcache and userdata fields of all card
							     objects for this notefile to remove circular links.)
    (ADD.PROCESS (LIST (FUNCTION NC.CleanupCardObjects)
			   (fetch (NoteFile HashArray) of NoteFile)))
    (replace (NoteFile Stream) of NoteFile with NIL)   (* Smash the notefile object so we don't have cycles -
							     card -> notefile -> card.)
    (create NoteFile smashing NoteFile UID ←(fetch (NoteFile UID) of NoteFile)
				  FullFileName ←(fetch (NoteFile FullFileName) of NoteFile)
				  Menu ←(fetch (NoteFile Menu) of NoteFile))
                                                             (* Usually we leave shell in notefiles hash array so 
							     there's a record.)
    (if Don'tMenuFlg
	then (NC.RemoveNoteFile NoteFile))
    NoteFile))
)
(* * Changes to functions in NCGRAPHCARD)

(DEFINEQ

(NC.DelReferencesToCardFromGraph
  (LAMBDA (SourceCard LinkOrDestinationCard)                 (* rht: " 1-May-86 17:25")
                                                             (* Delete from the graph specified by Graph all link 
							     icon nodes whose DESTINATIONID is eq to DestinationID)

          (* * rht 11/17/84: Now only redisplays graph if ID is both active *and* has a window.)



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



          (* * rht 4/30/86: Now uses value of NC.UseDeletedLinkIconIndicators to determine whether to delete node or replace 
	  with Deleted indicator.)


    (LET ((ImageBox (NC.DeletedLinkImageBoxFn NC.DeletedLinkImageObject))
	  LinkIcon
	  (LinkFlg (type? Link LinkOrDestinationCard))
	  DestinationCard Graph)
         (COND
	   (LinkFlg (OR (NC.CardP SourceCard)
			  (SETQ SourceCard (fetch (Link SourceCard) of LinkOrDestinationCard))))
	   (T (SETQ DestinationCard LinkOrDestinationCard)))
         (SETQ Graph (NC.FetchSubstance SourceCard))
         (for GraphNode in (fetch (GRAPH GRAPHNODES) of Graph)
	    when (AND (NC.LinkIconImageObjP (SETQ LinkIcon (fetch (GRAPHNODE NODELABEL)
								      of GraphNode)))
			  (COND
			    (LinkFlg (NC.SameLinkP LinkOrDestinationCard (NC.FetchLinkFromLinkIcon
						       LinkIcon)))
			    (T (NC.SameCardP (fetch (Link DestinationCard) of (
									 NC.FetchLinkFromLinkIcon
										      LinkIcon))
					       DestinationCard))))
	    do (if NC.UseDeletedLinkIconIndicatorsFlg
		     then (replace (GRAPHNODE NODELABEL) of GraphNode with 
									NC.DeletedLinkImageObject)
			    (replace (GRAPHNODE NODEWIDTH) of GraphNode
			       with (fetch (IMAGEBOX XSIZE) of ImageBox))
			    (replace (GRAPHNODE NODEHEIGHT) of GraphNode
			       with (fetch (IMAGEBOX YSIZE) of ImageBox))
		   else (NC.GraphRemoveNode GraphNode Graph (NC.FetchWindow SourceCard)
						T)))
         (COND
	   ((AND (NC.ActiveCardP SourceCard)
		   (NC.FetchWindow SourceCard))
	     (REDISPLAYGRAPH (NC.FetchWindow SourceCard)))))))

(NC.GraphDeleteNodeFn
  (LAMBDA (Node Graph Window)                                (* rht: "30-Apr-86 12:46")

          (* * Just mark the card as dirty.)



          (* * rht 4/30/86: Now makes sure there's a window first.)


    (AND Window (NC.MarkCardDirty (NC.CoerceToCard Window)))))

(NC.GraphDeleteLinkFn
  (LAMBDA (From To Graph Window)                             (* rht: "30-Apr-86 15:04")

          (* * Just mark the card as dirty.)



          (* * rht 4/30/86: Now makes sure there's a window first.)


    (AND Window (NC.MarkCardDirty (NC.CoerceToCard Window)))))
)
(* * Changes to functions in NCBROWSERCARD)

(DEFINEQ

(NC.GraphRemoveNode
  (LAMBDA (Node Graph Window QuietFlg)                       (* rht: "30-Apr-86 16:19")

          (* * Remove this node from the graph. This code taken from Grapher's EDITDELETENODE)



          (* * rht 4/30/86: Added QuietFlg and other minor fixes.)


    (for ToNode in (TOLINKS Node) bind OtherNode
       do                                                  (* Undisplay links.)
	    (SETQ OtherNode (GETNODEFROMID (if (EQ (CAR ToNode)
							   LINKPARAMS)
						   then (CADR ToNode)
						 else ToNode)
					       (fetch (GRAPH GRAPHNODES) of Graph)))
	    (AND Window (NC.DisplayGraphLinksBetween Node OtherNode Window Graph))
	    (GRAPHDELETELINK Node OtherNode Graph Window))
    (for FromNode in (FROMLINKS Node) bind OtherNode
       do                                                  (* Undisplay links.)
	    (SETQ OtherNode (GETNODEFROMID (if (EQ (CAR FromNode)
							   LINKPARAMS)
						   then (CADR FromNode)
						 else FromNode)
					       (fetch (GRAPH GRAPHNODES) of Graph)))
	    (AND Window (NC.DisplayGraphLinksBetween OtherNode Node Window Graph))
	    (GRAPHDELETELINK OtherNode Node Graph Window))
    (AND Window (DISPLAYNODE Node (CONSTANT (create POSITION
							    XCOORD ← 0
							    YCOORD ← 0))
				 Window Graph))
    (GRAPHDELETENODE Node Graph Window)
    (OR QuietFlg (NC.PrintMsg NIL T "Node " (fetch (GRAPHNODE NODELABEL) of Node)
				  " removed."))
    Node))

(NC.BrowserRemoveNode
  (LAMBDA (Graph Window DeleteCardFlg NodeToRemove QuietFlg)
                                                             (* rht: "30-Apr-86 15:46")

          (* * Called by grapher when user removes a node.)



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



          (* * rht 2/7/86: Changed to use NC.SetBrowserRoots instead of NC.PutProp)



          (* * rht 4/30/86: Now takes optional NodeToRemove and QuietFlg argument.)


    (PROG ((GraphCard (NC.CoerceToCard Window))
	     Card NodeToRemoveID RootCards NodesToRemove NumVirtuals)
	    (OR NodeToRemove (SETQ NodeToRemove (NC.SelectGraphNode Window Graph
									  (if DeleteCardFlg
									      then 
								 "Choose node of card to delete."
									    else 
									 "Choose node to remove."))))
	    (SETQ NodeToRemoveID (NC.CoerceToGraphNodeIDOrLabel NodeToRemove))
	    (SETQ Card (NC.CardFromBrowserNodeID NodeToRemoveID))
                                                             (* If we're supposed to be deleting a card, then check
							     that node represents a card and that user confirms.)
	    (if DeleteCardFlg
		then (if (NC.ValidCardP Card)
			   then (if (NOT (NC.AskYesOrNo (CONCAT "Want to delete the "
									  (NC.RetrieveTitle Card)
									  " card? ")
								"--"
								(QUOTE Yes)
								T Window NIL NIL))
				      then (FLIPNODE NodeToRemove Window)
					     (RETURN (NC.PrintMsg NIL T 
								    "Card & Node delete aborted.")))
			 else (NC.PrintMsg NIL T "No card for that node.")
				(FLASHW PROMPTWINDOW)
				(FLIPNODE NodeToRemove Window)
				(RETURN NIL)))
	    (AND (NC.ValidCardP GraphCard)
		   (NC.MarkCardDirty GraphCard))

          (* We require that all virtual nodes for this node must be removed at once if this one has any link edges to or 
	  from it.)


	    (SETQ NodesToRemove (for Node in (fetch (GRAPH GRAPHNODES) of Graph)
				     when (EQ NodeToRemoveID (NC.CoerceToGraphNodeIDOrLabel
						    Node))
				     collect Node))        (* If there are no edges into or out of this node, 
							     then just delete from graph.)
	    (if (AND (NOT DeleteCardFlg)
			 (NULL (fetch (GRAPHNODE FROMNODES) of NodeToRemove))
			 (NULL (fetch (GRAPHNODE TONODES) of NodeToRemove)))
		then (FLIPNODE NodeToRemove Window)      (* Delete the browsercontents link from the browser.)
		       (if (AND (NC.ValidCardP Card)
				    (NC.ValidCardP GraphCard))
			   then (NC.DelBrowserContentsLink GraphCard Card) 
                                                             (* Remove entry for this node from browser hash 
							     array.)
				  (NC.RemoveBrowserNodeHashArrayEntry GraphCard Card))
		       (RETURN (NC.GraphRemoveNode NodeToRemove Graph Window)))
                                                             (* If there are companion virtual nodes, ask for user 
							     confirmation.)
	    (if (AND (NOT DeleteCardFlg)
			 (GREATERP (SETQ NumVirtuals (LENGTH NodesToRemove))
				     1)
			 (NOT (PROGN (NC.PrintMsg Window T NumVirtuals 
						      " virtual companion nodes will be removed."
							(CHARACTER 13))
					 (NC.YesP (NC.AskUser "Still want to remove? " "--"
								  (QUOTE Yes)
								  NIL Window NIL NIL T)))))
		then (FLIPNODE NodeToRemove Window)
		       (RETURN NIL))                       (* Delete the browsercontents link from the browser.)
	    (AND (NC.ValidCardP Card)
		   (NC.ValidCardP GraphCard)
		   (NC.DelBrowserContentsLink GraphCard Card))
                                                             (* Delete all record of links to and from this node on
							     prop lists.)
	    (NC.SmashGraphNodeIDProps NodeToRemoveID)
	    (for Node in (fetch (GRAPH GRAPHNODES) of Graph) eachtime (BLOCK)
	       bind UID when (type? UID (SETQ UID (NC.CoerceToGraphNodeID Node)))
	       do (NC.UIDRemProp UID NodeToRemoveID))
	    (if (AND (NC.ValidCardP Card)
			 (NC.ValidCardP GraphCard))
		then                                       (* Remove from the root ids list.)
		       (SETQ RootCards (NC.FetchBrowserRoots GraphCard))
		       (if (for RootCard in RootCards eachtime (BLOCK)
				thereis (NC.SameCardP Card RootCard))
			   then (NC.SetBrowserRoots GraphCard (for RootCard in RootCards
								     eachtime (BLOCK)
								     unless (NC.SameCardP Card 
											 RootCard)
								     collect RootCard)))
                                                             (* Remove entry for this node from browser hash 
							     array.)
		       (NC.RemoveBrowserNodeHashArrayEntry GraphCard Card))
                                                             (* Get rid of node and its virtual buddies from 
							     graph.)
	    (AND Window (FLIPNODE NodeToRemove Window))
	    (for Node in NodesToRemove do (NC.GraphRemoveNode Node Graph Window))
                                                             (* Delete card if we're supposed to.)
	    (if DeleteCardFlg
		then (NC.PrintMsg NIL T "Deleting " Card " ... ")
		       (NC.DeleteNoteCards Card T)
		       (NC.PrintMsg NIL T "Done." (CHARACTER 13)))
	    (AND Window (REDISPLAYW Window))
	    (OR QuietFlg (NC.PrintMsg NIL T "Nodes: " (CONCATLIST
					    (for Node in NodesToRemove
					       collect (PACK* (fetch (GRAPHNODE NODEID)
								     of Node)
								  (QUOTE % ))))
					  "removed.")))))

(NC.DelReferencesToCardFromBrowser
  (LAMBDA (SourceCard LinkOrDestinationCard)                 (* rht: " 1-May-86 17:25")

          (* * Delete from the browser specified by SourceCard all link icon nodes whose DESTINATIONID is eq to 
	  DestinationID. This just checks the case of the SourceCard being a browser root and then passes off to GRAPHCARD's 
	  DelReferencesFn.)



          (* * rht 4/30/86: No longer passes control up to Super's DeleteLinksFn. Work is now done here.)


    (LET ((LinkFlg (type? Link LinkOrDestinationCard))
	  (ImageBox (NC.DeletedLinkImageBoxFn NC.DeletedLinkImageObject))
	  LinkIcon Graph DestinationCard BrowserRoots)
         (if LinkFlg
	     then (OR (NC.CardP SourceCard)
			  (SETQ SourceCard (fetch (Link SourceCard) of LinkOrDestinationCard)))
		    (SETQ DestinationCard (fetch (Link DestinationCard) of 
									    LinkOrDestinationCard))
	   else (SETQ DestinationCard LinkOrDestinationCard))
         (if (SETQ RootCardToDelete (for RootCard in (SETQ BrowserRoots (
								 NC.FetchBrowserRoots SourceCard))
					   eachtime (BLOCK) do (if (NC.SameCardP 
										  DestinationCard 
											 RootCard)
									 then (RETURN RootCard))))
	     then (NC.SetBrowserRoots SourceCard (DREMOVE RootCardToDelete BrowserRoots)))
         (SETQ Graph (NC.FetchSubstance SourceCard))
         (for GraphNode in (fetch (GRAPH GRAPHNODES) of Graph)
	    when (AND (NC.LinkIconImageObjP (SETQ LinkIcon (fetch (GRAPHNODE NODELABEL)
								      of GraphNode)))
			  (COND
			    (LinkFlg (NC.SameLinkP LinkOrDestinationCard (NC.FetchLinkFromLinkIcon
						       LinkIcon)))
			    (T (NC.SameCardP (fetch (Link DestinationCard) of (
									 NC.FetchLinkFromLinkIcon
										      LinkIcon))
					       DestinationCard))))
	    do (if NC.UseDeletedLinkIconIndicatorsFlg
		     then (replace (GRAPHNODE NODELABEL) of GraphNode with 
									NC.DeletedLinkImageObject)
			    (replace (GRAPHNODE NODEWIDTH) of GraphNode
			       with (fetch (IMAGEBOX XSIZE) of ImageBox))
			    (replace (GRAPHNODE NODEHEIGHT) of GraphNode
			       with (fetch (IMAGEBOX YSIZE) of ImageBox))
		   else (NC.BrowserRemoveNode Graph (NC.FetchWindow SourceCard)
						  NIL GraphNode T)))
         (COND
	   ((AND (NC.ActiveCardP SourceCard)
		   (NC.FetchWindow SourceCard))
	     (REDISPLAYGRAPH (NC.FetchWindow SourceCard)))))))

(NC.DelBrowserContentsLink
  (LAMBDA (GraphCard DestCard)                               (* rht: "30-Apr-86 12:36")

          (* * Delete the browsercontents link connecting GraphCard and DestID.)



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



          (* * rht 4/30/86: Now checks to make sure there's a link to delete.)


    (LET ((Links (NCP.GetLinks GraphCard DestCard NC.BrowserContentsLinkLabel)))
         (if (CDR Links)
	     then (NC.ReportError "NC.DelBrowserContentsLink" (CONCAT 
						       "Multiple browser contents links between "
									    (NC.FetchTitle 
											GraphCard)
									    " and "
									    (NC.FetchTitle DestCard)
									    ))
		    (RETURN NIL))
         (AND Links (NC.DeleteLink (CAR Links)
				       NIL T)))))

(NC.ComputeBrowserSavedLinkingInfo
  (LAMBDA (Card)                                             (* rht: "30-Apr-86 15:30")

          (* * Search the graph nodeIDs of Card's substance for special linking info for multiple links between same pair of 
	  nodes.)


    (for GraphNode in (fetch (GRAPH GRAPHNODES) of (NC.FetchSubstance Card))
       bind SavedLinkingInfoForNode UID eachtime (BLOCK)
       when (AND (type? UID (SETQ UID (fetch (GRAPHNODE NODEID) of GraphNode)))
		     (SETQ SavedLinkingInfoForNode (NC.ComputeBrowserSavedLinkingInfoForNode
			 UID)))
       collect (CONS UID SavedLinkingInfoForNode))))

(NC.GetBrowserHashArray
  (LAMBDA (BrowserCard Graph)                                (* rht: "30-Apr-86 15:33")

          (* * Build and install a hash array mapping cards to browsernode UIDs, unless one's already there.
	  If Graph argument is nil, then make a new hash array smashing any existin one.)



          (* * rht 4/30/86: Now makes sure we're not working with a label node instead of a card node.)


    (if (AND Graph (NC.HashArrayFromBrowserCard BrowserCard))
      else (LET ((HashArray (HASHARRAY NC.BrowserHashArraySize)))
	          (NC.SetUserDataProp BrowserCard (QUOTE BrowserHashArray)
					HashArray)
	          (AND Graph (for GraphNode in (fetch (GRAPH GRAPHNODES) of Graph)
				  bind GraphNodeID eachtime (BLOCK) when (SETQ GraphNodeID
										   (
									   NC.CoerceToGraphNodeID
										     GraphNode))
				  do (PUTHASH (NC.UIDGetProp GraphNodeID (QUOTE CardObject))
						  GraphNodeID HashArray)))))))

(NC.BrowserCreateCard
  (LAMBDA (Graph Window)                                     (* rht: "30-Apr-86 15:37")

          (* * Called from grapher ADDNODE fn. Used to create a new card and corresponding browser node.)



          (* * Rht 11/17/85: updated for new card and notefile objects.)



          (* * rht 4/30/86: Now only computes title if got a link.)


    (PROG ((GraphCard (NC.CoerceToCard Window))
	     Link GraphNodeID Card Title)
	    (SETQ Link (NC.MakeLink Window NC.BrowserContentsLinkLabel (QUOTE *New% Card*)
					GraphCard NIL NIL NIL T))
	    (if Link
		then (SETQ Title (NC.RetrieveTitle (SETQ Card (fetch (Link DestinationCard)
									 of Link))))
		       (NC.SetTitle Card (OR (NC.AskUser "Title of new card: " NIL
							       (if (STREQUAL "Untitled" Title)
								   then NIL
								 else Title)
							       T Window)
						 "Untitled"))
                                                             (* Create hash array if haven't already.)
		       (NC.GetBrowserHashArray GraphCard Graph)
		       (SETQ GraphNodeID (NC.GetBrowserNodeID GraphCard Card))
		       (NC.MarkCardDirty GraphCard)
		       (RETURN (NODECREATE GraphNodeID (NC.MakeLinkIcon Link)
					       (CURSORPOSITION NIL Window)))
	      else (RETURN NIL)))))

(NC.BringUpBrowserCard
  (LAMBDA (Card Substance Region/Position)                   (* rht: "30-Apr-86 16:29")

          (* * Given a browser Substance, open a browser window and set it up to be a NoteCard with ID.)



          (* * rht 11/17/84: Now returns window.)



          (* * rht 9/11/85: Now checks for changed link icon display global params.)



          (* * rht 11/17/85: Now handles new card and Notefile objects.)



          (* * rht 2/1/86: Now restores any saved UID user data info stashed on card's prop list.)



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



          (* * rht 2/14/86: Now rebuilds browser hash array.)



          (* * rht 2/28/86: Added WINDOWPROP for SCROLLFN and RESHAPEFN.)



          (* * rht 3/2/86: Took out call to NC.FetchBrowserHashArray.)



          (* * rht 4/5/86: Now only replaces graphnodes' TONODES' NODEID and DESTNODEID if they're non-nil.)


    (LET ((GraphNodes (fetch (GRAPH GRAPHNODES) of Substance))
	  Window OldUIDToNewUIDHashArray BrowserSavedLinkingInfo)

          (* * Restore any saved UID user data info stashed on card UID's prop list.)


         (if (SETQ BrowserSavedLinkingInfo (NC.FetchBrowserSavedLinkingInfo Card))
	     then (SETQ OldUIDToNewUIDHashArray (HASHARRAY 100 NIL (FUNCTION NC.MakeHashKey)
								 (FUNCTION NC.SameUIDP)))
		    (for BrowserSavedLinkingInfoForNode in BrowserSavedLinkingInfo
		       eachtime (BLOCK) bind SourceUID when (SETQ SourceUID
								      (
								   NC.NewBrowserNodeUIDFromOldUID
									(CAR 
								   BrowserSavedLinkingInfoForNode)
									GraphNodes 
									OldUIDToNewUIDHashArray))
		       do (for SavedLinkingInfo on (CDR BrowserSavedLinkingInfoForNode)
			       by (CDDR SavedLinkingInfo) eachtime (BLOCK)
			       do (NC.UIDPutProp SourceUID (NC.NewBrowserNodeUIDFromOldUID
						       (CAR SavedLinkingInfo)
						       GraphNodes OldUIDToNewUIDHashArray)
						     (CADR SavedLinkingInfo)))))
         (NC.SetBrowserSavedLinkingInfo Card NIL)

          (* * For each graph node corresponding to a notecard, hang the card object off the node id's prop list.)


         (for GraphNode in GraphNodes bind LinkIcon DestCard eachtime (BLOCK)
	    when (NC.LinkIconImageObjP (SETQ LinkIcon (fetch (GRAPHNODE NODELABEL)
							       of GraphNode)))
	    do (NC.UIDPutProp (NC.CoerceToGraphNodeID GraphNode)
				  (QUOTE CardObject)
				  (SETQ DestCard (fetch (Link DestinationCard)
						      of (NC.FetchLinkFromLinkIcon LinkIcon)))))

          (* * Make a new browser hash array with the new graph node UIDs.)


         (NC.SetUserDataProp Card (QUOTE BrowserHashArray)
			       NIL)
         (NC.GetBrowserHashArray Card Substance)

          (* * For each graph node, fix the NODEID and DESTNODEID fields of each of its TONODES LinkParameters.)


         (for GraphNode in GraphNodes eachtime (BLOCK)
	    do (for ToNode in (fetch (GRAPHNODE TONODES) of GraphNode)
		    bind (ThisNodeID ←(NC.CoerceToGraphNodeID GraphNode)) eachtime (BLOCK)
		    when (EQ (CAR ToNode)
				 LINKPARAMS)
		    do (AND (LISTGET ToNode (QUOTE NODEID))
				(LISTPUT ToNode (QUOTE NODEID)
					   ThisNodeID))
			 (AND (LISTGET ToNode (QUOTE DESTNODEID))
				(LISTPUT ToNode (QUOTE DESTNODEID)
					   (NC.CoerceToGraphNodeID (CADR ToNode))))))

          (* * Bring up card and mess with its window.)


         (SETQ Window (NC.ApplySupersFn EditFn Card Substance Region/Position))
         (NC.SetupTitleBarMenu Window Card (QUOTE Browser))
         (NC.MakeLinksLegendMenu Window (NC.FetchBrowserLinksLegend Card))
                                                             (* Disable the old-style right button grapher editor 
							     menu.)
         (WINDOWPROP Window (QUOTE RIGHTBUTTONFN)
		       (FUNCTION NC.BrowserRightButtonFn))
         (WINDOWADDPROP Window (QUOTE SHRINKFN)
			  (FUNCTION NC.GraphCardShrinkFn))
         (WINDOWADDPROP Window (QUOTE REPAINTFN)
			  (FUNCTION NC.BrowserRepaintFn)
			  T)
         (WINDOWPROP Window (QUOTE SCROLLFN)
		       (FUNCTION NC.BrowserScrollFn))
         (WINDOWPROP Window (QUOTE RESHAPEFN)
		       (FUNCTION NC.BrowserReshapeFn))

          (* * I have to hang notecard's Card on window now in case REDISPLAYW runs and tries to get Card from window.)


         (WINDOWPROP Window (QUOTE NoteCardObject)
		       Card)                                 (* Check if link icon display global params have 
							     changed since last time card was up.
							     If so, fix graph nodes and redisplay.)
         (if (NC.GraphLinkIconUpdateCheck Card Window Substance T)
	     then (REDISPLAYW Window))
     Window)))
)
(* * PLEASE MOVE THE FUNCTION NC.GraphRemoveNode FROM NCBROWSERCARD TO NCGRAPHCARD.)

(PUTPROPS RHTPATCH039 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (2395 2973 (NC.DelTEditProcesses 2405 . 2971)) (3021 7098 (
NC.DelReferencesToCardFromText 3031 . 5078) (NC.TextCardShrinkFn 5080 . 6135) (NC.MakeTEditPropsList 
6137 . 7096)) (7143 8317 (NC.DeleteLinkIconSketchElement 7153 . 8315)) (8366 11100 (
NC.SetupTitleBarMenu 8376 . 10391) (NC.ResetNoteFileInterface 10393 . 11098)) (11148 13011 (
NC.ForceDatabaseClose 11158 . 13009)) (13060 16004 (NC.DelReferencesToCardFromGraph 13070 . 15360) (
NC.GraphDeleteNodeFn 15362 . 15681) (NC.GraphDeleteLinkFn 15683 . 16002)) (16055 35654 (
NC.GraphRemoveNode 16065 . 17702) (NC.BrowserRemoveNode 17704 . 23727) (
NC.DelReferencesToCardFromBrowser 23729 . 26428) (NC.DelBrowserContentsLink 26430 . 27301) (
NC.ComputeBrowserSavedLinkingInfo 27303 . 28010) (NC.GetBrowserHashArray 28012 . 29067) (
NC.BrowserCreateCard 29069 . 30477) (NC.BringUpBrowserCard 30479 . 35652)))))
STOP