-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat #148: Allow creation of custom commands
- Loading branch information
Showing
21 changed files
with
417 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.devoxx.genie.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
public class CustomPrompt { | ||
private String name; | ||
private String prompt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/com/devoxx/genie/ui/dialog/CustomPromptDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.devoxx.genie.ui.dialog; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.ui.DialogWrapper; | ||
import com.intellij.openapi.ui.Messages; | ||
import com.intellij.ui.components.JBScrollPane; | ||
import com.intellij.ui.components.JBTextArea; | ||
import com.intellij.ui.components.JBTextField; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
public class CustomPromptDialog extends DialogWrapper { | ||
private final JBTextField nameField; | ||
private final JBTextArea promptArea; | ||
|
||
public CustomPromptDialog(Project project) { | ||
super(project); | ||
setTitle("Add Custom Prompt"); | ||
|
||
nameField = new JBTextField(20); | ||
promptArea = new JBTextArea(10, 40); | ||
promptArea.setLineWrap(true); | ||
promptArea.setWrapStyleWord(true); | ||
|
||
init(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
protected JComponent createCenterPanel() { | ||
JPanel dialogPanel = new JPanel(new BorderLayout(10, 10)); | ||
|
||
// Name input | ||
JPanel namePanel = new JPanel(new BorderLayout()); | ||
namePanel.add(new JLabel("Command Name:"), BorderLayout.WEST); | ||
namePanel.add(nameField, BorderLayout.CENTER); | ||
|
||
// Prompt input | ||
JPanel promptPanel = new JPanel(new BorderLayout()); | ||
promptPanel.add(new JLabel("Prompt:"), BorderLayout.NORTH); | ||
JBScrollPane scrollPane = new JBScrollPane(promptArea); | ||
promptPanel.add(scrollPane, BorderLayout.CENTER); | ||
|
||
dialogPanel.add(namePanel, BorderLayout.NORTH); | ||
dialogPanel.add(promptPanel, BorderLayout.CENTER); | ||
|
||
return dialogPanel; | ||
} | ||
|
||
@Override | ||
protected void doOKAction() { | ||
if (validateInput()) { | ||
super.doOKAction(); | ||
} | ||
} | ||
|
||
private boolean validateInput() { | ||
if (nameField.getText().trim().isEmpty()) { | ||
Messages.showErrorDialog("The command name cannot be empty.", "Invalid Name"); | ||
return false; | ||
} | ||
if (promptArea.getText().trim().isEmpty()) { | ||
Messages.showErrorDialog("The prompt cannot be empty.", "Invalid Prompt"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public String getCommandName() { | ||
return nameField.getText().trim(); | ||
} | ||
|
||
public String getPrompt() { | ||
return promptArea.getText().trim(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/devoxx/genie/ui/listener/CustomPromptChangeListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.devoxx.genie.ui.listener; | ||
|
||
public interface CustomPromptChangeListener { | ||
void onCustomPromptsChanged(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,48 @@ | ||
package com.devoxx.genie.ui.panel; | ||
|
||
import com.intellij.ui.components.JBLabel; | ||
|
||
import java.awt.*; | ||
|
||
import com.intellij.ui.components.JBScrollPane; | ||
import javax.swing.*; | ||
|
||
public class HelpPanel extends BackgroundPanel { | ||
private final JEditorPane helpPane; | ||
|
||
/** | ||
* Create a help panel, listing the fixed prompt commands available | ||
* | ||
* @param helpMsg the help message | ||
*/ | ||
public HelpPanel(String helpMsg) { | ||
super("helpPanel"); | ||
setLayout(new BorderLayout()); | ||
withPreferredHeight(80); | ||
withPreferredHeight(175); | ||
add(new JBLabel(helpMsg), BorderLayout.CENTER); | ||
|
||
helpPane = new JEditorPane("text/html", ""); | ||
helpPane.setEditable(false); | ||
helpPane.setOpaque(false); | ||
helpPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); | ||
|
||
JBScrollPane scrollPane = new JBScrollPane(helpPane); | ||
scrollPane.setBorder(null); | ||
scrollPane.setOpaque(false); | ||
scrollPane.getViewport().setOpaque(false); | ||
|
||
add(scrollPane, BorderLayout.CENTER); | ||
updateHelpText(helpMsg); | ||
} | ||
|
||
public void updateHelpText(String newHelpMsg) { | ||
helpPane.setText(newHelpMsg); | ||
updatePanelSize(); | ||
} | ||
|
||
private void updatePanelSize() { | ||
SwingUtilities.invokeLater(() -> { | ||
int preferredHeight = calculatePreferredHeight(); | ||
setPreferredSize(new Dimension(getWidth(), preferredHeight)); | ||
revalidate(); | ||
repaint(); | ||
}); | ||
} | ||
|
||
private int calculatePreferredHeight() { | ||
int contentHeight = helpPane.getPreferredSize().height; | ||
int maxHeight = 300; // Set a maximum height if needed | ||
return Math.min(contentHeight + 20, maxHeight); // Add some padding | ||
} | ||
} |
Oops, something went wrong.