(FILECREATED "29-Jun-87 17:05:30" {QV}<NOTECARDS>1.3K>LIBRARY>NCHISTORYCARD.;14 8136   

      changes to:  (FNS NCHist.HistoricizeNoteFile)

      previous date: "19-Apr-87 19:36:32" {QV}<NOTECARDS>1.3K>LIBRARY>NCHISTORYCARD.;13)


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

(PRETTYCOMPRINT NCHISTORYCARDCOMS)

(RPAQQ NCHISTORYCARDCOMS ((* * Package of History Card and handy functions)
			    (FNS NCHist.HistoricizeNoteFile NCHist.NoteFileWhenOpenedFn 
				 NCHist.CreateHistoryCardTitle NCHist.GetHistoryFileBox)
			    (FNS NCHist.HistoryCardMakeFn NCHist.HistoryCardWhenSavedFn 
				 NCHist.AddHistoryCard)
			    (FNS NCHist.ShaveLeadingSpace)
			    (GLOBALVARS NCHist.HistoryCardPosition)
			    (INITVARS (NCHist.HistoryCardPosition NIL))
			    (P (NCHist.AddHistoryCard)
			       (PUTPROP (QUOTE History)
					(QUOTE WhenSavedFn)
					(FUNCTION NCHist.HistoryCardWhenSavedFn)))))
(* * Package of History Card and handy functions)

(DEFINEQ

(NCHist.HistoricizeNoteFile
  (LAMBDA (NoteFile)                                         (* rht: "29-Jun-87 17:03")

          (* * Initialize given notefile for History Card use. Make a History Use Filebox if none exists and register in the 
	  notefile. Hang a call to NCHist.NoteFileWhenOpenedFn in the OpenEventsCard for the notefile.)



          (* * rht 4/19/87: Now calls NC.LoadFileFromDirectories rather than FILESLOAD.)


    (if (NCP.OpenNoteFileP NoteFile)
	then (LET ((OpenEventSExp (QUOTE (PROGN (NC.LoadFileFromDirectories (QUOTE 
										    NCHISTORYCARD))
						      (NCHist.NoteFileWhenOpenedFn NoteFile))))
		     (OpenEventsCard (NCP.GetOpenEventsCard NoteFile))
		     OpenEventsCardWasCachedFlg)

          (* * Add call to NCHist.NoteFileWhenOpenedFn to the open events card substance.)


		    (if (NOT (SETQ OpenEventsCardWasCachedFlg (NCP.ActiveCardP OpenEventsCard)
				   ))
			then (NCP.CacheCards OpenEventsCard))
		    (if (NOT (MEMBER OpenEventSExp (NCP.CardSubstance OpenEventsCard)))
			then (NCP.CardSubstance OpenEventsCard (CONS OpenEventSExp
									   (NCP.CardSubstance
									     OpenEventsCard))))
		    (if (NOT OpenEventsCardWasCachedFlg)
			then (NCP.CloseCards OpenEventsCard))

          (* * Run the history OpenNoteFileFn now.)


		    (NCHist.NoteFileWhenOpenedFn NoteFile))
      else (NCP.ReportError "NCHist.HistoritizeNoteFile" (CONCAT 
							    "Can't historitize closed notefile: "
								       NoteFile)))))

(NCHist.NoteFileWhenOpenedFn
  (LAMBDA (NoteFile)                                         (* rht: " 4-Feb-87 23:41")

          (* * Function to be called when we open a NoteFile that has been "Historitized." Creates and opens a new History 
	  card for this session)



          (* * rht 2/4/87: Now calls NCP.CreateCard with NoDisplayFlg NIL.)


    (DECLARE (GLOBALVARS NCHist.HistoryCardPosition))
    (NCHist.GetHistoryFileBox NoteFile)
    (NCP.OpenCard (NCP.CreateCard (QUOTE History)
				      NoteFile NIL NIL)
		    NCHist.HistoryCardPosition)))

(NCHist.CreateHistoryCardTitle
  (LAMBDA (Card)                                             (* rht: " 9-Dec-86 00:18")

          (* * Creates title for history card consisting of date and initials.)


    (LET ((NoteFile (NCP.CardNoteFile Card))
	  (SystemDate (DATE (DATEFORMAT NO.TIME NUMBER.OF.MONTH))))
         (CONCAT (NCHist.ShaveLeadingSpace (SUBSTRING SystemDate 4 5))
		   "/"
		   (NCHist.ShaveLeadingSpace (SUBSTRING SystemDate 1 2))
		   "/"
		   (NCHist.ShaveLeadingSpace (SUBSTRING SystemDate 7 8))
		   " "
		   (NCP.NoteFileProp NoteFile (QUOTE Initials))))))

(NCHist.GetHistoryFileBox
  (LAMBDA (NoteFile)                                         (* rht: "23-Nov-86 13:38")

          (* * Create a history filebox if there isn't one already.)


    (LET ((HistoryFileBox (NCP.LookupCardByName (QUOTE HistoryFileBox)
						  NoteFile)))
         (if (NOT (NCP.ValidCardP HistoryFileBox))
	     then (SETQ HistoryFileBox (NCP.CreateFileBox NoteFile "NoteFile Use History" T NIL 
								NIL (NCP.ContentsFileBox NoteFile)))
		    (NCP.RegisterCardByName (QUOTE HistoryFileBox)
					      HistoryFileBox))
         (NCP.AddSpecialCard HistoryFileBox)
     HistoryFileBox)))
)
(DEFINEQ

(NCHist.HistoryCardMakeFn
  (LAMBDA (Card Title NoDisplayFlg)                          (* rht: " 2-Feb-87 18:21")

          (* * If one doesn't exist, create a NoteFile use history filebox, otherwise bring up the old one.)


    (LET ((NoteFile (NCP.CardNoteFile Card))
	  ReturnValue HistoryFileBox)

          (* * If one doesn't exist, create a NoteFile use history filebox, otherwise find the old one.)


         (SETQ HistoryFileBox (NCHist.GetHistoryFileBox NoteFile))

          (* * Create a text card, then give it a title and file it)


         (SETQ ReturnValue (NCP.ApplySuperTypeFn MakeFn Card Title NoDisplayFlg))
                                                             (* Cache the history filebox so that NCP.FileCards 
							     won't have to close it.)
         (OR (NCP.CardCachedP HistoryFileBox)
	       (NCP.CacheCards HistoryFileBox))
         (NCP.FileCards Card HistoryFileBox)
         (NCP.CardTitle Card (OR Title (NCHist.CreateHistoryCardTitle Card)))
         (NC.NoteFileAddProp NoteFile (QUOTE HistoryCards)
			       Card)

          (* * Put the start time in the beginning of the card's substance)


         (NCP.CardAddText Card (CONCAT (DATE (DATEFORMAT NO.DATE NO.SECONDS))
					   " - "
					   (CHARACTER 13))
			    (QUOTE START))
     ReturnValue)))

(NCHist.HistoryCardWhenSavedFn
  (LAMBDA (HistoryCard)                                      (* rht: " 2-Feb-87 18:10")

          (* * QuitFn for the History card type. Delete old close time from the History card and insert the current close 
	  time in its place. Only do this for "current" history cards, i.e. ones opened during this session.)


    (if (for Card in (NCP.NoteFileProp (NCP.CardNoteFile HistoryCard)
					       (QUOTE HistoryCards))
	     when (NCP.ValidCardP Card) thereis (NCP.SameCardP Card HistoryCard))
	then (LET ((Stream (NCP.CardSubstance HistoryCard))
		     Time AfterDashPosition CRPosition)
		    (SETQ Time (CONCAT " " (DATE (DATEFORMAT NO.DATE NO.SECONDS))))
		    (SETQ AfterDashPosition (ADD1 (TEDIT.FIND Stream "-" 1)))
		    (SETQ CRPosition (TEDIT.FIND Stream (CHARACTER 13)
						     1))
		    (TEDIT.DELETE Stream AfterDashPosition (IDIFFERENCE CRPosition 
									    AfterDashPosition))
		    (NCP.CardAddText HistoryCard Time AfterDashPosition)))))

(NCHist.AddHistoryCard
  (LAMBDA NIL                                                (* rht: "21-Nov-86 17:54")

          (* * Add History card type to card type list)


    (NCP.CreateCardType (QUOTE History)
			  (QUOTE Text)
			  (BQUOTE ((MakeFn , (FUNCTION NCHist.HistoryCardMakeFn))))
			  (BQUOTE ((DisplayedInMenuFlg T))))))
)
(DEFINEQ

(NCHist.ShaveLeadingSpace
  (LAMBDA (String)                                           (* rht: " 9-Dec-86 00:18")

          (* * If first char of String is a space, then return substring consisting of the rest of String.)


    (if (EQ (NTHCHARCODE String 1)
		32)
	then (SUBSTRING String 2)
      else String)))
)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NCHist.HistoryCardPosition)
)

(RPAQ? NCHist.HistoryCardPosition NIL)
(NCHist.AddHistoryCard)
(PUTPROP (QUOTE History)
	 (QUOTE WhenSavedFn)
	 (FUNCTION NCHist.HistoryCardWhenSavedFn))
(PUTPROPS NCHISTORYCARD COPYRIGHT ("Xerox Corporation" 1986 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (989 4545 (NCHist.HistoricizeNoteFile 999 . 2629) (NCHist.NoteFileWhenOpenedFn 2631 . 
3231) (NCHist.CreateHistoryCardTitle 3233 . 3870) (NCHist.GetHistoryFileBox 3872 . 4543)) (4546 7449 (
NCHist.HistoryCardMakeFn 4556 . 5966) (NCHist.HistoryCardWhenSavedFn 5968 . 7077) (
NCHist.AddHistoryCard 7079 . 7447)) (7450 7811 (NCHist.ShaveLeadingSpace 7460 . 7809)))))
STOP