diff options
-rw-r--r-- | catbird/scene.scm | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/catbird/scene.scm b/catbird/scene.scm index 46d343e..445a66c 100644 --- a/catbird/scene.scm +++ b/catbird/scene.scm @@ -25,6 +25,7 @@ #:use-module (catbird mixins) #:use-module (catbird mode) #:use-module (catbird node) + #:use-module (catbird pushdown) #:use-module (chickadee data array-list) #:use-module (chickadee scripting) #:use-module (ice-9 exceptions) @@ -49,9 +50,7 @@ (define-root-class <scene> (<node>) (regions #:accessor regions #:init-value '()) - (major-mode #:accessor major-mode #:init-keyword #:major-mode - #:init-form (make <nothing-mode>)) - (major-mode-stack #:getter major-mode-stack #:init-thunk make-array-list) + (major-mode-state #:getter major-mode-state #:init-thunk make-pushdown-state) (minor-modes #:accessor minor-modes #:init-value '()) (input-map #:getter input-map #:init-value '())) @@ -75,13 +74,16 @@ (define-method (initialize (scene <scene>) args) (next-method) (with-scene scene - (attach (major-mode scene) scene))) + (replace-major-mode scene (make <nothing-mode>)))) + +(define-method (major-mode (scene <scene>)) + (state-current (major-mode-state scene))) (define-method (replace-major-mode (scene <scene>) (mode <major-mode>)) (let ((old-mode (major-mode scene))) (when old-mode (detach old-mode)) - (set! (major-mode scene) mode) + (state-replace! (major-mode-state scene) mode) (attach mode scene))) (define-method (replace-major-mode (mode <major-mode>)) @@ -89,24 +91,20 @@ (define-method (push-major-mode (scene <scene>) (mode <major-mode>)) (let ((old-mode (major-mode scene))) - (array-list-push! (major-mode-stack scene) old-mode) (when old-mode (pause old-mode)) - (set! (major-mode scene) mode) + (state-push! (major-mode-state scene) mode) (attach mode scene))) (define-method (push-major-mode (mode <major-mode>)) (push-major-mode (current-scene) mode)) (define-method (pop-major-mode (scene <scene>)) - (let ((stack (major-mode-stack scene))) - (unless (array-list-empty? stack) - (let ((mode (major-mode scene)) - (prev-mode (array-list-pop! stack))) - (when mode - (detach mode)) - (set! (major-mode scene) prev-mode) - (resume prev-mode))))) + (when (state-previous (major-mode-state scene)) + (let ((mode (major-mode scene))) + (when mode + (detach mode)) + (resume (state-pop! (major-mode-state scene)))))) (define-method (pop-major-mode) (pop-major-mode (current-scene))) |