From ffcd87e06fd830aef5bbd9a2bd8877db8b98501d Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Mon, 1 Oct 2012 00:35:05 +0200 Subject: [PATCH] Make the class do its work I still need to rewrite the macros to work with this new style of view. --- undone/main.scm | 20 +++++++------------- undone/view.scm | 6 ++++-- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/undone/main.scm b/undone/main.scm index 117e2c6..508a8f2 100644 --- a/undone/main.scm +++ b/undone/main.scm @@ -109,8 +109,6 @@ result) '())) -(define view-list '()) - (define (mkdirs path) (let ((parent (dirname path))) (if (not (file-exists? parent)) @@ -177,19 +175,17 @@ (cdr (assq 'state item)) (cdr (assq 'content item)))) -(define-view default - "Default todo-list view, show only the title." - "~2d ~a~%" id content) - (define (view args) "Show a list of todo items." (let* ((view-name (or (and (pair? args) (car args)) - "default")) + "view")) (view-symbol (string->symbol view-name)) (view-cons (assq view-symbol view-list)) - (view-func (if view-cons (cdr view-cons) '()))) - (if (procedure? view-func) - (apply view-func '())))) + (view-class (if view-cons (cdr view-cons) '()))) + (if (or (eq? view-class) + (memq view-class (class-subclasses ))) + (print-view (make view-class #:todo-list todo-list)) + (format #t "Unknown view: ~a~%" view-name)))) (define (load-rc-file) "Load the RC file containing custom views and such." @@ -220,6 +216,4 @@ (lambda (view) (format #t "~a~20t~a~%" (car view) (procedure-documentation (cdr view)))) - view-list)))) - - (print-view (make #:todo-list todo-list))) + view-list))))) diff --git a/undone/view.scm b/undone/view.scm index dcd694a..ce1ef23 100644 --- a/undone/view.scm +++ b/undone/view.scm @@ -1,7 +1,7 @@ (define-module (undone view) #:use-module (oop goops) - #:export ( sort-view filter-view print-item get-list-for - print-view)) + #:export ( view-list sort-view filter-view print-item + get-list-for print-view)) (define-generic sort-view) (define-generic filter-view) @@ -12,6 +12,8 @@ (define-class () (todo-list #:init-value '() #:init-keyword #:todo-list)) +(define view-list `((view . ,))) + (define-method (sort-view (v ) l) l) (define-method (print-item (v ) item)