Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 54464
Collapse All | Expand All

(-)src/org/eclipse/ui/editors/text/TextEditor.java (-51 lines)
Lines 109-135 Link Here
109
109
110
		super.dispose();
110
		super.dispose();
111
	}
111
	}
112
113
	/*
114
	 * @see AbstractTextEditor#doSaveAs()
115
	 * @since 2.1
116
	 */
117
	public void doSaveAs() {
118
		if (askIfNonWorkbenchEncodingIsOk())
119
			super.doSaveAs();
120
	}
121
	
112
	
122
	/*
123
	 * @see AbstractTextEditor#doSave(IProgressMonitor)
124
	 * @since 2.1
125
	 */
126
	public void doSave(IProgressMonitor monitor){
127
		if (askIfNonWorkbenchEncodingIsOk())
128
			super.doSave(monitor);
129
		else
130
			monitor.setCanceled(true);
131
	}
132
133
	/**
113
	/**
134
	 * Installs the encoding support on the given text editor.
114
	 * Installs the encoding support on the given text editor.
135
	 * <p> 
115
	 * <p> 
Lines 141-177 Link Here
141
	protected void installEncodingSupport() {
121
	protected void installEncodingSupport() {
142
		fEncodingSupport= new DefaultEncodingSupport();
122
		fEncodingSupport= new DefaultEncodingSupport();
143
		fEncodingSupport.initialize(this);
123
		fEncodingSupport.initialize(this);
144
	}
145
146
	/**
147
	 * Asks the user if it is ok to store in non-workbench encoding.
148
	 * 
149
	 * @return <true> if the user wants to continue or if no encoding support has been installed
150
	 * @since 2.1
151
	 */
152
	private boolean askIfNonWorkbenchEncodingIsOk() {
153
		
154
		if (fEncodingSupport == null)
155
			return true;
156
		
157
		IDocumentProvider provider= getDocumentProvider();
158
		if (provider instanceof IStorageDocumentProvider) {
159
			IEditorInput input= getEditorInput();
160
			IStorageDocumentProvider storageProvider= (IStorageDocumentProvider)provider;
161
			String encoding= storageProvider.getEncoding(input);
162
			String defaultEncoding= storageProvider.getDefaultEncoding();
163
			if (encoding != null && !encoding.equals(defaultEncoding)) {
164
				Shell shell= getSite().getShell();
165
				String title= TextEditorMessages.getString("Editor.warning.save.nonWorkbenchEncoding.title"); //$NON-NLS-1$
166
				String msg;
167
				if (input != null)
168
					msg= MessageFormat.format(TextEditorMessages.getString("Editor.warning.save.nonWorkbenchEncoding.message1"), new String[] {input.getName(), encoding});//$NON-NLS-1$
169
				else
170
					msg= MessageFormat.format(TextEditorMessages.getString("Editor.warning.save.nonWorkbenchEncoding.message2"), new String[] {encoding});//$NON-NLS-1$
171
				return MessageDialog.openQuestion(shell, title, msg);
172
			}
173
		}
174
		return true;
175
	}
124
	}
176
125
177
	/**
126
	/**
(-)src/org/eclipse/ui/editors/text/TextEditorMessages.properties (-4 lines)
Lines 26-35 Link Here
26
Editor.error.save.message=Save could not be completed. {0}
27
Editor.error.save.message=Save could not be completed. {0}
27
Editor.error.save.title=Problems During Save As...
28
Editor.error.save.title=Problems During Save As...
28
Editor.warning.save.delete=The original file ''{0}'' has been deleted.
29
Editor.warning.save.delete=The original file ''{0}'' has been deleted.
29
30
Editor.warning.save.nonWorkbenchEncoding.title= Save Resource In Non-Workbench Encoding
31
Editor.warning.save.nonWorkbenchEncoding.message1= {0} will be saved in \" {1} \" encoding which is not the current workbench encoding. This can result in conflicts with other tools. Continue anyway?
32
Editor.warning.save.nonWorkbenchEncoding.message2= The resource will be saved in \" {0} \" encoding which is not the current platform encoding. This can result in conflicts with other tools. Continue anyway?
33
30
34
Editor.AddMenu.label=&Add
31
Editor.AddMenu.label=&Add
35
32

Return to bug 54464