Add New Paste command in author editor page
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 17
- Joined: Tue Aug 15, 2023 10:58 pm
Add New Paste command in author editor page
We would like to add new paste commands in editor author page to paste a topic copied from an external application.
If the document in the editor is topic, the commands will paste the topic from external application as xref or link. at the position of the cursor.
paste from AW ->
paste as xref
paste as link
What APIs should I use to get the content from clipboard and insert xref or link elements?
Thanks,
Kehua
If the document in the editor is topic, the commands will paste the topic from external application as xref or link. at the position of the cursor.
paste from AW ->
paste as xref
paste as link
What APIs should I use to get the content from clipboard and insert xref or link elements?
Thanks,
Kehua
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Add New Paste command in author editor page
Hi Kehua,
It's good to give more context as we have multiple products, I think you are customizing the Oxygen Eclipse plugin, correct?
In the Oxygen Eclipse plugin's "plugin.xml" file there is an extension point defined named actionBarContributorCustomizer which you can implement with a custom Java class in your own plugin something like this for example:
So you need to use the mechanisms in Eclipse to read the clipboard (maybe you have there a different flavor than plain text) and then use our AuthorDocumentController APis to make changes inside the current XML document.
https://www.oxygenxml.com/InstData/Edit ... oller.html
Regards,
Radu
It's good to give more context as we have multiple products, I think you are customizing the Oxygen Eclipse plugin, correct?
In the Oxygen Eclipse plugin's "plugin.xml" file there is an extension point defined named actionBarContributorCustomizer which you can implement with a custom Java class in your own plugin something like this for example:
Code: Select all
package com.oxygenxml.editor.editors;
import java.util.List;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.widgets.CoolBar;
import org.eclipse.swt.widgets.Display;
import ro.sync.ecss.extensions.api.AuthorAccess;
import ro.sync.ecss.extensions.api.AuthorOperationException;
import ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPage;
/**
* @author raducoravu
*/
public class CustomActionBarContributorCustomizer extends ActionBarContributorCustomizer {
/**
* @see com.oxygenxml.editor.editors.ActionBarContributorCustomizer#customizeActionsContributedToDocumentMenu(java.util.List)
*/
@Override
public List<IAction> customizeActionsContributedToDocumentMenu(List<IAction> actions) {
return actions;
}
/**
* @see com.oxygenxml.editor.editors.ActionBarContributorCustomizer#customizeActionsContributedToDocumentToolbar(java.util.List)
*/
@Override
public List<IAction> customizeActionsContributedToDocumentToolbar(List<IAction> actions) {
return actions;
}
/**
* @see com.oxygenxml.editor.editors.ActionBarContributorCustomizer#customizeAuthorPageInternalCoolbar(org.eclipse.swt.widgets.CoolBar, ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPage)
*/
@Override
public void customizeAuthorPageInternalCoolbar(CoolBar coolbar,
WSAuthorEditorPage authorEditorPage) {
}
/**
* @see com.oxygenxml.editor.editors.ActionBarContributorCustomizer#customizeAuthorPopUpMenu(org.eclipse.jface.action.IMenuManager, ro.sync.ecss.extensions.api.AuthorAccess)
*/
@Override
public void customizeAuthorPopUpMenu(IMenuManager popUp, AuthorAccess authorAccess) {
popUp.add(new Action("Paste link") {
/**
* @see org.eclipse.jface.action.IAction#run()
*/
@Override
public void run() {
Clipboard clipboard = new Clipboard(Display.getDefault());
String contents = (String) clipboard.getContents(TextTransfer.getInstance());
try {
authorAccess.getDocumentController().insertXMLFragment("<link href=\"" + contents + "\"/>", authorAccess.getEditorAccess().getCaretOffset());
} catch (AuthorOperationException e) {
e.printStackTrace();
}
clipboard.dispose();
}
});
}
}
https://www.oxygenxml.com/InstData/Edit ... oller.html
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Add New Paste command in author editor page
Hi Kehua,
For Oxygen desktop there is a similar API to add a menu and toolbars customizer:
https://www.oxygenxml.com/InstData/Edit ... ustomizer)
Then you override the method:
https://www.oxygenxml.com/InstData/Edit ... horAccess)
and it will get called whenever Oxygen wants to show the popup menu in the Author visual editng mode allowing you to add a Java swing action to the popup menu then use the regular Java Swing ways of accessing the clipboard.
Regards,
Radu
For Oxygen desktop there is a similar API to add a menu and toolbars customizer:
https://www.oxygenxml.com/InstData/Edit ... ustomizer)
Then you override the method:
https://www.oxygenxml.com/InstData/Edit ... horAccess)
and it will get called whenever Oxygen wants to show the popup menu in the Author visual editng mode allowing you to add a Java swing action to the popup menu then use the regular Java Swing ways of accessing the clipboard.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 17
- Joined: Tue Aug 15, 2023 10:58 pm
Re: Add New Paste command in author editor page
Radu,
Thank you.
While I am adding the menu to popup menu, I would prefer it to be added at a specific location, for example, right after paste special menu.
what would be the right way to decide the position of paste special menu. I assume menu item name or label is localized, what is the key or property to be used to identify the menu item for paste special?
Thanks,
Kehua
Thank you.
While I am adding the menu to popup menu, I would prefer it to be added at a specific location, for example, right after paste special menu.
what would be the right way to decide the position of paste special menu. I assume menu item name or label is localized, what is the key or property to be used to identify the menu item for paste special?
Thanks,
Kehua
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Add New Paste command in author editor page
Hi Kehua,
Good question, we have an API method which for an action of a component which has some text "pluginWorkspaceAccess.getActionsProvider().getActionID(comp)" should return the translation "key" instead of the translated text.
You should try running some code like this to list all IDs from the popup menu, I think the menu you are interested in has the ID "Author/Paste_special".
Regards,
Radu
Good question, we have an API method which for an action of a component which has some text "pluginWorkspaceAccess.getActionsProvider().getActionID(comp)" should return the translation "key" instead of the translated text.
You should try running some code like this to list all IDs from the popup menu, I think the menu you are interested in has the ID "Author/Paste_special".
Code: Select all
public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
pluginWorkspaceAccess.addMenusAndToolbarsContributorCustomizer(new MenusAndToolbarsContributorCustomizer() {
@Override
public void customizeAuthorPopUpMenu(javax.swing.JPopupMenu popUp, ro.sync.ecss.extensions.api.AuthorAccess authorAccess) {
iterate(popUp);
}
private void iterate(JComponent comp) {
System.err.println(pluginWorkspaceAccess.getActionsProvider().getActionID(comp));
int cc = comp.getComponentCount();
for (int i = 0; i < cc; i++) {
if(comp.getComponent(i) instanceof JComponent) {
iterate((JComponent) comp.getComponent(i));
}
}
}
});
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