(DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP")
(FILECREATED "29-Feb-88 15:58:14" {QV}<NOTECARDS>1.3LNEXT>PMIPATCH092.;9 55662  

      changes to%:  (VARS PMIPATCH092COMS)
                    (FNS NCP.MakeDocument NC.MakeBrowserCard NCP.SelectCards 
                         NC.CoerceToInterestedWindow NC.MakeNoteCard NC.MakeDocument NC.MakeLink 
                         NCP.CreateCard)

      previous date%: "22-Feb-88 17:03:12" {QV}<NOTECARDS>1.3LNEXT>PMIPATCH092.;1)


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

(PRETTYCOMPRINT PMIPATCH092COMS)

(RPAQQ PMIPATCH092COMS (
          
          (* ;; "pmi 2/29/88: Misc. changes, including how browser and document cards are created.")

                        (DECLARE%: DONTCOPY (PROPS (PMIPATCH092 MAKEFILE-ENVIRONMENT)
                                                   (PMIPATCH092 FILETYPE)))
                        [DECLARE%: FIRST (P (NC.LoadFileFromDirectories 'NCDOCUMENTCARD)
                                            (NC.LoadFileFromDirectories 'NCBROWSERCARD]
                        
          
          (* ;; "Changed in NCDOCUMENTCARD")

                        (FNS NC.MakeDocument)
                        
          
          (* ;; "Changed in NCBROWSERCARD")

                        (FNS NC.MakeBrowserCard)
                        
          
          (* ;; "Changed in NCPROGINT")

                        (FNS NCP.SelectCards NCP.CreateCard NCP.CreateBrowserCard NCP.MakeDocument)
                        
          
          (* ;; "Changed in NCCARDS")

                        (FNS NC.MakeNoteCard)
                        
          
          (* ;; "Changed in NCINTERFACE")

                        (FNS NC.NoteFileIconButtonEventFn)
                        
          
          (* ;; "Changed in NCLINKS")

                        (FNS NC.MakeLink)
                        
          
          (* ;; "Changed in NCUTILITIES")

                        (FNS NC.CoerceToInterestedWindow)))



(* ;; "pmi 2/29/88: Misc. changes, including how browser and document cards are created.")

(DECLARE%: DONTCOPY 

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

(PUTPROPS PMIPATCH092 FILETYPE :BCOMPL)
)
(DECLARE%: FIRST 
(NC.LoadFileFromDirectories 'NCDOCUMENTCARD)
(NC.LoadFileFromDirectories 'NCBROWSERCARD)
)



(* ;; "Changed in NCDOCUMENTCARD")

(DEFINEQ

(NC.MakeDocument
  [LAMBDA (Card Title NoDisplayFlg TypeSpecificArgs InterestedWindow)
                                                             (* ; "Edited 25-Feb-88 13:38 by pmi")
          
          (* ;; "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.")
          
          (* ;; "pmi 2/25/88: Replaced CardIdentifier argument with TypeSpecificArgs, and added InterestedWindow argument.  The task of figuring out the parameters is now done here, rather than in NCP.MakeDocument. ")

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

                               (SETQ RootCard (OR (NC.CoerceToCard (CAR TypeSpecificArgs))
                                                  (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 none were passed in.")

                               (if (SETQ ParamProps (CADR TypeSpecificArgs))
                                   then (SETQ CurParams (NCP.DocumentParameters ParamProps))
                                 else (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)
                                        (if ParamProps
                                            then (SETPROPLIST 'NC.MakeDocParameters CurParams))
                                        (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 NC.MakeDocParameters to its original setting, if new params were passed in.")

                               (if ParamProps
                                   then (SETPROPLIST 'NC.MakeDocParameters CurParams))
                               (RETURN DocWindowOrCard])
)



(* ;; "Changed in NCBROWSERCARD")

(DEFINEQ

(NC.MakeBrowserCard
  [LAMBDA (Card Title NoDisplayFlg ParamList InterestedWindow)
                                                             (* ; "Edited 29-Feb-88 15:48 by pmi")
          
          (* ;; "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.")
          
          (* ;; "dwm 1/19/88 Sets ReadOnly prop based upon current NF ReadOnly status")
          
          (* ;; "pmi 2/29/88: Now asks for specs only if none are specified coming in. A browser created from a browser now prompts for everything.  Also added InterestedWindow argument.")

    (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))
            (Don'tAskForRoots (FMEMB 'ROOTCARDS ParamList))
            (Don'tAskForSpecs (OR (FMEMB 'LINKTYPES ParamList)
                                  (FMEMB 'FORMAT ParamList)
                                  (FMEMB 'DEPTH ParamList)))
            Lattice RootNodes Window Graph SpecialBrowserSpecs BrowserSpecs DropVirtualNodesFlg)
           (NC.IfAllCardsFree
            (NC.LockListOfCards RootCards "Make Browser Card")
            (if NoDisplayFlg
                then (SETQ Window InterestedWindow)
              else (SETQ Window (NC.MakeNewCardWindow Card (OR Title "Untitled")))
                   (WINDOWADDPROP Window 'SHRINKFN (FUNCTION NC.GraphCardShrinkFn)))
            (OR Don'tAskForRoots (SETQ RootCards (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 Don'tAskForSpecs
                                          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 (if RootCards
                                then (for RootCard in RootCards collect (NC.GetBrowserNodeID Card 
                                                                               RootCard))
                              else NIL))
            (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)
            (NC.SetUserDataProp Card 'ReadOnly (NC.CardReadOnlyOpenP Card))
            (COND
               (NoDisplayFlg (RETURN Card)))
            (WINDOWPROP Window 'GRAPH Graph)
            (NC.InstallTitleBarLeftMenu Window CardType)
            (NC.InstallTitleBarMiddleMenu Window CardType)
            (NC.RelayoutBrowserCard Window)
            (RETURN Window])
)



(* ;; "Changed in NCPROGINT")

(DEFINEQ

(NCP.SelectCards
  [LAMBDA (InstigatingCardOrWindow SingleCardFlg SelectionPredicate Msg CheckForCancelFlg)
                                                             (* ; "Edited 26-Feb-88 14:35 by pmi")
          
          (* ;; "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")
          
          (* ;; "pmi 2/26/88: Undid Randy't change of 12/12/86.  Now lets NC.CoerceToInterestedWindow (called from NC.SelectNoteCards) check that the instigating card is displayed.")

    (NCP.WithLockedCards (NC.SelectNoteCards SingleCardFlg SelectionPredicate
                                (if SingleCardFlg
                                    then NC.SelectingCardMenu
                                  else NC.SelectingCardsMenu)
                                InstigatingCardOrWindow Msg CheckForCancelFlg])

(NCP.CreateCard
  [LAMBDA (Type NoteFile Title NoDisplayFlg Props ParentFileBoxes TypeSpecificArgs InterestedWindow)
                                                             (* ; "Edited 23-Feb-88 12:25 by pmi")
          
          (* ;; "Creates a new notecard with given type, title, props and parents.  Any of those args can be nil.  Type being NIL will cause user to be asked.  Makes a card with initially empty substance.")
          
          (* ;; "rht 11/20/84: Had to add a horrible kluge: if creating a document card in which embedded links may be copied, then need to have document card visible on screen.  This is because ID is currently unattainable from just the Textstream --- need to have a window.  Until that is fixed, we temporarily bring up the document card while it's being filled in.")
          
          (* ;; "rht 11/17/85: Updated to handle new card and notefile objects.")
          
          (* ;; "rht 7/10/86: Ripped out the above described document kludge.")
          
          (* ;; 
          "rht 8/21/86: Now sticks (APPEND Props) on the card's proplist, i.e.  a top level copy.")
          
          (* ;; "rht 11/16/86: Changed call to NCP.ReportError")
          
          (* ;; "dsj 9/23/87: Added (NC.RetrievePropList Card) to APPEND to preserve properties set by user's makefn.")
          
          (* ;; "pmi 12/10/87: Added dsj's change;  see above comment.")
          
          (* ;; "pmi 2/23/88: Added InterestedWindow argument to passed on to NC.MakeNoteCard.")

    (if (NCP.CardTypeP Type)
        then (LET (Card CardIdentifier)
                  (if (SETQ CardIdentifier (NC.MakeNoteCard Type NoteFile Title NoDisplayFlg 
                                                  TypeSpecificArgs NIL InterestedWindow))
                      then (SETQ Card (if (WINDOWP CardIdentifier)
                                          then (NCP.CardFromWindow CardIdentifier)
                                        else CardIdentifier))
                           (if Props
                               then (NC.SetPropList Card (APPEND Props (NC.RetrievePropList Card)))
                                    (NC.SetPropListDirtyFlg Card T))
                           [for Box in (MKLIST ParentFileBoxes)
                              do (if (NCP.FileBoxP Box)
                                     then (NCP.FileCards Card Box)
                                   else (NCP.ReportError 'NCP.CreateCard (CONCAT Box 
                                                                          " not an existing filebox."
                                                                                ]
                           Card))
      else (NCP.ReportError 'NCP.CreateCard (CONCAT "Unknown card type: " Type))
           NIL])

(NCP.CreateBrowserCard
  [LAMBDA (NoteFile Title ParamList NoDisplayFlg Props ParentFileBoxes InterestedWindow)
                                                             (* ; "Edited 24-Feb-88 14:35 by pmi")
          
          (* ;; "Creates a new browser notecard with given type, title, props, parents, starting ID and link labels.")
          
          (* ;; "rht 11/17/85: Updated to handle new card and notefile objects.")
          
          (* ;; "rht 8/21/86: Changed call from NCP.ValidLinkType to NCP.ValidLinkTypeP.")
          
          (* ;; "rht 11/16/86: Changed call to NCP.ReportError")
          
          (* ;; "rht 3/7/87: Now properly accepts link types with '←' prefixes.")
          
          (* ;; "pmi 2/24/88: Now passes NIL as NewParamList if the user didn't specify any parameters.  Also added InterestedWindow argument.")

    (LET (ValidLinkTypes LinkTypes NewParamList)
         [SETQ ValidLinkTypes (for LinkType in (SETQ LinkTypes (LISTGET ParamList 'LINKTYPES))
                                 join (COND
                                         ((EQ LinkType 'ALL)
                                          (NCP.LinkTypes NoteFile))
                                         ((EQ LinkType '←ALL)
                                          (NCP.ReverseLinkTypes NoteFile))
                                         ((OR (NCP.ValidLinkTypeP LinkType NoteFile)
                                              (AND (STREQUAL (SUBSTRING LinkType 1 1)
                                                          "←")
                                                   (NCP.ValidLinkTypeP (SUBATOM LinkType 2)
                                                          NoteFile)))
                                          (LIST LinkType))
                                         (T (NCP.ReportError 'NCP.CreateBrowserCard (CONCAT LinkType 
                                                                            " not a valid link type."
                                                                                           ))
                                            NIL]
         (SETQ ValidLinkTypes (INTERSECTION ValidLinkTypes ValidLinkTypes))
         (if (AND LinkTypes (NULL ValidLinkTypes))
             then NIL
           else                                              (* ; 
                    "Make a copy of the user's param list since she may not want it to get rplaca'd.")

                (if ParamList
                    then (SETQ NewParamList (COPY ParamList))
                         (LISTPUT NewParamList 'LINKTYPES ValidLinkTypes)
                  else (SETQ NewParamList NIL))
                (NCP.CreateCard 'Browser NoteFile Title NoDisplayFlg Props ParentFileBoxes 
                       NewParamList InterestedWindow])

(NCP.MakeDocument
  [LAMBDA (NoteFile RootCard ParamProps NoDisplayFlg Props ParentFileBoxes InterestedWindow)
                                                             (* ; "Edited 26-Feb-88 16:33 by pmi")
          
          (* ;; "Do a MakeDocument starting from RootCard according to parameters in ParamProps if non-nil.  Otherwise use the default parameters.  Note that ParamProps are *only* used for the duration of this MakeDocument and do not affect the default parameter values.")
          
          (* ;; "rht 11/17/85: Updated to handle new card and notefile objects.")
          
          (* ;; "rht 8/25/86: Now passes non-nil QuietFlg to NCP.UncacheCards.")
          
          (* ;; "rht 11/16/86: Changed call to NCP.ReportError")
          
          (* ;; "pmi 2/26/88: Now passes ParamProps on down to NC.MakeDocument, which will handle fetching the existing parameters and restoring the original ones.  Also added InterestedWindow argument to be passed on to NCP.CreateCard.")

    (LET (CurParams DocCard WasActive)
         (if (NC.ValidCardP RootCard)
             then (AND (NOT (SETQ WasActive (NCP.CardCachedP RootCard)))
                       (NCP.CacheCards RootCard)) 
          
          (* ;; "(if ParamProps then (SETQ CurParams (NCP.DocumentParameters ParamProps)))")

                  (SETQ DocCard (NCP.CreateCard 'Document NoteFile NIL NoDisplayFlg Props 
                                       ParentFileBoxes (LIST RootCard ParamProps)
                                       InterestedWindow)) 
          
          (* ;; "(if ParamProps then (SETPROPLIST 'NC.MakeDocParameters CurParams))")

                  (AND (NOT WasActive)
                       (NCP.UncacheCards RootCard T))
                  DocCard
           else (NCP.ReportError 'NCP.MakeDocument (CONCAT RootCard " not a valid card or filebox."))
                NIL])
)



(* ;; "Changed in NCCARDS")

(DEFINEQ

(NC.MakeNoteCard
  [LAMBDA (NoteCardType NoteFile Title NoDisplayFlg TypeSpecificArgs Card InterestedWindow)
                                                             (* ; "Edited 25-Feb-88 14:06 by pmi")
                                                             (* ; 
                  "Make a new note card of type NoteCardType.  If type note specified, ask the user.")
          
          (* ;; "rht 2/1/85: Added call to NC.MarkCardDirty.")
          
          (* ;; "fgh 10/15/85 Added extra DatabaseStream argument for use by caching mechanism")
          
          (* ;; "fgh 11/11/85: Updated to handle new Card object.")
          
          (* ;; "fgh 2/5/86 Added call to NC.ApplyFn")
          
          (* ;; "kirk 15May86 Added call to NC.AttachNoteFileName")
          
          (* ;; "rht 7/4/86: Now checks for read-only notefile before proceeding.")
          
          (* ;; "kef 8/4/86: Updated to pass NoteCardType argument on to NC.GetNewCard.")
          
          (* ;; "rht 7/24/87: Replaced WINDOWPROP thing with call to NC.InstallCopyButtonEventFn.")
          
          (* ;; "pmi 2/25/88: Added InterestedWindow arg to be passed on to the card type's makefn.")

    (DECLARE (GLOBALVARS NC.ShowNoteFileOnCards))
    (if (NC.ReadOnlyNoteFileP NoteFile)
        then NIL
      else (LET (ReturnValue Window)
                (COND
                   ([SETQ NoteCardType (OR NoteCardType (NC.AskNoteCardType (fetch (NoteFile Menu)
                                                                               of NoteFile]
                    (SETQ Card (OR (PROGN (type? Card Card)
                                          Card)
                                   (NC.GetNewCard NoteFile NoteCardType)))
                    (NC.SetNewCardFlg Card T)
                    (NC.ActivateCard Card)
                    (NC.SetType Card NoteCardType)
                    [COND
                       ((OR [NULL (ERSETQ (SETQ ReturnValue (NC.ApplyFn MakeFn Card Title 
                                                                   NoDisplayFlg TypeSpecificArgs 
                                                                   InterestedWindow]
                            (NULL ReturnValue))
                        (NC.SetStatus Card 'DELETED)
                        (NC.DeactivateCard Card T))
                       (T (SETQ Window (WINDOWP ReturnValue))
                          [COND
                             ((NULL (NC.RetrieveTitle Card))
                              [SETQ Title (NC.SetTitle Card (SETQ Title
                                                             (COND
                                                                ((STRINGP Title)
                                                                 Title)
                                                                ((AND Title (OR (LITATOM Title)
                                                                                (NUMBERP Title)))
                                                                 (MKSTRING Title))
                                                                (T "Untitled"]
                              (AND Window (WINDOWPROP Window 'TITLE Title)))
                             (T (NC.SetTitle Card (MKSTRING (NC.RetrieveTitle Card]
                          (COND
                             (Window (WINDOWADDPROP Window 'CLOSEFN (FUNCTION NC.QuitCard)
                                            'FIRST)
                                    (WINDOWPROP Window 'NoteCardObject Card)
                                    (NC.InstallCopyButtonEventFn Window)))
                          (NC.SetTitleDirtyFlg Card T)
          
          (* ;; "Reset the type in case of recursive calls change the type.  Always want the highest level type in a recursive descent")

                          (NC.SetType Card NoteCardType)     (* ; 
                                             "Insure that a link ptr is set up during the first save")

                          (NC.SetLinksDirtyFlg Card T)
                          (NC.SetPropListDirtyFlg Card T)    (* ; "Mark that substance is dirty.")

                          (NC.MarkCardDirty Card T)
                          (if NC.ShowNoteFileOnCards
                              then (NC.AttachNoteFileName Window]
                    ReturnValue])
)



(* ;; "Changed in NCINTERFACE")

(DEFINEQ

(NC.NoteFileIconButtonEventFn
  [LAMBDA (Window)                                           (* ; "Edited 23-Feb-88 12:17 by pmi")
          
          (* ;; "Bring up NoteFile Menues")
          
          (* ;; "kirk 15Jul86 Adjusted title size check for change in font")
          
          (* ;; 
   "rht 11/23/86: Now calls NC.NoteFileIconMiddleButtonFn to put up a menu of middle button options.")
          
          (* ;; "pmi 3/20/87: Overhauled to have NewCards and ShowCards middlebutton menus appear when buttoned DOWN, instead of after the button comes back up.")
          
          (* ;; "pmi 4/3/87: Now unshades NewCards item during card creation to indicate that multiple cards may be created at the same time.")
          
          (* ;; "rg 11/4/87 calls NC.EditNoteCard w/ ReadOnly if NoteFile is read-only")
          
          (* ;; "pmi 2/23/88: Now passes Window as InterestedWindow argument to NC.MakeNoteCard.")

    (LET
     (NoteFile Menu)
     (if (MOUSESTATE UP)
       else
       (TOTOPW Window)
       (LET
        [(Menu (CAR (WINDOWPROP Window 'MENU]                (* ; "title bar")

        (SETQ NoteFile (WINDOWPROP Window 'NoteFile))
        (for Item in (fetch (MENU ITEMS) of Menu) when (INSIDEP (MENUITEMREGION Item Menu)
                                                              (LASTMOUSEX Window)
                                                              (LASTMOUSEY Window))
           do (RESETLST
               (RESETSAVE (SHADEITEM Item Menu GRAYSHADE)
                      (LIST 'SHADEITEM Item Menu (if (NULL (NC.NoteFileOpenP NoteFile))
                                                     then GRAYSHADE
                                                   elseif (AND (EQ (CAR Item)
                                                                   'NewCards)
                                                               (NC.ReadOnlyNoteFileP NoteFile))
                                                     then GRAYSHADE
                                                   else WHITESHADE)))
               (if (NULL (NC.NoteFileOpenP NoteFile))
                   then 

(* ;;; "If the NoteFile is not open, just print a message and return")

                        (FLASHW Window)
                        (NC.PrintMsg Window T (fetch (NoteFile FullFileName) of NoteFile)
                               " is not an open notefile.")
                        (DISMISS 1000)
                        (NC.ClearMsg Window T)
                 elseif (PROCESSP (NC.NoteFileProp NoteFile 'ProcessInProgress))
                   then 

(* ;;; "This will probably be overhauled with Randy G.'s concurrancy fixes")

                        (NC.PrintOperationInProgressMsg Window (CAR Item)
                               (NC.NoteFileProp NoteFile 'OperationInProgress))
                        NIL
                 else (SELECTQ (CAR Item)
                          (NewCards (if (NC.ReadOnlyNoteFileP NoteFile)
                                        then (FLASHW Window)
                                             (NC.PrintMsg Window T 
                                                   "Can't create a new card in a Read-Only notefile."
                                                    )
                                             (DISMISS 1000)
                                             (NC.ClearMsg Window T)
                                      elseif (LASTMOUSESTATE LEFT)
                                        then 
          
          (* ;; "For the left button, don't do anything until the button comes back up.  Otherwise, things happen too soon.")

                                             (UNTILMOUSESTATE UP)
                                             (if (INSIDEP (MENUITEMREGION Item Menu)
                                                        (LASTMOUSEX Window)
                                                        (LASTMOUSEY Window))
                                                 then (SHADEITEM Item Menu WHITESHADE)
                                                      (NC.MakeNoteCard NC.DefaultCardType NoteFile 
                                                             NIL NIL NIL NIL Window))
                                      else (SHADEITEM Item Menu WHITESHADE)
                                           (NC.MakeNoteCard NIL NoteFile NIL NIL NIL NIL Window)))
                          (ShowCards (if (LASTMOUSESTATE LEFT)
                                         then 
          
          (* ;; "For the left button, don't do anything until the button comes back up.  Otherwise, things happen too soon.")

                                              (UNTILMOUSESTATE UP)
                                              (if (INSIDEP (MENUITEMREGION Item Menu)
                                                         (LASTMOUSEX Window)
                                                         (LASTMOUSEY Window))
                                                  then (NC.EditNoteCard (fetch (NoteFile 
                                                                                  TableOfContentsCard
                                                                                      ) of NoteFile)
                                                              (fetch (NoteFile ReadOnlyFlg)
                                                                 of NoteFile)))
                                       else (NC.ChooseTopLevelCard NoteFile)))
                          NIL)))
              (RETURN) finally (if (LASTMOUSESTATE MIDDLE)
                                   then (NC.NoteFileIconMiddleButtonFn Window NoteFile)
                                 elseif (NULL (WINDOWPROP Window 'BusyOperation))
                                   then (RESETLST (RESETSAVE (WINDOWPROP Window 'BusyOperation 
                                                                    "Operation")
                                                         `(WINDOWPROP ,Window BusyOperation NIL))
                                               (NC.NoteFileOperations NoteFile))
                                 else (NC.PrintMsg NIL NIL (CHARACTER 13)
                                             (WINDOWPROP Window 'BusyOperation)
                                             " in progress.  Please wait."])
)



(* ;; "Changed in NCLINKS")

(DEFINEQ

(NC.MakeLink
  [LAMBDA (Window LinkLabel DestinationCard SourceCard DisplayMode AnchorMode Message NoDisplayFlg 
                 LinkToInsertAfter CrossFileLinksMode)       (* ; "Edited 24-Feb-88 15:03 by pmi")

(* ;;; "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.")
          
          (* ;; "rht 2/22/88: Now passes NIL argument to NC.AskNoteCardType which makes type selection menu come up at cursorpos.")
          
          (* ;; "pmi 2/24/88: Now passes Window as InterestedWindow argument to NC.MakeNoteCard.")

    (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))
                                           (NC.CoerceToCard (NC.MakeNoteCard Type (fetch (Card 
                                                                                             NoteFile
                                                                                               )
                                                                                     of SourceCard)
                                                                   NIL NoDisplayFlg NIL NIL Window]

(* ;;; "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])
)



(* ;; "Changed in NCUTILITIES")

(DEFINEQ

(NC.CoerceToInterestedWindow
  [LAMBDA (WinOrCardOrNoteFile)                              (* ; "Edited 26-Feb-88 14:35 by pmi")
          
          (* ;; "Try to return a window that can be used for NC.PrintMsg, NC.AskUser, etc.  If arg is an open win, use that.  If displayed card, then use its window.  If notefile, then use its notefile icon if open.  Last hope is to use the session icon if open.  Returning nil means that main prompt window will have to be used.")
          
          (* ;; "pmi 2/26/88: Now the session icon may be used even if it is shrunken.  Also now checks that a card is both valid and displayed before returning it.")

    (DECLARE (GLOBALVARS NC.NoteCardsIconWindow))
    (LET (Card NoteFile)
         (COND
            ((OPENWP WinOrCardOrNoteFile)
             WinOrCardOrNoteFile)
            [(AND (type? NoteFile WinOrCardOrNoteFile)
                  (OPENWP (NCP.NoteFileIconWindow WinOrCardOrNoteFile]
            ((AND (OR (NC.CardP WinOrCardOrNoteFile)
                      (TEXTSTREAMP WinOrCardOrNoteFile))
                  (NCP.ValidCardP (SETQ Card (NC.CoerceToCard WinOrCardOrNoteFile)))
                  (NCP.CardDisplayedP Card))
             (NC.FetchWindow Card))
            [(AND (NCP.ValidCardP Card)
                  (SETQ NoteFile (fetch (Card NoteFile) of Card))
                  (OPENWP (NCP.NoteFileIconWindow NoteFile]
            ((OPENWP NC.NoteCardsIconWindow))
            [(OPENWP (WINDOWPROP NC.NoteCardsIconWindow 'ICONWINDOW]
            (T NIL])
)
(PUTPROPS PMIPATCH092 COPYRIGHT ("Xerox Corporation" 1988))
(DECLARE%: DONTCOPY
  (FILEMAP (NIL (2480 11841 (NC.MakeDocument 2490 . 11839)) (11884 23179 (NC.MakeBrowserCard 11894 . 
23177)) (23218 32442 (NCP.SelectCards 23228 . 24706) (NCP.CreateCard 24708 . 27614) (
NCP.CreateBrowserCard 27616 . 30498) (NCP.MakeDocument 30500 . 32440)) (32479 36962 (NC.MakeNoteCard 
32489 . 36960)) (37003 43591 (NC.NoteFileIconButtonEventFn 37013 . 43589)) (43628 53971 (NC.MakeLink 
43638 . 53969)) (54012 55579 (NC.CoerceToInterestedWindow 54022 . 55577)))))
STOP