OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: Fred Tomke on April 23, 2009, 10:42:14 PM

Title: TreeLabelEdit
Post by: Fred Tomke on April 23, 2009, 10:42:14 PM
Hello,

I want to prevent the user from renaming some labels in a tree. But some may be edited. As I remember I can solve this using CancelLabelEdit in the OnBeginLabelEdit event. But unfortunately, it stays editable. I use the tree in a palette. What am I doing wrong?

Code (autolisp) Select

(defun c:layer_sc_ltm_tree_OnBeginLabelEdit (uKey /)
  (if (member (dcl_Tree_GetItemText layer_sc_ltm_tree uKey) '("Standard-Layertheme" "Standard-Layergroup"))
    (dcl_Tree_CancelLabelEdit layer_sc_ltm_tree)
  ); if
); c:layer_sc_ltm_tree_OnBeginLabelEdit


Fred
Title: Re: TreeLabelEdit
Post by: Fred Tomke on April 23, 2009, 11:02:46 PM
Hello,

I did some tests and I have the feeling that (dcl_Tree_CancelLabelEdit layer_sc_ltm_tree)  is without any effect?!

Fred
Title: Re: TreeLabelEdit
Post by: owenwengerd on April 25, 2009, 08:44:12 AM
I've now made some changes to the code so that CancelLabelEdit works as expected from within the OnBeginLabelEdit event handler.
Title: Re: TreeLabelEdit
Post by: Fred Tomke on April 26, 2009, 11:18:24 PM
Thanks Owen!

Fred
Title: Re: TreeLabelEdit
Post by: Fred Tomke on April 28, 2009, 12:31:42 PM
Hello,

I don't know whether it belongs to the same case or not but shouldn't it be possible to change the item label within OnEndLabelEdit?

Code (autolisp) Select

(defun c:layer_sc_ltm_tree_OnBeginLabelEdit (uKey)
  (setq ***ltm_label_name*** (cons uKey (dcl_Tree_GetItemText layer_sc_ltm_tree uKey)))
); c:layer_sc_ltm_tree_OnBeginLabelEdit

(defun c:layer_sc_ltm_tree_OnEndLabelEdit (strNewValue uKey / oObj oState)
  (cond
    ((not ***ltm_label_name***) nil)
    ((not (setq oObj (get_vlaObject_from_handle uKey))) nil)
    ((or (not strNewValue)
(= (setq strNewValue (vl-string-trim " " strNewValue)) "")
(= strNewValue (cdr ***ltm_label_name***))) nil)
    ((apply 'or (mapcar '(lambda (x) (vl-string-search x strNewValue))
'("<" ">" "/" "\\" "\"" ";" ":" "?" "*" "|" "~" "+" "." "," "=" "'" "Ã,´" "`"))) nil)
    ((< (setq intPic (car (dcl_Tree_GetItemImages layer_sc_ltm_tree uKey))) 2)
     (if (and (not (member (strcase strNewValue)
   (vl-remove (strcase (cdr ***ltm_label_name***))
     (mapcar 'strcase (mapcar 'vla-get-name (LTM_THEMES_LIST nil))))))
      (not (member (strcase strNewValue)
   (vl-remove (strcase (cdr ***ltm_label_name***))
     (mapcar 'strcase (mapcar 'vla-get-name (LTM_STATES_LIST)))))))
       (vla-put-name oObj strNewValue)
       (dcl_Tree_SetItemText layer_sc_ltm_tree uKey (cdr ***ltm_label_name***)) ;; <- this line does not work
     ))

    (T (dcl_Tree_SetItemText layer_sc_ltm_tree uKey (cdr ***ltm_label_name***))) ;; <- this line does not work
  ); cond
); c:layer_sc_ltm_tree_OnEndLabelEdit


Fred
Title: Re: TreeLabelEdit
Post by: owenwengerd on April 29, 2009, 06:01:20 PM
The problem is that the edited label gets set *after* OnEndLabelEdit returns, so it overwrites whatever you set from within the event handler. Luckily, there is a way to cancel the edit, so I added code to cancel the edit if the OnEndLabelEdit event handler calls SetItemLabel. This change should allow calls to SetItemLabel to work from within the event handler.
Title: Re: TreeLabelEdit
Post by: Fred Tomke on April 29, 2009, 11:19:59 PM
Thanks, Owen!