情景
最近做一个IDEA的Plugin开发,功能主要包括以下
- 根据用户输入以及模板生成一套模板代码
- 将生成的一套代码 git add
- 将生成的代码 在IDE 窗口中打开
问题
1. 现在我已经可以通过输入自动生成代码,但是却不会自动打开这个文件,想咨询下有没有已有的方法?
2. 怎么执行git add?
部分我的代码
LeetCodeConfigDialog.runWithCallBack(((number, url, name) -> {
PsiDirectoryImpl nowSelect = CommonUtil.getNowSelect(anActionEvent);
if (nowSelect == null) {
return;
}
String parentPath = nowSelect.getVirtualFile().getPath();
String parentPointPath = parentPath.replace('/', '.');
String filePackage = parentPointPath.substring(parentPointPath.indexOf("solutions.leetcode"));
GenerateBean bean = new GenerateBean(
new ClassConfigBean(parentPath, "LeetCode", "Solution" + number))
.addKeySet("$package", filePackage)
.addKeySet("$link", url)
.addKeySet("$number", number)
.addKeySet("$name", name);
if (ClassGenerator.generate(bean)) {
// 现在可以自动生成成功,已经走进这里了
// 应该是在这里需要补充一些代码,来打开新生成的文件,以及 git add 操作,该怎么写?
nowSelect.getVirtualFile().refresh(false, true);
} else {
CommonUtil.showMessage("Failed!", "文件生成失败!");
}
}));