generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41ba2fc
commit 99c9692
Showing
12 changed files
with
376 additions
and
67 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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/lilittlecat/chatgpt/action/AddTabAction.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,57 @@ | ||
package com.lilittlecat.chatgpt.action; | ||
|
||
import com.intellij.icons.AllIcons; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.project.DumbAwareAction; | ||
import com.intellij.openapi.ui.Messages; | ||
import com.intellij.openapi.wm.ToolWindow; | ||
import com.intellij.openapi.wm.ToolWindowManager; | ||
import com.intellij.ui.content.Content; | ||
import com.intellij.ui.content.ContentManager; | ||
import com.lilittlecat.chatgpt.message.ChatGPTBundle; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author <a href="https://github.com/LiLittleCat">LiLittleCat</a> | ||
* @since 2023/3/9 | ||
*/ | ||
public class AddTabAction extends DumbAwareAction { | ||
public AddTabAction(@NotNull @Nls String text) { | ||
super(() -> text, AllIcons.General.Add); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
String[] options = new String[] {"Content 1", "Content 2", "Content 3"}; | ||
// String selected = Messages.showChooseDialog("Select Content", "Choose Content to Add", options, options[0], null); | ||
String selected = Messages.showEditableChooseDialog("Select Content", "Choose Content to Add", AllIcons.General.Add, options, options[0], null); | ||
if (selected == null) { | ||
return; | ||
} | ||
ToolWindowManager instance = ToolWindowManager.getInstance(Objects.requireNonNull(e.getProject())); | ||
ToolWindow toolWindow = instance.getToolWindow(ChatGPTBundle.message("name")); | ||
assert toolWindow != null; | ||
ContentManager contentManager = toolWindow.getContentManager(); | ||
switch (selected) { | ||
case "Content 1": { | ||
Content content = contentManager.getFactory().createContent(new JLabel("Content 1"), "Content 1", true); | ||
contentManager.addContent(content); | ||
break; | ||
} | ||
case "Content 2": { | ||
Content content = contentManager.getFactory().createContent(new JLabel("Content 2"), "Content 2", true); | ||
contentManager.addContent(content); | ||
break; | ||
} | ||
case "Content 3": { | ||
Content content = contentManager.getFactory().createContent(new JLabel("Content 3"), "Content 3", true); | ||
contentManager.addContent(content); | ||
break; | ||
} | ||
} | ||
} | ||
} |
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
154 changes: 133 additions & 21 deletions
154
src/main/java/com/lilittlecat/chatgpt/setting/ChatGPTSettingsConfigurable.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 |
---|---|---|
@@ -1,69 +1,181 @@ | ||
package com.lilittlecat.chatgpt.setting; | ||
|
||
import com.intellij.openapi.options.ConfigurationException; | ||
import com.intellij.openapi.options.SearchableConfigurable; | ||
import com.intellij.ui.components.JBList; | ||
import com.intellij.ui.components.JBScrollPane; | ||
import com.lilittlecat.chatgpt.message.ChatGPTBundle; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author LiLittleCat | ||
* @link <a href="https://github.com/LiLittleCat">https://github.com/LiLittleCat</a> | ||
* @since 2022/12/10 | ||
*/ | ||
public class ChatGPTSettingsConfigurable implements SearchableConfigurable { | ||
private ChatGPTSettingsComponent settingComponent; | ||
// private ChatGPTSettingsComponent settingComponent; | ||
// | ||
// // A default constructor with no arguments is required because this implementation | ||
// // is registered as an applicationConfigurable EP | ||
// | ||
// @Nls(capitalization = Nls.Capitalization.Title) | ||
// @Override | ||
// public String getDisplayName() { | ||
// return ChatGPTBundle.message("setting.menu.text"); | ||
// } | ||
// | ||
// @Override | ||
// public JComponent getPreferredFocusedComponent() { | ||
// return settingComponent.getPreferredFocusedComponent(); | ||
// } | ||
// | ||
// @Nullable | ||
// @Override | ||
// public JComponent createComponent() { | ||
// settingComponent = new ChatGPTSettingsComponent(); | ||
// return settingComponent.getPanel(); | ||
// } | ||
// | ||
// @Override | ||
// public boolean isModified() { | ||
// ChatGPTSettingsState settings = ChatGPTSettingsState.getInstance(); | ||
// return !settingComponent.getSessionToken().equals(settings.sessionToken); | ||
// } | ||
// | ||
// @Override | ||
// public void apply() { | ||
// ChatGPTSettingsState settings = ChatGPTSettingsState.getInstance(); | ||
// settings.sessionToken = settingComponent.getSessionToken(); | ||
// } | ||
// | ||
// @Override | ||
// public void reset() { | ||
// ChatGPTSettingsState settings = ChatGPTSettingsState.getInstance(); | ||
// settingComponent.setSessionToken(settings.sessionToken); | ||
// } | ||
// | ||
// @Override | ||
// public void disposeUIResources() { | ||
// settingComponent = null; | ||
// } | ||
// | ||
// @NotNull | ||
// @Override | ||
// public String getId() { | ||
// return "com.lilittlecat.chatgpt.setting.ChatGPTSettingConfigurable"; | ||
// } | ||
|
||
// A default constructor with no arguments is required because this implementation | ||
// is registered as an applicationConfigurable EP | ||
private JTextField tokenField; | ||
private JComboBox<String> pathComboBox; | ||
private JPanel mainPanel; | ||
private List<String> paths; | ||
private JList<String> pathsList; | ||
private DefaultListModel<String> pathsListModel; | ||
|
||
@Nls(capitalization = Nls.Capitalization.Title) | ||
@Override | ||
public String getDisplayName() { | ||
return ChatGPTBundle.message("setting.menu.text"); | ||
public ChatGPTSettingsConfigurable() { | ||
paths = new ArrayList<>(); | ||
pathsListModel = new DefaultListModel<>(); | ||
pathsList.setModel(pathsListModel); | ||
} | ||
|
||
@Nls(capitalization = Nls.Capitalization.Title) | ||
@Override | ||
public JComponent getPreferredFocusedComponent() { | ||
return settingComponent.getPreferredFocusedComponent(); | ||
public String getDisplayName() { | ||
return "My Plugin Settings"; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public JComponent createComponent() { | ||
settingComponent = new ChatGPTSettingsComponent(); | ||
return settingComponent.getPanel(); | ||
mainPanel = new JPanel(new BorderLayout()); | ||
|
||
JPanel tokenPanel = new JPanel(new GridLayout(1, 2)); | ||
JLabel tokenLabel = new JLabel("Token:"); | ||
tokenField = new JTextField(); | ||
tokenPanel.add(tokenLabel); | ||
tokenPanel.add(tokenField); | ||
|
||
JPanel pathPanel = new JPanel(new GridLayout(1, 2)); | ||
JLabel pathLabel = new JLabel("Default Path:"); | ||
pathComboBox = new JComboBox<>(); | ||
pathPanel.add(pathLabel); | ||
pathPanel.add(pathComboBox); | ||
|
||
JPanel pathsPanel = new JPanel(new BorderLayout()); | ||
JLabel pathsLabel = new JLabel("Paths:"); | ||
pathsList = new JBList<>(); | ||
pathsList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); | ||
JScrollPane pathsScrollPane = new JBScrollPane(pathsList); | ||
pathsScrollPane.setPreferredSize(new Dimension(200, 100)); | ||
JButton addPathButton = new JButton("Add Path"); | ||
JButton removePathButton = new JButton("Remove Path"); | ||
addPathButton.addActionListener(e -> { | ||
String newPath = JOptionPane.showInputDialog(mainPanel, "Enter new path:"); | ||
if (newPath != null && !newPath.trim().isEmpty()) { | ||
paths.add(newPath); | ||
pathsListModel.addElement(newPath); | ||
} | ||
}); | ||
removePathButton.addActionListener(e -> { | ||
int index = pathsList.getSelectedIndex(); | ||
if (index != -1) { | ||
paths.remove(index); | ||
pathsListModel.remove(index); | ||
} | ||
}); | ||
JPanel pathsButtonPanel = new JPanel(new GridLayout(1, 2)); | ||
pathsButtonPanel.add(addPathButton); | ||
pathsButtonPanel.add(removePathButton); | ||
pathsPanel.add(pathsLabel, BorderLayout.NORTH); | ||
pathsPanel.add(pathsScrollPane, BorderLayout.CENTER); | ||
pathsPanel.add(pathsButtonPanel, BorderLayout.SOUTH); | ||
|
||
mainPanel.add(tokenPanel, BorderLayout.NORTH); | ||
mainPanel.add(pathPanel, BorderLayout.CENTER); | ||
mainPanel.add(pathsPanel, BorderLayout.SOUTH); | ||
|
||
return mainPanel; | ||
} | ||
|
||
@Override | ||
public boolean isModified() { | ||
ChatGPTSettingsState settings = ChatGPTSettingsState.getInstance(); | ||
return !settingComponent.getSessionToken().equals(settings.sessionToken); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void apply() { | ||
public void apply() throws ConfigurationException { | ||
ChatGPTSettingsState settings = ChatGPTSettingsState.getInstance(); | ||
settings.sessionToken = settingComponent.getSessionToken(); | ||
// Save the settings to some storage | ||
String token = tokenField.getText(); | ||
String defaultPath = (String) pathComboBox.getSelectedItem(); | ||
// Save the paths list to some storage | ||
settings.setSessionToken(token); | ||
settings.setDefaultUrl(defaultPath); | ||
settings.setUrlList(paths); | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
ChatGPTSettingsState settings = ChatGPTSettingsState.getInstance(); | ||
settingComponent.setSessionToken(settings.sessionToken); | ||
// Load the settings from some storage | ||
tokenField.setText(""); | ||
pathComboBox.removeAllItems(); | ||
// Load the paths list from some storage | ||
} | ||
|
||
@Override | ||
public void disposeUIResources() { | ||
settingComponent = null; | ||
mainPanel = null; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getId() { | ||
public @NotNull String getId() { | ||
return "com.lilittlecat.chatgpt.setting.ChatGPTSettingConfigurable"; | ||
} | ||
|
||
} |
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
Oops, something went wrong.