Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xText editor encoding when open and save file
xText editor encoding when open and save file [message #921580] Mon, 24 September 2012 08:39 Go to next message
Sebastian Glonner is currently offline Sebastian GlonnerFriend
Messages: 4
Registered: September 2012
Junior Member
Hallo,

I am desperate.
Please can someone tell me how to get the xText Editor to use UTF-8 encoding when displaying and saving files.

It works fine when i set encoding in the preferences but i want/need to force encoding programmatically.

I tried:

UIModule:
	
        public Class<? extends IEncodingProvider> bindIEncodingProvider() {
	    return UTF8EncodingProvider.class;
	}
	
	public void configureIFileSystemAccess(Binder binder) {		
		binder.bind(IFileSystemAccess.class).to(MyFileSystemAccess.class);
	}	


UTF8EncodingProvider:
public class UTF8EncodingProvider implements IEncodingProvider {

	@Override
	public String getEncoding(URI uri) {
		return "UTF-8";
	}
}


MyFileSystemAccess:
public class MyFileSystemAccess extends EclipseResourceFileSystemAccess2 {

	@Override
	protected String getEncoding(IFile file) throws CoreException {
		// TODO Auto-generated method stub
		return "UTF-8";
	}
	@Override
	protected StringInputStream getInputStream(String contentsAsString,
			String encoding) {
	
		System.out.println("askdfjaölskdj");
		return super.getInputStream(contentsAsString, "UTF-8");
	}
}


I appreciate any help/ideas.
Thx in advance.

[Updated on: Mon, 24 September 2012 08:40]

Report message to a moderator

Re: xText editor encoding when open and save file [message #921658 is a reply to message #921580] Mon, 24 September 2012 10:02 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Sebastian,

I assume you have to set the encoding as part of a content type
declaration in addition to the things that you did, e.g.

<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type id="myContentType" name="My Content Type"
base-type="org.eclipse.core.runtime.text"
priority="high"
file-extensions="myExt"
default-charset="UTF-8"/>
</..>

Best regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 24.09.12 10:39, schrieb Sebastian Glonner:
> Hallo,
>
> I am desperate. Please can someone tell me how to get the xText Editor
> to use UTF-8 encoding when displaying and saving files.
>
> It works fine when i set encoding in the preferences but i want/need to
> force encoding programmatically.
>
> I tried:
>
> UIModule:
>
> public Class<? extends IEncodingProvider> bindIEncodingProvider() {
> return UTF8EncodingProvider.class;
> }
>
> public void configureIFileSystemAccess(Binder binder) {
> binder.bind(IFileSystemAccess.class).to(MyFileSystemAccess.class);
> }
>
>
> UTF8EncodingProvider:
> public class UTF8EncodingProvider implements IEncodingProvider {
>
> @Override
> public String getEncoding(URI uri) {
> return "UTF-8";
> }
> }
>
>
> MyFileSystemAccess:
> public class MyFileSystemAccess extends EclipseResourceFileSystemAccess2 {
>
> @Override
> protected String getEncoding(IFile file) throws CoreException {
> // TODO Auto-generated method stub
> return "UTF-8";
> }
> @Override
> protected StringInputStream getInputStream(String contentsAsString,
> String encoding) {
>
> System.out.println("askdfjaölskdj");
> return super.getInputStream(contentsAsString, "UTF-8");
> }
> }
Re: xText editor encoding when open and save file [message #921802 is a reply to message #921580] Mon, 24 September 2012 12:47 Go to previous message
Sebastian Glonner is currently offline Sebastian GlonnerFriend
Messages: 4
Registered: September 2012
Junior Member
thousand thanks!
That did the trick. And i dont need any of the bindings!
Previous Topic:Marker translated to Annotation
Next Topic:problem for define dsl
Goto Forum:
  


Current Time: Sat Apr 20 02:06:01 GMT 2024

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

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

Back to the top