Skip to content

Commit

Permalink
add more url
Browse files Browse the repository at this point in the history
  • Loading branch information
LiLittleCat committed Mar 21, 2023
1 parent 41ba2fc commit 99c9692
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 67 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ plugins {
// Java support
id("java")
// Kotlin support
id("org.jetbrains.kotlin.jvm") version "1.7.21"
id("org.jetbrains.kotlin.jvm") version "1.8.0"
// Gradle IntelliJ Plugin
id("org.jetbrains.intellij") version "1.10.1"
id("org.jetbrains.intellij") version "1.12.0"
// Gradle Changelog Plugin
id("org.jetbrains.changelog") version "2.0.0"
// Gradle Qodana Plugin
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/com/lilittlecat/chatgpt/action/AddTabAction.java
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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
}
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
@SuppressWarnings("DialogTitleCapitalization")
Content browser = contentFactory.createContent(new ChatGPTToolWindow().getContent(),
Content browser = contentFactory.createContent(new ChatGPTToolWindow("https://baidu.com").getContent(),
ChatGPTBundle.message("browser.tab.name"), false);
contentManager.addContent(browser);
contentManager.setSelectedContent(browser);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lilittlecat.chatgpt.setting;

import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBList;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.components.JBTextArea;
import com.intellij.util.ui.FormBuilder;
Expand All @@ -18,6 +19,8 @@ public class ChatGPTSettingsComponent {
private final JPanel myMainPanel;
private final JBTextArea sessionToken = new JBTextArea();

private JBList<String> urlList;

public ChatGPTSettingsComponent() {
sessionToken.setFont(UIUtil.getLabelFont());
sessionToken.setLineWrap(true);
Expand Down
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";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
* @author LiLittleCat
* @link <a href="https://github.com/LiLittleCat">https://github.com/LiLittleCat</a>
Expand All @@ -20,6 +23,10 @@
public class ChatGPTSettingsState implements PersistentStateComponent<ChatGPTSettingsState> {
public String sessionToken = "";

public String defaultUrl = "";

public List<String> urlList = new ArrayList<>();

@Nullable
@Override
public ChatGPTSettingsState getState() {
Expand All @@ -31,10 +38,18 @@ public void loadState(@NotNull ChatGPTSettingsState state) {
XmlSerializerUtil.copyBean(state, this);
}

public void update(String sessionToken) {
public void setSessionToken(String sessionToken) {
this.sessionToken = sessionToken;
}

public void setDefaultUrl(String defaultUrl) {
this.defaultUrl = defaultUrl;
}

public void setUrlList(List<String> urlList) {
this.urlList = urlList;
}

public static ChatGPTSettingsState getInstance() {
return ApplicationManager.getApplication().getService(ChatGPTSettingsState.class);
}
Expand Down

0 comments on commit 99c9692

Please sign in to comment.