diff --git a/CHANGELOG.md b/CHANGELOG.md index baca7133..59567da3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [4.9.0] - 2025-09-25 +- Disables CodeSync group if an invalid project is opened + ## [4.8.0] - 2025-03-11 - Modified video link in README and plugin.xml diff --git a/build.gradle b/build.gradle index 5a02fd43..a05aa43d 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { } group 'com.codesync' -version '4.8.0' +version '4.9.0' compileJava.options.encoding = "UTF-8" diff --git a/src/main/java/org/intellij/sdk/codesync/Constants.java b/src/main/java/org/intellij/sdk/codesync/Constants.java index 19af79b2..8edfacb5 100644 --- a/src/main/java/org/intellij/sdk/codesync/Constants.java +++ b/src/main/java/org/intellij/sdk/codesync/Constants.java @@ -262,6 +262,11 @@ private CustomErrorCodes() { public static final int IS_FROZEN_REPO = 4000; public static final int PRIVATE_REPO_COUNT_LIMIT_REACHED = 4006; } + + public static final class StatusBarMessages { + public static final String OPEN_FOLDER = "CodeSync notification: CodeSync only works with folders. Please open a folder to start syncing."; + public static final String ACCOUNT_DEACTIVATED = "CodeSync notification: Your account is deactivated. In order to use CodeSync’s features, please use an active account."; + } } diff --git a/src/main/java/org/intellij/sdk/codesync/actions/CodeSyncActionGroup.java b/src/main/java/org/intellij/sdk/codesync/actions/CodeSyncActionGroup.java new file mode 100644 index 00000000..418da314 --- /dev/null +++ b/src/main/java/org/intellij/sdk/codesync/actions/CodeSyncActionGroup.java @@ -0,0 +1,88 @@ +package org.intellij.sdk.codesync.actions; + +import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import org.intellij.sdk.codesync.state.PluginState; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.intellij.sdk.codesync.state.StateUtils; +import org.intellij.sdk.codesync.state.PluginState; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import org.intellij.sdk.codesync.codeSyncSetup.CodeSyncSetupAction; +import org.intellij.sdk.codesync.utils.ProjectUtils; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import org.intellij.sdk.codesync.utils.ProjectUtils; +import com.intellij.openapi.ui.Messages; +import org.intellij.sdk.codesync.Constants.*; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.StatusBar; +import com.intellij.openapi.wm.WindowManager; + +import org.intellij.sdk.codesync.NotificationManager; + +public class CodeSyncActionGroup extends DefaultActionGroup { + + PluginState pluginState = StateUtils.getGlobalState(); + private boolean wasAlertShown = false; + + public void showStatusBarMessage(String alertMessage, Project project) { + StatusBar statusBar = WindowManager.getInstance().getStatusBar(project); + if (statusBar != null) { + statusBar.setInfo(alertMessage); + } + } + + private VirtualFile getRepoRoot(AnActionEvent anActionEvent, Project project) { + VirtualFile[] contentRoots = ProjectUtils.getAllContentRoots(project); + + if (contentRoots.length > 1) { + // If more than one module are present in the project then a file must be open to show repo setup action + // this is needed because without the file we can not determine the correct repo sync. + VirtualFile virtualFile = anActionEvent.getRequiredData(CommonDataKeys.PSI_FILE).getVirtualFile(); + return ProjectUtils.getRepoRoot(virtualFile, project); + } else if (contentRoots.length == 1) { + // If there is only one module then we can simply show the repo playback for the only repo present. + // Disable the button if repo is not in sync. + return contentRoots[0]; + } + + return null; + } + + @Override + public void update(@NotNull AnActionEvent e) { + Project project = e.getProject(); + + boolean visible = true; + + // Hide group if account is deactivated + if (StateUtils.getGlobalState().isAccountDeactivated) { + visible = false; + // Display alert message + showStatusBarMessage(StatusBarMessages.ACCOUNT_DEACTIVATED, project); + } + + // Hide group if invalid project path + if (project == null || (project.getBasePath() != null && project.getBasePath().startsWith("/tmp/"))) { + visible = false; + } + + VirtualFile repoRoot = this.getRepoRoot(e, project); + if (repoRoot == null) { + visible = false; + } + + // A single file is opened, no need to sync it. + if (!repoRoot.isDirectory()) { + visible = false; + // Display alert message + showStatusBarMessage(StatusBarMessages.OPEN_FOLDER, project); + } + + e.getPresentation().setVisible(visible); + e.getPresentation().setEnabled(visible); + } +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 6f656bab..51cadc7a 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -124,7 +124,10 @@ topic="com.intellij.openapi.project.ProjectManagerListener"/> -