TreeLabelEdit

Started by Fred Tomke, April 23, 2009, 10:42:14 PM

Previous topic - Next topic

Fred Tomke

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
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Fred Tomke

Hello,

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

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

owenwengerd

I've now made some changes to the code so that CancelLabelEdit works as expected from within the OnBeginLabelEdit event handler.
Owen Wengerd (Outside The Box) / ManuSoft

Fred Tomke

Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Fred Tomke

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
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

owenwengerd

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.
Owen Wengerd (Outside The Box) / ManuSoft

Fred Tomke

Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]