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?
(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
Hello,
I did some tests and I have the feeling that (dcl_Tree_CancelLabelEdit layer_sc_ltm_tree) is without any effect?!
Fred
I've now made some changes to the code so that CancelLabelEdit works as expected from within the OnBeginLabelEdit event handler.
Thanks Owen!
Fred
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?
(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
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.
Thanks, Owen!