package com.dida.didanugetextension.action; import com.dida.didanugetextension.action.base.BaseAction; import com.dida.didanugetextension.util.CommandHelper; import com.intellij.execution.ui.ConsoleView; import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.progress.Task; import groovyjarjarantlr4.v4.runtime.misc.NotNull; public class UpdateReferencesByProjectChainAction extends BaseAction { public UpdateReferencesByProjectChainAction() { super("Update References By Project Chain"); } @Override protected void runAction(Project project, ConsoleView consoleView,AnActionEvent event) { printToConsole("Begin to UpdateReferencesByProjectChain.", ConsoleViewContentType.NORMAL_OUTPUT); // 获取选中的项目文件或目录 VirtualFile file = event.getDataContext().getData(com.intellij.openapi.actionSystem.CommonDataKeys.VIRTUAL_FILE); if (file != null && project != null) { String csprojPath = file.getPath(); String command = "jenkins updateReferences " + csprojPath; if (project != null) { new Task.Backgroundable(project, "Update References By Project Chain", false) { @Override public void run(@NotNull ProgressIndicator indicator) { // 在这里执行你的CMD命令 CommandHelper.executeCommand(consoleView, command, "nugethelper.exe"); printToConsole("========== Finish to UpdateReferencesByProjectChain. ==========", ConsoleViewContentType.NORMAL_OUTPUT); } }.queue(); } } } @Override public void update(AnActionEvent e) { // 设置动作是否可见和启用 VirtualFile selectedFile = e.getData(CommonDataKeys.VIRTUAL_FILE); boolean isCsprojFile = selectedFile != null && selectedFile.getName().endsWith(".csproj"); e.getPresentation().setEnabledAndVisible(isCsprojFile); } }