java - Retrieving location of currently opened file or project in netbeans -
i'm using custom button in netbeans references file in open project. however, i'm having issue retrieving location of file based upon open project. therefore, need can return location of project i'm working in or location of file i'm working with.
in essence, need able call
string projectlocation = methodorvartogetopenprojectlocation(); i can't use current directory, because plugin i've created button doesn't live in same place project i'm working in.
any thoughts?
you can find project directory so:
lookup lookup = utilities.actionsglobalcontext(); project project = lookup.lookup(project.class); fileobject projectdir = project.getprojectdirectory(); string projectlocation = projectdir.getpath(); the classes netbeans api: utilities, lookup, project, , fileobject
if don't want use current project can use openprojects class. can first open project follows:
project project = openprojects.getdefault().getopenprojects()[0]; depending on button might make sense use the main project:
project mainproject = openprojects.getdefault().getmainproject();
Comments
Post a Comment