;;; -*- Mode:Lisp; Readtable:ZL; Package:USER; Base:8; Patch-File:T -*-
;;; Patch file for System version 124.1
;;; Reason:
;;;  tv:*system-keys* was initialized to a set of windows that supposedly would
;;;  always be in the system.  Well, we removed FED, and now System-F gives you
;;;  an error.  Several fixes:
;;;    - System-Help won't list known-to-be-absent flavors
;;;    - System-<x> beeps, not bombs, on absent flavors
;;;    - (tv:add-system-key) won't add an entry that is (equal) to
;;;      an existing entry.
;;;    - the various system-keys are now created when the file
;;;      defining the window is loaded.
;;; Written 23-May-88 16:10:48 by pld (Peter L. DeWolf) at site Gigamos Cambridge
;;; while running on Azathoth from band 2
;;; with Experimental System 124.0, Experimental Local-File 74.0, Experimental File-Server 23.0, Experimental Unix-Interface 12.0, Experimental ZMail 72.0, Experimental Tape 23.0, Experimental Lambda-Diag 16.0, microcode 1756, SDU Boot Tape 3.14, SDU ROM 8.



; From modified file DJ: L.WINDOW; BASSTR.LISP#413 at 23-May-88 16:10:52
#8R TV#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "TV")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: WINDOW; BASSTR  "

(DEFUN ADD-SYSTEM-KEY (CHAR WINDOW-OR-FLAVOR DOCUMENTATION &OPTIONAL (CREATE T))
  "Make typing the System key followed by CHAR select the window WINDOW-OR-FLAVOR.
WINDOW-OR-FLAVOR may be:
  an actual window
  a name of a flavor of window
  a list to evaluate to get a window or a flavor name.
CREATE says whether and how to create a new window if Control-char is pressed.
  It may be:
  T meaning create a window of flavor PROGRAM, or
  the name of a flavor to create, or
  a list to evaluate for effect, to create and select a window.
If CHAR is already defined to select a flavor window, then the old version is
  remembered. To restore the former definition, use (TV:REMOVE-SYSTEM-KEY CHAR)"
  (PUSHNEW (LIST (CHAR-UPCASE (GLOBAL:CHARACTER CHAR)) WINDOW-OR-FLAVOR DOCUMENTATION CREATE)
	   *SYSTEM-KEYS*
	   :TEST #'EQUAL)
  (SETQ *SYSTEM-KEYS* (STABLE-SORTCAR *SYSTEM-KEYS* #'ALPHALESSP)))

))

; From modified file DJ: L.WINDOW; BASSTR.LISP#413 at 23-May-88 16:11:01
#8R TV#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "TV")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: WINDOW; BASSTR  "

(DEFUN KBD-SYS-1 (CH &AUX E W SW MAKENEW FLAVOR-OR-WINDOW SW-ALIAS)
  (SETQ MAKENEW (CHAR-BIT CH :CONTROL)
	CH (CHAR-CODE CH))
  (COND ((OR (= CH #/?) (= CH #/HELP))
	 (USING-RESOURCE (WINDOW POP-UP-FINGER-WINDOW)
	   (SETF (SHEET-TRUNCATE-LINE-OUT-FLAG WINDOW) 0)
	   (SEND WINDOW :SET-LABEL "Keyboard system commands")
	   (WINDOW-CALL (WINDOW :DEACTIVATE)
	     (FORMAT WINDOW
		     "Type ~:@C followed by one of these characters to select the ~
                      corresponding program:~2%" #/SYSTEM)
	     (LET ((LIST (SORTCAR (COPY-LIST *SYSTEM-KEYS*) #'ALPHALESSP)) (TEM #/?))
	       (DOLIST (X LIST)
		 (OR (CHAR-EQUAL TEM (SETQ TEM (first X)))	;Skip duplicates
		     (and (atom (second x))	                ;Skip invalid flavors
			  (not (get (second x) 'si:flavor)))
		     (FORMAT WINDOW "~&~C~8T~A" TEM (third X)))))		 
	     (FORMAT WINDOW
	       "~2&Type ~:@C control-<character> to create a new window of a particular type.~@
                Type ~:@C after ~:@C to do nothing (if you typed ~:@C by accident).~%~@
		Type a space to flush: " #/SYSTEM #/RUBOUT #/SYSTEM #/SYSTEM)
	     (SETQ KBD-ESC-TIME NIL)		;Let kbd process proceed before we TYI.
	     (SEND WINDOW :TYI))))
	((SETQ E (ASSQ CH *SYSTEM-KEYS*))
	 ;; Find the most recently selected window of the desired type.
	 ;; If it is the same type as the selected window, make that the
	 ;; least recently selected so as to achieve the cycling-through effect.
	 ;; Otherwise the currently selected window becomes the most recently
	 ;; selected as usual, and terminal S will return to it.
	 ;; In any case, we must fake out :MOUSE-SELECT's typeahead action since
	 ;; that has already been properly taken care of and we don't want to snarf
	 ;; any characters already typed after the [SYSTEM] command.
	 (SETQ FLAVOR-OR-WINDOW
	       (IF (CONSP (SECOND E))
		   (EVAL (SECOND E))
		 (SECOND E)))
	 (DELAYING-SCREEN-MANAGEMENT	;Inhibit auto selection
	   (SETQ SW SELECTED-WINDOW)
	   (WHEN SW (SETQ SW-ALIAS (SEND SW :ALIAS-FOR-SELECTED-WINDOWS)))
	   (COND ((TYPEP FLAVOR-OR-WINDOW 'ESSENTIAL-WINDOW)
		  ;; If the *SYSTEM-KEYS* list has a specific window indicated, use that.
		  (AND SW (SEND SW :DESELECT NIL))
		  (SEND FLAVOR-OR-WINDOW :MOUSE-SELECT))
		 ((NULL FLAVOR-OR-WINDOW) NIL)	;NIL means he already did whatever he wanted.
		 ((not (get flavor-or-window 'si:flavor)) (beep))	;Invalid flavor
		 ((AND (NOT MAKENEW)
		       (SETQ W (FIND-WINDOW-OF-FLAVOR FLAVOR-OR-WINDOW)))
		  ;; Cycle through other windows of this flavor.
		  (WHEN SW (SEND SW :DESELECT (IF (TYPEP SW-ALIAS FLAVOR-OR-WINDOW) :END)))
		  (SEND W :MOUSE-SELECT))
		 ((AND (NOT MAKENEW) SW
		       (TYPEP SW-ALIAS FLAVOR-OR-WINDOW))
		  ;; There is only one window of this flavor, and this is it.
		  (BEEP))
		 ((NULL (FOURTH E)) (BEEP))	;Cannot create
		 ((ATOM (FOURTH E))
		  ;; Create a new window of this flavor.
		  ;; We create on the default screen.
		  (WHEN SW (SEND SW :DESELECT (IF (TYPEP SW-ALIAS FLAVOR-OR-WINDOW) :END)))
		  (LET ((FLAVOR (IF (EQ (FOURTH E) T) FLAVOR-OR-WINDOW (FOURTH E))))
		    (if (get flavor 'si:flavor)
			(SEND (MAKE-INSTANCE FLAVOR :SUPERIOR DEFAULT-SCREEN) :MOUSE-SELECT)
		      (beep))))
		 (T (EVAL (FOURTH E))))))
	(( CH #/RUBOUT) (BEEP)))
  (SETQ KBD-ESC-TIME NIL))

))

(unless (get 'fed:fed-frame 'si:flavor)
  (tv:remove-system-key #/F))