fix: codemp toolbar panel layout and titles

This commit is contained in:
əlemi 2024-10-02 02:29:02 +02:00
parent 3a1f1657d2
commit d48954abfc
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -4,6 +4,8 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.Messages;
import com.intellij.ui.treeStructure.Tree; import com.intellij.ui.treeStructure.Tree;
import mp.code.Workspace;
import mp.code.intellij.CodeMP; import mp.code.intellij.CodeMP;
import mp.code.intellij.util.FileUtil; import mp.code.intellij.util.FileUtil;
import mp.code.intellij.util.InteractionUtil; import mp.code.intellij.util.InteractionUtil;
@ -41,7 +43,7 @@ public class CodeMPToolPanel extends JPanel {
} }
case CONNECTED -> { case CONNECTED -> {
this.setLayout(new GridLayout(0, 1)); this.setLayout(new GridLayout(0, 1));
JTree tree = drawTree(InteractionUtil.listWorkspaces(project, true, true)); JTree tree = drawTree("all workspaces", InteractionUtil.listWorkspaces(project, true, true));
tree.addMouseListener(new SimpleMouseListener() { tree.addMouseListener(new SimpleMouseListener() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
@ -59,6 +61,7 @@ public class CodeMPToolPanel extends JPanel {
this.add(tree); this.add(tree);
} }
case JOINED -> { case JOINED -> {
this.setLayout(new BorderLayout(1, 0));
JButton createButton = new JButton(new AbstractAction("Create buffer") { JButton createButton = new JButton(new AbstractAction("Create buffer") {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -72,9 +75,11 @@ public class CodeMPToolPanel extends JPanel {
CodeMPToolPanel.this.redraw(project); CodeMPToolPanel.this.redraw(project);
} }
}); });
createButton.setSize(createButton.getPreferredSize()); // createButton.setSize(createButton.getPreferredSize());
this.add(createButton, BorderLayout.NORTH);
JTree tree = drawTree(CodeMP.getActiveWorkspace().getFileTree(Optional.empty(), false)); Workspace ws = CodeMP.getActiveWorkspace();
JTree tree = drawTree(ws.getWorkspaceId(), ws.getFileTree(Optional.empty(), false));
tree.addMouseListener(new SimpleMouseListener() { tree.addMouseListener(new SimpleMouseListener() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
@ -102,14 +107,13 @@ public class CodeMPToolPanel extends JPanel {
} }
}); });
this.add(createButton); this.add(tree, BorderLayout.CENTER);
this.add(tree);
} }
} }
} }
private JTree drawTree(String[] contents) { private JTree drawTree(String workspace, String[] contents) {
DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode root = new DefaultMutableTreeNode(workspace);
for(String content : contents) { for(String content : contents) {
root.add(new DefaultMutableTreeNode(content)); root.add(new DefaultMutableTreeNode(content));
} }