How to access opened files in Netbeans IDE

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

How to access opened files in Netbeans IDE

Martin Velek

Hello,
I've been struggling with this problem for a while. I've tried to google the solution, but with no luck so far. I'm working on extending Netbeans IDE and I need access to currently open tabs (preferably C source code files). I need to get the file paths to these files. Can anybody point me to the right direction? Thanks.

Yours faithfully
Martin Velek

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to access opened files in Netbeans IDE

Emilian Bold-2
Something like http://bits.netbeans.org/dev/javadoc/org-openide-windows/org/openide/windows/TopComponent.Registry.html#getOpened() ?

Then I guess you could look at the Nodes or see what's in the Lookup and find a DataObject/FileObject, etc.

--emi

On Tue, Feb 21, 2012 at 7:19 PM, Martin Velek <[hidden email]> wrote:

Hello,
I've been struggling with this problem for a while. I've tried to google the solution, but with no luck so far. I'm working on extending Netbeans IDE and I need access to currently open tabs (preferably C source code files). I need to get the file paths to these files. Can anybody point me to the right direction? Thanks.

Yours faithfully
Martin Velek




--
http://www.josekibold.ro : Honesty & well-done software.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to access opened files in Netbeans IDE

Ernie Rael
The class NbEditorUtilities has static methods getDataObject/getFileObject.

With the TopComponent you can do tc.getLookup().lookup(EditorCookie.class).getDocument() (and watch out for null)

-ernie

On 2/21/2012 9:22 AM, Emilian Bold wrote:
Something like http://bits.netbeans.org/dev/javadoc/org-openide-windows/org/openide/windows/TopComponent.Registry.html#getOpened() ?

Then I guess you could look at the Nodes or see what's in the Lookup and find a DataObject/FileObject, etc.

--emi

On Tue, Feb 21, 2012 at 7:19 PM, Martin Velek <[hidden email]> wrote:

Hello,
I've been struggling with this problem for a while. I've tried to google the solution, but with no luck so far. I'm working on extending Netbeans IDE and I need access to currently open tabs (preferably C source code files). I need to get the file paths to these files. Can anybody point me to the right direction? Thanks.

Yours faithfully
Martin Velek




--
http://www.josekibold.ro : Honesty & well-done software.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to access opened files in Netbeans IDE

Martin Velek
Thank you. Did you mean something like this?

List<FileObject> fos = new ArrayList<FileObject>();
Set<TopComponent> opened = TopComponent.getRegistry().getOpened();

Document d = null;
for (TopComponent tc : opened) {
    d = tc.getLookup().lookup(EditorCookie.class).getDocument();
    if (d != null) {
        fos.add(NbEditorUtilities.getFileObject(d));
    }
}

Unfortunately this piece of code causes a compilation error. I'm new to all this and this was all I could work out. Here's what compiler spit out: C:\Program Files\NetBeans 7.0.1\harness\common.xml:206: Compile failed; see the compiler error output for details.

common.xml:

205: <nb-javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="${build.compiler.debug}" debuglevel="${build.compiler.debuglevel}" encoding="UTF-8"

206: deprecation="${build.compiler.deprecation}" optimize="${build.compiler.optimize}" source="${javac.source}" target="${javac.target}" includeantruntime="false">

207: <classpath refid="cp"/>
208: <compilerarg line="${javac.compilerargs}"/>
209: <processorpath refid="processor.cp"/>
210: </nb-javac>

Loading...