(FILECREATED "15-Jan-86 15:42:17" {QV}<NOTECARDS>1.3K>FGHPATCH013.;1 10801  

      changes to:  (VARS FGHPATCH013COMS)
		   (FNS NC.SelectNoteCards))


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

(PRETTYCOMPRINT FGHPATCH013COMS)

(RPAQQ FGHPATCH013COMS ((* * REdefined from NCINTERFACE to account for SPAWN.MOUSE problems)
			  (FNS NC.SelectNoteCards)))
(* * REdefined from NCINTERFACE to account for SPAWN.MOUSE problems)

(DEFINEQ

(NC.SelectNoteCards
  (LAMBDA (SingleCardFlg SelectionPredicate Menu InstigatingCardOrWindow ReturnLinksFlg Msg 
			 CheckForCancelFlg)                  (* fgh: "15-Jan-86 15:38")

          (* 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.)



          (* * rht 8/1/84: Changed second RESETSAVE call to give NC.ClearMsg a NIL argument.)



          (* * rht 1/9/85: Fixed so now prints name of selected item even it's a link.)



          (* * rht 2/15/85: Now can backspace over last selection chosen. Added new arg Msg so that when we reprint the list,
	  we can reprint the message as well.)



          (* * rht 3/23/85: Added the CheckForCancelFlg arg, which if non-nil causes Cancel to be handled differently then 
	  Done after no selections. Namely, Cancel will return the atom CANCELLED whereas Done with no selections returns 
	  NIL. If CheckForCancelFlg is NIL then NIL is returned in both cases.)



          (* * fgh 11/14/85 Updated to handle Card and NoteFile objects.)



          (* * rht 11/18/85: Fixed so able to select when InstigatingNoteFile is NIL.)



          (* * fgh 12/20/85 Totally rewritten for 1.3 selection mechanism. Based on COPYINSERT now rather than on takingf 
	  over the mouse process.)



          (* * fgh 1/15/86 Added call to SPAWN.MOUSE in case this is called under the mouse process)


    (RESETLST (LET (Window Card ButtonEventFn InstigatingWindow InstigatingCard InstigatingNoteFile 
			     MenuWindow PromptWindow CopyInsertEvent SelectedCards 
			     PromptWindowProcess)
		     (OR SelectionPredicate (SETQ SelectionPredicate (FUNCTION TRUE)))
		     (COND
		       ((NC.CardP InstigatingCardOrWindow)
			 (SETQ InstigatingWindow (NC.FetchWindow InstigatingCardOrWindow)))
		       ((WINDOWP InstigatingCardOrWindow)
			 (SETQ InstigatingWindow InstigatingCardOrWindow))
		       (T (SETQ InstigatingWindow NIL)))
		     (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 selected:  ")

          (* * if we are running under the mouse process, start up a new mouse process)


		     (AND (EQ (QUOTE MOUSE)
				  (PROCESSPROP (THIS.PROCESS)
						 (QUOTE NAME)))
			    (SPAWN.MOUSE))

          (* * Set up the prompt window for proper use by the CopyInsertFn)


		     (SETQ PromptWindow (if InstigatingWindow
					      then (GETPROMPTWINDOW InstigatingWindow)
					    else PROMPTWINDOW))
		     (WINDOWPROP PromptWindow (QUOTE COPYINSERTFN)
				   (FUNCTION NC.SelectNoteCardsCopyInsertFn))
		     (WINDOWPROP PromptWindow (QUOTE CopyInsertEvent)
				   (SETQ CopyInsertEvent (CREATE.EVENT (QUOTE CopyInsertEvent)))
				   )
		     (RESETSAVE (WINDOWPROP PromptWindow (QUOTE SelectedCards)
						NIL)
				  (BQUOTE (WINDOWPROP , PromptWindow (QUOTE SelectedCards)
							  NIL)))
		     (RESETSAVE (WINDOWPROP PromptWindow (QUOTE SelectingCards)
						T)
				  (BQUOTE (WINDOWPROP , PromptWindow SelectingCards NIL)))

          (* * Make the process behind the prompt window includiong control for a blibnking cursor)


		     (WINDOWPROP PromptWindow (QUOTE PROCESS)
				   (SETQ PromptWindowProcess
				     (ADD.PROCESS (QUOTE (PROG NIL (BLOCK)
								     (TTYDISPLAYSTREAM
								       (PROCESSPROP (THIS.PROCESS)
										      (QUOTE WINDOW)
										      ))
								     XXXX
								     (BIN)
								     (BLOCK)
								     (GO XXXX)))
						    (QUOTE WINDOW)
						    PromptWindow
						    (QUOTE NAME)
						    (QUOTE SelectNoteCardsProc)
						    (QUOTE TTYENTRYFN)
						    (FUNCTION (LAMBDA (Process)
							(PROCESSPROP Process (QUOTE OldCaret)
								       (CARET CROSSHAIRS))
							(ECHOMODE)))
						    (QUOTE TTYEXITFN)
						    (FUNCTION (LAMBDA (Process)
							(CARET (PROCESSPROP Process (QUOTE
										  OldCaret)))
							(ECHOMODE T))))))
		     (RESETSAVE NIL (BQUOTE (DEL.PROCESS , PromptWindowProcess)))

          (* * Insure the prompt window is cleared on the way out)


		     (RESETSAVE NIL (BQUOTE (PROGN (AND (HASTTYWINDOWP , 
									      PromptWindowProcess)
								(TTY.PROCESS T))
							 (NC.ClearMsg , InstigatingWindow T))))

          (* * 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)))
		     (RESETSAVE (ATTACHMENU Menu PromptWindow (if InstigatingWindow
								      then (QUOTE TOP)
								    else (QUOTE BOTTOM))
						(QUOTE LEFT))
				  (BQUOTE (PROGN (DETACHWINDOW (WFROMMENU , Menu))
						     (DELETEMENU , Menu T))))

          (* * 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 (QUOTE PROCESS)))

          (* * Loop as long as necessary)


		     (until (OR (EQ SelectedCards (QUOTE CANCELLED))
				    (AND SingleCardFlg SelectedCards)
				    (EQ (CAR SelectedCards)
					  (QUOTE DONE)))
			do 

          (* * Wait for the user to respond by copy inserting something into the prompt window)


			     (AWAIT.EVENT CopyInsertEvent) 

          (* * Get the latest selection list)


			     (SETQ SelectedCards (WINDOWPROP PromptWindow (QUOTE SelectedCards))
			       )
			     (RESETLST 

          (* * Turn off the caret)


					 (RESETSAVE (TTY.PROCESS (THIS.PROCESS)))

          (* * If the last thing wasn't a done or cancel, process the new selection)


					 (if (AND (NEQ (CAR SelectedCards)
							     (QUOTE DONE))
						      (NEQ SelectedCards (QUOTE CANCELLED))
						      (NEQ (CAR SelectedCards)
							     (QUOTE *New% Card*)))
					     then 

          (* * Check to make sure that the selection is valid)


						    (COND
						      ((EQ (CAR SelectedCards)
							     (QUOTE *Undo% Selection*))
                                                             (* Chop off two elements from the list -
							     the indicator and the previous item.)
							(WINDOWPROP PromptWindow (QUOTE 
										    SelectedCards)
								      (SETQ SelectedCards
									(CDDR SelectedCards)))
							(NC.ClearMsg InstigatingWindow NIL))
						      ((AND InstigatingNoteFile (CAR 
										    SelectedCards)
							      (NOT (NC.SameNoteFileP
								       (fetch (Card NoteFile)
									  of (CAR SelectedCards))
								       InstigatingNoteFile)))
                                                             (* This card not from the same NoteFile)
							(NC.PrintMsg InstigatingWindow T 
								     "*** Invalid selection. ***"
								       (CHARACTER 13))
							(WINDOWPROP PromptWindow (QUOTE 
										    SelectedCards)
								      (SETQ SelectedCards
									(CDR SelectedCards))))
						      ((NULL (APPLY* SelectionPredicate
									 (CAR SelectedCards)))
                                                             (* Does this card match the slection predicate)
							(NC.PrintMsg InstigatingWindow T 
								     "*** Invalid selection. ***"
								       (CHARACTER 13))
							(WINDOWPROP PromptWindow (QUOTE 
										    SelectedCards)
								      (SETQ SelectedCards
									(CDR SelectedCards))))
						      (T     (* A valid selection.)
							 (NC.ClearMsg InstigatingWindow NIL)))

          (* * Print the results in the prompt window)


						    (NC.PrintMsg InstigatingWindow NIL
								   (COND
								     (Msg (CONCAT Msg (CHARACTER
										      13)))
								     (T ""))
								   "Items selected:  ")
						    (for Card in (REVERSE SelectedCards)
						       do (NC.PrintMsg InstigatingWindow NIL
									   (NC.RetrieveTitle Card)
									   ",  ")))))

          (* * Return the result)


		     (PROG1 (COND
				((EQ SelectedCards (QUOTE CANCELLED))
				  (COND
				    (CheckForCancelFlg (QUOTE CANCELLED))
				    (T NIL)))
				(SingleCardFlg (if (EQ (CAR SelectedCards)
							   (QUOTE DONE))
						   then NIL
						 else (CAR SelectedCards)))
				(T (if (EQ (CAR SelectedCards)
					       (QUOTE DONE))
				       then (DREVERSE (CDR SelectedCards))
				     else (DREVERSE SelectedCards))))
			      (WINDOWPROP PromptWindow (QUOTE SelectedCards)
					    NIL))))))
)
(PUTPROPS FGHPATCH013 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (464 10719 (NC.SelectNoteCards 474 . 10717)))))
STOP