programmatically call source format (CTRL+SHIFT+F) [message #784478] |
Fri, 27 January 2012 10:37  |
Eclipse User |
|
|
|
Hi,
I wondered how I can format text in an XML editor programmatically?
I've not seen any simple way to call the same action that is done from CTRL+SHIFT+F - surely this is simple!? I have the IEditorPart that I have created and opened, and the original text I have put in it. The editor is org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart.
I've tried:
TextEdit edit = codeFormatter.format( CodeFormatter.K_UNKNOWN,mystring, 0, mystring.length(), 0,null);
but edit always comes back as null.
Any help would be great.
Ta,
Mark.
|
|
|
|
Re: programmatically call source format (CTRL+SHIFT+F) [message #786487 is a reply to message #784567] |
Mon, 30 January 2012 08:49  |
Eclipse User |
|
|
|
thanks, I've determined what should work but unfortunately it's still failing for my particular editor I've opened (XML):
I open the editor and use a part listener to fire when the editor opens:
IEditorPart editor = page.openEditor(input, "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart");
public void partActivated(IWorkbenchPartReference ref) {
IWorkbenchPart editor = ref.getPart(false);
final ITextOperationTarget fOperationTarget = (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class);
if (fOperationTarget != null) {
WorkbenchJob refreshJob = new WorkbenchJob(
"Format transformed XML") {
public IStatus runInUIThread(IProgressMonitor monitor) {
fOperationTarget.doOperation(ISourceViewer.FORMAT);
return Status.OK_STATUS;
}
};
refreshJob.schedule(6000);
This doesn't work, however, and I get no error. I don't have the source for the XML editor so can't step through. I might try and get it and do this though unless anyone can see anything glaringly obvious.
Ta,
Mark.
|
|
|
Powered by
FUDForum. Page generated in 0.03880 seconds