[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
20/26: gurses: Populate dropdown boxes in forms using a menu.
From: |
John Darrington |
Subject: |
20/26: gurses: Populate dropdown boxes in forms using a menu. |
Date: |
Sun, 22 Jan 2017 12:09:25 +0000 (UTC) |
jmd pushed a commit to branch wip-installer
in repository guix.
commit 698048db349d5904462bea0c64dade3163e01746
Author: John Darrington <address@hidden>
Date: Thu Jan 19 20:26:57 2017 +0100
gurses: Populate dropdown boxes in forms using a menu.
* gurses/form.scm (form-set-current-field, make-form): Create a menu
and react to it on keystrokes.
---
gurses/form.scm | 56 +++++++++++++++++++++++++++++++++----------------------
1 file changed, 34 insertions(+), 22 deletions(-)
diff --git a/gurses/form.scm b/gurses/form.scm
index 2e8c242..4ee4ac9 100644
--- a/gurses/form.scm
+++ b/gurses/form.scm
@@ -34,17 +34,18 @@
#:use-module (ncurses curses)
#:use-module (ncurses panel)
+ #:use-module (gurses menu)
#:use-module (ice-9 match)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9))
(define-record-type <field>
- (make-field symbol label size choices popup value cursor-position)
+ (make-field symbol label size menu popup value cursor-position)
field?
(symbol field-symbol)
(label field-label)
(size field-size) ; The maximum length of values for this
field
- (choices field-choices) ; A list of acceptable values for this field
+ (menu field-menu) ; A menu of acceptable values for this field
(popup field-popup field-set-popup!)
(value field-value field-set-value!)
(cursor-position field-cursor-position field-set-cursor-position!))
@@ -130,23 +131,18 @@ label eq? to N"
(match x
((symbol label (? list? things))
(let ((width (apply max
- (map (lambda (x)
- (string-length x))
- things))))
- (make-field symbol label width things
- (let ((p
- (newwin (+ 2 (length
things))
- (+ 2 width) 0 0
#:panel #f)))
- (box p 0 0)
- (let loop ((ll things)
- (y 0))
- (if (not (null? ll))
- (begin
- (addstr p (car ll)
- #:y (1+ y)
#:x 1)
- (loop (cdr ll) (1+
y)))))
- p)
- "" 0)))
+ (map (lambda (x)
+ (string-length
x))
+ things)))
+ (menu (make-menu things)))
+ (make-field
+ symbol label width menu
+ (let ((p (newwin (+ 2 (length things))
+ (+ 4 width) 0 0 #:panel
#f)))
+ (box p 0 0)
+ (menu-post menu p)
+ p)
+ "" 0)))
((symbol label (? integer? size))
(make-field symbol label size #f #f "" 0))))
items)))
@@ -246,11 +242,27 @@ label eq? to N"
(hide-panel popup)))
(form-set-current-item! form which)
(let* ((new-field (array-ref (form-items form) which))
- (popup (field-popup new-field)))
+ (popup (field-popup new-field))
+ (win (form-window form))
+ (menu (field-menu new-field)))
(when popup
(ensure-panel! popup)
- (show-panel popup)))
- (move (form-window form) which (form-tabpos form)))
+ (show-panel popup)
+ (keypad! win #t)
+ (menu-refresh menu)
+ (let loop ((ch (getch win)))
+ (if (eq? ch #\newline)
+ (field-set-value! new-field (menu-get-current-item menu))
+ (begin
+ (std-menu-key-handler menu ch)
+ (menu-redraw menu)
+ (menu-refresh menu)
+ (update-panels)
+ (doupdate)
+ (loop (getch win)))))
+ (hide-panel popup)
+ (redraw-field form new-field (form-current-item form))
+ (move win which (form-tabpos form)))))
(define (form-next-field form)
- 25/26: installer: Emphasise that writing filesystems destroys existing data., (continued)
- 25/26: installer: Emphasise that writing filesystems destroys existing data., John Darrington, 2017/01/22
- 05/26: installer: Fix bug where the selected item of main page was not indicated., John Darrington, 2017/01/22
- 08/26: gurses: form: Use match instead of car, cdr etc., John Darrington, 2017/01/22
- 03/26: installer: Do not allow the creation of invalid file-system specificaitons., John Darrington, 2017/01/22
- 15/26: gurses: Allow menu update to work for panel windows., John Darrington, 2017/01/22
- 18/26: gurses: Populate the choices box in forms., John Darrington, 2017/01/22
- 06/26: installer: Add an explanatory text to the main page., John Darrington, 2017/01/22
- 22/26: installer: mount-points page: Enlarge the forms window., John Darrington, 2017/01/22
- 13/26: installer: Remove unnecessary "begin"., John Darrington, 2017/01/22
- 24/26: installer: Remove redundant list of file system types., John Darrington, 2017/01/22
- 20/26: gurses: Populate dropdown boxes in forms using a menu.,
John Darrington <=
- 12/26: installer: Fix bug in config generation., John Darrington, 2017/01/22
- 26/26: doc: Remove the text which mentions there is no graphical installer., John Darrington, 2017/01/22
- 19/26: installer: Add a popup window for forms which have multiple choice fields., John Darrington, 2017/01/22
- 16/26: gurses: Mini refactor., John Darrington, 2017/01/22
- 09/26: installer: Explicitly set the #:panel parameter for window creation procedures., John Darrington, 2017/01/22
- 11/26: installer: New procedure refresh*., John Darrington, 2017/01/22
- 23/26: gurses: Remove box from form popup window., John Darrington, 2017/01/22