简体   繁体   English

通过插件以编程方式刷新/同步IntelliJ IDEA项目

[英]Programmatically refresh/synchronize an IntelliJ IDEA project via a plugin

Is there a way to programmatically refresh/synchronize an IntelliJ IDEA project via a plugin? 有没有办法通过插件以编程方式刷新/同步IntelliJ IDEA项目?

I'm working on an IntelliJ IDEA plugin that creates a file within the active project. 我正在开发一个IntelliJ IDEA插件,可以在活动项目中创建一个文件。 And I want to refresh/synchronize the project automatically via the plugin so that the user can see the changes immediately. 我想通过插件自动刷新/同步项目,以便用户可以立即看到更改。 Is this possible in IntelliJ IDEA? 这在IntelliJ IDEA中是否可行?

After digging a bit more I came through the following solution and it worked. 经过多次挖掘后,我得到了以下解决方案,并且有效。

public void actionPerformed(AnActionEvent e) {

    // Create/Modify files

    // Get the project from the ActionEvent
    Project project = e.getData(PlatformDataKeys.PROJECT);

    // Get the Base Dir and refresh with the following parameters
    // 'asynchronous' set to false and 'recursive' set to true
    project.getBaseDir().refresh(false,true);

}

您可以使用SyncAction

SyncProjectAction().actionPerformed(actionEvent)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM