[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-dev] how to get the IDocument of an ITextFileBuffer created from an IFile?
|
> I try to replace text in a file and for that I would like to use a IDocument
> interface. Before I got it from (1.) a page, a (2.) IFileEditorInput and a
> (3.) IEditorDescriptor
> My function looked like underneath but then it always brought the window up
> front.. and I don't want that.
>
> public void replaceText(IFile file, int offset, int length, String text) {
> IWorkbench wb = PlatformUI.getWorkbench();
...
> }
> }
>
> Now I would like to get the IDocument interface from the ITextFileBuffer
> instead but it keeps returning a length of zero...
> Anyone who know why the ITextFileBuffer can't get hold of a working
> IDocument?
I don't know, but did you try something like the following using
a TextFileDocumentProvider?
public void replaceText( IFile file, int offset, int length, String text )
{
IDocumentProvider provider = new TextFileDocumentProvider();
try
{
provider.connect(file);
IDocument document = provider.getDocument(file);
if ( document != null )
{
document.replace(offset,length,text);
}
}
catch (CoreException e)
{
}
catch (BadLocationException e)
{
}
}