vectra 发表于 2015-5-5 09:53:28

为应用程序数据提供一个简单的修改界面

这是一个简单的表数据编辑器,用于编辑形如(("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"))

USER2128 发表于 2015-5-5 16:56:11

;;; 楼主为我们提供了一个很好的实用程序,我做了少少修改,楼主莫生气。
;;; 增加(mode_tile "value" 2),可减少鼠标动作,便于快速修改参数
;;; 返回值保证与原始参数的格式一致,按"取消"键时仍有返回,只是无修改
;;; 如有不妥之处,再次请求楼主见谅。
;;; 原作者:vectra; 修改: HLCAD(USER2128)
(defun edit (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))))
    )
;;;
(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=\"属性编辑\";
      :column{
      :list_box{key=\"name\";height=15;width=50;tabs=25;}
      :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)
    (mapcar '(lambda(x / a b c)
      (progn
        (setq a (car x)
              b (cdr x)
              c (cdr (assoc a Lst))
              )
        (cond ((= (type b) 'INT)(cons a (atoi c)))
              ((= (type b) 'REAL) (cons a (atof c)))
              (t (cons a c))
              )
        )) Lst0)
    Lst0)
)

;_$ (edit '(("Width" . 10) ("Height" . 100.0) ("Extendedable" . "Yes")))
;修改并确定后返回
;(("Width" . 20) ("Height" . 2.0) ("Extendedable" . "NO"))
;按"取消"后返原值(("Width" . 10) ("Height" . 100.0) ("Extendedable" . "Yes"))

lucas_3333 发表于 2015-5-5 17:37:35

USER2128 发表于 2015-5-5 16:56 static/image/common/back.gif


感谢俩位大师分享! 来一个成品如何?

USER2128 发表于 2015-5-6 07:44:22

lucas_3333 发表于 2015-5-5 17:37 static/image/common/back.gif
感谢俩位大师分享! 来一个成品如何?

这个程序早晚要用起来,今要出差几天,如有应用,将及时贴出。
谢谢你的奖励!

vectra 发表于 2015-5-6 08:12:37

我只是发了个非常简单的雏形,还有很大完善的空间,比如提供下拉列表选项,不同数据类型的编辑,帮助信息等。希望大家一起参与,更加完善。

fl202 发表于 2015-5-6 09:04:25

ctrl + 1特性版工具栏里, 与此有何区别?

sibelle_hu 发表于 2015-8-20 15:44:21

USER2128 发表于 2015-5-6 07:44 static/image/common/back.gif
这个程序早晚要用起来,今要出差几天,如有应用,将及时贴出。
谢谢你的奖励!

想看看成品

edata 发表于 2015-8-21 07:28:20

提点建议,如果要改首项呢,修改前是数字,修改后也应该是数字,缺少判断,列表框只显示名称,不知道值,需要点击才能显示,可不可以换种方式,名称和值都能出来,一目了然,数量多的时候比较明显,如果采用双列表呢,一个名称,一个值,点那边都能改。

lucas_3333 发表于 2015-8-21 08:31:08

edata 发表于 2015-8-21 07:28 static/image/common/back.gif
提点建议,如果要改首项呢,修改前是数字,修改后也应该是数字,缺少判断,列表框只显示名称,不知道值,需 ...

E大,好早啊, 支持提议, 也希望早日见到各位的成果

@vectra, @USER2128
页: [1]
查看完整版本: 为应用程序数据提供一个简单的修改界面