Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Anyone know how to pickup all editor save events?
Anyone know how to pickup all editor save events? [message #637772] Mon, 08 November 2010 19:19 Go to next message
Max Mising name is currently offline Max Mising nameFriend
Messages: 54
Registered: September 2010
Member
I have a perspective that reuses built in eclipse editors which I open with my own IURIEditorInput. I need to override all of the save events. I have overridden the built in org.eclipse.ui.file.save/saveAs/saveAll but the ones I'm having problems with are close/closeAll/closeOthers save's. Where they prompt to save on close if editor is dirty. I can't seem to pick up these events. Anyone know how? Remember, the big problem is I'm using built-in eclipse editors.

Thanks

Max
Re: Anyone know how to pickup all editor save events? [message #637792 is a reply to message #637772] Mon, 08 November 2010 21:35 Go to previous messageGo to next message
Devi Vara Prasad Bandaru is currently offline Devi Vara Prasad BandaruFriend
Messages: 100
Registered: March 2010
Location: Hyderabad
Senior Member

Try the below snippet. From debugging the code i could see that there is only one document provider associated with each type of editor(Java, Text etc..) . You need to test for the other editors.
private Map<Object, Object> docProviders = new WeakHashMap<Object, Object>();
    
	public void partOpened(IWorkbenchPart part) {
		if (part instanceof ITextEditor) {
			IDocumentProvider documentProvider = ((ITextEditor) part).getDocumentProvider();
			if (!docProviders.containsKey(documentProvider)) {
				documentProvider.addElementStateListener(saveEventListener);
			}
		}
	}

	private IElementStateListener saveEventListener = new IElementStateListener() {
		
		@Override
		public void elementDirtyStateChanged(Object element, boolean isDirty) {
			if (!isDirty) {
				System.out.println(element + " is saved at " + new Date());
			}
		}

		@Override
		public void elementMoved(Object originalElement, Object movedElement) {
			
		}

		@Override
		public void elementDeleted(Object element) {
		}
		
		@Override
		public void elementContentReplaced(Object element) {
		}
		
		@Override
		public void elementContentAboutToBeReplaced(Object element) {
		}
	};




Re: Anyone know how to pickup all editor save events? [message #637795 is a reply to message #637772] Mon, 08 November 2010 21:51 Go to previous messageGo to next message
Max Mising name is currently offline Max Mising nameFriend
Messages: 54
Registered: September 2010
Member
Thanks for the reply, I did end up doing that where I know the doc was saved if the last dirty state was dirty and the new state was not dirty. I was just hoping there might be a cleaner way

Max
Re: Anyone know how to pickup all editor save events? [message #637858 is a reply to message #637795] Tue, 09 November 2010 07:43 Go to previous message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Max wrote:
> Thanks for the reply, I did end up doing that where I know the doc was
> saved if the last dirty state was dirty and the new state was not
> dirty. I was just hoping there might be a cleaner way
Take a look at
org.eclipse.core.filebuffers.IFileBufferManager.addFileBuffe rListener(IFileBufferListener).

Dani
>
> Max
Previous Topic:Problem Starting glassfish server
Next Topic:how to organize dependent features
Goto Forum:
  


Current Time: Wed Jan 27 17:34:09 GMT 2021

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

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

Back to the top