mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-11-23 23:54:48 +01:00
feat: janky workspace create/invite/delete
This commit is contained in:
parent
7995b8db45
commit
d809462891
8 changed files with 224 additions and 5 deletions
|
@ -39,7 +39,7 @@ dependencies {
|
|||
tasks {
|
||||
patchPluginXml {
|
||||
sinceBuild.set('222')
|
||||
untilBuild.set('233.*')
|
||||
untilBuild.set('242.*')
|
||||
}
|
||||
|
||||
signPlugin {
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package mp.code.intellij.actions.workspace;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import mp.code.intellij.util.InteractionUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WorkspaceCreateAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
String workspaceName = Messages.showInputDialog(
|
||||
"Input name of new workspace",
|
||||
"CodeMP Create Workspace",
|
||||
Messages.getQuestionIcon()
|
||||
);
|
||||
|
||||
if(workspaceName == null) {
|
||||
Messages.showErrorDialog(
|
||||
"Workspace name cannot be null!",
|
||||
"CodeMP Create Workspace"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
InteractionUtil.createWorkspace(e.getProject(), workspaceName, null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package mp.code.intellij.actions.workspace;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import mp.code.intellij.util.InteractionUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WorkspaceDeleteAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
String[] availableWorkspaces = InteractionUtil.listWorkspaces(e.getProject(), true, false);
|
||||
if(availableWorkspaces.length == 0) {
|
||||
Messages.showErrorDialog(
|
||||
"You do not own any workspaces. Ensure you own at least one!",
|
||||
"CodeMP Delete Workspace"
|
||||
);
|
||||
}
|
||||
|
||||
int choice = Messages.showDialog( // TODO NOT THE ONE
|
||||
e.getProject(),
|
||||
"Please choose a workspace to delete:",
|
||||
"CodeMP Delete Workspace",
|
||||
availableWorkspaces,
|
||||
0,
|
||||
Messages.getQuestionIcon()
|
||||
);
|
||||
|
||||
InteractionUtil.deleteWorkspace(e.getProject(), availableWorkspaces[choice], null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package mp.code.intellij.actions.workspace;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import mp.code.intellij.CodeMP;
|
||||
import mp.code.intellij.util.InteractionUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class WorkspaceInviteAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
String[] availableWorkspaces = InteractionUtil.listWorkspaces(e.getProject(), true, false);
|
||||
if(availableWorkspaces.length == 0) {
|
||||
Messages.showErrorDialog(
|
||||
"You do not own any workspaces. Ensure you own at least one!",
|
||||
"CodeMP Invite To Workspace"
|
||||
);
|
||||
}
|
||||
|
||||
int choice = Messages.showDialog( // TODO NOT THE ONE
|
||||
e.getProject(),
|
||||
"Please choose a workspace to invite to:",
|
||||
"CodeMP Invite To Workspace",
|
||||
availableWorkspaces,
|
||||
0,
|
||||
Messages.getQuestionIcon()
|
||||
);
|
||||
|
||||
String userName = Messages.showInputDialog(
|
||||
"Input name of user to invite:",
|
||||
"CodeMP Invite To Workspace",
|
||||
Messages.getQuestionIcon()
|
||||
);
|
||||
|
||||
if(userName == null) {
|
||||
Messages.showErrorDialog(
|
||||
"Username cannot be null!",
|
||||
"CodeMP Invite To Workspace"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
InteractionUtil.inviteToWorkspace(e.getProject(), availableWorkspaces[choice], userName, null);
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
public class WorkspaceJoinAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
String[] availableWorkspaces = InteractionUtil.listWorkspaces(e.getProject());
|
||||
String[] availableWorkspaces = InteractionUtil.listWorkspaces(e.getProject(), true, true);
|
||||
if(availableWorkspaces.length == 0) {
|
||||
Messages.showErrorDialog(
|
||||
"There are no available workspaces. Ensure you have rights to access at least one!",
|
||||
|
|
|
@ -81,7 +81,7 @@ public class CodeMPWindowFactory implements ToolWindowFactory, DumbAware {
|
|||
}
|
||||
case CONNECTED -> {
|
||||
this.setLayout(new GridLayout(0, 1));
|
||||
JTree tree = drawTree(InteractionUtil.listWorkspaces(project));
|
||||
JTree tree = drawTree(InteractionUtil.listWorkspaces(project, true, true));
|
||||
tree.addMouseListener(new SimpleMouseListener() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
|
|
@ -69,6 +69,70 @@ public class InteractionUtil {
|
|||
notifyInfo(project, "Success", "Disconnected from server!");
|
||||
}
|
||||
|
||||
public static void createWorkspace(Project project, @NotNull String workspaceId, @Nullable Runnable after) {
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(project, String.format("Creating workspace %s...", workspaceId)) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
if(project == null) {
|
||||
Notifications.Bus.notify(new Notification(
|
||||
"CodeMP",
|
||||
"No project found",
|
||||
"Please ensure that you have an open project before attempting to create a workspace.",
|
||||
NotificationType.ERROR
|
||||
), null);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
CodeMP.getClient("workspace create").createWorkspace(workspaceId);
|
||||
if(after != null) after.run();
|
||||
notifyInfo(
|
||||
project,
|
||||
"Success",
|
||||
String.format("Created workspace %s!", workspaceId)
|
||||
);
|
||||
} catch(ConnectionException e) {
|
||||
InteractionUtil.notifyError(project, String.format(
|
||||
"Failed to create workspace %s!",
|
||||
workspaceId
|
||||
), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void inviteToWorkspace(Project project, @NotNull String workspaceId, @NotNull String userName, @Nullable Runnable after) {
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(project, String.format("Inviting %s to workspace %s...", userName, workspaceId)) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
if(project == null) {
|
||||
Notifications.Bus.notify(new Notification(
|
||||
"CodeMP",
|
||||
"No project found",
|
||||
"Please ensure that you have an open project before attempting to join a workspace.",
|
||||
NotificationType.ERROR
|
||||
), null);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
CodeMP.getClient("workspace invite").inviteToWorkspace(workspaceId, userName);
|
||||
if(after != null) after.run();
|
||||
notifyInfo(
|
||||
project,
|
||||
"Success",
|
||||
String.format("Joined workspace %s!", workspaceId)
|
||||
);
|
||||
} catch(ConnectionException e) {
|
||||
InteractionUtil.notifyError(project, String.format(
|
||||
"Failed to invite to workspace %s!",
|
||||
workspaceId
|
||||
), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void joinWorkspace(Project project, @NotNull String workspaceId, @Nullable Runnable after) {
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(project, String.format("Joining workspace %s...", workspaceId)) {
|
||||
@Override
|
||||
|
@ -117,6 +181,47 @@ public class InteractionUtil {
|
|||
});
|
||||
}
|
||||
|
||||
public static void deleteWorkspace(Project project, @NotNull String workspaceId, @Nullable Runnable after) {
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(project, String.format("Deleting workspace %s...", workspaceId)) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
if(project == null) {
|
||||
Notifications.Bus.notify(new Notification(
|
||||
"CodeMP",
|
||||
"No project found",
|
||||
"Please ensure that you have an open project before attempting to delete a workspace.",
|
||||
NotificationType.ERROR
|
||||
), null);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Client client = CodeMP.getClient("workspace delete");
|
||||
client.deleteWorkspace(workspaceId);
|
||||
|
||||
Optional<Workspace> ws = client.getWorkspace("workspace leave");
|
||||
if(ws.isPresent() && ws.get().getWorkspaceId().equals(workspaceId)) {
|
||||
CodeMP.leaveWorkspace();
|
||||
MemoryManager.startWorkspaceLifetime(workspaceId);
|
||||
}
|
||||
|
||||
if(after != null) after.run();
|
||||
|
||||
notifyInfo(
|
||||
project,
|
||||
"Success",
|
||||
String.format("Joined workspace %s!", workspaceId)
|
||||
);
|
||||
} catch(ConnectionException e) {
|
||||
InteractionUtil.notifyError(project, String.format(
|
||||
"Failed to join workspace %s!",
|
||||
workspaceId
|
||||
), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void leaveWorkspace(Project project, String workspaceId) {
|
||||
CodeMP.leaveWorkspace();
|
||||
MemoryManager.endWorkspaceLifetime(workspaceId);
|
||||
|
@ -127,10 +232,10 @@ public class InteractionUtil {
|
|||
);
|
||||
}
|
||||
|
||||
public static String[] listWorkspaces(Project project) {
|
||||
public static String[] listWorkspaces(Project project, boolean owned, boolean invited) {
|
||||
try {
|
||||
Client client = CodeMP.getClient("drawActiveWorkspaces");
|
||||
return client.listWorkspaces(true, true);
|
||||
return client.listWorkspaces(owned, invited);
|
||||
} catch(ConnectionRemoteException exception) {
|
||||
notifyError(project, "Failed to list workspaces!", exception);
|
||||
return new String[0];
|
||||
|
|
|
@ -12,8 +12,14 @@
|
|||
<add-to-group group-id="ToolsMenu" anchor="first"/>
|
||||
<action id="codemp.connect" class="mp.code.intellij.actions.ConnectAction" text="Connect"/>
|
||||
<action id="codemp.disconnect" class="mp.code.intellij.actions.DisconnectAction" text="Disconnect"/>
|
||||
<action id="codemp.workspace.create" class="mp.code.intellij.actions.workspace.WorkspaceCreateAction"
|
||||
text="Create Workspace"/>
|
||||
<action id="codemp.workspace.join" class="mp.code.intellij.actions.workspace.WorkspaceJoinAction"
|
||||
text="Join Workspace"/>
|
||||
<action id="codemp.workspace.invite" class="mp.code.intellij.actions.workspace.WorkspaceInviteAction"
|
||||
text="Invite To Workspace"/>
|
||||
<action id="codemp.workspace.delete" class="mp.code.intellij.actions.workspace.WorkspaceDeleteAction"
|
||||
text="Delete Workspace"/>
|
||||
<action id="codemp.workspace.leave" class="mp.code.intellij.actions.workspace.WorkspaceLeaveAction"
|
||||
text="Leave Workspace"/>
|
||||
</group>
|
||||
|
|
Loading…
Reference in a new issue