61 lines
2.5 KiB
Java
61 lines
2.5 KiB
Java
package com.example.plugin;
|
|
|
|
import com.intellij.openapi.actionSystem.AnAction;
|
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
|
import com.intellij.openapi.application.ApplicationManager;
|
|
import com.intellij.openapi.progress.ProgressIndicator;
|
|
import com.intellij.openapi.progress.ProgressManager;
|
|
import com.intellij.openapi.progress.Task;
|
|
import com.intellij.openapi.project.Project;
|
|
import com.intellij.openapi.ui.Messages;
|
|
import com.intellij.openapi.vfs.LocalFileSystem;
|
|
import com.intellij.openapi.vfs.VfsUtil;
|
|
import com.intellij.openapi.vfs.VirtualFile;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.util.Optional;
|
|
|
|
public class RefreshFromServerAction extends AnAction {
|
|
@Override
|
|
public void actionPerformed(@NotNull AnActionEvent e) {
|
|
Project project = e.getProject();
|
|
if (project == null) return;
|
|
|
|
String projectPath = project.getBasePath();
|
|
if (projectPath == null) return;
|
|
|
|
String serverId = ProjectServerMapping.getInstance().getServerIdForProject(projectPath);
|
|
if (serverId == null) {
|
|
Messages.showErrorDialog("No server associated with this project.", "Error");
|
|
return;
|
|
}
|
|
|
|
Optional<SshServer> maybeServer = SshServerManager.getInstance().findServer(serverId);
|
|
if (maybeServer.isEmpty()) {
|
|
Messages.showErrorDialog("Server not found.", "Error");
|
|
return;
|
|
}
|
|
SshServer server = maybeServer.get();
|
|
|
|
ProgressManager.getInstance().run(new Task.Modal(project, "Refreshing from " + server.name, true) {
|
|
@Override
|
|
public void run(@NotNull ProgressIndicator indicator) {
|
|
try {
|
|
String localRoot = SshServerManager.getLocalProjectPath(server);
|
|
ConnectToRemoteAction.syncProject(server, localRoot, indicator);
|
|
|
|
ApplicationManager.getApplication().invokeLater(() -> {
|
|
VirtualFile rootDir = LocalFileSystem.getInstance().findFileByPath(localRoot);
|
|
if (rootDir != null) {
|
|
VfsUtil.markDirtyAndRefresh(true, true, true, rootDir);
|
|
}
|
|
Messages.showInfoMessage("Project refreshed from " + server.name, "Refresh Complete");
|
|
});
|
|
} catch (Exception ex) {
|
|
ApplicationManager.getApplication().invokeLater(() ->
|
|
Messages.showErrorDialog("Refresh failed: " + ex.getMessage(), "Error"));
|
|
}
|
|
}
|
|
});
|
|
}
|
|
} |