blob: 6a6ea6b42a9feeaa124605b88f002cd2443d5baf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*******************************************************************************
* Copyright (c) 2012 protos software gmbh (http://www.protos.de).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* CONTRIBUTORS:
* Henrik Rentz-Reichert (initial contribution)
*
*******************************************************************************/
package org.eclipse.etrice.core.common.ui.editor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.xtext.ui.editor.XtextEditor;
/**
* @author Henrik Rentz-Reichert
*
*/
public class SaveOnFocusLostListener implements IPartListener {
private XtextEditor editor;
private String store;
private String key;
public SaveOnFocusLostListener(XtextEditor editor, String store, String key) {
this.editor = editor;
this.store = store;
this.key = key;
}
/* (non-Javadoc)
* @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart)
*/
@Override
public void partActivated(IWorkbenchPart part) {
}
/* (non-Javadoc)
* @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart)
*/
@Override
public void partBroughtToTop(IWorkbenchPart part) {
}
/* (non-Javadoc)
* @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
*/
@Override
public void partClosed(IWorkbenchPart part) {
}
/* (non-Javadoc)
* @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart)
*/
@Override
public void partDeactivated(IWorkbenchPart part) {
if (!(editor instanceof IValidatingEditor))
return;
boolean save = Platform.getPreferencesService().getBoolean(store, key, true, null);
if (save && editor.isDirty())
if (((IValidatingEditor)editor).isValid())
editor.doSave(new NullProgressMonitor());
}
/* (non-Javadoc)
* @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
*/
@Override
public void partOpened(IWorkbenchPart part) {
}
}
|