Fix minor bug

This commit is contained in:
Andros Fenollosa 2024-02-16 10:16:31 +01:00
parent e340419da5
commit 07c61db35f

View File

@ -96,6 +96,12 @@ Example: (lirve--shuffle '(1 2 3 4 5)) => (3 1 5 2 4)"
lirve--verbs lirve--verbs
))) )))
(defun lirve--is-win ()
"Return t if the state is win."
(and
(string= (lirve--value-field-simple-past) lirve--verb-to-learn-simple-past)
(string= (lirve--value-field-past-participle) lirve--verb-to-learn-past-participle)))
(defun lirve--full-path-unresolved () (defun lirve--full-path-unresolved ()
"Get the full path of the unresolved file." "Get the full path of the unresolved file."
(concat (file-name-directory user-init-file) lirve--file-name-unresolved)) (concat (file-name-directory user-init-file) lirve--file-name-unresolved))
@ -145,8 +151,7 @@ Example: (lirve--shuffle '(1 2 3 4 5)) => (3 1 5 2 4)"
(setq lirve--verb-to-learn-past-participle (alist-get 'past-participle verb-to-learn)) (setq lirve--verb-to-learn-past-participle (alist-get 'past-participle verb-to-learn))
(when (not (null (boundp 'learning-irregular-verbs-in-English--show-translation))) (setq lirve--translation (alist-get learning-irregular-verbs-in-English--show-translation (alist-get 'translations verb-to-learn)))) (when (not (null (boundp 'learning-irregular-verbs-in-English--show-translation))) (setq lirve--translation (alist-get learning-irregular-verbs-in-English--show-translation (alist-get 'translations verb-to-learn))))
;; Remove the verb from the list ;; Remove the verb from the list
(if turn-unresolved (when (not turn-unresolved)
(lirve--remove-verb-unresolved verb-to-learn)
(setq lirve--verbs-shuffle (cdr lirve--verbs-shuffle)))) (setq lirve--verbs-shuffle (cdr lirve--verbs-shuffle))))
;; Increase the count of verbs ;; Increase the count of verbs
(setq lirve--count-verbs (1+ lirve--count-verbs))) (setq lirve--count-verbs (1+ lirve--count-verbs)))
@ -234,6 +239,7 @@ Example: (lirve--shuffle '(1 2 3 4 5)) => (3 1 5 2 4)"
"Make the button check." "Make the button check."
(setq lirve--widget-button-check (widget-create 'push-button (setq lirve--widget-button-check (widget-create 'push-button
:notify (lambda (&rest ignore) :notify (lambda (&rest ignore)
(setq lirve--is-resolve (lirve--is-win))
(lirve--update)) (lirve--update))
lirve--text-button-check))) lirve--text-button-check)))
(defun lirve--make-space-after-check () (defun lirve--make-space-after-check ()
@ -243,14 +249,17 @@ Example: (lirve--shuffle '(1 2 3 4 5)) => (3 1 5 2 4)"
(defun lirve--show-solutions () (defun lirve--show-solutions ()
"Show solutions" "Show solutions"
;; Show the solutions
(widget-value-set lirve--widget-field-simple-past lirve--verb-to-learn-simple-past) (widget-value-set lirve--widget-field-simple-past lirve--verb-to-learn-simple-past)
(widget-value-set lirve--widget-field-past-participle lirve--verb-to-learn-past-participle) (widget-value-set lirve--widget-field-past-participle lirve--verb-to-learn-past-participle)
(lirve--save-verb-unresolved lirve--verb-to-learn-infinitive)) ;; Set state to lose
(setq lirve--is-resolve nil))
(defun lirve--make-button-show-solution () (defun lirve--make-button-show-solution ()
"Make the button show solution." "Make the button show solution."
(setq lirve--widget-button-show-solution (widget-create 'push-button (setq lirve--widget-button-show-solution (widget-create 'push-button
:notify (lambda (&rest ignore) :notify (lambda (&rest ignore)
(setq lirve--is-resolve (lirve--is-win))
(lirve--show-solutions) (lirve--show-solutions)
(lirve--update)) (lirve--update))
lirve--text-button-show-solution))) lirve--text-button-show-solution)))
@ -291,8 +300,7 @@ Example: (lirve--shuffle '(1 2 3 4 5)) => (3 1 5 2 4)"
(when (and (eq lirve--state 1) (when (and (eq lirve--state 1)
(or (or
(not (string= (lirve--value-field-simple-past) "")) (not (string= (lirve--value-field-simple-past) ""))
(not (string= (lirve--value-field-past-participle) ""))) (not (string= (lirve--value-field-past-participle) ""))))
)
(setq lirve--state 2)) (setq lirve--state 2))
;; Check the answers ;; Check the answers
(when (eq lirve--state 2) (when (eq lirve--state 2)
@ -300,14 +308,17 @@ Example: (lirve--shuffle '(1 2 3 4 5)) => (3 1 5 2 4)"
(when (and (when (and
(string= (lirve--value-field-simple-past) lirve--verb-to-learn-simple-past) (string= (lirve--value-field-simple-past) lirve--verb-to-learn-simple-past)
(string= (lirve--value-field-past-participle) lirve--verb-to-learn-past-participle)) (string= (lirve--value-field-past-participle) lirve--verb-to-learn-past-participle))
;; Add or remove from unresolved list
(if lirve--is-resolve
(lirve--remove-verb-unresolved lirve--verb-to-learn-infinitive)
(lirve--save-verb-unresolved lirve--verb-to-learn-infinitive))
;; Set the lirve--state ;; Set the lirve--state
(setq lirve--state 3)) (setq lirve--state 3))
;; Update the check labels ;; Update the check labels
(widget-value-set lirve--widget-label-check-simple-past (lirve--format-check-simple-past)) (widget-value-set lirve--widget-label-check-simple-past (lirve--format-check-simple-past))
(widget-value-set lirve--widget-label-check-past-participle (lirve--format-check-past-participle))) (widget-value-set lirve--widget-label-check-past-participle (lirve--format-check-past-participle)))
;; Update the success layout if needed ;; Update the success layout if needed
(lirve--toggle-layout-finish) (lirve--toggle-layout-finish))
(setq lirve--is-resolve t))
(defun lirve--main-layout () (defun lirve--main-layout ()
"Make widgets for the main layout." "Make widgets for the main layout."