(FILECREATED "10-Feb-85 01:51:53" {PHYLUM}<NOTECARDS>RELEASE1.2>NCBASICTYPES.;6 119503 

      changes to:  (FNS NC.TEditQuitFn NC.GraphCardCloseFn NC.SketchCardCloseFn)

      previous date: " 8-Feb-85 19:07:02" {PHYLUM}<NOTECARDS>RELEASE1.2>NCBASICTYPES.;5)


(* Copyright (c) 1984, 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT NCBASICTYPESCOMS)

(RPAQQ NCBASICTYPESCOMS ((E (SETQ NC.SystemDate (DATE)))
	(* * Internal variables)
	(GLOBALVARS NC.GraphTitleBarMenu NC.BrowserTitleBarMenu NC.SketchTitleBarMenu 
		    NC.StructEditTitleBarMenu NC.GraphTitleBarMiddleButtonMenu NC.MakeDocParameters 
		    NC.DashingStyles NC.GraphFlowerLinkSeparation TEDIT.DEFAULT.MENU 
		    INTERCALC.WindowList)
	(VARS (NC.MakeDocParameters (QUOTE ((HeadingsFromFileboxes NumberedBold UnnumberedBold NONE)
					    (TitlesFromNoteCards Bold NotBold NONE)
					    (BuildBackLinks ToCardsBoxes ToCards ToBoxes NONE)
					    (CopyEmbeddedLinks ALL NONE Select)
					    (ExpandEmbeddedLinks ALL NONE Select)
					    (--DONE--))))
	      (NC.DashingStyles (QUOTE (NIL (1 1)
					    (4 1)
					    (1 4)
					    (4 1 1 1)
					    (4 1 2 1)
					    (2 1 2 1))))
	      (NC.GraphFlowerLinkSeparation 8)
	      (NC.LinkDashingInBrowser NIL))
	(* * Note card types)
	(FNS NC.BringUpBrowserCard NC.BringUpGraphCard NC.BringUpSketchCard NC.BringUpTEditCard 
	     NC.ContentsCardP NC.MakeBrowserCard NC.MakeGraphCard NC.MakeSketchCard NC.MakeTEditCard 
	     NC.TEditQuitFn NC.GraphCardCloseFn NC.GraphCardLeftButtonFn NC.SketchDirtyP 
	     NC.GraphCardMiddleButtonFn NC.SketchCardCloseFn NC.TEditCloseFn NC.\TEDIT.LOOKS 
	     NC.\TEDIT.QUIT NC.MakeContentsCard NC.TextCopySubstance NC.GraphCopySubstance 
	     NC.SketchCopySubstance NC.MakeSearchCard NC.MarkSketchDirty NC.MarkTextDirty 
	     NC.CollectReferencesInGraph NC.CollectReferencesInSketch NC.CollectReferencesInText 
	     NC.MarkGraphDirty NC.MakeTEditLeftMenu NC.MakeTEditMiddleMenu NC.ResetTEdit 
	     NC.ResetTEditProcess NC.TEditBasedP NC.TEditMenuFn NC.TextDirtyP NC.GraphDirtyP 
	     NC.GrapherBasedP NC.SketchBasedP NC.FileBoxCollectChildren)
	(DECLARE: DONTCOPY (FILES (FROM {ERIS}<LISP>HARMONY>LIBRARY> LOADCOMP)
				  SKETCH SKETCHOBJ)
		  (FILES (FROM {PHYLUM}<NOTECARDS>MAPS> LOADCOMP)
			 NEWMAP))
	(ADVISE CREATE.SKETCHW.COMMANDMENU)
	(P (SETQ TEDIT.DEFAULT.PROPS (CONS (QUOTE SLOWUPDATE)
					   (CONS (QUOTE T)
						 TEDIT.DEFAULT.PROPS))))
	(* * Hooks into Grapher for NoteCards applications)
	(FNS NC.GraphAddNodeFn NC.GraphDeleteNodeFn NC.GraphAddLinkFn NC.GraphDeleteLinkFn 
	     NC.GraphMoveNodeFn NC.GraphFontChangeFn)
	(* * BROWSER And Search mechanisms)
	(FNS NC.ChooseBrowseOrSearch NC.GrowLinkLattice NC.UpdateBrowserCard NC.SubContentsLinkP 
	     NC.ContentsLinkP NC.NotBrowserHookP NC.SearchForCards NC.AskBrowserSpecs)
	(* * Grapher hacks for browser)
	(ADVISE DRAWLINE-IN-DISPLAYLINK/LR DRAWLINE-IN-DISPLAYLINK/TB)
	(FNS NC.MakeLinksLegend NC.MakeLinksLegendMenu NC.LinksLegendRepaintFn NC.GraphDisplayLinkFn 
	     NC.GraphDrawFlowerLink NC.LinksLegendReshapeFn NC.DrawDashedLine NC.RelayoutGraphCard)
	(* * MakeDocument stuff)
	(FNS NC.MakeDocument NC.DumpFileBoxToDoc NC.DumpNoteCardToDoc NC.FetchToLinksInOrder 
	     NC.AppendLinkToText NC.BuildMakeDocInspector NC.MakeDocInspectorSelectionFn 
	     NC.AppendStringToStream)
	(* * Struct Editor Stuff)
	(FNS NC.MakeStructEditCard NC.FixStructEditTitleBarMenu NC.StructEditAddNodeFn 
	     NC.StructEditAddLinkFn NC.StructEditDeleteNodeFn NC.StructEditDeleteLinkFn)
	(P (SETPROPLIST (QUOTE NC.MakeDocParameters)
			(QUOTE (HeadingsFromFileboxes NumberedBold TitlesFromNoteCards Bold 
						      BuildBackLinks NONE CopyEmbeddedLinks ALL 
						      ExpandEmbeddedLinks NONE --DONE-- --CANCEL-- 
						      VALUE ((HeadingsFromFileboxes NumberedBold 
										   UnnumberedBold 
										    NONE)
						       (TitlesFromNoteCards Bold NotBold NONE)
						       (BuildBackpointers ToCardsBoxes ToCards 
									  ToBoxes NONE)
						       (CopyEmbeddedLinks ALL NONE Select)
						       (ExpandEmbeddedLinks ALL NONE Select)
						       (--DONE--))))))
	(* * Link Index functions)
	(FNS NC.MakeLinkIndex NC.AppendLinkIndexEntry NC.LinkIndexCompareFn)
	(* * spreadsheet stuff)
	(FNS NC.AddSpreadsheetToCard NC.AskSpreadsheetTitle NC.GetSpreadsheets NC.IntercalcActiveP)))
(* * Internal variables)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NC.GraphTitleBarMenu NC.BrowserTitleBarMenu NC.SketchTitleBarMenu 
	    NC.StructEditTitleBarMenu NC.GraphTitleBarMiddleButtonMenu NC.MakeDocParameters 
	    NC.DashingStyles NC.GraphFlowerLinkSeparation TEDIT.DEFAULT.MENU INTERCALC.WindowList)
)

(RPAQQ NC.MakeDocParameters ((HeadingsFromFileboxes NumberedBold UnnumberedBold NONE)
			     (TitlesFromNoteCards Bold NotBold NONE)
			     (BuildBackLinks ToCardsBoxes ToCards ToBoxes NONE)
			     (CopyEmbeddedLinks ALL NONE Select)
			     (ExpandEmbeddedLinks ALL NONE Select)
			     (--DONE--)))

(RPAQQ NC.DashingStyles (NIL (1 1)
			     (4 1)
			     (1 4)
			     (4 1 1 1)
			     (4 1 2 1)
			     (2 1 2 1)))

(RPAQQ NC.GraphFlowerLinkSeparation 8)

(RPAQQ NC.LinkDashingInBrowser NIL)
(* * Note card types)

(DEFINEQ

(NC.BringUpBrowserCard
  (LAMBDA (ID Substance Region/Position)                     (* rht: " 3-Jan-85 23:25")

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


    (PROG (Window)
          (SETQ Window (NC.BringUpGraphCard ID Substance Region/Position))
          (NC.SetupTitleBarMenu Window ID (QUOTE Browser))
          (NC.MakeLinksLegendMenu Window (LISTGET (NC.RetrievePropList ID)
						  (QUOTE BrowserLinksLegend)))
          (RETURN Window))))

(NC.BringUpGraphCard
  (LAMBDA (ID Substance Region/Position)                     (* fgh: " 4-Feb-85 22:40")

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


    (PROG (Region Title GraphWindow IconWindow)
          (COND
	    ((SETQ GraphWindow (NC.FetchWindow ID))
	      (AND (WINDOWP (WINDOWPROP GraphWindow (QUOTE ICONFOR)))
		   (SETQ GraphWindow (EXPANDW GraphWindow)))
	      (TOTOPW GraphWindow)
	      (RPTQ 2 (FLASHW GraphWindow))
	      (RETURN GraphWindow)))
          (SETQ GraphWindow (SHOWGRAPH Substance (CREATEW (NC.DetermineDisplayRegion ID 
										  Region/Position)
							  (GETPROP ID (QUOTE NoteCardTitle)))
				       (FUNCTION NC.GraphCardLeftButtonFn)
				       (FUNCTION NC.GraphCardMiddleButtonFn)
				       NIL T))
          (NC.SetupTitleBarMenu GraphWindow ID)
          (RETURN GraphWindow))))

(NC.BringUpSketchCard
  (LAMBDA (ID Substance Region/Position)                     (* fgh: " 5-Feb-85 19:15")
                                                             (* Bring up a sketch card containing substance in 
							     specified region)

          (* * rht 2/1/85: Added windowprop to prevent sketch asking about saving changes.)


    (PROG (Region Title SketchViewer)
          (COND
	    ((SETQ SketchViewer (NC.FetchWindow ID))
	      (RPTQ 2 (FLASHW SketchViewer))
	      (TOTOPW SketchViewer)
	      (TTY.PROCESS (WINDOWPROP SketchViewer (QUOTE PROCESS)))
	      (RETURN SketchViewer)))
          (SETQ SketchViewer (SKETCHW.CREATE (OR Substance ID)
					     (NC.FetchRegionViewed ID)
					     (NC.DetermineDisplayRegion ID Region/Position)
					     (NC.FetchTitle ID)
					     (NC.FetchScale ID)))
          (WINDOWPROP SketchViewer (QUOTE DONTQUERYCHANGES)
		      T)
          (NC.SetupTitleBarMenu SketchViewer ID (QUOTE Sketch))
          (RETURN SketchViewer))))

(NC.BringUpTEditCard
  (LAMBDA (ID TextStream Region/Position)                    (* rht: " 8-Feb-85 10:47")
                                                             (* Bring up a TEdit window for Card ID whose text 
							     stream is TextStream in Region specified by 
							     Region/Position or by the user.)
    (PROG (Region TEditWindow TEditProcess Title TextStreamDirtyFlg)
          (COND
	    ((AND (SETQ TEditWindow (WINDOW.FROM.TEDIT.THING TextStream))
		  (SETQ TEditProcess (WINDOWPROP TEditWindow (QUOTE PROCESS))))
	      (TOTOPW TEditWindow)
	      (RPTQ 2 (FLASHW TEditWindow))
	      (TTY.PROCESS TEditProcess)
	      (RETURN TEditWindow)))
          (SETQ Region (NC.DetermineDisplayRegion ID Region/Position))
          (SETQ Title (NC.FetchTitle ID))
          (SETQ TEditWindow (CREATEW Region Title NIL T))
          (WINDOWPROP TEditWindow (QUOTE SHRINKFN)
		      (FUNCTION NC.ShrinkFn))
          (WINDOWPROP TEditWindow (QUOTE NoteCardsLeftButtonMenu)
		      (NC.MakeTEditLeftMenu (NC.FetchType ID)))
          (WINDOWPROP TEditWindow (QUOTE NoteCardsMiddleButtonMenu)
		      (NC.MakeTEditMiddleMenu))
          (SETQ TextStreamDirtyFlg (NC.CardDirtyP ID))
          (TEDIT TextStream TEditWindow NIL (LIST (QUOTE FONT)
						  NC.DefaultFont
						  (QUOTE TITLEMENUFN)
						  (FUNCTION NC.TEditMenuFn)))
          (AND TextStreamDirtyFlg (NC.MarkCardDirty ID))
          (RETURN TEditWindow))))

(NC.ContentsCardP
  (LAMBDA (ID DatabaseStream)                                (* fgh: " 7-Nov-84 21:23")
                                                             (* Return T if ID is a CONTENTS card.)
    (OR (EQ (QUOTE FileBox)
	    (NC.RetrieveType ID (OR DatabaseStream PSA.Database)))
	(PROGN (NC.PrintMsg NIL T ID " is not a FileBox.  Please choose again." (CHARACTER 13))
	       NIL))))

(NC.MakeBrowserCard
  (LAMBDA (ID Title NoDisplayFlg ListOfRootIDsAndListOfLinkLabels)
                                                             (* fgh: " 7-Feb-85 21:22")

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



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



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



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



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



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



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


    (PROG (Lattice Window Graph PropList BrowserSpecs (RootIDs (MKLIST (CAR 
								 ListOfRootIDsAndListOfLinkLabels)))
		   RootNodes
		   (ListOfLinkLabels (CADR ListOfRootIDsAndListOfLinkLabels))
		   LabelPairs)
          (NC.ActivateCard ID)
          (COND
	    ((NULL NoDisplayFlg)
	      (SETQ Window (CREATEW (NC.DetermineDisplayRegion ID NIL)
				    (NC.FetchTitle ID)
				    NIL))))
          (SETQ RootIDs (OR RootIDs (PROGN (NC.PrintMsg Window T 
			    "Please select the Cards and/or Boxes the browser should start from."
							(CHARACTER 13))
					   (NC.SelectNoteCards NIL NIL NC.SelectingBrowserSourceMenu 
							       Window))))
          (COND
	    ((OR (NULL RootIDs)
		 (NULL (OR ListOfLinkLabels (SETQ ListOfLinkLabels
			     (NC.AskLinkLabel Window T T NIL T T)))))
	      (NC.DeactivateCard ID)
	      (CLOSEW Window)
	      (RETURN)))
          (SETQ BrowserSpecs (COND
	      (NC.SpecialBrowserSpecsFlg (NC.AskBrowserSpecs Window))
	      (T (create BrowserSpecs))))
          (OR NoDisplayFlg (NC.PrintMsg Window NIL (CHARACTER 13)
					"Computing browser graph. Please wait. ..."))
          (SETQ RootNodes (for RootID in RootIDs
			     collect (SETQ Lattice (NC.GrowLinkLattice RootID Lattice 
								       ListOfLinkLabels ID 
								       PSA.Database))
				     (PACK* ID RootID)))
          (SETQ LabelPairs (NC.MakeLinksLegend Lattice Window))
          (OR NoDisplayFlg (WINDOWPROP Window (QUOTE NoteCardID)
				       ID))

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


          (for Node in Lattice do (replace (GRAPHNODE NODELABEL) of Node
				     with (NC.MakeLinkIcon (NC.MakeLink Window 
								      NC.BrowserContentsLinkLabel
									(fetch (GRAPHNODE NODELABEL)
									   of Node)
									ID NIL))))
          (SETQ Graph (LAYOUTGRAPH Lattice RootNodes (fetch (BrowserSpecs Format) of BrowserSpecs)
				   (fetch (BrowserSpecs Font) of BrowserSpecs)
				   (fetch (BrowserSpecs MotherD) of BrowserSpecs)
				   (fetch (BrowserSpecs PersonalD) of BrowserSpecs)
				   (fetch (BrowserSpecs FamilyD) of BrowserSpecs)))
          (OR NoDisplayFlg (NC.PrintMsg Window NIL "Done!"))
          (NC.SetSubstance ID Graph)
          (NC.PutProp ID (QUOTE BrowserLinkLabels)
		      (LIST (OR ListOfLinkLabels NC.SubBoxLinkLabel)))
          (NC.PutProp ID (QUOTE BrowserRoot)
		      RootIDs)
          (NC.PutProp ID (QUOTE BrowserLinksLegend)
		      LabelPairs)
          (AND NC.SpecialBrowserSpecsFlg (NC.PutProp ID (QUOTE BrowserSpecs)
						     (LIST BrowserSpecs)))
          (NC.SetPropListDirtyFlg ID T)
          (COND
	    (NoDisplayFlg (RETURN ID)))
          (replace (GRAPH GRAPH.ADDNODEFN) of Graph with (FUNCTION NC.StructEditAddNodeFn))
          (replace (GRAPH GRAPH.DELETENODEFN) of Graph with (FUNCTION NC.StructEditDeleteNodeFn))
          (replace (GRAPH GRAPH.ADDLINKFN) of Graph with (FUNCTION NC.StructEditAddLinkFn))
          (replace (GRAPH GRAPH.DELETELINKFN) of Graph with (FUNCTION NC.StructEditDeleteLinkFn))
          (replace (GRAPH GRAPH.MOVENODEFN) of Graph with (FUNCTION NC.GraphMoveNodeFn))
          (replace (GRAPH GRAPH.FONTCHANGEFN) of Graph with (FUNCTION NC.GraphFontChangeFn))
          (SHOWGRAPH Graph Window (FUNCTION NC.GraphCardLeftButtonFn)
		     (FUNCTION NC.GraphCardMiddleButtonFn)
		     NIL T)
          (NC.SetupTitleBarMenu Window ID (QUOTE Browser))
          (NC.ClearMsg Window T)
          (RETURN Window))))

(NC.MakeGraphCard
  (LAMBDA (ID Title NoDisplayFlg)                            (* fgh: " 5-Feb-85 19:15")

          (* * Creates a StructEdit card. Alot like a graph card except that it allows editing of underlying NC structure, and
	  doesn't allow an "insertlink" operation in title bar menu.)


    (PROG (Window Graph)
          (SETQ Graph (create GRAPH
			      GRAPH.ADDNODEFN ←(FUNCTION NC.GraphAddNodeFn)
			      GRAPH.DELETENODEFN ←(FUNCTION NC.GraphDeleteNodeFn)
			      GRAPH.ADDLINKFN ←(FUNCTION NC.GraphAddLinkFn)
			      GRAPH.DELETELINKFN ←(FUNCTION NC.GraphDeleteLinkFn)
			      GRAPH.MOVENODEFN ←(FUNCTION NC.GraphMoveNodeFn)
			      GRAPH.FONTCHANGEFN ←(FUNCTION NC.GraphFontChangeFn)))
          (NC.SetSubstance ID Graph)
          (COND
	    ((NOT NoDisplayFlg)
	      (SETQ Window (CREATEW (NC.DetermineDisplayRegion ID NIL)
				    (OR Title "Untitled")))
	      (SHOWGRAPH Graph Window (FUNCTION NC.GraphCardLeftButtonFn)
			 (FUNCTION NC.GraphCardMiddleButtonFn)
			 T T)
	      (NC.SetupTitleBarMenu Window ID)))
          (RETURN (OR Window ID)))))

(NC.MakeSketchCard
  (LAMBDA (ID Title NoDisplayFlg)                            (* fgh: " 5-Feb-85 19:16")

          (* * rht 2/1/85: Added windowprop to prevent sketch asking about saving changes.)


    (COND
      (NoDisplayFlg (NC.SetSubstance ID NIL)
		    ID)
      (T (PROG (Window)
	       (SETQ Window (SKETCHW.CREATE ID NIL (NC.DetermineDisplayRegion ID NIL)
					    (OR Title "Untitled")))
	       (WINDOWPROP Window (QUOTE DONTQUERYCHANGES)
			   T)
	       (NC.SetupTitleBarMenu Window ID (QUOTE Sketch))
	       (NC.SetSubstance ID (GETPROP ID (QUOTE SKETCH)))
	       (RETURN Window))))))

(NC.MakeTEditCard
  (LAMBDA (ID Title NoDisplayFlg)                            (* fgh: " 5-Feb-85 19:28")
                                                             (* Make up a blank text card and display it.)
    (COND
      (NoDisplayFlg (PROG (TextStream)
		          (SETQ TextStream (OPENTEXTSTREAM "" NIL NIL NIL
							   (LIST (QUOTE FONT)
								 NC.DefaultFont
								 (QUOTE TITLEMENUFN)
								 (FUNCTION NC.TEditMenuFn))))
		          (NC.SetSubstance ID TextStream)
		          (RETURN ID)))
      (T (PROG (Window)
	       (SETQ Window (CREATEW (NC.DetermineDisplayRegion ID NIL)
				     (OR Title "Untitled")))
	       (WINDOWPROP Window (QUOTE NoteCardsLeftButtonMenu)
			   (NC.MakeTEditLeftMenu (NC.FetchType ID)))
	       (WINDOWPROP Window (QUOTE NoteCardsMiddleButtonMenu)
			   (NC.MakeTEditMiddleMenu))
	       (WINDOWPROP Window (QUOTE SHRINKFN)
			   (FUNCTION NC.ShrinkFn))
	       (TEDIT NIL Window NIL (LIST (QUOTE FONT)
					   NC.DefaultFont
					   (QUOTE TITLEMENUFN)
					   (FUNCTION NC.TEditMenuFn)))
	       (until (WINDOWPROP Window (QUOTE TEXTSTREAM)) do (BLOCK))
	       (NC.SetSubstance ID (WINDOWPROP Window (QUOTE TEXTSTREAM)))
	       (RETURN Window))))))

(NC.TEditQuitFn
  (LAMBDA (WindowOrID)                                       (* rht: " 9-Feb-85 21:50")
                                                             (* Called by TEdit when quitting out of a TEdit-based 
							     note card. Close up attached windows,)
    (PROG (TextStream Window PromptWindow (ID (NC.CoerceToID WindowOrID)))
          (SETQ Window (NC.FetchWindow ID))
          (SETQ PromptWindow (CAR (WINDOWPROP Window (QUOTE PROMPTWINDOW))))
          (AND Window (for AttachedWindow in (ALLATTACHEDWINDOWS Window) unless (EQ AttachedWindow 
										    PromptWindow)
			 do (DETACHWINDOW AttachedWindow)
			    (CLOSEW AttachedWindow)
			    (until (NULL (OPENWP AttachedWindow)) do (BLOCK))))
          (SETQ TextStream (NC.FetchSubstance ID))
          (NC.DeactivateCard ID)                             (* MAke sure TEdit won't close the database file)
          (replace (TEXTOBJ TXTFILE) of (TEXTOBJ TextStream) with NIL)
          (TEDIT.MAPPIECES (TEXTOBJ TextStream)
			   (FUNCTION (LAMBDA (CH# PC PC# OBL)
			       (replace (PIECE PFILE) of PC with NIL))))

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


          (AND Window (SETQ PromptWindow (GETPROMPTWINDOW Window NIL NIL T))
	       (WINDOWPROP PromptWindow (QUOTE PROCESS)
			   NIL)
	       (REMOVEPROMPTWINDOW Window))
          (RETURN T))))

(NC.GraphCardCloseFn
  (LAMBDA (WindowOrID)                                       (* rht: " 9-Feb-85 21:50")
                                                             (* Called when a grapher-based note card is being 
							     closed. Writes graph to database and does other clean 
							     up functions)
    (PROG (Window (ID (NC.CoerceToID WindowOrID)))
          (SETQ Window (NC.FetchWindow ID))
          (AND Window (for AttachedWindow in (ALLATTACHEDWINDOWS Window)
			 do (DETACHWINDOW AttachedWindow)
			    (CLOSEW AttachedWindow)))
          (AND Window (REMOVEPROMPTWINDOW Window))
          (NC.DeactivateCard ID))))

(NC.GraphCardLeftButtonFn
  (LAMBDA (GraphNode GraphWindow)                            (* fgh: " 2-Oct-84 18:31")

          (* * If this is a node containing a link icon, then do: IF Selection in progress, then pressing a node gets its 
	  destination ID if its actually a note card node. Otherwise, bring up the note card pointed to by the node.)


    (PROG (ID (LinkIcon (fetch (GRAPHNODE NODELABEL) of GraphNode)))
          (AND (NC.LinkIconImageObjP LinkIcon)
	       (COND
		 (NC.SelectionInProgress (AND (SETQ ID (fetch (NOTECARDLINK DESTINATIONID)
							  of (NC.FetchLinkFromLinkIcon LinkIcon)))
					      (NOT (FMEMB ID NC.SelectedCards))
					      (SETQ NC.SelectedCards (CONS ID NC.SelectedCards))))
		 (T (NC.EditNoteCard (fetch (NOTECARDLINK DESTINATIONID) of (NC.FetchLinkFromLinkIcon
									      LinkIcon)))))))))

(NC.SketchDirtyP
  (LAMBDA (ID)                                               (* rht: " 1-Feb-85 15:47")

          (* * rht 2/1/85: No longer checks FILEPKGCHANGES. Now uses window prop. Note that we really should have a flag on 
	  the sketch object itself.)


    (OR (WINDOWPROP (NC.FetchWindow ID)
		    (QUOTE SKETCHCHANGED))
	(NULL (NC.FetchScale ID))
	(NULL (NC.FetchRegionViewed ID)))))

(NC.GraphCardMiddleButtonFn
  (LAMBDA (GraphNode GraphWindow)                            (* fgh: " 2-Oct-84 18:25")

          (* IF Selection in progress, then pressing a node gets its destination ID if its actually a note card node.
	  Otherwise, jump to normal button processing for an link icon)


    (PROG (ID (LinkIcon (fetch (GRAPHNODE NODELABEL) of GraphNode)))
          (AND (NC.LinkIconImageObjP LinkIcon)
	       (COND
		 (NC.SelectionInProgress (AND (SETQ ID (fetch (NOTECARDLINK DESTINATIONID)
							  of (NC.FetchLinkFromLinkIcon LinkIcon)))
					      (NOT (FMEMB ID NC.SelectedCards))
					      (SETQ NC.SelectedCards (CONS ID NC.SelectedCards))))
		 ((AND NC.SpecialBrowserMiddleButtonFn (EQ (NC.FetchType (NC.IDFromWindow GraphWindow)
									 )
							   (QUOTE BROWSER)))
		   (APPLY* NC.SpecialBrowserMiddleButtonFn GraphNode GraphWindow))
		 (T (NC.LinkIconMiddleButtonFn LinkIcon GraphWindow)))))))

(NC.SketchCardCloseFn
  (LAMBDA (WindowOrID)                                       (* rht: " 9-Feb-85 21:50")
                                                             (* Quit from a sketch card, saving information on the 
							     database)

          (* * rht 12/20/84: Added ugly kludge, setting SKETCHCHANGED to nil, to keep sketch from asking whether to save 
	  changes or not.)



          (* * rht 2/1/85: Removed above mentioned ugly kludge. It's now taken care of by a windowprop.
	  Now closes all sketch viewers for this sketch.)


    (PROG (ID Window OldRegion NewRegion)
          (SETQ ID (NC.CoerceToID WindowOrID))
          (SETQ Window (NC.FetchWindow ID))
          (COND
	    (Window (for Viewer in (ALL.SKETCH.VIEWERS (NC.FetchSubstance ID)) do (CLOSEW Viewer))
		    (SKED.CLEAR.SELECTION Window)
		    (for AttachedWindow in (ATTACHEDWINDOWS Window)
		       do (DETACHWINDOW AttachedWindow)
			  (CLOSEW AttachedWindow))))
          (COND
	    (Window (REMOVEPROMPTWINDOW Window)
		    (WINDOWPROP Window (QUOTE SKETCHOPMENU)
				NIL)))
          (TTY.PROCESS T)
          (NC.DeactivateCard ID))))

(NC.TEditCloseFn
  (LAMBDA (WindowOrTextStreamOrID)                           (* rht: "13-Nov-84 09:55")
                                                             (* Close this TEdit window by Quitting from TEdit)

          (* * rht 11/12/84: Changed call to TEXTSTREAM to a WINDOWPROP call.)


    (PROG (Window (ID (NC.CoerceToID WindowOrTextStreamOrID)))
          (SETQ Window (NC.FetchWindow ID))
          (NC.TEditQuitFn ID)
          (COND
	    (Window (WINDOWDELPROP Window (QUOTE CLOSEFN)
				   (FUNCTION NC.QuitCard))
		    (TEDIT.QUIT (TEXTSTREAM Window)))))))

(NC.\TEDIT.LOOKS
  (LAMBDA (TextStream)                                       (* fgh: "31-Mar-84 16:02")
    (\TEDIT.LOOKS (TEXTOBJ TextStream))))

(NC.\TEDIT.QUIT
  (LAMBDA (TextStream)                                       (* fgh: "10-May-84 16:27")
    (PROG ((Window (WINDOW.FROM.TEDIT.THING TextStream)))
          (NC.TEditQuitFn Window)
          (\TEDIT.QUIT Window))))

(NC.MakeContentsCard
  (LAMBDA (ID Title DontDisplay)                             (* rht: " 8-Feb-85 10:48")
                                                             (* Make up a blank contents card, hook it to the user 
							     specified parent contents cards, and display it.)

          (* * rht 12/2/84: In DontDisplay case, changed to return ID rather than TextStream.)



          (* * rht 12/8/84: Massive shaving. Took out code to force filing now (at creation time))


    (PROG (Window TextStream (Spacer (CONCAT (CHARACTER 13)
					     (CHARACTER 13))))
          (SETQ TextStream (OPENTEXTSTREAM ""))
          (COND
	    (NC.MarkersInFileBoxesFlg (TEDIT.INSERT.OBJECT (NC.MakePlaceMarker NC.SubBoxMarkerLabel)
							   TextStream 1)
				      (TEDIT.INSERT TextStream Spacer 2)
				      (TEDIT.INSERT.OBJECT (NC.MakePlaceMarker 
									  NC.FiledCardMarkerLabel)
							   TextStream 4)
				      (TEDIT.INSERT TextStream Spacer 5))
	    (T (TEDIT.INSERT TextStream Spacer 1)))
          (NC.SetSubstance ID TextStream)
          (NC.SetRegion ID (CREATEREGION 0 0 (NC.DefaultCardWidth ID)
					 (NC.DefaultCardHeight ID)))
          (COND
	    (DontDisplay (RETURN ID)))
          (SETQ Window (CREATEW (NC.DetermineDisplayRegion ID NIL)
				(NC.SetTitle ID (OR Title "Untitled"))))
          (WINDOWPROP Window (QUOTE NoteCardsLeftButtonMenu)
		      (NC.MakeTEditLeftMenu (NC.FetchType ID)))
          (WINDOWPROP Window (QUOTE NoteCardsMiddleButtonMenu)
		      (NC.MakeTEditMiddleMenu))              (* Display the card)
          (WINDOWPROP Window (QUOTE SHRINKFN)
		      (FUNCTION NC.ShrinkFn))
          (TEDIT TextStream Window NIL (LIST (QUOTE FONT)
					     NC.DefaultFont
					     (QUOTE TITLEMENUFN)
					     (FUNCTION NC.TEditMenuFn)))
          (until (WINDOWPROP Window (QUOTE TEXTSTREAM)) do (BLOCK))
          (NC.ActivateCard ID)
          (AND (GETPROMPTWINDOW Window NIL NIL T)
	       (PROG1 (DISMISS 1000)
		      (NC.ClearMsg Window T)))
          (RETURN Window))))

(NC.TextCopySubstance
  (LAMBDA (ID FromStream ToStream)                           (* fgh: "23-Oct-84 11:42")

          (* * Copy a text substance from FromStream to ToStream.)


    (PROG (FromStartPtr FromEndPtr ToEndPtrLoc ToEndPtr ToStartPtr)

          (* * Set up start/end pointers on ToStream)


          (SETQ ToStartPtr (IPLUS (GETFILEPTR ToStream)
				  6))
          (NC.PutPtr ToStream ToStartPtr)
          (SETQ ToEndPtrLoc (GETFILEPTR ToStream))
          (NC.PutPtr ToStream 0)

          (* * Get FromStream start/end pointers)


          (SETQ FromStartPtr (NC.GetPtr FromStream 3))
          (SETQ FromEndPtr (NC.GetPtr FromStream 3))

          (* * Copy the bytes, fixing up the file absolute pointers on the way.)


          (COND
	    ((IGREATERP (IDIFFERENCE FromEndPtr FromStartPtr)
			2)
	      (SETFILEPTR FromStream (IDIFFERENCE FromEndPtr 2))
	      (COND
		((FMEMB (\WIN FromStream)
			(QUOTE (31415 31416)))
		  (COPYBYTES FromStream ToStream FromStartPtr (IDIFFERENCE FromEndPtr 8))
		  (\DWOUT ToStream (IPLUS (IDIFFERENCE (\DWIN FromStream)
						       FromStartPtr)
					  ToStartPtr))
		  (RPTQ 2 (\WOUT ToStream (\WIN FromStream))))
		(T (COPYBYTES FromStream ToStream FromStartPtr FromEndPtr))))
	    (T (COPYBYTES FromStream ToStream FromStartPtr FromEndPtr)))

          (* * Set up the ned ptr on the ToStream)


          (SETQ ToEndPtr (GETFILEPTR ToStream))
          (SETFILEPTR ToStream ToEndPtrLoc)
          (NC.PutPtr ToStream ToEndPtr)
          (RETURN T))))

(NC.GraphCopySubstance
  (LAMBDA (ID FromStream ToStream)                           (* fgh: "23-Oct-84 11:43")

          (* * Copy a graph substance from FromStream to ToStream.)


    (PROG (FromStartPtr FromEndPtr ToEndPtrLoc ToEndPtr ToStartPtr)

          (* * Set up start/end pointers on ToStream)


          (SETQ ToStartPtr (IPLUS (GETFILEPTR ToStream)
				  6))
          (NC.PutPtr ToStream ToStartPtr)
          (SETQ ToEndPtrLoc (GETFILEPTR ToStream))
          (NC.PutPtr ToStream 0)

          (* * Get FromStream start/end pointers)


          (SETQ FromStartPtr (NC.GetPtr FromStream 3))
          (SETQ FromEndPtr (NC.GetPtr FromStream 3))

          (* * Copy the bytes)


          (COPYBYTES FromStream ToStream FromStartPtr FromEndPtr)

          (* * Set up the ned ptr on the ToStream)


          (SETQ ToEndPtr (GETFILEPTR ToStream))
          (SETFILEPTR ToStream ToEndPtrLoc)
          (NC.PutPtr ToStream ToEndPtr)
          (RETURN T))))

(NC.SketchCopySubstance
  (LAMBDA (ID FromStream ToStream)                           (* fgh: "23-Oct-84 11:43")

          (* * Copy a sketch substance from FromStream to ToStream.)


    (PROG (FromStartPtr FromEndPtr ToEndPtrLoc ToEndPtr ToStartPtr)

          (* * Set up start/end pointers on ToStream)


          (SETQ ToStartPtr (IPLUS (GETFILEPTR ToStream)
				  6))
          (NC.PutPtr ToStream ToStartPtr)
          (SETQ ToEndPtrLoc (GETFILEPTR ToStream))
          (NC.PutPtr ToStream 0)

          (* * Get FromStream start/end pointers)


          (SETQ FromStartPtr (NC.GetPtr FromStream 3))
          (SETQ FromEndPtr (NC.GetPtr FromStream 3))

          (* * Copy the bytes)


          (COPYBYTES FromStream ToStream FromStartPtr FromEndPtr)

          (* * Set up the ned ptr on the ToStream)


          (SETQ ToEndPtr (GETFILEPTR ToStream))
          (SETFILEPTR ToStream ToEndPtrLoc)
          (NC.PutPtr ToStream ToEndPtr)
          (RETURN T))))

(NC.MakeSearchCard
  (LAMBDA (ListCardID Title NoDisplayFlg)                    (* rht: "31-Jan-85 21:22")

          (* Search for cards with specified characteristics and create a list card containing pointers to these cards.
	  For now search is limited to cards whose title contains a specified string.)



          (* * rht 11/8/84: Fixed some confusion between ListCardID and ID variables.)


    (PROG (SearchString IDs WindowOrID Window)
          (SPAWN.MOUSE)
          (SETQ WindowOrID (NC.MakeTEditCard ListCardID (OR Title "SearchCard")
					     NoDisplayFlg))
          (NC.ActivateCard ListCardID)
          (SETQ Window (AND (WINDOWP WindowOrID)
			    WindowOrID))
          (SETQ SearchString (NC.AskUser "Please enter the search string" " -- " NIL T Window))
          (COND
	    ((OR (EQUAL SearchString "")
		 (NOT SearchString))
	      (RETURN WindowOrID)))
          (NC.SetTitle ListCardID (SETQ Title (OR Title (CONCAT "Cards with %"" SearchString 
								"%" in title"))))
          (AND Window (WINDOWPROP Window (QUOTE TITLE)
				  Title))
          (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
		    (NC.PrintMsg Window T "Searching for cards ...")
		    (SETQ IDs (bind Title ID for ID# from 1 to (SUB1 (SUBATOM (NC.GetNewID 
										     PSA.Database T)
									      3))
				 when (AND (SETQ Title (NC.FetchTitle (SETQ ID (NC.IDFromNumber
									  ID#))))
					   (STRPOS SearchString Title))
				 collect ID))
		    (TEDIT.INSERT (NC.FetchSubstance ListCardID)
				  (CONCAT " List compiled on: " (DATE)
					  (CHARACTER 13))
				  1)
		    (for ID in IDs unless (EQ ListCardID ID) do (NC.InsertLinkBeforeMarker
								  ListCardID ID 
								  NC.ListContentsLinkLabel
								  (QUOTE Title)
								  NIL PSA.Database))
		    (NC.PrintMsg Window NIL "Done!" (CHARACTER 13)))
          (BLOCK 250)
          (NC.ClearMsg Window T)
          (RETURN WindowOrID))))

(NC.MarkSketchDirty
  (LAMBDA (ID ResetFlg)                                      (* rht: " 1-Feb-85 15:37")

          (* * Mark or unmark sketch as having been changed.)



          (* * rht 2/1/85: Now goes through window prop rather than FILEPKG.)


    (WINDOWPROP (NC.FetchWindow ID)
		(QUOTE SKETCHCHANGED)
		ResetFlg)))

(NC.MarkTextDirty
  (LAMBDA (ID ResetFlg)                                      (* rht: " 1-Feb-85 15:45")

          (* * Mark or unmark TextStream as being changed.)



          (* * rht 2/1/85: Updated to use the documented function.)


    (TEDIT.STREAMCHANGEDP (TEXTSTREAM (NC.FetchSubstance ID))
			  ResetFlg)))

(NC.CollectReferencesInGraph
  (LAMBDA (ID CheckAndDeleteFlg DatabaseStream ReturnLinkIconsFlg ReturnLocationsFlg)
                                                             (* fgh: "23-Oct-84 16:18")

          (* * Return a list of all links or link icons in graph substance Substance. If CheckAndDeleteFlg, then delete any 
	  links found that are not valid links.)


    (PROG ((Substance (NC.FetchSubstance ID))
	   ActualLink DirtyFlg Links LinkIcon CollectItem)
          (SETQ Links (for GraphNode in (fetch (GRAPH GRAPHNODES) of Substance)
			 when (COND
				((NC.LinkIconImageObjP (SETQ LinkIcon (fetch (GRAPHNODE NODELABEL)
									 of GraphNode)))
				  (SETQ ActualLink (NC.FetchLinkFromLinkIcon LinkIcon))
				  (COND
				    ((NULL CheckAndDeleteFlg))
				    ((AND (LISTP CheckAndDeleteFlg)
					  (FMEMB (fetch (NOTECARDLINK DESTINATIONID) of ActualLink)
						 CheckAndDeleteFlg)))
				    ((NC.ValidLinkP ActualLink DatabaseStream))
				    (T (replace (GRAPHNODE NODELABEL) of GraphNode with 
									NC.DeletedLinkImageObject)
				       (SETQ DirtyFlg T)
				       NIL)))
				(T NIL))
			 collect (PROGN (SETQ CollectItem (COND
					    (ReturnLinkIconsFlg LinkIcon)
					    (T ActualLink)))
					(COND
					  ((NULL ReturnLocationsFlg)
					    CollectItem)
					  (T (CONS CollectItem (fetch (GRAPHNODE NODELABEL)
								  of GraphNode)))))))
          (RETURN (CONS Links DirtyFlg)))))

(NC.CollectReferencesInSketch
  (LAMBDA (ID CheckAndDeleteFlg DatabaseStream ReturnLinkIconsFlg ReturnLocationsFlg)
                                                             (* rht: " 6-Feb-85 14:36")

          (* * Return a list of all links in sketch substance Substance. If CheckAndDeleteFlg, then delete any links found 
	  that are not valid links.)


    (PROG ((Substance (NC.FetchSubstance ID))
	   DirtyFlg Links LinkIcon CollectItem ActualLink)
          (SETQ Links (for SketchElt in (SUBSET (fetch (SKETCH SKETCHELTS) of Substance)
						(FUNCTION (LAMBDA (SketchElt)
						    (AND (EQ (fetch (INDIVIDUALGLOBALPART GTYPE)
								of (fetch (GLOBALPART 
									     INDIVIDUALGLOBALPART)
								      of SketchElt))
							     (QUOTE SKIMAGEOBJ))
							 (NC.LinkIconImageObjP
							   (fetch (SKIMAGEOBJ SKIMAGEOBJ)
							      of (fetch (GLOBALPART 
									     INDIVIDUALGLOBALPART)
								    of SketchElt)))))))
			 when (PROG NIL
				    (SETQ ActualLink (NC.FetchLinkFromLinkIcon
					(SETQ LinkIcon (fetch (SKIMAGEOBJ SKIMAGEOBJ)
							  of (fetch (GLOBALPART INDIVIDUALGLOBALPART)
								of SketchElt)))))
				    (COND
				      ((NULL CheckAndDeleteFlg)
                                                             (* No checking required)
					(RETURN T))
				      ((AND (LISTP CheckAndDeleteFlg)
					    (FMEMB (fetch (NOTECARDLINK DESTINATIONID) of ActualLink)
						   CheckAndDeleteFlg))
                                                             (* Already checked since ID cached on CheckAndDeleteFlg
							     list)
					(RETURN T))
				      ((NC.ValidLinkP ActualLink DatabaseStream)
                                                             (* Link is valid)
					(RETURN T))
				      (T                     (* Link is bad. Replace it with the DeletedLink image 
							     object.)
					 (replace (SKIMAGEOBJ SKIMAGEOBJ) of (fetch (GLOBALPART
										      
									     INDIVIDUALGLOBALPART)
										of SketchElt)
					    with NC.DeletedLinkImageObject)
					 (SETQ DirtyFlg T)
					 (RETURN NIL))))
			 collect (PROGN (SETQ CollectItem (COND
					    (ReturnLinkIconsFlg LinkIcon)
					    (T ActualLink)))
					(COND
					  (ReturnLocationsFlg
					    (CONS CollectItem (LOWERLEFT (fetch (SKIMAGEOBJ 
									     SKIMOBJ.GLOBALREGION)
									    of (fetch (GLOBALPART
											
									     INDIVIDUALGLOBALPART)
										  of SketchElt)))))
					  (T CollectItem)))))
          (RETURN (CONS Links DirtyFlg)))))

(NC.CollectReferencesInText
  (LAMBDA (ID CheckAndDeleteFlg DatabaseStream ReturnLinkIconsFlg ReturnLocationsFlg)
                                                             (* fgh: "23-Oct-84 11:56")

          (* * Return a list of all links or link icons in text substance Substance. If CheckAndDeleteFlg, then delete any 
	  links found that are not valid links.)


    (PROG (ActualLink DirtyFlg Links (Substance (NC.FetchSubstance ID)))
          (SETQ Links (for ImageObjectDecriptor in (TEDIT.LIST.OF.OBJECTS (TEXTOBJ Substance)
									  (FUNCTION 
									    NC.LinkIconImageObjP))
			 when (PROG NIL
				    (SETQ ActualLink (NC.FetchLinkFromLinkIcon (CAR 
									     ImageObjectDecriptor)))
				    (COND
				      ((NULL CheckAndDeleteFlg)
                                                             (* No checking required)
					(RETURN T))
				      ((AND (LISTP CheckAndDeleteFlg)
					    (FMEMB (fetch (NOTECARDLINK DESTINATIONID) of ActualLink)
						   CheckAndDeleteFlg))
                                                             (* Already checked since ID cached on CheckAndDeleteFlg
							     list)
					(RETURN T))
				      ((NC.ValidLinkP ActualLink DatabaseStream)
                                                             (* Link is valid)
					(RETURN T))
				      (T                     (* Link is bad. Replace it with the DeletedLink image 
							     object.)
					 (create IMAGEOBJ
					    smashing (CAR ImageObjectDecriptor)
						     OBJECTDATUM ←(fetch (IMAGEOBJ OBJECTDATUM)
								     of NC.DeletedLinkImageObject)
						     IMAGEOBJPLIST ←(fetch (IMAGEOBJ IMAGEOBJPLIST)
								       of NC.DeletedLinkImageObject)
						     IMAGEOBJFNS ←(fetch (IMAGEOBJ IMAGEOBJFNS)
								     of NC.DeletedLinkImageObject))
					 (SETQ DirtyFlg T)
					 (RETURN NIL))))
			 collect (COND
				   ((AND ReturnLinkIconsFlg (NOT ReturnLocationsFlg))
				     (CAR ImageObjectDecriptor))
				   ((AND ReturnLinkIconsFlg ReturnLocationsFlg)
				     (CONS (CAR ImageObjectDecriptor)
					   (CADR ImageObjectDecriptor)))
				   ((AND (NOT ReturnLinkIconsFlg)
					 ReturnLocationsFlg)
				     (CONS ActualLink (CADR ImageObjectDecriptor)))
				   (T ActualLink))))
          (RETURN (CONS Links DirtyFlg)))))

(NC.MarkGraphDirty
  (LAMBDA (ID ResetFlg)                                      (* fgh: "24-Oct-84 18:33")

          (* * Mark or unmark graph as having been changed -- Sorry no can do!!!)


    NIL))

(NC.MakeTEditLeftMenu
  (LAMBDA (NoteCardType)                                     (* rht: " 6-Feb-85 16:32")

          (* * Make the LeftButton TEdit menu appropriate for this type of text card. If menu doesn't exist, then make it.)



          (* * rht 8/1/84: Added a new menu item for the CONTENTS menu called Collect Children)



          (* * rht 9/17/84: (actually redoing earlier changes which got trashed) Added menu item for the CONTENTS menu called 
	  Make Document.)



          (* * rht 9/20/84: New menu item for TEXT menu called "Insert Spreadsheet".)



          (* * rht 9/25/84: Made MakeDocument also present in TEXT menu.)



          (* * rht 12/8/84: Now both fileboxes and notecards do filing via NC.AddParents. Also took out all the strange uses 
	  of NC.TEditMenus.)


    (\TEDIT.CREATEMENU (COND
			 ((NEQ NoteCardType (QUOTE FileBox))
			   (QUOTE ((Show/Edit% Properties (FUNCTION NC.EditProperties)
							  
					"Brings up an editor for the property list of this card."
							  (SUBITEMS (Edit% Property% List
								      (FUNCTION NC.EditProperties)
								      
					"Brings up an editor for the property list of this card.")
								    (Show% Links
								      (FUNCTION NC.ShowPointers)
								      
					   "Brings up a list of the links to and from this card.")))
				    (Title/Sources/FileBoxes (FUNCTION (LAMBDA (TextStream)
								 (NC.AssignTitle TextStream)
								 (NC.AssignSources TextStream)
								 (NC.FileNoteCard TextStream)))
							     
		       "Do all of the operations necessary to file this note card in a file box."
							     (SUBITEMS (Assign% Title
									 (FUNCTION NC.AssignTitle)
									 
						       "Assigns a (new) title to this note card.")
								       (Designate% Sources
									 (FUNCTION NC.AssignSources)
									 
				       "Designate the source(s) of the information in this card.")
								       (File% in% FileBoxes
									 (FUNCTION NC.AddParents)
									 
						 "File this note card in one or more file boxes.")
								       (Unfile% from% FileBoxes
									 (FUNCTION NC.UnfileNoteCard)
									 
					   "Remove this card from one or more of its file boxes.")
								       (Delete% Source
									 (FUNCTION NC.DeleteSource)
									 
							"Delete one of the sources of this card.")))
				    (Insert% Link (FUNCTION NC.AddLinkToTextCard)
						  
		     "Insert a link to another card at the currently selected point in the text."
						  (SUBITEMS (Insert% Link (FUNCTION 
									    NC.AddLinkToTextCard)
									  
		     "Insert a link to another card at the currently selected point in the text.")
							    (Insert% Links (FUNCTION 
									    NC.AddLinksToTextCard)
									   
		       "Insert links to other cards at the currently selected point in the text.")))
				    (Close% and% Save (FUNCTION NC.QuitCard)
						      
					  "Close this note card after saving it in the NoteFile."
						      (SUBITEMS (Close% and% Save
								  (FUNCTION NC.TEditCloseFn)
								  
					  "Close this note card after saving it in the NoteFile.")
								(Close% w/o% Saving
								  (FUNCTION NC.QuitWithoutSaving)
								  
		      "Close this note card without saving any changes made since the last Save.")
								(Save% in% NoteFile
								  (FUNCTION NC.CardSaveFn)
								  
				       "Save this card in the NoteFile but don't close the card.")
								(Delete% Card (FUNCTION 
									       NC.DeleteNoteCards)
									      
						"Permenantly delete this card from the NoteFile.")))))
			   )
			 (T (QUOTE ((Show/Edit% Properties (FUNCTION NC.EditProperties)
							   
					"Brings up an editor for the property list of this card."
							   (SUBITEMS (Edit% Property% List
								       (FUNCTION NC.EditProperties)
								       
					"Brings up an editor for the property list of this card.")
								     (Show% Links
								       (FUNCTION NC.ShowPointers)
								       
					   "Brings up a list of the links to and from this card.")))
				     (Put% in% FileBox (FUNCTION NC.AddParents)
						       "Put this FileBox in new parent FileBox(es).")
				     (Assign% Title (FUNCTION NC.AssignTitle)
						    "Assign a new title to this FileBox.")
				     (Collect% Children (FUNCTION NC.FileBoxCollectChildren)
							
				       "Collect new child cards and file boxes for this FileBox.")
				     (Close% and% Save (FUNCTION NC.TEditCloseFn)
						       
					  "Close this note card after saving it in the NoteFile."
						       (SUBITEMS (Close% and% Save
								   (FUNCTION NC.TEditCloseFn)
								   
					  "Close this note card after saving it in the NoteFile.")
								 (Save% in% NoteFile
								   (FUNCTION NC.CardSaveFn)
								   
				       "Save this card in the NoteFile but don't close the card.")
								 (Delete% FileBox
								   (FUNCTION NC.DeleteNoteCards)
								   
					     "Permenantly delete this FileBox from the NoteFile.")))))
			    )))))

(NC.MakeTEditMiddleMenu
  (LAMBDA NIL                                                (* rht: " 6-Feb-85 14:51")

          (* * Make the Middle Button Menu fort a Tedit card.)


    (\TEDIT.CREATEMENU (DREMOVE NIL (BQUOTE ((Restart% Editor (FUNCTION NC.ResetTEdit)
							      
					      "Resets and restarts the editor for this Card/Box.")
					     ,
					     (AND NC.AnnoFlg (for Item in (fetch (MENU ITEMS)
									     of TEDIT.DEFAULT.MENU)
								when (EQ (CAR Item)
									 (QUOTE Annotate))
								do (RETURN Item)))
					     (Advanced% Editing% Menu (FUNCTION \TEDIT.EXPANDED.MENU)
								      
					  "Brings up the menu for the advanced editing commands.")
					     (Change% Font (FUNCTION NC.\TEDIT.LOOKS)
							   "Changes the font of the selected text.")
					     (Hardcopy (FUNCTION TEDIT.HARDCOPY)
						       "Send a copy to the default printer.")))))))

(NC.ResetTEdit
  (LAMBDA (TextStream)                                       (* NoteCards% User "17-Jun-84 01:58")

          (* * Kill the Tedit process running on TextStream and the restart a new one. Goal is to clean up display if TEdit 
	  goea awary.)


    (ADD.PROCESS (LIST (FUNCTION NC.ResetTEditProcess)
		       TextStream)
		 (QUOTE NAME)
		 (QUOTE ResetTEdit))))

(NC.ResetTEditProcess
  (LAMBDA (TextStream)                                       (* rht: " 5-Feb-85 22:45")

          (* * Added-process that actually does the works for NC.ResetTEdit. Kill the Tedit process running on TextStream and 
	  the restart a new one. Goal is to clean up display if TEdit goea awary.)



          (* * rht 2/1/85: Changed to calls to NC.MarkCardDirty and NC.CardDirtyP.)


    (PROG ((Window (WINDOW.FROM.TEDIT.THING TextStream))
	   (TextObj (TEXTOBJ TextStream))
	   DirtyFlg ID)
          (SETQ ID (NC.IDFromWindow Window))
          (COND
	    ((OR (NOT (WINDOWP Window))
		 (NULL ID))
	      (RETURN)))
          (SETQ DirtyFlg (NC.CardDirtyP ID))
          (TEDIT.KILL TextStream)
          (TEDIT TextStream Window)
          (NC.MarkCardDirty ID (NOT DirtyFlg))
          (WINDOWPROP Window (QUOTE TITLE)
		      (NC.RetrieveTitle ID PSA.Database))
          (RETURN))))

(NC.TEditBasedP
  (LAMBDA (Type)                                             (* rht: " 8-Nov-84 12:03")

          (* * Returns T if Type is a note card type that is based on TEdit or else an ID of such a note card.
	  NIL otherise.)



          (* * rht 11/8/84: Hacked to reflect notecards typing mechanism. Seems gross to have to search the types list to get 
	  the record.)


    (if (NC.IDP Type)
	then (SETQ Type (NC.FetchType Type)))
    (for CardType in NC.CardTypes when (EQ Type (fetch (NoteCardType TypeName) of CardType))
       do (RETURN (EQ (QUOTE TEXT)
		      (fetch (NoteCardType SubstanceType) of CardType))))))

(NC.TEditMenuFn
  (LAMBDA (Window)                                           (* NoteCards% User "17-Jun-84 00:23")

          (* * Gets called from LEFT or MIDDLE button press in title bar of TEdit window. If LEFT press bring up the Notecards
	  Manipulation Window. IF MIDDLE press bring up the TEdit specific NoteCard operations menu. Bring up menus using 
	  TEDIT.DEFAULT.MENUFN)


    (PROGN (COND
	     ((LASTMOUSESTATE LEFT)
	       (WINDOWPROP Window (QUOTE TEDIT.MENU)
			   (WINDOWPROP Window (QUOTE NoteCardsLeftButtonMenu))))
	     (T (WINDOWPROP Window (QUOTE TEDIT.MENU)
			    (WINDOWPROP Window (QUOTE NoteCardsMiddleButtonMenu)))))
	   (TEDIT.DEFAULT.MENUFN Window))))

(NC.TextDirtyP
  (LAMBDA (ID)                                               (* fgh: "23-Oct-84 12:34")

          (* * Return T is TextSubstance has been changed.)


    (TEDIT.STREAMCHANGEDP (TEXTSTREAM (NC.FetchSubstance ID)))))

(NC.GraphDirtyP
  (LAMBDA (Graph)                                            (* rht: " 1-Feb-85 15:39")

          (* * A graph is always considered to be dirty since we can't tell whether its changed or not.)



          (* * rht 2/1/85: For now we can't tell by looking at graph substance whether we're dirty or not.
	  Leave it up to the SubstanceDirtyFlg on the card.)


    NIL))

(NC.GrapherBasedP
  (LAMBDA (NoteCardType)                                     (* fgh: "20-Aug-84 01:56")

          (* * Returns T if NoteCardType is a note card type that is based on Grapher or else an ID of such a note card.
	  NIL otherise.)


    (PROG ((GrapherType (QUOTE (GRAPH BROWSER))))
          (RETURN (OR (FMEMB NoteCardType GrapherType)
		      (AND (NC.IDP NoteCardType)
			   (FMEMB (NC.FetchType NoteCardType)
				  GrapherType)))))))

(NC.SketchBasedP
  (LAMBDA (NoteCardType)                                     (* fgh: "20-Aug-84 01:57")

          (* * Returns T if NoteCardType is a note card type that is based on Sketch or else an ID of such a note card.
	  NIL otherise.)


    (PROG ((SketchType (QUOTE (SKETCH))))
          (RETURN (OR (FMEMB NoteCardType SketchType)
		      (AND (NC.IDP NoteCardType)
			   (FMEMB (NC.FetchType NoteCardType)
				  SketchType)))))))

(NC.FileBoxCollectChildren
  (LAMBDA (WindowOrTextStream ID NewChildren NoDisplayFlg)   (* rht: " 7-Dec-84 20:19")

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


    (PROG (Window ReturnVal)
          (COND
	    (WindowOrTextStream (SETQ Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))))
          (OR ID (SETQ ID (NC.IDFromWindow Window)))
          (COND
	    (NewChildren)
	    (T (NC.PrintMsg Window T " Please select new children." (CHARACTER 13))
	       (SETQ NewChildren (NC.SelectNoteCards NIL NIL NC.SelectingFileBoxChildrenMenu ID))))
          (if (NULL (AND NewChildren ID (for NewChildID in NewChildren bind OneHook
					   when (NC.MakeChildLink NewChildID ID Window)
					   do (SETQ OneHook T) finally (RETURN OneHook))))
	      then (OR NoDisplayFlg (NC.PrintMsg Window NIL 
						 "No appropriate NoteCards or FileBoxes chosen."
						 (CHARACTER 13)
						 "Hence no children added."
						 (CHARACTER 13)))
		   (SETQ ReturnVal NIL)
	    else (SETQ ReturnVal ID))
          (AND Window (GETPROMPTWINDOW Window NIL NIL T)
	       (PROG1 (DISMISS 1000)
		      (NC.ClearMsg Window T)))
          (RETURN ReturnVal))))
)
(DECLARE: DONTCOPY 
(FILESLOAD (FROM {ERIS}<LISP>HARMONY>LIBRARY> LOADCOMP)
	   SKETCH SKETCHOBJ)

(FILESLOAD (FROM {PHYLUM}<NOTECARDS>MAPS> LOADCOMP)
	   NEWMAP)
)

(PUTPROPS CREATE.SKETCHW.COMMANDMENU READVICE (NIL (AFTER NIL (NC.RemoveSketchMenuItems !VALUE))))
(READVISE CREATE.SKETCHW.COMMANDMENU)
(SETQ TEDIT.DEFAULT.PROPS (CONS (QUOTE SLOWUPDATE)
				(CONS (QUOTE T)
				      TEDIT.DEFAULT.PROPS)))
(* * Hooks into Grapher for NoteCards applications)

(DEFINEQ

(NC.GraphAddNodeFn
  (LAMBDA (Graph Window)                                     (* rht: " 3-Feb-85 23:38")

          (* * Add a node, normal or link, to a graph)



          (* * rht 11/9/84: Now checks result of NC.MakeLink before building link.)


    (PROG (LinkLabel Link (GraphID (NC.IDFromWindow Window)))
          (RETURN (COND
		    ((NULL (WINDOWPROP Window (QUOTE NoteCardInsertingLink)
				       NIL))
		      (NC.MarkCardDirty GraphID)
		      (DEFAULT.ADDNODEFN Graph Window))
		    ((AND (SETQ LinkLabel (NC.AskLinkLabel Window NIL NIL T T))
			  (SETQ Link (NC.MakeLink Window LinkLabel)))
		      (NC.MarkCardDirty GraphID)
		      (NODECREATE (for bind NodeID unless (FASSOC (SETQ NodeID (GENSYM))
								  (fetch (GRAPH GRAPHNODES)
								     of Graph))
				     do (RETURN NodeID))
				  (NC.MakeLinkIcon Link)
				  (CURSORPOSITION NIL Window))))))))

(NC.GraphDeleteNodeFn
  (LAMBDA (Node Graph Window)                                (* rht: " 3-Feb-85 23:49")

          (* * Just mark the card as dirty.)


    (PROG ((GraphID (NC.IDFromWindow Window)))
          (NC.MarkCardDirty GraphID))))

(NC.GraphAddLinkFn
  (LAMBDA (From To Graph Window)                             (* rht: " 3-Feb-85 23:49")

          (* * Just mark the card as dirty.)


    (PROG ((GraphID (NC.IDFromWindow Window)))
          (NC.MarkCardDirty GraphID))))

(NC.GraphDeleteLinkFn
  (LAMBDA (From To Graph Window)                             (* rht: " 3-Feb-85 23:50")

          (* * Just mark the card as dirty.)


    (PROG ((GraphID (NC.IDFromWindow Window)))
          (NC.MarkCardDirty GraphID))))

(NC.GraphMoveNodeFn
  (LAMBDA (Node Newpos Graph Window)                         (* rht: " 3-Feb-85 23:45")

          (* * Just mark the card as dirty.)


    (PROG ((GraphID (NC.IDFromWindow Window)))
          (NC.MarkCardDirty GraphID))))

(NC.GraphFontChangeFn
  (LAMBDA (How Node Graph Window)                            (* rht: " 3-Feb-85 23:50")

          (* * Just mark the card as dirty.)


    (PROG ((GraphID (NC.IDFromWindow Window)))
          (NC.MarkCardDirty GraphID))))
)
(* * BROWSER And Search mechanisms)

(DEFINEQ

(NC.ChooseBrowseOrSearch
  (LAMBDA NIL                                                (* rht: " 4-Sep-84 18:34")
                                                             (* Asks the user whether a browser or search is desired
							     an calls the appropriate function to do the work.)

          (* * rht 9/4/84: Added entry in the menu for Link Index.)


    (PROG (Menu W Z (Font (FONTCREATE (QUOTE HELVETICA)
				      12
				      (QUOTE BOLD))))
          (SETQ Menu (OR (AND (BOUNDP (QUOTE NC.BrowseOrSearchMenu))
			      (type? MENU NC.BrowseOrSearchMenu)
			      NC.BrowseOrSearchMenu)
			 (SETQ NC.BrowseOrSearchMenu (create MENU
							     ITEMS ←(QUOTE (Browse Search Link% Index)
									   )
							     MENUFONT ← Font
							     ITEMHEIGHT ←(IPLUS 2
										(FONTPROP
										  Font
										  (QUOTE HEIGHT)))
							     TITLE ← "Which?"))))
          (SETQ W (MENUITEMREGION (CAR (NTH (fetch (MENU ITEMS) of NC.MainMenu)
					    1))
				  NC.MainMenu))
          (SETQ Z (WINDOWPROP (WFROMMENU NC.MainMenu)
			      (QUOTE REGION)))
          (replace MENUPOSITION of Menu with (CONS (IPLUS (fetch (REGION LEFT) of W)
							  (fetch (REGION LEFT) of Z))
						   (IPLUS (fetch (REGION TOP) of W)
							  (fetch (REGION BOTTOM) of Z)
							  (IMINUS (fetch (MENU IMAGEHEIGHT)
								     of Menu)))))
          (RETURN (SELECTQ (MENU Menu)
			   (Browse (NC.MakeNoteCard (QUOTE BROWSER)))
			   (Search (NC.SearchForCards))
			   (Link% Index (NC.MakeLinkIndex))
			   NIL)))))

(NC.GrowLinkLattice
  (LAMBDA (RootID CurrentGraph ListOfLinkLabels GraphID DatabaseStream)
                                                             (* rht: "15-Jan-85 17:15")

          (* Grow a lattice by following the links from RootID card among ListOfLinkLabels. Lattice will be fed to 
	  LAYOUTGRAPH, so for each note card encountered by following the links just fill in the ID, LABEL and daughter IDs)



          (* * rht 8/3/84: Changed so as to also follow from links if they are present (prefixed by "←") on ListOfLinkLabels.)



          (* * rht 10/4/84: Now stores the link label on the prop list of the NODEID of the graph under the property name of 
	  the destination ID. This is so that links can be drawn with dashing depending on the link's label.)


    (PROG (ToLinks FromLinks DestinationIDs GraphRootID (StartingIDChar (ADD1 (NCHARS GraphID))))
          (SETQ GraphRootID (PACK* GraphID RootID))
          (COND
	    ((FASSOC GraphRootID CurrentGraph)
	      (RETURN CurrentGraph))
	    ((NC.ActiveCardP RootID)
	      (SETQ ToLinks (NC.FetchToLinks RootID))
	      (SETQ FromLinks (NC.FetchFromLinks RootID)))
	    (T (WITH.MONITOR (NC.FetchMonitor DatabaseStream "NC.GrowLinkLattice")
			     (NC.GetLinks RootID DatabaseStream)
			     (SETQ ToLinks (NC.FetchToLinks RootID))
			     (SETQ FromLinks (NC.FetchFromLinks RootID)))))
                                                             (* Crush the ID's proplist.)
          (SETPROPLIST GraphRootID NIL)
          (SETQ DestinationIDs (NCONC (for Link in ToLinks bind DestID
					 when (OR (NULL ListOfLinkLabels)
						  (NC.LinkLabelP Link ListOfLinkLabels))
					 collect (ADDPROP GraphRootID (SETQ DestID
							    (PACK* GraphID (fetch (NOTECARDLINK
										    DESTINATIONID)
									      of Link)))
							  (fetch (NOTECARDLINK LINKLABEL)
							     of Link)
							  T)
						 DestID)
				      (for Link in FromLinks bind DestID
					 when (OR (NULL ListOfLinkLabels)
						  (NC.ReverseLinkLabelP Link ListOfLinkLabels))
					 collect (ADDPROP GraphRootID (SETQ DestID
							    (PACK* GraphID (fetch (NOTECARDLINK
										    SOURCEID)
									      of Link)))
							  (PACK* (QUOTE ←)
								 (fetch (NOTECARDLINK LINKLABEL)
								    of Link))
							  T)
						 DestID)))
          (SETQ DestinationIDs (INTERSECTION DestinationIDs DestinationIDs))
          (SETQ CurrentGraph (NCONC CurrentGraph
				    (LIST (create GRAPHNODE
						  NODEID ← GraphRootID
						  TONODES ← DestinationIDs
						  NODELABEL ← RootID))))
          (for DestinationID in DestinationIDs when (NOT (FASSOC DestinationID CurrentGraph))
	     do (NC.GrowLinkLattice (SUBATOM DestinationID StartingIDChar)
				    CurrentGraph ListOfLinkLabels GraphID DatabaseStream))
          (RETURN CurrentGraph))))

(NC.UpdateBrowserCard
  (LAMBDA (Window)                                           (* rht: " 3-Feb-85 23:53")

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



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


    (PROG (ID LinkLabels RootIDs RootNodes Lattice LinkIcon Graph NodeLabel OldNode Link PropList 
	      BrowserSpecs)
          (DETACHALLWINDOWS Window)
          (NC.PrintMsg Window T (CHARACTER 13)
		       "Computing browser graph. Please wait. ...")
          (SETQ ID (NC.IDFromWindow Window))
          (SETQ PropList (NC.FetchPropList ID))
          (SETQ LinkLabels (CAR (LISTGET PropList (QUOTE BrowserLinkLabels))))
          (SETQ RootIDs (MKLIST (LISTGET PropList (QUOTE BrowserRoot))))
          (SETQ BrowserSpecs (OR (CAR (LISTGET PropList (QUOTE BrowserSpecs)))
				 (create BrowserSpecs)))
          (SETQ Graph (fetch (GRAPH GRAPHNODES) of (WINDOWPROP Window (QUOTE GRAPH))))
          (SETQ RootNodes (for RootID in RootIDs
			     collect (SETQ Lattice (NC.GrowLinkLattice RootID Lattice 
								       ListOfLinkLabels ID 
								       PSA.Database))
				     (PACK* ID RootID)))
          (NC.MakeLinksLegend Lattice Window)
          (LISTPUT PropList (QUOTE BrowserLinksLegend)
		   (WINDOWPROP Window (QUOTE NCLABELPAIRS)))
          (NC.SetPropListDirtyFlg ID T)                      (* Remove all links that are in the old browser graph 
							     but not in the new one)
          (for Node in Graph when (AND (NOT (FASSOC (fetch (GRAPHNODE NODEID) of Node)
						    Lattice))
				       (NC.LinkIconImageObjP (SETQ LinkIcon (fetch (GRAPHNODE 
											NODELABEL)
									       of Node))))
	     do (WITH.MONITOR (NC.FetchMonitor PSA.Database)
			      (SETQ Link (NC.FetchLinkFromLinkIcon LinkIcon))
			      (NC.DelToLink Link PSA.Database)
			      (NC.DelFromLink Link PSA.Database T)))
                                                             (* Create Links for all nodes in the new browser graph 
							     but not in the old one.)
          (for Node in Lattice
	     do (COND
		  ((AND (SETQ OldNode (FASSOC (fetch (GRAPHNODE NODEID) of Node)
					      Graph))
			(NC.LinkIconImageObjP (SETQ LinkIcon (fetch (GRAPHNODE NODELABEL)
								of OldNode)))))
		  (T (SETQ LinkIcon (NC.MakeLinkIcon (NC.MakeLink Window NC.BrowserContentsLinkLabel
								  (fetch (GRAPHNODE NODELABEL)
								     of Node)
								  ID
								  (QUOTE Title))))))
		(replace (GRAPHNODE NODELABEL) of Node with LinkIcon))
          (SETQ Graph (LAYOUTGRAPH Lattice RootNodes (fetch (BrowserSpecs Format) of BrowserSpecs)
				   (fetch (BrowserSpecs Font) of BrowserSpecs)
				   (fetch (BrowserSpecs MotherD) of BrowserSpecs)
				   (fetch (BrowserSpecs PersonalD) of BrowserSpecs)
				   (fetch (BrowserSpecs FamilyD) of BrowserSpecs)))
          (replace (GRAPH GRAPH.ADDNODEFN) of Graph with (FUNCTION NC.StructEditAddNodeFn))
          (replace (GRAPH GRAPH.DELETENODEFN) of Graph with (FUNCTION NC.StructEditDeleteNodeFn))
          (replace (GRAPH GRAPH.ADDLINKFN) of Graph with (FUNCTION NC.StructEditAddLinkFn))
          (replace (GRAPH GRAPH.DELETELINKFN) of Graph with (FUNCTION NC.StructEditDeleteLinkFn))
          (replace (GRAPH GRAPH.MOVENODEFN) of Graph with (FUNCTION NC.GraphMoveNodeFn))
          (replace (GRAPH GRAPH.FONTCHANGEFN) of Graph with (FUNCTION NC.GraphFontChangeFn))
          (SHOWGRAPH Graph Window (FUNCTION NC.GraphCardLeftButtonFn)
		     (FUNCTION NC.GraphCardMiddleButtonFn)
		     NIL T)
          (NC.SetSubstance (NC.IDFromWindow Window)
			   (WINDOWPROP Window (QUOTE GRAPH)))
          (OR (EQ (WINDOWPROP Window (QUOTE BUTTONEVENTFN))
		  (FUNCTION NC.TitleBarButtonEventFn))
	      (WINDOWPROP Window (QUOTE OLDBUTTONEVENTFN)
			  (WINDOWPROP Window (QUOTE BUTTONEVENTFN)
				      (FUNCTION NC.TitleBarButtonEventFn))))
          (NC.ClearMsg Window T))))

(NC.SubContentsLinkP
  (LAMBDA (Link)                                             (* NoteCards% User " 5-Jun-84 17:28")
    (COND
      ((EQ NC.SubBoxLinkLabel (fetch (NOTECARDLINK LINKLABEL) of Link))
	T)
      (T NIL))))

(NC.ContentsLinkP
  (LAMBDA (Link)                                             (* NoteCards% User " 5-Jun-84 17:28")
    (COND
      ((EQ NC.FiledCardLinkLabel (fetch (NOTECARDLINK LINKLABEL) of Link))
	T)
      (T NIL))))

(NC.NotBrowserHookP
  (LAMBDA (Link)                                             (* NoteCards% User " 5-Jun-84 17:29")
    (COND
      ((EQ (fetch (NOTECARDLINK LINKLABEL) of Link)
	   NC.BrowserContentsLinkLabel)
	NIL)
      (T T))))

(NC.SearchForCards
  (LAMBDA NIL                                                (* rht: "31-Jan-85 21:23")

          (* Search for cards with specified characteristics and create a list card containing pointers to these cards.
	  For now search is limited to cards whose title contains a specified string.)


    (PROG (SearchString ListCardID IDs Window)
          (SPAWN.MOUSE)
          (SETQ SearchString (NC.AskUser "Please enter the search string" " -- " NIL T))
          (COND
	    ((OR (EQUAL SearchString "")
		 (NOT SearchString))
	      (RETURN)))
          (SETQ Window (NC.MakeNoteCard (QUOTE TEXT)
					(CONCAT "Cards with %"" SearchString "%" in title")))
          (SETQ ListCardID (NC.IDFromWindow Window))
          (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
		    (NC.PrintMsg Window T "Searching for cards ...")
		    (SETQ IDs (bind Title ID for ID# from 1 to (SUB1 (SUBATOM (NC.GetNewID 
										     PSA.Database T)
									      3))
				 when (AND (SETQ Title (NC.FetchTitle (SETQ ID (NC.IDFromNumber
									  ID#))))
					   (STRPOS SearchString Title))
				 collect ID))
		    (TEDIT.INSERT (NC.FetchSubstance ListCardID)
				  (CONCAT " List compiled on: " (DATE)
					  (CHARACTER 13))
				  1)
		    (for ID in IDs unless (EQ ListCardID ID) do (NC.InsertLinkBeforeMarker
								  ListCardID ID 
								  NC.ListContentsLinkLabel
								  (QUOTE Title)
								  NIL PSA.Database))
		    (NC.PrintMsg Window NIL "Done!" (CHARACTER 13)))
          (BLOCK 250)
          (NC.ClearMsg Window T)
          (RETURN))))

(NC.AskBrowserSpecs
  (LAMBDA (BrowserWindow)                                    (* fgh: "13-Aug-84 23:46")

          (* * Get the specification for laying out a browser graph from the user and return them in a BrowserSpecs record.)


    (PROG (BrowserSpecs)
          (OR (WINDOWP BrowserWindow)
	      (SETQ BrowserWindow))
          (SETQ BrowserSpecs (create BrowserSpecs
				     Format ←(LIST (COND
						     ((MEMBER (NC.AskUser 
							      "Should this be a compact browser?"
									  " -- " "No" T BrowserWindow 
									  T)
							      (QUOTE ("Yes" "yes" "Y" "y" "Ye" "ye")))
						       (QUOTE COMPACT))
						     (T (QUOTE LATTICE)))
						   (COND
						     ((MEMBER (NC.AskUser 
							     "Should this be a vertical browser?"
									  " -- " "No" T BrowserWindow 
									  T)
							      (QUOTE ("Yes" "yes" "Y" "y" "Ye" "ye")))
						       (QUOTE VERTICAL))
						     (T (QUOTE HORIZONTAL))))
				     Font ← NIL
				     MotherD ←(FIXP (MKATOM (NC.AskUser 
							  "What is the MotherD for this browser?"
									" -- " NIL T BrowserWindow T))
						    )
				     PersonalD ←(FIXP (MKATOM (OR (NC.AskUser 
							 "What is the PersoalD for this browser?"
									      " -- " NIL T 
									      BrowserWindow T)
								  10)))
				     FamilyD ←(FIXP (MKATOM (NC.AskUser 
							  "What is the FamilyD for this browser?"
									" -- " NIL T BrowserWindow T))
						    )))
          (RETURN BrowserSpecs))))
)
(* * Grapher hacks for browser)


(PUTPROPS DRAWLINE-IN-DISPLAYLINK/LR READVICE ((DISPLAYLINK/LR . DRAWLINE)
					       (BEFORE NIL (RETURN (PROG (Pos)
									 (SETQ Pos
									       (STKPOS (QUOTE 
										   DISPLAYLINK/LR)
										       -1))
									 (NC.GraphDisplayLinkFn
									   (STKARG 2 Pos)
									   (STKARG 3 Pos)
									   X1 Y1 X2 Y2 WIDTH 
									   OPERATION STREAM COLOR)
									 (RELSTK Pos))))))

(PUTPROPS DRAWLINE-IN-DISPLAYLINK/TB READVICE ((DISPLAYLINK/TB . DRAWLINE)
					       (BEFORE NIL (RETURN (PROG (Pos)
									 (SETQ Pos
									       (STKPOS (QUOTE 
										   DISPLAYLINK/TB)
										       -1))
									 (NC.GraphDisplayLinkFn
									   (STKARG 2 Pos)
									   (STKARG 3 Pos)
									   X1 Y1 X2 Y2 WIDTH 
									   OPERATION STREAM COLOR)
									 (RELSTK Pos))))))
(READVISE DRAWLINE-IN-DISPLAYLINK/LR DRAWLINE-IN-DISPLAYLINK/TB)
(DEFINEQ

(NC.MakeLinksLegend
  (LAMBDA (Lattice Win)                                      (* rht: "19-Oct-84 18:09")

          (* * For every node in the lattice, there should be properties off of its NODEID for each node it's connected to.
	  The values of these props are lists of linklabels. Change these values to also contain the dashing number by 
	  assigning a unique dashing number to each new label we come across. If the global var NC.LinkDashingInBrowser is 
	  non-nil, then put out a menu serving as a legend mapping link label names to dashing styles.
	  If not, then the menu just contains names of link labels.)


    (PROG (LabelPairs (Region (WINDOWPROP Win (QUOTE REGION)))
		      (MaxDashingStylesNum (LENGTH NC.DashingStyles)))
          (for Node in Lattice bind NodeID (LabelNum ← 0)
	     do (SETQ NodeID (fetch (GRAPHNODE NODEID) of Node))
		(for DestNodeID in (fetch (GRAPHNODE TONODES) of Node)
		   do (PUTPROP NodeID DestNodeID (for Label in (GETPROP NodeID DestNodeID)
						    bind Pair
						    collect (COND
							      ((NULL (SETQ Pair (FASSOC Label 
										       LabelPairs)))
								(SETQ Pair
								  (CONS Label (COND
									  ((ILESSP LabelNum 
									      MaxDashingStylesNum)
									    (SETQ LabelNum
									      (ADD1 LabelNum)))
									  (T LabelNum))))
								(SETQ LabelPairs (CONS Pair 
										       LabelPairs))))
							    Pair))))
          (SETQ LabelPairs (DREVERSE LabelPairs))
          (AND Win (NC.MakeLinksLegendMenu Win LabelPairs))
          (RETURN LabelPairs))))

(NC.MakeLinksLegendMenu
  (LAMBDA (Win LabelPairs)                                   (* rht: "10-Jan-85 17:37")

          (* * Build a links legend menu and attach to Win)



          (* * rht 1/10/85: Before starting, kill any old links legend menus for Win.)


    (PROG (Menu MenuWin PromptWin MainWinPromptInfo)
          (for AttachedWin in (ATTACHEDWINDOWS Win) when (WINDOWPROP AttachedWin (QUOTE 
										  LINKSLEGENDWINP))
	     do (CLOSEW AttachedWin))
          (SETQ Menu (COND
	      (NC.LinkDashingInBrowser (create MENU
					       ITEMS ←(for Pair in LabelPairs
							 join (LIST (CAR Pair)
								    (LIST (QUOTE "   "))))
					       TITLE ←(QUOTE Links)
					       MENUCOLUMNS ← 2))
	      (T (create MENU
			 ITEMS ←(for Pair in LabelPairs collect (CAR Pair))
			 TITLE ←(QUOTE Links)
			 MENUCOLUMNS ← 1))))
          (SETQ MenuWin (MENUWINDOW Menu))
          (WINDOWADDPROP MenuWin (QUOTE REPAINTFN)
			 (QUOTE NC.LinksLegendRepaintFn))
          (WINDOWADDPROP MenuWin (QUOTE RESHAPEFN)
			 (QUOTE NC.LinksLegendReshapeFn))
          (WINDOWADDPROP MenuWin (QUOTE LINKSLEGENDWINP)
			 T)
          (WINDOWPROP Win (QUOTE NCLABELPAIRS)
		      LabelPairs)                            (* Detach the prompt window for a second, saving the 
							     prompt window info from the main win's props.)
          (if (SETQ PromptWin (GETPROMPTWINDOW Win NIL NIL T))
	      then (SETQ MainWinPromptInfo (WINDOWPROP Win (QUOTE PROMPTWINDOW)))
		   (DETACHWINDOW PromptWin))                 (* Stick the links legend window at lower right 
							     corner.)
          (ATTACHWINDOW MenuWin Win (QUOTE RIGHT)
			(QUOTE TOP)
			(QUOTE LOCALCLOSE))                  (* Put back the prompt window if it exists.)
          (if PromptWin
	      then (ATTACHWINDOW PromptWin Win (QUOTE TOP)
				 (QUOTE LEFT)
				 (QUOTE HERE))
		   (WINDOWPROP Win (QUOTE PROMPTWINDOW)
			       MainWinPromptInfo))           (* These CLOSEFNs added to get around a problem with 
							     ATTACHEDWINDOW package.)
          (for AttachedWin in (ATTACHEDWINDOWS Win) do (WINDOWADDPROP AttachedWin (QUOTE CLOSEFN)
								      (QUOTE DETACHWINDOW)))
          (OPENW MenuWin)
          (MOVEW Win (MAKEWITHINREGION (WINDOWREGION Win)
				       WHOLESCREEN))
          (AND NC.LinkDashingInBrowser (NC.LinksLegendRepaintFn MenuWin NIL))
      NIL)))

(NC.LinksLegendRepaintFn
  (LAMBDA (Win Region)                                       (* rht: "15-Oct-84 14:34")

          (* * Repaint the right-hand column dashing in the browser's links legend menu.)


    (PROG ((Menu (CAR (WINDOWPROP Win (QUOTE MENU))))
	   Items
	   (LabelPairs (WINDOWPROP (MAINWINDOW Win)
				   (QUOTE NCLABELPAIRS))))
          (SETQ Items (fetch (MENU ITEMS) of Menu))
          (for Item in (CDR Items) by (CDDR Item) as LabelPair in LabelPairs bind ItemRegion LeftPos 
										  RightPos
	     do (SETQ ItemRegion (MENUITEMREGION Item Menu))
		(SETQ LeftPos (create POSITION
				      XCOORD ←(IPLUS 4 (fetch (REGION LEFT) of ItemRegion))
				      YCOORD ←(IPLUS (LRSH (fetch (REGION HEIGHT) of ItemRegion)
							   1)
						     (fetch (REGION BOTTOM) of ItemRegion))))
		(SETQ RightPos (create POSITION
				       XCOORD ←(IDIFFERENCE (IPLUS (fetch (REGION WIDTH)
								      of ItemRegion)
								   (fetch (REGION LEFT) of ItemRegion)
								   )
							    4)
				       YCOORD ←(IPLUS (LRSH (fetch (REGION HEIGHT) of ItemRegion)
							    1)
						      (fetch (REGION BOTTOM) of ItemRegion))))
		(DRAWCURVE (LIST LeftPos RightPos)
			   NIL NIL (CAR (FNTH NC.DashingStyles (CDR LabelPair)))
			   Win)))))

(NC.GraphDisplayLinkFn
  (LAMBDA (Node1 Node2 X1 Y1 X2 Y2 Width Operation Stream Color)
                                                             (* rht: "15-Jan-85 09:45")

          (* * Expects to find a list of pairs on Node1's ID's proplist under the property with name Node2's ID 
	  (or vice versa) These are pairs of label and dashing number. For each one, draw a spline with one knot using given 
	  dashing number. The more we draw, the farther each gets from the center line. The very first is along the center 
	  line. Subsequent splines alternate on either side of the center line. If NC.LinkDashingInBrowser is nil, then just 
	  draw one straight solid link as before.)


    (COND
      (NC.LinkDashingInBrowser (for Pair in (OR (GETPROP (fetch (GRAPHNODE NODEID) of Node1)
							 (fetch (GRAPHNODE NODEID) of Node2))
						(GETPROP (fetch (GRAPHNODE NODEID) of Node2)
							 (fetch (GRAPHNODE NODEID) of Node1)))
				  as i from 0 do (NC.GraphDrawFlowerLink X1 Y1 X2 Y2
									 (LIST (QUOTE ROUND)
									       Width Color)
									 (CAR (FNTH NC.DashingStyles
										    (CDR Pair)))
									 i Stream Width Operation 
									 Color)))
      (T (DRAWLINE X1 Y1 X2 Y2 Width Operation Stream Color)))))

(NC.GraphDrawFlowerLink
  (LAMBDA (X1 Y1 X2 Y2 Brush Dashing Num Win Width Operation Color)
                                                             (* rht: "15-Jan-85 09:45")

          (* * Draw one link between given points according to given Dashing. If Num is 0, then draw straight line.
	  Otherwise, draw curves above for odd Num and below for even Num, getting wider for bigger values of Num.)


    (PROG ((MidpointX (LRSH (IPLUS X1 X2)
			    1))
	   (MidpointY (LRSH (IPLUS Y1 Y2)
			    1)))
          (COND
	    ((ZEROP Num)
	      (NC.DrawDashedLine X1 Y1 X2 Y2 Width Operation Win Color Dashing))
	    (T (SETQ MidpointY (COND
		   ((ODDP Num)
		     (IPLUS MidpointY (ITIMES NC.GraphFlowerLinkSeparation (LRSH (ADD1 Num)
										 1))))
		   (T (IDIFFERENCE MidpointY (ITIMES NC.GraphFlowerLinkSeparation
						     (LRSH (ADD1 Num)
							   1))))))
	       (DRAWCURVE (LIST (CONS X1 Y1)
				(CONS MidpointX MidpointY)
				(CONS X2 Y2))
			  NIL Brush Dashing Win))))))

(NC.LinksLegendReshapeFn
  (LAMBDA (Window OldImage OldRegion)                        (* rht: " 7-Dec-84 12:15")

          (* * Called when main window is reshaped. Just redisplays the links legend.)


    (REDISPLAYW Window)))

(NC.DrawDashedLine
  (LAMBDA (X1 Y1 X2 Y2 WIDTH OPERATION STREAM COLOR DASHING)
                                                             (* rht: "14-Jan-85 15:11")

          (* * Direct theft of the intermezzo DRAWDASHEDLINE code. When we move to Intermezzo, throw this away.)


    (PROG ((DASHON T)
	   (DASHTAIL DASHING)
	   DASHCNT
	   (ADJACENT (IDIFFERENCE X2 X1))
	   (OPPOSITE (IDIFFERENCE Y2 Y1))
	   (LENGTHDRAWN 0)
	   NEWX NEWY LINELENGTH SINE COSINE)
          (SETQ LINELENGTH (FIX (SQRT (IPLUS (ITIMES ADJACENT ADJACENT)
					     (ITIMES OPPOSITE OPPOSITE)))))
          (SETQ SINE (FQUOTIENT OPPOSITE LINELENGTH))
          (SETQ COSINE (FQUOTIENT ADJACENT LINELENGTH))
          (while (ILESSP LENGTHDRAWN LINELENGTH)
	     do (SETQ DASHCNT (CAR DASHTAIL))
		(SETQ DASHTAIL (CDR DASHTAIL))
		(add LENGTHDRAWN DASHCNT)
		(SETQ NEWX (FPLUS X1 (FTIMES COSINE DASHCNT)))
		(SETQ NEWY (FPLUS Y1 (FTIMES SINE DASHCNT)))
		(COND
		  (DASHON (DRAWLINE X1 Y1 NEWX NEWY WIDTH OPERATION STREAM COLOR))
		  (T (RELMOVETO NEWX NEWY STREAM)))
		(SETQ DASHON (NOT DASHON))
		(SETQ X1 NEWX)
		(SETQ Y1 NEWY)
		(COND
		  ((NULL DASHTAIL)
		    (SETQ DASHTAIL DASHING)))))))

(NC.RelayoutGraphCard
  (LAMBDA (Window)                                           (* rht: "15-Jan-85 14:18")

          (* * Called from the middle button of a graph or browser or structedit card. This lays out and displays the graph, 
	  but does not recompute the nodes.)


    (PROG (ID Graph OldGraph PropList BrowserSpecs)
          (NC.PrintMsg Window T (CHARACTER 13)
		       "Laying out graph. Please wait. ...")
          (SETQ ID (NC.IDFromWindow Window))
          (SETQ PropList (NC.FetchPropList ID))
          (SETQ BrowserSpecs (OR (CAR (LISTGET PropList (QUOTE BrowserSpecs)))
				 (create BrowserSpecs)))
          (SETQ Graph (LAYOUTGRAPH (SETQ OldGraph (fetch (GRAPH GRAPHNODES)
						     of (WINDOWPROP Window (QUOTE GRAPH))))
				   (LIST (CAAR OldGraph))
				   (fetch (BrowserSpecs Format) of BrowserSpecs)
				   (fetch (BrowserSpecs Font) of BrowserSpecs)
				   (fetch (BrowserSpecs MotherD) of BrowserSpecs)
				   (fetch (BrowserSpecs PersonalD) of BrowserSpecs)
				   (fetch (BrowserSpecs FamilyD) of BrowserSpecs)))
          (replace (GRAPH GRAPH.ADDNODEFN) of Graph with (FUNCTION NC.StructEditAddNodeFn))
          (replace (GRAPH GRAPH.DELETENODEFN) of Graph with (FUNCTION NC.StructEditDeleteNodeFn))
          (replace (GRAPH GRAPH.ADDLINKFN) of Graph with (FUNCTION NC.StructEditAddLinkFn))
          (replace (GRAPH GRAPH.DELETELINKFN) of Graph with (FUNCTION NC.StructEditDeleteLinkFn))
          (SHOWGRAPH Graph Window (FUNCTION NC.GraphCardLeftButtonFn)
		     (FUNCTION NC.GraphCardMiddleButtonFn)
		     NIL T)
          (NC.SetSubstance ID (WINDOWPROP Window (QUOTE GRAPH)))
          (OR (EQ (WINDOWPROP Window (QUOTE BUTTONEVENTFN))
		  (FUNCTION NC.TitleBarButtonEventFn))
	      (WINDOWPROP Window (QUOTE OLDBUTTONEVENTFN)
			  (WINDOWPROP Window (QUOTE BUTTONEVENTFN)
				      (FUNCTION NC.TitleBarButtonEventFn))))
          (NC.ClearMsg Window T))))
)
(* * MakeDocument stuff)

(DEFINEQ

(NC.MakeDocument
  (LAMBDA (ID Title NoDisplayFlg WindowOrTextStreamOrID)     (* rht: "21-Nov-84 15:30")

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


    (PROG (RootID RootTitle DocWindow DocCardID DocWindowOrID DocStream HeadingsFromFileboxes 
		  TitlesFromNoteCards BuildBackLinks CopyEmbeddedLinks ExpandEmbeddedLinks InspectWin 
		  WasActive)
          (OR NoDisplayFlg (SPAWN.MOUSE))
          (SETQ DocWindowOrID (NC.MakeNoteCard (QUOTE Text)
					       "Document" NoDisplayFlg NIL ID))
          (COND
	    (NoDisplayFlg (SETQ DocWindow NIL)
			  (SETQ DocCardID DocWindowOrID))
	    (T (SETQ DocWindow DocWindowOrID)
	       (SETQ DocCardID (NC.IDFromWindow DocWindow))))
                                                             (* NC.MakeNoteCard either returned an ID or a window 
							     depending on NoDisplayFlg.)
          (SETQ RootTitle (NC.FetchTitle (SETQ RootID (COND
					     ((NC.IDP WindowOrTextStreamOrID)
					       WindowOrTextStreamOrID)
					     ((TEXTSTREAMP WindowOrTextStreamOrID)
					       (NC.IDFromWindow (WINDOW.FROM.TEDIT.THING 
									   WindowOrTextStreamOrID)))
					     ((WINDOWP WindowOrTextStreamOrID)
					       (NC.IDFromWindow WindowOrTextStreamOrID))
					     (T (PROGN (NC.PrintMsg DocWindow T 
			"Please select the Note Card or File Box the document should start from."
								    (CHARACTER 13))
						       (NC.SelectNoteCards T NIL 
								    NC.SelectingBrowserSourceMenu 
									   DocWindow)))))))
          (if (NOT RootID)
	      then (NC.DeleteNoteCards ID T)
		   (RETURN NIL))
          (NC.SetTitle DocCardID (CONCAT "Document from %"" RootTitle "%""))
          (AND DocWindow (WINDOWPROP DocWindow (QUOTE TITLE)
				     (NC.FetchTitle DocCardID)))
          (SETQ DocStream (NC.FetchSubstance DocCardID))

          (* * 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 ID 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 ... ")
		    (OR (SETQ WasActive (NC.ActiveCardP RootID))
			(NC.GetNoteCard RootID PSA.Database))
		    (SELECTQ (NC.RetrieveType RootID PSA.Database)
			     (FileBox (NC.DumpFileBoxToDoc RootID DocCardID DocStream "" 
							   HeadingsFromFileboxes TitlesFromNoteCards 
							   BuildBackLinks CopyEmbeddedLinks 
							   ExpandEmbeddedLinks T))
			     (Text (NC.DumpNoteCardToDoc RootID DocCardID DocStream "" 1 
							 HeadingsFromFileboxes TitlesFromNoteCards 
							 BuildBackLinks CopyEmbeddedLinks 
							 ExpandEmbeddedLinks T))
			     NIL)
		    (OR WasActive (NC.DeactivateCard RootID))

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


		    (RESETSAVE NIL (QUOTE (PROGN (for ID in (GETPROP DocCardID (QUOTE SeenCards))
						    do (REMPROP ID (QUOTE SeenBefore)))
						 (REMPROP DocCardID (QUOTE SeenCards)))))
		    (NC.PrintMsg DocWindow NIL "Done!"))
          (COND
	    ((NOT NoDisplayFlg)
	      (BLOCK 250)
	      (NC.ClearMsg DocWindow T)))
          (RETURN DocWindowOrID))))

(NC.DumpFileBoxToDoc
  (LAMBDA (FileBoxID DocID DocStream CurSection HeadingsFromFileboxes TitlesFromNoteCards 
		     BuildBackLinks CopyEmbeddedLinks ExpandEmbeddedLinks NoInitialCRs)
                                                             (* rht: "21-Nov-84 15:26")

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


    (PROG ((DocObject (TEXTOBJ DocStream)))
          (OR NoInitialCRs (NC.AppendStringToStream DocStream (CONCAT (CHARACTER 13)
								      (CHARACTER 13))))
          (AND (EQ HeadingsFromFileboxes (QUOTE NumberedBold))
	       (NC.AppendStringToStream DocStream (CONCAT CurSection " ")
					T))
          (AND (NEQ HeadingsFromFileboxes (QUOTE NONE))
	       (NC.AppendStringToStream DocStream (CONCAT (NC.FetchTitle FileBoxID))
					T))
          (AND (FMEMB BuildBackLinks (QUOTE (ToBoxes ToCardsBoxes)))
	       (NC.AppendLinkToText DocID FileBoxID NC.DocBackPtrLinkLabel (QUOTE Icon)))
          (COND
	    ((GETPROP FileBoxID (QUOTE SeenBefore))
	      (NC.PrintMsg NIL NIL FileBoxID " only expanded once.")
	      (RETURN)))
          (ADDPROP DocID (QUOTE SeenCards)
		   FileBoxID T)
          (PUTPROP FileBoxID (QUOTE SeenBefore)
		   T)
          (NC.AppendStringToStream DocStream (CONCAT (CHARACTER 13)
						     (CHARACTER 13)))
          (for Link in (NC.FetchToLinksInOrder FileBoxID) bind ChildID ActiveP (SubSectionNum ← 1)
							       (FirstTime ← T)
	     when (FMEMB (fetch (NOTECARDLINK LINKLABEL) of Link)
			 (BQUOTE (, NC.FiledCardLinkLabel , NC.SubBoxLinkLabel)))
	     do (SETQ ChildID (fetch (NOTECARDLINK DESTINATIONID) of Link))
		(SETQ ActiveP (NC.ActiveCardP ChildID))
		(SELECTQ (NC.RetrieveType ChildID PSA.Database)
			 (Text (OR ActiveP (NC.GetNoteCard ChildID PSA.Database))
			       (SETQ SubSectionNum
				 (NC.DumpNoteCardToDoc ChildID DocID DocStream CurSection 
						       SubSectionNum HeadingsFromFileboxes 
						       TitlesFromNoteCards BuildBackLinks 
						       CopyEmbeddedLinks ExpandEmbeddedLinks 
						       FirstTime))
			       (OR ActiveP (NC.DeactivateCard ChildID)))
			 (FileBox (OR ActiveP (NC.GetNoteCard ChildID PSA.Database))
				  (NC.DumpFileBoxToDoc ChildID DocID DocStream
						       (COND
							 ((EQUAL "" CurSection)
							   (CONCAT SubSectionNum))
							 (T (CONCAT CurSection "." SubSectionNum)))
						       HeadingsFromFileboxes TitlesFromNoteCards 
						       BuildBackLinks CopyEmbeddedLinks 
						       ExpandEmbeddedLinks FirstTime)
				  (SETQ SubSectionNum (ADD1 SubSectionNum))
				  (OR ActiveP (NC.DeactivateCard ChildID)))
			 (NC.PrintMsg NIL NIL "Ignoring non-text card " ChildID (CHARACTER 13)))
		(SETQ FirstTime NIL)))))

(NC.DumpNoteCardToDoc
  (LAMBDA (CardID DocID DocStream SectionNum BoxNum HeadingsFromFileboxes TitlesFromNoteCards 
		  BuildBackLinks CopyEmbeddedLinks ExpandEmbeddedLinks NoInitialCRs)
                                                             (* rht: "21-Nov-84 15:30")

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


    (PROG ((CardStream (NC.FetchSubstance CardID))
	   CardObj
	   (DocObj (TEXTOBJ DocStream)))
          (SETQ CardObj (TEXTOBJ CardStream))
          (OR NoInitialCRs (PROGN (NC.AppendStringToStream DocStream (CONCAT (CHARACTER 13)))
				  (AND (NEQ TitlesFromNoteCards (QUOTE NONE))
				       (NC.AppendStringToStream DocStream (CONCAT (CHARACTER 13))))))
          (AND (NEQ TitlesFromNoteCards (QUOTE NONE))
	       (NC.AppendStringToStream DocStream (CONCAT (NC.FetchTitle CardID))
					(EQ TitlesFromNoteCards (QUOTE Bold))))
          (AND (FMEMB BuildBackLinks (QUOTE (ToCards ToCardsBoxes)))
	       (NC.AppendLinkToText DocID CardID NC.DocBackPtrLinkLabel (QUOTE Icon)))
          (COND
	    ((GETPROP CardID (QUOTE SeenBefore))
	      (NC.PrintMsg NIL NIL CardID " only expanded once." (CHARACTER 13))
	      (RETURN)))
          (ADDPROP DocID (QUOTE SeenCards)
		   CardID T)
          (PUTPROP CardID (QUOTE SeenBefore)
		   T)
          (NC.AppendStringToStream DocStream (CONCAT (CHARACTER 13)
						     (CHARACTER 13)))

          (* * 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 ToID (LastLoc ← 1)
		  (CurLoc ← 0)
		  ActiveP ExpandP CopyP AlreadyExpanded
	     do (SETQ LinkSpec (NC.FetchLinkFromLinkIcon (CAR Object)))
		(SETQ LinkLabel (fetch (NOTECARDLINK LINKLABEL) 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)
					      0
					      (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 (GETPROP (SETQ ToID (fetch (NOTECARDLINK DESTINATIONID)
								     of LinkSpec))
						       (QUOTE SeenBefore)))
			ExpandP)
		    (NC.PrintMsg NIL NIL ToID " only expanded once." (CHARACTER 13))))
		(COND
		  ((OR CopyP (AND ExpandP AlreadyExpanded))
                                                             (* Copy this link.)
		    (TEDIT.COPY (TEDIT.SETSEL CardStream CurLoc 1)
				(TEDIT.SETSEL DocStream (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 ToID))
		    (SELECTQ (NC.RetrieveType ToID PSA.Database)
			     (Text (OR ActiveP (NC.GetNoteCard ToID PSA.Database))
				   (SETQ BoxNum
				     (NC.DumpNoteCardToDoc ToID DocID DocStream SectionNum BoxNum 
							   HeadingsFromFileboxes TitlesFromNoteCards 
							   BuildBackLinks CopyEmbeddedLinks 
							   ExpandEmbeddedLinks (EQ CurLoc 1)))
				   (OR ActiveP (NC.DeactivateCard ToID)))
			     (FileBox (OR ActiveP (NC.GetNoteCard ToID PSA.Database))
				      (NC.DumpFileBoxToDoc ToID DocID DocStream
							   (COND
							     ((EQUAL SectionNum "")
							       (CONCAT BoxNum))
							     (T (CONCAT SectionNum "." BoxNum)))
							   HeadingsFromFileboxes TitlesFromNoteCards 
							   BuildBackLinks CopyEmbeddedLinks 
							   ExpandEmbeddedLinks (EQ CurLoc 1))
				      (SETQ BoxNum (ADD1 BoxNum))
				      (OR ActiveP (NC.DeactivateCard ToID)))
			     (NC.PrintMsg NIL NIL "Ignoring non-text card " ToID (CHARACTER 13)))))
	     finally (COND
		       ((ILESSP CurLoc (fetch TEXTLEN of DocObj))
			 (TEDIT.COPY (TEDIT.SETSEL CardStream LastLoc (IDIFFERENCE (fetch TEXTLEN
										      of CardObj)
										   CurLoc))
				     (TEDIT.SETSEL DocStream (fetch TEXTLEN of DocObj)
						   0
						   (QUOTE RIGHT))))))
          (RETURN BoxNum))))

(NC.FetchToLinksInOrder
  (LAMBDA (ID)                                               (* fgh: " 1-Oct-84 21:08")

          (* * Return the list of To links appearing in the text of ID in the order in which they appear.)


    (for ObjectPair in (TEDIT.LIST.OF.OBJECTS (TEXTOBJ (NC.FetchSubstance ID))
					      (FUNCTION NC.LinkIconImageObjP))
       collect (NC.FetchLinkFromLinkIcon (CAR ObjectPair)))))

(NC.AppendLinkToText
  (LAMBDA (SourceID DestinationID LinkLabel DisplayMode)     (* fgh: "28-Sep-84 19:08")

          (* * Insert a link icon in SourceID's textstream at the cursor. This is somewhat like 
	  NC.InsertLinkAndTitleBeforeMarker. Leaves cursor (selection) positioned at end of text ready for insertion.)


    (PROG (TextStream)
          (NC.InsertLinkBeforeMarker SourceID DestinationID LinkLabel DisplayMode 9999 NIL T)
          (SETQ TextStream (NC.FetchSubstance SourceID))
          (TEDIT.SETSEL TextStream (GETEOFPTR TextStream)
			0
			(QUOTE RIGHT)))))

(NC.BuildMakeDocInspector
  (LAMBDA (MainWin)                                          (* rht: " 6-Nov-84 22:28")

          (* * Build and dislay an inspector window on the parameters for making documents.)


    (PROG (InspectWindow Region (PromptWin (GETPROMPTWINDOW MainWin)))
          (SETQ Region (WINDOWPROP (OR PromptWin MainWin)
				   (QUOTE REGION)))
          (SETQ InspectWindow (INSPECTW.CREATE (QUOTE NC.MakeDocParameters)
					       (for Item in NC.MakeDocParameters collect
										  (CAR Item))
					       (FUNCTION GETPROP)
					       NIL "Use left button to change values." NIL
					       (FUNCTION NC.InspectorTitleCommandFn)
					       "MakeDocument Parameters"
					       (FUNCTION NC.MakeDocInspectorSelectionFn)
					       (create POSITION
						       XCOORD ←(fetch LEFT of Region)
						       YCOORD ←(IPLUS (fetch BOTTOM of Region)
								      (fetch HEIGHT of Region)))
					       NIL))
          (MOVEW InspectWindow (MAKEWITHINREGION (WINDOWPROP InspectWindow (QUOTE REGION))
						 WHOLESCREEN))
          (WINDOWPROP InspectWindow (QUOTE NoteCardsMakeDocInspector)
		      T)
          (RETURN InspectWindow))))

(NC.MakeDocInspectorSelectionFn
  (LAMBDA (Property ValueFlg InspectWin)                     (* rht: "17-Nov-84 15:43")

          (* * Called when user buttons in the make document inspector menu on the Property parameter.
	  Put up a menu of choices for new values for this parameter.)



          (* * rht 11/17/84: Now can select --CANCEL--. Notice strange way of checking for --DONE-- versus --CANCEL--.
	  This is because the Inspector package doesn't send the property name in Property arg if ValueFlg is on.
	  That bug has been reported.)


    (PROG (Menu Answer)
          (if (FMEMB Property (QUOTE (--DONE-- --CANCEL--)))
	      then (CLOSEW InspectWin)
		   (if ValueFlg
		       then (PUTPROP (QUOTE NC.MakeDocParameters)
				     (QUOTE --DONE--)
				     (QUOTE QUIT)))
		   (RETURN NIL))
          (AND ValueFlg (RETURN (INSPECTW.SELECTITEM InspectWin)))
          (SETQ Menu (create MENU
			     ITEMS ←(CDR (FASSOC Property NC.MakeDocParameters))
			     TITLE ← "Choose New Value"))
          (SETQ Answer (MENU Menu))
          (COND
	    ((AND Answer (OR (NEQ Answer (QUOTE Select))
			     (SETQ Answer (NC.AskLinkLabel InspectWin T T NIL NIL T))))
	      (PUTPROP (QUOTE NC.MakeDocParameters)
		       Property Answer)
	      (INSPECTW.REDISPLAY InspectWin Property)))
          (INSPECTW.SELECTITEM InspectWin))))

(NC.AppendStringToStream
  (LAMBDA (Stream String BoldFlg)                            (* rht: "16-Nov-84 12:38")

          (* * Add the String to the end of the tedit Stream.)



          (* * rht 11/16/84: Now calls TEDIT.LOOKS in any case, bold or no.)


    (PROG ((StrLen (NCHARS String)))
          (TEDIT.INSERT Stream String (TEDIT.SETSEL Stream (fetch (TEXTOBJ TEXTLEN)
							      of (TEXTOBJ Stream))
						    0
						    (QUOTE RIGHT))
			NIL T)
          (TEDIT.LOOKS Stream (if BoldFlg
				  then (QUOTE (FACE BRR))
				else (QUOTE (FACE MRR)))
		       (ADD1 (IDIFFERENCE (fetch (TEXTOBJ TEXTLEN) of (TEXTOBJ Stream))
					  StrLen))
		       StrLen))))
)
(* * Struct Editor Stuff)

(DEFINEQ

(NC.MakeStructEditCard
  (LAMBDA (ID Title NoDisplayFlg)                            (* rht: " 3-Feb-85 23:50")

          (* * Creates a StructEdit card. Alot like a graph card except that it allows editing of underlying NC structure, and
	  doesn't allow an "insertlink" operation in title bar menu.)


    (PROG (ReturnValue Graph)
          (SETQ ReturnValue (APPLY* (NCP.CardTypeFn (QUOTE Graph)
						    (QUOTE MakeCardFn))
				    ID Title NoDisplayFlg))
          (SETQ Graph (NC.FetchSubstance ID))
          (replace (GRAPH GRAPH.ADDNODEFN) of Graph with (FUNCTION NC.StructEditAddNodeFn))
          (replace (GRAPH GRAPH.DELETENODEFN) of Graph with (FUNCTION NC.StructEditDeleteNodeFn))
          (replace (GRAPH GRAPH.ADDLINKFN) of Graph with (FUNCTION NC.StructEditAddLinkFn))
          (replace (GRAPH GRAPH.DELETELINKFN) of Graph with (FUNCTION NC.StructEditDeleteLinkFn))
          (replace (GRAPH GRAPH.MOVENODEFN) of Graph with (FUNCTION NC.GraphMoveNodeFn))
          (replace (GRAPH GRAPH.FONTCHANGEFN) of Graph with (FUNCTION NC.GraphFontChangeFn))
          (RETURN ReturnValue))))

(NC.FixStructEditTitleBarMenu
  (LAMBDA (Window)                                           (* rht: "12-Jan-85 12:56")

          (* * Remove the InsertLink item from the Window's title bar menu.)


    (PROG ((Menu (WINDOWPROP Window (QUOTE TitleBarLeftButtonMenu)))
	   MenuItems)
          (SETQ MenuItems (fetch (MENU ITEMS) of Menu))
          (replace (MENU ITEMS) of Menu with (for Item in MenuItems when (EQ (CAR Item)
									     (QUOTE Insert% Link))
						do (RETURN (LSUBST NIL Item MenuItems)))))))

(NC.StructEditAddNodeFn
  (LAMBDA (Graph Window)                                     (* rht: " 3-Feb-85 23:27")

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


    (PROG ((Link (NC.MakeLink Window NC.BrowserContentsLinkLabel NIL NIL NIL NIL 
			      "Please select Card or Box."
			      T))
	   (GraphID (NC.IDFromWindow Window))
	   GraphNodeID ID Title)
          (COND
	    (Link (COND
		    ((FASSOC (SETQ GraphNodeID (PACK* GraphID (SETQ ID (fetch (NOTECARDLINK 
										    DESTINATIONID)
									  of Link))))
			     (fetch (GRAPH GRAPHNODES) of Graph))
		      (NC.PrintMsg Window T "Node for card '" (NC.FetchTitle ID)
				   "' already in graph.")
		      (NCP.DeleteLinks Link)
		      (RETURN NIL))
		    ((AND (NC.FetchNewCardFlg ID)
			  (SETQ Title (NC.AskUser "Title of new card: " "--" NIL T Window)))
		      (NC.SetTitle ID Title)))
		  (NC.MarkCardDirty GraphID)
		  (RETURN (NODECREATE GraphNodeID (NC.MakeLinkIcon Link)
				      (CURSORPOSITION NIL Window))))))))

(NC.StructEditAddLinkFn
  (LAMBDA (FromNode ToNode Graph Window)                     (* rht: " 3-Feb-85 23:27")

          (* * Called by grapher when user creates a new link.)


    (PROG ((GraphID (NC.IDFromWindow Window))
	   SourceID SourceType DestinationID LinkLabel StartingIDChar)
          (NC.MarkCardDirty GraphID)
          (SETQ StartingIDChar (ADD1 (NCHARS GraphID)))
          (SETQ SourceID (SUBATOM (fetch (GRAPHNODE NODEID) of FromNode)
				  StartingIDChar))
          (SETQ DestinationID (SUBATOM (fetch (GRAPHNODE NODEID) of ToNode)
				       StartingIDChar))
          (SETQ LinkLabel (COND
	      ((EQ (SETQ SourceType (NC.FetchType SourceID))
		   (QUOTE FileBox))
		(COND
		  ((EQ (NC.FetchType DestinationID)
		       (QUOTE FileBox))
		    NC.SubBoxLinkLabel)
		  (T NC.FiledCardLinkLabel)))
	      (T (NC.AskLinkLabel Window NIL NIL T))))
          (COND
	    ((EQ (NCP.CardTypeSubstance SourceType)
		 (QUOTE TEXT))
	      (NCP.LocalGlobalLink LinkLabel SourceID DestinationID))
	    (T (NCP.GlobalGlobalLink LinkLabel SourceID DestinationID))))))

(NC.StructEditDeleteNodeFn
  (LAMBDA (Node Graph Window)                                (* rht: " 3-Feb-85 23:28")

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


    (PROG ((GraphID (NC.IDFromWindow Window))
	   ID StartingIDChar)
          (SETQ StartingIDChar (ADD1 (NCHARS GraphID)))
          (SETQ ID (SUBATOM (fetch (GRAPHNODE NODEID) of Node)
			    StartingIDChar))
          (NC.MarkCardDirty GraphID)
          (COND
	    ((AND (NCP.ValidID ID)
		  (NC.YesP (NC.AskUser (CONCAT "Want to delete the " (NC.FetchTitle ID)
					       " card? ")
				       "--"
				       (QUOTE Yes)
				       T Window)))
	      (NCP.DeleteCards ID)
	      (NC.PrintMsg Window NIL "Done."))))))

(NC.StructEditDeleteLinkFn
  (LAMBDA (FromNode ToNode Graph Window)                     (* rht: " 6-Feb-85 14:56")

          (* * Called by grapher when user deletes a link.)


    (PROG ((GraphID (NC.IDFromWindow Window))
	   SourceID SourceType DestinationID LinkLabel StartingIDChar Link Links)
          (SETQ StartingIDChar (ADD1 (NCHARS GraphID)))
          (SETQ SourceID (SUBATOM (fetch (GRAPHNODE NODEID) of FromNode)
				  StartingIDChar))
          (SETQ DestinationID (SUBATOM (fetch (GRAPHNODE NODEID) of ToNode)
				       StartingIDChar))
          (SETQ Links (NCP.GetLinks SourceID DestinationID))
          (OR Links (RETURN NIL))
          (NC.MarkCardDirty GraphID)
          (SETQ Link (COND
	      ((CDR Links)
		(MENU (create MENU
			      ITEMS ←(for Link in Links collect (LIST (fetch (NOTECARDLINK LINKLABEL)
									 of Link)
								      Link))
			      TITLE ← "Which link to delete?")))
	      (T (CAR Links))))
          (COND
	    ((AND Link (NC.YesP (NC.AskUser (CONCAT "Want to delete the " (fetch (NOTECARDLINK 
											LINKLABEL)
									     of Link)
						    " link between "
						    (NC.FetchTitle SourceID)
						    " and "
						    (NC.FetchTitle DestinationID)
						    "? ")
					    "--"
					    (QUOTE Yes)
					    T Window)))
	      (NCP.DeleteLinks Link)
	      (NC.PrintMsg Window NIL "Done."))))))
)
(SETPROPLIST (QUOTE NC.MakeDocParameters)
	     (QUOTE (HeadingsFromFileboxes NumberedBold TitlesFromNoteCards Bold BuildBackLinks NONE 
					   CopyEmbeddedLinks ALL ExpandEmbeddedLinks NONE --DONE-- 
					   --CANCEL-- VALUE ((HeadingsFromFileboxes NumberedBold 
										   UnnumberedBold 
										    NONE)
					    (TitlesFromNoteCards Bold NotBold NONE)
					    (BuildBackpointers ToCardsBoxes ToCards ToBoxes NONE)
					    (CopyEmbeddedLinks ALL NONE Select)
					    (ExpandEmbeddedLinks ALL NONE Select)
					    (--DONE--)))))
(* * Link Index functions)

(DEFINEQ

(NC.MakeLinkIndex
  (LAMBDA (ID Title NoDisplayFlg SpecialArgsList)            (* rht: "31-Jan-85 21:23")

          (* * Gather all instances of a given set of linktypes, printing the titles of cards at the from and to ends of the 
	  link.)



          (* * rht 10/24/84: Now callable from Programmer's interface. If NoDisplayFlg it non-nil, then will build LinkIndex 
	  invisibly. If SpecialArgsList is non-nil, then should be list of (<linklabels> <backpointersP> <sortP>))


    (PROG (IndexCardID Window WindowOrID LinkLabels BackLinksP Stream SortedWinners LastID)
          (SPAWN.MOUSE)
          (SETQ WindowOrID (NC.MakeNoteCard (QUOTE Text)
					    "Link Index" NoDisplayFlg NIL ID))
          (COND
	    (NoDisplayFlg (SETQ Window NIL)
			  (SETQ IndexCardID WindowOrID))
	    (T (SETQ Window WindowOrID)
	       (SETQ IndexCardID (NC.IDFromWindow Window))))
          (SETQ LinkLabels (COND
	      (SpecialArgsList (CAR SpecialArgsList))
	      (T (NC.AskLinkLabel Window T T NIL NIL T))))
          (COND
	    ((NULL LinkLabels)
	      (NC.PrintMsg Window T "No link labels to search for.")
	      (RETURN NIL)))
          (SETQ BackLinksP (COND
	      (SpecialArgsList (CADR SpecialArgsList))
	      (T (NC.YesP (NC.AskUser "Build back links to cards and boxes? " "--" NIL NIL Window T)))
	      ))
          (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
		    (SETQ Stream (NC.FetchSubstance IndexCardID))
		    (NC.AppendStringToStream Stream (CONCAT "Sorted link index compiled on: "
							    (DATE)
							    (CHARACTER 13)
							    " for linktypes: "
							    (CAR LinkLabels)))
		    (for Label in (CDR LinkLabels) do (NC.AppendStringToStream Stream
									       (CONCAT ", " Label)))
		    (NC.AppendStringToStream Stream (CONCAT (CHARACTER 13)
							    (CHARACTER 13)))
		    (SETQ LastID (SUB1 (SUBATOM (NC.GetNewID PSA.Database T)
						3)))         (* Subtract one more so that this LinkIndex's ID isn't 
							     counted.)
		    (SETQ LastID (SUB1 LastID))
		    (NC.PrintMsg Window T "Gathering links ... ")

          (* * Find all ID's with instances of a desired link label, record whether they were active, sort them, print their 
	  titles to the stream, and deactivate the ones that weren't active.)


		    (SETQ SortedWinners (SORT (for ID# from 1 to LastID bind ID ActiveP
						 when (PROGN (SETQ ID (NC.IDFromNumber ID#))
							     (SETQ ActiveP (NC.ActiveCardP ID))
							     (PUTPROP ID (QUOTE WasActiveFlg)
								      ActiveP)
							     (OR ActiveP (NC.GetLinks ID PSA.Database)
								 )
							     (OR (for Link in (NC.FetchToLinks ID)
								    thereis (NC.LinkLabelP Link 
										       LinkLabels))
								 (for Link in (NC.FetchFromLinks
										ID)
								    thereis (NC.ReverseLinkLabelP
									      Link LinkLabels))))
						 collect (CONS (NC.FetchTitle ID)
							       ID))
					      T))
		    (for WinnerPair in SortedWinners bind ID
		       do (SETQ ID (CDR WinnerPair))
			  (NC.AppendLinkIndexEntry Stream IndexCardID ID (CAR WinnerPair)
						   LinkLabels BackLinksP))
		    (for ID# from 1 to LastID bind ID
		       do (SETQ ID (NC.IDFromNumber ID#))
			  (OR (GETP ID (QUOTE WasActiveFlg))
			      (NC.DeactivateCard ID))
			  (REMPROP ID (QUOTE WasActiveFlg)))
		    (NC.PrintMsg Window NIL "Done!" (CHARACTER 13)))
          (COND
	    ((NOT NoDisplayFlg)
	      (BLOCK 250)
	      (NC.ClearMsg Window T)))
          (RETURN IndexCardID))))

(NC.AppendLinkIndexEntry
  (LAMBDA (Stream IndexCardID ID Title LinkLabels BackLinksP)
                                                             (* rht: "21-Nov-84 15:40")

          (* * Build a link index entry consisting of all instances of links from or to ID with a label in LinkLabels.
	  Append these to the end of Stream.)


    (PROG (FromLinks ToLinks ToLinkPairs FromLinkPairs (SortArg (FUNCTION NC.LinkIndexCompareFn)))
          (SETQ ToLinks (NC.FetchToLinks ID))
          (SETQ FromLinks (NC.FetchFromLinks ID))

          (* * Find all winning links.)


          (SETQ ToLinkPairs (SORT (for Link in ToLinks bind Label when (SETQ Label (NC.LinkLabelP
									   Link LinkLabels))
				     collect (CONS Label Link))
				  SortArg))
          (SETQ FromLinkPairs (SORT (for Link in FromLinks bind Label when (SETQ Label
									     (NC.ReverseLinkLabelP
									       Link LinkLabels))
				       collect (CONS Label Link))
				    SortArg))

          (* * Print the title of ID if there were any wins.)


          (COND
	    ((OR ToLinkPairs FromLinkPairs)
	      (NC.AppendStringToStream Stream Title)
	      (if BackLinksP
		  then (NC.AppendStringToStream Stream " ")
		       (NC.AppendLinkToText IndexCardID ID NC.LinkIndexBackPtrLinkLabel (QUOTE Icon)))
	      (NC.AppendStringToStream Stream (CONCAT (CHARACTER 13)))))

          (* * Print the winning links from the ID card.)


          (for LinkPair in ToLinkPairs bind OldLabel Label DestID
	     do (SETQ Label (CAR LinkPair))
		(SETQ DestID (fetch (NOTECARDLINK DESTINATIONID) of (CDR LinkPair)))
		(COND
		  ((NEQ OldLabel Label)
		    (NC.AppendStringToStream Stream (CONCAT "  <" Label "> TO" (CHARACTER 13)))
		    (SETQ OldLabel Label)))
		(NC.AppendStringToStream Stream "    ")
		(NC.AppendStringToStream Stream (NC.FetchTitle DestID))
		(if BackLinksP
		    then (NC.AppendStringToStream Stream " ")
			 (NC.AppendLinkToText IndexCardID DestID NC.LinkIndexBackPtrLinkLabel
					      (QUOTE Icon)))
		(NC.AppendStringToStream Stream (CONCAT (CHARACTER 13))))
          (for LinkPair in FromLinkPairs bind OldLabel Label DestID
	     do (SETQ Label (CAR LinkPair))
		(SETQ DestID (fetch (NOTECARDLINK SOURCEID) of (CDR LinkPair)))
		(COND
		  ((NEQ OldLabel Label)
		    (NC.AppendStringToStream Stream (CONCAT "  <" Label "> FROM" (CHARACTER 13)))
		    (SETQ OldLabel Label)))
		(NC.AppendStringToStream Stream "    ")
		(NC.AppendStringToStream Stream (NC.FetchTitle DestID))
		(if BackLinksP
		    then (NC.AppendStringToStream Stream " ")
			 (NC.AppendLinkToText IndexCardID DestID NC.LinkIndexBackPtrLinkLabel
					      (QUOTE Icon)))
		(NC.AppendStringToStream Stream (CONCAT (CHARACTER 13)))))))

(NC.LinkIndexCompareFn
  (LAMBDA (Pair1 Pair2)                                      (* rht: " 5-Sep-84 15:31")

          (* * Used when sorting cons pairs of link labels and links. Sort on label and then title of link.)


    (COND
      ((EQ (CAR Pair1)
	   (CAR Pair2))
	(ALPHORDER (NC.FetchTitle (fetch (NOTECARDLINK DESTINATIONID) of (CDR Pair1)))
		   (NC.FetchTitle (fetch (NOTECARDLINK DESTINATIONID) of (CDR Pair2)))))
      (T (ALPHORDER (CAR Pair1)
		    (CAR Pair2))))))
)
(* * spreadsheet stuff)

(DEFINEQ

(NC.AddSpreadsheetToCard
  (LAMBDA (TextStream)                                       (* rht: "20-Sep-84 11:54")

          (* * Called from a TEXT TEdit window to add a new spreadsheet to the text.)


    (PROG (Title (Window (WINDOW.FROM.TEDIT.THING TextStream)))
          (COND
	    ((NC.IntercalcActiveP)
	      (SETQ Title (NC.AskSpreadsheetTitle Window))
	      (AND Title (RETURN (Intercalc.InsertImageObj Window Title))))
	    (T (NC.PrintMsg NIL T "Sorry, Intercalc has not been loaded."))))))

(NC.AskSpreadsheetTitle
  (LAMBDA (MainWindow)                                       (* rht: "26-Sep-84 12:33")

          (* * Asks the user to choose a spreadsheet from the existing ones or choose a title for a new one.)


    (PROG (Menu Choice SpreadsheetTitles)
          (SETQ SpreadsheetTitles (for Win in (NC.GetSpreadsheets) collect (WINDOWPROP Win
										       (QUOTE 
											SHEETNAME))))
          (GETPROMPTWINDOW MainWindow 3 (FONTCREATE (QUOTE HELVETICA)
						    10))
          (NC.PrintMsg MainWindow T "Please choose spreadsheet." (CHARACTER 13))
          (SETQ Menu (create MENU
			     TITLE ← "Spreadsheet Title?"
			     ITEMS ←(APPEND SpreadsheetTitles (LIST (QUOTE --New% Spreadsheet--)
								    (QUOTE **CANCEL**)))
			     MENUPOSITION ←(AND (WINDOWP MainWindow)
						(create POSITION
							XCOORD ←(fetch (REGION LEFT)
								   of (WINDOWPROP MainWindow
										  (QUOTE REGION)))
							YCOORD ←(fetch (REGION TOP)
								   of (WINDOWREGION MainWindow))))))
          (SETQ Choice (MENU Menu))
          (COND
	    ((EQ Choice (QUOTE **CANCEL**))
	      (SETQ Choice NIL)))
          (COND
	    ((EQ Choice (QUOTE --New% Spreadsheet--))
	      (SETQ Choice (NC.AskUser "Enter new spreadsheet title" " -- " NIL NIL MainWindow T))
	      (CreateSheet Choice)))
          (NC.ClearMsg MainWindow T)
          (RETURN Choice))))

(NC.GetSpreadsheets
  (LAMBDA NIL                                                (* rht: "20-Sep-84 11:49")

          (* * Return the list of all currently active intercalc spreadsheets.)

                                                             (* rht: "20-Sep-84 11:47")
    INTERCALC.WindowList))

(NC.IntercalcActiveP
  (LAMBDA NIL                                                (* rht: "20-Sep-84 11:58")

          (* * Is intercalc loaded and active in the current environment?)

                                                             (* rht: "20-Sep-84 11:47")
    (BOUNDP (QUOTE INTERCALC.WindowList))))
)
(PUTPROPS NCBASICTYPES COPYRIGHT ("Xerox Corporation" 1984 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (5222 54007 (NC.BringUpBrowserCard 5232 . 5853) (NC.BringUpGraphCard 5855 . 6874) (
NC.BringUpSketchCard 6876 . 7981) (NC.BringUpTEditCard 7983 . 9596) (NC.ContentsCardP 9598 . 10040) (
NC.MakeBrowserCard 10042 . 15277) (NC.MakeGraphCard 15279 . 16465) (NC.MakeSketchCard 16467 . 17144) (
NC.MakeTEditCard 17146 . 18520) (NC.TEditQuitFn 18522 . 20174) (NC.GraphCardCloseFn 20176 . 20890) (
NC.GraphCardLeftButtonFn 20892 . 21821) (NC.SketchDirtyP 21823 . 22266) (NC.GraphCardMiddleButtonFn 
22268 . 23298) (NC.SketchCardCloseFn 23300 . 24563) (NC.TEditCloseFn 24565 . 25202) (NC.\TEDIT.LOOKS 
25204 . 25366) (NC.\TEDIT.QUIT 25368 . 25621) (NC.MakeContentsCard 25623 . 27885) (
NC.TextCopySubstance 27887 . 29554) (NC.GraphCopySubstance 29556 . 30605) (NC.SketchCopySubstance 
30607 . 31658) (NC.MakeSearchCard 31660 . 33829) (NC.MarkSketchDirty 33831 . 34186) (NC.MarkTextDirty 
34188 . 34534) (NC.CollectReferencesInGraph 34536 . 36121) (NC.CollectReferencesInSketch 36123 . 38898
) (NC.CollectReferencesInText 38900 . 41396) (NC.MarkGraphDirty 41398 . 41611) (NC.MakeTEditLeftMenu 
41613 . 46756) (NC.MakeTEditMiddleMenu 46758 . 47732) (NC.ResetTEdit 47734 . 48144) (
NC.ResetTEditProcess 48146 . 49158) (NC.TEditBasedP 49160 . 49884) (NC.TEditMenuFn 49886 . 50635) (
NC.TextDirtyP 50637 . 50891) (NC.GraphDirtyP 50893 . 51298) (NC.GrapherBasedP 51300 . 51805) (
NC.SketchBasedP 51807 . 52300) (NC.FileBoxCollectChildren 52302 . 54005)) (54477 56839 (
NC.GraphAddNodeFn 54487 . 55492) (NC.GraphDeleteNodeFn 55494 . 55762) (NC.GraphAddLinkFn 55764 . 56029
) (NC.GraphDeleteLinkFn 56031 . 56299) (NC.GraphMoveNodeFn 56301 . 56567) (NC.GraphFontChangeFn 56569
 . 56837)) (56882 70518 (NC.ChooseBrowseOrSearch 56892 . 58637) (NC.GrowLinkLattice 58639 . 61751) (
NC.UpdateBrowserCard 61753 . 66391) (NC.SubContentsLinkP 66393 . 66639) (NC.ContentsLinkP 66641 . 
66887) (NC.NotBrowserHookP 66889 . 67147) (NC.SearchForCards 67149 . 68926) (NC.AskBrowserSpecs 68928
 . 70516)) (71440 83577 (NC.MakeLinksLegend 71450 . 73180) (NC.MakeLinksLegendMenu 73182 . 75863) (
NC.LinksLegendRepaintFn 75865 . 77337) (NC.GraphDisplayLinkFn 77339 . 78699) (NC.GraphDrawFlowerLink 
78701 . 79804) (NC.LinksLegendReshapeFn 79806 . 80050) (NC.DrawDashedLine 80052 . 81391) (
NC.RelayoutGraphCard 81393 . 83575)) (83609 101814 (NC.MakeDocument 83619 . 88678) (
NC.DumpFileBoxToDoc 88680 . 92030) (NC.DumpNoteCardToDoc 92032 . 97160) (NC.FetchToLinksInOrder 97162
 . 97616) (NC.AppendLinkToText 97618 . 98240) (NC.BuildMakeDocInspector 98242 . 99537) (
NC.MakeDocInspectorSelectionFn 99539 . 101039) (NC.AppendStringToStream 101041 . 101812)) (101847 
108428 (NC.MakeStructEditCard 101857 . 103108) (NC.FixStructEditTitleBarMenu 103110 . 103714) (
NC.StructEditAddNodeFn 103716 . 104872) (NC.StructEditAddLinkFn 104874 . 106087) (
NC.StructEditDeleteNodeFn 106089 . 106883) (NC.StructEditDeleteLinkFn 106885 . 108426)) (109004 116601
 (NC.MakeLinkIndex 109014 . 112941) (NC.AppendLinkIndexEntry 112943 . 116039) (NC.LinkIndexCompareFn 
116041 . 116599)) (116632 119415 (NC.AddSpreadsheetToCard 116642 . 117193) (NC.AskSpreadsheetTitle 
117195 . 118748) (NC.GetSpreadsheets 118750 . 119070) (NC.IntercalcActiveP 119072 . 119413)))))
STOP