Insert indexterm action
Are you missing a feature? Request its implementation here.
-
- Posts: 163
- Joined: Sat Aug 28, 2010 1:23 am
Insert indexterm action
Hi there,
I would like to create an "Insert indexterm" action that operates on the current selected text. Say the user has highlighted the word "whatever" in the editor. This action would insert <indexterm><primary>whatever</primary></indexterm> at the end of the nearest ancestor block element (e.g. <para>) but otherwise leave the cursor unmoved. Would that be possible? I think an action like this would be useful for several of the frameworks with only the specific indexterm markup changed.
Thanks,
David
I would like to create an "Insert indexterm" action that operates on the current selected text. Say the user has highlighted the word "whatever" in the editor. This action would insert <indexterm><primary>whatever</primary></indexterm> at the end of the nearest ancestor block element (e.g. <para>) but otherwise leave the cursor unmoved. Would that be possible? I think an action like this would be useful for several of the frameworks with only the specific indexterm markup changed.
Thanks,
David
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Insert indexterm action
Hi David,
The operation needs a custom Java implementation.
Please see this example:
Regards,
Radu
The operation needs a custom Java implementation.
Please see this example:
Code: Select all
package ro.sync.ecss.extensions.docbook;
import javax.swing.text.BadLocationException;
import ro.sync.ecss.extensions.api.ArgumentDescriptor;
import ro.sync.ecss.extensions.api.ArgumentsMap;
import ro.sync.ecss.extensions.api.AuthorAccess;
import ro.sync.ecss.extensions.api.AuthorOperation;
import ro.sync.ecss.extensions.api.AuthorOperationException;
import ro.sync.ecss.extensions.api.node.AuthorNode;
/**
* Insert an index term.
*/
public class InsertIndexTermOperation implements AuthorOperation {
/**
* @see ro.sync.ecss.extensions.api.AuthorOperation#doOperation(ro.sync.ecss.extensions.api.AuthorAccess, ro.sync.ecss.extensions.api.ArgumentsMap)
*/
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
throws IllegalArgumentException, AuthorOperationException {
String selectedText = authorAccess.getEditorAccess().getSelectedText();
if(selectedText != null && !selectedText.isEmpty()) {
//We can make an index term from it.
//Keep the caret position, we'll come back to it
int currentCaretPos = authorAccess.getEditorAccess().getCaretOffset();
//Find the insert position.
try {
//The end of the current element
AuthorNode toInsertIn = authorAccess.getDocumentController().getNodeAtOffset(currentCaretPos);
//But maybe it is an inline
//Go up to find a paragraph
while(! "para".equals(toInsertIn.getName())) {
toInsertIn = toInsertIn.getParent();
}
if(toInsertIn != null) {
authorAccess.getDocumentController().insertXMLFragment("<indexterm xmlns=\"http://docbook.org/ns/docbook\"><primary>" + selectedText + "</primary></indexterm>", toInsertIn.getEndOffset());
//And move the cursor back
authorAccess.getEditorAccess().setCaretPosition(currentCaretPos);
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
/**
* @see ro.sync.ecss.extensions.api.AuthorOperation#getArguments()
*/
public ArgumentDescriptor[] getArguments() {
return null;
}
/**
* @see ro.sync.ecss.extensions.api.Extension#getDescription()
*/
public String getDescription() {
return "Insert index term";
}
}
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 163
- Joined: Sat Aug 28, 2010 1:23 am
Re: Insert indexterm action
Thanks Radu. That gives me something to work with. I'll have to handle some other situations (like when the word in question is in a <title> or <entry>). I'll let you know if I need more help with that.
David
David
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Insert indexterm action
Hi Fons,
Creating your own Author operations implies some knowledge of Java as all our SDK is Java based:
http://www.oxygenxml.com/developer.html ... horing_SDK
You will need the libraries which come with the SDK to build the new operation. The SDK also comes with a tutorial for customizing a document type.
Once you create a new jar library with the new operation class you can modify the Docbook(4 or 5) document type from the Preferences->Document Type Association page, in the Classpath tab add the path to your jar library and then in the Author->Actions tab create an action which uses the operation. Then the action can be mounted to the main menu, contextual menu or to the toolbar.
Maybe David can share with you the jar library of the operation he implemented.
Regards,
Radu
Creating your own Author operations implies some knowledge of Java as all our SDK is Java based:
http://www.oxygenxml.com/developer.html ... horing_SDK
You will need the libraries which come with the SDK to build the new operation. The SDK also comes with a tutorial for customizing a document type.
Once you create a new jar library with the new operation class you can modify the Docbook(4 or 5) document type from the Preferences->Document Type Association page, in the Classpath tab add the path to your jar library and then in the Author->Actions tab create an action which uses the operation. Then the action can be mounted to the main menu, contextual menu or to the toolbar.
Maybe David can share with you the jar library of the operation he implemented.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 14
- Joined: Mon Jun 21, 2021 7:07 pm
Re: Insert indexterm action
I would like to have this kind of feature also. Is is possible for SyncRO Soft to add this to the factory installed OxygenXML Author so that us newbies do not have to learn the API and how to build custom extensions? Or perhaps make an example that we can download?
Thanks!
Thanks!
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Insert indexterm action
Hi,
What XML vocabulary are you using? The current thread was started by someone using the DocBook XML vocabulary. Are you using DITA, DocBook, or something else?
How should a custom indexterm insertion action behave in order to be useful to you?
If you want to select text and have it wrapped in an index term you can already define code templates in Oxygen, and inside code templates you can use editor variables to expand the current selection, there is an example here:
https://blog.oxygenxml.com/topics/dita_ ... ricks.html
around this paragraph:
Radu
What XML vocabulary are you using? The current thread was started by someone using the DocBook XML vocabulary. Are you using DITA, DocBook, or something else?
How should a custom indexterm insertion action behave in order to be useful to you?
If you want to select text and have it wrapped in an index term you can already define code templates in Oxygen, and inside code templates you can use editor variables to expand the current selection, there is an example here:
https://blog.oxygenxml.com/topics/dita_ ... ricks.html
around this paragraph:
Regards,Code templates - Define small fragments of XML content that can be inserted either by defining a shortcut key or by pressing ENTER in the editing area.
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 14
- Joined: Mon Jun 21, 2021 7:07 pm
Re: Insert indexterm action
I am using DocBook.
Thank you for your suggestion. The code template works quite well for this.
I have defined my code template content as:
${selection}<indexterm><primary>${selection}</primary></indexterm>
Oxygen is a great product!
Thank you for your suggestion. The code template works quite well for this.
I have defined my code template content as:
${selection}<indexterm><primary>${selection}</primary></indexterm>
Oxygen is a great product!
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