Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Enable File-->Save when view part is dirty(How to enable File-->Save (Ctrl+S) menu item when a selected view part is set dirty)
Enable File-->Save when view part is dirty [message #1748272] Mon, 21 November 2016 17:39 Go to next message
Paolo M. is currently offline Paolo M.Friend
Messages: 8
Registered: November 2016
Junior Member
I'm using Eclipse Neon.1 Release (4.6.1) to develop a plugin which contributes to ide.
A view part has a MDirtyable member which is set "dirty" (here an example):

@Inject
MDirtyable dirty;
...
	@PostConstruct
	public void createControls(Composite parent) {
		...
		dirty.setDirty(true);
		...
	}

	@Persist
	public void save() {
	  	dirty.setDirty(false);
	}


How can I enable menu item File-->Save (Ctrl+s) and toolbar item in Eclipse ide?
I must define a command "org.eclipse.ui.file.save" in a fragment?

I made another rcp example, defining command "org.eclipse.ui.file.save", handler and menu item, and it works.

How can be enabled File-->Save menu item in a plugin (ide contribution) when a part is set dirty?

Thank you
Re: [workaround] Enable File-->Save when view part is dirty [message #1748460 is a reply to message #1748272] Wed, 23 November 2016 10:40 Go to previous messageGo to next message
Paolo M. is currently offline Paolo M.Friend
Messages: 8
Registered: November 2016
Junior Member
I found a workaround:

	@Inject
	ECommandService commandService;
	
	@Inject
	EHandlerService handlerService;

	@PostConstruct
	public void createControls(Composite parent) {

		handlerService.activateHandler("org.eclipse.ui.file.save", new org.eclipse.e4.ui.internal.workbench.handlers.SaveHandler());
		....
		dirty.setDirty(true);
		commandService.getCommand("org.eclipse.ui.file.save").isEnabled();
		....
	}

	@Persist
	public void save(ECommandService commandService) {
		....
		dirty.setDirty(false);
		commandService.getCommand("org.eclipse.ui.file.save").isEnabled();
	}

Re: Enable File-->Save when view part is dirty [message #1748461 is a reply to message #1748272] Wed, 23 November 2016 10:46 Go to previous message
Paolo M. is currently offline Paolo M.Friend
Messages: 8
Registered: November 2016
Junior Member
I found a workaround:
	@Inject
	MDirtyable dirty;

	@Inject
	ECommandService commandService;
	
	@Inject
	EHandlerService handlerService;

	@PostConstruct
	public void createControls(Composite parent) {

		handlerService.activateHandler("org.eclipse.ui.file.save", new org.eclipse.e4.ui.internal.workbench.handlers.SaveHandler());
		....
		dirty.setDirty(true);
		commandService.getCommand("org.eclipse.ui.file.save").isEnabled();
		....
	}

	@Persist
	public void save(ECommandService commandService) {
		....
		dirty.setDirty(false);
		commandService.getCommand("org.eclipse.ui.file.save").isEnabled();
	}
Previous Topic:.e4xmi eclipse modeling framework (EMF) file
Next Topic:Slow reaction of Eclipse Editors on a Windows VM
Goto Forum:
  


Current Time: Sun Jun 24 03:48:13 GMT 2018

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

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

Back to the top