(DEFINE-FILE-INFO PACKAGE "IL" READTABLE "INTERLISP" BASE 10)
(FILECREATED " 1-Feb-88 18:12:57" {QV}<NOTECARDS>1.3LNEXT>RGPATCH079.;4 142887 

      changes to%:  (VARS RGPATCH079COMS)
                    (MACROS .NAMED-RESETLST. NAMED-RESETLST)
                    (FNS NC.MakeFilingLinks NC.AddLinksToCard NC.AddParents NC.MakeBrowserCard 
                         NC.UpdateBrowserCard NC.FileBoxCollectChildren NCP.CloseCards 
                         NCP.SelectCards NC.CopyCards NC.MoveCards NC.SelectNoteCards 
                         NC.CopyStructure NC.DeleteStructure NAMED-RESETLST NAMED-RESETUNWIND)
                    (FUNCTIONS NCP.WithLockedCards NAMED-RESETUNSAVE .NAMED-RESETLST. NAMED-RESETSAVE
                           )

      previous date%: "29-Jan-88 20:09:29" {QV}<NOTECARDS>1.3LNEXT>RGPATCH079.;1)


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

(PRETTYCOMPRINT RGPATCH079COMS)

(RPAQQ RGPATCH079COMS (
          
          (* ;; "rg 1/29/88: NAMED-RESETLST machinery rewritten to conform to Lyric versions of corresponding system functions")

                       [DECLARE%: DONTEVAL@LOAD DOCOPY (P (NC.LoadFileFromDirectories 'NCBROWSERCARD)
                                                          (NC.LoadFileFromDirectories 'NCDOCUMENTCARD
                                                                 ]
                       
          
          (* ;; "new in NCDECLS")

                       (MACROS .NAMED-RESETLST.)
                       (FNS NAMED-RESETUNWIND)
                       
          
          (* ;; "REMOVE FNS definitions of NAMED-RESETLST, NAMED-RESETSAVE, and NAMED-RESETUNSAVE from NCDECLS.  Also, NAMED-RESETRESTORE has been superceded by NAMED-RESETUNWIND")

                       
          
          (* ;; "changes to NCDECLS")

                       (MACROS NAMED-RESETLST)
                       (FUNCTIONS NCP.WithLockedCards NAMED-RESETSAVE NAMED-RESETUNSAVE)
                       
          
          (* ;; "changes to NCLINKS")

                       (FNS NC.MakeLink NC.MakeFilingLinks NC.AddGlobalLinksToCard NC.AddLinksToCard)
                       
          
          (* ;; "changes to NCCARDS")

                       (FNS NC.AddParents NC.DeleteNoteCards NC.UnfileNoteCard)
                       
          
          (* ;; "changes to NCBROWSERCARD")

                       (FNS NC.MakeBrowserCard NC.UpdateBrowserCard NC.BrowserAddNode)
                       
          
          (* ;; "changes to NCFILEBOXCARD")

                       (FNS NC.FileBoxCollectChildren)
                       
          
          (* ;; "changes to NCPROGINT")

                       (FNS NCP.CloseCards NCP.SelectCards)
                       
          
          (* ;; "changes to NCDOCUMENTCARD")

                       (FNS NC.MakeDocument)
                       
          
          (* ;; "changes to NCDATABASE")

                       (FNS NC.CopyCards NC.MoveCards)
                       
          
          (* ;; "changes to NCINTERFACE")

                       (FNS NC.SelectNoteCards NC.CloseNoteCards NC.CopyStructure NC.CloseStructure 
                            NC.DeleteStructure NC.MoveStructure)))



(* ;; 
"rg 1/29/88: NAMED-RESETLST machinery rewritten to conform to Lyric versions of corresponding system functions"
)

(DECLARE%: DONTEVAL@LOAD DOCOPY 
(NC.LoadFileFromDirectories 'NCBROWSERCARD)
(NC.LoadFileFromDirectories 'NCDOCUMENTCARD)
)



(* ;; "new in NCDECLS")

(DECLARE%: EVAL@COMPILE 
[PROGN (DEFMACRO .NAMED-RESETLST. (HANDLE FORM &OPTIONAL INIT OTHERBINDINGS)
          `[LET ((,HANDLE ,INIT)
                 ,@OTHERBINDINGS)
                [DECLARE (SPECVARS ,HANDLE ,@(MAPCAR OTHERBINDINGS 'CAR]
                (CL:UNWIND-PROTECT ,FORM (NAMED-RESETUNWIND ,HANDLE])

       (PUTPROPS .NAMED-RESETLST. DMACRO
              (DEFMACRO (HANDLE FORM &OPTIONAL INIT OTHERBINDINGS) `[LET
                                                                     ((,HANDLE ,INIT)
                                                                      ,@OTHERBINDINGS)
                                                                     [DECLARE
                                                                      (SPECVARS
                                                                       ,HANDLE
                                                                       ,@(MAPCAR OTHERBINDINGS
                                                                                'CAR]
                                                                     (CL:UNWIND-PROTECT
                                                                      ,FORM
                                                                      (NAMED-RESETUNWIND ,HANDLE]
                 )
]
)
(DEFINEQ

(NAMED-RESETUNWIND
  [LAMBDA (HANDLE NORMALP)                            (* ; "Edited 29-Jan-88 18:14 by Randy.Gobbel")
          
          (* ;; "taken from Lyric RESETUNWIND of 4-Nov-86 16:53")

    (while (LISTP HANDLE) bind OLDVALUE RESETZ do (SETQ RESETZ (pop HANDLE))
                                                  (if (LISTP (CAR RESETZ))
                                                      then   (* ; "RESETSAVE and RESETFORM do this")

                                                           (SETQ OLDVALUE (if (CDR RESETZ)
                                                                              then 
          
          (* ;; "occurs for RESETSAVE's when second argument is specified.  In this case, (CADR RESETZ) is the value of the saving form, i.e. the first argument to RESETSAVE.")

                                                                                   (CADR RESETZ)
                                                                            else (CADAR RESETZ)))
                                                           (APPLY (CAAR RESETZ)
                                                                  (CDAR RESETZ))
                                                    else     (* ; 
                                                             "RESETSAVE of a symbol sets its value")

                                                         (SETTOPVAL (CAR RESETZ)
                                                                (CDR RESETZ])
)



(* ;; 
"REMOVE FNS definitions of NAMED-RESETLST, NAMED-RESETSAVE, and NAMED-RESETUNSAVE from NCDECLS.  Also, NAMED-RESETRESTORE has been superceded by NAMED-RESETUNWIND"
)




(* ;; "changes to NCDECLS")

(DECLARE%: EVAL@COMPILE 
[PROGN (DEFMACRO NAMED-RESETLST (HANDLE FORM) `[LET ((,HANDLE NIL)
                                                     ((LISPXHIST LISPXHIST)))
                                                    (DECLARE (SPECVARS ,HANDLE LISPXHIST))
                                                    (CL:UNWIND-PROTECT ,FORM (NAMED-RESETUNWIND
                                                                              ,HANDLE])

       (PUTPROPS NAMED-RESETLST MACRO ((H X . Y)
                                       (.NAMED-RESETLST. H (PROGN X . Y)
                                              NIL
                                              ((LISPXHIST LISPXHIST]
)

(DEFMACRO NCP.WithLockedCards (&BODY Body) `(NAMED-RESETLST CardListResetVar ,@Body))


(DEFMACRO NAMED-RESETSAVE (RESETHANDLE &REST FORMS)
   `(LET (RESETITEM)
         (SETQ ,RESETHANDLE
          (CONS [SETQ RESETITEM
                 ,(COND
                     [(AND (ATOM (CAR FORMS))
                           (CAR FORMS))
                      (SUBPAIR '(VAR VAL) (CDR X)
                             '(PROG1 (CONS 'VAR (GETTOPVAL 'VAR))
                                     (SETTOPVAL 'VAR VAL]
                     [(CDR FORMS)
                      `(LIST ,(CADR FORMS) ,(CAR FORMS]
                     (T `(LIST (LIST ',(COND
                                          ((EQ (CAAR FORMS)
                                               'SETQ)
                                           (CAR (CADDAR FORMS)))
                                          (T (CAAR FORMS))) ,(CAR FORMS]
                ,RESETHANDLE))
         RESETITEM))


(DEFMACRO NAMED-RESETUNSAVE (RESETHANDLE ITEMFORM)
   `[LET ((ITEMLIST ,ITEMFORM))
         (for ITEM in ITEMLIST do (SET RESETHANDLE (DREMOVE ITEM ,RESETHANDLE))
                                  (COND
                                     ((LISTP (CAR ITEM))
                                      [SETQ OLDVALUE (COND
                                                        ((CDR ITEM)
                                                         (CADR ITEM))
                                                        (T (CADAR ITEM]
                                      (APPLY (CAAR ITEM)
                                             (CDAR ITEM)))
                                     (T (SETTOPVAL (CAR ITEM)
                                               (CDR ITEM])




(* ;; "changes to NCLINKS")

(DEFINEQ

(NC.MakeLink
  [LAMBDA (Window LinkLabel DestinationCard SourceCard DisplayMode AnchorMode Message NoDisplayFlg 
                 LinkToInsertAfter CrossFileLinksMode)       (* rht%: "20-Nov-87 22:27")
          
          (* * Make a link from (OR Window SourceCard) to DestinationCard with linklabel 
          of LinkLabel)
          
          (* * rht 1/12/85%: If need to create a new card, then now shows card type menu 
          near window of SourceID.)
          
          (* * rht 1/13/85%: Added extra args Message and NoDisplayFlg.)
          
          (* * rht 3/26/85%: Added LinkToInsertAfter arg which should be NIL or a link to 
          insert the new To link after. If NIL, then insert at front of ToLinks.)
          
          (* * kirk 9/23/85%: took out GETPROMPTWINDOW call for asknotecardtype)
          
          (* * kirk%: 14Nov85%: changed NC.CoerceToID to to NC.CoerceToCard)
          
          (* * fgh |11/16/85| Changed from PROG to LET and used COND to contyrol 
          returnmed value.)
          
          (* * fgh |2/5/86| Changed call DefaultLinkDisplayMode to FetchLinkDisplayMode)
          
          (* * fgh |6/5/86| Now calls AskLinkLabel if LinkLabel arg is NIL)
          
          (* * rht 7/4/86%: Added check for readonly card.)
          
          (* * kef 7/17/86%: Added calls to grab the write permission on the appropriate 
          card parts.)
          
          (* * kef 7/22/86%: Saves the links on the Destination Card now right away, 
          while still holding onto the FROMLINKS write lock.)
          
          (* * fgh |8/30/86| Adpated to use NC.IfCardPartNotBusy.)
          
          (* * rht 9/29/86%: Tossed Ken's call to NC.PutFromLinks;
          It was the cause of too many nasty breaks.
          Also made syntactic fixes.)
          
          (* * rht 10/4/86%: Now handles cross file links.
          New arg CrossFileLinksMode determines whether cross-file link will be two-way, 
          i.e. will destination card know it's being linked to.)
          
          (* * rht 11/10/86%: Now creates new crossfile link if Destination card is a 
          CrossFileLink card that we didn't just create.)
          
          (* * rht 11/14/86%: Now checks if non-nil DestinationCard before trying to do 
          cross-filelink stuff.)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection.)
          
          (* * rht 12/9/86%: Throws out JustCreatedFlg marker stuff.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rht 12/16/86%: Fixed bug whereby electing not to open notefile containing 
          crossfilelink dest card caused break.)
          
          (* * rht 12/16/86%: Now passes Window down to NC.GetCrossFileLinkDestCard.)
          
          (* * rg |3/18/87| added NCP.WithLockedCards wrapper)
          
          (* * rht 5/25/87%: No longer tries to make two way cross-file links when dest 
          notefile is open read-only. Also assumes that CrossFileLinksMode is one of 
          TWOWAY, ONEWAY or ASK. Now fills in the new RemoteCrossFileLinkCardUID field of 
          cross file link cards.)
          
          (* * rht 11/20/87%: Now recomputes ShowLinks menus if they're visible.)

    (DECLARE (GLOBALVARS NC.SelectingSingleCardMenu NC.NewCrossFileLinksMode))
    (OR SourceCard (SETQ SourceCard (NC.CoerceToCard Window)))
    (AND
     (NC.CheckForNotReadOnly SourceCard Window "Can't make links in ")
     (NCP.WithLockedCards
      (LET
       (Link Type)
       (OR Window (SETQ Window (NC.FetchWindow SourceCard)))
       (OR Message (SETQ Message "Please shift-select the Card or Box to be linked to."))
       (OR LinkLabel (SETQ LinkLabel (NC.AskLinkLabel Window NIL NIL T NIL)))
       (OR DestinationCard (SETQ DestinationCard (NC.SelectNoteCards T
                                                        [FUNCTION (LAMBDA (Card)
                                                                    (COND
                                                                       ((NOT (NC.SameCardP Card 
                                                                                    SourceCard))
                                                                        T)
                                                                       (T (NC.PrintMsg Window T 
                                                                 "A Card/Box cannot link to itself. "
                                                                                 (CHARACTER 13)
                                                                                 "Selection ignored."
                                                                                 (CHARACTER 13))
                                                                          NIL]
                                                        NC.SelectingSingleCardMenu SourceCard Message
                                                        )))
       [if (EQ DestinationCard '*New% Card*)
           then (SETQ DestinationCard (AND (SETQ Type (NC.AskNoteCardType (WINDOWREGION Window)))
                                           (NC.CoerceToCard (NC.MakeNoteCard Type (fetch (Card 
                                                                                             NoteFile
                                                                                               )
                                                                                     of SourceCard)
                                                                   NIL NoDisplayFlg]
          
          (* * If we're trying to link to a CrossFileLink card, then check whether card 
          was just created. If so, then it's the first link, otherwise we make a new 
          CrossFileLink.)

       (AND DestinationCard (NC.CrossFileLinkCardP DestinationCard)
            (SETQ DestinationCard (NC.GetCrossFileLinkDestCard DestinationCard Window))
            (NC.SetUserDataProp DestinationCard 'JustCreatedFlg NIL))
       (if DestinationCard
           then
           (NC.IfCardPartNotBusy
            DestinationCard
            'FROMLINKS
            (NC.IfCardPartNotBusy
             SourceCard
             'TOLINKS
          
          (* * If have cross-file link, then make two new crossfilelink cards, one per 
          notefile. Make global link over there from crossfilelink card to 
          DestinationCard and local link here from SourceCard to crossfilelink card.)

             [if (NOT (NC.SameNoteFileP (fetch (Card NoteFile) of SourceCard)
                             (fetch (Card NoteFile) of DestinationCard)))
                 then (LET ([CrossFileLinksTwoWayFlg (OR (EQ CrossFileLinksMode 'TWOWAY)
                                                         (AND (NULL CrossFileLinksMode)
                                                              (EQ NC.NewCrossFileLinksMode
                                                                  'TWOWAY))
                                                         (AND [OR (EQ CrossFileLinksMode 'ASK)
                                                                  (AND (NULL CrossFileLinksMode)
                                                                       (EQ NC.NewCrossFileLinksMode
                                                                           'ASK]
                                                              (NC.AskCrossFileLinkMode 
                                                                     DestinationCard Window]
                            RemoteSourceCard)
                           (if CrossFileLinksTwoWayFlg
                               then (AND (SETQ RemoteSourceCard (NC.CreateCrossFileLinkCard 
                                                                       DestinationCard SourceCard T))
                                         (NC.MakeGlobalLink Window LinkLabel DestinationCard 
                                                RemoteSourceCard DisplayMode)))
                           (SETQ DestinationCard (NC.CreateCrossFileLinkCard SourceCard 
                                                        DestinationCard CrossFileLinksTwoWayFlg))
                           (if RemoteSourceCard
                               then 
          
          (* Make the two crossfile link cards know about each other's UIDs.)

                                    (replace (CrossFileLinkSubstance RemoteCrossFileLinkCardUID)
                                       of (NC.FetchSubstance RemoteSourceCard)
                                       with (fetch (Card UID) of DestinationCard))
                                    (replace (CrossFileLinkSubstance RemoteCrossFileLinkCardUID)
                                       of (NC.FetchSubstance DestinationCard)
                                       with (fetch (Card UID) of RemoteSourceCard]
             [SETQ Link (create Link
                               UID ← (NC.MakeUID)
                               SourceCard ← SourceCard
                               DestinationCard ← DestinationCard
                               AnchorMode ← AnchorMode
                               Label ← LinkLabel
                               DisplayMode ← (OR DisplayMode (NC.FetchLinkDisplayMode SourceCard]
             (NC.AddToLink Link LinkToInsertAfter)
             (NC.AddFromLink Link)                           (* Recompute ShowLinks menus if 
                                                             they're up.)
             (if (NC.FetchShowLinksWindow SourceCard)
                 then (NC.ShowLinks SourceCard))
             (if (NC.FetchShowLinksWindow DestinationCard)
                 then (NC.ShowLinks DestinationCard))
             Link))
         else NIL])

(NC.MakeFilingLinks
  [LAMBDA (Card Msg InterestedWindow)                        (* Randy.Gobbel " 2-Apr-87 15:38")
          
          (* Hooks card specified by Card to all of the current contents cards by a 
          Contents link)
          
          (* * rht 8/1/84%: Changed the NC.PrintMsg2 call for "No FileBox has been specified." 
          to use NIL as second arg rather than T. This prevents erasure of previous error 
          messages.)
          
          (* * rht 12/8/84%: Massive rewrite. Now calls NC.MakeChildLink.
          And always orphanizes if no parent specified.
          This is because it's currently called only by NC.InsureProperFiling.)
          
          (* * rht 6/25/85%: Now returns NewParents and checks if CANCELLED comes back 
          from NC.SelectNoteCards so can abort the calling operation.)
          
          (* * Fgh |11/15/85| Adapted from and intended to replace NC.MakeContentsHooks)
          
          (* * fgh |8/6/86| Updated to use NC.AttachPromptWindow and added Msg arg)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rg |2/19/87| Make sure NewParents always has the real value)
          
          (* * rg |3/18/87| added NC.CardSelectionOperation wrapper)
          
          (* * rht 3/23/87%: Changed so that message will fit on one less line.)
          
          (* * rht 3/23/87%: Now takes InterestedWindow arg.)
          
          (* * Rht 3/24/87%: Now calls NC.CoerceToInterestedWindow)
          
          (* * rht 3/26/87%: No longer allows selection of boxes in foreign notefiles.)
          
          (* * rg |4/1/87| changed CANCELLED to DON'T)

    (DECLARE (GLOBALVARS NC.SelectingContentsMenu))
    (NCP.WithLockedCards (PROG ((NoteFile (fetch (Card NoteFile) of Card))
                                OneHook NewParents)
                               (OR InterestedWindow (SETQ InterestedWindow (
                                                                          NC.CoerceToInterestedWindow
                                                                            Card)))
                               (SETQ NewParents (NC.SelectNoteCards
                                                 NIL
                                                 [FUNCTION (LAMBDA (SelectedCard)
                                                             (AND (NC.FileBoxP SelectedCard)
                                                                  (NC.SameNoteFileP
                                                                   NoteFile
                                                                   (fetch (Card NoteFile)
                                                                      of SelectedCard]
                                                 NC.SelectingContentsMenu Card
                                                 (CONCAT (OR Msg "")
                                                        
                                                    "('Done' with no selections files in ToBeFiled.)"
                                                        )
                                                 T))
                               [COND
                                  ([NOT (OR (EQ NewParents 'DON'T)
                                            (AND NewParents (for ParentCard in NewParents
                                                               bind OneHook
                                                               when (NC.MakeChildLink Card ParentCard 
                                                                           InterestedWindow)
                                                               do (SETQ OneHook T)
                                                               finally (RETURN OneHook]
                                   (NC.PrintMsg InterestedWindow NIL "No FileBox has been specified."
                                          (CHARACTER 13)
                                          "This card will be filed in the ToBeFiled Box."
                                          (CHARACTER 13))
                                   (SETQ NewParents (NC.HookToOrphanCard Card (fetch (NoteFile 
                                                                                        ToBeFiledCard
                                                                                            )
                                                                                 of NoteFile)))
                                   (COND
                                      ((NC.AttachPromptWindow InterestedWindow NIL NIL NIL T)
                                       (SPAWN.MOUSE)
                                       (DISMISS 2000)
                                       (NC.ClearMsg InterestedWindow T]
                               (RETURN NewParents])

(NC.AddGlobalLinksToCard
  [LAMBDA (CardIdentifier SingleLinkFlg)                     (* pmi%: "21-May-87 15:42")
          
          (* * Called from card's menu to add some global links.)
          
          (* * rht 11/24/85%: Fixed bugs. It was calling NC.CoerceToID.)
          
          (* * fgh |6/9/86| Added chack for other interaction operations already in 
          progress.)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rg |3/4/87| rewritten for new version of NC.ProtectedCardOperation)
          
          (* * rg |3/18/87| added NC.CardSelectionOperation wrapper)
          
          (* * rg |3/31/87| fixed bug in NC.ProtectedCardOperation wrapper)
          
          (* * pmi 5/21/87%: Changed NC.CardSelectionOperation to NCP.WithLockedCards)

    (NC.ProtectedCardOperation
     (NC.CoerceToCard CardIdentifier)
     "Add Global Link(s)" NIL
     (NCP.WithLockedCards (LET (Window SourceCard DestinationCards Label)
                               (SETQ SourceCard (NC.CoerceToCard CardIdentifier))
                               (SETQ Window (NC.FetchWindow SourceCard))
                               (SETQ Label (NC.AskLinkLabel Window NIL NIL T T))
                               (AND Label (if SingleLinkFlg
                                              then (NC.MakeGlobalLink Window Label NIL SourceCard)
                                                   (NC.ClearMsg Window T)
                                            else (SETQ DestinationCards
                                                  (NC.SelectNoteCards
                                                   NIL
                                                   [FUNCTION (LAMBDA (Card)
                                                               (COND
                                                                  ((NEQ Card SourceCard)
                                                                   T)
                                                                  (T (NC.PrintMsg Window T 
                                                                "A Card/Box cannot point to itself. "
                                                                            (CHARACTER 13)
                                                                            "Selection ignored."
                                                                            (CHARACTER 13))
                                                                     NIL]
                                                   NC.SelectingMultipleCardsMenu SourceCard 
                                           "Please shift-select the Cards or Boxes to be pointed to."
                                                   ))
                                                 (NC.ClearMsg Window T)
                                                 (for DestinationCard in DestinationCards
                                                    do (NC.MakeGlobalLink Window Label 
                                                              DestinationCard SourceCard])

(NC.AddLinksToCard
  [LAMBDA (CardIdentifier LinkLabel DestinationCards)        (* Randy.Gobbel " 2-Apr-87 15:38")
          
          (* * Adds multiple links to card designated by CardIdentifier.
          Rest of args can be NIL.)
          
          (* * fgh |6/9/86| Added Checks to make sure other interaction operation not in 
          porgress.)
          
          (* * rht 9/23/86%: Fixed bug in function passed to NC.SelectNoteCards.)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rg |3/4/87| rewritten for new version of NC.ProtectedCardOperation)
          
          (* * rg |3/18/87| added NC.CardSelectionOperation wrapper)
          
          (* * RG |4/2/87| changed NC.CardSelectionOperation to NCP.WithLockedCards)

    (LET ((SourceCard (NC.CoerceToCard CardIdentifier))
          CardType Window OperationInProgress)
         (NC.ProtectedCardOperation
          SourceCard "Insert Links" NIL
          (NCP.WithLockedCards (SETQ Window (NC.FetchWindow SourceCard))
                 (SETQ CardType (NC.FetchType SourceCard))
                 (OR LinkLabel (SETQ LinkLabel (NC.AskLinkLabel Window NIL NIL T T)))
                 (if LinkLabel
                     then (OR DestinationCards (SETQ DestinationCards
                                                (NC.SelectNoteCards NIL
                                                       [FUNCTION (LAMBDA (SelectedCard)
                                                                   (COND
                                                                      ((NOT (NC.SameCardP 
                                                                                   SelectedCard 
                                                                                   SourceCard))
                                                                       T)
                                                                      (T (NC.PrintMsg (NC.FetchWindow
                                                                                       SourceCard)
                                                                                T 
                                                                "A Card/Box cannot point to itself. "
                                                                                (CHARACTER 13)
                                                                                "Selection ignored."
                                                                                (CHARACTER 13))
                                                                         NIL]
                                                       NC.SelectingMultipleCardsMenu SourceCard 
                                           "Please shift-select the Cards or Boxes to be pointed to."
                                                       )))
                          (NC.ClearMsg Window T)
                          (for DestinationCard in DestinationCards do (NC.AddLinkToCard 
                                                                             CardIdentifier LinkLabel 
                                                                             DestinationCard])
)



(* ;; "changes to NCCARDS")

(DEFINEQ

(NC.AddParents
  [LAMBDA (WindowOrTextStream)                               (* Randy.Gobbel " 2-Apr-87 15:38")
          
          (* Add a subtopic link from a contents card specified by the user to the 
          contents card specified by WindowOrTextStream.
          But first check to make sure that this would not introduce any circularities in 
          the contents lattice.)
          
          (* * rht 12/8/84%: Massive shaving. Now calls NC.MakeChildLink to do the tough 
          work.)
          
          (* * rht 10/3/85%: No longer prints final, annoying, slow-to-disappear message 
          in prompt window if nothing selected.)
          
          (* * fgh |11/13/85| Updated to handle Card object.)
          
          (* * fgh |6/9/86| Added code to check to make sure that another operation is 
          not in progress on this card when this fn is called.)
          
          (* * rht 7/5/86%: Now checks for readonly cards.)
          
          (* * rht&pmi 11/24/86%: Surrounded call to NC.MakeChildLink with 
          NC.ActivateCardAndDo so that ParentCard will be active for duration of the 
          call.)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rht 1/28/87%: Took out call to NC.ActivateCardAndDo.
          Need to make sure ParentCard gets saved after getting link if wasn't active 
          originally.)
          
          (* * rg |3/3/87| Enlarged scope of NC.ProtectedCardOperation)
          
          (* * rg |3/18/87| added NC.CardSelectionOperation wrapper)
          
          (* * rg |4/2/87| changed NC.CardSelectionOperation to NCP.WithLockedCards)

    (NCP.WithLockedCards
     (LET (Card NewParents (Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream)))
          (SETQ Card (NC.CoerceToCard Window))
          (NC.ProtectedCardOperation
           Card "Designate FileBoxes" NIL
           (if (NC.CheckForNotReadOnly Card Window "Can't do filing in ")
               then (SETQ NewParents (NC.SelectNoteCards NIL (FUNCTION NC.FileBoxP)
                                            NC.SelectingParentsMenu Card 
                                            " Please shift-select the new parent FileBox(es)."))
                    (AND NewParents Card
                         (for ParentCard in NewParents bind OneHook
                            when [LET ((WasActiveFlg (NC.ActiveCardP ParentCard)))
                                      (OR WasActiveFlg (NC.GetNoteCard ParentCard))
                                      (PROG1 (NC.MakeChildLink Card ParentCard Window)
                                             (OR WasActiveFlg
                                                 (NC.QuitCard ParentCard NIL NIL NIL NIL NIL T]
                            do (SETQ OneHook T) finally (RETURN OneHook])

(NC.DeleteNoteCards
  [LAMBDA (CardIdentifiers NoIndividualConfirmFlg DontClearFlg InterestedWindow QuietFlg 
                 NoGroupConfirmFlg)                          (* pmi%: "15-Jan-88 11:46")
          
          (* Delete note cards. If no card specified then get a list of note cards to be 
          deleted. Then delete these cards.)
          
          (* * fgh 11/11/85%: Updated to handle new Card objects.
          Also split off main work of deleteing a single note card into NC.DeleteNoteCard 
          function.)
          
          (* * kirk 21Feb86 Added InterestedWindow)
          
          (* * kirk 29Apr86 Now returns CardIdentifiers)
          
          (* * fgh |6/9/86| Added checks to see if other operations are in progress)
          
          (* * rht 7/4/86%: Now checks that card is not read-only.)
          
          (* * kirk 18Aug86 Added main window for windowless cards.)
          
          (* * rht 8/29/86%: Reorganized and added call to NC.SeverAllLinks to make 
          deleting more efficient. Added QuietFlg, NoGroupConfirmFlg and 
          Don'tPutToBeDeletedCardsFlg args.)
          
          (* * rht 9/5/86%: Now forces NoGroupConfirmFlg to be non-nil if 
          NoIndividualConfirmFlg is NIL and only one card to delete.)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rht 12/16/86%: Removed obsolete Don'tPutToBeDeletedCardsFlg arg.)
          
          (* * rht 3/9/87%: Changed NC.DeleteSelectingMenu to NC.SelectingCardsMenu.)
          
          (* * rg |3/9/87| added NC.ProtectedSessionOperation wrapper)
          
          (* * rg |3/11/87| changed call of NC.DeleteNoteCard to 
          NC.DeleteNoteCardInternal)
          
          (* * rg |3/18/87| changed NC.ProtectedSessionOperation to 
          NC.CardSelectionOperation)
          
          (* * rht 3/30/87%: Now calls NC.SeverExternalLinks rather than 
          NC.SeverAllLinks.)
          
          (* * dsj 9/28/87%: Added call to NC.CardsToDelete which accesses the 
          WhenDeletedFn prop of card type. This does not yet handle the general case of 
          allowing me to bypass asking the user for confirmation, which is an operation 
          that should be a super type's WhenDeletedFn.)
          
          (* * pmi 1/15/88%: Added dsj's change (see above comment))

    (DECLARE (GLOBALVARS NC.SelectingCardsMenu))
    (NCP.WithLockedCards
     (NC.IfAllCardsFree
      (NC.LockListOfCards (MKLIST CardIdentifiers)
             "Delete Note Cards")
      (OR CardIdentifiers (SETQ CardIdentifiers (NC.SelectNoteCards NIL NIL NC.SelectingCardsMenu 
                                                       InterestedWindow 
                                                  "Please shift-select the Note Cards to be deleted."
                                                       )))
          
          (* * Kludge in case args are nil, say, when we're called from a card's menu.)

      (if (AND (NULL NoIndividualConfirmFlg)
               (NULL NoGroupConfirmFlg)
               (EQ (LENGTH (MKLIST CardIdentifiers))
                   1))
          then (SETQ NoGroupConfirmFlg T)
               (SETQ QuietFlg T))
          
          (* * First collect cards that are deletable.)

      (LET ((CardsToDelete (for CardIdentifier in (MKLIST CardIdentifiers) bind Card
                              eachtime (BLOCK)
                              when [AND (SETQ Card (NC.CoerceToCard CardIdentifier))
                                        (if (NOT (NC.TopLevelCardP Card))
                                          else (NC.PrintMsg (NC.FetchWindow Card)
                                                      T "You cannot delete this FileBox."
                                                      (CHARACTER 13))
                                               (DISMISS 1000)
                                               (NC.ClearMsg (NC.FetchWindow Card)
                                                      T)
                                               NIL)
                                        (NC.CheckForNotReadOnly Card (NC.FetchWindow Card)
                                               "Can't delete cards from a ")
                                        (OR NoIndividualConfirmFlg (PROG1 (NC.AskYesOrNo
                                                                           
                                                              "Are you sure you want to delete this?" 
                                                                           " -- " "Yes" (NULL 
                                                                                         DontClearFlg
                                                                                              )
                                                                           (OR (NC.FetchWindow Card)
                                                                               InterestedWindow)
                                                                           NIL NIL)
                                                                          (NC.ClearMsg] collect
                                                                                        Card))
            (NumSpecified (LENGTH (MKLIST CardIdentifiers)))
            NumToDelete FinalNumToDelete)
           (SETQ NumToDelete (LENGTH CardsToDelete))
           (if [AND (GREATERP NumToDelete 0)
                    (if (EQUAL NumToDelete NumSpecified)
                        then (OR NoGroupConfirmFlg (PROG1 (NC.AskYesOrNo (CONCAT "You've specified " 
                                                                                NumToDelete 
                                                                                " cards to delete."
                                                                                (CHARACTER 13)
                                                                                
                                                             "Are you sure you want to delete them? "
                                                                                )
                                                                 NIL "Yes" (NULL DontClearFlg)
                                                                 InterestedWindow)
                                                          (NC.ClearMsg)))
                      else (PROG1 (NC.AskYesOrNo (CONCAT "Out of " NumSpecified " cards specified, "
                                                        (DIFFERENCE NumSpecified NumToDelete)
                                                        " are not deletable."
                                                        (CHARACTER 13)
                                                        "Want to delete the remaining " NumToDelete 
                                                        " cards? ")
                                         NIL "Yes" (NULL DontClearFlg)
                                         InterestedWindow)
                                  (NC.ClearMsg]
               then 
          
          (* * dsj 9/28/87%: Let programmer have control over aborting deletion here.)

                    (SETQ CardsToDelete (NC.CardsToDelete CardsToDelete))
                    (SETQ FinalNumToDelete (LENGTH CardsToDelete))
                    (if (GREATERP FinalNumToDelete 0)
                        then (if (GREATERP NumToDelete FinalNumToDelete)
                                 then (NC.PrintMsg InterestedWindow T "Can only delete " 
                                             FinalNumToDelete " cards out of " NumToDelete 
                                             " specified for deletion.")
                                      (DISMISS 3000)
                                      (NC.ClearMsg InterestedWindow)) 
          
          (* * Mark UIDs of cards about to be deleted.)

                             (for Card in CardsToDelete do (NC.UIDPutProp (fetch (Card UID)
                                                                             of Card)
                                                                  'AboutToBeDeletedFlg T)) 
          
          (* * Sever all links into and out of CardsToDelete)

                             (NC.SeverExternalLinks CardsToDelete QuietFlg InterestedWindow) 
          
          (* * Now delete the cards one at a time.)

                             (OR QuietFlg (NC.PrintMsg InterestedWindow T "Deleting cards: 1 out of " 
                                                 FinalNumToDelete " ..."))
                             (for Card in CardsToDelete as i from 1 eachtime (BLOCK)
                                do (OR QuietFlg
                                       (if (ZEROP (REMAINDER i 10))
                                           then (NC.PrintMsg InterestedWindow T "Deleting cards: " i 
                                                       " out of " FinalNumToDelete " ...")))
                                   (NC.DeleteNoteCardInternal Card QuietFlg InterestedWindow T))
                             (OR QuietFlg (NC.ClearMsg InterestedWindow T)))
                    CardIdentifiers])

(NC.UnfileNoteCard
  [LAMBDA (WindowOrTextStream)                               (* Randy.Gobbel " 2-Apr-87 15:38")
          
          (* Take a notecard out of a file box. Called fom title bar menu.)
          
          (* * fgh |11/12/85| Updated to handle Card objects.)
          
          (* * fgh |6/9/86| Added code to check to make sure that another operation is 
          not in progress on this card when this fn is called.)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rht 2/2/87%: Fixed bug |#418:| Trashed all the stuff about opening 
          PropListEditor on the fromlinks. Now just uses SelectNoteCards to choose the 
          fileboxes to delete from.)
          
          (* * rg |3/4/87| rewritten for new NC.ProtectedCardOperation)
          
          (* * rg |3/18/87| added NC.CardSelectionOperation wrapper)
          
          (* * RG |4/2/87| changed NC.CardSelectionOperation to NCP.WithLockedCards)

    (DECLARE (GLOBALVARS NC.SelectingParentsMenu))
    (NCP.WithLockedCards (LET ((Card (NC.CoerceToCard WindowOrTextStream)))
                              (NC.ProtectedCardOperation
                               Card "Unfile" NIL
                               (LET* [(FromLinks (NC.FetchFromLinks Card))
                                      (Parents (for FromLink in FromLinks
                                                  when (FMEMB (fetch (Link Label) of FromLink)
                                                              '(FiledCard SubBox))
                                                  collect (fetch (Link SourceCard) of FromLink]
                                     (for Box in (NC.SelectNoteCards NIL [FUNCTION (LAMBDA (Box)
                                                                                     (AND
                                                                                      (NC.FileBoxP
                                                                                       Box)
                                                                                      (FMEMB Box 
                                                                                             Parents]
                                                        NC.SelectingParentsMenu Card 
                              "Please shift-select the file box(es) from which to remove this card. "
                                                        )
                                        do (for FromLink in FromLinks
                                              when (NC.SameCardP Box (fetch (Link SourceCard)
                                                                        of FromLink))
                                              do (NC.DeleteLink FromLink T])
)



(* ;; "changes to NCBROWSERCARD")

(DEFINEQ

(NC.MakeBrowserCard
  [LAMBDA (Card Title NoDisplayFlg ParamList)                (* rht%: " 4-Jun-87 11:49")
          
          (* Make a browser card with id Card using root at RootID and the link following 
          predictae specified by Predicate. IF Root and/or ListOfLinkLabels not 
          specified, ask the user.)
          
          (* * rht 8/3/84%: Changed to call NC.AskLinkLabel with its ReverseLinkLabel 
          parameter set to T.)
          
          (* * fgh |10/2/84| Changed Link Icons to be image objects in NodeLabel of Graph 
          Npodes rather than annotations on graph nodes.)
          
          (* * rht 10/19/84%: Fixed setting up of browser card's prop list in case 
          NoDisplayFlg is T so we have no Window. Now NC.MakeLinksLegend returns the 
          label pairs.)
          
          (* * rht 11/27/84%: Removed the WINDOWADDPROP call to put NC.GraphCardCloseFn 
          on the CLOSEFN of the window. This causes trouble.
          NC.QuitCard will get put on by NC.MakeNoteCard and that's enough.)
          
          (* * rht 1/3/85%: Now puts a dummy region of the right size if the NoDisplayFlg 
          is on.)
          
          (* * rht 1/15/85%: Put hooks for AddNode, AddLink, etc.
          so editing graph edits underlying structure.)
          
          (* * rht 2/14/85%: Added VerticalFlg and made BrowserSpecs get put on browser's 
          proplist in all cases.)
          
          (* * rht 4/1/85%: Now calls NC.AskBrowserSpecs with additional Don'tAskFlg in 
          case of call from Programmer's interface.)
          
          (* * rht 11/17/85%: Updated to handle new card and notefile objects.)
          
          (* * rht 2/7/86%: Now gets browser format, etc.
          via fetch/set fns.)
          
          (* * rht 5/6/86%: Took out call to NC.SetupTitleBarMenu.)
          
          (* * rht 5/8/86%: Added calls to rig title bar properly.)
          
          (* * rht 7/10/86%: Now passes ListOfLinkLabels to NC.AskBrowserSpecs.)
          
          (* * rht 9/19/86%: Mod to above fix. Now calls NC.MakeNewCardWindow a new fn 
          that creates window and hangs Card off windowprop.)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection. Also added GLOBALVARS statement.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rht 12/16/86%: Now checks that NC.MakeLink succeeded before creating a 
          real link icon. If not, then make a standin for a cross file link icon.)
          
          (* * rg |3/18/87| added NC.CardSelectionOperation wrapper)
          
          (* * rht 3/20/87%: Removed needless call to NC.ActivateCard.)
          
          (* * rg |4/2/87| changed wrapper to NCP.WithLockedCards and added 
          NC.IfAllCardsFree wrapper)
          
          (* * rht 5/26/87%: Now handles cross-file links properly, i.e.
          uses cross-file link standin in cases when GrowLinkLattice wasn't able to 
          follow into the remote notefile.)

    (DECLARE (GLOBALVARS NC.SubBoxLinkLabel NC.BrowserContentsLinkLabel NC.SpecialBrowserSpecsFlg 
                    NC.*Graph*BrowserFormat NC.SelectingBrowserSourceMenu))
    (NCP.WithLockedCards
     (PROG ([RootCards (MKLIST (LISTGET ParamList 'ROOTCARDS]
            (ListOfLinkLabels (LISTGET ParamList 'LINKTYPES))
            (BrowserFormat (LISTGET ParamList 'FORMAT))
            (Depth (LISTGET ParamList 'DEPTH))
            (CardType (NC.RetrieveType Card))
            Lattice RootNodes Window Graph SpecialBrowserSpecs BrowserSpecs DropVirtualNodesFlg)
           (NC.IfAllCardsFree
            (NC.LockListOfCards RootCards "Make Browser Card")
            [COND
               ((NULL NoDisplayFlg)
                (SETQ Window (NC.MakeNewCardWindow Card (OR Title "Untitled")))
                (WINDOWADDPROP Window 'SHRINKFN (FUNCTION NC.GraphCardShrinkFn]
            [if (NULL RootCards)
                then (SETQ RootCards (if NoDisplayFlg
                                         then (LIST NIL)
                                       else (NC.SelectNoteCards NIL NIL NC.SelectingBrowserSourceMenu 
                                                   Window 
                          "Please shift-select the Cards and/or Boxes the browser should start from." 
                                                   T]
            (COND
               ((EQ RootCards 'DON'T)
                (NC.DeactivateCard Card)
                (CLOSEW Window)
                (RETURN)))
            (NC.HoldTTYProcess)
            [SETQ BrowserSpecs (NC.AskBrowserSpecs Window Card ListOfLinkLabels Depth BrowserFormat T
                                      (if (OR ParamList NoDisplayFlg)
                                          then 'DONTASK]
            (COND
               ((NULL BrowserSpecs)
                (NC.DeactivateCard Card)
                (CLOSEW Window)
                (RETURN)))
            (SETQ ListOfLinkLabels (CAR BrowserSpecs))
            (SETQ Depth (CADR BrowserSpecs))
            (SETQ BrowserFormat (CADDR BrowserSpecs))
          
          (* If user wants *GRAPH* format, i.e. virtual nodes eliminated, then set the 
          flag)

            (if (FMEMB NC.*Graph*BrowserFormat BrowserFormat)
                then (SETQ DropVirtualNodesFlg T))
            [SETQ SpecialBrowserSpecs (COND
                                         (NC.SpecialBrowserSpecsFlg (NC.AskSpecialBrowserSpecs Window
                                                                           ))
                                         (T (create SPECIALBROWSERSPECS]
            (OR NoDisplayFlg (NC.PrintMsg Window T (CHARACTER 13)
                                    "Computing browser graph. Please wait. ..."))
                                                             (* Create new browser hash array)
            (NC.GetBrowserHashArray Card)                    (* Compute lattice breakdth-first 
                                                             starting from roots.)
            (SETQ Lattice (NC.GrowLinkLattice RootCards NIL ListOfLinkLabels Card Depth))
            (SETQ RootNodes (for RootCard in RootCards collect (NC.GetBrowserNodeID Card RootCard)))
            (OR NoDisplayFlg (WINDOWPROP Window 'NoteCardObject Card))
          
          (* * Link destination id information stored in NodeLabel field into a LinkIcon 
          for display)

            (for Node in Lattice bind NodeID (CrossFileLinkModePropList ← (LIST (fetch (Card NoteFile
                                                                                             )
                                                                                   of Card)
                                                                                NIL))
               eachtime (BLOCK)
               do [replace (GRAPHNODE NODELABEL) of Node
                     with (LET (NewLink)
                               (if [AND (NOT (NC.CrossFileLinkCardP (fetch (GRAPHNODE NODELABEL)
                                                                       of Node)))
                                        (SETQ NewLink (NC.MakeLink Window NC.BrowserContentsLinkLabel
                                                             (fetch (GRAPHNODE NODELABEL)
                                                                of Node)
                                                             Card NIL NIL NIL NIL NIL
                                                             (NC.ComputeCrossFileLinkMode
                                                              (fetch (GRAPHNODE NODELABEL)
                                                                 of Node)
                                                              CrossFileLinkModePropList Window]
                                   then (NC.MakeLinkIcon NewLink)
                                 else (NC.MakeCrossFileLinkIconStandIn (fetch (GRAPHNODE NODELABEL)
                                                                          of Node] 
          
          (* Untouch each graph node so that next Recompute will put fresh values on 
          proplist.)

                  (SETQ NodeID (fetch (GRAPHNODE NODEID) of Node))
                  (NC.GraphNodeIDRemProp (NC.CoerceToGraphNodeID NodeID)
                         'TouchedFlg)
                  (NC.GraphNodeIDRemProp (NC.CoerceToGraphNodeID NodeID)
                         'VisitedFlg))
            (SETQ Graph (if (AND Lattice RootNodes)
                            then (LAYOUTGRAPH Lattice RootNodes (SUBST 'LATTICE 
                                                                       NC.*Graph*BrowserFormat 
                                                                       BrowserFormat)
                                        (fetch (SPECIALBROWSERSPECS Font) of SpecialBrowserSpecs)
                                        (fetch (SPECIALBROWSERSPECS MotherD) of SpecialBrowserSpecs)
                                        (fetch (SPECIALBROWSERSPECS PersonalD) of SpecialBrowserSpecs
                                               )
                                        (fetch (SPECIALBROWSERSPECS FamilyD) of SpecialBrowserSpecs))
                          else (create GRAPH)))
            (NC.SetBrowserLinksLegend Card (NC.MakeLinksLegend Graph Window DropVirtualNodesFlg))
            (OR NoDisplayFlg (NC.PrintMsg Window NIL "Done!"))
            (NC.SetSubstance Card Graph)
            (NC.SetBrowserLinkLabels Card (OR ListOfLinkLabels (LIST NC.SubBoxLinkLabel)))
            (NC.SetBrowserRoots Card RootCards)
            (NC.SetBrowserFormat Card BrowserFormat)
            (NC.SetBrowserDepth Card Depth)
            (NC.SetSpecialBrowserSpecs Card SpecialBrowserSpecs)
            (COND
               (NoDisplayFlg (RETURN Card)))
            (WINDOWPROP Window 'GRAPH Graph)
            (NC.InstallTitleBarLeftMenu Window CardType)
            (NC.InstallTitleBarMiddleMenu Window CardType)
            (NC.RelayoutBrowserCard Window)
            (RETURN Window])

(NC.UpdateBrowserCard
  [LAMBDA (Window)                                           (* rht%: " 4-Jun-87 11:50")
          
          (* * rht 10/14/84%: Added call to DETACHALLWINDOWS to close any existing links 
          legend window and prompt window. Also added call to NC.MakeLinksLegend to make 
          a new attached legend menu.)
          
          (* * rht 1/15/85%: Put hooks for AddNode, AddLink, etc.
          so editing graph edits underlying structure.)
          
          (* * rht 2/14/85%: Added ability to respecify roots and link labels before 
          recomputing graph.)
          
          (* * rht 3/8/85%: Modified to use new browser props stored on card's proplist 
          as of release |1.2.|)
          
          (* * rht 3/17/85%: Now takes OnlyLayoutFlg argument.
          If set, then don't recompute lattice or ask about root nodes.)
          
          (* * rht 11/17/85%: updated to handle new card and notefile objects.)
          
          (* * kirk 23Jan86 Changed to use NC.AskYesOrNo)
          
          (* * rht 2/7/86%: Now gets and sets browser format, etc.
          via fetch/set fns.)
          
          (* * rht 3/7/86%: Now only closes the Links legend menu attached window.)
          
          (* * rht 6/10/86%: Moved code to delete links legend menu and code to make new 
          browser hash array to after questioning user about respecifying roots.)
          
          (* * rht 11/1/86%: Added NC.ProtectedCardOperation wrapper and check for ops in 
          progress.)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rht 12/16/86%: Now checks that NC.MakeLink succeeded before creating a 
          real link icon. If not, then make a standin for a cross file link icon.)
          
          (* * rg |3/4/87| rewritten for new version of NC.ProtectedCardOperation, 
          removed DontCheckOpInProgressFlg)
          
          (* * rg |3/18/87| added NC.CardSelectionOperation wrapper)
          
          (* * rht 3/19/87%: Fixed the part that calls NC.MakeLink so it really only 
          rebuilds links if they've changed.)
          
          (* * rg |4/1/87| changed CANCELLED to DON'T)
          
          (* * rht 5/26/87%: Now handles cross-file links properly, i.e.
          uses cross-file link standin in cases when GrowLinkLattice wasn't able to 
          follow into the remote notefile.)

    (LET
     ((Card (NC.CoerceToCard Window)))
     (NC.ProtectedCardOperation
      Card "Recompute Browser Card" NIL
      (NCP.WithLockedCards
       (PROG (LinkLabels RootCards RootNodes Lattice LinkIcon Graph GraphNodes NodeLabel BrowserSpecs 
                    BrowserFormat DropVirtualNodesFlg Depth SpecialBrowserSpecs OldLabelNodes 
                    OldRootCards)
             (SETQ RootCards (NC.FetchBrowserRoots Card))
             (NC.IfAllCardsFree
              (NC.LockListOfCards RootCards "Update Browser Card")
              (SETQ LinkLabels (NC.FetchBrowserLinkLabels Card))
              [SETQ BrowserFormat (OR (NC.FetchBrowserFormat Card)
                                      '(LATTICE]
          
          (* If user wants *GRAPH* format, i.e. virtual nodes eliminated, then set the 
          flag)

              (if (FMEMB NC.*Graph*BrowserFormat BrowserFormat)
                  then (SETQ DropVirtualNodesFlg T))
              (SETQ Depth (OR (NC.FetchBrowserDepth Card)
                              999999))
              (SETQ SpecialBrowserSpecs (OR (NC.FetchSpecialBrowserSpecs Card)
                                            (create SPECIALBROWSERSPECS)))
              [SETQ GraphNodes (fetch (GRAPH GRAPHNODES) of (SETQ Graph (WINDOWPROP Window
                                                                               'GRAPH]
                                                             (* Get new roots.)
              [if (OR (NULL RootCards)
                      (NC.AskYesOrNo "Want to respecify roots? " "--" "No" T Window T NIL))
                  then (NC.BrowserFlipRoots Window Card GraphNodes (SETQ OldRootCards RootCards))
                       (SETQ RootCards (NC.SelectNoteCards NIL NIL NC.SelectingBrowserSourceMenu 
                                              Window (CONCAT 
                          "Please shift-select the Cards and/or Boxes the browser should start from."
                                                            (CHARACTER 13)
                                                            "(Current roots are highlighted.)")
                                              T))
                       (NC.BrowserFlipRoots Window Card GraphNodes OldRootCards)
                       (COND
                          ((EQ RootCards 'DON'T)
                           (RETURN]                          (* Get rid of the links legend menu 
                                                             attached window.)
              (for Win in (ATTACHEDWINDOWS Window) when (WINDOWPROP Win 'LINKSLEGENDWINP)
                 do (DETACHWINDOW Win)
                    (CLOSEW Win))
          
          (* Smash the current hash array, putting a fresh one in its place.)

              (NC.GetBrowserHashArray Card)
              (NC.PrintMsg Window T (CHARACTER 13)
                     "Computing browser graph. Please wait. ...")
                                                             (* Compute lattice breadth-first from 
                                                             the roots.)
              (SETQ Lattice (NC.GrowLinkLattice RootCards NIL LinkLabels Card Depth))
              (SETQ RootNodes (for RootCard in RootCards collect (NC.GetBrowserNodeID Card RootCard))
               )
              (NC.SetPropListDirtyFlg Card T)
          
          (* Remove all links that are in the old browser graph but not in the new one)

              [for Node in GraphNodes eachtime (BLOCK)
                 unless [for LatticeNode in Lattice bind (CardForNode ← (NC.CardFromBrowserNodeID
                                                                         (NC.CoerceToGraphNodeID
                                                                          Node)))
                           thereis (NC.SameCardP CardForNode (NC.CardFromBrowserNodeID (
                                                                               NC.CoerceToGraphNodeID
                                                                                        LatticeNode]
                 do (LET ((NodeLabel (fetch (GRAPHNODE NODELABEL) of Node)))
                         (COND
                            ((NC.LinkIconImageObjP NodeLabel)
                             (NC.DeleteLink (NC.FetchLinkFromLinkIcon NodeLabel)
                                    T T))
                            ((STRINGP NodeLabel)             (* Collect the label nodes from the 
                                                             old browser.)
                             (SETQ OldLabelNodes (CONS Node OldLabelNodes]
          
          (* Create Links for all nodes in the new browser graph but not in the old one.)

              [for Node in Lattice eachtime (BLOCK) bind (CrossFileLinkModePropList
                                                          ←
                                                          (LIST (fetch (Card NoteFile) of Card)
                                                                NIL))
                 do
                 (LET
                  [(NodeID (fetch (GRAPHNODE NODEID) of Node))
                   (OldNode (for GraphNode in GraphNodes bind (CardForNode ← (
                                                                             NC.CardFromBrowserNodeID
                                                                              (NC.CoerceToGraphNodeID
                                                                               Node)))
                               when (NC.SameCardP CardForNode (NC.CardFromBrowserNodeID (
                                                                               NC.CoerceToGraphNodeID
                                                                                         GraphNode)))
                               do (RETURN GraphNode]
                  [if OldNode
                      then (replace (GRAPHNODE NODELABEL) of Node with (fetch (GRAPHNODE NODELABEL)
                                                                          of OldNode))
                    else (replace (GRAPHNODE NODELABEL) of Node
                            with (LET (NewLink)
                                      (if [AND (NOT (NC.CrossFileLinkCardP (fetch (GRAPHNODE 
                                                                                         NODELABEL)
                                                                              of Node)))
                                               (SETQ NewLink (NC.MakeLink Window 
                                                                    NC.BrowserContentsLinkLabel
                                                                    (fetch (GRAPHNODE NODELABEL)
                                                                       of Node)
                                                                    Card NIL NIL NIL NIL NIL
                                                                    (NC.ComputeCrossFileLinkMode
                                                                     (fetch (GRAPHNODE NODELABEL)
                                                                        of Node)
                                                                     CrossFileLinkModePropList Window
                                                                     ]
                                          then (NC.MakeLinkIcon NewLink)
                                        else (NC.MakeCrossFileLinkIconStandIn (fetch (GRAPHNODE
                                                                                      NODELABEL)
                                                                                 of Node]
          
          (* Untouch each graph node so that next Recompute will put fresh values on 
          proplist.)

                  (NC.GraphNodeIDRemProp NodeID 'TouchedFlg)
                  (NC.GraphNodeIDRemProp NodeID 'VisitedFlg] (* Throw in the label nodes from the 
                                                             old browser.)
              (SETQ Lattice (NCONC Lattice OldLabelNodes))
          
          (* For each old label node, take away nonexistent fromnodes and save the label 
          nodes that no longer have any from nodes.)

              (for OldLabelNode in OldLabelNodes eachtime (BLOCK)
                 do (replace (GRAPHNODE FROMNODES) of OldLabelNode
                       with (for FromNodeID in (fetch (GRAPHNODE FROMNODES) of OldLabelNode)
                               bind FromNode eachtime (BLOCK) when (SETQ FromNode (FASSOC FromNodeID 
                                                                                         Lattice))
                               collect 
          
          (* If the From node isn't a label node, then add to its Tonode list.)

                                     [if (NC.LinkIconImageObjP (fetch (GRAPHNODE NODELABEL)
                                                                  of FromNode))
                                         then (replace (GRAPHNODE TONODES) of FromNode
                                                 with (CONS (fetch (GRAPHNODE NODEID) of OldLabelNode
                                                                   )
                                                            (fetch (GRAPHNODE TONODES) of FromNode]
                                     FromNodeID)) 
          
          (* For the old label node's ToNodes, just need to remove any for ToNodes that 
          no longer exist.)

                    (replace (GRAPHNODE TONODES) of OldLabelNode
                       with (for ToNodeID in (fetch (GRAPHNODE TONODES) of OldLabelNode) bind ToNode
                               eachtime (BLOCK) when (SETQ ToNode (FASSOC ToNodeID Lattice))
                               collect 
          
          (* If the To node isn't a label node, then add to its FromNode list.)

                                     [if (NC.LinkIconImageObjP (fetch (GRAPHNODE NODELABEL)
                                                                  of ToNode))
                                         then (replace (GRAPHNODE FROMNODES) of ToNode
                                                 with (CONS (fetch (GRAPHNODE NODEID) of OldLabelNode
                                                                   )
                                                            (fetch (GRAPHNODE FROMNODES) of ToNode]
                                     ToNodeID)))
          
          (* Layout graph, including as roots any non-virtual nodes with no from nodes to 
          avoid disconnected graphs.)

              (SETQ Graph (if (AND Lattice RootNodes)
                              then (LAYOUTGRAPH Lattice
                                          (for Node in Lattice bind NodeID
                                             eachtime (BLOCK)
                                                   (SETQ NodeID (OR (NC.CoerceToGraphNodeID Node)
                                                                    (fetch (GRAPHNODE NODEID)
                                                                       of Node)))
                                             when (OR (FMEMB NodeID RootNodes)
                                                      (NULL (fetch (GRAPHNODE FROMNODES) of Node)))
                                             collect NodeID)
                                          (SUBST 'LATTICE NC.*Graph*BrowserFormat BrowserFormat)
                                          (fetch (SPECIALBROWSERSPECS Font) of SpecialBrowserSpecs)
                                          (fetch (SPECIALBROWSERSPECS MotherD) of SpecialBrowserSpecs
                                                 )
                                          (fetch (SPECIALBROWSERSPECS PersonalD) of 
                                                                                  SpecialBrowserSpecs
                                                 )
                                          (fetch (SPECIALBROWSERSPECS FamilyD) of SpecialBrowserSpecs
                                                 ))
                            else (create GRAPH)))
          
          (* Build links legend and fix up TONODES in the graph.)

              (NC.SetBrowserLinksLegend Card (NC.MakeLinksLegend Graph Window DropVirtualNodesFlg))
              (NC.SetBrowserRoots Card RootCards)
              (NC.SetBrowserDepth Card Depth)
              (WINDOWPROP Window 'GRAPH Graph)
              (NC.RelayoutBrowserCard Window])

(NC.BrowserAddNode
  [LAMBDA (Graph Window)                                     (* Randy.Gobbel " 2-Apr-87 15:38")
          
          (* * Called by grapher when user creates a new node.
          Returns new node or nil.)
          
          (* * rht 11/17/85%: updated to handle new card and notefile formats.)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection. Also added GLOBALVARS statement.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rg |3/18/87| added NC.ProtectedCardOperation and NC.CardSelectionOperation 
          wrappers)
          
          (* * rg |4/2/87| changed NC.CardSelectionOperation to NCP.WithLockedCards)

    (DECLARE (GLOBALVARS NC.BrowserContentsLinkLabel))
    (NC.ProtectedCardOperation (NC.CoerceToCard Window)
           "Add Node" Window (NCP.WithLockedCards
                              (PROG ((GraphCard (NC.CoerceToCard Window))
                                     Link GraphNodeID Card)
          
          (* Get user to select an existing card. Not allowed to create a new one.)

                                    (SETQ Card (NC.SelectNoteCards T
                                                      [FUNCTION (LAMBDA (SelectedCard)
                                                                  (COND
                                                                     ((NOT (NC.SameCardP SelectedCard 
                                                                                  GraphCard))
                                                                      T)
                                                                     (T (NC.PrintMsg Window T 
                                                                  "The browser can't link to itself."
                                                                               (CHARACTER 13)
                                                                               "Selection ignored."
                                                                               (CHARACTER 13))
                                                                        NIL]
                                                      NC.SelectingCardMenu GraphCard 
                                                  "Shift-select a card or box to include in browser."
                                                      ))
                                    (if (NULL Card)
                                        then (RETURN NIL))   (* Make link from browser to new card.)
                                    (SETQ Link (NC.MakeLink Window NC.BrowserContentsLinkLabel Card 
                                                      GraphCard NIL NIL NIL T))
          
          (* Check that it doesn't already exist. If not, create a browser node.)

                                    (COND
                                       (Link                 (* Create hash array if haven't 
                                                             already.)
                                             (NC.GetBrowserHashArray GraphCard Graph)
                                             [SETQ GraphNodeID (NC.GetBrowserNodeID
                                                                GraphCard
                                                                (SETQ Card (fetch (Link 
                                                                                      DestinationCard
                                                                                        )
                                                                              of Link]
                                             (COND
                                                ((for Node in (fetch (GRAPH GRAPHNODES) of Graph)
                                                    thereis (EQ GraphNodeID (NC.CoerceToGraphNodeID
                                                                             Node)))
                                                 (NC.PrintMsg Window T "Node for card '" (
                                                                                     NC.RetrieveTitle
                                                                                          Card)
                                                        "' already in graph.")
                                                 (NCP.DeleteLinks Link)
                                                 (RETURN NIL)))
                                             (NC.MarkCardDirty GraphCard)
                                             (RETURN (NODECREATE GraphNodeID (NC.MakeLinkIcon Link)
                                                            (CURSORPOSITION NIL Window])
)



(* ;; "changes to NCFILEBOXCARD")

(DEFINEQ

(NC.FileBoxCollectChildren
  [LAMBDA (WindowOrTextStream Card NewChildren NoDisplayFlg) (* Randy.Gobbel " 2-Apr-87 15:38")
          
          (* * Ask user for new children (either cards or fileboxes) for this filebox.
          Check to make sure that no circularities are introduced.
          This code is sort of the inverse of the NC.AddParents code and thus looks quite 
          similar.)
          
          (* * rht 10/29/84%: Added NoDisplayFlg to prevent error message when no 
          appropriate elements exist. Also now returns ID if at least one child was 
          added, NIL otherwise.)
          
          (* * fgh |11/13/85| Updated to handle Card object.)
          
          (* * rht 7/5/86%: Now checks for readonly cards.)
          
          (* * rht 8/11/86%: Added code to check to make sure that another operation is 
          not in progress on this card when this fn is called.)
          
          (* * rht 10/17/86%: Made successful filing operations NOT do dismiss.)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rht 1/28/87%: Now activates parent box if necessary and saves before 
          deactivating.)
          
          (* * rg |3/4/87| rewritten for new version of NC.ProtectedCardOperation)
          
          (* * rg |3/18/87| added NC.CardSelectionOperation wrapper)

    (OR Card (SETQ Card (NC.CoerceToCard WindowOrTextStream)))
    (NC.ProtectedCardOperation
     Card "Put Cards Here" NIL
     (NCP.WithLockedCards (LET ((Window (NC.FetchWindow Card)))
                               (if (NC.CheckForNotReadOnly Card Window "Can't do filing in ")
                                   then (OR NewChildren (SETQ NewChildren
                                                         (NC.SelectNoteCards NIL NIL 
                                                                NC.SelectingFileBoxChildrenMenu Card 
                                                                " Please shift-select new children.")
                                                         ))
                                        (COND
                                           ([AND NewChildren Card
                                                 (LET ((WasActiveFlg (NC.ActiveCardP Card)))
                                                      (OR WasActiveFlg (NC.GetNoteCard Card))
                                                      (PROG1 (for NewChild in NewChildren
                                                                bind OneHook
                                                                when (NC.MakeChildLink NewChild Card 
                                                                            Window)
                                                                do (SETQ OneHook T)
                                                                finally (RETURN OneHook))
                                                             (OR WasActiveFlg
                                                                 (NC.QuitCard Card NIL NIL NIL NIL 
                                                                        NIL T]
                                            Card)
                                           ((NULL NoDisplayFlg)
                                            (NC.PrintMsg Window NIL 
                                                   "No appropriate NoteCards or FileBoxes chosen."
                                                   (CHARACTER 13)
                                                   "Hence no children added."
                                                   (CHARACTER 13))
                                            (DISMISS 1000)
                                            (NC.ClearMsg Window T)
                                            NIL)
                                           (T NIL])
)



(* ;; "changes to NCPROGINT")

(DEFINEQ

(NCP.CloseCards
  [LAMBDA (Cards QuietFlg)                                   (* Randy.Gobbel " 2-Apr-87 16:59")
          
          (* * Uncache and undisplay any active cards in Cards)
          
          (* * rht 11/16/86%: Changed call to NCP.ReportError)
          
          (* * rht 3/9/87%: Fixed so that wouldn't try to get PROCESS windowprop from NIL 
          Win.)
          
          (* * rg |3/9/87| fixed args to NC.QuitCard ;
          added NC.ProtectedSessionOperation wrapper)
          
          (* * rg |4/2/87| changed NC.ProtectedSessionOperation to NCP.WithLockedCards ;
          added NC.IfAllCardsFree wrapper)

    (NCP.WithLockedCards
     (NC.IfAllCardsFree (NC.LockListOfCards (MKLIST Cards)
                               "Close Cards")
            (for Card in (MKLIST Cards) bind Win (OldProc ← (TTY.PROCESS))
               do (if (NOT (NC.ValidCardP Card))
                      then (NCP.ReportError "NCP.CloseCards" (CONCAT Card 
                                                                  " not an existing card or filebox."
                                                                    ))
                    elseif (AND (NCP.CardCachedP Card)
                                (NEQ (NC.QuitCard Card T NIL NIL NIL NIL QuietFlg)
                                     'CANCELLED)
                                (SETQ Win (NC.FetchWindow Card)))
                      then (bind [Process ← (AND Win (WINDOWPROP Win 'PROCESS]
                              until (OR (NULL Process)
                                        (PROCESS.FINISHEDP Process)) do (BLOCK)))
               finally (AND (PROCESSP OldProc)
                            (TTY.PROCESS OldProc))
                     (RETURN Card])

(NCP.SelectCards
  [LAMBDA (InstigatingCardOrWindow SingleCardFlg SelectionPredicate Msg CheckForCancelFlg)
                                                             (* Randy.Gobbel " 2-Apr-87 15:38")
          
          (* * Return a list of cards selected. A menu pops up near the prompt window 
          with "DONE" and "CANCEL" buttons. User selects by clicking in card's title bar.)
          
          (* * rht 11/18/85%: Updated to handle new notefile and card object formats.
          Now takes optional extra args and passes to NC.SelectNoteCards.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rht 3/2/87%: Fix to bug |#342:| Now makes sure instigating card is 
          displayed, else passes NIL to NC.SelectNoteCards.)
          
          (* * rg |4/2/87| added NCP.WithLockedCards wrapper)

    (NCP.WithLockedCards (NC.SelectNoteCards SingleCardFlg SelectionPredicate
                                (if SingleCardFlg
                                    then NC.SelectingCardMenu
                                  else NC.SelectingCardsMenu)
                                (COND
                                   ((OPENWP InstigatingCardOrWindow)
                                    InstigatingCardOrWindow)
                                   ((AND (NCP.ValidCardP InstigatingCardOrWindow)
                                         (NCP.CardDisplayedP InstigatingCardOrWindow))
                                    InstigatingCardOrWindow)
                                   (T NIL))
                                Msg CheckForCancelFlg])
)



(* ;; "changes to NCDOCUMENTCARD")

(DEFINEQ

(NC.MakeDocument
  [LAMBDA (Card Title NoDisplayFlg CardIdentifier)           (* rht%: " 4-Jun-87 12:14")
          
          (* * Called from a filebox's title bar. Makes a document by smashing all the 
          descendant cards's text together. Ask user if wants numbered section headings 
          and titles. The former are made from FileBox titles, the latter from notecard 
          titles. Delete embedded links at the end if the user desires.)
          
          (* * rht 10/22/84%: Hacked to be callable from Programmer's interface.)
          
          (* * rht 11/17/84%: Checks for cancel when choosing rootID and also when 
          setting parameters.)
          
          (* * rht 8/25/85%: Now dumps sketch and graph cards as well as text cards.)
          
          (* * rht 9/16/85%: Now handles cr's around titles using para leading.)
          
          (* * fgh |11/178/85| Updated to handle Card and NoteFile objects.)
          
          (* * kirk 27Jun86 Moved NC.RetrieveTitle call so does not break when user 
          Cancels)
          
          (* * rht 7/31/86%: Now checks for card types having ExportSubstanceFn prop.)
          
          (* * kirk |8/22/86| Fix of free use of NoteFile var)
          
          (* * rht 10/15/86%: Integrated markM's changes and fixed box numbering.)
          
          (* * rht 11/17/86%: Now calls NC.ApplySupersFn rather than NC.MakeNoteCard.)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rg |3/16/87| NC.DeleteNoteCards -> NC.DeleteNoteCard)
          
          (* * rg |3/18/87| added NC.CardSelectionOperation wrapper.
          Still needs ProtectedCardOperation wrapper!)
          
          (* * rg |4/2/87| changed NC.CardSelectionOperation to NCP.WithLockedCards)
          
          (* * rht 4/17/87%: No longer bugs user for confirm of delete when cancel'ing.)
          
          (* * rht 6/4/87%: Now stashes on doc card a prop list of destination notefiles 
          of cross-file links encountered during creation of contents.)

    (NCP.WithLockedCards (PROG (RootCard RootTitle DocWindow DocCard DocWindowOrCard DocStream 
                                      HeadingsFromFileboxes TitlesFromNoteCards BuildBackLinks 
                                      CopyEmbeddedLinks ExpandEmbeddedLinks InspectWin 
                                      RootSubstanceType)
                               (OR NoDisplayFlg (SPAWN.MOUSE))
                               (SETQ DocWindowOrCard (NC.ApplySupersFn MakeFn Card "Document" 
                                                            NoDisplayFlg))
                               (if NoDisplayFlg
                                   then (SETQ DocWindow NIL)
                                        (SETQ DocCard DocWindowOrCard)
                                 else (SETQ DocWindow DocWindowOrCard)
                                      (SETQ DocCard (NC.CoerceToCard DocWindow)))
          
          (* NC.MakeNoteCard either returned an Card or a window depending on 
          NoDisplayFlg.)

                               (SETQ RootCard (OR (NC.CoerceToCard CardIdentifier)
                                                  (NC.SelectNoteCards T NIL NC.SelectingCardMenu 
                                                         DocWindow 
                      "Please shift-select the Note Card or File Box the document should start from."
                                                         )))
                               (if (NOT RootCard)
                                   then (NC.DeleteNoteCard Card NIL T)
                                        (RETURN NIL))
                               (SETQ RootTitle (NC.RetrieveTitle RootCard))
                               (NC.SetTitle DocCard (CONCAT "Document from %"" RootTitle "%""))
                               (AND DocWindow (WINDOWPROP DocWindow 'TITLE (NC.RetrieveTitle DocCard)
                                                     ))
                               (SETQ DocStream (NC.FetchSubstance DocCard))
          
          (* * Get MakeDocument parameters from user via inspector window.)

                               (if (NOT NoDisplayFlg)
                                   then (SETQ InspectWin (NC.BuildMakeDocInspector DocWindow))
                                        (TOTOPW InspectWin)
                                        (for while (OPENWP InspectWin) do (BLOCK)))
                               (if (EQ (GETPROP 'NC.MakeDocParameters '--DONE--)
                                       'QUIT)
                                   then (PUTPROP 'NC.MakeDocParameters '--DONE-- '--CANCEL--)
                                        (NC.DeleteNoteCard Card NIL T)
                                        (RETURN NIL))
                               (SETQ HeadingsFromFileboxes (GETPROP 'NC.MakeDocParameters
                                                                  'HeadingsFromFileboxes))
                               (SETQ TitlesFromNoteCards (GETPROP 'NC.MakeDocParameters '
                                                                TitlesFromNoteCards))
                               (SETQ BuildBackLinks (GETPROP 'NC.MakeDocParameters 'BuildBackLinks))
                               (SETQ CopyEmbeddedLinks (GETPROP 'NC.MakeDocParameters '
                                                              CopyEmbeddedLinks))
                               (SETQ ExpandEmbeddedLinks (GETPROP 'NC.MakeDocParameters '
                                                                ExpandEmbeddedLinks))
          
          (* * Call recursive routine to dump filebox.)

                               (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
                                      (NC.PrintMsg DocWindow NIL 
                                             "Collecting text from descendant cards ... ")
          
          (* * Clean up the SeenBefore markers placed on the cards and boxes just copied.)

                                      [RESETSAVE NIL '(PROGN (for Card
                                                                in (NC.FetchUserDataProp DocCard
                                                                          'SeenCards)
                                                                do (NC.SetUserDataProp Card
                                                                          'SeenBefore NIL))
                                                             (NC.SetUserDataProp DocCard 'SeenCards 
                                                                    NIL]
                                                             (* Clean up the 
                                                             CrossFileLinkModePropList hung off the 
                                                             Doccard.)
                                      [RESETSAVE NIL '(PROGN (NC.SetUserDataProp DocCard '
                                                                    CrossFileLinkModePropList NIL]
          
          (* * Unbelievably kludgy hack to get around Intermezzo TEdit bug.
          Just insert and delete a CR.)

                                      (TEDIT.INSERT DocStream NC.CRString 1)
                                      (TEDIT.DELETE DocStream 1 1)
                                      (NC.SetUserDataProp DocCard 'CrossFileLinkModePropList
                                             (LIST (fetch (Card NoteFile) of DocCard)
                                                   NIL))
                                      (NC.DumpCardToDoc RootCard DocCard DocStream 0 0 
                                             HeadingsFromFileboxes TitlesFromNoteCards BuildBackLinks 
                                             CopyEmbeddedLinks ExpandEmbeddedLinks)
                                      (NC.PrintMsg DocWindow NIL "Done!"))
                               (COND
                                  ((NOT NoDisplayFlg)
                                   (BLOCK 250)
                                   (NC.ClearMsg DocWindow T)))
                               (RETURN DocWindowOrCard])
)



(* ;; "changes to NCDATABASE")

(DEFINEQ

(NC.CopyCards
  [LAMBDA (Cards DestNoteFileOrFileBox RootCards QuietFlg InterestedWindow CopyExternalToLinksMode)
                                                      (* ; "Edited 19-Jan-88 15:51 by Randy.Gobbel")
          
          (* * Create copies of cards in Cards. If DestNoteFileOrFileBox is a notefile, 
          then destination will be the contents box in that notefile, else the FileBox's 
          notefile. RootCards should be NIL or a subset of Cards.
          If NIL, then file all Cards in the dest filebox.
          Otherwise, just file RootCards in that filebox and assume others are linked 
          somehow to the RootCards. Links between cards in Cards are copied, but links 
          from or to outside cards aren't.)
          
          (* * Currently all Cards must be in same notefile, but this perhaps could be 
          relaxed if could prevent possibility of two cards in different notefiles having 
          the same UID.)
          
          (* * kirk 24Apr86 Added calls to select cards if none provided)
          
          (* * rht 9/2/86%: Added InterestedWindow arg.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rg |3/18/87| added NC.CardSelectionOperation wrapper)
          
          (* * rg |4/2/87| changed NC.CardSelectionOperation to NCP.WithLockedCards ;
          added NC.IfAllCardsFree wrapper)
          
          (* * rht&rg&pmi 4/22/87%: No longer calls ERROR!)
          
          (* * rg |6/2/87| was checking for CANCELLED instead of DON'T)
          
          (* * rg |6/5/87| deletes new cards if we cancel out halfway through)
          
          (* * rht 6/6/87%: Now optionally copies "external" links.
          Passes extra new args to NC.FixUpLinksInCardCopy.)
          
          (* * rht 6/22/87%: Now returns list of cards copied, like it used to.)
          
          (* * pmi 10/29/87%: Now returns list of card copies, instead of cards copied.)
          
          (* * pmi 12/10/87%: Now returns new cards in the same order as their 
          corresponding original cards. At dsj's suggestion
          (and implementation) (\, now) can pass (QUOTE NONE) as RootCards, meaning don't 
          file any of the new cards in the destination filebox.)

    (NCP.WithLockedCards
     (NC.IfAllCardsFree
      (NC.LockListOfCards Cards "Copy Cards")
      (PROG (NumCards SourceNoteFile DestNoteFile BoxToFileIn TempStream CardHashArray LinksHashArray 
                   CurrentLinkLabels NewLinkLabels NewCardsAndLocsOnStream CopyExternalToLinksFlg 
                   NewCardList)
          
          (* * Make sure the arguments are valid.)

            (if (NULL Cards)
                then (if (NULL (SETQ Cards (NC.SelectNoteCards NIL NIL NC.SelectingCardsMenu NIL 
                                                 "Shift-select from the same NoteFile cards to copy:" 
                                                  NIL)))
                         then (RETURN NIL)))
            (SETQ Cards (MKLIST Cards))
            (SETQ NumCards (LENGTH Cards))                   (* All Cards to copy must live in same 
                                                             notefile.)
            (SETQ SourceNoteFile (fetch (Card NoteFile) of (CAR Cards)))
            (if [NOT (AND (type? NoteFile SourceNoteFile)
                          (OPENP (fetch (NoteFile Stream) of SourceNoteFile]
                then (NC.ReportError "NC.CopyCards" (CONCAT (fetch (NoteFile FullFileName)
                                                               of SourceNoteFile)
                                                           " not an open notefile.")))
            (if (NOT (for Card in Cards always (NC.SameNoteFileP (fetch (Card NoteFile) of Card)
                                                      SourceNoteFile)))
                then (NC.ReportError "NC.CopyCards" 
                            "All cards in Cards arg don't live in the same notefile."))
                                                             (* Compute dest notefile and dest 
                                                             filebox.)
            (if (NOT DestNoteFileOrFileBox)
                then (if (EQ 'DON'T (SETQ DestNoteFileOrFileBox (NC.SelectNoteCards T NIL 
                                                                       NC.SelectingCardMenu NIL 
                                                   "Shift-select the FileBox to contain these cards." 
                                                                       T)))
                         then (RETURN NIL)))
            (if (type? NoteFile DestNoteFileOrFileBox)
                then (SETQ DestNoteFile DestNoteFileOrFileBox)
                     (SETQ BoxToFileIn (fetch (NoteFile TableOfContentsCard) of DestNoteFile))
              elseif (NCP.FileBoxP DestNoteFileOrFileBox)
                then (SETQ BoxToFileIn DestNoteFileOrFileBox)
                     (SETQ DestNoteFile (fetch (Card NoteFile) of BoxToFileIn))
              else (NC.ReportError "NC.CopyCards" (CONCAT "Arg not notefile or filebox: " 
                                                         DestNoteFileOrFileBox)))
            (if [NOT (AND (type? NoteFile DestNoteFile)
                          (OPENP (fetch (NoteFile Stream) of DestNoteFile]
                then (NC.ReportError "NC.CopyCards" (CONCAT (fetch (NoteFile FullFileName)
                                                               of DestNoteFile)
                                                           " not an open notefile.")))
            (if (LDIFFERENCE (SETQ RootCards (MKLIST RootCards))
                       Cards)
                then (NC.ReportError "NC.CopyCards" 
                            "RootCards argument not subset of Cards argument."))
            (if (NULL RootCards)
                then (SETQ RootCards Cards)
              elseif (EQ RootCards 'NONE)
                then (SETQ RootCards))
          
          (* * Figure out whether to copy "external" links.)

            [SETQ CopyExternalToLinksFlg (SELECTQ CopyExternalToLinksMode
                                             (COPY T)
                                             (DON'TCOPY NIL)
                                             (SELECTQ (NC.AskUserWithMenu '(Yes No Cancel)
                                                             (CONCAT "You've asked to copy "
                                                                    (LENGTH Cards)
                                                                    " cards."
                                                                    (CHARACTER 13)
                                                                    
                                              "Links among these cards will be automatically copied."
                                                                    (CHARACTER 13)
                                                                    
                            "Do you also want to copy links pointing from these cards to elsewhere? "
                                                                    )
                                                             InterestedWindow)
                                                 (Yes T)
                                                 (No NIL)
                                                 (RETURN NIL]
          
          (* * Now get to work.)

            (SETQ TempStream (OPENSTREAM '{NODIRCORE} 'BOTH))
            (SETQ CurrentLinkLabels (NC.RetrieveLinkLabels DestNoteFile))
            (SETQ NewLinkLabels (TCONC NIL))
            (SETQ LinksHashArray (HASHARRAY NC.CopyCardsLinksHashArraySize NIL (FUNCTION 
                                                                                NC.MakeHashKey)
                                        (FUNCTION NC.SameUIDP)))
            (SETQ CardHashArray (HASHARRAY NumCards NIL (FUNCTION NC.MakeHashKeyFromCard)
                                       (FUNCTION NC.SameCardP)))
          
          (* * Create new cards in DestNoteFile for each card.
          Make these cards by copying original cards to a temp stream.
          Keep track of UID mappings between original cards and card copies using 
          CardHashArray.)

            (OR QuietFlg (NC.PrintMsg InterestedWindow T "Copying cards: creating empty copies."
                                (CHARACTER 13)
                                "Processing item " 1 " out of " NumCards "..." (CHARACTER 13)))
            (SETQ NewCardsAndLocsOnStream NIL)
            [RESETLST [RESETSAVE NIL '(PROGN (if RESETSTATE
                                                 then (for CardAndLoc in NewCardsAndLocsOnStream
                                                         do (NC.DeleteNoteCardInternal (CAR 
                                                                                           CardAndLoc
                                                                                            )
                                                                   T InterestedWindow))
                                                      (NC.ClearMsg InterestedWindow T]
                   (for Card in Cards as i from 1 bind NewCard WasActiveFlg HadStatusNILFlg IndexLocs
                      eachtime (BLOCK) unless (NC.CrossFileLinkCardP Card)
                      do [OR QuietFlg (if (ZEROP (REMAINDER i 100))
                                          then (NC.PrintMsg InterestedWindow T 
                                                      "Copying cards: creating empty copies."
                                                      (CHARACTER 13)
                                                      "Processing item " i " out of " NumCards "..."
                                                      (CHARACTER 13]
                         (if (NOT (SETQ WasActiveFlg (NC.ActiveCardP Card)))
                             then (NC.GetNoteCard Card))
                         (if (SETQ HadStatusNILFlg (NULL (fetch (Card Status) of Card)))
                             then 
          
          (* Have to have Status slot ACTIVE in order that Put to stream won't break.)

                                  (replace (Card Status) of Card with 'ACTIVE))
                         (SETQ IndexLocs (NC.PutNoteCardToStream Card NIL T TempStream))
                         (if HadStatusNILFlg
                             then (replace (Card Status) of Card with NIL))
                         (if (NOT WasActiveFlg)
                             then (NC.DeactivateCard Card))  (* Make new empty card for copy.)
                         (SETQ NewCard (NC.GetNewCard DestNoteFile)) 
                                                             (* Map old cards to card copies.)
                         (PUTHASH Card NewCard CardHashArray)
                         (push NewCardsAndLocsOnStream (CONS NewCard IndexLocs]
          
          (* * For each card, get it off the temp stream, fix its links, fix browser info 
          if necessary, and write it down to the dest notefile.)

            (SETFILEPTR TempStream 0)
            (OR QuietFlg (NC.PrintMsg InterestedWindow T 
                                "Copying cards: fixing links and browser cards." (CHARACTER 13)
                                "Processing item " 1 " out of " NumCards "..." (CHARACTER 13)))
            (SETQ NewCardList)
            (for NewCardAndLocsOnStream in NewCardsAndLocsOnStream as i from 1 eachtime (BLOCK)
               bind (CrossFileLinkModePropList ← (LIST DestNoteFile NIL))
               do [OR QuietFlg (if (ZEROP (REMAINDER i 100))
                                   then (NC.PrintMsg InterestedWindow T 
                                               "Copying cards: fixing links and browser cards."
                                               (CHARACTER 13)
                                               "Processing item " i " out of " NumCards "..."
                                               (CHARACTER 13]
                  (LET ((NewCard (CAR NewCardAndLocsOnStream))
                        (IndexLocs (CDR NewCardAndLocsOnStream)))
          
          (* Have to make status active for Get fns to work.)

                       (NC.SetStatus NewCard 'ACTIVE)
                       (NC.GetNoteCardFromStream NewCard TempStream IndexLocs)
                       (NC.FixUpLinksInCardCopy NewCard CardHashArray LinksHashArray 
                              CurrentLinkLabels NewLinkLabels InterestedWindow CopyExternalToLinksFlg 
                              CrossFileLinkModePropList)
                       (if (NC.IsSubTypeOfP (NC.FetchType NewCard)
                                  'Browser)
                           then (NC.FixUpBrowserCardCopy NewCard CardHashArray))
                       (NC.PutNoteCard NewCard)
                       (push NewCardList NewCard)))
          
          (* * Link RootCards under filebox in DestNotefile.)

            (OR QuietFlg (NC.PrintMsg InterestedWindow T "Copying cards: filing " (LENGTH RootCards)
                                " new cards in "
                                (NC.FetchTitle BoxToFileIn)
                                "..."
                                (CHARACTER 13)))
            (AND RootCards (NC.FileBoxCollectChildren NIL BoxToFileIn (for RootCard in RootCards
                                                                         eachtime (BLOCK)
                                                                         collect (GETHASH RootCard 
                                                                                        CardHashArray
                                                                                        ))
                                  T))
          
          (* * Put out any new link labels to the dest notefile.)

            (AND (SETQ NewLinkLabels (CDAR NewLinkLabels))
                 (NC.StoreLinkLabels DestNoteFile (APPEND NewLinkLabels CurrentLinkLabels)))
            (OR QuietFlg (NC.ClearMsg InterestedWindow T))
            (RETURN NewCardList])

(NC.MoveCards
  [LAMBDA (Cards DestNoteFileOrFileBox RootCards QuietFlg InterestedWindow CopyExternalToLinksMode)
                                                             (* pmi%: "29-Oct-87 11:12")
          
          (* * Move cards into a filebox by copying and deleting.)
          
          (* * rht&rg&pmi 4/22/87%: Took out ERROR!)
          
          (* * rg |6/2/87| added NCP.WithLockedCards wrapper)
          
          (* * pmi 10/29/87%: Added CopyExternalToLinksMode argument to be passed down to 
          NC.CopyCards.)

    (DECLARE (GLOBALVARS NC.SelectingCardsMenu))
    (NCP.WithLockedCards (NC.IfAllCardsFree (NC.LockListOfCards Cards "Move Cards")
                                (OR Cards (SETQ Cards (NC.SelectNoteCards NIL NIL 
                                                             NC.SelectingCardsMenu NIL 
                                                 "Shift-select from the same NoteFile cards to move:"
                                                             )))
                                (if Cards
                                    then (SETQ Cards (MKLIST Cards))
                                         (NC.CopyCards Cards DestNoteFileOrFileBox RootCards QuietFlg 
                                                InterestedWindow CopyExternalToLinksMode)
                                         (NC.DeleteNoteCards Cards T NIL InterestedWindow QuietFlg 
                                                NIL])
)



(* ;; "changes to NCINTERFACE")

(DEFINEQ

(NC.SelectNoteCards
  [LAMBDA (SingleCardFlg SelectionPredicate Menu InstigatingCardOrWindow Msg CheckForCancelFlg 
                 FileLevelLockFlg)                    (* ; "Edited  1-Feb-88 17:43 by Randy.Gobbel")

(* ;;; "Select a set of note cards or a single note card, depending on SingleCardFlg.  Works by interpreting all mouse presses until a card has been chosen (if SingleCardFlg is T) or until the Done button has been pressed (if SingleCardFlg is NIL).  If the mouse press occus within a Title bar of a notecard, add that note card to the selected list.  Otherwise, if you are pointing into a note card, call the BUTTONEVENTFN for that note card.  The Selection in Progress flag has been set, so all note card BUTTONEVENTFNs should know to ignore all presses except those that occur on link icons.  Link icon presses should simply add the desination of that link to the selected note cards list.  This function should always be called from inside of an NC.CardSelectionOperation wrapper.")
          
          (* ;; "RG 4/1/87 changed CANCELLED to DON'T")
          
          (* ;; "rg 4/22/87 changed some names,")
          
          (* ;; "rht&rg&pmi 4/22/87: Moved location of ALLOW.BUTTON.EVENTS.")
          
          (* ;; "rg 6/2/87 added FileLevelLockFlg")
          
          (* ;; "rht 6/6/87: If user selects a cross-file link card, then try to follow it.")

    (DECLARE (USEDFREE CardListResetVar))
          
          (* ;; "if we are running under the mouse process, start up a new mouse process")

    (ALLOW.BUTTON.EVENTS)
    (LET
     (Window Card ButtonEventFn InstigatingWindow InstigatingCard InstigatingNoteFile MenuWindow 
            PromptWindow CopyInsertEvent CardProcessedEvent SelectedCards BinLoopProcess 
            OldTTYProcess OpInProgress ResetItems TTYResetVar InternalResetVar)
     (NAMED-RESETLST
      InternalResetVar
      (OR SelectionPredicate (SETQ SelectionPredicate (FUNCTION TRUE)))
      (SETQ PromptWindow (OR (NC.AttachPromptWindow (SETQ InstigatingWindow (
                                                                          NC.CoerceToInterestedWindow
                                                                             InstigatingCardOrWindow)
                                                     ))
                             PROMPTWINDOW))
      (SETQ InstigatingCard (NC.CoerceToCard InstigatingCardOrWindow))
      (SETQ InstigatingNoteFile (AND InstigatingCard (fetch (Card NoteFile) of InstigatingCard)))
      (NC.PrintMsg InstigatingWindow T (COND
                                          (Msg (CONCAT Msg (CHARACTER 13)))
                                          (T ""))
             "Items shift-selected:  ")
      (SETQ OldTTYProcess (TTY.PROCESS))
          
          (* ;; "Set up the prompt window for proper use by the CopyInsertFn")

      (NAMED-RESETSAVE InternalResetVar (WINDOWPROP PromptWindow 'SelectCardsMonitor
                                               (CREATE.MONITORLOCK 'SelectCards))
             `(WINDOWPROP ,PromptWindow SelectCardsMonitor NIL))
      [WINDOWPROP PromptWindow 'CopyInsertEvent (SETQ CopyInsertEvent (CREATE.EVENT 'CopyInsertEvent]
      (WINDOWPROP PromptWindow 'NewCardsProcessed T)
      [WINDOWPROP PromptWindow 'CardProcessedEvent (SETQ CardProcessedEvent (CREATE.EVENT
                                                                             'CardProcessedEvent]
      (WINDOWPROP PromptWindow 'SelectNoteCardsProcess (THIS.PROCESS))
      (WINDOWPROP PromptWindow 'COPYINSERTFN (FUNCTION NC.SelectNoteCardsCopyInsertFn))
      (NAMED-RESETSAVE InternalResetVar (WINDOWPROP PromptWindow 'SelectedCards NIL)
             `(WINDOWPROP ,PromptWindow SelectedCards NIL))
      (NAMED-RESETSAVE InternalResetVar (WINDOWPROP PromptWindow 'SelectingCards T)
             `(WINDOWPROP ,PromptWindow SelectingCards NIL))
          
          (* ;; "make sure ↑E aborts properly")

      (NAMED-RESETSAVE InternalResetVar (RESET.INTERRUPTS (LISPINTERRUPTS)
                                               T))
          
          (* ;; "Make the process behind the prompt window including control for a blinking cursor")

      [WINDOWPROP PromptWindow 'PROCESS (SETQ BinLoopProcess
                                         (ADD.PROCESS '(PROG NIL
                                                             (BLOCK)
                                                             (TTYDISPLAYSTREAM (PROCESSPROP
                                                                                (THIS.PROCESS)
                                                                                'WINDOW))
                                                         XXXX
                                                             (BIN)
                                                             (BLOCK)
                                                             (GO XXXX)) 'WINDOW PromptWindow
                                                'NAME
                                                'BinLoopProcess
                                                'TTYENTRYFN
                                                [FUNCTION (LAMBDA (Process)
                                                            (PROCESSPROP Process 'OldCaret
                                                                   (CARET CROSSHAIRS))
                                                            (ECHOMODE]
                                                'TTYEXITFN
                                                (FUNCTION (LAMBDA (Process)
                                                            (CARET (PROCESSPROP Process 'OldCaret))
                                                            (ECHOMODE T]
      [NAMED-RESETSAVE InternalResetVar NIL `(DEL.PROCESS ,BinLoopProcess]
          
          (* ;; "Insure the prompt window is cleared on the way out")

      [NAMED-RESETSAVE InternalResetVar NIL
             `(PROGN (AND (HASTTYWINDOWP ,BinLoopProcess)
                          (TTY.PROCESS (if (AND (PROCESSP ,OldTTYProcess)
                                                (HASTTYWINDOWP ,OldTTYProcess))
                                           then ,OldTTYProcess
                                         else T)))
                     (NC.ClearMsg ,InstigatingWindow T]
      (WINDOWADDPROP PromptWindow 'CLOSEFN (FUNCTION NC.ZapBinLoopProcess))
          
          (* ;; "Set up the menu above the prompt window")
                                                             (* ; 
                                    "fix in case MENUPOSITION is set incorrectly in menu passed down")

      (replace (MENU MENUPOSITION) of Menu with (CONSTANT (create POSITION
                                                                 XCOORD ← 0
                                                                 YCOORD ← 0)))
      [NAMED-RESETSAVE InternalResetVar (PROGN (ATTACHMENU Menu (OR InstigatingWindow PROMPTWINDOW)
                                                      (if InstigatingWindow
                                                          then 'TOP
                                                        else 'BOTTOM)
                                                      (if (AND (WINDOWP InstigatingWindow)
                                                               (WINDOWP PromptWindow))
                                                          then (CDR (WINDOWPROP PromptWindow
                                                                           'WHEREATTACHED))
                                                        else 'LEFT))
                                               (WINDOWPROP (WFROMMENU Menu)
                                                      'SelectionPromptWindow PromptWindow))
             `(PROGN (REMOVEWINDOW (WFROMMENU ,Menu]
          
          (* ;; 
 "If there is an instigating window, make sure it and all its attachments are visible on the screen.")

      (if InstigatingWindow
          then (NC.MoveWindowOntoScreen InstigatingWindow))
          
          (* ;; "Give the prompt window the tty process")

      (TTY.PROCESS (WINDOWPROP PromptWindow 'PROCESS))
          
          (* ;; "Loop as long as necessary")

      [WITH.MONITOR
       (WINDOWPROP PromptWindow 'SelectCardsMonitor)
       (until (OR (EQ SelectedCards 'DON'T)
                  (AND SingleCardFlg SelectedCards)
                  (EQ (CAR SelectedCards)
                      'DONE))
          do
          (                                                  (* ; 
                    "Wait for the user to respond by copy inserting something into the prompt window")

           (until [OR (NOT (PROCESSP BinLoopProcess))
                      (NOT (EQ SelectedCards (WINDOWPROP PromptWindow 'SelectedCards]
              do (MONITOR.AWAIT.EVENT (WINDOWPROP PromptWindow 'SelectCardsMonitor)
                        CopyInsertEvent 1000))               (* ; "Get the latest selection list")

           (SETQ SelectedCards (WINDOWPROP PromptWindow 'SelectedCards))
           (WINDOWPROP PromptWindow 'NewCardsProcessed T)
           (NOTIFY.EVENT CardProcessedEvent T)
           (OR (PROCESSP BinLoopProcess)
               (SETQ SelectedCards 'DON'T))
           (NAMED-RESETLST
            TTYResetVar                                      (* ; "Turn off the caret")

            (NAMED-RESETSAVE TTYResetVar (TTY.PROCESS (THIS.PROCESS)))
                                                             (* ; 
                               "If the last thing wasn't a done or cancel, process the new selection")

            (SETQ Card (CAR SelectedCards))
            (WITH.MONITOR
             NC.LockLock
             (COND
                ((AND (NEQ Card 'DONE)
                      (NEQ SelectedCards 'DON'T)
                      (NEQ Card '*New% Card*))               (* ; "Try to follow cross-file links.")

                 [if (AND (NC.ValidCardP Card)
                          (NC.CrossFileLinkCardP Card))
                     then (SETQ Card (NC.GetCrossFileLinkDestCard Card InstigatingWindow))
                          (WINDOWPROP PromptWindow 'SelectedCards (SETQ SelectedCards
                                                                   (CONS Card (CDR SelectedCards]
                                                             (* ; 
                                                     "Check to make sure that the selection is valid")

                 [COND
                    ((EQ Card '*Undo% Selection*)            (* ; 
                       "Chop off two elements from the list --- the indicator and the previous item.")

                     (SETQ Card (CADR SelectedCards))
                     (WINDOWPROP PromptWindow 'SelectedCards (SETQ SelectedCards (CDDR SelectedCards)
                                                              ))
                                                             (* ; 
                                "now get our hands off of all the locks we've acquired for this card")

                     (if Card
                         then (NAMED-RESETUNSAVE CardListResetVar (NC.FetchUserDataProp Card
                                                                         'ResetItems))
                              (NC.SetUserDataProp Card 'ResetItems NIL))
                     (NC.ClearMsg InstigatingWindow NIL))
                    [(OR (NOT (NC.ValidCardP Card))
                         (NULL (APPLY* SelectionPredicate Card)))
                                                             (* ; 
                                                        "Does this card match the slection predicate")

                     (NC.PrintMsg InstigatingWindow T "*** Invalid selection. ***" (CHARACTER 13))
                     (WINDOWPROP PromptWindow 'SelectedCards (SETQ SelectedCards (CDR SelectedCards]
                    ((AND (SETQ OpInProgress (if FileLevelLockFlg
                                                 then (NC.NoteFileCheckOpInProgress
                                                       (fetch (Card NoteFile) of Card))
                                               else (NC.CardCheckOpInProgress Card)))
                          (NEQ OpInProgress 'US))
                     (NC.PrintOperationInProgressMsg InstigatingWindow "Select Card" OpInProgress)
                     (DISMISS 1000)
                     (WINDOWPROP PromptWindow 'SelectedCards (SETQ SelectedCards (CDR SelectedCards))
                            )
                     (NC.ClearMsg InstigatingWindow NIL))
                    (T                                       (* ; "A valid selection.")

                       (NC.ClearMsg InstigatingWindow NIL)
                       [if FileLevelLockFlg
                           then [SETQ ResetItems
                                 (LIST (NAMED-RESETSAVE CardListResetVar (NC.NoteFileProp
                                                                          (fetch (Card NoteFile)
                                                                             of Card)
                                                                          'OperationInProgress 
                                                                          "Select Card")
                                              `(NC.NoteFileProp ,(fetch (Card NoteFile) of Card) 
                                                      OperationInProgress NIL))
                                       (NAMED-RESETSAVE CardListResetVar (NC.NoteFileProp
                                                                          (fetch (Card NoteFile)
                                                                             of Card)
                                                                          'ProcessInProgress
                                                                          (THIS.PROCESS))
                                              `(NC.NoteFileProp ,(fetch (Card NoteFile) of Card) 
                                                      ProcessInProgress NIL))
                                       (NAMED-RESETSAVE CardListResetVar (SETQ NC.NoteFileBusyList
                                                                          (CONS (THIS.PROCESS)
                                                                                NC.NoteFileBusyList))
                                              '(SETQ NC.NoteFileBusyList (DREMOVE (THIS.PROCESS)
                                                                                NC.NoteFileBusyList]
                         else (SETQ ResetItems (LIST [NAMED-RESETSAVE CardListResetVar
                                                            (SETQ NC.CardBusyList (CONS (THIS.PROCESS
                                                                                         )
                                                                                        
                                                                                      NC.CardBusyList
                                                                                        ))
                                                            '(SETQ NC.CardBusyList (DREMOVE (
                                                                                         THIS.PROCESS
                                                                                             )
                                                                                          
                                                                                      NC.CardBusyList
                                                                                          ]
                                                     [NAMED-RESETSAVE
                                                      CardListResetVar
                                                      [NC.NoteFileProp
                                                       (fetch (Card NoteFile) of Card)
                                                       'CardProcessInProgressList
                                                       (CONS (THIS.PROCESS)
                                                             (NC.NoteFileProp (fetch (Card NoteFile)
                                                                                 of Card)
                                                                    'CardProcessInProgressList]
                                                      `(NC.ResetCardProcessInProgress
                                                        ,(fetch (Card NoteFile) of Card]
                                                     (NAMED-RESETSAVE CardListResetVar
                                                            (NC.SetUserDataProp Card '
                                                                   OperationInProgress "Select Card")
                                                            `(NC.SetUserDataProp ,Card 
                                                                    OperationInProgress NIL))
                                                     (NAMED-RESETSAVE CardListResetVar
                                                            (NC.SetUserDataProp Card '
                                                                   ProcessInProgress (THIS.PROCESS))
                                                            `(NC.SetUserDataProp ,Card 
                                                                    ProcessInProgress NIL]
                       (NAMED-RESETSAVE InternalResetVar (NC.SetUserDataProp Card 'ResetItems 
                                                                ResetItems)
                              `(NC.SetUserDataProp ,Card ResetItems NIL]
          
          (* ;; "Print the results in the prompt window")

                 (NC.PrintMsg InstigatingWindow NIL (COND
                                                       (Msg (CONCAT Msg (CHARACTER 13)))
                                                       (T ""))
                        "Items selected:  ")
                 (for ThisCard in (REVERSE SelectedCards)
                    do (NC.PrintMsg InstigatingWindow NIL (NC.RetrieveTitle ThisCard)
                              ",  ")
                       (if [AND InstigatingWindow (GREATERP (DSPXPOSITION NIL PromptWindow)
                                                         (TIMES 1.25 (WINDOWPROP InstigatingWindow
                                                                            'WIDTH]
                           then (NC.PrintMsg InstigatingWindow NIL (CHARACTER 13]
          
          (* ;; "Return the result")

      (PROG1 [COND
                ((EQ SelectedCards 'DON'T)
                 (COND
                    (CheckForCancelFlg 'DON'T)
                    (T NIL)))
                (SingleCardFlg (if (EQ (CAR SelectedCards)
                                       'DONE)
                                   then NIL
                                 else (CAR SelectedCards)))
                (T (if (EQ (CAR SelectedCards)
                           'DONE)
                       then (DREVERSE (CDR SelectedCards))
                     else (DREVERSE SelectedCards]
             (WINDOWPROP PromptWindow 'SelectedCards NIL])

(NC.CloseNoteCards
  [LAMBDA (CardIdOrCardList NoCheckFlg DontClearFlg InterestedWindow)
                                                             (* Randy.Gobbel " 2-Apr-87 15:38")
          
          (* * Close note acrds on the screen)
          
          (* * fgh |11/14/85| Updated to handle Card object.)
          
          (* * kirk 21Feb86 Added InterestedWindow)
          
          (* * fgh |6/27/86| Fixed call to NC.SelectNoteCards to use just 
          InterestedWindow)
          
          (* * pmi 12/5/86%: Modified message to NC.SelectNoteCards to mention 
          SHIFT-selection.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rht 3/9/87%: Changed NC.DeleteSelectingMenu to NC.SelectingCardsMenu.)
          
          (* * rg |3/9/87| added NC.ProtectedSessionOperation wrapper)
          
          (* * rg |4/1/87| changes NC.ProtectedSessionOperation to NCP.WithLockedCards ;
          also added NC.IfAllCardsFree wrapper)

    (DECLARE (GLOBALVARS NC.SelectingCardsMenu))
    (NCP.WithLockedCards (NC.IfAllCardsFree (NC.LockListOfCards (MKLIST CardIdOrCardList)
                                                   "Close Note Cards")
                                (LET (Cards Window)
                                     [SETQ Cards (COND
                                                    ((LISTP CardIdOrCardList))
                                                    (CardIdOrCardList (NC.CoerceToCard 
                                                                             CardIdOrCardList))
                                                    (T (NC.SelectNoteCards NIL NIL 
                                                              NC.SelectingCardsMenu InterestedWindow 
                                                        "Please shift-select the cards to be closed."
                                                              ]
                                     (ALLOW.BUTTON.EVENTS)
                                     (for Card in (MKLIST Cards)
                                        do (COND
                                              ((AND (NC.ActiveCardP Card)
                                                    (SETQ Window (NC.FetchWindow Card)))
                                               (COND
                                                  ((NEQ (NC.QuitCard Card T)
                                                        'DON'T)
                                                   (while (OPENWP Window) do (BLOCK])

(NC.CopyStructure
  [LAMBDA (RootCards DestinationFileBox TraversalSpecs InterestedWindow QuietFlg)
                                                             (* pmi%: "29-Oct-87 17:17")
          
          (* * Copy a NoteCard structure into a filebox)
          
          (* * kirk 13/7/86%: Placed TraversalSpecs after RootCards selection and changed 
          prompt message)
          
          (* * rht 9/2/86%: Threw away CheckFlg arg.
          Wasn't being used. Changed to call NCP.CollectCards instead of outdated 
          NC.CollectCards. Changed arg named ToPosition to DestinationFileBox.
          Also changed FromCard to RootCard. Passes two link types to 
          NC.AskTraversalSpecs.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rht 3/9/87%: Now accepts multiple root cards.)
          
          (* * rg |3/9/87| added NC.ProtectedSessionOperation wrapper)
          
          (* * RG |3/18/87| changed NC.ProtectedSessionOperation to NCP.WithLockedCards ;
          added NC.IfAllCardsFree wrapper)
          
          (* * rht&rg&pmi 4/22/87%: Removed calls to ERROR!)
          
          (* * rg |6/2/87| added check for DON'T to selection of dest filebox)
          
          (* * pmi 10/29/87%: Now saves cards returned from NCP.CollectCards to return to 
          NC.MoveStructure.)

    (DECLARE (GLOBALVARS NC.SelectingCardsMenu NC.SelectingCardMenu))
    (NCP.WithLockedCards
     (SETQ RootCards (MKLIST RootCards))
     (NC.IfAllCardsFree (NC.LockListOfCards RootCards "Copy Structure")
            (LET (OriginalCards)
                 (if [AND (OR RootCards (SETQ RootCards (NC.SelectNoteCards NIL NIL 
                                                               NC.SelectingCardsMenu NIL 
                                                       "Shift-select the root cards of the structure"
                                                               )))
                          [OR TraversalSpecs (SETQ TraversalSpecs (NC.AskTraversalSpecs
                                                                   (fetch (Card NoteFile)
                                                                      of (CAR RootCards))
                                                                   '(SubBox FiledCard]
                          (OR DestinationFileBox (NEQ (SETQ DestinationFileBox
                                                       (NC.SelectNoteCards T [FUNCTION (LAMBDA (Card)
                                                                                         (NC.FileBoxP
                                                                                          Card T]
                                                              NC.SelectingCardMenu NIL 
                                                 "Shift-select the FileBox to contain the structure." 
                                                              T))
                                                      'DON'T]
                     then (NC.CopyCards (SETQ OriginalCards (NCP.CollectCards RootCards
                                                                   (fetch (TRAVERSALSPECS LinkTypes)
                                                                      of TraversalSpecs)
                                                                   (fetch (TRAVERSALSPECS Depth)
                                                                      of TraversalSpecs)))
                                 DestinationFileBox RootCards QuietFlg InterestedWindow)
                          OriginalCards])

(NC.CloseStructure
  [LAMBDA (RootCards TraversalSpecs InterestedWindow QuietFlg)
                                                             (* Randy.Gobbel " 2-Apr-87 15:38")
          
          (* * rht 9/2/86%: Replaced call to outdated NC.CollectCards with 
          NCP.CollectCards. Threw away useless NoCheckFlg and Don'tClearFlg args.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rht 3/9/87%: Now accepts multiple root cards.)
          
          (* * rg |3/9/87| added NC.ProtectedSessionOperation wrapper)
          
          (* * rg |4/1/87| changes NC.ProtectedSessionOperation to NCP.WithLockedCards ;
          added NC.IfAllCardsFree wrapper)

    (NCP.WithLockedCards (SETQ RootCards (MKLIST RootCards))
           (NC.IfAllCardsFree (NC.LockListOfCards RootCards "Close Structure")
                  (OR RootCards (SETQ RootCards (NC.SelectNoteCards NIL NIL NC.SelectingCardsMenu NIL 
                                                       "Shift-select the root cards of the structure"
                                                       ))
                      (ERROR!))
                  [OR TraversalSpecs (SETQ TraversalSpecs (NC.AskTraversalSpecs (fetch (Card NoteFile
                                                                                             )
                                                                                   of (CAR RootCards)
                                                                                       )
                                                                 '(SubBox FiledCard]
                  (if (AND RootCards TraversalSpecs)
                      then (OR QuietFlg (NC.PrintMsg InterestedWindow T 
                                               "Collecting cards to close ..."))
                           (NC.CloseNoteCards (NCP.CollectCards RootCards (fetch (TRAVERSALSPECS
                                                                                  LinkTypes)
                                                                             of TraversalSpecs)
                                                     (fetch (TRAVERSALSPECS Depth) of TraversalSpecs)
                                                     )
                                  NIL NIL InterestedWindow)
                           (OR QuietFlg (NC.ClearMsg InterestedWindow T))
                           RootCards])

(NC.DeleteStructure
  [LAMBDA (RootCards TraversalSpecs InterestedWindow QuietFlg Don'tPutToBeDeletedCardsFlg)
                                                             (* Randy.Gobbel " 2-Apr-87 15:38")
          
          (* * rht 8/29/86%: Reorganized and changed to call NCP.CollectCards which is 
          more efficient than the old NCP.ComputeTransitiveClosure.
          Also now takes QuietFlg and Don'tPutToBeDeletedCardsFlg args.
          Threw away Don'tClearFlg.)
          
          (* * pmi 12/12/86%: Removed obsolete ReturnLinksFlg argument in call to 
          NC.SelectNoteCards.)
          
          (* * rht 3/9/87%: Now accepts multiple root cards.)
          
          (* * rg |3/9/87| added NC.ProtectedSessionOperation wrapper)
          
          (* * rg |4/2/87| turned NC.ProtectedSessionOperation into 
          NC.CardSelectionOperation)

    (NCP.WithLockedCards (SETQ RootCards (MKLIST RootCards))
           (NC.IfAllCardsFree (NC.LockListOfCards RootCards "Delete Structure")
                  (OR RootCards (SETQ RootCards (NC.SelectNoteCards NIL NIL NC.SelectingCardsMenu NIL 
                                                       "Shift-select the root cards of the structure"
                                                       ))
                      (ERROR!))
                  [OR TraversalSpecs (SETQ TraversalSpecs (NC.AskTraversalSpecs (fetch (Card NoteFile
                                                                                             )
                                                                                   of (CAR RootCards)
                                                                                       )
                                                                 '(SubBox FiledCard]
                  (if (AND RootCards TraversalSpecs)
                      then (OR QuietFlg (NC.PrintMsg InterestedWindow T 
                                               "Collecting cards to delete ..."))
                           (NC.DeleteNoteCards (NCP.CollectCards RootCards (fetch (TRAVERSALSPECS
                                                                                   LinkTypes)
                                                                              of TraversalSpecs)
                                                      (fetch (TRAVERSALSPECS Depth) of TraversalSpecs
                                                             ))
                                  T NIL InterestedWindow QuietFlg NIL Don'tPutToBeDeletedCardsFlg)
                           (OR QuietFlg (NC.ClearMsg InterestedWindow T))
                           RootCards])

(NC.MoveStructure
  [LAMBDA (RootCards DestinationFileBox TraversalSpecs InterestedWindow QuietFlg 
                 Don'tPutToBeDeletedCardsFlg)                (* Randy.Gobbel " 2-Jun-87 19:44")
          
          (* * Copy a NoteCard structure into a filebox)
          
          (* * rht 9/2/86%: Added QuietFlg and Don'tPutToBeDeletedCardsFlg args.
          Changed names of a few args and removed Don'tClearFlg arg.
          Took out REVERSE to save time and space.)
          
          (* * rht 3/9/87%: Now accepts multiple root cards.)
          
          (* * rht&rg&pmi 4/22/87%: Now checks that NC.CopyStructure returns valid stuff 
          before deleting.)
          
          (* * rg |6/2/87| added NCP.WithLockedCards wrapper)

    (NCP.WithLockedCards (MKLIST RootCards)
           (NC.IfAllCardsFree (NC.LockListOfCards RootCards "Move Structure")
                  (LET ((Structure (NC.CopyStructure (MKLIST RootCards)
                                          DestinationFileBox TraversalSpecs InterestedWindow QuietFlg
                                          )))
                       (AND Structure (NC.DeleteNoteCards Structure T NIL InterestedWindow QuietFlg 
                                             NIL Don'tPutToBeDeletedCardsFlg])
)
(PUTPROPS RGPATCH079 COPYRIGHT ("Xerox Corporation" 1988))
(DECLARE%: DONTCOPY
  (FILEMAP (NIL (4847 6402 (NAMED-RESETUNWIND 4857 . 6400)) (9091 31037 (NC.MakeLink 9101 . 19177) (
NC.MakeFilingLinks 19179 . 24292) (NC.AddGlobalLinksToCard 24294 . 27602) (NC.AddLinksToCard 27604 . 
31035)) (31074 46763 (NC.AddParents 31084 . 34125) (NC.DeleteNoteCards 34127 . 43711) (
NC.UnfileNoteCard 43713 . 46761)) (46806 77887 (NC.MakeBrowserCard 46816 . 57246) (
NC.UpdateBrowserCard 57248 . 72975) (NC.BrowserAddNode 72977 . 77885)) (77930 82042 (
NC.FileBoxCollectChildren 77940 . 82040)) (82081 85582 (NCP.CloseCards 82091 . 83890) (NCP.SelectCards
 83892 . 85580)) (85626 94088 (NC.MakeDocument 85636 . 94086)) (94128 110267 (NC.CopyCards 94138 . 
108761) (NC.MoveCards 108763 . 110265)) (110308 142805 (NC.SelectNoteCards 110318 . 129888) (
NC.CloseNoteCards 129890 . 132534) (NC.CopyStructure 132536 . 136257) (NC.CloseStructure 136259 . 
138805) (NC.DeleteStructure 138807 . 141515) (NC.MoveStructure 141517 . 142803)))))
STOP