加入判断输入是否非法,暂仅判断输入'INT 'REAL 'STR
输入非法不修改,按取消不修改
;;; 原作者:vectra
(defun PropertyEdit (Lst0 / Lst update-textbox update-list make-load-dcl)
(defun update-textbox (index)
(set_tile "value" (vl-princ-to-string (cdr (nth (atoi index) Lst))))
);依list_boxd的定位index(索引)值自表lst取值,向edit_box赋值
(defun update-list (value / newadd_list index old typ0 typ)
(defun newadd_list (value index / new)
(setq new (strcat (car old) "\t" value))
(start_list "name" 1 index) ;_指定修改 index 位置上的数据
(add_list new)
(end_list)
)
(setq index (atoi (get_tile "name"))
old (nth index Lst)
typ0 (type (cdr old));'INT 'REAL 'STR.....
typ (type (read value))
)
(cond
((= 'INT typ0 typ)
(newadd_list value index)(setq Lst (subst (cons (car old) (atoi value)) old Lst))
)
((and (= 'REAL typ0)(member typ (list 'INT 'REAL)))
(newadd_list value index)(setq Lst (subst (cons (car old) (atof value)) old Lst))
)
((= 'STR typ0);
(newadd_list value index) (setq Lst (subst (cons (car old) value) old Lst))
)
(t (alert "数据类型非法!"))
)
);;依value返回值并判断数据类型更新list_boxd及表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
);;;写对话框文件
(setq Lst Lst0)
(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) (mode_tile \"value\" 2)");点击执行的动作
(action_tile "value" "(update-list $VALUE)")
(if (= (start_dialog) 1) lstLst0)
) 本帖最后由 yoyoho 于 2020-9-16 23:56 编辑
感谢 vectra 分享程序!!!! 研究一下!!!!!!! 好东西喔。不错 本帖最后由 伪书虫86 于 2022-3-20 00:16 编辑
收藏了半年终于明白了用处,但是发现了一个问题,值为0.85之类小于1的小数时,更新的话,会变成.85,小数点前的0会消失,不知道该怎么处理
static/image/hrline/5.gif
问题已解决,过来填个坑。
value为propertybag-edit的返回值,由于源程序返回值,如果填入的是数,返回的仍是数,会有可能导致写入属性块的时候有异常,故只需将返回值稍作处理即可,代码如下:
[*](setq value (mapcar '(lambda(x) (if (numberp (cdr x)) (cons (car x) (rtos (cdr x) 2)) x)) value))
页:
1
[2]