Synchronize virtual file to the physical file in the Intellij IDEA plugin

前提是你 提交于 2019-12-23 09:46:58

问题


I'm implementing the plugin for Intellij IDEA that needs file to be saved before executing action. Action is shell command, it requires file name to be passed as the command-line parameter.

AFAIK Idea saves (synchronizes) files on frame deactivation, so if I right-click on the file, and click on my action - old version of file will be used. If I go to other window, return to Idea and click my action - current version of the file will be used.

I've read this doc about Virtual File System, and found that I can trigger file to be loaded from file system (e.g. VirtualFileManager.syncRefresh() or VirtualFileManager.asyncRefresh()). I tried this hoping it would work, but it doesn't.

Question is: how to manually (programmatically) save file?


回答1:


While formatting my question I checked one more time, and this worked for me.

FileDocumentManager.getInstance().saveAllDocuments();

EDIT
Finally came up with the solution

FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document document = fileDocumentManager.getDocument(file);
if (document != null) {
    fileDocumentManager.saveDocument(document);
}


来源:https://stackoverflow.com/questions/20460557/synchronize-virtual-file-to-the-physical-file-in-the-intellij-idea-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!