;;; -*- Mode:Common-Lisp; Package:NEWS; Base:10; Fonts:(CPTFONT HL12B HL12I MEDFNB) -*-


;1;; The tv:auto-scrolling-mixin was included so scrolling will start from the bottom up instead of*
;1;; top down.  The lisp-listener window scrolls from the bottom up.  The default lisp-interactor*
;1;; is supposed to be the same as the lisp-listener but it scrolls from the top down.*
(defflavor 4EXPLORER-NEWS*
	   ((news-initialize-check nil)		;1When T then execute the method (Explorer-News :after :expose).*
	    (tv:deexposed-typeout-action *deexposed-typeout-action*))
      (tv:auto-scrolling-mixin tv:lisp-interactor)
  :GETTABLE-INSTANCE-VARIABLES
  :SETTABLE-INSTANCE-VARIABLES
  :INITTABLE-INSTANCE-VARIABLES
  (:DEFAULT-INIT-PLIST :FONT-MAP (LIST *default-font*))
  (:documentation "Explorer News window"))


(defmethod 4(EXPLORER-NEWS :AFTER :INIT*) (&rest ignore)
  (setf *en* self)
  (process-preset tv:process 'explorer-news-window self)
  (send tv:process :run-reason self))


;1;;If the news system must be reinitialized then restart the program.  This will prevent the user from*
;1;;changing important news variables (i.e. newsrc file, news host) without reinitializing the news system.*

(defmethod 4(EXPLORER-NEWS :AFTER :EXPOSE*) (&rest ignore)
  (when news-initialize-check
    (cond
      ((news-initialized-p)
       (reset-news-daemon :start))
      (t
       (process-preset tv:process 'explorer-news-window self)
       (send tv:process :run-reason self)))))


;1;;Causes the who line to be updated.*
(defmethod 4(EXPLORER-NEWS :AFTER :SELECT*) (&rest ignore)
  (tv:mouse-wakeup))


(defmethod 4(EXPLORER-NEWS :WHO-LINE-DOCUMENTATION-STRING*) ()
  *who-line-message*)


(defun 4EXPLORER-NEWS-WINDOW* (window)
  "2Run EN in an Explorer news window.*"
  
  (let ((*terminal-io* window))
    (news:en1)))
  

(defun 4FIND-OR-CREATE-EN-WINDOW* ()
  (dolist (sh (w:sheet-inferiors w:default-screen) (w:make-window 'Explorer-News)); :activate-p t))
    (and (typep sh 'Explorer-News) (return sh))))


;1;;*
;1;; Add to system key and system menu.*
;1;;*
;1;;I have to go through these steps to get the Explorer news program to show up in the system menu.*
(w:add-to-system-menu-column :programs "2Explorer News*"
			   '(en)
			   "2manage network news.*"
			   :sorted)
(w:delete-from-system-menu-column :programs "2Explorer News*")
(w:add-to-system-menu-column :programs "2Explorer News*"
			   '(en)
			   "2manage network news.*"
			   :sorted)
(format t "~2%Note:  Explorer news added to the system menu.")

(cond
  ((assoc #\N tv:*system-keys*)
   (format t "~%Warning:  System-N already bound.  Use the function (w:add-system-key #\\<char> '(news:en) \"\")~%to bind Explorer news to some other system key."))
  (t
   (w:add-system-key #\N '(en) "Explorer news - manage network news." t)
   (format t "~%Note:  Explorer news bound to System-N.")))

(format t "~2%")
