Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » programmatically call source format (CTRL+SHIFT+F)
programmatically call source format (CTRL+SHIFT+F) [message #784478] Fri, 27 January 2012 15:37 Go to next message
Mark Walters is currently offline Mark WaltersFriend
Messages: 25
Registered: June 2011
Junior Member
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 #784567 is a reply to message #784478] Fri, 27 January 2012 18:02 Go to previous messageGo to next message
Eclipse UserFriend
Look and find the handlers for the format command. The workbench menu spy (Alt-Shift-F2) will tell you the command identifier for a particular menu item, and then a bit of grovelling/grepping through th3 source should provide the associated handler.
Re: programmatically call source format (CTRL+SHIFT+F) [message #786487 is a reply to message #784567] Mon, 30 January 2012 13:49 Go to previous message
Mark Walters is currently offline Mark WaltersFriend
Messages: 25
Registered: June 2011
Junior Member
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.
Previous Topic:Expression-bases Activities always disabled
Next Topic:Dynamic Menu Entry enablement
Goto Forum:
  


Current Time: Fri Mar 29 06:19:06 GMT 2024

Powered by FUDForum. Page generated in 0.02228 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top