这是一个简单的表数据编辑器,用于编辑形如(("Width" . 10) ("Height" . 100.0) ("Extendedable" . "Yes"))的表
按确定返回修改后的表,按取消返回nil。
- (defun edit (lst / update-textbox update-list)
- (defun update-textbox (index)
- (set_tile "value"
- (vl-princ-to-string (cdr (nth (atoi index) lst)))
- )
- )
- (defun update-list (value / index new old)
- (setq index (atoi (get_tile "name"))
- old (nth index lst)
- )
- (if (/= (cdr old) value)
- (progn
- (setq new (strcat (car old) "\t" value))
- (start_list "name" 1 index) ;_ 指定修改 index 位置上的数据
- (add_list new)
- (end_list)
- (setq lst (subst (cons (car old) value) old lst))
- )
- )
- )
- (defun make-load-dcl (/ dclfile dlg file)
- (setq dclfile (vl-filename-mktemp nil nil ".dcl")
- file (open dclfile "w")
- )
- (write-line
- "PropertyEditForm:dialog{label=\"属性编辑\";
- :row{:list_box{key=\"name\";height=25;width=50;tabs=25;}
- :row{:edit_box{key=\"value\";width=30;}}}
- ok_cancel;}"
- file
- )
- (close file)
- (setq dlg (load_dialog dclfile))
- (vl-file-delete dclfile)
- dlg
- )
- (new_dialog "PropertyEditForm" (make-load-dcl))
- (start_list "name")
- (mapcar
- 'add_list
- (mapcar
- '(lambda (e) (strcat (car e) "\t" (vl-princ-to-string (cdr e))))
- lst
- )
- )
- (end_list)
- (action_tile "name" "(update-textbox $VALUE)")
- (action_tile "value" "(update-list $VALUE)")
- (if (= (start_dialog) 1)
- lst
- )
- )
_$ (edit '(("Width" . 10) ("Height" . 100.0) ("Extendedable" . "Yes")))
修改并确定后返回
(("Width" . "20") ("Height" . "2") ("Extendedable" . "NO"))
|