Skip to main content



      Home
Home » Modeling » TMF (Xtext) » right place to add save actions?
right place to add save actions? [message #786926] Mon, 30 January 2012 19:23 Go to next message
Eclipse UserFriend
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 #787188 is a reply to message #786926] Tue, 31 January 2012 03:55 Go to previous messageGo to next message
Eclipse UserFriend
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 16:10 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: right place to add save actions? [message #1412967 is a reply to message #940606] Wed, 27 August 2014 08:57 Go to previous message
Eclipse UserFriend
The above made my day, thanks Smile
Previous Topic:Code Formatter and comments.
Next Topic:Non-empty model in the beginning
Goto Forum:
  


Current Time: Wed Jul 02 16:38:21 EDT 2025

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

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

Back to the top