Skip to main content
Mar 8, 2024 7:30 PM UTC
Solved

Callback on DELETE key

I need to add a callback on when the DELETE key is pressed.  I don't need to change the behavior of the key pressing but only to detect it and being able to run a function additionally to the normal process.

 

Thanks for your time.

PartnerAnswer
Mar 18, 2024 4:01 PM UTC

Good afternoon, thanks for taking the time to answer me back.  I ended up using the following code:

 

doc_add_callback(current_doc(), 'delete', 'triggerDelete');

...

function triggerDelete(doc, op){
	local tickEvent;
	if($op == 1 && numerotationHelper::insertionInProgress == 0){
		# callback are always called twice
		# https://support.ptc.com/help/arbortext/r8.1.0.0/en/index.html#page/Program/acl_ref/help148-517.html
		numerotationHelper::lastDeletePressed = javascript('d = Date.now();d.toString();');
		local selectedElement = selected_element();
		if(index(selectedElement, "-1")>0){
			numerotationHelper::lastObjectParentDeleted = "";
			numerotationHelper::lastObjectDeleted = "";
		}
		else{
			numerotationHelper::lastObjectParentDeleted = oid_parent($selectedElement);
			numerotationHelper::lastObjectDeleted = oid_name($selectedElement);
		}
	}
}

Once again, thank you !

3 replies

Mar 14, 2024 5:18 PM UTC

Hi gbélanger,

Welcome to the PTC Community!

Thank you for your question. 


I’d like to recommend to bring more details and context to your initial inquiry. 

It also helps to have screenshot(s) to better understand what you are trying to do in your process. 

This will increase your chances to receive meaningful help from other Community members. 

 

Regards,

Anurag 

 

PartnerAuthorAnswer
Mar 18, 2024 4:01 PM UTC

Good afternoon, thanks for taking the time to answer me back.  I ended up using the following code:

 

doc_add_callback(current_doc(), 'delete', 'triggerDelete');

...

function triggerDelete(doc, op){
	local tickEvent;
	if($op == 1 && numerotationHelper::insertionInProgress == 0){
		# callback are always called twice
		# https://support.ptc.com/help/arbortext/r8.1.0.0/en/index.html#page/Program/acl_ref/help148-517.html
		numerotationHelper::lastDeletePressed = javascript('d = Date.now();d.toString();');
		local selectedElement = selected_element();
		if(index(selectedElement, "-1")>0){
			numerotationHelper::lastObjectParentDeleted = "";
			numerotationHelper::lastObjectDeleted = "";
		}
		else{
			numerotationHelper::lastObjectParentDeleted = oid_parent($selectedElement);
			numerotationHelper::lastObjectDeleted = oid_name($selectedElement);
		}
	}
}

Once again, thank you !

Mar 14, 2024 7:10 PM UTC

You can do this using the map command in ACL, something like this:

function myDeleteExtras() {
 # do whatever extra stuff you need here...
 EditDelete; # this executes the normal delete operation
}

map Delete {myDeleteExtras()}