(FILECREATED "22-May-85 16:38:36" {PHYLUM}<NOTECARDS>RELEASE1.2>NCCARDS.;15 81202  

      changes to:  (FNS NC.EditNoteCard NC.AssignTitle)

      previous date: "17-Mar-85 19:40:33" {PHYLUM}<NOTECARDS>RELEASE1.2>NCCARDS.;13)


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

(PRETTYCOMPRINT NCCARDSCOMS)

(RPAQQ NCCARDSCOMS ((E (SETQ NC.SystemDate (DATE)))
	(* * Internal variables)
	(GLOBALVARS NC.SubBoxMarkerLabel NC.FiledCardMarkerLabel NC.PlaceMarkerDisplayFont 
		    NC.OrphanID NC.RootID NC.UnclassifiedID NC.LinkLabelsID USERNAME 
		    NC.SavePropEditMenu TEDIT.SELPENDING NC.SystemLinkLabels NC.SourceLinkLabel 
		    NC.FiledCardLinkLabel)
	(VARS (NC.OrphanID (QUOTE NC00002))
	      (NC.RootID (QUOTE NC00001))
	      (NC.UnclassifiedID (QUOTE NC00003))
	      (NC.LinkLabelsID (QUOTE NC00004))
	      (NC.TopLevelCards (QUOTE (NC00001 NC00002 NC00003)))
	      (NC.SubBoxMarkerLabel "File Boxes")
	      (NC.FiledCardMarkerLabel "Note Cards")
	      (NC.PlaceMarkerDisplayFont (FONTCREATE (QUOTE HELVETICA)
						     12
						     (QUOTE ITALIC))))
	(* * Manipulate Note Card Representations)
	(FNS NC.SetNewCardFlg NC.FetchNewCardFlg NC.CoerceToID NC.ActivateCard NC.ActiveCardP 
	     NC.DeactivateCard NC.FetchFromLinks NC.FetchGlobalLinks NC.FetchLinksDirtyFlg 
	     NC.FetchPropList NC.FetchRegion NC.FetchRegionViewed NC.FetchScale NC.FetchSubstance 
	     NC.FetchTitle NC.FetchToLinks NC.FetchType NC.FetchWindow NC.IDP NC.MarkCardDirty 
	     NC.CardDirtyP NC.SetFromLinks NC.SetGlobalLinks NC.SetInitialPropList 
	     NC.SetLinksDirtyFlg NC.SetPropList NC.SetRegion NC.SetRegionViewed NC.SetScale 
	     NC.SetSubstance NC.SetTitle NC.SetToLinks NC.SetType NC.FetchTitleDirtyFlg 
	     NC.SetTitleDirtyFlg NC.FetchPropListDirtyFlg NC.SetPropListDirtyFlg NC.ShrinkFn 
	     NC.SetSubstanceDirtyFlg NC.FetchSubstanceDirtyFlg NC.TurnOffDirtyFlgs)
	(* * Retrieve Note Card Info)
	(FNS NC.RetrieveFromLinks NC.RetrieveLinkLabels NC.RetrievePropList NC.RetrieveTitle 
	     NC.RetrieveToLinks NC.RetrieveGlobalLinks NC.RetrieveType)
	(* * General note card manipulations)
	(FNS NC.AddParents NC.AssignSources NC.AssignTitle NC.DeleteNoteCards NC.EditNoteCard 
	     NC.MakeNoteCard NC.FileNoteCard NC.QuitCard NC.CheckContentsHooks NC.CheckSources 
	     NC.CheckTitle NC.DeleteSource NC.DetermineContentsCards NC.DetermineSources 
	     NC.InsureProperFiling NC.QuitWithoutSaving NC.UnfileNoteCard NC.UpdateUpdateList 
	     NC.CollectReferences NC.CardSaveFn NC.DetermineDisplayRegion NC.AbortCard 
	     NC.CardNeedsFilingP)
	(* * Prop List Editor)
	(RECORDS PropListItem)
	(FNS NC.AddPropToPropList NC.CloseAllPropListEditors NC.ClosePropListEditor 
	     NC.DelPropFromList NC.EditPropButtonFN NC.EditProperties NC.EditPropList 
	     NC.ExtractPropList NC.OpenPropListEditor NC.ProcessEditedPropList NC.PropListEditorOpenP 
	     NC.SelectProperty NC.ShowPointers NC.StringIsListP NC.PutProp NC.GetProp)
	(* * Unknown ?????????)
	(FNS NC.FetchBeingDeletedFlg NC.SetBeingDeletedFlg)
	(* * Place marker ImageObjects)
	(FNS NC.PlaceMarkerCopyFn NC.PlaceMarkerDisplayFn NC.PlaceMarkerGetFn 
	     NC.PlaceMarkerImageBoxFn NC.PlaceMarkerPutFn NC.MakePlaceMarker)))
(* * Internal variables)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NC.SubBoxMarkerLabel NC.FiledCardMarkerLabel NC.PlaceMarkerDisplayFont NC.OrphanID 
	    NC.RootID NC.UnclassifiedID NC.LinkLabelsID USERNAME NC.SavePropEditMenu TEDIT.SELPENDING 
	    NC.SystemLinkLabels NC.SourceLinkLabel NC.FiledCardLinkLabel)
)

(RPAQQ NC.OrphanID NC00002)

(RPAQQ NC.RootID NC00001)

(RPAQQ NC.UnclassifiedID NC00003)

(RPAQQ NC.LinkLabelsID NC00004)

(RPAQQ NC.TopLevelCards (NC00001 NC00002 NC00003))

(RPAQ NC.SubBoxMarkerLabel "File Boxes")

(RPAQ NC.FiledCardMarkerLabel "Note Cards")

(RPAQ NC.PlaceMarkerDisplayFont (FONTCREATE (QUOTE HELVETICA)
					    12
					    (QUOTE ITALIC)))
(* * Manipulate Note Card Representations)

(DEFINEQ

(NC.SetNewCardFlg
  (LAMBDA (ID Value)                                         (* NoteCards% User " 6-Jun-84 17:29")
                                                             (* Set the new card flg of ID to Value)
    (PUTPROP ID (QUOTE NoteCardNewCard)
	     Value)))

(NC.FetchNewCardFlg
  (LAMBDA (ID)                                               (* NoteCards% User " 6-Jun-84 17:30")
                                                             (* Return the value of the new card flg of ID)
    (GETPROP ID (QUOTE NoteCardNewCard))))

(NC.CoerceToID
  (LAMBDA (WindowOrTextStreamOrID)                           (* rht: " 1-Feb-85 16:16")

          (* * Get the ID of WindowOrTextStreamOrID)


    (PROG (Window)
          (RETURN (COND
		    ((NC.IDP WindowOrTextStreamOrID)
		      WindowOrTextStreamOrID)
		    ((WINDOWP WindowOrTextStreamOrID)
		      (NC.IDFromWindow WindowOrTextStreamOrID))
		    ((TEXTSTREAMP WindowOrTextStreamOrID)
		      (AND (SETQ Window (WINDOW.FROM.TEDIT.THING WindowOrTextStreamOrID))
			   (NC.IDFromWindow Window)))
		    (T (NC.ReportError "NC.CoerceToID " (CONCAT 
							 "Arg not Window or TextStream or ID:   "
								WindowOrTextStreamOrID))))))))

(NC.ActivateCard
  (LAMBDA (ID)                                               (* fgh: "15-Feb-84 00:33")
    (PUTPROP ID (QUOTE NoteCardActive)
	     T)))

(NC.ActiveCardP
  (LAMBDA (ID)                                               (* fgh: "15-Feb-84 00:35")
    (AND (GETPROP ID (QUOTE NoteCardActive))
	 (GETPROP ID (QUOTE NoteCardType)))))

(NC.DeactivateCard
  (LAMBDA (ID DeleteTypeAndTitleFlg)                         (* rht: " 1-Feb-85 18:58")

          (* * Remove all the information from the prop list of the NoteCard ID, except for the title which usually statys 
	  cached.)


    (PROG NIL
          (REMPROP ID (QUOTE NoteCardRegion))
          (REMPROP ID (QUOTE NoteCardActive))
          (REMPROP ID (QUOTE NoteCardFromLinks))
          (REMPROP ID (QUOTE NoteCardToLinks))
          (REMPROP ID (QUOTE NoteCardPropList))
          (REMPROP ID (QUOTE NoteCardGlobalLinks))
          (REMPROP ID (QUOTE NoteCardLinksDirty))
          (REMPROP ID (QUOTE SKETCH))
          (REMPROP ID (QUOTE NoteCardSketchScale))
          (REMPROP ID (QUOTE NoteCardRegionViewed))
          (REMPROP ID (QUOTE NoteCardNewCard))
          (REMPROP ID (QUOTE NoteCardTitleDirty))
          (REMPROP ID (QUOTE NoteCardPropListDirty))
          (REMPROP ID (QUOTE NoteCardSubstanceDirty))
          (REMPROP ID (QUOTE VALUE))
          (COND
	    (DeleteTypeAndTitleFlg (REMPROP ID (QUOTE NoteCardTitle))
				   (REMPROP ID (QUOTE NoteCardType))))
          (SET ID))))

(NC.FetchFromLinks
  (LAMBDA (ID)                                               (* fgh: "16-Feb-84 00:14")
    (GETPROP ID (QUOTE NoteCardFromLinks))))

(NC.FetchGlobalLinks
  (LAMBDA (ID)                                               (* fgh: "23-Apr-84 19:45")
    (GETPROP ID (QUOTE NoteCardGlobalLinks))))

(NC.FetchLinksDirtyFlg
  (LAMBDA (ID)                                               (* fgh: "23-Apr-84 19:59")
    (GETPROP ID (QUOTE NoteCardLinksDirty))))

(NC.FetchPropList
  (LAMBDA (ID)                                               (* fgh: "15-Feb-84 23:57")
    (GETPROP ID (QUOTE NoteCardPropList))))

(NC.FetchRegion
  (LAMBDA (ID)                                               (* fgh: "15-Feb-84 18:19")
    (GETPROP ID (QUOTE NoteCardRegion))))

(NC.FetchRegionViewed
  (LAMBDA (ID)                                               (* fgh: "28-Apr-84 19:45")
    (GETPROP ID (QUOTE NoteCardRegionViewed))))

(NC.FetchScale
  (LAMBDA (ID)                                               (* fgh: "28-Apr-84 19:46")
    (GETPROP ID (QUOTE NoteCardSketchScale))))

(NC.FetchSubstance
  (LAMBDA (ID)                                               (* fgh: "10-Oct-84 21:57")

          (* * Return the substance of card ID)


    (EVAL ID)))

(NC.FetchTitle
  (LAMBDA (ID)                                               (* fgh: "14-Feb-84 21:55")
    (GETPROP ID (QUOTE NoteCardTitle))))

(NC.FetchToLinks
  (LAMBDA (ID)                                               (* fgh: "16-Feb-84 00:14")
    (GETPROP ID (QUOTE NoteCardToLinks))))

(NC.FetchType
  (LAMBDA (ID)                                               (* fgh: "13-Feb-84 21:13")
    (GETPROP ID (QUOTE NoteCardType))))

(NC.FetchWindow
  (LAMBDA (ID)                                               (* rht: " 7-Nov-84 20:55")

          (* * Given an ID of a card, return the open window containing that card.)


    (PROG ((NoteCardType (NC.FetchType ID)))
          (RETURN (COND
		    ((NC.ActiveCardP ID)
		      (for Window in (OPENWINDOWS) when (OR (EQ ID (WINDOWPROP Window (QUOTE 
										       NoteCardID)))
							    (EQ ID (WINDOWPROP (WINDOWPROP
										 Window
										 (QUOTE ICONFOR))
									       (QUOTE NoteCardID))))
			 do (RETURN (COND
				      ((EQ ID (WINDOWPROP Window (QUOTE NoteCardID)))
					Window)
				      (T (WINDOWPROP Window (QUOTE ICONFOR)))))))
		    (T NIL))))))

(NC.IDP
  (LAMBDA (ID)                                               (* fgh: "13-Feb-84 21:11")
    (AND (EQ (NCHARS ID)
	     7)
	 (EQ (SUBATOM ID 1 2)
	     (QUOTE NC))
	 (FIXP (SUBATOM ID 3))
	 (ILESSP (SUBATOM ID 3)
		 NC.IndexSizeInEntries))))

(NC.MarkCardDirty
  (LAMBDA (ID ResetFlg)                                      (* rht: " 1-Feb-85 17:18")
                                                             (* Mark card specified by ID as being DIRTY and needing
							     to be writtent to the database)

          (* * rht 2/1/85: Now also sets/resets property on ID indicating substance dirty.)


    (APPLY* (NC.MarkCardDirtyFn (NC.FetchType ID))
	    ID ResetFlg)
    (NC.SetSubstanceDirtyFlg ID (NOT ResetFlg))))

(NC.CardDirtyP
  (LAMBDA (ID)                                               (* rht: " 1-Feb-85 15:33")

          (* * Return T if card ID has been changed.)



          (* * rht 2/1/85: Now also checks flag on prop list.)


    (OR (APPLY* (NC.SubstanceDirtyPFn (NC.FetchType ID))
		ID)
	(NC.FetchSubstanceDirtyFlg ID))))

(NC.SetFromLinks
  (LAMBDA (ID Links)                                         (* fgh: "16-Feb-84 00:13")
    (PUTPROP ID (QUOTE NoteCardFromLinks)
	     Links)))

(NC.SetGlobalLinks
  (LAMBDA (ID GlobalLinks)                                   (* fgh: "23-Apr-84 19:44")
    (PUTPROP ID (QUOTE NoteCardGlobalLinks)
	     GlobalLinks)))

(NC.SetInitialPropList
  (LAMBDA (ID DatabaseStream)                                (* fgh: "27-Mar-84 00:45")
    (NC.SetPropList ID (NCONC (LIST (QUOTE Sources)
				    NIL)
			      (NC.FetchPropList ID)))))

(NC.SetLinksDirtyFlg
  (LAMBDA (ID Value)                                         (* fgh: "23-Apr-84 19:52")
    (PUTPROP ID (QUOTE NoteCardLinksDirty)
	     Value)))

(NC.SetPropList
  (LAMBDA (ID PropList)                                      (* fgh: "16-Feb-84 00:02")
    (PUTPROP ID (QUOTE NoteCardPropList)
	     PropList)))

(NC.SetRegion
  (LAMBDA (ID Region)                                        (* fgh: "15-Feb-84 18:19")
    (PUTPROP ID (QUOTE NoteCardRegion)
	     Region)))

(NC.SetRegionViewed
  (LAMBDA (ID RegionValue)                                   (* fgh: "28-Apr-84 19:44")
    (PUTPROP ID (QUOTE NoteCardRegionViewed)
	     RegionValue)))

(NC.SetScale
  (LAMBDA (ID ScaleValue)                                    (* fgh: "28-Apr-84 19:46")
    (PUTPROP ID (QUOTE NoteCardSketchScale)
	     ScaleValue)))

(NC.SetSubstance
  (LAMBDA (ID Substance)                                     (* fgh: "10-Oct-84 22:03")

          (* * Set the substance of card ID to be substance)


    (SET ID Substance)))

(NC.SetTitle
  (LAMBDA (ID Title)                                         (* fgh: "14-Feb-84 21:54")
    (PUTPROP ID (QUOTE NoteCardTitle)
	     Title)))

(NC.SetToLinks
  (LAMBDA (ID Links)                                         (* fgh: "16-Feb-84 00:14")
    (PUTPROP ID (QUOTE NoteCardToLinks)
	     Links)))

(NC.SetType
  (LAMBDA (ID NoteCardType)                                  (* fgh: " 2-Mar-84 23:05")
    (PUTPROP ID (QUOTE NoteCardType)
	     NoteCardType)))

(NC.FetchTitleDirtyFlg
  (LAMBDA (ID)                                               (* fgh: " 5-Oct-84 22:18")
    (GETPROP ID (QUOTE NoteCardTitleDirty))))

(NC.SetTitleDirtyFlg
  (LAMBDA (ID Value)                                         (* fgh: " 5-Oct-84 22:20")
    (PUTPROP ID (QUOTE NoteCardTitleDirty)
	     Value)))

(NC.FetchPropListDirtyFlg
  (LAMBDA (ID)                                               (* fgh: " 5-Oct-84 22:19")
    (GETPROP ID (QUOTE NoteCardPropListDirty))))

(NC.SetPropListDirtyFlg
  (LAMBDA (ID Value)                                         (* fgh: " 5-Oct-84 22:21")
    (PUTPROP ID (QUOTE NoteCardPropListDirty)
	     Value)))

(NC.ShrinkFn
  (LAMBDA NIL                                                (* NoteCards% User " 8-Jun-84 17:53")
                                                             (* SHRINKFN for all NoteCards and FileBoxes.
							     For now just the default title icon.)
    NIL))

(NC.SetSubstanceDirtyFlg
  (LAMBDA (ID Value)                                         (* rht: " 1-Feb-85 15:29")
    (PUTPROP ID (QUOTE NoteCardSubstanceDirty)
	     Value)))

(NC.FetchSubstanceDirtyFlg
  (LAMBDA (ID)                                               (* rht: " 1-Feb-85 15:30")
    (GETPROP ID (QUOTE NoteCardSubstanceDirty))))

(NC.TurnOffDirtyFlgs
  (LAMBDA (ID)                                               (* rht: " 6-Feb-85 15:56")

          (* * Make this card look not dirty by turning off all its dirty flags.)


    (NC.MarkCardDirty ID (QUOTE RESET))
    (NC.SetLinksDirtyFlg ID NIL)
    (NC.SetTitleDirtyFlg ID NIL)
    (NC.SetPropListDirtyFlg ID NIL)))
)
(* * Retrieve Note Card Info)

(DEFINEQ

(NC.RetrieveFromLinks
  (LAMBDA (ID DatabaseStream)                                (* fgh: "11-Apr-84 22:16")
                                                             (* Get or Fetch the from links for the card ID)
    (COND
      ((NC.ActiveCardP ID)
	(NC.FetchFromLinks ID))
      (T (WITH.MONITOR (NC.FetchMonitor DatabaseStream)
		       (NC.GetLinks ID DatabaseStream)
		       (PROG1 (NC.FetchFromLinks ID)
			      (NC.DeactivateCard ID)))))))

(NC.RetrieveLinkLabels
  (LAMBDA (DatabaseStream SystemLinksFlg)                    (* NoteCards% User "21-Jun-84 19:57")
                                                             (* Retrieve the list of link labels used in database 
							     specified by DatabaseStream.
							     Include system maintained links only when specified by 
							     SystemLinksFlg)
    (UNION (AND SystemLinksFlg NC.SystemLinkLabels)
	   (for Label in (NC.GetLinkLabels DatabaseStream) when (OR SystemLinksFlg
								    (NULL (NC.SystemLinkLabelP Label))
								    )
	      collect Label))))

(NC.RetrievePropList
  (LAMBDA (ID DatabaseStream)                                (* fgh: "22-Mar-84 12:48")
                                                             (* Fetch or get the prop list for the note card 
							     specified by ID)
    (COND
      ((NC.ActiveCardP ID)
	(NC.FetchPropList ID))
      (T (NC.GetPropList ID DatabaseStream)))))

(NC.RetrieveTitle
  (LAMBDA (ID DatabaseStream)                                (* fgh: " 9-Apr-84 19:37")
                                                             (* If note card specified by ID is active then fetch 
							     its title. Otherwise activate the card, fetch title and
							     then deactivate the card.)
    (OR (NC.FetchTitle ID)
	(NC.SetTitle ID (NC.GetTitle ID DatabaseStream)))))

(NC.RetrieveToLinks
  (LAMBDA (ID DatabaseStream)                                (* fgh: "11-Apr-84 22:26")
                                                             (* Get or Fetch the from links for the card ID)
    (COND
      ((NC.ActiveCardP ID)
	(NC.FetchToLinks ID))
      (T (WITH.MONITOR (NC.FetchMonitor DatabaseStream)
		       (NC.GetLinks ID DatabaseStream)
		       (PROG1 (NC.FetchToLinks ID)
			      (NC.DeactivateCard ID)))))))

(NC.RetrieveGlobalLinks
  (LAMBDA (ID DatabaseStream)                                (* fgh: " 2-Oct-84 17:21")

          (* * Fetch or get the global links of ID)


    (COND
      ((NC.ActiveCardP ID)
	(NC.FetchGlobalLinks ID))
      (T (NC.GetLinks ID DatabaseStream)
	 (PROG1 (NC.FetchGlobalLinks ID)
		(NC.DeactivateCard ID))))))

(NC.RetrieveType
  (LAMBDA (ID DatabaseStream)                                (* fgh: " 2-Oct-84 17:49")
                                                             (* Get or Fetch NoteCardType of ID)
    (COND
      ((NC.FetchType ID))
      (T (NC.GetType ID DatabaseStream)))))
)
(* * General note card manipulations)

(DEFINEQ

(NC.AddParents
  (LAMBDA (WindowOrTextStream)                               (* rht: "15-Feb-85 15:57")

          (* Add a subtopic link from a contents card specified by the user to the contents card specified by 
	  WindowOrTextStream. But first check to make sure that this would not introduce any circularities in the contents 
	  lattice.)



          (* * rht 12/8/84: Massive shaving. Now calls NC.MakeChildLink to do the tough work.)


    (PROG (ID NewParents (Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream)))
          (SETQ ID (NC.IDFromWindow Window))
          (SETQ NewParents (NC.SelectNoteCards NIL (FUNCTION NC.ContentsCardP)
					       NC.SelectingParentsMenu ID NIL 
					       " Please select the new parent FileBox(es)."))
          (if (NULL (AND NewParents ID (for ParentID in NewParents bind OneHook
					  when (NC.MakeChildLink ID ParentID Window)
					  do (SETQ OneHook T) finally (RETURN OneHook))))
	      then (NC.PrintMsg Window NIL "No appropriate FileBoxes chosen." (CHARACTER 13)
				"Hence no parents added."
				(CHARACTER 13)))
          (AND (GETPROMPTWINDOW Window NIL NIL T)
	       (PROG1 (DISMISS 5000)
		      (NC.ClearMsg Window T))))))

(NC.AssignSources
  (LAMBDA (WindowOrTextStream)                               (* rht: " 5-Feb-85 23:54")
                                                             (* Called from title bar menus.
							     Assign a new source link to this card.
							     Destination to be specified by the user.)
    (PROG (ID Sources (Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream)))
          (SETQ ID (NC.IDFromWindow Window))
          (SETQ Sources (NC.DetermineSources PSA.Database NIL ID))
          (for Source in Sources do (NC.AddSourceLink ID Source PSA.Database))
          (NC.SetLinksDirtyFlg ID T)
          (NC.ClearMsg Window T))))

(NC.AssignTitle
  (LAMBDA (WindowOrTextStreamOrID NoClearMsgFlg NewTitle)    (* rht: "22-May-85 12:02")

          (* * Change the title of the card specified by the WindowOrTextStreamOrID)



          (* * rht 2/1/85: Changed from NC.PutTitle to NC.SetTitleDirtyFlg, unless card is not active.
	  We shouldn't be writing to the notefile until save time.)


    (PROG (ID ContainingCardID Window)
          (COND
	    ((WINDOWP WindowOrTextStreamOrID)
	      (SETQ Window WindowOrTextStreamOrID)
	      (SETQ ID (NC.IDFromWindow Window)))
	    ((TEXTSTREAMP WindowOrTextStreamOrID)
	      (SETQ Window (WINDOW.FROM.TEDIT.THING WindowOrTextStreamOrID))
	      (SETQ ID (NC.IDFromWindow Window)))
	    ((NC.IDP WindowOrTextStreamOrID)
	      (SETQ ID WindowOrTextStreamOrID)
	      (SETQ Window (NC.FetchWindow ID))))
          (SETQ NewTitle (OR (STRINGP NewTitle)
			     (AND NewTitle (OR (LITATOM NewTitle)
					       (NUMBERP NewTitle))
				  (MKSTRING NewTitle))
			     (NC.AskUser (CONCAT "Enter the title for this card" (CHARACTER 13))
					 "-->  "
					 (NC.RetrieveTitle ID PSA.Database)
					 (NULL NoClearMsgFlg)
					 Window)))
          (AND (NULL NewTitle)
	       (RETURN))
          (NC.SetTitle ID NewTitle)
          (COND
	    ((NC.ActiveCardP ID)
	      (NC.SetTitleDirtyFlg ID T))
	    (T (NC.PutTitle ID PSA.Database)))
          (AND (WINDOWP Window)
	       (WINDOWPROP Window (QUOTE TITLE)
			   NewTitle))
          (for FromLink in (NC.RetrieveFromLinks ID PSA.Database)
	     do (AND (NC.ActiveCardP (SETQ ContainingCardID (fetch (NOTECARDLINK SOURCEID)
							       of FromLink)))
		     (WINDOWP (NC.FetchWindow ContainingCardID))
		     (NC.UpdateLinkImages ContainingCardID ID))))))

(NC.DeleteNoteCards
  (LAMBDA (CardTextStreamWindowOrID NoCheckFlg DontClearFlg)
                                                             (* rht: " 8-Mar-85 13:35")
                                                             (* Delete note cards. If no card specified then get a 
							     list of note cards to be deleted.
							     Then delete these cards.)
    (PROG (Cards)
          (SETQ Cards (OR CardTextStreamWindowOrID (NC.SelectNoteCards NIL NIL NC.DeleteSelectingMenu 
								       NIL NIL 
						    "Please select the Note Cards to be deleted.")))
          (for Card in (MKLIST Cards)
	     do (SETQ ID (NC.CoerceToID Card))
		(COND
		  ((NULL ID))
		  ((FMEMB ID NC.TopLevelCards)
		    (NC.PrintMsg (NC.FetchWindow ID)
				 T "You cannot delete this FileBox." (CHARACTER 13))
		    (DISMISS 1000)
		    (NC.ClearMsg (NC.FetchWindow ID)
				 T))
		  (T (AND (OR NoCheckFlg (PROG1 (FMEMB (MKATOM (NC.AskUser 
							  "Are you sure you want to delete this?"
									   " -- " "Yes" (NULL 
										     DontClearFlg)
									   (NC.FetchWindow ID)))
						       (QUOTE (Y y Yes YES)))
						(NC.ClearMsg)))
			  (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
				    (WITH.MONITOR (NC.FetchMonitor PSA.Database)
						  (PROG (ToLinks FromLinks Window)
						        (NC.SetBeingDeletedFlg ID T)
						        (OR (NC.ActiveCardP ID)
							    (NC.GetLinks ID PSA.Database))
						        (SETQ ToLinks (NC.FetchToLinks ID))
						        (SETQ FromLinks (NC.FetchFromLinks ID))
						        (NC.SetToLinks ID NIL)
						        (NC.SetFromLinks ID NIL)
						        (for ToLink in ToLinks
							   do (NC.DelFromLink ToLink PSA.Database))
						        (for FromLink in FromLinks
							   do (NC.DelToLink FromLink PSA.Database)
							      (NC.DelReferencesToCard
								(fetch (NOTECARDLINK SOURCEID)
								   of FromLink)
								ID PSA.Database))
						        (NC.MarkCardDeleted ID PSA.Database)
						        (NC.SetNewCardFlg ID NIL)
						        (if (NC.ActiveCardP ID)
							    then (NC.TurnOffDirtyFlgs ID)
								 (SETQ Window (NC.FetchWindow ID))
								 (AND Window (NC.GreyCard ID))
								 (NC.CloseAllPropListEditors ID)
								 (NC.QuitCard ID T T))
						        (NC.DeactivateCard ID T)
						        (NC.SetBeingDeletedFlg ID NIL)))))))))))

(NC.EditNoteCard
  (LAMBDA (ID Region/Position)                               (* rht: "22-May-85 15:38")

          (* * Bring the already created NoteCard specified by ID onto the screen at Region or Position specified by 
	  Region/Position)


    (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
	      (PROG (Substance NoteCardType Window)
		    (COND
		      ((NC.ActiveCardP ID)
			(SETQ Substance (NC.FetchSubstance ID)))
		      (T (SETQ Substance (NC.FetchSubstance (NC.GetNoteCard ID PSA.Database)))))
		    (SETQ NoteCardType (NC.FetchType ID))
		    (OR (WINDOWP (SETQ Window (APPLY* (NC.EditFn NoteCardType)
						      ID Substance Region/Position)))
			(RETURN Window))
		    (WINDOWADDPROP Window (QUOTE CLOSEFN)
				   (FUNCTION NC.QuitCard)
				   (QUOTE FIRST))
		    (WINDOWPROP Window (QUOTE NoteCardID)
				ID)
		    (RETURN Window)))))

(NC.MakeNoteCard
  (LAMBDA (NoteCardType Title NoDisplayFlg TypeSpecificArgs ID)
                                                             (* rht: "28-Feb-85 22:15")
                                                             (* Make a new note card of type NoteCardType.
							     If type note specified, ask the user.)

          (* * rht 2/1/85: Added call to NC.MarkCardDirty.)


    (PROG (ReturnValue CopyID Window)
          (AND (SETQ NoteCardType (OR NoteCardType (NC.AskNoteCardType)))
	       (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
			 (OR (NC.IDP ID)
			     (SETQ ID (NC.GetNewID PSA.Database)))
			 (NC.SetNewCardFlg ID T)
			 (NC.ActivateCard ID)
			 (OR (NC.FetchType ID)
			     (NC.SetType ID NoteCardType))
			 (COND
			   ((OR (NULL (ERSETQ (SETQ ReturnValue (APPLY* (NC.MakeCardFn NoteCardType)
									ID Title NoDisplayFlg 
									TypeSpecificArgs))))
				(NULL ReturnValue))
			     (NC.MarkCardDeleted ID PSA.Database)
			     (SETPROPLIST ID NIL))
			   (T (SETQ Window (WINDOWP ReturnValue))
			      (COND
				((NULL (NC.FetchTitle ID))
				  (SETQ Title (NC.SetTitle ID (SETQ Title
							     (COND
							       ((STRINGP Title)
								 Title)
							       ((AND Title (OR (LITATOM Title)
									       (NUMBERP Title)))
								 (MKSTRING Title))
							       (T "Untitled")))))
				  (AND Window (WINDOWPROP Window (QUOTE TITLE)
							  Title)))
				(T (NC.SetTitle ID (MKSTRING (NC.FetchTitle ID)))))
			      (COND
				(Window (WINDOWADDPROP Window (QUOTE CLOSEFN)
						       (FUNCTION NC.QuitCard)
						       (QUOTE FIRST))
					(WINDOWPROP Window (QUOTE NoteCardID)
						    ID)))
			      (NC.SetTitleDirtyFlg ID T)     (* Reset the type in case of recursive calls change the
							     type. Always want the highest level type in a recursive
							     descent)
			      (NC.SetType ID NoteCardType)   (* Insure that a link ptr is set up during the first 
							     save)
			      (NC.SetLinksDirtyFlg ID T)
			      (NC.SetPropListDirtyFlg ID T)
                                                             (* Mark that substance is dirty.)
			      (NC.MarkCardDirty ID T)))))
          (RETURN ReturnValue))))

(NC.FileNoteCard
  (LAMBDA (WindowOrTextStream)                               (* rht: " 5-Feb-85 23:55")
                                                             (* Called from title bar menus -
							     adds card containing TextStream to a Contents Card or 
							     Cards)
    (PROG ((ID (NC.IDFromWindow (WINDOW.FROM.TEDIT.THING WindowOrTextStream))))
          (NC.CheckTitle ID PSA.Database)
          (NC.MakeContentsHooks ID PSA.Database))))

(NC.QuitCard
  (LAMBDA (WindowOrTextStreamOrID CallCloseWFlg DontSaveFlg)
                                                             (* rht: " 9-Feb-85 22:57")

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



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


    (PROG (Window (ID (NC.CoerceToID WindowOrTextStreamOrID)))
          (OR DontSaveFlg (NC.CardSaveFn ID PSA.Database T))
          (SETQ Window (NC.FetchWindow ID))
          (AND Window (WINDOWDELPROP Window (QUOTE CLOSEFN)
				     (FUNCTION NC.QuitCard)))
          (RETURN (PROG1 (APPLY* (NC.QuitCardFn (NC.FetchType ID))
				 ID)
			 (AND CallCloseWFlg Window (CLOSEW Window)))))))

(NC.CheckContentsHooks
  (LAMBDA (ID DatabaseStream)                                (* rht: " 9-Feb-85 22:31")
                                                             (* Check to make sure this card has a contents hook of 
							     some sort. If not, hook it up to a contents card.)

          (* * rht 12/8/84: Now checks whether both cards *and* fileboxes have been filed.)



          (* * rht 12/9/84: Now files in orphan filebox if NC.ForceFiling flag is off, without bothering the user.)



          (* * rht 2/9/85: Added call to NC.CardNeedsFilingP)


    (COND
      ((NC.CardNeedsFilingP ID)
	(if NC.ForceFilingFlg
	    then (NC.PrintMsg (NC.FetchWindow ID)
			      T "This card is not currently filed in a FileBox." (CHARACTER 13))
		 (NC.MakeContentsHooks ID DatabaseStream)
	  else (NC.PrintMsg (NC.FetchWindow ID)
			    T "This card is not currently filed in a FileBox." (CHARACTER 13)
			    "It is being filed in the Orphan FileBox.")
	       (NC.HookToOrphanCard ID NC.OrphanID DatabaseStream))))))

(NC.CheckSources
  (LAMBDA (ID DatabaseStream)                                (* fgh: " 8-Jan-85 16:25")

          (* Called when quitting a note card. Check to make sure that the sources are appropriately set for this note card.
	  If not, get the source information from the default setting or from the user.)


    (PROG (Sources)
          (SETQ Sources (for Link in (NC.FetchGlobalLinks ID) when (EQ NC.SourceLinkLabel
								       (fetch (NOTECARDLINK LINKLABEL)
									  of Link))
			   collect Link))
          (COND
	    ((NOT (NC.ContentsCardP ID))
	      (NC.PrintMsg (NC.FetchWindow ID)
			   T "This card has no designated sources." (CHARACTER 13))
	      (SETQ Sources (NC.DetermineSources DatabaseStream T ID))
	      (for Source in Sources do (NC.AddSourceLink ID Source DatabaseStream))
	      (NC.SetLinksDirtyFlg ID T))))))

(NC.CheckTitle
  (LAMBDA (ID DatabaseStream)                                (* rht: " 6-Dec-84 19:01")
                                                             (* If card specified by ID has no title, ask the user 
							     for a title.)

          (* * rht 11/19/84: Now checks NC.ForceTitlesFlg before griping.)



          (* * rht 12/6/84: Now sends ID rather than Window to NC.AssignTitle.)


    (PROG (Title (Window (NC.FetchWindow ID)))
          (COND
	    ((AND NC.ForceTitlesFlg (OR (NULL (NC.FetchTitle ID))
					(EQUAL "Untitled" (NC.FetchTitle ID))))
	      (NC.PrintMsg Window T "This note card has no title." (CHARACTER 13))
	      (NC.AssignTitle ID T))
	    ((AND (NULL NC.ForceTitlesFlg)
		  (NULL (NC.FetchTitle ID)))
	      (NC.AssignTitle ID NIL "Untitled"))))))

(NC.DeleteSource
  (LAMBDA (WindowOrTextStream)                               (* rht: "15-Feb-85 15:59")
                                                             (* Called from title bar menus.
							     Deletes source/s/ for the card specified by 
							     WindowOrTextStream)
    (PROG ((Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))
	   ID Sources EditWindow)
          (SETQ ID (NC.IDFromWindow Window))
          (SETQ Sources (for Link in (NC.FetchGlobalLinks ID)
			   when (AND (EQ NC.SourceLinkLabel (fetch (NOTECARDLINK LINKLABEL)
							       of Link))
				     (NEQ (fetch (NOTECARDLINK DESTINATIONID) of Link)
					  (QUOTE NC00000)))
			   collect Link))
          (COND
	    ((NULL Sources)
	      (NC.PrintMsg Window T "This card has no sources." (CHARACTER 13))
	      (SPAWN.MOUSE)
	      (DISMISS 2000)
	      (NC.ClearMsg Window T))
	    (T (SETQ EditWindow (NC.OpenPropListEditor Window (LIST (QUOTE Source% TO)
								    Sources)
						       "Sources" T T))
	       (until (WINDOWPROP EditWindow (QUOTE TEXTOBJ)) do (BLOCK))
	       (SETQ Sources (NC.SelectNoteCards NIL NIL NC.DeleteSelectingMenu ID NIL 
						 "Select source(s) to be deleted."))
	       (NC.ClearMsg Window T)
	       (NC.ClosePropListEditor EditWindow (QUOTE NoSave))
	       (for ToBeDeletedLink in (NC.FetchGlobalLinks ID)
		  when (AND (EQ NC.SourceLinkLabel (fetch (NOTECARDLINK LINKLABEL) of ToBeDeletedLink)
				)
			    (FMEMB (fetch (NOTECARDLINK DESTINATIONID) of ToBeDeletedLink)
				   Sources))
		  do (NC.DelToLink ToBeDeletedLink PSA.Database)
		     (NC.DelFromLink ToBeDeletedLink PSA.Database))
	       (NC.SetGlobalLinks ID (for Link in (NC.FetchGlobalLinks ID)
					when (NOT (FMEMB (fetch (NOTECARDLINK DESTINATIONID)
							    of Link)
							 Sources))
					collect Link)))))))

(NC.DetermineContentsCards
  (LAMBDA (DatabaseStream OptionalFilingFlg ID)              (* rht: "15-Feb-85 16:01")

          (* Returns a list of contents cards for filing a card. The rule used for the choice is: First ask the user.
	  If the user returns NIL, then use the Orphan Note Card)



          (* * rht 8/1/84: Changed so that user can't file a card twice in the same box.)


    (PROG (NewParents (ParentIDs (for Link in (NC.FetchFromLinks ID)
				    when (EQ (fetch (NOTECARDLINK LINKLABEL) of Link)
					     NC.FiledCardLinkLabel)
				    collect (fetch (NOTECARDLINK SOURCEID) of Link)))
		      (Window (NC.FetchWindow ID)))
          (RETURN (COND
		    ((PROGN (SETQ NewParents (NC.SelectNoteCards NIL NIL (COND
								   (ParentIDs NC.SelectingParentsMenu)
								   (T NC.SelectingContentsMenu))
								 ID NIL
								 (CONCAT 
						  "Please select the Boxes to file this card in."
									 (if ParentIDs
									     then ""
									   else (CONCAT (CHARACTER
											  13)
											
							   "NoBox files it in the ToBeFiled box.")))))
			    (for NewParentID in NewParents unless (AND (FMEMB NewParentID ParentIDs)
								       (NC.PrintMsg Window T
										    (NC.FetchTitle
										      ID)
										    
									     " already filed in "
										    (NC.FetchTitle
										      NewParentID)
										    (CHARACTER 13)))
			       collect NewParentID)))
		    ((AND (NOT OptionalFilingFlg)
			  (NOT ParentIDs))
		      (NC.PrintMsg Window T "No Box has been specified." (CHARACTER 13)
				   "Filing this card in the ToBeFiled Box."
				   (CHARACTER 13))
		      (LIST NC.UnclassifiedID)))))))

(NC.DetermineSources
  (LAMBDA (DatabaseStream NoSourceOptionFlg ID)              (* rht: "15-Feb-85 16:02")

          (* Returns a list of source cards according to the following rule: Ask the user. If the user returns no source 
	  cards, use all open source cards on the screen. Otherwise, return NIL)


    (PROG (Selections (Window (NC.FetchWindow ID)))
          (NC.PrintMsg Window NIL "Select source(s) for this card." (CHARACTER 13)
		       "NoSource" " to indicate no source." (CHARACTER 13))
          (SETQ Selections (NC.SelectNoteCards NIL NIL NC.SelectingSourcesMenu ID NIL
					       (CONCAT "Select source(s) for this card."
						       (CHARACTER 13)
						       " NoSource to indicate no source.")))
          (NC.ClearMsg Window)
          (AND (IGREATERP (LENGTH Selections)
			  1)
	       (DREMOVE (QUOTE NC00000)
			Selections))
          (RETURN Selections))))

(NC.InsureProperFiling
  (LAMBDA (ID DatabaseStream)                                (* rht: " 9-Dec-84 18:40")
                                                             (* Called when any type of note card is being quitted 
							     from, i.e., closed)

          (* * rht 12/9/84: Moved check of the NC.ForceFiling flag into NC.CheckContentsHooks.)


    (COND
      ((NULL (NC.FetchBeingDeletedFlg ID))
	(NC.CheckTitle ID DatabaseStream)
	(AND NC.ForceSourcesFlg (NC.CheckSources ID DatabaseStream))
	(NC.CheckContentsHooks ID DatabaseStream)))))

(NC.QuitWithoutSaving
  (LAMBDA (IDOrWindowOrTextStream DatabaseStream)            (* rht: " 9-Feb-85 17:41")

          (* Quit from a note card without saving its contents on the database. But must make sure that any updates that would
	  have been done to this card even if it had been on the database are carried out on the old image currently on the 
	  database)



          (* * rht 2/1/85: Now only writes out links if it has to. Also resets dirty flags and calls normal quit procedure.
	  I think we've still got possible problems with recently changed titles, both ours and those of cards we point to.)



          (* * rht 2/3/85: Now handles title changes properly. Also fixed so that changes to from links will force links to be
	  written.)



          (* * rht 2/9/85: Now accepts IDs as arg.)


    (PROG (Window ID FromLinks ToLinks DeletedLinks Process TextObj MadeNewLinksP ChangedFromLinksP 
		  OldFromLinks OldToLinks)
          (OR (STREAMP DatabaseStream)
	      (SETQ DatabaseStream PSA.Database))
          (if (NC.IDP IDOrWindowOrTextStream)
	      then (SETQ ID IDOrWindowOrTextStream)
		   (SETQ Window (NC.FetchWindow ID))
	    else (SETQ Window (WINDOW.FROM.TEDIT.THING IDOrWindowOrTextStream))
		 (SETQ ID (NC.IDFromWindow Window)))
          (SETQ FromLinks (NC.FetchFromLinks ID))
          (SETQ ToLinks (NC.FetchToLinks ID))
          (COND
	    ((FMEMB (MKATOM (NC.AskUser "Are you sure you want to flush your changes?" " -- " "Yes" T 
					Window))
		    (QUOTE (Y y Yes YES)))
	      (COND
		((NC.IDP (NC.GetNoteCard ID DatabaseStream))
                                                             (* If from links have changed then we'll have to write 
							     the new ones out.)
		  (SETQ OldFromLinks (NC.FetchFromLinks ID))
		  (COND
		    ((NOT (NC.SameLinks FromLinks OldFromLinks))
		      (NC.SetFromLinks ID FromLinks)
		      (SETQ ChangedFromLinksP T)))           (* Delete the back links from all links that are not in
							     the old to link set.)
		  (SETQ OldToLinks (NC.FetchToLinks ID))
		  (for ToLink in ToLinks when (NOT (for Link in OldToLinks
						      bind (ToLinkID ←(fetch (NOTECARDLINK LINKID)
									 of ToLink))
						      thereis (EQ ToLinkID (fetch (NOTECARDLINK
										    LINKID)
									      of Link))))
		     do (NC.DelFromLink ToLink DatabaseStream T)
			(SETQ MadeNewLinksP T))              (* Check to make sure none of the old To links point to
							     a deleted card. If so, replace with a deleted marker.)
		  (SETQ DeletedLinks (bind DestinationID for Link in OldToLinks
					when (PROGN (SETQ DestinationID (fetch (NOTECARDLINK 
										    DESTINATIONID)
									   of Link))
						    (AND (NOT (NC.ActiveCardP DestinationID))
							 (EQ (QUOTE DELETED)
							     (NC.GetType DestinationID DatabaseStream)
							     )))
					collect (NC.DelReferencesToCard ID DestinationID 
									DatabaseStream)
						Link))
		  (NC.SetToLinks ID (LDIFFERENCE OldToLinks DeletedLinks))
                                                             (* Mark links dirty if we had to delete any to links or
							     if the from links changed.)
		  (NC.SetLinksDirtyFlg ID (OR DeletedLinks ChangedFromLinksP))
                                                             (* Mark the substance dirty if had to delete any to 
							     links.)
		  (COND
		    (DeletedLinks (NC.MarkCardDirty ID))
		    (T (NC.MarkCardDirty ID (QUOTE RESET))))
		  (NC.SetPropListDirtyFlg ID NIL)
		  (COND
		    ((NC.FetchTitleDirtyFlg ID)

          (* If we've changed title and any of the cards pointing to this one are up on the screen, then we need to update 
	  their images.)


		      (for FromLink in OldFromLinks bind SourceID
			 when (AND (NC.ActiveCardP (SETQ SourceID (fetch (NOTECARDLINK SOURCEID)
								     of FromLink)))
				   (WINDOWP (NC.FetchWindow SourceID)))
			 do (NC.UpdateLinkImages SourceID ID))
		      (NC.SetTitleDirtyFlg ID NIL)))
		  (NC.QuitCard ID))
		(T                                           (* If the card has never been written to the database 
							     quit w/o saving is equivalent to deleting the card.)
		   (NC.PrintMsg Window T "This card has never been saved." (CHARACTER 13)
				"It will be deleted from the database."
				(CHARACTER 13))
		   (NC.DeleteNoteCards ID NIL T))))))))

(NC.UnfileNoteCard
  (LAMBDA (WindowOrTextStream)                               (* rht: "15-Feb-85 16:03")
                                                             (* Take a notecard out of a file box.
							     Called fom title bar menu.)
    (PROG (Links ID Window EditWindow FileBoxes)
          (SETQ Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))
          (SETQ ID (NC.IDFromWindow Window))
          (SETQ Links (bind SourceID for Link in (NC.FetchFromLinks ID)
			 when (EQ (fetch (NOTECARDLINK LINKLABEL) of Link)
				  NC.FiledCardLinkLabel)
			 collect (PROGN (replace (LINKDISPLAYMODE SHOWTITLEFLG)
					   of (fetch (NOTECARDLINK DISPLAYMODE) of Link)
					   with (QUOTE SOURCE))
					Link)))
          (SETQ EditWindow (NC.OpenPropListEditor WindowOrTextStream (LIST (QUOTE FileBoxes)
									   Links)
						  "List of File Boxes" T T))
          (BLOCK)
          (SETQ FileBoxes (NC.SelectNoteCards NIL (FUNCTION (LAMBDA (LinkOrID)
						  (COND
						    ((LISTP LinkOrID)
						      (NC.ContentsCardP (fetch (NOTECARDLINK SOURCEID)
									   of LinkOrID)))
						    (T (NC.ContentsCardP LinkOrID)))))
					      NC.SelectingParentsMenu ID T 
				"Please select the file box(es) from which to remove this card. "))
          (NC.ClosePropListEditor EditWindow (QUOTE NoSave))
          (DISMISS)
          (NC.ClearMsg Window T)
          (for Box in FileBoxes do (NC.DelReferencesToCard (COND
							     ((LISTP Box)
							       (fetch (NOTECARDLINK SOURCEID)
								  of Box))
							     (T Box))
							   ID PSA.Database))
          (for Link in Links when (OR (FMEMB (fetch (NOTECARDLINK SOURCEID) of Link)
					     FileBoxes)
				      (MEMBER Link FileBoxes))
	     do (NC.DelToLink Link PSA.Database)
		(NC.DelFromLink Link PSA.Database)))))

(NC.UpdateUpdateList
  (LAMBDA (ID)                                               (* fgh: " 5-Oct-84 22:28")
                                                             (* Update the list of update authors and times for the 
							     note card specified by ID)
    (COND
      ((NC.ActiveCardP ID)
	(COND
	  ((NULL (NC.FetchPropList ID))
	    (NC.SetPropList ID (LIST (QUOTE Updates)
				     (LIST (LIST USERNAME (DATE))))))
	  (T (LISTPUT (NC.FetchPropList ID)
		      (QUOTE Updates)
		      (CONS (LIST USERNAME (DATE))
			    (LISTGET (NC.FetchPropList ID)
				     (QUOTE Updates))))))
	(NC.SetPropListDirtyFlg ID T))
      (T (NC.ReportError "NC.UpdateUpdateList" (CONCAT ID ": Card not active on screen"))))))

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

          (* * Collect all the links in a card specified by ID. RETURNS the CONS of a list of link identifiers {described 
	  below} and a dirtyflg that is non-NIL if the Substance of ID has been modified {i.e., when a non-valid link is found
	  and CheckAndDeleteFlg is NIL}. IF CheckAndDeleteFlg is non-NIL checks for valid links and deletes those that are not
	  valid. If ReturnLinkIconsFlg is NIL, returns link icons. Otherwise, returns links. If ReturnLinkIconsFlg is NIL, 
	  returns just the links/link icons. Otherwise, returns the CONS of link/link icon and the type-specific location of 
	  the link icon in the card.)


    (COND
      ((NC.ActiveCardP ID)
	(APPLY* (NC.CollectReferencesFn (NC.FetchType ID))
		ID CheckAndDeleteFlg DatabaseStream ReturnLinkIconsFlg ReturnLocationsFlg))
      (T (NC.ReportError "NC.CollectReferences" (CONCAT "Attempt to call with inactive card:  " ID))))
    ))

(NC.CardSaveFn
  (LAMBDA (WindowOrID DatabaseStream InsureFilingFlg)        (* rht: " 9-Feb-85 22:08")

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



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


    (PROG ((ID (NC.CoerceToID WindowOrID))
	   Window OldRegion NewRegion DoneAPutP)
          (OR (STREAMP DatabaseStream)
	      (SETQ DatabaseStream PSA.Database))
          (SETQ Window (NC.FetchWindow ID))
          (AND InsureFilingFlg (NC.InsureProperFiling ID DatabaseStream))
          (NC.PrintMsg Window T ID ": Checking ... ")
          (COND
	    ((OR (NC.CardDirtyP ID)
		 (NC.FetchNewCardFlg ID))
	      (OR DoneAPutP (NC.PrintMsg Window NIL "Saving "))
	      (NC.PrintMsg Window NIL "substance, ")
	      (NC.PutNoteCard ID DatabaseStream T)
	      (SETQ DoneAPutP T)
	      (NC.MarkCardDirty ID (QUOTE RESET)))
	    ((AND (NOT (NC.FetchBeingDeletedFlg ID))
		  Window
		  (OR (NOT (EQUAL (fetch (REGION WIDTH) of (SETQ OldRegion (NC.FetchRegion ID)))
				  (fetch (REGION WIDTH) of (SETQ NewRegion (WINDOWPROP Window
										       (QUOTE REGION))
							     ))))
		      (NOT (EQUAL (fetch (REGION HEIGHT) of OldRegion)
				  (fetch (REGION HEIGHT) of NewRegion)))))
	      (OR DoneAPutP (NC.PrintMsg Window NIL "Saving "))
	      (NC.PrintMsg Window NIL "region, ")
	      (NC.UpdateRegionData ID DatabaseStream)
	      (SETQ DoneAPutP T)))
          (COND
	    ((NC.FetchTitleDirtyFlg ID)
	      (OR DoneAPutP (NC.PrintMsg Window NIL "Saving "))
	      (NC.PrintMsg Window NIL "title, ")
	      (NC.PutTitle ID DatabaseStream)
	      (SETQ DoneAPutP T)))
          (COND
	    ((NC.FetchPropListDirtyFlg ID)
	      (OR DoneAPutP (NC.PrintMsg Window NIL "Saving "))
	      (NC.PrintMsg Window NIL "proplist, ")
	      (NC.PutPropList ID DatabaseStream)
	      (SETQ DoneAPutP T)))
          (COND
	    ((NC.FetchLinksDirtyFlg ID)
	      (OR DoneAPutP (NC.PrintMsg Window NIL "Saving "))
	      (NC.PrintMsg Window NIL "links, ")
	      (NC.PutLinks ID DatabaseStream)
	      (SETQ DoneAPutP T)))
          (OR DoneAPutP (NC.PrintMsg Window NIL (CHARACTER 13)
				     "Nothing changed. "))   (* It's not a new card anymore.)
          (NC.SetNewCardFlg ID NIL)
          (NC.PrintMsg Window NIL "Done." (CHARACTER 13))
          (DISMISS 500)
          (NC.ClearMsg Window T))))

(NC.DetermineDisplayRegion
  (LAMBDA (ID Region/Position)                               (* fgh: " 4-Feb-85 23:33")
    (PROG (DefaultHeight Region)
          (RETURN (COND
		    ((type? REGION Region/Position)
		      Region/Position)
		    ((POSITIONP Region/Position)
		      (COND
			((SETQ Region (NC.FetchRegion ID))
			  (CREATEREGION (fetch (POSITION XCOORD) of Region/Position)
					(fetch (POSITION YCOORD) of Region/Position)
					(fetch (REGION WIDTH) of Region)
					(fetch (REGION HEIGHT) of Region)))
			(T (CREATEREGION (fetch XCOORD of Region/Position)
					 (fetch YCOORD of Region/Position)
					 (NC.DefaultCardWidth ID)
					 (NC.DefaultCardHeight ID)))))
		    (T (COND
			 ((SETQ Region (NC.FetchRegion ID))
			   (GETBOXREGION (fetch WIDTH of Region)
					 (fetch HEIGHT of Region)
					 (GETMOUSEX)
					 (IDIFFERENCE (GETMOUSEY)
						      (fetch HEIGHT of Region))
					 NIL
					 (CONCAT "Please specify location for Note Card " ID)))
			 (T (GETBOXREGION (NC.DefaultCardWidth ID)
					  (SETQ DefaultHeight (NC.DefaultCardHeight ID))
					  (GETMOUSEX)
					  (IDIFFERENCE (GETMOUSEY)
						       DefaultHeight)
					  NIL
					  (CONCAT "Please specify location for Note Card " ID)))))))))
)

(NC.AbortCard
  (LAMBDA (ID)                                               (* rht: " 9-Feb-85 22:01")

          (* * Kill this card's process and its window.)


    (NC.QuitCard ID NIL T)))

(NC.CardNeedsFilingP
  (LAMBDA (ID)                                               (* rht: " 9-Feb-85 22:29")

          (* * Returns non-nil if this card is filed in some not currently filed anywhere unless it's a top level card.
	  Assumes card is active.)


    (AND (NOT (FMEMB ID NC.TopLevelCards))
	 (for Link in (NC.FetchFromLinks ID) never (FMEMB (fetch (NOTECARDLINK LINKLABEL)
							     of Link)
							  (QUOTE (FiledCard SubBox)))))))
)
(* * Prop List Editor)

[DECLARE: EVAL@COMPILE 

(RECORD PropListItem (PropertyName Value OriginalListFlg AllowEditFlg AllowSelectFlg ButtonFn))
]
(DEFINEQ

(NC.AddPropToPropList
  (LAMBDA (editW)                                            (* fgh: "13-Aug-84 23:46")
                                                             (* Add a new prop to the propList being edited in 
							     editW)
    (PROG (selectedObject propName propValue insertPtr insertChars beginPtr
			  (stream (WINDOWPROP editW (QUOTE TEXTSTREAM)))
			  (tobj (WINDOWPROP editW (QUOTE TEXTOBJ))))
          (SETQ propName (MKATOM (NC.AskUser "New Property Name is = " NIL NIL T editW)))
          (NC.PrintMsg editW NIL (CHARACTER 13))
          (SETQ propValue (NC.AskUser "This property's value is = " NIL NIL NIL editW))
                                                             (* Insert these values into the editW)
                                                             (* Position just before selected button)
          (NC.PrintMsg editW T "Please select a property before which to insert this new property."
		       (CHARACTER 13))
          (SETQ selectedObject (NC.SelectProperty editW))
          (NC.ClearMsg editW T)
          (AND (NULL selectedObject)
	       (RETURN NIL))
          (SETQ insertPtr (TEDIT.FIND.OBJECT tobj selectedObject))
          (SETQ beginPtr insertPtr)                          (* Insert a button with this property name)
          (TEDIT.INSERT.OBJECT (MBUTTON.CREATE propName (FUNCTION NC.EditPropButtonFN)
					       (FONTCREATE (QUOTE HELVETICA)
							   10
							   (QUOTE BOLD)))
			       stream insertPtr)             (* Spacer between Prop and Value)
          (add insertPtr 1)
          (TEDIT.INSERT stream (CHARACTER 9)
			insertPtr)
          (TEDIT.LOOKS (TEXTOBJ stream)
		       (QUOTE (PROTECTED ON))
		       insertPtr 1)
          (add insertPtr 1)                                  (* Create a new field (Copied from JBS's 
							     \TEXTMENU.DOC.CREATE))
          (TEDIT.INSERT stream (CONCAT "  {}" (CHARACTER 13))
			insertPtr)
          (TEDIT.LOOKS (TEXTOBJ stream)
		       (QUOTE (PROTECTED ON))
		       insertPtr 5)
          (TEDIT.LOOKS (TEXTOBJ stream)
		       (QUOTE (PROTECTED ON SELECTPOINT ON))
		       (IPLUS insertPtr 2)
		       1)
          (TEDIT.INSERT stream (MKSTRING propValue)
			(IPLUS insertPtr 3))
          (TEDIT.LOOKS (TEXTOBJ stream)
		       (QUOTE (PROTECTED OFF SELECTPOINT OFF))
		       (IPLUS insertPtr 3)
		       (NCHARS (MKSTRING propValue)))
          (add insertPtr (NCHARS (MKSTRING propValue)))
          (add insertPtr 5))))

(NC.CloseAllPropListEditors
  (LAMBDA (ID)                                               (* fgh: " 7-May-84 18:30")
                                                             (* Force all prop list editors open on card ID to close
							     without saving changes.)
    (for AttachedWindow in (ALLATTACHEDWINDOWS (NC.FetchWindow ID)) when (WINDOWPROP AttachedWindow
										     (QUOTE 
										   PropListEditor))
       do (NC.ClosePropListEditor AttachedWindow (QUOTE NoSave))
	  (BLOCK))))

(NC.ClosePropListEditor
  (LAMBDA (Window SaveFlg)                                   (* NoteCards% User " 7-Jun-84 15:25")

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


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

(NC.DelPropFromList
  (LAMBDA (editW)                                            (* rht: " 6-Feb-85 00:00")
    (PROG ((tobj (WINDOWPROP editW (QUOTE TEXTOBJ)))
	   (stream (WINDOWPROP editW (QUOTE TEXTSTREAM)))
	   selectedObject CH#)
          (NC.PrintMsg editW T "Please select property to be deleted.")
          (SETQ selectedObject (NC.SelectProperty editW))
          (NC.ClearMsg editW T)
          (COND
	    ((COND
		((NOT (IMAGEOBJPROP selectedObject (QUOTE EditPropListNoDelete)))
		  (SETQ CH# (TEDIT.FIND.OBJECT tobj selectedObject))
		  (MBUTTON.FIND.NEXT.FIELD tobj CH#)         (* Delete everything between the imageobj and the 
							     end-of-line.)
		  (TEDIT.LOOKS tobj (QUOTE (PROTECTED OFF))
			       CH#
			       (IPLUS 3 (IDIFFERENCE (fetch CHLIM of (fetch SCRATCHSEL of tobj))
						     CH#)))
		  (TEDIT.DELETE stream CH# (IPLUS 3 (IDIFFERENCE (fetch CHLIM
								    of (fetch SCRATCHSEL
									  of tobj))
								 CH#)))
		  (TEDIT.SETSEL stream (GETEOFPTR stream)
				0
				(QUOTE RIGHT)))
		(T (NC.PrintMsg editW T "Selected property:value pair cannot be deleted."
				(CHARACTER 13)))))))))

(NC.EditPropButtonFN
  (LAMBDA (imageObject sel window)                           (* fgh: "20-Apr-84 21:17")
                                                             (* This is the default function called whenever the 
							     user selects a button in the NC.EditPropList window.)
    (WINDOWPROP window (QUOTE SelectedObject)
		imageObject)))

(NC.EditProperties
  (LAMBDA (TextStream)                                       (* fgh: "23-Apr-84 20:48")
                                                             (* Open a property list editor for the card 
							     corresponding to TextStream.
							     Called from Title bar menus.)
    (PROG ((ID (NC.IDFromWindow (WINDOW.FROM.TEDIT.THING TextStream))))
          (NC.OpenPropListEditor TextStream (APPEND (NC.FetchPropList ID)
						    (LIST (QUOTE ID)
							  ID))
				 "Edit Property List"))))

(NC.EditPropList
  (LAMBDA (propList window showOnlyFlg)                      (* fgh: "25-Oct-84 20:52")

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



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


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

(NC.ExtractPropList
  (LAMBDA (editW)                                            (* fgh: "31-May-84 19:19")
                                                             (* Exctract the prop list from the TextStream in prop 
							     list editor window editW)
    (PROG ((tobj (WINDOWPROP editW (QUOTE TEXTOBJ)))
	   menuStream button propName (propValue T)
	   EOL
	   (CH# 1)
	   (propList (WINDOWPROP editW (QUOTE PROPERTYLIST.BEING.EDITED))))
                                                             (* Move through each field/value pair in menu.
							     Update each PROP in the list.)
                                                             (* For each property in the list, move to the next 
							     field, and drop its value into the field slot.)
          (SETQ menuStream (fetch STREAMHINT of tobj))       (* for each button in the menu do)
          (RETURN (while (SETQ button (MBUTTON.FIND.NEXT.BUTTON tobj CH#))
		     collect                                 (* Convert the name of the button into the property 
							     name)
                                                             (* Set up the looks of the fields so that 
							     MBUTTON.NEXT.FIELD will work correctly -- Real kludge 
							     to get around limitations in TEditMenu stuff)
			     (TEDIT.LOOKS tobj (QUOTE (PROTECTED ON SELECTPOINT ON))
					  (IPLUS 4 (CDR button))
					  1)
			     (COND
			       ((SETQ EOL (MBUTTON.FIND.NEXT.BUTTON tobj (IPLUS 4 (CDR button))))
				 (SETQ EOL (IDIFFERENCE (CDR EOL)
							2)))
			       (T (SETQ EOL (SUB1 (TEDIT.FIND tobj (CHARACTER 13)
							      (CDR button))))))
			     (TEDIT.LOOKS tobj (QUOTE (PROTECTED OFF))
					  (IPLUS 4 (CDR button))
					  (IDIFFERENCE EOL (IPLUS 4 (CDR button))))
                                                             (* Get the name of the property from the butrton)
			     (SETQ propName (IMAGEOBJPROP (CAR button)
							  (QUOTE MBTEXT)))
                                                             (* Now get its value by reading the next field)
			     (SETQ propValue (MBUTTON.NEXT.FIELD.AS.TEXT.OR.IMAGEOBJ tobj
										     (CDR button)))
			     (COND
			       ((NULL propValue)
				 (SETQ propValue (fetch (PropListItem Value) of (FASSOC propName 
											propList))))
			       ((IMAGEOBJP propValue))
			       ((NC.StringIsListP propValue 0)
                                                             (* This string should really be interpreted as a LIST)
				 (SETQ propValue (READ propValue)))
			       (T                            (* This really is a string)
				  (SETQ propValue (MKATOM propValue))))
                                                             (* Keep track of where that property was in the menu 
							     stream)
			     (SETQ CH# (ADD1 (CDR button)))
			     (LIST propName propValue))))))

(NC.OpenPropListEditor
  (LAMBDA (WindowOrTextStream PropList Title ShowOnlyFlg MakeImageObjFlg)
                                                             (* rht: "17-Mar-85 18:19")
                                                             (* Open a property list editor above the card specified
							     by TextStream , which is either a TextStream or a 
							     Window)
    (PROG ((Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))
	   EditWindow ID)                                    (* Make sure there is no prop list editor already 
							     there)
          (AND (NC.PropListEditorOpenP Window)
	       (RETURN))
          (SETQ ID (NC.IDFromWindow Window))                 (* FOR each prop/value pair with LISTP value.
							     Make a series of individual prop/value pairs 
							     corresponding to the elements of the LISTP)
          (SETQ PropList (for Item on PropList by (CDDR Item)
			    join (COND
				   ((NLISTP (CADR Item))
				     (LIST (create PropListItem
						   PropertyName ←(CAR Item)
						   Value ←(CADR Item)
						   OriginalListFlg ← NIL
						   AllowEditFlg ← NIL
						   AllowSelectFlg ← NIL
						   ButtonFn ← NIL)))
				   (T (for Element in (CADR Item) collect (create PropListItem
										  PropertyName ←(CAR
										    Item)
										  Value ← Element
										  OriginalListFlg ← T
										  AllowEditFlg ← NIL
										  AllowSelectFlg ← 
										  NIL
										  ButtonFn ← NIL))))))
                                                             (* If specified, translate all NOTECARDLINK values into
							     Image Objects for display.)
          (AND MakeImageObjFlg (for Item in PropList bind LinkIcon when (type? NOTECARDLINK
									       (fetch (PropListItem
											Value)
										  of Item))
				  do (replace (PropListItem Value) of Item
					with (SETQ LinkIcon (NC.MakeLinkIcon (fetch (PropListItem
										      Value)
										of Item)))
					     (IMAGEOBJPROP LinkIcon (QUOTE InsidePropListEditor)
							   T))))
                                                             (* Indicate which properties can be edited by user.)
          (for Item in PropList do (COND
				     ((FMEMB (fetch (PropListItem PropertyName) of Item)
					     (QUOTE (ID Updates)))
				       (replace (PropListItem AllowEditFlg) of Item with T)
				       (replace (PropListItem AllowSelectFlg) of Item with T))
				     (ShowOnlyFlg (replace (PropListItem AllowEditFlg) of Item
						     with NIL)
						  (replace (PropListItem AllowSelectFlg)
						     of Item with T))
				     (T (replace (PropListItem AllowEditFlg) of Item with NIL)
					(replace (PropListItem AllowSelectFlg) of Item with NIL))))
                                                             (* Call the prop list editor)
          (ATTACHWINDOW (SETQ EditWindow (CREATEW (CREATEREGION 1000 2000 100 100)
						  (OR Title "Edit Property List")
						  NIL T))
			Window
			(QUOTE TOP)
			(QUOTE JUSTIFY))
          (WINDOWADDPROP EditWindow (QUOTE CLOSEFN)
			 (FUNCTION NC.ClosePropListEditor))
          (WINDOWPROP EditWindow (QUOTE PropListEditor)
		      (COND
			(ShowOnlyFlg (QUOTE ShowOnly))
			(T T)))
          (NC.EditPropList PropList EditWindow ShowOnlyFlg)
          (RETURN EditWindow))))

(NC.ProcessEditedPropList
  (LAMBDA (EditedPropList OldPropList)                       (* rht: " 6-Feb-85 00:01")
                                                             (* Take an edited prop list and set the prop list of 
							     the card as required.)

          (* * rht 2/1/85: Removed call to NC.MarkCardDirty.)


    (PROG (ID NewPropList Prop ListItem oldItem Value)
          (SETQ ID (fetch (PropListItem Value) of (FASSOC (QUOTE ID)
							  OldPropList)))
          (for Item in EditedPropList
	     do (SETQ Prop (fetch (PropListItem PropertyName) of Item))
		(SETQ oldItem (FASSOC Prop OldPropList))
		(COND
		  ((EQ Prop (QUOTE ID)))
		  ((NULL NewPropList)
		    (SETQ NewPropList (LIST Prop (COND
					      ((fetch (PropListItem OriginalListFlg) of oldItem)
						(LIST (CADR Item)))
					      (T (CADR Item))))))
		  ((SETQ Value (LISTGET NewPropList Prop))
		    (LISTPUT NewPropList Prop (COND
			       ((LISTP Value)
				 (NCONC1 Value (CADR Item)))
			       (T (LIST (CADR Item)
					Value)))))
		  (T (LISTPUT NewPropList Prop (COND
				((fetch (PropListItem OriginalListFlg) of oldItem)
				  (LIST (CADR Item)))
				(T (CADR Item)))))))
          (NC.SetPropList ID NewPropList)
          (NC.SetPropListDirtyFlg ID T))))

(NC.PropListEditorOpenP
  (LAMBDA (Window)                                           (* NoteCards% User "17-Jun-84 15:13")
                                                             (* Is there a prop list editor opened on this window?)
    (for AttachedWindow in (ALLATTACHEDWINDOWS Window) thereis (WINDOWPROP AttachedWindow
									   (QUOTE PropListEditor)))))

(NC.SelectProperty
  (LAMBDA (Window)                                           (* fgh: "20-Apr-84 21:44")
                                                             (* Select one of the properties in prop list editor 
							     window Window)
    (PROG ((ClippingRegion (DSPCLIPPINGREGION NIL Window)))
          (WINDOWPROP Window (QUOTE SelectedObject)
		      NIL)
          (until (WINDOWPROP Window (QUOTE SelectedObject))
	     do (until (AND (MOUSESTATE LEFT)
			    (EQ (WHICHW LASTMOUSEX LASTMOUSEY)
				Window)))
		(COND
		  ((INSIDEP ClippingRegion (LASTMOUSEX Window)
			    (LASTMOUSEY Window))
		    (APPLY* (WINDOWPROP Window (QUOTE BUTTONEVENTFN))
			    Window))))
          (AND (EQ TEDIT.SELPENDING (WINDOWPROP Window (QUOTE TEXTOBJ)))
	       (SETQ TEDIT.SELPENDING))
          (RETURN (WINDOWPROP Window (QUOTE SelectedObject)
			      NIL)))))

(NC.ShowPointers
  (LAMBDA (TextStream)                                       (* rht: "17-Mar-85 18:38")
                                                             (* Open an inspector for the links for note card 
							     specified by TextStream above the window for the note 
							     card.)
    (PROG (Links (ID (NC.IDFromWindow (WINDOW.FROM.TEDIT.THING TextStream))))
          (SETQ Links (NCONC (for Link in (NC.FetchToLinks ID)
				join (LIST (if (EQ (fetch (NOTECARDLINK ANCHORMODE) of Link)
						   (QUOTE GlobalGlobal))
					       then "Global TO"
					     else "TO")
					   (LIST (create NOTECARDLINK
						    copying Link DISPLAYMODE ←(create LINKDISPLAYMODE
										 copying
										  (fetch
										    (NOTECARDLINK
										      DISPLAYMODE)
										     of Link)
										  SHOWTITLEFLG ← T 
										  SHOWLINKTYPEFLG ← T)
							 ))))
			     (for Link in (NC.FetchFromLinks ID)
				join (LIST "FROM" (LIST (create NOTECARDLINK
							   copying Link DISPLAYMODE ←(create 
										  LINKDISPLAYMODE
											copying
											 (fetch
											   (
NOTECARDLINK DISPLAYMODE) of Link)
											 SHOWTITLEFLG 
											 ← T 
										  SHOWLINKTYPEFLG ← T)
								   SOURCEID ←(fetch (NOTECARDLINK
										      DESTINATIONID)
										of Link)
								   DESTINATIONID ←(fetch
								     (NOTECARDLINK SOURCEID)
										     of Link)))))))
          (NC.OpenPropListEditor TextStream Links "List of Links" T T))))

(NC.StringIsListP
  (LAMBDA (string parenCount)                                (* dmr: "20-Mar-84 23:46")
                                                             (* T if string has a balanced number of 
							     (and). Var "parenCount" counts open parens.)
    (PROG (nextParen)
          (COND
	    ((NULL string)
	      (COND
		((ZEROP parenCount)
		  (RETURN T))
		(T (RETURN NIL)))))
          (SETQ nextParen (STRPOSL (QUOTE (%( %)))
				   string))
          (COND
	    ((NULL nextParen)
	      (RETURN NIL)))
          (COND
	    ((EQ (CHARCODE "(")
		 (EVAL (BQUOTE (CHARCODE , (SUBSTRING string nextParen nextParen)))))
	      (RETURN (NC.StringIsListP (SUBSTRING string (ADD1 nextParen))
					(ADD1 parenCount)))))
          (COND
	    ((EQ (CHARCODE ")")
		 (EVAL (BQUOTE (CHARCODE , (SUBSTRING string nextParen nextParen)))))
	      (RETURN (NC.StringIsListP (SUBSTRING string (ADD1 nextParen))
					(SUB1 parenCount)))))
          (BREAK))))

(NC.PutProp
  (LAMBDA (ID Prop Value DatabaseStream)                     (* fgh: " 7-Feb-85 21:20")

          (* * Put a property value pair on the NoteCardsPropList property of ID. ID must be active.)


    (PROG ((PropList (NC.FetchPropList ID)))
          (COND
	    (PropList (LISTPUT PropList Prop Value)
		      (NC.SetPropList ID PropList))
	    (T (NC.SetPropList ID (LIST Prop Value)))))))

(NC.GetProp
  (LAMBDA (ID Prop DatabaseStream)                           (* fgh: " 7-Feb-85 21:20")

          (* * Get the value of a property on the NoteCardsPropList property of ID. ID must be active.)


    (LISTGET (NC.FetchPropList ID)
	     Prop)))
)
(* * Unknown ?????????)

(DEFINEQ

(NC.FetchBeingDeletedFlg
  (LAMBDA (ID)                                               (* fgh: "26-Mar-84 20:47")
    (GETPROP ID (QUOTE BeingDeleted))))

(NC.SetBeingDeletedFlg
  (LAMBDA (ID Value)                                         (* fgh: "26-Mar-84 20:46")
    (PUTPROP ID (QUOTE BeingDeleted)
	     Value)))
)
(* * Place marker ImageObjects)

(DEFINEQ

(NC.PlaceMarkerCopyFn
  (LAMBDA (ImageObj)                                         (* fgh: " 5-Mar-84 23:22")
    (NC.MakePlaceMarker (IMAGEOBJPROP ImageObj (QUOTE OBJECTDATUM)))))

(NC.PlaceMarkerDisplayFn
  (LAMBDA (ImageObj Stream)                                  (* rht: " 7-Dec-84 19:33")

          (* * rht 9/24/84: Now works for press and interpress as well as screen.)


    (PROG ((Label (IMAGEOBJPROP ImageObj (QUOTE OBJECTDATUM)))
	   (Scale (DSPSCALE NIL Stream))
	   (Font (FONTCREATE (QUOTE HELVETICA)
			     12
			     (QUOTE ITALIC)
			     NIL Stream)))
          (RELMOVETO (ITIMES Scale 3)
		     0 Stream)
          (DSPFONT (PROG1 (DSPFONT Font Stream)
			  (PRIN1 (U-CASE Label)
				 Stream))
		   Stream))))

(NC.PlaceMarkerGetFn
  (LAMBDA (FileStream TextStream)                            (* fgh: " 5-Mar-84 23:25")
    (NC.MakePlaceMarker (READ FileStream))))

(NC.PlaceMarkerImageBoxFn
  (LAMBDA (ImageObj Stream)                                  (* rht: " 7-Dec-84 19:33")

          (* * rht 9/24/84: Now scales the box dimensions so can go to press and interpress.)


    (PROG ((Font (FONTCREATE (QUOTE HELVETICA)
			     12
			     (QUOTE ITALIC)
			     NIL Stream))
	   (Label (IMAGEOBJPROP ImageObj (QUOTE OBJECTDATUM)))
	   (Scale (DSPSCALE NIL Stream)))
          (RETURN (create IMAGEBOX
			  XSIZE ←(IPLUS (TIMES 6 Scale)
					(STRINGWIDTH (U-CASE Label)
						     Font))
			  YSIZE ←(IPLUS (TIMES 18 Scale)
					(FONTPROP Font (QUOTE HEIGHT)))
			  YDESC ←(IPLUS (TIMES 3 Scale)
					(FONTPROP Font (QUOTE DESCENT)))
			  XKERN ← 0)))))

(NC.PlaceMarkerPutFn
  (LAMBDA (ImageObj FileStream)                              (* fgh: "29-Feb-84 19:15")
    (PROG ((Label (IMAGEOBJPROP ImageObj (QUOTE OBJECTDATUM))))
          (PRIN2 (MKSTRING Label)
		 FileStream))))

(NC.MakePlaceMarker
  (LAMBDA (Label)                                            (* fgh: " 5-Mar-84 01:43")
    (IMAGEOBJCREATE Label (IMAGEFNSCREATE (FUNCTION NC.PlaceMarkerDisplayFn)
					  (FUNCTION NC.PlaceMarkerImageBoxFn)
					  (FUNCTION NC.PlaceMarkerPutFn)
					  (FUNCTION NC.PlaceMarkerGetFn)
					  (FUNCTION NC.PlaceMarkerCopyFn)
					  (FUNCTION NILL)
					  (FUNCTION NILL)
					  (FUNCTION NILL)
					  (FUNCTION NILL)
					  (FUNCTION NILL)))))
)
(PUTPROPS NCCARDS COPYRIGHT ("Xerox Corporation" 1984 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (3996 14859 (NC.SetNewCardFlg 4006 . 4298) (NC.FetchNewCardFlg 4300 . 4589) (
NC.CoerceToID 4591 . 5309) (NC.ActivateCard 5311 . 5481) (NC.ActiveCardP 5483 . 5698) (
NC.DeactivateCard 5700 . 6986) (NC.FetchFromLinks 6988 . 7155) (NC.FetchGlobalLinks 7157 . 7328) (
NC.FetchLinksDirtyFlg 7330 . 7502) (NC.FetchPropList 7504 . 7669) (NC.FetchRegion 7671 . 7832) (
NC.FetchRegionViewed 7834 . 8007) (NC.FetchScale 8009 . 8174) (NC.FetchSubstance 8176 . 8365) (
NC.FetchTitle 8367 . 8526) (NC.FetchToLinks 8528 . 8691) (NC.FetchType 8693 . 8850) (NC.FetchWindow 
8852 . 9656) (NC.IDP 9658 . 9954) (NC.MarkCardDirty 9956 . 10476) (NC.CardDirtyP 10478 . 10837) (
NC.SetFromLinks 10839 . 11016) (NC.SetGlobalLinks 11018 . 11205) (NC.SetInitialPropList 11207 . 11445)
 (NC.SetLinksDirtyFlg 11447 . 11629) (NC.SetPropList 11631 . 11809) (NC.SetRegion 11811 . 11983) (
NC.SetRegionViewed 11985 . 12174) (NC.SetScale 12176 . 12356) (NC.SetSubstance 12358 . 12567) (
NC.SetTitle 12569 . 12738) (NC.SetToLinks 12740 . 12913) (NC.SetType 12915 . 13089) (
NC.FetchTitleDirtyFlg 13091 . 13263) (NC.SetTitleDirtyFlg 13265 . 13447) (NC.FetchPropListDirtyFlg 
13449 . 13627) (NC.SetPropListDirtyFlg 13629 . 13817) (NC.ShrinkFn 13819 . 14112) (
NC.SetSubstanceDirtyFlg 14114 . 14304) (NC.FetchSubstanceDirtyFlg 14306 . 14486) (NC.TurnOffDirtyFlgs 
14488 . 14857)) (14896 18072 (NC.RetrieveFromLinks 14906 . 15404) (NC.RetrieveLinkLabels 15406 . 16057
) (NC.RetrievePropList 16059 . 16447) (NC.RetrieveTitle 16449 . 16892) (NC.RetrieveToLinks 16894 . 
17386) (NC.RetrieveGlobalLinks 17388 . 17763) (NC.RetrieveType 17765 . 18070)) (18117 51848 (
NC.AddParents 18127 . 19452) (NC.AssignSources 19454 . 20166) (NC.AssignTitle 20168 . 22114) (
NC.DeleteNoteCards 22116 . 24718) (NC.EditNoteCard 24720 . 25694) (NC.MakeNoteCard 25696 . 28165) (
NC.FileNoteCard 28167 . 28665) (NC.QuitCard 28667 . 29544) (NC.CheckContentsHooks 29546 . 30653) (
NC.CheckSources 30655 . 31610) (NC.CheckTitle 31612 . 32496) (NC.DeleteSource 32498 . 34583) (
NC.DetermineContentsCards 34585 . 36424) (NC.DetermineSources 36426 . 37396) (NC.InsureProperFiling 
37398 . 38000) (NC.QuitWithoutSaving 38002 . 42817) (NC.UnfileNoteCard 42819 . 44862) (
NC.UpdateUpdateList 44864 . 45693) (NC.CollectReferences 45695 . 46860) (NC.CardSaveFn 46862 . 49705) 
(NC.DetermineDisplayRegion 49707 . 51129) (NC.AbortCard 51131 . 51337) (NC.CardNeedsFilingP 51339 . 
51846)) (52005 78124 (NC.AddPropToPropList 52015 . 54761) (NC.CloseAllPropListEditors 54763 . 55324) (
NC.ClosePropListEditor 55326 . 57477) (NC.DelPropFromList 57479 . 58776) (NC.EditPropButtonFN 58778 . 
59153) (NC.EditProperties 59155 . 59719) (NC.EditPropList 59721 . 64909) (NC.ExtractPropList 64911 . 
68075) (NC.OpenPropListEditor 68077 . 71753) (NC.ProcessEditedPropList 71755 . 73210) (
NC.PropListEditorOpenP 73212 . 73615) (NC.SelectProperty 73617 . 74611) (NC.ShowPointers 74613 . 76272
) (NC.StringIsListP 76274 . 77404) (NC.PutProp 77406 . 77845) (NC.GetProp 77847 . 78122)) (78155 78515
 (NC.FetchBeingDeletedFlg 78165 . 78333) (NC.SetBeingDeletedFlg 78335 . 78513)) (78554 81119 (
NC.PlaceMarkerCopyFn 78564 . 78764) (NC.PlaceMarkerDisplayFn 78766 . 79385) (NC.PlaceMarkerGetFn 79387
 . 79556) (NC.PlaceMarkerImageBoxFn 79558 . 80344) (NC.PlaceMarkerPutFn 80346 . 80598) (
NC.MakePlaceMarker 80600 . 81117)))))
STOP