;;; -*- Mode:Lisp; Readtable:ZL; Package:USER; Base:8; Patch-File:T -*-
;;; Patch file for System version 126.6
;;; Reason:
;;;  System-Help now prints keystroke characters with a remark.
;;;  Example:   (Top-L)
;;; Written 1-Aug-88 13:00:16 by pld (Peter L. DeWolf) at site Gigamos Cambridge
;;; while running on Azathoth from band 1
;;; with Experimental System 126.5, ZWEI 125.7, ZMail 73.0, Local-File 75.1, File-Server 24.0, Unix-Interface 13.0, Tape 24.2, Lambda-Diag 17.0, microcode 1762, SDU Boot Tape 3.14, SDU ROM 8, the old ones.



; From modified file DJ: L.WINDOW; BASSTR.LISP#416 at 1-Aug-88 13:00:18
#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~16T~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))

))
