[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
124/197: gurses: Populate dropdown boxes in forms using a menu.
From: |
Danny Milosavljevic |
Subject: |
124/197: gurses: Populate dropdown boxes in forms using a menu. |
Date: |
Mon, 3 Jul 2017 20:37:12 -0400 (EDT) |
dannym pushed a commit to branch wip-installer-2
in repository guix.
commit 4a4f0b47f1cf09d99fa43f3ef552c5705a350791
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)
- 101/197: installer: Replace one usage of car with match., (continued)
- 101/197: installer: Replace one usage of car with match., Danny Milosavljevic, 2017/07/03
- 109/197: installer: Fix bug where the selected item of main page was not indicated., Danny Milosavljevic, 2017/07/03
- 104/197: installer: Support btrfs, Danny Milosavljevic, 2017/07/03
- 111/197: gurses: Change highlighting from bold to inverse., Danny Milosavljevic, 2017/07/03
- 108/197: installer: Do not add file systems which are invalid., Danny Milosavljevic, 2017/07/03
- 164/197: gurses: Use match instead of car., Danny Milosavljevic, 2017/07/03
- 170/197: installer: Remove unused procedure., Danny Milosavljevic, 2017/07/03
- 152/197: installer: New file i18n.scm., Danny Milosavljevic, 2017/07/03
- 110/197: installer: Add an explanatory text to the main page., Danny Milosavljevic, 2017/07/03
- 120/197: gurses: Mini refactor., Danny Milosavljevic, 2017/07/03
- 124/197: gurses: Populate dropdown boxes in forms using a menu.,
Danny Milosavljevic <=
- 131/197: gurses: Use inverse instead of underline for field value area., Danny Milosavljevic, 2017/07/03
- 133/197: installer: Change livery., Danny Milosavljevic, 2017/07/03
- 146/197: gurses: Use match instead of car/cdr in line-split., Danny Milosavljevic, 2017/07/03
- 147/197: gurses: In paragraph-format avoid use of car and cdr., Danny Milosavljevic, 2017/07/03
- 144/197: gurses: Avoid one more use of car and cdr., Danny Milosavljevic, 2017/07/03
- 143/197: gurses: Add predicate to test if a complex char is blank., Danny Milosavljevic, 2017/07/03
- 149/197: gurses: Add new procedure "word-endings"., Danny Milosavljevic, 2017/07/03
- 155/197: installer: Use _ instead of M_ for host-name-refresh., Danny Milosavljevic, 2017/07/03
- 160/197: installer: New convenience procedures., Danny Milosavljevic, 2017/07/03
- 158/197: installer: Correct placement of gettext call., Danny Milosavljevic, 2017/07/03