(FILECREATED "30-Jan-85 14:58:41" {PHYLUM}<NOTECARDS>RELEASE1.1>LOOPSNOTECARDS.;17 77486  

      changes to:  (CLASSES Card FileboxCard)

      previous date: "28-Jan-85 20:10:15" {PHYLUM}<NOTECARDS>RELEASE1.1>LOOPSNOTECARDS.;16)


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

(PRETTYCOMPRINT LOOPSNOTECARDSCOMS)

(RPAQQ LOOPSNOTECARDSCOMS ((* File created by TRIGG)
	(CLASSES BrowserCard Card DocumentCard FileboxCard GlobalAnchor GraphCard GrapherSubstance 
		 Link LinkAnchor LinkIndexCard Notefile PointAnchor SearchCard SketchCard 
		 SketchSubstance SpanAnchor Substance TEditSubstance TextCard TopLevel)
	(METHODS Card.BringUp Card.CollectLinksInCard Card.Deactivate Card.Delete 
		 Card.DeleteLinksInCard Card.File Card.GetActiveP Card.GetIndexPtr 
		 Card.GetInitialInfoFromStream Card.GetLinksFromStream Card.GetNCid 
		 Card.GetPropListFromStream Card.GetPtrsFromStream Card.GetRegionFromStream 
		 Card.GetTitleFromStream Card.GetTypeName Card.InsureProperFiling 
		 Card.MakeDummyRegion Card.PutLinksToStream Card.PutPropListToStream 
		 Card.PutRegionToStream Card.PutRegionToStreamAtCurPtr Card.PutSubstanceToStream 
		 Card.PutTitleToStream Card.Quit Card.RegionChangedP Card.Retrieve Card.Store 
		 Card.StoreIfNeeded Card.Unfile Card.UpdateLinksInCard GrapherSubstance.BringUp 
		 GrapherSubstance.ChangedP GrapherSubstance.RetrieveFromStream 
		 GrapherSubstance.StoreOnStream Link.Testfoo Notefile.CardItemFromNumber 
		 Notefile.Close Notefile.CreateCards Notefile.ForceNotefileClose 
		 Notefile.GetCardInitialInfo Notefile.GetCardTitle Notefile.GetCardType 
		 Notefile.GetCardTypeAndTitle Notefile.GetFullFileName Notefile.GetHighestID 
		 Notefile.GetStream Notefile.Open Notefile.QuitAllCards Notefile.SaveNextLinkID 
		 SketchSubstance.BringUp SketchSubstance.ChangedP SketchSubstance.RetrieveFromStream 
		 SketchSubstance.StoreOnStream Substance.ChangedP Substance.GetSubstanceVal 
		 Substance.MarkUnchanged Substance.Wrapup TEditSubstance.BringUp 
		 TEditSubstance.ChangedP TEditSubstance.RetrieveFromStream 
		 TEditSubstance.StoreOnStream TEditSubstance.Wrapup TopLevel.AskCardRegion 
		 TopLevel.AskNotefileName TopLevel.MakeNotefileName TopLevel.OpenNotefile 
		 TopLevel.QuitNotefile)
	(FNS NCL.QuitCard NCL.GetPtrs NCL.IndexFromNumber NCL.ClassNameFromTypeName 
	     NCL.CardFromWindow)
	(VARS (NCL.TypeToClassAssocList (QUOTE ((Text . TextCard)
						(Graph . GraphCard)
						(Sketch . SketchCard)
						(FileBox . FileboxCard)
						(Browser . BrowserCard)
						(LinkIndex . LinkIndexCard)
						(Search . SearchCard)
						(Document . DocumentCard)))))
	(GLOBALVARS NCL.TypeToClassAssocList NCL.CurrentTopLevel)
	(INSTANCES)
	(RECORDS NotefileCardsArrayItem)))



(* File created by TRIGG)

(DEFCLASSES BrowserCard Card DocumentCard FileboxCard GlobalAnchor GraphCard GrapherSubstance Link 
	    LinkAnchor LinkIndexCard Notefile PointAnchor SearchCard SketchCard SketchSubstance 
	    SpanAnchor Substance TEditSubstance TextCard TopLevel)
[DEFCLASS BrowserCard
   (MetaClass Class Edited:                                  (* rht: "25-Jan-85 16:49"))
   (Supers GraphCard)
   (ClassVariables (DefaultWindowWidth 500)
		   (DefaultWindowHeight 350)
		   (TypeNameOnNotefile Browser))]

[DEFCLASS Card
   (MetaClass Class Edited:                                  (* rht: "30-Jan-85 14:19"))
   (Supers Object)
   (ClassVariables (SubstanceClassName Substance doc         (* The class name of the substance for this card type.)
				       )
		   (DefaultWindowHeight 200 doc              (* The height of the generic card's window when first 
							     created.))
		   (DefaultWindowWidth 300 doc               (* The width of a generic card's window when first 
							     created.))
		   (TypeNameOnNotefile NIL doc               (* The atom on the notefile representing this class 
							     name.))
		   (LeftMenuItems (Show/Edit% Properties Title/Sources/Fileboxes Insert% Link 
							 Close% and% Save)
				  doc                        (* The items to appear on this class's title bar left 
							     button menus. Items are other class variables.)
				  )
		   (Show/Edit% Properties (Edit% Property% List Show% Links)
					  ItemValue EditProperties ItemMessage 
					  "Edit property list or show links."
					  doc                (* The menu item for showing links or editing the 
							     property list.)
					  )
		   (Edit% Property% List NIL ItemValue EditProperties ItemMessage 
					"Brings up an editor for the property list of this card."
					 doc                 (* The menu item for editing the property list.)
					 )
		   (Show% Links NIL ItemValue ShowLinks ItemMessage 
				"Brings up a list of the links to and from this card."
				doc                          (* The menu item for showing links)
				)
		   (Title/Sources/Fileboxes (Assign% Title Designate% Sources File% in% FileBoxes 
							   Unfile% from% Fileboxes Delete% Source)
					    ItemValue EditTitleSourcesFileboxes ItemMessage 
		       "Do all of the operations necessary to file this note card in a file box."
					    doc              (* The menu item for hacking titles, sources and 
							     filing.)
					    )
		   (Assign% Title NIL ItemValue AssignTitle ItemMessage 
				  "Assigns a (new) title to this note card."
				  doc                        (* The menu item for changing the title.)
				  )
		   (Designate% Sources NIL ItemValue AssignSources ItemMessage 
				       "Designate the source(s) of the information in this card."
				       doc                   (* The menu item for assigning new sources.)
				       )
		   (File% in% FileBoxes NIL ItemValue File ItemMessage 
					"File this note card in one or more file boxes."
					doc                  (* The menu item for adding new parent fileboxes.)
					)
		   (Unfile% from% Fileboxes NIL ItemValue Unfile ItemMessage 
					   "Remove this card from one or more of its file boxes."
					    doc              (* The menu item for removing parent fileboxes.)
					    )
		   (Delete% Source NIL ItemValue DeleteSource ItemMessage 
				   "Delete one of the sources of this card."
				   doc                       (* The menu item for removing source.)
				   )
		   (Insert% Link%(s%) (Insert% Link Insert% Links)
				      ItemValue AddLink ItemMessage 
		     "Insert a link to another card at the currently selected point in the text."
				      doc                    (* The menu item for adding link 
							     (s).)
				      )
		   (Insert% Link NIL ItemValue AddLink ItemMessage 
		     "Insert a link to another card at the currently selected point in the text."
				 doc                         (* The menu item for adding link.)
				 )
		   (Insert% Links NIL ItemValue AddLinks ItemMessage 
		       "Insert links to other cards at the currently selected point in the text."
				  doc                        (* The menu item for adding links.)
				  )
		   (Close (Close% and% Save Close% w/o% Saving Save% in% NoteFile Delete% Card)
			  ItemValue Quit ItemMessage 
			  "Close this note card after saving it in the NoteFile."
			  doc                                (* The menu item for different sorts of closing.)
			  )
		   (Close% and% Save NIL ItemValue Quit ItemMessage 
				     "Close this note card after saving it in the NoteFile."
				     doc                     (* The menu item for closing and saving.)
				     )
		   (Close% w/o% Saving NIL ItemValue QuitWithoutSaving ItemMessage 
		      "Close this note card without saving any changes made since the last Save."
				       doc                   (* The menu item for closing without saving.)
				       )
		   (Save% in% NoteFile NIL ItemValue SaveWithoutClosing ItemMessage 
				       "Save this card in the NoteFile but don't close the card."
				       doc                   (* The menu item for saving without closing)
				       )
		   (Delete% Card NIL ItemValue Delete ItemMessage 
				 "Permenantly delete this card from the NoteFile."
				 doc                         (* The menu item for deleting the card.)
				 ))
   (InstanceVariables (Title "Untitled" doc                  (* Title of card))
		      (NCid NIL doc                          (* fake id for file))
		      (PropList NIL doc                      (* IV added by TRIGG))
		      (ToLinks NIL doc                       (* IV added by TRIGG))
		      (FromLinks NIL doc                     (* IV added by TRIGG))
		      (Substance NIL doc                     (* IV added by TRIGG))
		      (Window NIL doc                        (* IV added by TRIGG))
		      (Region NIL doc                        (* IV added by TRIGG))
		      (DirtyFlg NIL doc                      (* IV added by TRIGG))
		      (Notefile NIL doc                      (* IV added by TRIGG))
		      (DefaultLinkDisplayMode NIL doc        (* IV added by TRIGG))
		      (ActiveP NIL doc                       (* IV added by TRIGG))
		      (LinksDirtyFlg NIL doc                 (* Says whether card's links need to be written out.)
				     )
		      (TitleDirtyFlg NIL doc                 (* Non-nil if title has changed since last time card 
							     was written.))
		      (PropListDirtyFlg NIL doc              (* Non-nil if proplist has changed since last time card
							     was written.))
		      (CardNumber NIL doc                    (* The index for this card. Used to access the array 
							     stored in the notefile object.))
		      (GlobalLinks NIL doc                   (* The global links. These should be taken out, since 
							     the anchor gives whether global or local.)
				   ))]

[DEFCLASS DocumentCard
   (MetaClass Class Edited:                                  (* rht: "25-Jan-85 16:49"))
   (Supers TextCard)
   (ClassVariables (DefaultWindowWidth 335)
		   (DefaultWindowHeight 200)
		   (TypeNameOnNotefile Document))]

[DEFCLASS FileboxCard
   (MetaClass Class Edited:                                  (* rht: "30-Jan-85 14:23"))
   (Supers TextCard)
   (ClassVariables (TypeNameOnNotefile FileBox)
		   (LeftMenuItems (Show/Edit% Properties Title/Sources/Fileboxes Collect% Children 
							 Close% and% Save)
				  doc                        (* The items to appear on this class's title bar left 
							     button menus. Items are other class variables.)
				  )
		   (Collect% Children NIL ItemValue CollectChildren ItemMessage 
				      "Collect new child cards and fileboxes for this filebox."
				      doc                    (* The menu item for adding new children.)
				      ))]

[DEFCLASS GlobalAnchor
   (MetaClass Class Edited:                                  (* rht: "18-Jan-85 14:43"))
   (Supers LinkAnchor)]

[DEFCLASS GraphCard
   (MetaClass Class Edited:                                  (* rht: "25-Jan-85 16:58"))
   (Supers Card)
   (ClassVariables (DefaultWindowWidth 300)
		   (DefaultWindowHeight 200)
		   (TypeNameOnNotefile Graph doc             (* The atom on the notefile representing this class 
							     name.))
		   (SubstanceClassName GrapherSubstance))]

[DEFCLASS GrapherSubstance
   (MetaClass Class Edited:                                  (* rht: "18-Jan-85 14:42"))
   (Supers Substance)
   (ClassVariables (GraphLeftButtonFn NCL.GraphLeftButtonFn doc 
                                                             (* The left button fn passed to SHOWGRAPH.)
				      )
		   (GraphMiddleButtonFn NCL.GraphMiddleButtonFn doc 
                                                             (* The middle button fn passed to SHOWGRAPH.)
					))]

[DEFCLASS Link
   (MetaClass Class Edited:                                  (* rht: "18-Jan-85 14:40"))
   (Supers Object)
   (InstanceVariables (Source **DefaultValue doc             (* test for Gregor)))]

[DEFCLASS LinkAnchor
   (MetaClass Class Edited:                                  (* rht: "18-Jan-85 14:41"))
   (Supers Object)]

[DEFCLASS LinkIndexCard
   (MetaClass Class Edited:                                  (* rht: "25-Jan-85 16:49"))
   (Supers TextCard)
   (ClassVariables (TypeNameOnNotefile LinkIndex))]

[DEFCLASS Notefile
   (MetaClass Class Edited:                                  (* rht: "18-Jan-85 11:10"))
   (Supers Object)
   (InstanceVariables (Stream NIL doc                        (* The stream for this notefile.))
		      (FullFileName **DefaultValue doc       (* The fullname of the notefile's FileName)
				    )
		      (IndexSizeInEntries NIL doc            (* Number of entries in this notefile.))
		      (NextLinkID NIL doc                    (* ID number of the next link in this notefile.)
				  )
		      (CardsArray NIL doc                    (* List of all cards in the notefile.
							     Includes inactive cards, but not deleted ones.)
				  ))]

[DEFCLASS PointAnchor
   (MetaClass Class Edited:                                  (* rht: "18-Jan-85 14:43"))
   (Supers LinkAnchor)]

[DEFCLASS SearchCard
   (MetaClass Class Edited:                                  (* rht: "25-Jan-85 16:49"))
   (Supers TextCard)
   (ClassVariables (TypeNameOnNotefile Search))]

[DEFCLASS SketchCard
   (MetaClass Class Edited:                                  (* rht: "25-Jan-85 16:48"))
   (Supers Card)
   (ClassVariables (DefaultWindowWidth 400)
		   (DefaultWindowHeight 350)
		   (TypeNameOnNotefile Sketch)
		   (SubstanceClassName SketchSubstance))]

[DEFCLASS SketchSubstance
   (MetaClass Class Edited:                                  (* rht: "18-Jan-85 14:42"))
   (Supers Substance)
   (ClassVariables (InitialScale NIL doc                     (* The initial scale passed to SKETCHW.CREATE)
				 ))
   (InstanceVariables (Scale NIL doc                         (* Something that sketch wants.))
		      (RegionViewed NIL doc                  (* Something that sketch wants.)))]

[DEFCLASS SpanAnchor
   (MetaClass Class Edited:                                  (* rht: "18-Jan-85 14:43"))
   (Supers LinkAnchor)]

[DEFCLASS Substance
   (MetaClass Class Edited:                                  (* rht: "18-Jan-85 14:41"))
   (Supers Object)
   (InstanceVariables (SubstanceVal NIL doc                  (* This slot contains the actual substance, say TEdit 
							     stream, graph, etc.))
		      (DirtyFlg **DefaultValue doc           (* Inidicates whether the substance has been written 
							     since last chane.)))]

[DEFCLASS TEditSubstance
   (MetaClass Class Edited:                                  (* rht: "18-Jan-85 14:41"))
   (Supers Substance)
   (ClassVariables (DefaultFont NIL doc                      (* The default tedit font passed to TEDIT.)
				)
		   (TitleMenuFn **DefaultValue doc           (* The TITLEMENUFN passed as a prop to TEDIT.)
				))]

[DEFCLASS TextCard
   (MetaClass Class Edited:                                  (* rht: "25-Jan-85 16:48"))
   (Supers Card)
   (ClassVariables (TypeNameOnNotefile Text)
		   (SubstanceClassName TEditSubstance))]

[DEFCLASS TopLevel
   (MetaClass Class Edited:                                  (* rht: "22-Jan-85 15:09"))
   (Supers Object)
   (InstanceVariables (Notefiles NIL doc                     (* List of Notefiles currently open.))
		      (NotefileNameSuggestion NIL doc        (* used to prompt user when asking for a notefile 
							     name.))
		      (UncachingNotCompletedFlg **DefaultValue doc 
                                                             (* If non-nil, then crashed during last notefile close.
							     Need to finish uncaching IDs.)))]

[METH Card  BringUp (Region/Position)
      (* * This brings up a card. If window already exists, then flash. Otherwise, retrieve the card, 
	 create a window, and return it.)]


[METH Card  CollectLinksInCard NIL
      (*)]


[METH Card  Deactivate (ClearTitle)
      (* * Clear all junk off the card.)]


[METH Card  Delete NIL
      (*)]


[METH Card  DeleteLinksInCard NIL
      (*)]


[METH Card  File NIL
      (*)]


[METH Card  GetActiveP NIL
      (* * Is this card active?)]


[METH Card  GetIndexPtr NIL
      (* * Return the stream index ptr for this card number.)]


[METH Card  GetInitialInfoFromStream (Stream Ptr)
      (* * Get the preliminary junk for a notecard. Check to make sure type agrees and return 
	 pointer.)]


[METH Card  GetLinksFromStream (Stream)
      (* * Grab the links for this card from the notefile. Stream's pointer is assumed to be set 
	 properly.)]


[METH Card  GetNCid NIL
      (* * Just return the NCid slot)]


[METH Card  GetPropListFromStream (Stream)
      (* * Fetch and set the card's proplist. Stream's pointer is assumed to be posistioned properly.)
]


[METH Card  GetPtrsFromStream (Stream)
      (* * Return the list of pointers into the notefile for a given card. First element of the list 
	 is the card's status.)]


[METH Card  GetRegionFromStream (Stream)
      (* * Retrieve the card's region from the stream. Stream pointer should be all set.)]


[METH Card  GetTitleFromStream (Stream)
      (* * Retrieve the card's title from the notefile stream. Stream's pointer is assumed to be 
	 properly positioned.)]


[METH Card  GetTypeName NIL
      (* * Return the type name which should be written to the notefile to represent this class.)]


[METH Card  InsureProperFiling NIL
      (* New method template)]


[METH Card  MakeDummyRegion NIL
      (* * Make a region with width and height corresponding to the default size of window's for this 
	 type of card.)]


[METH Card  PutLinksToStream (Stream)
      (* * Put the links of card onto notefile stream.)]


[METH Card  PutPropListToStream (Stream)
      (* * Put the proplist of card ID onto notefile stream.)]


[METH Card  PutRegionToStream (Stream)
      (* * Put out the region to the stream, first positioning the stream properly.)]


[METH Card  PutRegionToStreamAtCurPtr (Stream)
      (* * Put the card's region down to the stream at the current stream ptr.)]


[METH Card  PutSubstanceToStream (Stream UpdateUpdateListFlg)
      (* * This dumps the initial junk like ID and type, dumps the substance, and then updates the 
	 index with the new pointer.)]


[METH Card  PutTitleToStream (Stream)
      (* * Put the title of card ID onto notefile stream.)]


[METH Card  Quit (Don'tSave InsideOfWindowClose ClearTitle)
      (* * Close this card and its window.)]


[METH Card  RegionChangedP NIL
      (* * Return non-nil if the card has a window and it's region has changed.)]


[METH Card  Retrieve NIL
      (*)]


[METH Card  Store NIL
      (*)]


[METH Card  StoreIfNeeded NIL
      (* * Store any parts of the card that are dirty back in the notefile.)]


[METH Card  Unfile NIL
      (*)]


[METH Card  UpdateLinksInCard NIL
      NIL]


[METH GrapherSubstance  BringUp (Window Title)
      (* * Bring up this graph in the given window.)]


[METH GrapherSubstance  ChangedP NIL
      (* * Right now, always have to write out graph, even if hasn't really changed, because grapher 
	 doesn't tell us when changes were made.)]


[METH GrapherSubstance  RetrieveFromStream (Notefile Stream)
      (* * Set the substance's SubstanceVal by fetching a Graph substance from the notefile.)]


[METH GrapherSubstance  StoreOnStream (Stream Window)
      (* * Put Graph to notefile stream.)]


[METH Link  Testfoo (increment)
      (* New method template)]


[METH Notefile  CardItemFromNumber (CardNumber)
      (* * Use CardNumber as index into array to retrieve the pair for that card. First element is 
	 pointer to object, second is status litatom.)]


[METH Notefile  Close (QuietFlg)
      (* * Closes this notefile.)]


[METH Notefile  CreateCards (QuietFlg OperationMsg)
      (* * Create objects for each card in the notefile and cache titles. Create an array containing 
	 pointers to card objects and card status. Array indices are card ID numbers.)]


[METH Notefile  ForceNotefileClose NIL
      (* * Really close the database, i.e.. bypass the ADVISE on CLOSEF that prevents closing of the 
	 database.)]


[METH Notefile  GetCardInitialInfo (Ptr ID CardType)
      NIL]


[METH Notefile  GetCardTitle (ID TitlePtr)
      (* * Retrieve a card's title from the notefile.)]


[METH Notefile  GetCardType (ID Ptr)
      (* * Get a card's type from the notefile.)]


[METH Notefile  GetCardTypeAndTitle (ID Index)
      (* * Retrieve the type and title of ID from the notefile.)]


[METH Notefile  GetFullFileName NIL
      (* * Just return the full name of the file this notefile is for.)]


[METH Notefile  GetHighestID NIL
      (* New method template)]


[METH Notefile  GetStream NIL
      (* * Return the stream for this notefile.)]


[METH Notefile  Open (Access QuietFlg)
      (* * Open this notefile, creating objects for each active card and caching titles. Returns 
	 non-nil if successful.)]


[METH Notefile  QuitAllCards (QuietFlg OperationMsg)
      (* * Quit any remaining active cards and remove pointers to them from the notefile.)]


[METH Notefile  SaveNextLinkID (ClosingDatabaseFlg)
      (* * Save the next link id info for DatabaseStream on the database)]


[METH SketchSubstance  BringUp (Window Title)
      (* * Bring up this sketch in the given window with given title.)]


[METH SketchSubstance  ChangedP (Window)
      (* * Is this sketch substance dirty?)]


[METH SketchSubstance  RetrieveFromStream (Notefile Stream)
      (* * Set the substance's SubstanceVal by fetching a Sketch substance from the notefile.)]


[METH SketchSubstance  StoreOnStream (Stream Window)
      (* Put the sketch substance for card ID to the database. Store the global sketch descriptor, 
	 the scale and region viewed for ID and any cached bit maps.)]


[METH Substance  ChangedP NIL
      (* * Has the substance been changed since last write?)]


[METH Substance  GetSubstanceVal NIL
      (* * Just return the value of the substance.)]


[METH Substance  MarkUnchanged NIL
      (* * Note that the substance is no longer dirty.)]


[METH Substance  Wrapup NIL
      (* * Called when quitting a card after saving substance. Do nothing is the generic case.)]


[METH TEditSubstance  BringUp (Window Title)
      (* * This brings up tedit in the given window.)]


[METH TEditSubstance  ChangedP NIL
      (* * Return non-nil if this substance is dirty.)]


[METH TEditSubstance  RetrieveFromStream (Stream)
      (* * Set the substance's SubstanceVal by fetching a TEdit stream from the notefile stream.)]


[METH TEditSubstance  StoreOnStream (Stream Window)
      (* * Put this substance on the notefile stream.)]


[METH TEditSubstance  Wrapup NIL
      (* * Stuff to do when quitting a tedit card after it's been saved.)]


[METH TopLevel  AskCardRegion (Width Height PromptMsg)
      (* * Get from user a region to bring up the card in.)]


[METH TopLevel  AskNotefileName (Msg ClearFirstFlg NoSuggestFlg)
      (* New method template)]


[METH TopLevel  MakeNotefileName (Name)
      (* * Attach the .NOTEFILE extension.)]


[METH TopLevel  OpenNotefile (FileName Access QuietFlg Don'tCreateFlg)
      (* * Open a notefile: create a notefile object and send it the open message.)]


[METH TopLevel  QuitNotefile (Notefile)
      (* * Remove this notefile from the list of "active" notefiles.)]


(DEFINEQ

(Card.BringUp
  (Method ((Card BringUp)
	   self Region/Position)                             (* rht: "28-Jan-85 19:56")

          (* * This brings up a card. If window already exists, then flash. Otherwise, retrieve the card, create a window, and
	  return it.)


	  (LET (Region Width Height)                         (* First retrieve card's info from notefile if 
							     necessary)
	    (OR (@ ActiveP)
		(← self Retrieve))                           (* Already has a window?)
	    (if (@ Window)
		then (TOTOPW (@ Window))
		     (RPTQ 2 (FLASHW (@ Window)))
		     (TTY.PROCESS (WINDOWPROP (@ Window)
					      (QUOTE PROCESS)))
		     (@ Window)
	      else                                           (* No, create region and window.)
		   (if (@ Region)
		       then (SETQ Width (fetch WIDTH of (@ Region)))
			    (SETQ Height (fetch HEIGHT of (@ Region)))
		     else (SETQ Width (GetClassValue self DefaultWindowWidth))
			  (SETQ Height (GetClassValue self DefaultWindowHeight)))
		   (←@
		     Region
		     (COND
		       ((type? REGION Region/Position)
			 Region/Position)
		       ((POSITIONP Region/Position)
			 (CREATEREGION (fetch XCOORD of Region/Position)
				       (fetch YCOORD of Region/Position)
				       Width Height))
		       (T (← NCL.CurrentTopLevel AskCardRegion Width Height (CONCAT 
						"Please specify location for edit of Note Card '"
										    (@ Title)
										    "'")))))
		   (←@
		     Window
		     (CREATEW (@ Region)
			      (@ Title)
			      NIL T))                        (* Hang useful fns, menus and junk off the window.)
		   (WINDOWPROP (@ Window)
			       (QUOTE SHRINKFN)
			       (FUNCTION NCL.ShrinkFn))
		   (WINDOWPROP (@ Window)
			       (QUOTE NoteCardsLeftButtonMenu)
			       (← self GetLeftMenu))
		   (WINDOWPROP (@ Window)
			       (QUOTE NoteCardsMiddleButtonMenu)
			       (← self GetMiddleMenu))
		   (WINDOWADDPROP Window (QUOTE CLOSEFN)
				  (FUNCTION NCL.QuitCard)
				  (QUOTE FIRST))
		   (WINDOWPROP Window (QUOTE NOTECARDOBJECT)
			       self)                         (* Bring up the card's substance in the window.)
		   (← (@ Substance)
		      BringUp
		      (@ Window)
		      (@ Title))
		   (@ Window)))))

(Card.CollectLinksInCard
  (Method ((Card CollectLinksInCard)
	   self)                                             (* rht: "18-Jan-85 10:59")
                                                             (*)
	  (To be written)))

(Card.Deactivate
  (Method ((Card Deactivate)
	   self ClearTitle)                                  (* rht: "23-Jan-85 12:01")

          (* * Clear all junk off the card.)


	  (NC.DeactivateCard (@ NCid)
			     ClearTitle)
	  (←@
	    Region NIL)
	  (←@
	    PropList NIL)
	  (←@
	    ToLinks NIL)
	  (←@
	    FromLinks NIL)
	  (←@
	    Notefile NIL)
	  (←@
	    NCid NIL)
	  (←@
	    Substance NIL)
	  (AND ClearTitle (←@
		 Title NIL))
	  (←@
	    ActiveP NIL)
	  self))

(Card.Delete
  (Method ((Card Delete)
	   self)                                             (* rht: "18-Jan-85 10:59")
                                                             (*)
	  (To be written)))

(Card.DeleteLinksInCard
  (Method ((Card DeleteLinksInCard)
	   self)                                             (* rht: "18-Jan-85 10:59")
                                                             (*)
	  (To be written)))

(Card.File
  (Method ((Card File)
	   self)                                             (* rht: "18-Jan-85 11:29")
                                                             (*)
	  (To be written)))

(Card.GetActiveP
  (Method ((Card GetActiveP)
	   self)                                             (* rht: "24-Jan-85 23:33")

          (* * Is this card active?)


	  (@ ActiveP)))

(Card.GetIndexPtr
  (Method ((Card GetIndexPtr)
	   self)                                             (* rht: "25-Jan-85 15:00")

          (* * Return the stream index ptr for this card number.)


	  (NCL.IndexFromNumber (@ CardNumber))))

(Card.GetInitialInfoFromStream
  (Method ((Card GetInitialInfoFromStream)
	   self Stream Ptr)                                  (* rht: "25-Jan-85 16:15")

          (* * Get the preliminary junk for a notecard. Check to make sure type agrees and return pointer.)


	  (WITH.MONITOR (NC.FetchMonitor Stream "Card.GetInitialInfoFromStream")
			(LET (ActualID ActualType (CardType (← self GetTypeName)))
			  (SETFILEPTR Stream Ptr)
			  (COND
			    ((NOT (NC.GetIdentifier Stream NC.ItemIdentifier))
			      (NC.ReportError "Card.GetInitialInfoFromStream" (CONCAT (@ NCid)
										      
					  " Error in Database file -- incorrect item identifier.")))
			    ((NEQ (SETQ ActualID (READ Stream))
				  (@ NCid))
			      (NC.ReportError "Card.GetInitialInfoFromStream" (CONCAT 
						 "ID mismatch while reading item.  Expected ID: "
										      (@ NCid)
										      "   Found ID: " 
										      ActualID)))
			    ((NEQ CardType (SETQ ActualType (READ Stream)))
			      (NC.ReportError "Card.GetInitialInfoFromStream"
					      (CONCAT 
					      "Type mismatch while reading card info.  Expected "
						      CardType ".  Found " ActualType 
						      " while reading ID: "
						      (@ NCid)))))
			  (READC Stream)
			  (GETFILEPTR Stream)))))

(Card.GetLinksFromStream
  (Method ((Card GetLinksFromStream)
	   self Stream)                                      (* rht: "24-Jan-85 18:32")

          (* * Grab the links for this card from the notefile. Stream's pointer is assumed to be set properly.)


	  (LET (ActualID)                                    (* Get Links)
	    (COND
	      ((NOT (NC.GetIdentifier Stream NC.LinksIdentifier))
		(NC.ReportError "Card.GetLinksFromStream" (CONCAT ID 
					 " Error in Database file -- incorrect links identifier."))))
	    (SETQ ActualID (READ Stream))
	    (COND
	      ((NEQ ActualID (@ NCid))
		(NC.ReportError "Card.GetLinksFromStream" (CONCAT 
						 "ID mismatch while reading links. Expected ID: "
								  (@ NCid)
								  "   Found ID: " ActualID))))
	    (←@
	      ToLinks
	      (READ Stream))
	    (←@
	      FromLinks
	      (READ Stream))
	    (←@
	      GlobalLinks
	      (LISTP (READ Stream)))
	    (←@
	      LinksDirtyFlg NIL)
	    self)))

(Card.GetNCid
  (Method ((Card GetNCid)
	   self)                                             (* rht: "24-Jan-85 23:35")

          (* * Just return the NCid slot)


	  (@ NCid)))

(Card.GetPropListFromStream
  (Method ((Card GetPropListFromStream)
	   self Stream)                                      (* rht: "24-Jan-85 18:44")

          (* * Fetch and set the card's proplist. Stream's pointer is assumed to be posistioned properly.)


	  (LET (ActualID)
	    (COND
	      ((NOT (NC.GetIdentifier Stream NC.PropsIdentifier))
		(NC.ReportError "Card.GetPropListFromStream" (CONCAT ID 
				     " Error in Database file -- incorrect prop list identifier."))))
	    (COND
	      ((NEQ (SETQ ActualID (READ Stream))
		    (@ NCid))
		(COND
		  (NoReportFlg (RETURN))
		  (T (NC.ReportError "Card.GetPropListFromStream" (CONCAT 
						 "ID mismatch while reading item.  Expected ID: "
									  (@ NCid)
									  "   Found ID: " ActualID))))
		))
	    (←@
	      PropList
	      (READ Stream))
	    self)))

(Card.GetPtrsFromStream
  (Method ((Card GetPtrsFromStream)
	   self Stream)                                      (* rht: "25-Jan-85 13:19")

          (* * Return the list of pointers into the notefile for a given card. First element of the list is the card's 
	  status.)


	  (WITH.MONITOR (NC.FetchMonitor Stream "Card.GetPtrsFromStream")
			(NCL.GetPtrs (← self GetIndexPtr)
				     Stream))))

(Card.GetRegionFromStream
  (Method ((Card GetRegionFromStream)
	   self Stream)                                      (* rht: "24-Jan-85 18:07")

          (* * Retrieve the card's region from the stream. Stream pointer should be all set.)


	  (←@
	    Region
	    (NC.GetRegion (@ NCid)
			  Stream))))

(Card.GetTitleFromStream
  (Method ((Card GetTitleFromStream)
	   self Stream)                                      (* rht: "25-Jan-85 17:04")

          (* * Retrieve the card's title from the notefile stream. Stream's pointer is assumed to be properly positioned.)


	  (LET (ActualID)

          (* * Had to comment out the following call to NC.GetIdentifier until the NC.TitlesIdentifier snafu is cleared up.)



          (* * (if (NOT (NC.GetIdentifier Stream NC.TitlesIdentifier)) then (NC.ReportError "Card.GetTitleFromStream" 
	  (CONCAT (@ NCid) " Error in Database file -- incorrect title identifier."))))



          (* * The following call to READ should be removed when the above code is restored.)


	    (READ Stream)
	    (SETQ ActualID (READ Stream))
	    (if (NEQ ActualID (@ NCid))
		then (COND
		       (NoReportFlg (RETURN))
		       (T (NC.ReportError "Card.GetTitleFromStream" (CONCAT 
						 "ID mismatch while reading item.  Expected ID: "
									    (@ NCid)
									    "   Found ID: " ActualID))
			  )))
	    (←@
	      Title
	      (READ Stream))
	    self)))

(Card.GetTypeName
  (Method ((Card GetTypeName)
	   self)                                             (* rht: "25-Jan-85 16:14")

          (* * Return the type name which should be written to the notefile to represent this class.)


	  (OR (GetClassValue self (QUOTE TypeNameOnNotefile))
	      (← self ClassName))))

(Card.InsureProperFiling
  (Method ((Card InsureProperFiling)
	   self)                                             (* rht: "23-Jan-85 13:55")
                                                             (* New method template)
	  self))

(Card.MakeDummyRegion
  (Method ((Card MakeDummyRegion)
	   self)                                             (* rht: "25-Jan-85 00:38")

          (* * Make a region with width and height corresponding to the default size of window's for this type of card.)


	  (CREATEREGION 0 0 (GetClassValue self (QUOTE DefaultWindowWidth))
			(GetClassValue self (QUOTE DefaultWindowHeight)))))

(Card.PutLinksToStream
  (Method ((Card PutLinksToStream)
	   self Stream)                                      (* rht: "25-Jan-85 01:37")

          (* * Put the links of card onto notefile stream.)


	  (LET (DataPtr Index)
	    (SETQ Index (← self GetIndexPtr))

          (* * Check to make sure this is an active note card.)


	    (SETFILEPTR Stream Index)
	    (if (NOT (EQ (NC.GetStatus Stream)
			 (QUOTE ACTIVE)))
		then (NC.ReportError "Card.PutLinksToStream" (CONCAT (@ NCid)
								     " is not an active note card.")))

          (* * Write the links data at the end of the database file.)


	    (SETFILEPTR Stream (SETQ DataPtr (GETEOFPTR Stream)))
	    (NC.PutIdentifier Stream NC.LinksIdentifier)
	    (PRINT (@ NCid)
		   Stream)
	    (PRINT (@ ToLinks)
		   Stream)
	    (PRINT (@ FromLinks)
		   Stream)
	    (PRINT (@ GlobalLinks)
		   Stream)
	    (←@
	      LinksDirtyFlg NIL)
	    (NC.SetLinksDirtyFlg (@ NCid))

          (* * Now update the index to point to the link data just written. Done last in case writing of links doesn't 
	  complete okay.)


	    (SETFILEPTR Stream Index)
	    (NC.GetStatus Stream)
	    (NC.GetPtr Stream)
	    (NC.PutPtr Stream DataPtr)
	    self)))

(Card.PutPropListToStream
  (Method ((Card PutPropListToStream)
	   self Stream)                                      (* rht: "25-Jan-85 01:29")

          (* * Put the proplist of card ID onto notefile stream.)


	  (LET (DataPtr)

          (* * First write out the title.)


	    (SETFILEPTR Stream (SETQ DataPtr (GETEOFPTR Stream)))
	    (NC.PutIdentifier Stream NC.PropsIdentifier)
	    (PRINT (@ NCid)
		   Stream)
	    (PRINT (@ PropList)
		   Stream)

          (* * Now update the Index to reflect the new data just written. Done last in case the substance putting bombed for 
	  some reason.)


	    (SETFILEPTR Stream (← self GetIndexPtr))
	    (NC.GetStatus Stream)
	    (NC.GetPtr Stream)
	    (NC.GetPtr Stream)
	    (NC.GetPtr Stream)
	    (NC.PutPtr Stream DataPtr)
	    (←@
	      PropListDirtyFlg NIL)
	    (NC.SetPropListDirtyFlg (@ NCid)
				    NIL)
	    self)))

(Card.PutRegionToStream
  (Method ((Card PutRegionToStream)
	   self Stream)                                      (* rht: "25-Jan-85 01:19")

          (* * Put out the region to the stream, first positioning the stream properly.)


	  (LET (Ptr Status ActualID NoteCardType)
	    (SETQ PtrList (← self GetPtrsFromStream Stream))
	    (SETQ Status (CAR PtrList))
	    (SETQ Ptr (CADR PtrList))
	    (if (NEQ Status (QUOTE ACTIVE))
		then (NC.ReportError "Card.PutRegionToStream" (CONCAT (@ NCid)
								      " not an active note card on "
								      (FULLNAME DatabaseStream))))
	    (SETFILEPTR Stream Ptr)
	    (if (NOT (NC.GetIdentifier Stream NC.ItemIdentifier))
		then (NC.ReportError "Card.PutRegionToStream" (CONCAT (@ NCid)
								      
					    "Error in database file -- incorrect item identifier")))
	    (if (NEQ (SETQ ActualID (READ Stream))
		     (@ NCid))
		then (NC.ReportError "Card.PutRegionToStream" (CONCAT "ID mismatch: Expected ID: "
								      (@ NCid)
								      "   Found ID: " ActualID)))
	    (SETQ NoteCardType (READ Stream))
	    (READC Stream)
	    (← self PutRegionToStreamAtCurPtr Stream)
	    self)))

(Card.PutRegionToStreamAtCurPtr
  (Method ((Card PutRegionToStreamAtCurPtr)
	   self Stream)                                      (* rht: "25-Jan-85 00:16")

          (* * Put the card's region down to the stream at the current stream ptr.)


	  (LET (Region)
	    (COND
	      ((AND (@ Window)
		    (SETQ Region (WINDOWPROP (@ Window)
					     (QUOTE REGION)))))
	      ((SETQ Region (@ Region)))
	      (T (SETQ Region (← self MakeDummyRegion))))
	    (NC.PutPtr Stream (fetch LEFT of Region)
		       2)
	    (NC.PutPtr Stream (fetch BOTTOM of Region)
		       2)
	    (NC.PutPtr Stream (fetch WIDTH of Region)
		       2)
	    (NC.PutPtr Stream (fetch HEIGHT of Region)
		       2)
	    self)))

(Card.PutSubstanceToStream
  (Method ((Card PutSubstanceToStream)
	   self Stream UpdateUpdateListFlg)                  (* rht: "25-Jan-85 16:15")

          (* * This dumps the initial junk like ID and type, dumps the substance, and then updates the index with the new 
	  pointer.)


	  (LET (DataPtr)
	    (AND UpdateUpdateListFlg (NC.UpdateUpdateList (@ NCid)))

          (* * First write out identifier, ID, type, and region.)


	    (SETFILEPTR Stream (SETQ DataPtr (GETEOFPTR Stream)))
	    (NC.PutIdentifier Stream NC.ItemIdentifier)
	    (PRINT (@ NCid)
		   Stream)
	    (PRINT (← self GetTypeName)
		   Stream)
	    (← self PutRegionToStreamAtCurPtr Stream)

          (* * Write out the substance of the card.)


	    (← (@ Substance)
	       StoreOnStream Stream (@ Window))

          (* * Now update the Index to reflect the new data just written. Done last in case the substance putting bombed for 
	  some reason.)


	    (SETFILEPTR Stream (← self GetIndexPtr))
	    (NC.PutStatus Stream ACTIVE)
	    (NC.PutPtr Stream DataPtr)
	    self)))

(Card.PutTitleToStream
  (Method ((Card PutTitleToStream)
	   self Stream)                                      (* rht: "25-Jan-85 01:37")

          (* * Put the title of card ID onto notefile stream.)


	  (LET (DataPtr)

          (* * First write out the title.)


	    (SETFILEPTR Stream (SETQ DataPtr (GETEOFPTR Stream)))
	    (NC.PutIdentifier Stream NC.TitleIdentifier)
	    (PRINT (@ NCid)
		   Stream)
	    (PRINT (@ Title)
		   Stream)

          (* * Now update the Index to reflect the new data just written. Done last in case the substance putting bombed for 
	  some reason.)


	    (SETFILEPTR Stream (← self GetIndexPtr))
	    (NC.GetStatus Stream)
	    (NC.GetPtr Stream)
	    (NC.GetPtr Stream)
	    (NC.PutPtr Stream DataPtr)
	    (←@
	      TitleDirtyFlg NIL)
	    (NC.SetTitleDirtyFlg (@ NCid)
				 NIL)
	    self)))

(Card.Quit
  (Method ((Card Quit)
	   self Don'tSave InsideOfWindowClose ClearTitle)    (* rht: "25-Jan-85 02:28")

          (* * Close this card and its window.)


	  (OR Don'tSave (← self StoreIfNeeded))
	  (AND (@ Substance)
	       (← (@ Substance)
		  Wrapup
		  (@ Window)))
	  (if (@ Window)
	      then (WINDOWDELPROP (@ Window)
				  (QUOTE CLOSEFN)
				  (FUNCTION NCL.QuitCard))

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


		   (WINDOWPROP (GETPROMPTWINDOW (@ Window)
						NIL NIL T)
			       (QUOTE PROCESS)
			       NIL)
		   (REMOVEPROMPTWINDOW (@ Window))
		   (for AttachedWindow in (ALLATTACHEDWINDOWS (@ Window))
		      do (DETACHWINDOW AttachedWindow)
			 (CLOSEW AttachedWindow))
		   (OR InsideOfWindowClose (CLOSEW (@ Window)))
		   (←@
		     Window NIL))
	  (← self Deactivate ClearTitle)
	  self))

(Card.RegionChangedP
  (Method ((Card RegionChangedP)
	   self)                                             (* rht: "23-Jan-85 17:04")

          (* * Return non-nil if the card has a window and it's region has changed.)


	  (PROG (NewRegion)
	        (RETURN (AND (@ Window)
			     (OR (NOT (EQUAL (fetch WIDTH of (@ Region))
					     (fetch WIDTH of (SETQ NewRegion (WINDOWPROP
								 (@ Window)
								 (QUOTE REGION))))))
				 (NOT (EQUAL (fetch HEIGHT of (@ Region))
					     (fetch HEIGHT of NewRegion)))))))))

(Card.Retrieve
  (Method ((Card Retrieve)
	   self)                                             (* rht: "25-Jan-85 16:55")
                                                             (*)
	  (LET ((Stream (← (@ Notefile)
			   GetStream)))
	    (WITH.MONITOR (NC.FetchMonitor Stream "Card.Retrieve")
			  (PROG (PtrList Ptr LinksPtr TitlePtr PropsPtr Status)
			        (SETQ PtrList (← self GetPtrsFromStream Stream))
			        (SETQ Status (CAR PtrList))
			        (SETQ Ptr (CADR PtrList))
			        (SETQ LinksPtr (CADDR PtrList))
			        (SETQ TitlePtr (CADDDR PtrList))
			        (SETQ PropsPtr (CAR (CDDDDR PtrList)))
			        (if (NEQ Status (QUOTE ACTIVE))
				    then (RETURN Status))    (* Check initial junk like type and id.)
			        (← self GetInitialInfoFromStream Stream Ptr)
			        (← self GetRegionFromStream Stream)
                                                             (* If there's no Substance, create a fresh one of 
							     proper class.)
			        (OR (@ Substance)
				    (←@
				      Substance
				      (← ($! (GetClassValue self (QUOTE SubstanceClassName)))
					 New)))
			        (← (@ Substance)
				   RetrieveFromStream Stream)

          (* * Setup ID with appropriate properties for retrieved card)


			        (NC.SetType (@ NCid)
					    (← self GetTypeName))
			        (NC.SetRegion (@ NCid)
					      (@ Region))
			        (NC.SetSubstance (@ NCid)
						 (← (@ Substance)
						    GetSubstanceVal))

          (* * Get Links)


			        (SETFILEPTR Stream LinksPtr)
			        (← self GetLinksFromStream Stream)
                                                             (* Setup ID with appropriate properties for retrieved 
							     card)
			        (NC.SetToLinks (@ NCid)
					       (@ ToLinks))
			        (NC.SetFromLinks (@ NCid)
						 (@ FromLinks))
			        (NC.SetGlobalLinks (@ NCid)
						   (@ GlobalLinks))
			        (NC.SetLinksDirtyFlg (@ NCid)
						     NIL)

          (* * GetTitle)


			        (SETFILEPTR Stream TitlePtr)
			        (← self GetTitleFromStream Stream)
			        (NC.SetTitle (@ NCid)
					     (@ Title))

          (* * Get Prop List)


			        (SETFILEPTR Stream PropsPtr)
			        (← self GetPropListFromStream Stream)
			        (NC.SetPropList (@ NCid)
						(@ PropList))

          (* * Activate Card and return)


			        (←@
				  ActiveP T)
			        (NC.ActivateCard (@ NCid))
			        (RETURN self))))))

(Card.Store
  (Method ((Card Store)
	   self)                                             (* rht: "18-Jan-85 11:29")
                                                             (*)
	  (To be written)))

(Card.StoreIfNeeded
  (Method ((Card StoreIfNeeded)
	   self)                                             (* rht: "25-Jan-85 17:17")

          (* * Store any parts of the card that are dirty back in the notefile.)


	  (LET ((Stream (← (@ Notefile)
			   GetStream)))
	    (← self InsureProperFiling)
	    (WITH.MONITOR (NC.FetchMonitor Stream "Card.StoreIfNeeded")
			  (AND (@ Window)
			       (NC.PrintMsg (@ Window)
					    T "Updating NoteFile ... " (CHARACTER 13)))
			  (if (← (@ Substance)
				 ChangedP
				 (@ Window))
			      then (NC.PrintMsg (@ Window)
						NIL "writing card substance and region, ")
				   (← self PutSubstanceToStream Stream) 
                                                             (* storing substance causes region to be written out, 
							     otherwise if it's changed do it here)
			    elseif (← self RegionChangedP)
			      then (NC.PrintMsg (@ Window)
						NIL "writing card region, ")
				   (← self PutRegionToStream Stream))
			  (← (@ Substance)
			     MarkUnchanged)
			  (if (@ TitleDirtyFlg)
			      then (NC.PrintMsg (@ Window)
						NIL "title, ")
				   (← self PutTitleToStream Stream))
			  (if (@ PropListDirtyFlg)
			      then (NC.PrintMsg (@ Window)
						NIL "proplist, ")
				   (← self PutPropListToStream Stream))
			  (if (@ LinksDirtyFlg)
			      then (NC.PrintMsg (@ Window)
						NIL "links, ")
				   (← self PutLinksToStream Stream))
			  (COND
			    ((@ Window)
			      (NC.PrintMsg (@ Window)
					   NIL "Done!!" (CHARACTER 13))
			      (DISMISS 500)
			      (NC.ClearMsg Window T)))))
	  self))

(Card.Unfile
  (Method ((Card Unfile)
	   self)                                             (* rht: "18-Jan-85 11:29")
                                                             (*)
	  (To be written)))

(Card.UpdateLinksInCard
  (Method ((Card UpdateLinksInCard)
	   self)                                             (* rht: "18-Jan-85 10:59")
                                                             (*)
	  (To be written)))

(GrapherSubstance.BringUp
  (Method ((GrapherSubstance BringUp)
	   self Window Title)                                (* rht: "28-Jan-85 11:50")

          (* * Bring up this graph in the given window.)


	  (SHOWGRAPH (@ SubstanceVal)
		     Window
		     (GetClassValue self GraphLeftButtonFn)
		     (GetClassValue self GraphMiddleButtonFn)
		     NIL T)))

(GrapherSubstance.ChangedP
  (Method ((GrapherSubstance ChangedP)
	   self)                                             (* rht: "25-Jan-85 02:22")

          (* * Right now, always have to write out graph, even if hasn't really changed, because grapher doesn't tell us when 
	  changes were made.)


	  T))

(GrapherSubstance.RetrieveFromStream
  (Method ((GrapherSubstance RetrieveFromStream)
	   self Notefile Stream)                             (* rht: "24-Jan-85 18:17")

          (* * Set the substance's SubstanceVal by fetching a Graph substance from the notefile.)


	  (←@
	    SubstanceVal
	    (NC.GetGraphSubstance Stream))))

(GrapherSubstance.StoreOnStream
  (Method ((GrapherSubstance StoreOnStream)
	   self Stream Window)                               (* rht: "25-Jan-85 01:09")

          (* * Put Graph to notefile stream.)


	  (LET (EndPtr EndPtrLoc StartPtr)                   (* Clean up BITMAPS in Graph data structure)
	    (SETQ StartPtr (IPLUS (GETFILEPTR Stream)
				  6))
	    (NC.PutPtr Stream StartPtr)
	    (SETQ EndPtrLoc (GETFILEPTR Stream))
	    (NC.PutPtr Stream 0)
	    (for GraphNode in (fetch GRAPHNODES of (@ SubstanceVal)) do (replace (GRAPHNODE 
										  NODELABELBITMAP)
									   of GraphNode with NIL))
                                                             (* Write data stucture)
	    (HPRINT (@ SubstanceVal)
		    Stream)
	    (SETQ EndPtr (GETFILEPTR Stream))
	    (SETFILEPTR Stream EndPtrLoc)
	    (NC.PutPtr Stream EndPtr)
	    self)))

(Link.Testfoo
  (Method ((Link Testfoo)
	   self increment)                                   (* rht: "23-Jan-85 17:16")
                                                             (* New method template)
	  (←@
	    Source increment)))

(Notefile.CardItemFromNumber
  (Method ((Notefile CardItemFromNumber)
	   self CardNumber)                                  (* rht: "24-Jan-85 23:37")

          (* * Use CardNumber as index into array to retrieve the pair for that card. First element is pointer to object, 
	  second is status litatom.)


	  (ELT (@ CardsArray)
	       CardNumber)))

(Notefile.Close
  (Method ((Notefile Close)
	   self QuietFlg)                                    (* rht: "25-Jan-85 17:13")

          (* * Closes this notefile.)


	  (PROG (File CardTotal ID OpenWindows)
	        (COND
		  ((SETQ OpenWindows (for Window in (OPENWINDOWS) bind Card
					when (AND (SETQ Card (OR (NCL.CardFromWindow Window)
								 (NCL.CardFromWindow
								   (WINDOWPROP Window (QUOTE ICONFOR))
								   )))
						  (@ Card ActiveP)
						  (EQ (@ Card Notefile)
						      self))
					collect Window))
		    (NC.PrintMsg NIL T 
				 "There are cards for this notefile still active on the screen."
				 (CHARACTER 13))
		    (COND
		      ((NC.YesP (NC.AskUser "Want to close and save them? " " -- " (QUOTE Yes)))
			(NC.PrintMsg NIL T "Closing and saving active cards ... ")
			(RESETLST (RESETSAVE NC.ForceSourcesFlg NIL)
				  (RESETSAVE NC.ForceFilingFlg NIL)
				  (RESETSAVE NC.ForceTitlesFlg NIL)
				  (for Window in OpenWindows
				     do (COND
					  ((WINDOWPROP Window (QUOTE ICONFOR))
					    (SETQ Window (EXPANDW Window))))
					(← (NCL.CardFromWindow Window)
					   Quit)
					(until (NULL (OPENWP Window)) do (BLOCK))))
			(NC.PrintMsg NIL NIL "Done." (CHARACTER 13)))
		      (T (RETURN NIL)))))
	        (OR QuietFlg (NC.PrintMsg NIL T "Closing Notefile ... " (CHARACTER 13)))
	        (RESETLST (RESETSAVE NC.ForceSourcesFlg NIL)
			  (RESETSAVE NC.ForceFilingFlg NIL)
			  (RESETSAVE NC.ForceTitlesFlg NIL)
			  (← self QuitAllCards QuietFlg "Closing NoteFile."))
	        (← self SaveNextLinkID T)
	        (SETQ File (FULLNAME (@ Stream)))

          (* * Set PSA.Database GlobalVar to NIL so that the advise to CLOSEF will not refuse to close this file.)


	        (← self ForceNotefileClose)
	        (replace (MENU TITLE) of NC.MainMenu with "No Open NoteFile")
	        (replace (MENU IMAGE) of NC.MainMenu with NIL)
	        (WINDOWPROP (WFROMMENU NC.MainMenu)
			    (QUOTE CLOSEFN)
			    NIL)
	        (NC.DisplayMainMenu)
	        (OR QuietFlg (NC.PrintMsg NIL T File " closed.")))))

(Notefile.CreateCards
  (Method ((Notefile CreateCards)
	   self QuietFlg OperationMsg)                       (* rht: "25-Jan-85 16:43")

          (* * Create objects for each card in the notefile and cache titles. Create an array containing pointers to card 
	  objects and card status. Array indices are card ID numbers.)


	  (LET ((CardTotal (← self GetHighestID))
	     Array)
	    (←@
	      CardsArray
	      (SETQ Array (ARRAY (IMAX (ITIMES 2 CardTotal)
				       500)
				 (QUOTE POINTER))))
	    (for CardNumber from 1 to CardTotal bind ID Pair
	       do (COND
		    ((AND (NULL QuietFlg)
			  (ZEROP (IREMAINDER CardNumber 10)))
		      (NC.PrintMsg NIL T (COND
				     (OperationMsg (CONCAT OperationMsg (CHARACTER 13)))
				     (T ""))
				   "Processing item number " CardNumber " out of " CardTotal "."
				   (CHARACTER 13))))
		  (SETQ ID (NC.IDFromNumber CardNumber))
		  (SETQ Pair (← self GetCardTypeAndTitle ID (NCL.IndexFromNumber CardNumber)))
		  (SETA Array CardNumber (if (LISTP Pair)
					     then (create NotefileCardsArrayItem
							  CardObject ←(← ($! (
NCL.ClassNameFromTypeName (CAR Pair)))
									 NewWithValues
									 (BQUOTE
									   ((Title , (CDR Pair))
									    (NCid , ID)
									    (CardNumber , CardNumber)
									    (Notefile , self))))
							  CardStatus ←(QUOTE ACTIVE))
					   else (create NotefileCardsArrayItem
							CardObject ← NIL
							CardStatus ← Pair))))
	    self)))

(Notefile.ForceNotefileClose
  (Method ((Notefile ForceNotefileClose)
	   self)                                             (* rht: "25-Jan-85 17:18")

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



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


	  (\UPDATEOF (@ Stream))
	  (CLOSEF (PROG1 (@ Stream)
			 (←@
			   Stream NIL)))
	  self))

(Notefile.GetCardInitialInfo
  (Method ((Notefile GetCardInitialInfo)
	   self Ptr ID CardType)                             (* rht: "22-Jan-85 14:47")

          (* * Get the preliminary junk for a notecard. Check to make sure type agrees and return pointer and region.)


	  (WITH.MONITOR (NC.FetchMonitor (@ Stream)
					 "Notefile.GetCardInitialInfo")
			(PROG (ActualID ActualType)
			      (SETFILEPTR (@ Stream)
					  Ptr)
			      (COND
				((NOT (NC.GetIdentifier (@ Stream)
							NC.ItemIdentifier))
				  (NC.ReportError "Notefile.GetCardInitialInfo" (CONCAT ID 
					  " Error in Database file -- incorrect item identifier.")))
				((NEQ (SETQ ActualID (READ (@ Stream)))
				      ID)
				  (NC.ReportError "NC.GetNoteCard" (CONCAT 
						 "ID mismatch while reading item.  Expected ID: "
									   ID "   Found ID: " 
									   ActualID)))
				((NEQ CardType (SETQ ActualType (READ (@ Stream))))
				  (NC.ReportError "Notefile.GetCardInitialInfo"
						  (CONCAT 
					      "Type mismatch while reading card info.  Expected "
							  CardType ".  Found " ActualType 
							  " while reading ID: "
							  ID))))
			      (READC (@ Stream))
			      (RETURN (LIST (GETFILEPTR (@ Stream))
					    (NC.GetRegion ID (@ Stream))))))))

(Notefile.GetCardTitle
  (Method ((Notefile GetCardTitle)
	   self ID TitlePtr)                                 (* rht: "25-Jan-85 15:39")

          (* * Retrieve a card's title from the notefile.)


	  (WITH.MONITOR (NC.FetchMonitor (@ Stream)
					 "Notefile.GetCardTitle")
			(LET (ActualID)
			  (SETFILEPTR (@ Stream)
				      TitlePtr)

          (* * Had to comment out the following call to NC.GetIdentifier until the NC.TitlesIdentifier snafu is cleared up.)



          (* * (if (NOT (NC.GetIdentifier (@ Stream) NC.TitlesIdentifier)) then (NC.ReportError "Notefile.GetCardTitle" 
	  (CONCAT ID " Error in Database file -- incorrect title identifier."))))



          (* * The following call to READ should be removed when the above code is restored.)


			  (READ (@ Stream))
			  (SETQ ActualID (READ (@ Stream)))
			  (if (NEQ ActualID ID)
			      then (NC.ReportError "Notefile.GetCardTitle"
						   (CONCAT 
						 "ID mismatch while reading item.  Expected ID: "
							   ID "   Found ID: " ActualID)))
			  (READ (@ Stream))))))

(Notefile.GetCardType
  (Method ((Notefile GetCardType)
	   self ID Ptr)                                      (* rht: "25-Jan-85 14:28")

          (* * Get a card's type from the notefile.)


	  (WITH.MONITOR (NC.FetchMonitor (@ Stream)
					 "Notefile.GetCardType")
			(LET (ActualID)
			  (SETFILEPTR (@ Stream)
				      Ptr)
			  (if (NOT (NC.GetIdentifier (@ Stream)
						     NC.ItemIdentifier))
			      then (NC.ReportError "Notefile.GetCardType" (CONCAT ID 
					  " Error in Database file -- incorrect item identifier.")))
			  (SETQ ActualID (READ (@ Stream)))
			  (if (NEQ ActualID ID)
			      then (NC.ReportError "Notefile.GetCardType" (CONCAT 
						 "ID mismatch while reading item.  Expected ID: "
										  ID "   Found ID: " 
										  ActualID)))
			  (READ (@ Stream))))))

(Notefile.GetCardTypeAndTitle
  (Method ((Notefile GetCardTypeAndTitle)
	   self ID Index)                                    (* rht: "25-Jan-85 14:13")

          (* * Retrieve the type and title of ID from the notefile.)


	  (WITH.MONITOR (NC.FetchMonitor (@ Stream)
					 "Notefile.GetCardTypeAndTitle")
			(PROG (PtrList Ptr TitlePtr Status)
			      (SETQ PtrList (NCL.GetPtrs Index (@ Stream)))
			      (SETQ Status (CAR PtrList))
			      (SETQ Ptr (CADR PtrList))
			      (SETQ TitlePtr (CADDDR PtrList))
			      (COND
				((NEQ Status (QUOTE ACTIVE))
				  (RETURN Status))
				(T (RETURN (CONS (← self GetCardType ID Ptr)
						 (← self GetCardTitle ID TitlePtr)))))))))

(Notefile.GetFullFileName
  (Method ((Notefile GetFullFileName)
	   self)                                             (* rht: "25-Jan-85 17:42")

          (* * Just return the full name of the file this notefile is for.)


	  (@ FullFileName)))

(Notefile.GetHighestID
  (Method ((Notefile GetHighestID)
	   self)                                             (* rht: "21-Jan-85 19:07")
                                                             (* New method template)
	  (SUB1 (SUBATOM (NC.GetNewID (@ Stream)
				      T)
			 3))))

(Notefile.GetStream
  (Method ((Notefile GetStream)
	   self)                                             (* rht: "25-Jan-85 16:45")

          (* * Return the stream for this notefile.)


	  (@ Stream)))

(Notefile.Open
  (Method ((Notefile Open)
	   self Access QuietFlg)                             (* rht: "25-Jan-85 16:26")

          (* * Open this notefile, creating objects for each active card and caching titles. Returns non-nil if successful.)


	  (AND (NULL QuietFlg)
	       (NC.PrintMsg NIL T "Opening ... " (CHARACTER 13)))
	  (←@
	    Stream
	    (OPENSTREAM (@ FullFileName)
			(OR Access (QUOTE BOTH))
			(QUOTE OLD)))
	  (NC.SetMonitor (@ Stream)
			 (CREATE.MONITORLOCK (MKATOM (CONCAT (@ FullFileName)
							     ":LOCK"))))
	  (SETFILEPTR (@ Stream)
		      0)
	  (NC.GetPtr (@ Stream)
		     2)
	  (←@
	    IndexSizeInEntries
	    (NC.GetPtr (@ Stream)
		       2))
	  (←@
	    NextLinkID
	    (NC.GetPtr (@ Stream)))

          (* * If the next link id on the disk is divisble by 100 then system must have crashed without closing database file.
	  In this case bump up the next link id to insure no conflicts)


	  (if (ZEROP (IREMAINDER (@ NextLinkID)
				 100))
	      then (←@
		     NextLinkID
		     (IPLUS 101 (@ NextLinkID))))            (* Create cards and Cache all of the titles in this 
							     database)
	  (← self CreateCards QuietFlg "Opening NoteFile.")
	  (replace (MENU TITLE) of NC.MainMenu with (CONCAT "NoteFile: "
							    (LISTGET (UNPACKFILENAME
								       (FULLNAME (@ Stream)))
								     (QUOTE NAME))))
	  (replace (MENU IMAGE) of NC.MainMenu with NIL)
	  (NC.DisplayMainMenu)
	  self))

(Notefile.QuitAllCards
  (Method ((Notefile QuitAllCards)
	   self QuietFlg OperationMsg)                       (* rht: "25-Jan-85 17:15")

          (* * Quit any remaining active cards and remove pointers to them from the notefile.)


	  (LET ((CardTotal (← self GetHighestID)))
	    (for CardNumber from 1 to CardTotal bind Card CardItem
	       do (COND
		    ((AND (NULL QuietFlg)
			  (ZEROP (IREMAINDER CardNumber 10)))
		      (NC.PrintMsg NIL T (COND
				     (OperationMsg (CONCAT OperationMsg (CHARACTER 13)))
				     (T ""))
				   "Processing item number " CardNumber " out of " CardTotal "."
				   (CHARACTER 13))))
		  (SETQ CardItem (← self CardItemFromNumber CardNumber))
		  (if (EQ (fetch (NotefileCardsArrayItem CardStatus)
				 CardItem)
			  (QUOTE ACTIVE))
		      then (if (← (SETQ Card (fetch (NotefileCardsArrayItem CardObject)
						    CardItem))
				  GetActiveP)
			       then (← Card Quit NIL NIL T)
			     else (← Card Deactivate T))
			   (SETPROPLIST (← Card GetNCid)
					NIL)))
	    (←@
	      CardsArray NIL)
	    self)))

(Notefile.SaveNextLinkID
  (Method ((Notefile SaveNextLinkID)
	   self ClosingDatabaseFlg)                          (* rht: "23-Jan-85 11:24")

          (* * Save the next link id info for DatabaseStream on the database)


	  (WITH.MONITOR (NC.FetchMonitor (@ Stream))
			(if ClosingDatabaseFlg
			    then 

          (* * Rule is never save a next id divisible by 100.0 That way, a system crash will be marked by an id divisible by 
	  100, i.e., an id written during system operation rather than by system close operation.)


				 (COND
				   ((ZEROP (IREMAINDER (@ NextLinkID)
						       100))
				     (←@
				       NextLinkID
				       (ADD1 (@ NextLinkID))))))
			(SETFILEPTR (@ Stream)
				    4)
			(NC.PutPtr (@ Stream)
				   (@ NextLinkID))
			(@ NextLinkID))
	  self))

(SketchSubstance.BringUp
  (Method ((SketchSubstance BringUp)
	   self Window Title)                                (* rht: "28-Jan-85 11:44")

          (* * Bring up this sketch in the given window with given title.)


	  (SKETCHW.CREATE (@ SubstanceVal)
			  NIL Window Title (GetClassValue self InitialScale))))

(SketchSubstance.ChangedP
  (Method ((SketchSubstance ChangedP)
	   self Window)                                      (* rht: "25-Jan-85 02:20")

          (* * Is this sketch substance dirty?)


	  (LET ((EPSILON (CONSTANT (FQUOTIENT 1 1024))))
	    (OR (←Super
		  self ChangedP)
		(NULL (@ Scale))
		(NULL (@ RegionViewed))
		(AND Window (GREATERP (ABS (DIFFERENCE (@ Scale)
						       (SCALE.FROM.SKW Window)))
				      EPSILON))
		(AND Window (for OldNumber in (@ RegionViewed) as NewNumber in (SK.REGION.VIEWED
										 Window)
			       thereis (GREATERP (ABS (DIFFERENCE OldNumber NewNumber))
						 EPSILON)))))))

(SketchSubstance.RetrieveFromStream
  (Method ((SketchSubstance RetrieveFromStream)
	   self Notefile Stream)                             (* rht: "24-Jan-85 18:18")

          (* * Set the substance's SubstanceVal by fetching a Sketch substance from the notefile.)


	  (←@
	    SubstanceVal
	    (NC.GetSketchSubstance Stream))))

(SketchSubstance.StoreOnStream
  (Method ((SketchSubstance StoreOnStream)
	   self Stream Window)                               (* rht: "25-Jan-85 01:08")

          (* Put the sketch substance for card ID to the database. Store the global sketch descriptor, the scale and region 
	  viewed for ID and any cached bit maps.)


	  (LET (SketchSpecs EndPtr EndPtrLoc StartPtr)
	    (SETQ StartPtr (IPLUS (GETFILEPTR Stream)
				  6))
	    (NC.PutPtr Stream StartPtr)
	    (SETQ EndPtrLoc (GETFILEPTR Stream))
	    (NC.PutPtr Stream 0)
	    (HPRINT (@ SubstanceVal)
		    Stream T T)
	    (PRINT (AND Window (SCALE.FROM.SKW Window))
		   Stream)
	    (PRINT (AND Window (SK.REGION.VIEWED Window))
		   Stream)
	    (COND
	      ((AND Window (SETQ SketchSpecs (LOCALSPECS.FROM.VIEWER Window)))
		(MAPSKETCHSPECS SketchSpecs (FUNCTION NC.PutCachedMap)
				Stream)))
	    (PRINT "###ENDSKETCH###" Stream)
	    (SETQ EndPtr (GETFILEPTR Stream))
	    (SETFILEPTR Stream EndPtrLoc)
	    (NC.PutPtr Stream EndPtr)
	    self)))

(Substance.ChangedP
  (Method ((Substance ChangedP)
	   self)                                             (* rht: "25-Jan-85 02:12")

          (* * Has the substance been changed since last write?)


	  (@ DirtyFlg)))

(Substance.GetSubstanceVal
  (Method ((Substance GetSubstanceVal)
	   self)                                             (* rht: "24-Jan-85 18:09")

          (* * Just return the value of the substance.)


	  (@ SubstanceVal)))

(Substance.MarkUnchanged
  (Method ((Substance MarkUnchanged)
	   self)                                             (* rht: "25-Jan-85 02:07")

          (* * Note that the substance is no longer dirty.)


	  (←@
	    DirtyFlg NIL)
	  self))

(Substance.Wrapup
  (Method ((Substance Wrapup)
	   self)                                             (* rht: "25-Jan-85 01:59")

          (* * Called when quitting a card after saving substance. Do nothing is the generic case.)


	  self))

(TEditSubstance.BringUp
  (Method ((TEditSubstance BringUp)
	   self Window Title)                                (* rht: "28-Jan-85 11:57")

          (* * This brings up tedit in the given window.)


	  (TEDIT (@ SubstanceVal)
		 Window NIL (LIST (QUOTE FONT)
				  (GetClassValue self DefaultFont)
				  (QUOTE TITLEMENUFN)
				  (GetClassValue self MenuFn)))))

(TEditSubstance.ChangedP
  (Method ((TEditSubstance ChangedP)
	   self)                                             (* rht: "23-Jan-85 16:58")

          (* * Return non-nil if this substance is dirty.)


	  (TEDIT.STREAMCHANGEDP (@ SubstanceVal))))

(TEditSubstance.RetrieveFromStream
  (Method ((TEditSubstance RetrieveFromStream)
	   self Stream)                                      (* rht: "24-Jan-85 17:40")

          (* * Set the substance's SubstanceVal by fetching a TEdit stream from the notefile stream.)


	  (←@
	    SubstanceVal
	    (NC.GetTextSubstance Stream))))

(TEditSubstance.StoreOnStream
  (Method ((TEditSubstance StoreOnStream)
	   self Stream Window)                               (* rht: "25-Jan-85 01:10")

          (* * Put this substance on the notefile stream.)


	  (LET (EndPtr EndPtrLoc StartPtr TempStream TempFile)
	    (SETQ StartPtr (IPLUS (GETFILEPTR Stream)
				  6))
	    (NC.PutPtr Stream StartPtr)
	    (SETQ EndPtrLoc (GETFILEPTR Stream))
	    (NC.PutPtr Stream 0)                             (* Put textstream to temp file)
	    (SETQ TempStream (GETSTREAM (SETQ TempFile (OPENFILE (PACK* (QUOTE {CORE}NC)
									(GENSYM))
								 (QUOTE OUTPUT)))))
	    (AND (ZEROP (fetch (TEXTOBJ TEXTLEN) of (TEXTOBJ (@ SubstanceVal))))
		 (TEDIT.INSERT (@ SubstanceVal)
			       "   " 1))
	    (TEDIT.PUT.PCTB (TEXTOBJ (@ SubstanceVal))
			    TempStream)
	    (SETFILEPTR Stream StartPtr)                     (* Copy temp file to database file fixing up pointers 
							     on the way)
	    (SETQ TempStream (GETSTREAM (OPENFILE (CLOSEF TempFile)
						  (QUOTE INPUT))))
	    (COND
	      ((IGREATERP (GETEOFPTR TempStream)
			  2)
		(SETFILEPTR TempStream (IDIFFERENCE (GETEOFPTR TempStream)
						    2))
		(COND
		  ((FMEMB (\WIN TempStream)
			  (QUOTE (31415 31416)))
		    (COPYBYTES TempStream Stream 0 (IDIFFERENCE (GETEOFPTR TempStream)
								8))
		    (\DWOUT Stream (IPLUS (\DWIN TempStream)
					  StartPtr))
		    (RPTQ 2 (\WOUT Stream (\WIN TempStream))))
		  (T (SETFILEPTR TempStream 0)
		     (COPYBYTES TempStream Stream))))
	      (T (SETFILEPTR TempStream 0)
		 (COPYBYTES TempStream Stream)))
	    (SETQ EndPtr (GETFILEPTR Stream))
	    (SETFILEPTR Stream EndPtrLoc)
	    (NC.PutPtr Stream EndPtr)
	    (DELFILE (CLOSEF TempFile))                      (* Fix up PCTB of Substance in case want to go on 
							     editing.)
	    (TEDIT.MAPPIECES (TEXTOBJ (@ SubstanceVal))
			     (FUNCTION (LAMBDA (CH%# PC PC%# OBL)
				 (PROG (PFile)
				       (COND
					 ((AND (SETQ PFile (fetch (PIECE PFILE) of PC))
					       (EQ (FULLNAME PFile)
						   (FULLNAME TempStream)))
					   (replace (PIECE PFILE) of PC with Stream)
					   (replace (PIECE PFPOS) of PC
					      with (IPLUS StartPtr (fetch (PIECE PFPOS) of PC)))))))))
	    (TEDIT.STREAMCHANGEDP (@ SubstanceVal)
				  (QUOTE CHANGED))
	    self)))

(TEditSubstance.Wrapup
  (Method ((TEditSubstance Wrapup)
	   self)                                             (* rht: "25-Jan-85 02:25")

          (* * Stuff to do when quitting a tedit card after it's been saved.)


	  (replace (TEXTOBJ TXTFILE) of (TEXTOBJ (@ SubstanceVal)) with NIL)
	  (TEDIT.MAPPIECES (TEXTOBJ (@ SubstanceVal))
			   (FUNCTION (LAMBDA (CH%# PC PC%# OBL)
			       (replace (PIECE PFILE) of PC with NIL))))))

(TopLevel.AskCardRegion
  (Method ((TopLevel AskCardRegion)
	   self Width Height PromptMsg)                      (* rht: "28-Jan-85 11:04")

          (* * Get from user a region to bring up the card in.)


	  (GETBOXREGION Width Height (GETMOUSEX)
			(IDIFFERENCE (GETMOUSEY)
				     Height)
			NIL PromptMsg)))

(TopLevel.AskNotefileName
  (Method ((TopLevel AskNotefileName)
	   self Msg ClearFirstFlg NoSuggestFlg)              (* rht: "22-Jan-85 16:14")
                                                             (* New method template)
	  (MKATOM (NC.AskUser Msg Prompt (AND (NOT NoSuggestFlg)
					      (@ NotefileNameSuggestion))
			      ClearFirstFlg NIL T))))

(TopLevel.MakeNotefileName
  (Method ((TopLevel MakeNotefileName)
	   self Name)                                        (* rht: "22-Jan-85 16:17")

          (* * Attach the .NOTEFILE extension.)


	  (SETQ Name (PACKFILENAME (QUOTE BODY)
				   Name
				   (QUOTE EXTENSION)
				   (QUOTE NOTEFILE)))
	  (←@
	    NotefileNameSuggestion
	    (PACKFILENAME (QUOTE VERSION)
			  NIL
			  (QUOTE BODY)
			  (FULLNAME Name)))
	  Name))

(TopLevel.OpenNotefile
  (Method ((TopLevel OpenNotefile)
	   self FileName Access QuietFlg Don'tCreateFlg)     (* rht: "25-Jan-85 17:51")

          (* * Open a notefile: create a notefile object and send it the open message.)


	  (PROG (Notefile FullName)
	        (OR FileName (SETQ FileName (← self AskNotefileName "Name of NoteFile to open:" T)))
	        (OR FileName (RETURN NIL))
	        (SETQ FileName (← self MakeNotefileName FileName))
	        (if (OPENP FileName)
		    then (NC.PrintMsg NIL T FileName " is an already open file." (CHARACTER 13))
			 (RETURN))
	        (AND (NOT (SETQ FullName (INFILEP FileName)))
		     (COND
		       (Don'tCreateFlg (NC.PrintMsg NIL T "Couldn't find NoteFile " FileName "."
						    (CHARACTER 13))
				       (RETURN NIL))
		       ((NC.YesP (NC.AskUser (CONCAT "Unable to find NoteFile " FileName "."
						     (CHARACTER 13)
						     "Want to create new NoteFile by that name? ")
					     " -- " "Yes" T NIL T))
			 (NC.CreateDatabaseFile FileName NIL "Opening NoteFile" T)
			 (AND (NOT (SETQ FullName (INFILEP FileName)))
			      (NC.PrintMsg NIL T "Still unable to find Notefile " FileName "."
					   (CHARACTER 13))
			      (RETURN NIL)))
		       (T (RETURN NIL))))
	        (SETQ Notefile (OR (for Notefile in (@ Notefiles) when (EQ (← Notefile 
									      GetFullFileName)
									   FullName)
				      do (RETURN Notefile))
				   (← ($ Notefile)
				      NewWithValues
				      (BQUOTE ((FileName , FileName)
					       (FullFileName , FullName))))))
	        (if (← Notefile GetStream)
		    then (NC.ReportError "TopLevel.OpenNotefile" (CONCAT "File " FullName 
					   " is closed, but a notefile has an open stream on it.")))
	        (if (← Notefile Open Access QuietFlg)
		    then (←@
			   Notefiles
			   (CONS Notefile (@ Notefiles)))
			 (RETURN Notefile)
		  else (RETURN NIL)))))

(TopLevel.QuitNotefile
  (Method ((TopLevel QuitNotefile)
	   self Notefile)                                    (* rht: "25-Jan-85 17:48")

          (* * Remove this notefile from the list of "active" notefiles.)


	  (←@
	    Notefiles
	    (LSUBST NIL Notefile (@ Notefiles)))
	  self))
)
(DEFINEQ

(NCL.QuitCard
  (LAMBDA (Window)                                           (* rht: "22-Jan-85 23:01")

          (* * This is called when window is closed from right button menu.)


    (← (NCL.CardFromWindow Window)
       Quit NIL T)))

(NCL.GetPtrs
  (LAMBDA (Index Stream)                                     (* rht: "25-Jan-85 13:18")

          (* * Return a list of pointers from the index of card ID)


    (WITH.MONITOR (NC.FetchMonitor Stream "NC.GetPtrs")
		  (LET (Ptr LinksPtr TitlePtr PropsPtr Status PtrList EofPtr)
		    (SETFILEPTR Stream Index)
		    (SETQ Status (NC.GetStatus Stream))
		    (SETQ Ptr (NC.GetPtr Stream))
		    (SETQ LinksPtr (NC.GetPtr Stream))
		    (SETQ TitlePtr (NC.GetPtr Stream))
		    (SETQ PropsPtr (NC.GetPtr Stream))
		    (SETQ PtrList
		      (create POINTERLIST
			      STATUS ← Status
			      MAINPTR ← Ptr
			      LINKSPTR ← LinksPtr
			      TITLEPTR ← TitlePtr
			      PROPSPTR ← PropsPtr
			      INDEXPTR ← Index))
		    (SETQ EofPtr (GETEOFPTR Stream))
		    (AND (EQ Status (QUOTE ACTIVE))
			 (for Ptr in (CDR PtrList) when (OR (IGREATERP Ptr EofPtr)
							    (MINUSP Ptr))
			    do (replace (POINTERLIST STATUS) of PtrList with (QUOTE BADPOINTER))))
		    PtrList))))

(NCL.IndexFromNumber
  (LAMBDA (Number)                                           (* rht: "25-Jan-85 14:59")

          (* * Compute the stream index for this card number.)


    (LSH Number 4)))

(NCL.ClassNameFromTypeName
  (LAMBDA (TypeName)                                         (* rht: "25-Jan-85 16:04")

          (* * Return the Class name corresponding to the type name stored on the notefile. If don't have a class name for 
	  that type, then use the type name.)


    (OR (CDR (FASSOC TypeName NCL.TypeToClassAssocList))
	TypeName)))

(NCL.CardFromWindow
  (LAMBDA (Window)                                           (* rht: "25-Jan-85 17:10")

          (* * Returns non-nil if this window is for a notecard.)


    (WINDOWPROP Window (QUOTE NOTECARDOBJECT))))
)

(RPAQQ NCL.TypeToClassAssocList ((Text . TextCard)
				 (Graph . GraphCard)
				 (Sketch . SketchCard)
				 (FileBox . FileboxCard)
				 (Browser . BrowserCard)
				 (LinkIndex . LinkIndexCard)
				 (Search . SearchCard)
				 (Document . DocumentCard)))
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NCL.TypeToClassAssocList NCL.CurrentTopLevel)
)
[DECLARE: EVAL@COMPILE 

(RECORD NotefileCardsArrayItem (CardObject . CardStatus))
]
(PUTPROPS LOOPSNOTECARDS COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (23821 74739 (Card.BringUp 23831 . 26289) (Card.CollectLinksInCard 26291 . 26531) (
Card.Deactivate 26533 . 27028) (Card.Delete 27030 . 27246) (Card.DeleteLinksInCard 27248 . 27486) (
Card.File 27488 . 27700) (Card.GetActiveP 27702 . 27897) (Card.GetIndexPtr 27899 . 28154) (
Card.GetInitialInfoFromStream 28156 . 29519) (Card.GetLinksFromStream 29521 . 30560) (Card.GetNCid 
30562 . 30753) (Card.GetPropListFromStream 30755 . 31650) (Card.GetPtrsFromStream 31652 . 32079) (
Card.GetRegionFromStream 32081 . 32401) (Card.GetTitleFromStream 32403 . 33569) (Card.GetTypeName 
33571 . 33916) (Card.InsureProperFiling 33918 . 34167) (Card.MakeDummyRegion 34169 . 34585) (
Card.PutLinksToStream 34587 . 35902) (Card.PutPropListToStream 35904 . 36847) (Card.PutRegionToStream 
36849 . 38132) (Card.PutRegionToStreamAtCurPtr 38134 . 38911) (Card.PutSubstanceToStream 38913 . 40056
) (Card.PutTitleToStream 40058 . 40956) (Card.Quit 40958 . 42008) (Card.RegionChangedP 42010 . 42621) 
(Card.Retrieve 42623 . 45323) (Card.Store 45325 . 45539) (Card.StoreIfNeeded 45541 . 47283) (
Card.Unfile 47285 . 47501) (Card.UpdateLinksInCard 47503 . 47741) (GrapherSubstance.BringUp 47743 . 
48126) (GrapherSubstance.ChangedP 48128 . 48450) (GrapherSubstance.RetrieveFromStream 48452 . 48798) (
GrapherSubstance.StoreOnStream 48800 . 49748) (Link.Testfoo 49750 . 49999) (
Notefile.CardItemFromNumber 50001 . 50372) (Notefile.Close 50374 . 52723) (Notefile.CreateCards 52725
 . 54352) (Notefile.ForceNotefileClose 54354 . 54863) (Notefile.GetCardInitialInfo 54865 . 56223) (
Notefile.GetCardTitle 56225 . 57349) (Notefile.GetCardType 57351 . 58228) (
Notefile.GetCardTypeAndTitle 58230 . 58998) (Notefile.GetFullFileName 59000 . 59257) (
Notefile.GetHighestID 59259 . 59571) (Notefile.GetStream 59573 . 59789) (Notefile.Open 59791 . 61396) 
(Notefile.QuitAllCards 61398 . 62604) (Notefile.SaveNextLinkID 62606 . 63445) (SketchSubstance.BringUp
 63447 . 63782) (SketchSubstance.ChangedP 63784 . 64503) (SketchSubstance.RetrieveFromStream 64505 . 
64851) (SketchSubstance.StoreOnStream 64853 . 65972) (Substance.ChangedP 65974 . 66204) (
Substance.GetSubstanceVal 66206 . 66445) (Substance.MarkUnchanged 66447 . 66700) (Substance.Wrapup 
66702 . 66955) (TEditSubstance.BringUp 66957 . 67357) (TEditSubstance.ChangedP 67359 . 67624) (
TEditSubstance.RetrieveFromStream 67626 . 67971) (TEditSubstance.StoreOnStream 67973 . 70601) (
TEditSubstance.Wrapup 70603 . 71092) (TopLevel.AskCardRegion 71094 . 71436) (TopLevel.AskNotefileName 
71438 . 71825) (TopLevel.MakeNotefileName 71827 . 72306) (TopLevel.OpenNotefile 72308 . 74430) (
TopLevel.QuitNotefile 74432 . 74737)) (74740 76958 (NCL.QuitCard 74750 . 75003) (NCL.GetPtrs 75005 . 
76116) (NCL.IndexFromNumber 76118 . 76329) (NCL.ClassNameFromTypeName 76331 . 76709) (
NCL.CardFromWindow 76711 . 76956)))))
STOP