how to open a project?

Answered


ProjectManager.getInstance ().open("/someDir/aProject.ipr");

doesn't exist. Is there another way?

Alain

8 comments
Comment actions Permalink

Alain Ravet wrote:


ProjectManager.getInstance ().open("/someDir/aProject.ipr");

doesn't exist. Is there another way?


You can use

ProjectManagerEx pm = ProjectManagerEx.getInstanceEx();
Project p = pm.loadProject("/someDir/aProject.ipr");
pm.openProject(p);

HTH,
Sascha

0
Comment actions Permalink

Sascha

ProjectManagerEx pm = ProjectManagerEx.getInstanceEx();




Where does

ProjectManagerEx

come from?

Alain

0
Comment actions Permalink

Alain Ravet wrote:

Where does

ProjectManagerEx

come from?


The almighty idea.jar ;)

Sascha

0
Comment actions Permalink


>>Where does ProjectManagerEx come from?
>>
>>
>The almighty idea.jar ;)
>

>

Thanks.


Posted:
move ProjectManagerEx to the openAPI
http://www.jetbrains.net/jira/browse/IDEA-3523

Alain

0
Comment actions Permalink

>>Where does
>>
>> ProjectManagerEx
>>
>>come from?


The almighty idea.jar ;)

So it's not OPEN API but CLOSED API :).

Maybe there should be a jetbrains.intellij.closedapi newsgroup :), since
without closed api it's not possible to do much (see also thread about
'Javascript language plugin sources').

Ahmed.

0
Comment actions Permalink


>

Maybe there should be a jetbrains.intellij.closedapi newsgroup




, with funny hats and secret handshakes ?
:)


Alain

0
Comment actions Permalink

Ahmed Mohombe wrote:

So it's not OPEN API but CLOSED API :).


IMHO any API that isn't obfuscated can be considered "open". Personally I don't care if
something is inside openapi.jar or not if it's useful ;-). The only problem is that
sometimes guessing parameter meanings can be hard, but usually you'll get an answer in here.

Sascha

0
Comment actions Permalink

https://github.com/liang0-0/custom-editor/tree/master/src/com/lang/project 

public class SwitchProject extends AnAction {

@Override
public void update(AnActionEvent e) {
e.getPresentation().setEnabledAndVisible(ProjectManager.getInstance().getOpenProjects().length > 0);
}

@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);

Project[] projects = ProjectManager.getInstance().getOpenProjects();
List<Project> allProject = new ArrayList<>(Arrays.asList(projects));
allProject.remove(project);
if (projects.length == 1) {
return;
}
ListPopup listPopup = JBPopupFactory.getInstance()
.createListPopup(new ProjectListPopupStep("", allProject));
listPopup.showInFocusCenter();
}

}

public class ProjectListPopupStep extends BaseListPopupStep<Project> {

public ProjectListPopupStep(String title, List<Project> projects) {
super(title, projects);
}

@NotNull
@Override
public String getTextFor(Project value) {
return value.getName();
}

@Override
public SpeedSearchFilter<Project> getSpeedSearchFilter() {
return new SpeedSearchFilter<Project>() {
@Override
public boolean canBeHidden(Project value) {
return true;
}

@Override
public String getIndexedString(Project value) {
return value.getName();
}
};
}



@Override
public boolean isSpeedSearchEnabled() {
return true;
}

@Override
public PopupStep onChosen(Project project, boolean finalChoice) {
if (null == project || project.getBasePath() == null) {
return FINAL_CHOICE;
}
try {
ProjectManagerEx projectManagerEx = ProjectManagerEx.getInstanceEx();
Project p = projectManagerEx.loadProject(project.getBasePath());
if (null == p) {
return FINAL_CHOICE;
}
final JFrame projectFrame = WindowManager.getInstance().getFrame(project);
if (null == projectFrame) {
return FINAL_CHOICE;
}
projectManagerEx.openProject(p);
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
Component mostRecentFocusOwner = projectFrame.getMostRecentFocusOwner();
if (mostRecentFocusOwner != null) {
IdeFocusManager.getGlobalInstance().requestFocus(mostRecentFocusOwner, true);
}
});
return FINAL_CHOICE;
} catch (IOException e) {
e.printStackTrace();
return FINAL_CHOICE;
}
}
}

 

<actions>
<action class="com.lang.project.SwitchProject" id="com.lang.project.SwitchProject" text="Switch Project Window">
<add-to-group group-id="WindowMenu" relative-to-action="PreviousProjectWindow" anchor="after"/>
<keyboard-shortcut keymap="$default" first-keystroke="control alt p"/>
</action>
</actions>
1

Please sign in to leave a comment.