(DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP")
(FILECREATED "30-Mar-88 17:49:47" {QV}<NOTECARDS>1.3LNEXT>RHTPATCH314.;1 10586  

      changes to%:  (VARS RHTPATCH314COMS))


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

(PRETTYCOMPRINT RHTPATCH314COMS)

(RPAQQ RHTPATCH314COMS ((DECLARE%: DONTCOPY (PROPS (RHTPATCH314 MAKEFILE-ENVIRONMENT)
                                                   (RHTPATCH314 FILETYPE)))
                        

(* ;;; "Fixes storage leak whereby card objects that were killed by tedit-process-killer weren't collectable after closing the card.")

                        
          
          (* ;; "Change to NCTEXTCARD")

                        (FNS NC.TEditCloseFn)
                        
          
          (* ;; "Change to NCCARDS")

                        (FNS NC.QuitCard)))
(DECLARE%: DONTCOPY 

(PUTPROPS RHTPATCH314 MAKEFILE-ENVIRONMENT (:PACKAGE "INTERLISP" :READTABLE "INTERLISP"))

(PUTPROPS RHTPATCH314 FILETYPE :TCOMPL)
)



(* ;;; 
"Fixes storage leak whereby card objects that were killed by tedit-process-killer weren't collectable after closing the card."
)




(* ;; "Change to NCTEXTCARD")

(DEFINEQ

(NC.TEditCloseFn
  [LAMBDA (CardIdentifier)                                   (* ; "Edited 30-Mar-88 17:45 by Trigg")
                                                             (* ; 
                                                     "Close this TEdit window by Quitting from TEdit")
          
          (* ;; "rht 11/12/84: Changed call to TEXTSTREAM to a WINDOWPROP call.")
          
          (* ;; "fgh 11/13/85 Updated to handle Card objects.")
          
          (* ;; 
        "rht 8/8/87: Now smashes value of PREVPREVPC and its proplist so PIECE objects can be GC'ed.")
          
          (* ;; 
     "rht 3/30/88: Now restarts tedit process if it was killed - this seems to prevent storage leak.")

    (DECLARE (GLOBALVARS PREVPREVPC))
    (LET ((Card (NC.CoerceToCard CardIdentifier))
          Window)
         (SETQ Window (NC.FetchWindow Card))
         (NC.TEditQuitFn Card)
         (if Window
             then                                            (* ; 
                                                 "Process may have been turned off.  Try to restart.")

                  (OR (WINDOWPROP Window 'PROCESS)
                      (RESTART-PROCESS-OF-TEDIT-WINDOW Window))
                  (WINDOWDELPROP Window 'CLOSEFN (FUNCTION NC.QuitCard))
                  (TEDIT.QUIT (TEXTSTREAM Window)))
          
          (* ;; "Ugliness supremo: This to allow PIECE objects, and the links they point to, to be GC'ed.  Why does TEdit let this junk hang around???")

         (SETQ PREVPREVPC NIL)
         (SETPROPLIST 'PREVPREVPC NIL])
)



(* ;; "Change to NCCARDS")

(DEFINEQ

(NC.QuitCard
  [LAMBDA (CardIdentifier CallCloseWFlg DontSaveFlg DontRecacheFlg InterestedWindow OperationMsg 
                 QuietFlg Don'tDeactivateFlg)                (* ; "Edited 30-Mar-88 17:47 by Trigg")

(* ;;; "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")
          
          (* ;; "fgh 11/11/85: Updated to handle CardID and CardInfo objects.")
          
          (* ;; "fgh 1/16/86 Put in code to insure that if one of the TopLevelCards is quit then it is reactivated immedialtely to make sure it stays cached for fast access.")
          
          (* ;; "fgh 2/5/86 Added call to NC.ApplyFn")
          
          (* ;; "fgh 5/2/86 Added DontRecacheFlg arg")
          
          (* ;; "fgh 6/9/86 Added code to check to make sure other operations are not in progress.  And DontCheckOpInProgressFlg arg to match")
          
          (* ;; "fgh 6/26/86 Added InterestedWindow & OperationMsg arg.")
          
          (* ;; "rht 7/2/86: Now bails out if notefile is readonly, user confirms, but we're supposed to write down changes.")
          
          (* ;; "rht 7/13/86: Now takes QuietFlg arg.")
          
          (* ;; "rht 7/14/86: Call NC.DeactivateCard from here instead of in card type QuitFn.  Take a Don'tDeactivateFlg as well.")
          
          (* ;; "rht 10/7/86: Now removes DELETEME imageobj's from card substance.")
          
          (* ;; "rht 11/2/86: Now returns DON'T if operation in progress.")
          
          (* ;; "rht 11/13/86: Now closes open proplist editor if any before saving.")
          
          (* ;; 
     "rg 3/4/87 rewritten to use new NC.ProtectedCardOperation, removed DontCheckOpInProgressFlg arg")
          
          (* ;; "rht 3/24/87: Now calls NC.CoerceToInterestedWindow and passes InterestedWindow to NC.InsureProperFiling.")
          
          (* ;; 
  "rht 4/24/87: Fixed a vmem leak: when CallCloseWFlg is nil it doesn't clear CardObject windowprop.")
          
          (* ;; "pmi 9/16/87: Undoes previous fix to this function.  Needed to get NCLOGGER working.  It depends on getting the CardObject off of the Window passed in as CardIdentifier.")
          
          (* ;; "rht 3/30/88: Restores fix of 4/24/87.  NCLOGGER will have to finesse this somehow.")

    (DECLARE (GLOBALVARS NC.RemoveDELETEMEImageObjsFromCardFlg))
    (LET ((Card (NC.CoerceToCard CardIdentifier))
          Window ReadOnlyCardFlg)
         (NC.ProtectedCardOperation
          Card "Close Card" InterestedWindow
          (PROG NIL
                (SETQ ReadOnlyCardFlg (NC.ReadOnlyCardP Card))
                                                             (* ; 
                       "The window not being open should mean that it's shrunken.  If so, expand it.")

                (SETQ Window (NC.FetchWindow Card))
                (OR InterestedWindow (SETQ InterestedWindow (NC.CoerceToInterestedWindow Card)))
                (COND
                   ((AND Window (NOT (OPENWP Window)))
                    (EXPANDW Window)))
          
          (* ;; "if proper filing says don't quit then get out")

                [OR DontSaveFlg ReadOnlyCardFlg (COND
                                                   ((EQ (NC.InsureProperFiling Card InterestedWindow)
                                                        'DON'T)
                                                    (RETURN 'DON'T]
          
          (* ;; "If card is readonly but we've made changes that we're supposed to save, then get user confirmation and bail out.")

                (if [AND (NOT DontSaveFlg)
                         (NOT Don'tDeactivateFlg)
                         ReadOnlyCardFlg
                         (NC.CardSomehowDirtyP Card)
                         (NULL QuietFlg)
                         (NOT (PROGN (NC.PrintMsg InterestedWindow T 
                                            "Card has been changed, but notefile is readonly."
                                            (CHARACTER 13))
                                     (NC.AskYesOrNo "Want to quit anyway, flushing changes? " NIL
                                            'Yes NIL InterestedWindow]
                    then (RETURN 'DON'T))
          
          (* ;; "Otherwise go ahead and quit")

                (RETURN (PROGN                               (* ; 
                                                             "Close open proplist editor if any.")

                               [AND Window (LET ((PropListEditorWindow (NC.PropListEditorOpenP Window
                                                                              )))
                                                (AND PropListEditorWindow (CLOSEW 
                                                                                 PropListEditorWindow
                                                                                 ]
                               (COND
                                  ((AND Window NC.CloseCardsOffScreenFlg)
                                   [COND
                                      ((NOT (NC.FetchSavedRegion Card))
                                       (NC.SetSavedRegion Card (WINDOWPROP Window 'REGION]
                                   (MOVEW Window 1500 1500)))
                               (OR DontSaveFlg (if ReadOnlyCardFlg
                                                   then (NC.TurnOffDirtyFlgs Card)
                                                 else (AND NC.RemoveDELETEMEImageObjsFromCardFlg
                                                           (NC.RemoveDELETEMEImageObjsFromCard
                                                            Card
                                                            (FUNCTION NC.DELETEMEImageObjP)))
                                                      (NC.CardSaveFn Card (OR 
                                                                            NC.CloseCardsOffScreenFlg 
                                                                              QuietFlg)
                                                             InterestedWindow OperationMsg)))
                               (AND Window (WINDOWDELPROP Window 'CLOSEFN (FUNCTION NC.QuitCard)))
                               (PROG1 (NC.ApplyFn QuitFn Card)
                                      (AND Window (WINDOWPROP Window 'NoteCardObject NIL))
                                      (AND CallCloseWFlg Window (CLOSEW Window))
                                      (OR Don'tDeactivateFlg (NC.DeactivateCard Card))
          
          (* ;; "if this is one of the top level cards, then make sure it stays cached")

                                      (if (AND (NC.TopLevelCardP Card)
                                               (NULL DontRecacheFlg)
                                               (NULL Don'tDeactivateFlg))
                                          then (NCP.ActivateCards Card])
)
(PUTPROPS RHTPATCH314 COPYRIGHT ("Xerox Corporation" 1988))
(DECLARE%: DONTCOPY
  (FILEMAP (NIL (1230 2877 (NC.TEditCloseFn 1240 . 2875)) (2913 10503 (NC.QuitCard 2923 . 10501)))))
STOP