ChangeAttributeOperation - element location

manojdcoder
Posts: 63
Joined: Thu Oct 29, 2020 12:01 am

ChangeAttributeOperation - element location

Post by manojdcoder » Tue Nov 24, 2020 4:24 am

I would like to change an attribute of an element upon double click. I added the event at document level and now when the event is fired I have the event.target, but not sure how may I convert the target into a valid element location so I can invoke ChangeAttributeOperation . An example would be very much appreciated.

cristi_talau
Posts: 341
Joined: Thu Sep 04, 2014 4:22 pm

Re: ChangeAttributeOperation - element location

Post by cristi_talau » Tue Nov 24, 2020 2:10 pm

With our existing API, you can implement an approximation of this behavior by calling

Code: Select all

editor.getSelectionManager().getSelection().getNodeAtSelection()
However, if we understand what you are trying to achieve we may propose an alternative way of doing this. Is this request related to your other post about replacing an image on double click? If yes, I can give you details on how to implement this in version 23 of Web Author (which is now releases).

If not, please let us know about your specific use-case.

Best,
Cristian

manojdcoder
Posts: 63
Joined: Thu Oct 29, 2020 12:01 am

Re: ChangeAttributeOperation - element location

Post by manojdcoder » Tue Nov 24, 2020 5:56 pm

Yes, its related to my other post about changing image upon double click.

Basically we want to allow user to update references (images, xref, conref etc.,) upon double clicking the element. If you can show me how this could be done with v23, will be great.

manojdcoder
Posts: 63
Joined: Thu Oct 29, 2020 12:01 am

Re: ChangeAttributeOperation - element location

Post by manojdcoder » Wed Nov 25, 2020 6:35 pm

@Cristian Did you get a chance to look at this?

cristi_talau
Posts: 341
Joined: Thu Sep 04, 2014 4:22 pm

Re: ChangeAttributeOperation - element location

Post by cristi_talau » Wed Nov 25, 2020 11:02 pm

Hello,

In version 23.0, Web Author added support to configure a floating contextual toolbar that is displayed near the user selection in two cases, when an element is selected, or when the user selection is inside an element.

To this end you can add CSS rules like:

Code: Select all

xref:-oxy-selection-inside, xref:-oxy-selected {
    -oxy-floating-toolbar: oxy_button(actionID, 'replace.xref.href');
}
And define an action to replace the href of an xref element with the ID "replace.xref.href". The same approach works for other elements, except for images for which you need to apply also the patch that I mentioned in the other post: post60109.html#p60109

Another approach is to simply listen for double click and then look at the node where the current selection is:

Code: Select all

editor.getSelectionManager().getSelection().getNodeAtSelection()
Best,
Cristian

manojdcoder
Posts: 63
Joined: Thu Oct 29, 2020 12:01 am

Re: ChangeAttributeOperation - element location

Post by manojdcoder » Wed Nov 25, 2020 11:25 pm

Thank you for your continuous support. But unfortunately I don't think we can use floating toolbar for this purpose. We had been using XEditor and migrating to Oxygen, we would like to keep some features intact, one of which is double tap to change references.

As I already mentioned, I'm able to get my hands on current node [1], but not sure how may I convert it to an element location that is expected by ChangeAttributeOperation [2].

[1] https://www.oxygenxml.com/maven/com/oxy ... .Node.html
[2] https://www.oxygenxml.com/InstData/Edit ... ation.html

cristi_talau
Posts: 341
Joined: Thu Sep 04, 2014 4:22 pm

Re: ChangeAttributeOperation - element location

Post by cristi_talau » Wed Nov 25, 2020 11:36 pm

In this case, as I mentioned, instead of looking at the click target, you can rely on the editor to set the selection and just ask it for the element at selection using code like below:

Code: Select all

editor.getSelectionManager().getSelection().getNodeAtSelection()

manojdcoder
Posts: 63
Joined: Thu Oct 29, 2020 12:01 am

Re: ChangeAttributeOperation - element location

Post by manojdcoder » Wed Nov 25, 2020 11:50 pm

I'm sorry I don't understand. If I'm not wrong I have use ActionsManager.invokeOperation [1], pass ro.sync.ecss.extensions.commons.operations.ChangeAttributeOperation as operation and supply the parameters.

The operation expects element, it expects the following parameters

1. name (Attribute name) - href (in case of image in DITA)
2. value (Attribute value) - new file path
3. elementLocation (Xpath) - How do I convert editor.getSelectionManager().getSelection().getNodeAtSelection() into a valid elementLocation?

[1] https://www.oxygenxml.com/maven/com/oxy ... nager.html

cristi_talau
Posts: 341
Joined: Thu Sep 04, 2014 4:22 pm

Re: ChangeAttributeOperation - element location

Post by cristi_talau » Thu Nov 26, 2020 12:01 am

Now I understand your problem. Starting from the node at selection, you could traverse the DOM and compute the XPath of that element like /topic[1]/body[1]/p[1]/xref[2].

Post Reply