mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug Fixing
This commit is contained in:
parent
889a492487
commit
395aab5426
3 changed files with 46 additions and 9 deletions
|
@ -1,3 +1,9 @@
|
|||
2004-06-21 Hoda Amer
|
||||
Fix for PR 67696: [I18N] - New Class Wizard does not take project encoding into account when creating files
|
||||
Now the encoding is taken into consideration when committing a working copy contents to a file.
|
||||
* model/org/eclipse/cdt/internal/core/model/Buffer.java
|
||||
* model/org/eclipse/cdt/internal/core/model/WorkingCopy.java
|
||||
|
||||
2004-06-18 Alain Magloire
|
||||
|
||||
Fix for PR 66108
|
||||
|
|
|
@ -12,11 +12,15 @@ package org.eclipse.cdt.internal.core.model;
|
|||
***********************************************************************/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.ICLogConstants;
|
||||
import org.eclipse.cdt.core.model.*;
|
||||
import org.eclipse.cdt.core.model.BufferChangedEvent;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
import org.eclipse.cdt.core.model.IBufferChangedListener;
|
||||
import org.eclipse.cdt.core.model.ICModelStatusConstants;
|
||||
import org.eclipse.cdt.core.model.IOpenable;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
@ -300,16 +304,31 @@ public class Buffer implements IBuffer {
|
|||
|
||||
// use a platform operation to update the resource contents
|
||||
try {
|
||||
String encoding = null;
|
||||
try {
|
||||
encoding = this.file.getCharset();
|
||||
}
|
||||
catch (CoreException ce) {
|
||||
// use no encoding
|
||||
}
|
||||
String contents = this.getContents();
|
||||
if (contents == null) return;
|
||||
byte[] bytes = contents.getBytes();
|
||||
byte[] bytes = encoding == null
|
||||
? contents.getBytes()
|
||||
: contents.getBytes(encoding);
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
||||
|
||||
this.file.setContents(
|
||||
stream,
|
||||
force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
|
||||
null);
|
||||
}
|
||||
if (this.file.exists()) {
|
||||
this.file.setContents(
|
||||
stream,
|
||||
force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
|
||||
null);
|
||||
} else {
|
||||
this.file.create(stream, force, null);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION);
|
||||
}
|
||||
catch (CoreException e) {
|
||||
throw new CModelException(e);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.model;
|
|||
***********************************************************************/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
|
@ -83,9 +84,18 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
String contents = this.getSource();
|
||||
if (contents == null) return;
|
||||
try {
|
||||
byte[] bytes = contents.getBytes();
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
||||
IFile originalRes = (IFile)original.getResource();
|
||||
String encoding = null;
|
||||
try {
|
||||
encoding = originalRes.getCharset();
|
||||
}
|
||||
catch (CoreException ce) {
|
||||
// use no encoding
|
||||
}
|
||||
byte[] bytes = encoding == null
|
||||
? contents.getBytes()
|
||||
: contents.getBytes(encoding);
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
|
||||
if (originalRes.exists()) {
|
||||
originalRes.setContents(
|
||||
stream,
|
||||
|
@ -97,6 +107,8 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
|
|||
force,
|
||||
monitor);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION);
|
||||
} catch (CoreException e) {
|
||||
throw new CModelException(e);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue