Determine the current project

Is there any way to get the current project?
I found ProjectManager.getInstance().getOpenProjects(), but now I only have a list of open projects without any hint which one is currently active.

8 comments
Comment actions Permalink

Hello Martin,

MF> Is there any way to get the current project?
MF> I found ProjectManager.getInstance().getOpenProjects(), but now I
MF> only have a list of open projects without any hint which one is
MF> currently active.

Old time issue. It's not possible. But you can make some tricks with current
editor...

Thanks!
--
Alexey Efimov, Java Developer
Tops BI
http://www.topsbi.ru

0
Comment actions Permalink

Oh yes, it's possible!

I'm currently inside a SettingsEditor. Though this works:

class MySettingsEditor extends SettingsEditor {

// unrelated stuff omitted...

private Project getCurrentProject() {
WindowManager wm = WindowManager.getInstance();
Project[] projects =
ProjectManager.getInstance().getOpenProjects();
for (int i = 0; i < projects.length; i++) {
if (SwingUtilities.isDescendingFrom(getComponent(),
wm.suggestParentWindow(projects+))) {
return projects+;
}
}
return null;
}
}

Alexey Efimov wrote:

Hello Martin,

MF> Is there any way to get the current project?
MF> I found ProjectManager.getInstance().getOpenProjects(), but now I
MF> only have a list of open projects without any hint which one is
MF> currently active.

Old time issue. It's not possible. But you can make some tricks with
current editor...

Thanks!
--
Alexey Efimov, Java Developer
Tops BI
http://www.topsbi.ru


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0
Comment actions Permalink

Hello Martin,

MF> Oh yes, it's possible!

:)) Yes from DispatchThread... But that is active project in real? Is it
the same as modal dialog is show?

So, can i ask in that place you need to know active project? Just for interest.

Thanks!
--
Alexey Efimov, Java Developer
Tops BI
http://www.topsbi.ru

0
Comment actions Permalink

I use it to display some information in the currently visible state bar
from within an IDE configuration panel. So I don't care if it's really
the active project the user is working with, I only care that the
project's state bar is currently visible.

Alexey Efimov wrote:

Hello Martin,

MF> Oh yes, it's possible!

:)) Yes from DispatchThread... But that is active project in real? Is it
the same as modal dialog is show?

So, can i ask in that place you need to know active project? Just for
interest.

Thanks!
--
Alexey Efimov, Java Developer
Tops BI
http://www.topsbi.ru


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0
Comment actions Permalink

Hello Martin,

MF> I use it to display some information in the currently visible state
MF> bar from within an IDE configuration panel. So I don't care if it's
MF> really the active project the user is working with, I only care that
MF> the project's state bar is currently visible.

Now i catch :)
If you have Project level Configurable, then simple method to get current
project - ask it from Project level component.

Thanks!
--
Alexey Efimov, Java Developer
Tops BI
http://www.topsbi.ru

0
Comment actions Permalink

Yes, that would have been the simple case. But unfortunately I'm in an
application level configurable...

Alexey Efimov wrote:

Hello Martin,

MF> I use it to display some information in the currently visible state
MF> bar from within an IDE configuration panel. So I don't care if it's
MF> really the active project the user is working with, I only care that
MF> the project's state bar is currently visible.

Now i catch :)
If you have Project level Configurable, then simple method to get
current project - ask it from Project level component.

Thanks!
--
Alexey Efimov, Java Developer
Tops BI
http://www.topsbi.ru


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0
Comment actions Permalink

Hello Martin,

MF> Yes, that would have been the simple case. But unfortunately I'm in
MF> an application level configurable...

In this case you get right solution :))
Also you can use:
com.intellij.ide.DataManager to get current DataContext.

Project project = (Project)DataManager.getInstance().getDataContext().getData(DataConstants.PROJECT);

Thanks!
--
Alexey Efimov, Java Developer
Tops BI
http://www.topsbi.ru

0
Comment actions Permalink

Yes, unless the plugin should work with IDEA 4.5... :(

Alexey Efimov wrote:

Hello Martin,

MF> Yes, that would have been the simple case. But unfortunately I'm in
MF> an application level configurable...

In this case you get right solution :)) Also you can use:
com.intellij.ide.DataManager to get current DataContext.

Project project =
(Project)DataManager.getInstance().getDataContext().getData(DataConstants.PROJECT);


Thanks!
--
Alexey Efimov, Java Developer
Tops BI
http://www.topsbi.ru


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0

Please sign in to leave a comment.