|
Re: right place to add save actions? [message #787188 is a reply to message #786926] |
Tue, 31 January 2012 08:55 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Henrik,
there is no need to save twice. I'd go with modifying the document's
content and calling super.doSave...
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 31.01.12 01:23, schrieb Henrik Lindberg:
> Hi,
> I want to add a couple of save actions to my editor (to perform actions
> like 'remove trailing whitespace', 'ensure file ends with a newline',
> and 'replace funky whitespace characters with regular space' - to
> mention a few).
>
> What is the right approach to doing this. By default, it seems that the
> IDE SaveAction ends up calling doSaveDocument(...) on
> XtextDocumentProvider that is inherited from FileDocumentProvider.
>
> Is it a good approach to override the document provider with my own,
> implement doSaveDocument, and perform an update of the document using an
> IUnitOfWork before passing on to the super doSaveDocument ?
>
> Or is the right approach to save it twice? I.e. first save "as is", then
> run a modification, and then trigger the save again?
>
> Any pointers or bits of advice?
>
> Regards
> - henrik
|
|
|
Re: right place to add save actions? [message #940606 is a reply to message #787188] |
Thu, 11 October 2012 20:10 |
Michael Steiner Messages: 3 Registered: April 2010 |
Junior Member |
|
|
Hi,
I want to implement the save action "Format source code" (i.e. "Format on save"). Therefore, I call the Xtext format command in a custom XtextDocumentProvider:
public class MyDslDocumentProvider extends XtextDocumentProvider {
private static final String XTEXT_FORMAT_ACTION_COMMAND_ID = "org.eclipse.xtext.ui.FormatAction";
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
throws CoreException {
// auto-format
IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
try {
service.executeCommand(XTEXT_FORMAT_ACTION_COMMAND_ID, null);
} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
e.printStackTrace();
}
// save
super.doSaveDocument(monitor, element, document, overwrite);
}
}
Is this the right approach or is there a better way?
Regards,
Michael
|
|
|
|
Powered by
FUDForum. Page generated in 0.02848 seconds