(FILECREATED "25-Oct-85 10:20:01" {QV}<NOTECARDS>RELEASE1.2I>NCCARDS.;26 85797  

      changes to:  (FNS NC.CoerceToID)

      previous date: "18-Oct-85 13:07:50" {QV}<NOTECARDS>RELEASE1.2I>NCCARDS.;24)


(* 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 NC.CloseCardsOffScreenFlg NC.BringUpCardAtOldPosFlg 
		    PSA.Database)
	(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.FetchSavedRegion 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.SetSavedRegion NC.SetRegionViewed 
	     NC.SetScale NC.SetSubstance NC.SetTitle NC.SetToLinks NC.SetType NC.FetchTitleDirtyFlg 
	     NC.SetTitleDirtyFlg NC.FetchPropListDirtyFlg NC.SetPropListDirtyFlg 
	     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)
	(* * Functions for handling dates.)
	(FNS NC.FetchTitleDate NC.FetchItemDate NC.FetchPropListDate NC.FetchLinksDate)
	(FNS NC.SetTitleDate NC.SetItemDate NC.SetPropListDate NC.SetLinksDate)))
(* * 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 NC.CloseCardsOffScreenFlg 
	    NC.BringUpCardAtOldPosFlg PSA.Database)
)

(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: "25-Oct-85 10:19")

          (* * Get the ID of WindowOrTextStreamOrID)


    (LET (Window)
      (COND
	((NC.IDP WindowOrTextStreamOrID)
	  WindowOrTextStreamOrID)
	((WINDOWP WindowOrTextStreamOrID)
	  (NC.IDFromWindow WindowOrTextStreamOrID))
	((TEXTSTREAMP WindowOrTextStreamOrID)
	  (if (WINDOWP (SETQ Window (WINDOW.FROM.TEDIT.THING WindowOrTextStreamOrID)))
	      then (NC.IDFromWindow Window)
	    else (STREAMPROP WindowOrTextStreamOrID (QUOTE NoteCardID))))
	(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: " 3-Oct-85 12:30")

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



          (* * rht 7/9/85: Now also removes the new date properties.)


    (REMPROP ID (QUOTE NoteCardRegion))
    (REMPROP ID (QUOTE NoteCardSavedRegion))
    (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))
    (REMPROP ID (QUOTE NoteCardItemDate))
    (REMPROP ID (QUOTE NoteCardLinksDate))
    (REMPROP ID (QUOTE NoteCardTitleDate))
    (REMPROP ID (QUOTE NoteCardPropListDate))
    (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.FetchSavedRegion
  (LAMBDA (ID)                                               (* rht: " 3-Oct-85 12:33")
    (GETPROP ID (QUOTE NoteCardSavedRegion))))

(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: "22-Sep-85 17:08")

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



          (* * rht 9/22/85: Rewrote slightly to remove the dangerous nested WINDOWPROP calls.)


    (LET ((NoteCardType (NC.FetchType ID)))
      (if (NC.ActiveCardP ID)
	  then (for Window in (OPENWINDOWS) bind UnshrunkenWin
		  do (COND
		       ((EQ ID (WINDOWPROP Window (QUOTE NoteCardID)))
			 (RETURN Window))
		       ((AND (WINDOWP (SETQ UnshrunkenWin (WINDOWPROP Window (QUOTE ICONFOR))))
			     (EQ ID (WINDOWPROP UnshrunkenWin (QUOTE NoteCardID))))
			 (RETURN UnshrunkenWin))))))))

(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.SetSavedRegion
  (LAMBDA (ID Region)                                        (* rht: " 3-Oct-85 14:44")
    (PUTPROP ID (QUOTE NoteCardSavedRegion)
	     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.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: " 3-Oct-85 19:43")

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



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



          (* * rht 10/3/85: No longer prints final, annoying, slow-to-disappear message in prompt window if nothing selected.)


    (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)."))
          (AND NewParents ID (for ParentID in NewParents bind OneHook when (NC.MakeChildLink ID 
											 ParentID 
											   Window)
				do (SETQ OneHook T) finally (RETURN OneHook))))))

(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: "30-May-85 21:54")

          (* * 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 OldTitle)
          (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))
					 "-->  "
					 (if (AND (STREQUAL (SETQ OldTitle (NC.RetrieveTitle ID 
										     PSA.Database))
							    "Untitled")
						  (NC.FetchNewCardFlg ID))
					     then NIL
					   else OldTitle)
					 (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: " 4-Oct-85 14:33")
                                                             (* 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 (NC.YesP (NC.AskUser 
							  "Are you sure you want to delete this?"
								     " -- " "Yes" (NULL DontClearFlg)
								     (NC.FetchWindow ID)
								     NIL NIL T))
						(NC.ClearMsg)))
			  (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
				    (RESETSAVE NIL (BQUOTE (NC.SetBeingDeletedFlg , ID NIL)))
				    (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)
						        (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.SetNewCardFlg ID NIL)
						        (NC.DeactivateCard ID T)))))))))))

(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: " 4-Oct-85 01:38")

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



          (* * rht 6/25/85: Now moves card off screen before saving if NC.CloseCardsOffScreenFlg is non-nil.)



          (* * rht 6/25/85: Brought the insure proper filing check back here from NC.CardSaveFn. Bails out if user cancelled 
	  operation inside of NC.InsureProperFiling)


    (PROG (Window (ID (NC.CoerceToID WindowOrTextStreamOrID)))
          (SETQ Window (NC.FetchWindow ID))                  (* The window not being open should mean that it's 
							     shrunken. If so, expand it.)
          (if (NOT (OPENWP Window))
	      then (EXPANDW Window))
          (OR DontSaveFlg (if (EQ (NC.InsureProperFiling ID PSA.Database)
				  (QUOTE CANCELLED))
			      then (RETURN (QUOTE DON'T))))
          (if (AND Window NC.CloseCardsOffScreenFlg)
	      then (if (NOT (NC.FetchSavedRegion ID))
		       then (NC.SetSavedRegion ID (WINDOWPROP Window (QUOTE REGION))))
		   (MOVEW Window 1500 1500))
          (OR DontSaveFlg (NC.CardSaveFn ID PSA.Database NC.CloseCardsOffScreenFlg))
          (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: "19-Aug-85 17:38")
                                                             (* 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 (" ID ") is not currently filed in a FileBox."
			      (CHARACTER 13))
		 (NC.MakeContentsHooks ID DatabaseStream)
	  else (NC.PrintMsg (NC.FetchWindow ID)
			    T "This card (" ID ") is not currently filed in a FileBox." (CHARACTER
			      13)
			    "It is being filed in the ToBeFiled FileBox."
			    (CHARACTER 13))
	       (NC.HookToOrphanCard ID NC.UnclassifiedID 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-Jul-85 13:48")

          (* 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
	    ((NC.YesP (NC.AskUser "Are you sure you want to flush your changes?" " -- " "Yes" T 
				  Window NIL NIL T))
	      (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 T))
		(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)                               (* fgh: "18-Jul-85 17:02")
                                                             (* 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 (create NOTECARDLINK copying Link DISPLAYMODE ←(create 
										  LINKDISPLAYMODE
										   copying
										    (fetch
										      (NOTECARDLINK
											DISPLAYMODE)
										       of Link)
										    SHOWTITLEFLG ←(
										      QUOTE SOURCE))))
	    )
          (SETQ EditWindow (NC.OpenPropListEditor WindowOrTextStream (LIST (QUOTE FileBoxes)
									   Links)
						  "List of File Boxes" T T))
          (BLOCK)
          (SETQ FileBoxes (NC.SelectNoteCards NIL (FUNCTION (LAMBDA (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 QuietFlg)               (* rht: "20-Sep-85 14:51")

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



          (* * rht 6/25/85: Pulled out InsureFilingFlg. That check now done upstairs in NC.QuitCard.)



          (* * rht 9/20/85: Added QuietFlg.)


    (PROG ((ID (NC.CoerceToID WindowOrID))
	   Window OldRegion NewRegion DoneAPutP)
          (OR (STREAMP DatabaseStream)
	      (SETQ DatabaseStream PSA.Database))
          (SETQ Window (NC.FetchWindow ID))
          (OR QuietFlg (NC.PrintMsg Window T ID ": Checking ... "))
          (COND
	    ((OR (NC.CardDirtyP ID)
		 (NC.FetchNewCardFlg ID))
	      (OR DoneAPutP QuietFlg (NC.PrintMsg Window NIL "Saving "))
	      (OR QuietFlg (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 QuietFlg (NC.PrintMsg Window NIL "Saving "))
	      (OR QuietFlg (NC.PrintMsg Window NIL "region, "))
	      (NC.UpdateRegionData ID DatabaseStream)
	      (SETQ DoneAPutP T)))
          (COND
	    ((NC.FetchTitleDirtyFlg ID)
	      (OR DoneAPutP QuietFlg (NC.PrintMsg Window NIL "Saving "))
	      (OR QuietFlg (NC.PrintMsg Window NIL "title, "))
	      (NC.PutTitle ID DatabaseStream)
	      (SETQ DoneAPutP T)))
          (COND
	    ((NC.FetchPropListDirtyFlg ID)
	      (OR DoneAPutP QuietFlg (NC.PrintMsg Window NIL "Saving "))
	      (OR QuietFlg (NC.PrintMsg Window NIL "proplist, "))
	      (NC.PutPropList ID DatabaseStream)
	      (SETQ DoneAPutP T)))
          (COND
	    ((NC.FetchLinksDirtyFlg ID)
	      (OR DoneAPutP QuietFlg (NC.PrintMsg Window NIL "Saving "))
	      (OR QuietFlg (NC.PrintMsg Window NIL "links, "))
	      (NC.PutLinks ID DatabaseStream)
	      (SETQ DoneAPutP T)))
          (OR DoneAPutP QuietFlg (NC.PrintMsg Window NIL (CHARACTER 13)
					      "Nothing changed. "))
                                                             (* It's not a new card anymore.)
          (NC.SetNewCardFlg ID NIL)
          (OR QuietFlg (NC.PrintMsg Window NIL "Done." (CHARACTER 13)))
          (DISMISS 500)
          (NC.ClearMsg Window T))))

(NC.DetermineDisplayRegion
  (LAMBDA (ID Region/Position)                               (* rht: " 3-Oct-85 12:00")
    (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)))))
		    ((AND NC.BringUpCardAtOldPosFlg (NC.FetchRegion 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: "23-Aug-85 15:31")
                                                             (* Add a new prop to the propList being edited in 
							     editW)
    (PROG ((promptWindow (GETPROMPTWINDOW editW 5 NIL NIL))
	   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 promptWindow)))
          (NC.PrintMsg promptWindow NIL (CHARACTER 13))
          (SETQ propValue (NC.AskUser (CONCAT "Value for " propName " property = ")
				      NIL NIL T promptWindow))
                                                             (* Insert these values into the editW)
                                                             (* Position just before selected button)
          (NC.PrintMsg promptWindow 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)                                   (* fgh: "29-Mar-85 19:47")

          (* 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 (CAR (MKLIST (fetch (TEXTOBJ \WINDOW) of TextObj))))
		     (until (fetch (TEXTOBJ EDITFINISHEDFLG) of TextObj) do (BLOCK)))))))

(NC.DelPropFromList
  (LAMBDA (editW)                                            (* fgh: "23-Aug-85 15:34")
    (PROG ((promptWindow (GETPROMPTWINDOW editW 5 NIL NIL))
	   (tobj (WINDOWPROP editW (QUOTE TEXTOBJ)))
	   (stream (WINDOWPROP editW (QUOTE TEXTSTREAM)))
	   selectedObject CH#)
          (NC.PrintMsg promptWindow T "Please select property to be deleted.")
          (SETQ selectedObject (NC.SelectProperty editW))
          (NC.ClearMsg promptWindow 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 2 (IDIFFERENCE (fetch CHLIM of (fetch SCRATCHSEL of tobj))
						     CH#)))
		  (TEDIT.DELETE stream CH# (IPLUS 2 (IDIFFERENCE (fetch CHLIM
								    of (fetch SCRATCHSEL
									  of tobj))
								 CH#)))
		  (TEDIT.SETSEL stream (GETEOFPTR stream)
				0
				(QUOTE RIGHT)))
		(T (NC.PrintMsg promptWindow 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: "11-Jul-85 19:06")
                                                             (* 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)))
	   PropList)
          (SETQ PropList (NC.FetchPropList ID))
          (NC.OpenPropListEditor TextStream (NCONC (for SubList on PropList by (CDDR SubList)
						      when (NEQ (CAR SubList)
								(QUOTE Updates))
						      join (LIST (CAR SubList)
								 (CADR SubList)))
						   (LIST (QUOTE ID)
							 ID
							 (QUOTE ItemDate)
							 (NC.FetchItemDate ID)
							 (QUOTE LinksDate)
							 (NC.FetchLinksDate ID)
							 (QUOTE PropsDate)
							 (NC.FetchPropListDate ID)
							 (QUOTE TitleDate)
							 (NC.FetchTitleDate ID)
							 (QUOTE Updates)
							 (LISTGET PropList (QUOTE Updates))))
				 "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: "18-Oct-85 12:09")
                                                             (* 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))
	   (SystemProperties (QUOTE (ID Updates ItemDate LinksDate PropsDate TitleDate)))
	   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)
					     SystemProperties)
				       (replace (PropListItem AllowEditFlg) of Item with T)
				       (replace (PropListItem AllowSelectFlg) of Item with T))
				     (ShowOnlyFlg (replace (PropListItem AllowEditFlg) of Item
						     with NIL)
						  (replace (PropListItem AllowSelectFlg)
						     of Item with T))
				     (T (replace (PropListItem AllowEditFlg) of Item with NIL)
					(replace (PropListItem AllowSelectFlg) of Item with NIL))))
                                                             (* Call the prop list editor)
          (ATTACHWINDOW (SETQ EditWindow (CREATEW (CREATEREGION 1000 2000 100 100)
						  (OR Title "Edit Property List")
						  NIL T))
			Window
			(QUOTE TOP)
			(QUOTE JUSTIFY)
			(QUOTE LOCALCLOSE))
          (WINDOWADDPROP EditWindow (QUOTE CLOSEFN)
			 (FUNCTION NC.ClosePropListEditor))
          (WINDOWPROP EditWindow (QUOTE PropListEditor)
		      (COND
			(ShowOnlyFlg (QUOTE ShowOnly))
			(T T)))
          (NC.EditPropList PropList EditWindow ShowOnlyFlg)
          (RETURN EditWindow))))

(NC.ProcessEditedPropList
  (LAMBDA (EditedPropList OldPropList)                       (* fgh: "11-Jul-85 19:17")
                                                             (* 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
		  ((FMEMB Prop (QUOTE (ID ItemDate LinksDate PropsDate TitleDate))))
		  ((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)))))
)
(* * Functions for handling dates.)

(DEFINEQ

(NC.FetchTitleDate
  (LAMBDA (ID)                                               (* rht: " 9-Jul-85 16:00")
    (GETPROP ID (QUOTE NoteCardTitleDate))))

(NC.FetchItemDate
  (LAMBDA (ID)                                               (* rht: " 9-Jul-85 16:02")
    (GETPROP ID (QUOTE NoteCardItemDate))))

(NC.FetchPropListDate
  (LAMBDA (ID)                                               (* rht: " 9-Jul-85 16:02")
    (GETPROP ID (QUOTE NoteCardPropListDate))))

(NC.FetchLinksDate
  (LAMBDA (ID)                                               (* rht: " 9-Jul-85 16:02")
    (GETPROP ID (QUOTE NoteCardLinksDate))))
)
(DEFINEQ

(NC.SetTitleDate
  (LAMBDA (ID Date)                                          (* rht: " 9-Jul-85 16:05")
    (PUTPROP ID (QUOTE NoteCardTitleDate)
	     Date)))

(NC.SetItemDate
  (LAMBDA (ID Date)                                          (* rht: " 9-Jul-85 16:05")
    (PUTPROP ID (QUOTE NoteCardItemDate)
	     Date)))

(NC.SetPropListDate
  (LAMBDA (ID Date)                                          (* rht: " 9-Jul-85 16:06")
    (PUTPROP ID (QUOTE NoteCardPropListDate)
	     Date)))

(NC.SetLinksDate
  (LAMBDA (ID Date)                                          (* rht: " 9-Jul-85 16:06")
    (PUTPROP ID (QUOTE NoteCardLinksDate)
	     Date)))
)
(PUTPROPS NCCARDS COPYRIGHT ("Xerox Corporation" 1984 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (4333 15504 (NC.SetNewCardFlg 4343 . 4635) (NC.FetchNewCardFlg 4637 . 4926) (
NC.CoerceToID 4928 . 5683) (NC.ActivateCard 5685 . 5855) (NC.ActiveCardP 5857 . 6072) (
NC.DeactivateCard 6074 . 7577) (NC.FetchFromLinks 7579 . 7746) (NC.FetchGlobalLinks 7748 . 7919) (
NC.FetchLinksDirtyFlg 7921 . 8093) (NC.FetchPropList 8095 . 8260) (NC.FetchRegion 8262 . 8423) (
NC.FetchSavedRegion 8425 . 8596) (NC.FetchRegionViewed 8598 . 8771) (NC.FetchScale 8773 . 8938) (
NC.FetchSubstance 8940 . 9129) (NC.FetchTitle 9131 . 9290) (NC.FetchToLinks 9292 . 9455) (NC.FetchType
 9457 . 9614) (NC.FetchWindow 9616 . 10412) (NC.IDP 10414 . 10710) (NC.MarkCardDirty 10712 . 11232) (
NC.CardDirtyP 11234 . 11593) (NC.SetFromLinks 11595 . 11772) (NC.SetGlobalLinks 11774 . 11961) (
NC.SetInitialPropList 11963 . 12201) (NC.SetLinksDirtyFlg 12203 . 12385) (NC.SetPropList 12387 . 12565
) (NC.SetRegion 12567 . 12739) (NC.SetSavedRegion 12741 . 12923) (NC.SetRegionViewed 12925 . 13114) (
NC.SetScale 13116 . 13296) (NC.SetSubstance 13298 . 13507) (NC.SetTitle 13509 . 13678) (NC.SetToLinks 
13680 . 13853) (NC.SetType 13855 . 14029) (NC.FetchTitleDirtyFlg 14031 . 14203) (NC.SetTitleDirtyFlg 
14205 . 14387) (NC.FetchPropListDirtyFlg 14389 . 14567) (NC.SetPropListDirtyFlg 14569 . 14757) (
NC.SetSubstanceDirtyFlg 14759 . 14949) (NC.FetchSubstanceDirtyFlg 14951 . 15131) (NC.TurnOffDirtyFlgs 
15133 . 15502)) (15541 18717 (NC.RetrieveFromLinks 15551 . 16049) (NC.RetrieveLinkLabels 16051 . 16702
) (NC.RetrievePropList 16704 . 17092) (NC.RetrieveTitle 17094 . 17537) (NC.RetrieveToLinks 17539 . 
18031) (NC.RetrieveGlobalLinks 18033 . 18408) (NC.RetrieveType 18410 . 18715)) (18762 54028 (
NC.AddParents 18772 . 19944) (NC.AssignSources 19946 . 20658) (NC.AssignTitle 20660 . 22792) (
NC.DeleteNoteCards 22794 . 25384) (NC.EditNoteCard 25386 . 26360) (NC.MakeNoteCard 26362 . 28831) (
NC.FileNoteCard 28833 . 29331) (NC.QuitCard 29333 . 31156) (NC.CheckContentsHooks 31158 . 32336) (
NC.CheckSources 32338 . 33293) (NC.CheckTitle 33295 . 34179) (NC.DeleteSource 34181 . 36266) (
NC.DetermineContentsCards 36268 . 38107) (NC.DetermineSources 38109 . 39079) (NC.InsureProperFiling 
39081 . 39683) (NC.QuitWithoutSaving 39685 . 44472) (NC.UnfileNoteCard 44474 . 46654) (
NC.UpdateUpdateList 46656 . 47485) (NC.CollectReferences 47487 . 48652) (NC.CardSaveFn 48654 . 51817) 
(NC.DetermineDisplayRegion 51819 . 53309) (NC.AbortCard 53311 . 53517) (NC.CardNeedsFilingP 53519 . 
54026)) (54185 81259 (NC.AddPropToPropList 54195 . 57062) (NC.CloseAllPropListEditors 57064 . 57625) (
NC.ClosePropListEditor 57627 . 59790) (NC.DelPropFromList 59792 . 61167) (NC.EditPropButtonFN 61169 . 
61544) (NC.EditProperties 61546 . 62705) (NC.EditPropList 62707 . 67895) (NC.ExtractPropList 67897 . 
71061) (NC.OpenPropListEditor 71063 . 74844) (NC.ProcessEditedPropList 74846 . 76345) (
NC.PropListEditorOpenP 76347 . 76750) (NC.SelectProperty 76752 . 77746) (NC.ShowPointers 77748 . 79407
) (NC.StringIsListP 79409 . 80539) (NC.PutProp 80541 . 80980) (NC.GetProp 80982 . 81257)) (81290 81650
 (NC.FetchBeingDeletedFlg 81300 . 81468) (NC.SetBeingDeletedFlg 81470 . 81648)) (81689 84254 (
NC.PlaceMarkerCopyFn 81699 . 81899) (NC.PlaceMarkerDisplayFn 81901 . 82520) (NC.PlaceMarkerGetFn 82522
 . 82691) (NC.PlaceMarkerImageBoxFn 82693 . 83479) (NC.PlaceMarkerPutFn 83481 . 83733) (
NC.MakePlaceMarker 83735 . 84252)) (84297 84987 (NC.FetchTitleDate 84307 . 84474) (NC.FetchItemDate 
84476 . 84641) (NC.FetchPropListDate 84643 . 84816) (NC.FetchLinksDate 84818 . 84985)) (84988 85714 (
NC.SetTitleDate 84998 . 85174) (NC.SetItemDate 85176 . 85350) (NC.SetPropListDate 85352 . 85534) (
NC.SetLinksDate 85536 . 85712)))))
STOP