Silas Vedder
2 years ago
6 changed files with 262 additions and 116 deletions
@ -1,56 +1,79 @@
|
||||
(in-package #:cl-bible.chapter) |
||||
|
||||
(defun book/chapter-window (canvas title) |
||||
(defclass chapter () |
||||
((%verses :initarg :verses |
||||
:reader verses))) |
||||
|
||||
(defgeneric chapter-to-clog (chapter parent &key translation)) |
||||
(defgeneric book/chapter-window (canvas title)) |
||||
(defgeneric translations-drop-down (div display chapter drop-down)) |
||||
(defgeneric display-chapter-or-book (canvas title chapter)) |
||||
(defgeneric load-chapter (canvas book chapter)) |
||||
(defgeneric load-book (canvas book)) |
||||
|
||||
(defmethod chapter-to-clog ((chapter chapter) (parent clog:clog-obj) &key (translation :mng)) |
||||
(labels ((verse-to-clog (verse) |
||||
;;; (clog:set-on-click |
||||
(v:verse-to-clog verse parent :translation translation) |
||||
;;; (lambda (obj) |
||||
;;; (declare (ignore obj)) |
||||
;;; (v::show-notes verse parent))) |
||||
)) |
||||
(mapcar #'verse-to-clog (verses chapter)))) |
||||
|
||||
(defmethod book/chapter-window (canvas (title string)) |
||||
(let* ((win (window-content |
||||
(create-gui-window canvas |
||||
:title title |
||||
:height 400 |
||||
:width 650))) |
||||
:width 500))) |
||||
(mbar (create-gui-menu-bar win)) |
||||
(drop-down (create-gui-menu-drop-down mbar :content "Translations"))) |
||||
(values (create-div win) |
||||
drop-down))) |
||||
|
||||
(defun translations-drop-down (div display verses drop-down) |
||||
(defmethod translations-drop-down ((div clog:clog-div) display (chapter chapter) drop-down) |
||||
(mapcar |
||||
(lambda (translation) |
||||
(labels ((verse-to-clog (verse) |
||||
(v:verse-to-clog verse |
||||
div |
||||
:translation (second translation))) |
||||
(hide-verse (verse) (setf (hiddenp verse) t)) |
||||
(callback (obj) |
||||
(labels ((callback (obj) |
||||
(declare (ignore obj)) |
||||
(mapc #'hide-verse display) |
||||
(setf display (mapcar #'verse-to-clog verses)))) |
||||
(d:update-bible (third translation)))) |
||||
(create-gui-menu-item drop-down |
||||
:content (first translation) |
||||
:on-click #'callback))) |
||||
d:*translations*)) |
||||
|
||||
(defun display-chapter-or-book (canvas title verses) |
||||
(defmethod display-chapter-or-book (canvas (title string) (chapter chapter)) |
||||
(multiple-value-bind (div drop-down) |
||||
(book/chapter-window canvas title) |
||||
(flet ((verse-to-clog (verse) |
||||
(v:verse-to-clog verse |
||||
div |
||||
:translation d:*translation*))) |
||||
(let ((display (mapcar #'verse-to-clog verses))) |
||||
(translations-drop-down div display verses drop-down))))) |
||||
|
||||
(defun load-chapter (canvas book chapter) |
||||
(let ((display (chapter-to-clog chapter div :translation d:*translation*))) |
||||
(translations-drop-down div display chapter drop-down)))) |
||||
|
||||
(defmethod load-chapter (canvas (book string) (chapter string)) |
||||
(let* ((bk (s:find-book d:*bible* book)) |
||||
(verses (if (find #\- chapter) |
||||
(loop :for chap :in (uiop:split-string chapter :separator '(#\-)) |
||||
:append (s:find-chapter bk chap)) |
||||
(s:find-chapter bk chapter)))) |
||||
(display-chapter-or-book canvas |
||||
(format nil "~A: ~A ~A" |
||||
d:*translation* |
||||
book |
||||
chapter) |
||||
(s:find-chapter |
||||
(s:find-book d:*bible* book) |
||||
chapter))) |
||||
(make-instance 'chapter :verses verses)))) |
||||
|
||||
(defun load-book (canvas book) |
||||
(defmethod load-book ((canvas clog:clog-body) (book string)) |
||||
(display-chapter-or-book canvas |
||||
(format nil "~A: ~A" |
||||
d:*translation* |
||||
book) |
||||
(s:find-book d:*bible* book))) |
||||
(make-instance 'chapter |
||||
:verses (s:find-book d:*bible* book)))) |
||||
|
||||
(defmethod load-position ((canvas clog:clog-body) (pos string)) |
||||
(display-chapter-or-book canvas |
||||
(format nil "~A: ~A" |
||||
d:*translation* |
||||
pos) |
||||
(make-instance 'chapter |
||||
:verses (s:find-verse d:*bible* (s:parse-position pos))))) |
||||
|
Loading…
Reference in new issue