Customize delete keyboard button operation
Posted: Thu Nov 09, 2023 1:44 pm
Hi,
I have added below code for customizing delete operation. The code is working fine in no tag panel view and achieving following scenarios.
But in partial tag panel or full tag panel if I am selecting any tag, it is getting deleted even if it is required element.
Please refer below screenshot having selected Title element through title tag. Even if this element is required this Title element will get deleted since I have selected it through Title tag.
I have added below code for customizing delete operation. The code is working fine in no tag panel view and achieving following scenarios.
- At cursor location it is checking if the element is required it is showing element can't be deleted.
- By selecting the element from outline panel and pressing delete button from keyboard, it is deleting element only if the element is not required.
But in partial tag panel or full tag panel if I am selecting any tag, it is getting deleted even if it is required element.
Code: Select all
public class CustomDeleteHandler implements AuthorSchemaAwareEditingHandler {
@Override
public AuthorDocumentFragment handleCreateDocumentFragment(int arg0, int arg1, int arg2, AuthorAccess authorAcess)
throws BadLocationException {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean handleDelete(int arg0, int arg1, AuthorAccess authorAccess, boolean arg3) throws InvalidEditException {
// TODO Auto-generated method stub
try {
int caretOffset = authorAccess.getEditorAccess().getCaretOffset();
AuthorElement nodeAtCaret = (AuthorElement) authorAccess.getEditorAccess().getFullySelectedNode();
if (nodeAtCaret == null) {
nodeAtCaret = (AuthorElement) authorAccess.getDocumentController().getNodeAtOffset(caretOffset);
}
if(authorAccess.getDocumentController().getAuthorSchemaManager().isRequiredElement(nodeAtCaret))
{
authorAccess.getWorkspaceAccess().showInformationMessage("Selected element can not be deleted");
return true;
}
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new InvalidEditException
(e.getMessage(), "Invalid Delete Operation: " + e.getMessage(), e, false);
}
authorAccess.getWorkspaceAccess().showInformationMessage("Selected element can be deleted");
return false;
}