Skip to content

Fix/20250323 #35

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

Merged
merged 6 commits into from
Mar 24, 2025
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
4 changes: 2 additions & 2 deletions src/main/java/cn/xiaoheiban/action/ApiAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public String getExtension() {
@Override
public void performed(@NotNull AnActionEvent e, @NotNull VirtualFile file, @NotNull Project project) {
String parent = file.getParent().getPath();
FileChooseDialog dialog = new FileChooseDialog("API Generate Option", "Cancel", false);
FileChooseDialog dialog = new FileChooseDialog("API Generate Option", "Cancel", false,false);
dialog.setDefaultPath(parent);
dialog.setOnClickListener(new FileChooseDialog.OnClickListener() {
@Override
public void onOk(String goctlHome, String output, String protoPath, String style) {
public void onOk(String goctlHome, String output, String protoPath, String style,boolean group,boolean client) {
ProgressManager.getInstance().run(new Task.Backgroundable(project, "generating api ...") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/xiaoheiban/action/ModelAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public String getExtension() {
@Override
public void performed(@NotNull AnActionEvent e, @NotNull VirtualFile file, @NotNull Project project) {
String parent = file.getParent().getPath();
FileChooseDialog dialog = new FileChooseDialog("Model Generate Option", "Cancel", false);
FileChooseDialog dialog = new FileChooseDialog("Model Generate Option", "Cancel", false, false);
dialog.setDefaultPath(parent);
dialog.setOnClickListener(new FileChooseDialog.OnClickListener() {
@Override
public void onOk(String goctlHome, String output, String protoPath, String style) {
public void onOk(String goctlHome, String output, String protoPath, String style, boolean group,boolean client) {
ProgressManager.getInstance().run(new Task.Backgroundable(project, "generating model ...") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/cn/xiaoheiban/action/RpcAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public void performed(@NotNull AnActionEvent e, @NotNull VirtualFile file, @NotN
try {
String parent = file.getParent().getPath();
String content = IO.read(file.getInputStream());
FileChooseDialog dialog = new FileChooseDialog("zRPC Generate Option", "Cancel", content.contains("import"));
FileChooseDialog dialog = new FileChooseDialog("zRPC Generate Option", "Cancel", content.contains("import"), true);
dialog.setDefaultPath(parent);
dialog.setOnClickListener(new FileChooseDialog.OnClickListener() {
@Override
public void onOk(String goctlHome, String output, String protoPath, String style) {
generateRpc(project, goctlHome, protoPath, path, output, style, e);
public void onOk(String goctlHome, String output, String protoPath, String style, boolean group, boolean client) {
generateRpc(project, goctlHome, protoPath, path, output, style, group, client, e);
}

@Override
Expand All @@ -44,7 +44,7 @@ public void onJump() {
}
}

private void generateRpc(Project project, String goctlHome, String protoPath, String src, String target, String style, AnActionEvent e) {
private void generateRpc(Project project, String goctlHome, String protoPath, String src, String target, String style, boolean group, boolean client, AnActionEvent e) {
ProgressManager.getInstance().run(new Task.Backgroundable(project, "generating rpc ...") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
Expand All @@ -67,6 +67,12 @@ public void run(@NotNull ProgressIndicator indicator) {
}
}
}
if (group) {
command += " --multiple ";
}
if (!client) {
command += " --client=false ";
}
boolean done = Exec.runGoctl(project, command);
if (done) {
FileReload.reloadFromDisk(e);
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/cn/xiaoheiban/action/RpcQuickAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public void performed(@NotNull AnActionEvent e, @NotNull VirtualFile file, @NotN
String content = IO.read(file.getInputStream());
boolean hasImport = content.contains("import");
if (!hasImport) {
generateRpc(project, "", "", path, parent, "", e);
generateRpc(project, "", "", path, parent, "", false, false, e);
return;
}
FileChooseDialog dialog = new FileChooseDialog("zRPC Generate Option", "Cancel", content.contains("import"));
FileChooseDialog dialog = new FileChooseDialog("zRPC Generate Option", "Cancel", content.contains("import"), true);
dialog.setDefaultPath(parent);
dialog.setOnClickListener(new FileChooseDialog.OnClickListener() {
@Override
public void onOk(String goctlHome, String output, String protoPath, String style) {
generateRpc(project, goctlHome, protoPath, path, output, style, e);
public void onOk(String goctlHome, String output, String protoPath, String style, boolean group, boolean client) {
generateRpc(project, goctlHome, protoPath, path, output, style, group, client, e);
}

@Override
Expand All @@ -56,7 +56,7 @@ public void onJump() {
}
}

private void generateRpc(Project project, String goctlHome, String protoPath, String src, String target, String style, AnActionEvent e) {
private void generateRpc(Project project, String goctlHome, String protoPath, String src, String target, String style, boolean group, boolean client, AnActionEvent e) {
ProgressManager.getInstance().run(new Task.Backgroundable(project, "generating rpc ...") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
Expand All @@ -82,6 +82,12 @@ public void run(@NotNull ProgressIndicator indicator) {
}
}
}
if (group) {
command += " --multiple ";
}
if (!client) {
command += " --client=false ";
}
boolean done = Exec.runGoctl(project, command);
if (done) {
FileReload.reloadFromDisk(e);
Expand Down
47 changes: 41 additions & 6 deletions src/main/java/cn/xiaoheiban/ui/FileChooseDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,33 @@

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class FileChooseDialog extends DialogWrapper {
private OnClickListener onOkClickListener;
private String title;
private boolean rpc;
private boolean showProtoPath;

public interface OnClickListener {
void onOk(String goctlHome, String output, String protoPath, String style);
void onOk(String goctlHome, String output, String protoPath, String style, boolean group, boolean client);

void onJump();
}

private TextFieldWithBrowseButton textFieldWithBrowseButton;
private TextFieldWithBrowseButton protoPathBrowseButton;
private TextFieldWithBrowseButton templateBrowseButton;
private Checkbox groupCheckBox, clientBox;
private JTextField gozeroTextField;
private final String stylePropertyKey = "cn.xiaoheiban.go-zero" + "_style";

public FileChooseDialog(String title, String cancelText, boolean showProtoPath) {
public FileChooseDialog(String title, String cancelText, boolean showProtoPath, boolean rpc) {
super(true);
this.title = title;
this.showProtoPath = showProtoPath;
this.rpc = rpc;
init();
setTitle(title);
setOKButtonText("Confirm");
Expand All @@ -61,7 +66,7 @@ public void setDefaultPath(String path) {
@Override
protected JComponent createCenterPanel() {
final JPanel contentPane = new JPanel();
contentPane.setLayout(new GridLayoutManager(4, 2, new Insets(10, 10, 10, 10), -1, -1));
contentPane.setLayout(new GridLayoutManager(6, 2, new Insets(10, 10, 10, 10), -1, -1));

Dimension labelDimension = new Dimension(100, -1);
Dimension textFieldDimension = new Dimension(500, -1);
Expand Down Expand Up @@ -113,6 +118,29 @@ protected JComponent createCenterPanel() {
contentPane.add(stylePanel, new GridConstraints(0, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
contentPane.add(outputPanel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
contentPane.add(templatePanel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
if (rpc) {
final JPanel groupPanel = new JPanel();
groupPanel.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
final JLabel groupLabel = new JLabel();
groupLabel.setText("Group");
groupPanel.add(groupLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, labelDimension, null, 0, false));

groupCheckBox = new Checkbox();
groupPanel.add(groupCheckBox, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, textFieldDimension, null, 0, false));
contentPane.add(groupPanel, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));

final JPanel clientPanel = new JPanel();
clientPanel.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
final JLabel clientLabel = new JLabel();
clientLabel.setText("Client");
clientPanel.add(clientLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, labelDimension, null, 0, false));

clientBox = new Checkbox();
clientBox.setState(true);
clientPanel.add(clientBox, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, textFieldDimension, null, 0, false));
contentPane.add(clientPanel, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));

}
if (showProtoPath) {
final JPanel protoPathPanel = new JPanel();
protoPathPanel.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
Expand All @@ -126,7 +154,7 @@ protected JComponent createCenterPanel() {
TextBrowseFolderListener protoPathListener = new TextBrowseFolderListener(protoPathChooserDescriptor);
protoPathBrowseButton.addBrowseFolderListener(protoPathListener);
protoPathPanel.add(protoPathBrowseButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, textFieldDimension, null, 0, false));
contentPane.add(protoPathPanel, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
contentPane.add(protoPathPanel, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
}
return contentPane;
}
Expand All @@ -136,7 +164,8 @@ protected JComponent createCenterPanel() {
protected ValidationInfo doValidate() {
String goctlHome = templateBrowseButton.getText();
String outputBrowserPath = textFieldWithBrowseButton.getText();

boolean groupCheck = false;
boolean clientCheck = true;
// store style string
String style = gozeroTextField.getText();
PropertiesComponent.getInstance().setValue(stylePropertyKey, style);
Expand All @@ -154,8 +183,14 @@ protected ValidationInfo doValidate() {
protoPath = protoFile.getPath();
}
}
if (groupCheckBox != null) {
groupCheck = groupCheckBox.getState();
}
if (clientBox != null) {
clientCheck = clientBox.getState();
}
if (this.onOkClickListener != null) {
this.onOkClickListener.onOk(goctlHome, output, protoPath, style);
this.onOkClickListener.onOk(goctlHome, output, protoPath, style, groupCheck, clientCheck);
}
return null;
}
Expand Down
Loading