Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group 'com.codesync'
version '4.8.0'
version '4.9.0'


compileJava.options.encoding = "UTF-8"
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/intellij/sdk/codesync/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
}


Original file line number Diff line number Diff line change
@@ -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);
}
}
5 changes: 4 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@
topic="com.intellij.openapi.project.ProjectManagerListener"/>
</projectListeners>
<actions>
<group id="org.intellij.sdk.action.GroupedActions" text="CodeSync" popup="true"
<group id="org.intellij.sdk.action.GroupedActions"
class="org.intellij.sdk.codesync.actions.CodeSyncActionGroup"
text="CodeSync"
popup="true"
icon="CodeSyncIcons.codeSyncIcon">
<add-to-group group-id="MainMenu" anchor="after" relative-to-action="ToolsMenu"/>
<add-to-group group-id="EditorPopupMenu" anchor="last"/>
Expand Down
Loading