Source code for PromoteDemoteItemOperation
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 25
- Joined: Thu Aug 07, 2014 3:40 pm
Source code for PromoteDemoteItemOperation
Post by Bruno.Ballarin »
Hi,
I could not find the source code for the recently introduced PromoteDemoteItemOperation.
I am interested in finding an javascript example showing how to select a subset of similar elements either partially or totally included in the current selection at the caret position.
For instance if I make the following selection in Oxygen Dita Author mode:
and run the PromoteDemoteItemOperation on this selection, I obtain this:
So I am interested in this piece of code that is able to select all the similar elements (here <li> elements) that are completely or partially belonging to the current selection at the caret position, in order to perform some operations on them.
Cheers,
Bruno
I could not find the source code for the recently introduced PromoteDemoteItemOperation.
I am interested in finding an javascript example showing how to select a subset of similar elements either partially or totally included in the current selection at the caret position.
For instance if I make the following selection in Oxygen Dita Author mode:
and run the PromoteDemoteItemOperation on this selection, I obtain this:
So I am interested in this piece of code that is able to select all the similar elements (here <li> elements) that are completely or partially belonging to the current selection at the caret position, in order to perform some operations on them.
Cheers,
Bruno
Re: Source code for PromoteDemoteItemOperation
Hi Bruno,
You should try this API:
https://www.oxygenxml.com/InstData/Edit ... t-int-int-
Regards,
Radu
You should try this API:
Code: Select all
authorAccess.getDocumentController().getNodesToSelect(authorAccess.getEditorAccess().getSelectionStart(), authorAccess.getEditorAccess().getSelectionEnd());
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 25
- Joined: Thu Aug 07, 2014 3:40 pm
Re: Source code for PromoteDemoteItemOperation
Post by Bruno.Ballarin »
Thank you Radu,
with your help, I have been able to put together the JSOperation (provided below) that does the following:
After selecting a range of cells in a table row, or an entire row:
I assume this has to do with the fact that the selection correspond to 2 discontinued areas in the text view and that the getSelectionStart() and getSelectionEnd() return only the offset of the last xml fragment of the selection.
Maybe the function getSelectionIntervals() "Get the selection [start offset, end offset] intervals list" would do the trick but when I try to use it I got an error: "Could not find function getSelectionIntervals() ...". Do I need to update my Dita framework to make use of this function? How?
with your help, I have been able to put together the JSOperation (provided below) that does the following:
After selecting a range of cells in a table row, or an entire row:
- If any cell in the selection has attribute rotate = "...", the attribute "rotate" is removed for the entire row
- If none of the cells in the selection have the attribute "rotate", the attribute rotate = "1" is set for the entire selection
I assume this has to do with the fact that the selection correspond to 2 discontinued areas in the text view and that the getSelectionStart() and getSelectionEnd() return only the offset of the last xml fragment of the selection.
Maybe the function getSelectionIntervals() "Get the selection [start offset, end offset] intervals list" would do the trick but when I try to use it I got an error: "Could not find function getSelectionIntervals() ...". Do I need to update my Dita framework to make use of this function? How?
Code: Select all
function doOperation() {
if(authorAccess.getEditorAccess().hasSelection()) {
startOffset = authorAccess.getEditorAccess().getSelectionStart();
endOffset = authorAccess.getEditorAccess().getSelectionEnd();
results = authorAccess.getDocumentController().findNodesByXPath("../descendant-or-self::entry", true, true, true);
rotated = false;
for(i = 0; i < results.length; i++){
if(results[i].getEndOffset() > startOffset && results[i].getStartOffset() < endOffset && results[i].getAttribute("rotate") != null){
rotated = true;
}
}
if (rotated == true){
for(i = 0; i < results.length; i++){
if(results[i].getEndOffset() > startOffset && results[i].getStartOffset() < endOffset){
authorAccess.getDocumentController().removeAttribute("rotate", results[i]);
}
}
}
if (rotated == false){
for(i = 0; i < results.length; i++){
if(results[i].getEndOffset() > startOffset && results[i].getStartOffset() < endOffset){
authorAccess.getDocumentController().setAttribute("rotate", new Packages.ro.sync.ecss.extensions.api.node.AttrValue("1"), results[i]);
}
}
}
}
}
Re: Source code for PromoteDemoteItemOperation
Hi,
Indeed, and mostly when it comes to tables, you may have multiple selection intervals.
The method can be accessed like:
https://www.oxygenxml.com/InstData/Edit ... Model.html
Regards,
Radu
Indeed, and mostly when it comes to tables, you may have multiple selection intervals.
The method can be accessed like:
Code: Select all
authorAccess.getEditorAccess().getAuthorSelectionModel().getSelectionIntervals();
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 25
- Joined: Thu Aug 07, 2014 3:40 pm
Re: Source code for PromoteDemoteItemOperation
Post by Bruno.Ballarin »
Thank you Radu,
I got it to work now: Set/clear Attribute rotate = "1" on:
I got it to work now: Set/clear Attribute rotate = "1" on:
- an arbitrary selection of cells (including multiple cells belonging to multiple rows)
- a single cell at cursor position
Code: Select all
function doOperation() {
if(authorAccess.getEditorAccess().hasSelection()) {
offsetList = authorAccess.getEditorAccess().getAuthorSelectionModel().getSelectionIntervals();
results = authorAccess.getDocumentController().findNodesByXPath("ancestor-or-self::table/descendant-or-self::entry", true, true, true);
rotated = false;
for(i = 0; i < results.length; i++){
for(j = 0; j < offsetList.size(); j++){
if(results[i].getEndOffset() >= offsetList.get(j).getStartOffset() && results[i].getStartOffset() < offsetList.get(j).getEndOffset() && results[i].getAttribute("rotate") != null){
rotated = true;
}
}
}
if (rotated == true){
for(i = 0; i < results.length; i++){
for(j = 0; j < offsetList.size(); j++){
if(results[i].getEndOffset() >= offsetList.get(j).getStartOffset() && results[i].getStartOffset() < offsetList.get(j).getEndOffset()){
authorAccess.getDocumentController().removeAttribute("rotate", results[i]);
}
}
}
}
if (rotated == false){
for(i = 0; i < results.length; i++){
for(j = 0; j < offsetList.size(); j++){
if(results[i].getEndOffset() >= offsetList.get(j).getStartOffset() && results[i].getStartOffset() < offsetList.get(j).getEndOffset()){
authorAccess.getDocumentController().setAttribute("rotate", new Packages.ro.sync.ecss.extensions.api.node.AttrValue("1"), results[i]);
}
}
}
}
} else {
results = authorAccess.getDocumentController().findNodesByXPath("ancestor-or-self::entry", true, true, true);
rotated = false;
for(i = 0; i < results.length; i++){
if(results[i].getAttribute("rotate") != null){
rotated = true;
}
}
if (rotated == true){
for(i = 0; i < results.length; i++){
authorAccess.getDocumentController().removeAttribute("rotate", results[i]);
}
}
if (rotated == false){
for(i = 0; i < results.length; i++){
authorAccess.getDocumentController().setAttribute("rotate", new Packages.ro.sync.ecss.extensions.api.node.AttrValue("1"), results[i]);
}
}
}
}
Re: Source code for PromoteDemoteItemOperation
Hi Bruno,
Great, thanks for updating the forum thread. Probably in the future we might also need to add a default operation in Oxygen (we have a Table Properties operation which can be used to edit a table's configuration) to do the same thing. I will add an issue on our side.
Regards,
Radu
Great, thanks for updating the forum thread. Probably in the future we might also need to add a default operation in Oxygen (we have a Table Properties operation which can be used to edit a table's configuration) to do the same thing. I will add an issue on our side.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service