;;; -*- Mode:Lisp; Readtable:ZL; Package:USER; Base:8; Patch-File:T -*-
;;; Patch file for Kermit version 36.5
;;; Reason:
;;;  Consolidate redundant menu options.
;;;  
;;;  Server/Send is gone; it executed the same function as Send Files, and only sends files.
;;;  
;;;  Server/Bye is gone. Server/Finish now works as follows:
;;;    * With a left mouse-click, it just finishes.
;;;    * With a middle mouse-click, it finishes and logs out.
;;;    * With a right click, it offers a menu to choose between
;;;      "Just Finish" or "Finish and Log Out".  Moving away from
;;;      the menu without choosing causes neither option to be taken.
;;; Written 20-Jul-88 19:16:30 by keith (Keith Corbett) at site Gigamos Cambridge
;;; while running on Breaking Glass from band 1
;;; with System 125.7, ZWEI 125.2, ZMail 73.0, Local-File 75.0, File-Server 24.0, Unix-Interface 13.0, Tape 24.0, Lambda-Diag 17.0, Experimental Window-Maker 2.0, Experimental Kermit 36.4, microcode 1761, SDU Boot Tape 3.14, SDU ROM 103, 7/19.



; From modified file DJ: L.NETWORK.KERMIT; WINDOW.LISP#82 at 20-Jul-88 19:16:34
#8R KERMIT#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "KERMIT")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERMIT; WINDOW  "

			    
(defconst all-kermit-command-pane-items
      '(("Connect" :funcall make-connection
	 :documentation "Establish a virtual terminal or Kermit connection with remote host.")

	("Disconnect" :funcall close-connection
	   :documentation "Interrupt the connection made by Connect.")

	("Send files" :funcall send-files
	   :documentation "Send files to a remote Kermit.")

	("Receive files" :funcall receive-files
	   :documentation "Receive files from a remote Kermit.")

	;;Removed - redundant with Send Files
	;;("Server//send" :funcall send-files
	;;   :documentation "Send files to a remote Kermit (same as Send Files).")

	("Server//receive" :funcall receive-files-from-server
	   :documentation "Receive files from a remote Kermit that's in Server mode.")

	("Server//finish" :buttons ;;Used to be :funcall finish-server
	 ((nil :funcall finish-server
	       :documentation "Finish with server; don't logout.")
	  (nil :funcall bye-server
	       :documentation "Finish with server and logout.")
	  (nil :funcall finish-server-maybe-logout
	       :documentation "Choose from menu how to finish with server: Just Finish or Finish and Logout"))
	 :documentation "Finish with Kermit that's in Server mode.  L:Just Finish, M:Finish and Logout, R:Menu.")

	;;Folded into Server Finish  as mouse-middle option
	;;("Server//bye" :funcall bye-server
	;; :documentation "Finish and be logged out by remote Kermit that's in Server mode.")

	("Remote Login Server"
	 :funcall be-a-server
	 :documentation "Put Kermit in mode to process remote logins and file transfers.")

	("Kermit Server"
	 :funcall be-a-kermit-server-only
	 :documentation "Put Kermit directly into Kermit SERVER mode (wait for Kermit commands).")

	("Serial Port" :funcall set-baud-rate
	   :documentation "Set parameters for serial port.")

;	("Restart Program" :funcall restart-program
;	   :documentation "Abandon everything  and start Kermit from scratch.")

	("Review Parameters" :funcall review-parameters
	   :documentation "Review, and maybe modify, global Kermit parameters.")


;	("Refresh Windows" :funcall refresh-windows
;	   :documentation "Refresh all the windows in this display.")

;	("List directory" :funcall list-user-directory
;	   :documentation "List the default directory in the interaction pane.")

	("Configure Window" :funcall switch-configurations
	 :documentation "Toggle between window configurations.")

	("Help" :funcall kermit-interactive-help
	 :documentation "Interactive Help for Kermit.")


	))


;;;User interaction

))

; From modified file DJ: L.NETWORK.KERMIT; WINDOW.LISP#82 at 20-Jul-88 19:16:49
#8R KERMIT#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "KERMIT")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERMIT; WINDOW  "


(defun finish-server-maybe-logout (&optional logout)
  (setq logout
	(or logout
	    (multiple-value-bind (choice item-chosen)
		(tv:menu-choose '(("Just Finish" :value nil)("Finish and Logout" :value T))
				"Choose one")
	      (if item-chosen choice
		(return-from finish-server-maybe-logout nil)))))
  (if logout
      (bye-server)
    (finish-server)))

;;;; Bye

))

; From modified file DJ: L.NETWORK.KERMIT; WINDOW.LISP#82 at 20-Jul-88 19:16:52
#8R KERMIT#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "KERMIT")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERMIT; WINDOW  "


(defvar *kermit-last-mouse-buttons* :unbound
  "Value from :menu blip of mouse button mask when Kermit command was pressed")

))

; From modified file DJ: L.NETWORK.KERMIT; WINDOW.LISP#82 at 20-Jul-88 19:16:55
#8R KERMIT#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "KERMIT")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERMIT; WINDOW  "


(defmethod (kermit-frame :top-level) (kermit-frame)
  (let ((status-pane (funcall kermit-frame :get-pane 'status-pane))
	(command-pane (funcall kermit-frame :get-pane 'command-pane))
	(interaction-pane (funcall kermit-frame :get-pane 'interaction-pane))
	(terminal-pane (funcall kermit-frame :get-pane 'terminal-pane))
	(terminal-io-syn-stream (make-syn-stream 'terminal-io))
	(*kermit-last-mouse-buttons* nil)
	(*sdu-serial-default-baud-rate* *sdu-serial-default-baud-rate*)
	(*sdu-serial-xon-xoff-p* *sdu-serial-xon-xoff-p*)
	(*sdu-serial-ascii-p* NIL)		;For now, Kermit controls Ascii translation
	)
    (let ((terminal-io interaction-pane)
	  (standard-input terminal-io-syn-stream)
	  (standard-output terminal-io-syn-stream)
	  (query-io terminal-io-syn-stream)
	  (trace-output terminal-io-syn-stream)
	  (error-output terminal-io-syn-stream)
	  (debug-io terminal-io-syn-stream)
	  (ibase 10.)
	  (base 10.)
	  )
      
      ;; if kermit is not yet ready to accept commands, either because it is
      ;; just being started up or because a reset or warm boot has been done
      ;; before it was ready for commands, do various initialization actions.
      
      (cond
	((not kermit-ready-for-commands?)
	 
	 (setq kterm-state (make-instance 'kterm-state))
	 (setq kstate				;have kstate bound to a kstate instance
	       (progn
		 (fs:force-user-to-login)	;default-pathname setup depends on user
		 (make-instance 'kstate)	;  being logged in!
		 ))
	 (setf kermit-ready-for-commands? t)))      
      ;;;
      ;; this is kermit's top-level command execution loop.      
      ;;
      (error-restart-loop (sys:abort "Restart kermit process")
	(loop as character = (funcall terminal-io :any-tyi)	      
	      as command?
	      = (when (and (not (atom character))
			   (eq (first character) :menu))
		  (setq *kermit-last-mouse-buttons* (third character))
		  (second character))
	      doing
	      (cond
		((memq (get command? :funcall) all-commands-requiring-kermit-serial-stream)
		 (or kermit-serial-stream
		     (setq kermit-serial-stream (eval serial-stream-open-form)))
		 (if (eq (funcall command-pane :execute command?) :close)
		     (send self :close-serial-stream)))
		(command?
		 (funcall command-pane :execute command?))
		((not (atom character))
		 (beep-at-user))
		((= character #\hand-down)
		 (send kermit-frame ':set-configuration 'long-terminal)
		 (setq debug-io terminal-pane))
		((= character #\hand-up)
		 (send kermit-frame ':set-configuration 'default)
		 (setq debug-io terminal-io-syn-stream)
		 (send kermit-frame :refresh))
		('else
		 (handle-unanticipated-terminal-input character))))))))

))
