(FILECREATED " 5-Jun-87 12:25:16" {QV}<NOTECARDS>1.3K>NEXT>RGPATCH045.;1 6011   

      changes to:  (VARS RGPATCH045COMS)
		   (FNS NC.CheckForExpandIndex))


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

(PRETTYCOMPRINT RGPATCH045COMS)

(RPAQQ RGPATCH045COMS ((* * rg 6/5/87 several bugs fixed: now only offers to expand if index is 
			    completely full; clears prompt window on cancel; menu allows other mouse 
			    events)
			 (* * changes to NCDATABASE)
			 (FNS NC.CheckForExpandIndex)))
(* * rg 6/5/87 several bugs fixed: now only offers to expand if index is completely full; 
clears prompt window on cancel; menu allows other mouse events)

(* * changes to NCDATABASE)

(DEFINEQ

(NC.CheckForExpandIndex
  [LAMBDA (NoteFile QuietFlg InterestedWindow)               (* Randy.Gobbel " 5-Jun-87 12:21")

          (* * If index is full, then confirm with user whether it's okay to expand in place. Offer user ability to change 
	  the amount to expand by. Return nil if no expand, return new index size otherwise. We MUST expand otherwise error 
	  out.)



          (* * rht 5/24/87: Now passes QuietFlg to NC.ExpandIndexInPlace.)



          (* * rg 6/3/87 call to Checkpoint wasn't checking for DON'T)



          (* * rg 6/5/87 now only offers to expand if completely full, plus misc other small fixes)


    (DECLARE (GLOBALVARS NC.IndexFractionToExpandBy NC.MenuFont))
    (OR InterestedWindow (SETQ InterestedWindow (NC.CoerceToInterestedWindow NoteFile)))
    (LET [(IndexSize (fetch (NoteFile HashArraySize) of NoteFile))
	  (NumUsed (SUB1 (DIFFERENCE (fetch (NoteFile NextIndexNum) of NoteFile)
					 (LENGTH (fetch (NoteFile IndexNumsFreeList)
						      of NoteFile]
         (if (EQ NumUsed IndexSize)
	     then (LET ([Menu (create MENU
					  TITLE ← " Expand notefile index? "
					  CENTERFLG ← T
					  MENUBORDERSIZE ← 1
					  MENUOUTLINESIZE ← 1
					  MENUROWS ← 1
					  MENUFONT ← NC.MenuFont
					  ITEMHEIGHT ← (IPLUS 10 (FONTPROP NC.MenuFont
									       (QUOTE HEIGHT)))
					  MENUTITLEFONT ← (FONTCREATE (QUOTE HELVETICA)
									10
									(QUOTE BOLD))
					  ITEMS ← (QUOTE ((Yes (QUOTE Yes)
								 
					  "Go ahead and expand index to make room for new cards.")
							     (Cancel (QUOTE Cancel)
								     "Cancel creation of new card.")
							     (Change% Num (QUOTE Change% Num)
									  
					     "Change the number of new cards to expand index by."]
			  (PromptWindow (OR (NC.AttachPromptWindow InterestedWindow)
					      PROMPTWINDOW))
			  NewIndexSize NumNewSlots NewNum ActualNumNewSlots)
		         [SETQ NewIndexSize (PLUS IndexSize (SETQ NumNewSlots
							(FIX (FTIMES IndexSize 
								       NC.IndexFractionToExpandBy]
		         (for
			    do (NC.PrintMsg InterestedWindow T (CONCAT (fetch (NoteFile
											FullFileName)
										of NoteFile)
									     " is full (" NumUsed 
									     " out of "
									     IndexSize 
									     " cards used)."
									     (CHARACTER 13)))
				 (NC.PrintMsg InterestedWindow NIL (CONCAT 
						 "Okay to checkpoint notefile and make room for "
									       NumNewSlots 
									       " new cards?"
									       (CHARACTER 13)))
				 (ALLOW.BUTTON.EVENTS)
				 (SELECTQ (MENU Menu (CREATEPOSITION (fetch (REGION LEFT)
									      of (WINDOWREGION
										     PromptWindow))
									   (fetch (REGION TOP)
									      of (WINDOWREGION
										     PromptWindow)))
						    T)
					    (Yes             (* Go ahead and expand index after checkpointing 
							     notefile.)
						 (if (EQ (NC.CheckpointNoteFile
							       NoteFile NIL NIL InterestedWindow
							       (CONCAT "Expanding notefile index"
									 (CHARACTER 13)))
							     (QUOTE DON'T))
						     then (NC.ClearMsg InterestedWindow T)
							    (ERROR!))
						 (SETQ ActualNumNewSlots
						   (NC.ExpandIndexInPlace NoteFile NewIndexSize NIL 
									    InterestedWindow NIL 
									    QuietFlg))
						 (COND
						   ((NULL ActualNumNewSlots)
                                                             (* Looks like NC.ExpandIndexInPlace bombed for some 
							     reason.)
						     (FLASHW PROMPTWINDOW)
                                                             (* If index is full, we have to bail out of card 
							     creation.)
						     (NC.PrintMsg NIL T 
				      "Couldn't expand index.  Card creation operation canceled.")
						     (ERROR!))
						   ((LESSP ActualNumNewSlots NumNewSlots)
                                                             (* NC.ExpandIndexInPlace probably bombed but we at 
							     least got some of what we asked for.)
						     (FLASHW PROMPTWINDOW)
						     (NC.PrintMsg NIL T 
								    "Only able to make room for "
								    ActualNumNewSlots 
								    " new cards out of "
								    NumNewSlots " requested." NIL)))
						 (NC.ClearMsg InterestedWindow T)
						 (RETURN NewIndexSize))
					    (Cancel          (* Bad news. We have to bail out because index is 
							     full.)
						    (NC.ClearMsg InterestedWindow T)
						    (ERROR!))
					    [Change% Num     (* Let user change number of new slots to make room 
							     for.)
							 (SETQ NewNum
							   (RNUMBER "Number of new cards to add" 
								      NIL NIL NIL T))
							 (if (AND (NUMBERP NewNum)
								      (GREATERP NewNum 0))
							     then (SETQ NewIndexSize
								      (PLUS IndexSize (SETQ 
										NumNewSlots NewNum]
					    NIL])
)
(PUTPROPS RGPATCH045 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (725 5930 (NC.CheckForExpandIndex 735 . 5928)))))
STOP