Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Convert Line Delimiter Programmatically
Convert Line Delimiter Programmatically [message #550562] Fri, 30 July 2010 19:40 Go to next message
Miguel Mateus is currently offline Miguel MateusFriend
Messages: 3
Registered: June 2010
Location: Portugal
Junior Member
Hello,

I would like to know if there is any way i can change a file's line delimiter programmatically. Something like calling the "Convert Line Delimiter To" from my code (giving an IFile or an IPath).

(changing the line delimiter in the preferences is not an option as it is not applied to already existing files.)

Thank you,
Miguel
Re: Convert Line Delimiter Programmatically [message #550670 is a reply to message #550562] Wed, 04 August 2010 06:30 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3801
Registered: July 2009
Senior Member
Miguel Mateus wrote:
> Hello,
>
> I would like to know if there is any way i can change a file's line
> delimiter programmatically. Something like calling the "Convert Line
> Delimiter To" from my code (giving an IFile or an IPath).
>
> (changing the line delimiter in the preferences is not an option as it
> is not applied to already existing files.)
File > Convert Line Delimiters To

Dani
>
> Thank you,
> Miguel
Re: Convert Line Delimiter Programmatically [message #550981 is a reply to message #550670] Wed, 04 August 2010 18:27 Go to previous messageGo to next message
Miguel Mateus is currently offline Miguel MateusFriend
Messages: 3
Registered: June 2010
Location: Portugal
Junior Member
Thanks Dani, but what i need is a way to call the "File > Convert Line Delimiters To" action from my code.

I've been trying something like this:

public static void convertLineDelimiters(IFile file) {
IPath[] paths = new IPath[] { file.getFullPath() };

ITextFileBufferManager buffManager = FileBuffers.getTextFileBufferManager();

TextFileBufferOperation convertOperation =
new ConvertLineDelimitersOperation("\n");

FileBufferOperationRunner runner = new FileBufferOperationRunner(buffManager, null);

runner.execute(paths, convertOperation, new NullProgressMonitor());
}

But i'm having problems using objects from the package: "org.eclipse.core.filebuffers.manipulation", any reason why?

Thanks.
Re: Convert Line Delimiter Programmatically [message #551061 is a reply to message #550981] Thu, 05 August 2010 05:52 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3801
Registered: July 2009
Senior Member
Miguel Mateus wrote:
> Thanks Dani, but what i need is a way to call the "File > Convert Line
> Delimiters To" action from my code.
>
> I've been trying something like this:
>
> public static void convertLineDelimiters(IFile file) {
> IPath[] paths = new IPath[] { file.getFullPath() };
>
> ITextFileBufferManager buffManager =
> FileBuffers.getTextFileBufferManager();
>
> TextFileBufferOperation convertOperation =
> new ConvertLineDelimitersOperation("\n");
>
> FileBufferOperationRunner runner = new
> FileBufferOperationRunner(buffManager, null);
>
> runner.execute(paths, convertOperation, new NullProgressMonitor());
> }
>
> But i'm having problems using objects from the package:
> "org.eclipse.core.filebuffers.manipulation", any reason why?
Maybe you didn't add it to the 'Require-Bundle' section in your manifest?

Dani
>
> Thanks.
Re: Convert Line Delimiter Programmatically [message #551121 is a reply to message #551061] Thu, 05 August 2010 10:29 Go to previous message
Miguel Mateus is currently offline Miguel MateusFriend
Messages: 3
Registered: June 2010
Location: Portugal
Junior Member
Dani Megert wrote:
>> Thanks Dani, but what i need is a way to call the "File > Convert Line
>> Delimiters To" action from my code.
>>
>> I've been trying something like this:
>>
>> public static void convertLineDelimiters(IFile file) {
>> IPath[] paths = new IPath[] { file.getFullPath() };
>>
>> ITextFileBufferManager buffManager =
>> FileBuffers.getTextFileBufferManager();
>>
>> TextFileBufferOperation convertOperation =
>> new ConvertLineDelimitersOperation("\n");
>>
>> FileBufferOperationRunner runner = new
>> FileBufferOperationRunner(buffManager, null);
>>
>> runner.execute(paths, convertOperation, new NullProgressMonitor());
>> }
>>
>> But i'm having problems using objects from the package:
>> "org.eclipse.core.filebuffers.manipulation", any reason why?
>Maybe you didn't add it to the 'Require-Bundle' section in your manifest?
I'd completely forgotten about that. It's working.

Thank you so much,
Miguel Mateus
>
>Dani
>>
>> Thanks.
Previous Topic:Unable to delete/move files after opening
Next Topic:Project set import (Error deleting resources) eclipse 3.4.2, 3.5.2 and 3.6
Goto Forum:
  


Current Time: Mon Dec 22 08:03:53 GMT 2014

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

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