mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-364682 Review git repository init flow in workspace project
add "Enable VCS Integration" to subproject context menu GitOrigin-RevId: e400534c39f929ebb60f879683974d99696bcb01
This commit is contained in:
committed by
intellij-monorepo-bot
parent
49bca52ac5
commit
4bd6d76d5c
@@ -5,8 +5,6 @@ import com.intellij.ide.impl.TrustedProjects;
|
||||
import com.intellij.openapi.actionSystem.ActionUpdateThread;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectUtil;
|
||||
@@ -20,8 +18,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public class StartUseVcsAction extends DumbAwareAction {
|
||||
private static final Logger LOG = Logger.getInstance(StartUseVcsAction.class);
|
||||
|
||||
public StartUseVcsAction() {
|
||||
super(VcsBundle.messagePointer("action.enable.version.control.integration.text"));
|
||||
}
|
||||
@@ -33,35 +29,34 @@ public class StartUseVcsAction extends DumbAwareAction {
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
Project project = e.getData(CommonDataKeys.PROJECT);
|
||||
|
||||
boolean enabled = isEnabled(project);
|
||||
|
||||
Presentation presentation = e.getPresentation();
|
||||
presentation.setEnabledAndVisible(enabled);
|
||||
e.getPresentation().setEnabledAndVisible(guessDirectory(e) != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull final AnActionEvent e) {
|
||||
Project project = e.getData(CommonDataKeys.PROJECT);
|
||||
if (project == null) return;
|
||||
if (!isEnabled(project)) return;
|
||||
VirtualFile targetDirectory = ProjectUtil.guessProjectDir(project);
|
||||
if (targetDirectory == null) {
|
||||
LOG.warn("Project directory is null");
|
||||
return;
|
||||
}
|
||||
@Nullable VirtualFile directory = guessDirectory(e);
|
||||
if (directory == null) return;
|
||||
|
||||
StartUseVcsDialog dialog = new StartUseVcsDialog(project, targetDirectory.getPath());
|
||||
StartUseVcsDialog dialog = new StartUseVcsDialog(project, directory.getPath());
|
||||
if (dialog.showAndGet()) {
|
||||
AbstractVcs vcs = dialog.getVcs();
|
||||
vcs.enableIntegration();
|
||||
vcs.enableIntegration(directory);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isEnabled(@Nullable Project project) {
|
||||
if (project == null || !TrustedProjects.isTrusted(project)) return false;
|
||||
protected @Nullable VirtualFile guessDirectory(@NotNull AnActionEvent e) {
|
||||
Project project = e.getData(CommonDataKeys.PROJECT);
|
||||
if (project == null || !TrustedProjects.isTrusted(project)) return null;
|
||||
ProjectLevelVcsManagerImpl manager = ProjectLevelVcsManagerImpl.getInstanceImpl(project);
|
||||
return manager.haveVcses() && !manager.hasAnyMappings();
|
||||
if (manager.haveVcses() && !manager.hasAnyMappings()) {
|
||||
VirtualFile targetDirectory = ProjectUtil.guessProjectDir(project);
|
||||
if (targetDirectory == null) {
|
||||
return null;
|
||||
}
|
||||
return targetDirectory;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user