|
Lines 10-23
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.ide.dialogs; |
11 |
package org.eclipse.ui.ide.dialogs; |
| 12 |
|
12 |
|
|
|
13 |
import org.eclipse.core.internal.resources.ProjectPreferences; |
| 13 |
import org.eclipse.core.resources.IContainer; |
14 |
import org.eclipse.core.resources.IContainer; |
| 14 |
import org.eclipse.core.resources.IFile; |
15 |
import org.eclipse.core.resources.IFile; |
|
|
16 |
import org.eclipse.core.resources.IProject; |
| 15 |
import org.eclipse.core.resources.IResource; |
17 |
import org.eclipse.core.resources.IResource; |
| 16 |
import org.eclipse.core.resources.IWorkspaceRoot; |
18 |
import org.eclipse.core.resources.IWorkspaceRoot; |
|
|
19 |
import org.eclipse.core.resources.ProjectScope; |
| 20 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 17 |
import org.eclipse.core.runtime.Assert; |
21 |
import org.eclipse.core.runtime.Assert; |
| 18 |
import org.eclipse.core.runtime.CoreException; |
22 |
import org.eclipse.core.runtime.CoreException; |
| 19 |
import org.eclipse.core.runtime.IProgressMonitor; |
23 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 20 |
import org.eclipse.core.runtime.IStatus; |
24 |
import org.eclipse.core.runtime.IStatus; |
|
|
25 |
import org.eclipse.core.runtime.Platform; |
| 21 |
import org.eclipse.core.runtime.Status; |
26 |
import org.eclipse.core.runtime.Status; |
| 22 |
import org.eclipse.core.runtime.content.IContentDescription; |
27 |
import org.eclipse.core.runtime.content.IContentDescription; |
| 23 |
import org.eclipse.core.runtime.jobs.Job; |
28 |
import org.eclipse.core.runtime.jobs.Job; |
|
Lines 27-32
Link Here
|
| 27 |
import org.eclipse.osgi.util.NLS; |
32 |
import org.eclipse.osgi.util.NLS; |
| 28 |
import org.eclipse.swt.SWT; |
33 |
import org.eclipse.swt.SWT; |
| 29 |
import org.eclipse.swt.layout.GridData; |
34 |
import org.eclipse.swt.layout.GridData; |
|
|
35 |
import org.eclipse.swt.widgets.Button; |
| 30 |
import org.eclipse.swt.widgets.Composite; |
36 |
import org.eclipse.swt.widgets.Composite; |
| 31 |
import org.eclipse.swt.widgets.Control; |
37 |
import org.eclipse.swt.widgets.Control; |
| 32 |
import org.eclipse.swt.widgets.Group; |
38 |
import org.eclipse.swt.widgets.Group; |
|
Lines 36-41
Link Here
|
| 36 |
import org.eclipse.ui.ide.IDEEncoding; |
42 |
import org.eclipse.ui.ide.IDEEncoding; |
| 37 |
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; |
43 |
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; |
| 38 |
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; |
44 |
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; |
|
|
45 |
import org.osgi.service.prefs.BackingStoreException; |
| 46 |
import org.osgi.service.prefs.Preferences; |
| 39 |
|
47 |
|
| 40 |
/** |
48 |
/** |
| 41 |
* The ResourceEncodingFieldEditor is a field editor for editing the encoding of |
49 |
* The ResourceEncodingFieldEditor is a field editor for editing the encoding of |
|
Lines 56-61
Link Here
|
| 56 |
|
64 |
|
| 57 |
private Composite group; |
65 |
private Composite group; |
| 58 |
|
66 |
|
|
|
67 |
private Button separateDerivedEncodingsButton = null; |
| 68 |
|
| 59 |
/** |
69 |
/** |
| 60 |
* Creates a new encoding field editor for setting the encoding on the given |
70 |
* Creates a new encoding field editor for setting the encoding on the given |
| 61 |
* resource. |
71 |
* resource. |
|
Lines 140-145
Link Here
|
| 140 |
|
150 |
|
| 141 |
} |
151 |
} |
| 142 |
|
152 |
|
|
|
153 |
private boolean getStoredSeparateDerivedEncodingsValue() { |
| 154 |
// be careful looking up for our node so not to create any nodes as side effect |
| 155 |
Preferences node = Platform.getPreferencesService().getRootNode() |
| 156 |
.node(ProjectScope.SCOPE); |
| 157 |
String projectName = ((IProject) resource).getName(); |
| 158 |
try { |
| 159 |
//TODO once bug 90500 is fixed, should be as simple as this: |
| 160 |
// String path = projectName + IPath.SEPARATOR + ResourcesPlugin.PI_RESOURCES; |
| 161 |
// return node.nodeExists(path) ? node.node(path).getBoolean(ResourcesPlugin.PREF_SEPARATE_DERIVED_ENCODINGS, false) : false; |
| 162 |
// for now, take the long way |
| 163 |
if (!node.nodeExists(projectName)) |
| 164 |
return false; |
| 165 |
node = node.node(projectName); |
| 166 |
if (!node.nodeExists(ResourcesPlugin.PI_RESOURCES)) |
| 167 |
return false; |
| 168 |
node = node.node(ResourcesPlugin.PI_RESOURCES); |
| 169 |
return node.getBoolean( |
| 170 |
ProjectPreferences.PREF_SEPARATE_DERIVED_ENCODINGS, false); |
| 171 |
} catch (BackingStoreException e) { |
| 172 |
// default value |
| 173 |
return false; |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
private boolean hasSameSeparateDerivedEncodings() { |
| 178 |
return (separateDerivedEncodingsButton == null) |
| 179 |
|| ((separateDerivedEncodingsButton != null) && (separateDerivedEncodingsButton |
| 180 |
.getSelection() == getStoredSeparateDerivedEncodingsValue())); |
| 181 |
} |
| 182 |
|
| 143 |
/* |
183 |
/* |
| 144 |
* (non-Javadoc) |
184 |
* (non-Javadoc) |
| 145 |
* |
185 |
* |
|
Lines 154-160
Link Here
|
| 154 |
encoding = null; |
194 |
encoding = null; |
| 155 |
} |
195 |
} |
| 156 |
// Don't update if the same thing is selected |
196 |
// Don't update if the same thing is selected |
| 157 |
if (hasSameEncoding(encoding)) { |
197 |
final boolean hasSameEncoding = hasSameEncoding(encoding); |
|
|
198 |
final boolean hasSameSeparateDerivedEncodings = hasSameSeparateDerivedEncodings(); |
| 199 |
if (hasSameEncoding && hasSameSeparateDerivedEncodings) { |
| 158 |
return; |
200 |
return; |
| 159 |
} |
201 |
} |
| 160 |
|
202 |
|
|
Lines 200-210
Link Here
|
| 200 |
*/ |
242 |
*/ |
| 201 |
protected IStatus run(IProgressMonitor monitor) { |
243 |
protected IStatus run(IProgressMonitor monitor) { |
| 202 |
try { |
244 |
try { |
| 203 |
if (resource instanceof IContainer) { |
245 |
if (!hasSameEncoding) { |
| 204 |
((IContainer) resource).setDefaultCharset( |
246 |
if (resource instanceof IContainer) { |
| 205 |
finalEncoding, monitor); |
247 |
((IContainer) resource).setDefaultCharset( |
| 206 |
} else { |
248 |
finalEncoding, monitor); |
| 207 |
((IFile) resource).setCharset(finalEncoding, monitor); |
249 |
} else { |
|
|
250 |
((IFile) resource).setCharset(finalEncoding, |
| 251 |
monitor); |
| 252 |
} |
| 253 |
} |
| 254 |
if (!hasSameSeparateDerivedEncodings) { |
| 255 |
Preferences prefs = new ProjectScope((IProject) resource).getNode(ResourcesPlugin.PI_RESOURCES); |
| 256 |
if (getStoredSeparateDerivedEncodingsValue()) |
| 257 |
prefs.remove(ProjectPreferences.PREF_SEPARATE_DERIVED_ENCODINGS); |
| 258 |
else |
| 259 |
prefs.putBoolean(ProjectPreferences.PREF_SEPARATE_DERIVED_ENCODINGS, true); |
| 260 |
prefs.flush(); |
| 208 |
} |
261 |
} |
| 209 |
return Status.OK_STATUS; |
262 |
return Status.OK_STATUS; |
| 210 |
} catch (CoreException e) {// If there is an error return the |
263 |
} catch (CoreException e) {// If there is an error return the |
|
Lines 214-219
Link Here
|
| 214 |
IDEWorkbenchMessages.ResourceEncodingFieldEditor_ErrorStoringMessage, |
267 |
IDEWorkbenchMessages.ResourceEncodingFieldEditor_ErrorStoringMessage, |
| 215 |
e.getStatus()); |
268 |
e.getStatus()); |
| 216 |
return e.getStatus(); |
269 |
return e.getStatus(); |
|
|
270 |
} catch (BackingStoreException e) { |
| 271 |
IDEWorkbenchPlugin.log(IDEWorkbenchMessages.ResourceEncodingFieldEditor_ErrorStoringMessage, e); |
| 272 |
return new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, e.getMessage(), e); |
| 217 |
} |
273 |
} |
| 218 |
} |
274 |
} |
| 219 |
}; |
275 |
}; |
|
Lines 237-244
Link Here
|
| 237 |
* |
293 |
* |
| 238 |
* @see org.eclipse.jface.preference.FieldEditor#load() |
294 |
* @see org.eclipse.jface.preference.FieldEditor#load() |
| 239 |
*/ |
295 |
*/ |
| 240 |
public void load() {// Override the load method as we are not using a |
296 |
public void load() {// Override the load method as we are not using a preference store |
| 241 |
// preference store |
|
|
| 242 |
setPresentsDefaultValue(false); |
297 |
setPresentsDefaultValue(false); |
| 243 |
doLoad(); |
298 |
doLoad(); |
| 244 |
} |
299 |
} |
|
Lines 248-259
Link Here
|
| 248 |
* |
303 |
* |
| 249 |
* @see org.eclipse.jface.preference.FieldEditor#loadDefault() |
304 |
* @see org.eclipse.jface.preference.FieldEditor#loadDefault() |
| 250 |
*/ |
305 |
*/ |
| 251 |
public void loadDefault() { |
306 |
public void loadDefault() {// Override the loadDefault method as we are not using a preference store |
| 252 |
setPresentsDefaultValue(true); |
307 |
setPresentsDefaultValue(true); |
| 253 |
doLoadDefault(); |
308 |
doLoadDefault(); |
| 254 |
refreshValidState(); |
309 |
refreshValidState(); |
| 255 |
} |
310 |
} |
| 256 |
|
311 |
|
|
|
312 |
/* (non-Javadoc) |
| 313 |
* @see org.eclipse.jface.preference.FieldEditor#doLoadDefault() |
| 314 |
*/ |
| 315 |
protected void doLoadDefault() { |
| 316 |
super.doLoadDefault(); |
| 317 |
if (separateDerivedEncodingsButton != null) |
| 318 |
separateDerivedEncodingsButton |
| 319 |
.setSelection(getStoredSeparateDerivedEncodingsValue()); |
| 320 |
} |
| 321 |
|
| 257 |
/* |
322 |
/* |
| 258 |
* (non-Javadoc) |
323 |
* (non-Javadoc) |
| 259 |
* |
324 |
* |
|
Lines 360-365
Link Here
|
| 360 |
label.setLayoutData(layoutData); |
425 |
label.setLayoutData(layoutData); |
| 361 |
|
426 |
|
| 362 |
} |
427 |
} |
|
|
428 |
|
| 429 |
if (resource.getType() == IResource.PROJECT) { |
| 430 |
separateDerivedEncodingsButton = new Button(group, SWT.CHECK); |
| 431 |
GridData data = new GridData(); |
| 432 |
data.horizontalSpan = 2; |
| 433 |
separateDerivedEncodingsButton.setLayoutData(data); |
| 434 |
separateDerivedEncodingsButton |
| 435 |
.setText(IDEWorkbenchMessages.ResourceEncodingFieldEditor_SeparateDerivedEncodingsLabel); |
| 436 |
separateDerivedEncodingsButton |
| 437 |
.setSelection(getStoredSeparateDerivedEncodingsValue()); |
| 438 |
} |
| 363 |
return group; |
439 |
return group; |
| 364 |
} |
440 |
} |
| 365 |
|
441 |
|