How to get recent project by right-clicking on the welcome screen?

已回答

I find the function com.intellij.openapi.wm.impl.welcomeScreen.projectActions.RecentProjectsWelcomeScreenActionBase#getSelectedItem

But this function is internal, so I try to find in my override function's parameter  AnActionEvent like below

Then use e.dataContext.getData("RECENT_PROJECT_SELECTED_ITEM") to get the project ,similarly,the interface I got  com.intellij.openapi.wm.impl.welcomeScreen.recentProjects.RecentProjectTreeItem and its implements are also internally modified

In the end I got the class by reflect, but it wasn't elegant enough, is there any other way?

0

Hi,

These classes and members are not intended for use in plugins. Using reflection is dangerous and will lead to errors in case the implementation was changed.

Why do you need this? What is your use case?

0

I want to place some configuration files in project's .idea folder by right-click menu at welcome screen without open them

But I only use RecentProjectsManager or RecentProjectListActionProvider to get all recent projects not the selected by user

0

I see. I'm sorry, but Welcome Screen doesn't seem to be intended for extending.

I suggest finding another solution, for example:

  • Asking a user to add these files after a project is opened
  • Providing an action in a place when a project is opened, e.g., in the project view
0

I can use RecentProjectListActionProvider.getInstance().getActions() to get all recent projects, then popup a dialog let user to choose, but this interaction is too cumbersome

Since there is a way to get all the projects, why not open the API to let the plugin get the project currently selected by the user

0

RecentProjectListActionProvider is not a part of the welcome screen (welcome screen just uses it) but a service used more widely, so it seems a different case.

You can request opening this API via https://youtrack.jetbrains.com/issues/IJPL, but I doubt the responsible team will do it. Looking at the welcome screen code, the classes and members you need are in “impl” module, in “impl” package, and are explicitly marked as internal. It seems to be closed by design.

0

Can add actions to one recent project's right-click menu, but cant get selected project.

Wouldn't that be strange?

0

请先登录再写评论。