Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP CodeSync Tool Window Button #101

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.intellij.sdk.codesync.eventBus;

import com.intellij.util.messages.Topic;

public interface CodeSyncEventBus {
Topic<CodeSyncEventBus> TOPIC = Topic.create("CodeSyncEventBus", CodeSyncEventBus.class);

void onEvent(); // Define your event method here
}
197 changes: 197 additions & 0 deletions src/main/java/org/intellij/sdk/codesync/toolWindow/ButtonList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
package org.intellij.sdk.codesync.toolWindow;

import com.intellij.openapi.project.Project;
import com.intellij.util.messages.MessageBus;
import org.intellij.sdk.codesync.state.PluginState;
import org.intellij.sdk.codesync.state.StateUtils;
import org.intellij.sdk.codesync.utils.CommonUtils;
import org.intellij.sdk.codesync.utils.ProjectUtils;

import javax.swing.*;
import java.awt.*;

public class ButtonList extends JPanel {

static boolean userLoggedIn = false;
static boolean repoConnected = false;
static boolean needToAvailTrail = false;
static boolean needToUpgradeToPro = true;
static boolean isNestedRepo = false;
static boolean isIgnoredNestedRepo = true;

CodeSyncLabel loginMessage = new CodeSyncLabel("Login and connect the repository to start streaming your code.");
CodeSyncLabel connectRepoMessage = new CodeSyncLabel("Great! Now just connect the repository to start streaming your code.");
CodeSyncLabel userCanStreamMessage = new CodeSyncLabel("Your repository is in sync.");
CodeSyncLabel tryProForFreeMessage = new CodeSyncLabel("Your repository size is exceeding the free limit.");
CodeSyncLabel tryProForFreeMessage2 = new CodeSyncLabel("<a href=''>Try Pro for free</a> to continue using CodeSync.");
CodeSyncLabel upgradeToProMessage = new CodeSyncLabel("Your free trial of CodeSync has ended.");
CodeSyncLabel upgradeToProMessage2 = new CodeSyncLabel("Please upgrade your plan to continue using CodeSync, or contact sales.");
CodeSyncLabel nestedDirMessage = new CodeSyncLabel("This file is ignored by .syncignore and is not in sync with CodeSync.");
CodeSyncLabel nestedIgnoredDirMessage = new CodeSyncLabel("Current directory is ignored by a parent directory for streaming.");
CodeSyncLabel nestedIgnoredDirMessage2 = new CodeSyncLabel("To include this directory/file, remove it from the .syncignore file.");

CodeSyncButton login = new CodeSyncButton("Login");
CodeSyncButton logout = new CodeSyncButton("Logout");
CodeSyncButton connectRepository = new CodeSyncButton("Connect Repository");
CodeSyncButton disconnectRepository = new CodeSyncButton("Disconnect Repository");
CodeSyncButton viewFilePlayback = new CodeSyncButton("View File Playback");
CodeSyncButton viewDashboard = new CodeSyncButton("View Dashboard");
CodeSyncButton tryProForFree = new CodeSyncButton("Try Pro For Free");
CodeSyncButton upgradeToPro = new CodeSyncButton("Upgrade To Pro");
CodeSyncButton openSyncIgnoreFile = new CodeSyncButton("Open .syncignore File");
CodeSyncButton viewParentRepositoryOnWeb = new CodeSyncButton("View Parent Repository on Web");
CodeSyncButton unsyncParentRepository = new CodeSyncButton("Unsync Parent Repository");

public ButtonList(){
this.addingActionListeners();
this.removeAll();

Project project = CommonUtils.getCurrentProject();
String repoPath = ProjectUtils.getRepoPath(project);
PluginState pluginState = StateUtils.getState(repoPath);
PluginState globalState = StateUtils.getGlobalState();

setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
setAlignmentX(Component.CENTER_ALIGNMENT);

add(Box.createVerticalGlue());
if(!userLoggedIn){ //Replace it with !globalState.isAuthenticated
userNotLoggedIn();
}else if(isNestedRepo){
if(isIgnoredNestedRepo){
syncIgnoredNestedDirOpen();
}else{
nestedDirOpen();
}
}else if(!repoConnected){ //Replace it with !pluginState.isRepoInSync
repositoryNotConnected();
}else if(needToAvailTrail){
userNeedToAvailTrail();
}else if(needToUpgradeToPro){
userNeedToUpgradeToPro();
}else {
userCanStream();
}
add(Box.createVerticalGlue());
}

private void addingActionListeners(){
login.addActionListener(e -> loginAction());
logout.addActionListener(e -> logoutAction());
connectRepository.addActionListener(e -> connectRepositoryAction());
disconnectRepository.addActionListener(e -> disconnectRepositoryAction());
viewFilePlayback.addActionListener(e -> viewFilePlaybackAction());
viewDashboard.addActionListener(e -> viewDashboardAction());
tryProForFree.addActionListener(e -> tryProForFreeAction());
upgradeToPro.addActionListener(e -> upgradeToProAction());
openSyncIgnoreFile.addActionListener(e -> openSyncIgnoreFileAction());
viewParentRepositoryOnWeb.addActionListener(e -> viewParentRepositoryOnWebAction());
unsyncParentRepository.addActionListener(e -> unsyncParentRepositoryAction());
}

private void loginAction(){
System.out.println("Login Button Clicked");
this.userLoggedIn = true;
CodeSyncToolWindow.updateMenu();
}

private void logoutAction(){
System.out.println("Logout Button Clicked");
this.userLoggedIn = false;
CodeSyncToolWindow.updateMenu();
}

private void connectRepositoryAction(){
System.out.println("Connect Repository Button Clicked");
this.repoConnected = true;
CodeSyncToolWindow.updateMenu();
}

private void disconnectRepositoryAction(){
System.out.println("Disconnect Repository Button Clicked");
this.repoConnected = false;
CodeSyncToolWindow.updateMenu();
}

private void viewFilePlaybackAction(){
System.out.println("View File Playback Button Clicked");
}

private void viewDashboardAction(){
System.out.println("View Dashboard Button Clicked");
}

private void tryProForFreeAction(){
System.out.println("Try Pro For Free Button Clicked");
}

private void upgradeToProAction(){
System.out.println("Upgrade To Pro Button Clicked");
}

private void openSyncIgnoreFileAction(){
System.out.println("Open SyncIgnore File Button Clicked");
}

private void viewParentRepositoryOnWebAction(){
System.out.println("View Parent Repository On Web Button Clicked");
}

private void unsyncParentRepositoryAction(){
System.out.println("Unsync Parent Repository Button Clicked");
}

private void userNotLoggedIn(){
this.add(loginMessage);
this.add(login);
}

private void repositoryNotConnected(){
this.add(connectRepoMessage);
this.add(connectRepository);
this.add(logout);
}

private void userCanStream(){
this.add(userCanStreamMessage);
this.add(viewFilePlayback);
this.add(viewDashboard);
this.add(disconnectRepository);
this.add(logout);
}

private void userNeedToAvailTrail(){
this.add(tryProForFreeMessage);
this.add(tryProForFreeMessage2);
this.add(viewFilePlayback);
this.add(viewDashboard);
this.add(tryProForFree);
this.add(disconnectRepository);
this.add(logout);
}

private void userNeedToUpgradeToPro(){
this.add(upgradeToProMessage);
this.add(upgradeToProMessage2);
this.add(viewFilePlayback);
this.add(viewDashboard);
this.add(upgradeToPro);
this.add(disconnectRepository);
this.add(logout);
}

private void syncIgnoredNestedDirOpen(){
this.add(nestedIgnoredDirMessage);
this.add(nestedIgnoredDirMessage2);
this.add(openSyncIgnoreFile);
this.add(viewParentRepositoryOnWeb);
this.add(unsyncParentRepository);
}

private void nestedDirOpen(){
this.add(nestedDirMessage);
this.add(viewParentRepositoryOnWeb);
this.add(unsyncParentRepository);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.intellij.sdk.codesync.toolWindow;

import javax.swing.*;
import java.awt.*;

public class CodeSyncButton extends JButton {

public CodeSyncButton(String buttonText){
super(buttonText);
Dimension buttonSize = new Dimension(200, 50);
this.setMaximumSize(buttonSize);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.intellij.sdk.codesync.toolWindow;

import javax.swing.*;
import java.awt.*;

public class CodeSyncLabel extends JLabel {

public CodeSyncLabel(String labelText){
super("<html><p>" + labelText + "</p></html>");
this.setBackground(Color.GREEN);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.intellij.sdk.codesync.toolWindow;

import javax.swing.*;
import java.awt.*;

public class CodeSyncMenu extends JPanel {

CodeSyncMenu(){
JPanel controlsPanel = new JPanel();
controlsPanel.setLayout(new GridBagLayout());
controlsPanel.add(new ButtonList());
this.add(controlsPanel);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.intellij.sdk.codesync.toolWindow;

import com.intellij.util.messages.MessageBus;
import org.intellij.sdk.codesync.eventBus.CodeSyncEventBus;
import org.intellij.sdk.codesync.utils.CommonUtils;

import javax.swing.*;
import java.awt.*;

public class CodeSyncToolWindow {

private static JPanel contentPanel = new JPanel();
private static JPanel rightPanel = new JPanel();
private static JPanel leftPanel = new JPanel();

public static void createToolWindow() {
contentPanel.setLayout(new BorderLayout(0, 20));
contentPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

rightPanel.setLayout(new BorderLayout());
leftPanel.setLayout(new BorderLayout());

rightPanel.setPreferredSize(new Dimension((int) (Toolkit.getDefaultToolkit().getScreenSize().width * 0.7), 0));
leftPanel.setPreferredSize(new Dimension((int) (Toolkit.getDefaultToolkit().getScreenSize().width * 0.3), 0));

contentPanel.add(rightPanel, BorderLayout.CENTER);
contentPanel.add(leftPanel, BorderLayout.WEST);

rightPanel.add(new RightSide());
leftPanel.add(new ButtonList(), BorderLayout.CENTER);
}

public static void updateMenu(){
leftPanel.removeAll();
leftPanel.add(new CodeSyncMenu(), BorderLayout.CENTER);
MessageBus messageBus = CommonUtils.getCurrentProject().getMessageBus();
CodeSyncEventBus eventBus = messageBus.syncPublisher(CodeSyncEventBus.TOPIC);
eventBus.onEvent(); // Notify subscribers about the event
}

public static JPanel getContentPanel() {
createToolWindow();
return contentPanel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.intellij.sdk.codesync.toolWindow;

import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import org.intellij.sdk.codesync.eventBus.CodeSyncEventBus;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;

public class CodeSyncToolWindowButton implements ToolWindowFactory, DumbAware {

CodeSyncToolWindow toolWindowContent;

@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
Content content = ContentFactory.SERVICE.getInstance().createContent(CodeSyncToolWindow.getContentPanel(), "", false);
toolWindow.getContentManager().addContent(content);
toolWindow.setSplitMode(false, null);

// Register a listener to update the content whenever the event occurs
project.getMessageBus().connect().subscribe(CodeSyncEventBus.TOPIC, () -> {
SwingUtilities.invokeLater(() -> {
// Perform any updates or changes to the CodeSyncToolWindow content here
// Repaint the content panel to reflect the changes
toolWindowContent.getContentPanel().revalidate();
toolWindowContent.getContentPanel().repaint();
});
});
}
}
35 changes: 35 additions & 0 deletions src/main/java/org/intellij/sdk/codesync/toolWindow/RightSide.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.intellij.sdk.codesync.toolWindow;

import javax.swing.*;
import java.util.Objects;

public class RightSide extends JPanel {

public RightSide(){

setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
JLabel imageLabel = new JLabel();
JLabel introText = new JLabel();
JLabel lineOne = new JLabel();
JLabel lineTwo = new JLabel();
JLabel lineThree = new JLabel();

imageLabel.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/codesync.png"))));
introText.setText("CodeSync streams your code in real-time to the cloud, allowing you to review the entire history of the codebase on the web.");
lineOne.setText("• Review your coding progress every day. (What did I actually write today?!)");
lineTwo.setText("• Align with teammates. (Never again be surprised by a Pull Request!)");
lineThree.setText("• Or, rewind back to any point in the past. (Never again lose code you didn't commit!)");

add(Box.createVerticalGlue());
add(Box.createHorizontalBox());
this.add(imageLabel);
this.add(introText);
this.add(lineOne);
this.add(lineTwo);
this.add(lineThree);
add(Box.createHorizontalBox());
add(Box.createVerticalGlue());

}

}
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,7 @@

<extensions defaultExtensionNs="com.intellij">
<notificationGroup icon="CodeSyncIcons.codeSyncIcon" id="CodeSync Notifications" displayType="BALLOON" key="codesync.notification"/>
<toolWindow id="CodeSync" secondary="true" icon="AllIcons.Toolwindows.Problems" anchor="bottom"
doNotActivateOnStart="true" factoryClass="org.intellij.sdk.codesync.toolWindow.CodeSyncToolWindowButton"/>
</extensions>
</idea-plugin>
Binary file added src/main/resources/icons/codesync.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.