mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-06 08:02:13 +00:00
1.1.1 - Remove missing api key notification on startup
This commit is contained in:
parent
07c2f6a0d7
commit
36c8255aa6
5 changed files with 25 additions and 86 deletions
|
|
@ -4,7 +4,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = "ee.carlrobert"
|
||||
version = "1.1.0"
|
||||
version = "1.1.1"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
package ee.carlrobert.chatgpt.ide.notification;
|
||||
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationGroupManager;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import ee.carlrobert.chatgpt.ide.settings.SettingsConfigurable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NotificationService {
|
||||
|
||||
private Notification notification;
|
||||
|
||||
public void createAndNotify(@NotNull Project project) {
|
||||
createNotification();
|
||||
notify(project);
|
||||
}
|
||||
|
||||
public void expire() {
|
||||
if (notification != null) {
|
||||
notification.expire();
|
||||
}
|
||||
}
|
||||
|
||||
private void notify(@NotNull Project project) {
|
||||
this.notification
|
||||
.addAction(new AnAction("Open Settings") {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent event) {
|
||||
DataContext dataContext = event.getDataContext();
|
||||
Project project = PlatformDataKeys.PROJECT.getData(dataContext);
|
||||
ShowSettingsUtil.getInstance().showSettingsDialog(project, SettingsConfigurable.class);
|
||||
}
|
||||
})
|
||||
.notify(project);
|
||||
}
|
||||
|
||||
private void createNotification() {
|
||||
this.notification = NotificationGroupManager.getInstance()
|
||||
.getNotificationGroup("ChatGPT-Empty-API-Key")
|
||||
.createNotification("ChatGPT API key not set", NotificationType.WARNING);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
package ee.carlrobert.chatgpt.ide.notification;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.startup.StartupActivity;
|
||||
import ee.carlrobert.chatgpt.ide.settings.SettingsState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ShowNotificationActivity implements StartupActivity {
|
||||
|
||||
@Override
|
||||
public void runActivity(@NotNull Project project) {
|
||||
var notificationService = ApplicationManager.getApplication().getService(NotificationService.class);
|
||||
var apiKey = SettingsState.getInstance().apiKey;
|
||||
if (apiKey == null || apiKey.isEmpty()) {
|
||||
notificationService.createAndNotify(project);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package ee.carlrobert.chatgpt.ide.toolwindow;
|
|||
import static ee.carlrobert.chatgpt.ide.toolwindow.ToolWindowUtil.createIconLabel;
|
||||
import static ee.carlrobert.chatgpt.ide.toolwindow.ToolWindowUtil.createTextArea;
|
||||
import static ee.carlrobert.chatgpt.ide.toolwindow.ToolWindowUtil.justifyLeft;
|
||||
import static java.lang.String.format;
|
||||
|
||||
import com.intellij.ide.ui.LafManager;
|
||||
import com.intellij.ide.ui.LafManagerListener;
|
||||
|
|
@ -60,16 +61,11 @@ public class ToolWindowService implements LafManagerListener {
|
|||
addIconLabel(Icons.DefaultImageIcon, "ChatGPT:");
|
||||
addSpacing(8);
|
||||
|
||||
var apiKey = SettingsState.getInstance().apiKey;
|
||||
if (apiKey == null || apiKey.isEmpty()) {
|
||||
var label = new JLabel("<html>API key not provided. <font color='#589df6'><u>Open Settings</u></font> to set one.</html>");
|
||||
label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
label.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
ShowSettingsUtil.getInstance().showSettingsDialog(project, SettingsConfigurable.class);
|
||||
}
|
||||
});
|
||||
scrollablePanel.add(justifyLeft(label));
|
||||
var settings = SettingsState.getInstance();
|
||||
if (settings.isGPTOptionSelected && settings.apiKey.isEmpty()) {
|
||||
notifyMissingCredential(project, "API key not provided.");
|
||||
} else if (settings.isChatGPTOptionSelected && settings.accessToken.isEmpty()) {
|
||||
notifyMissingCredential(project, "Access token not provided.");
|
||||
} else {
|
||||
var textArea = new SyntaxTextArea();
|
||||
scrollablePanel.add(textArea);
|
||||
|
|
@ -135,6 +131,17 @@ public class ToolWindowService implements LafManagerListener {
|
|||
scrollablePanel.add(justifyLeft(createIconLabel(imageIcon, text)));
|
||||
}
|
||||
|
||||
private void notifyMissingCredential(Project project, String text) {
|
||||
var label = new JLabel(format("<html>%s <font color='#589df6'><u>Open Settings</u></font> to set one.</html>", text));
|
||||
label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
label.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
ShowSettingsUtil.getInstance().showSettingsDialog(project, SettingsConfigurable.class);
|
||||
}
|
||||
});
|
||||
scrollablePanel.add(justifyLeft(label));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lookAndFeelChanged(@NotNull LafManager source) {
|
||||
for (var textArea : textAreas) {
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@
|
|||
<br />
|
||||
<span>Available commands</span>
|
||||
<ul>
|
||||
<li><b>Find bugs:</b> Analyze and find bugs in your code. Right click on a selected block of code, run command.</li>
|
||||
<li><b>Add tests:</b> Write tests for you. Right click on a selected block of code, run command.</li>
|
||||
<li><b>Refactor:</b> Refactor your code. Right click on a selected block of code, run command.</li>
|
||||
<li><b>Optimize:</b> Add suggestions to your code to improve. Right click on a selected block of code, run command.</li>
|
||||
<li><b>Explain:</b> Explain the selected code. Right click on a selected block of code, run command.</li>
|
||||
<li><b>Find bugs:</b> Analyze and find bugs in your code. Right-click on a selected block of code, run command.</li>
|
||||
<li><b>Add tests:</b> Write tests for you. Right-click on a selected block of code, run command.</li>
|
||||
<li><b>Refactor:</b> Refactor your code. Right-click on a selected block of code, run command.</li>
|
||||
<li><b>Optimize:</b> Add suggestions to your code to improve. Right-click on a selected block of code, run command.</li>
|
||||
<li><b>Explain:</b> Explain the selected code. Right-click on a selected block of code, run command.</li>
|
||||
</ul>
|
||||
<br />
|
||||
<p><b>Before using the plugin, it is necessary to configure the API key in the Settings → Tools → ChatGPT</b></p>
|
||||
|
|
@ -21,6 +21,8 @@
|
|||
<change-notes>
|
||||
<![CDATA[
|
||||
<ul>
|
||||
<li><b>1.1.1</b> Remove startup notification</li>
|
||||
<li><b>1.1.0</b> Add reverse proxy support, fix text selection and copy functionality</li>
|
||||
<li><b>1.0.9</b> Add code syntax highlighting and copy functionality, remove plugin required for restart</li>
|
||||
<li><b>1.0.8</b> Migrate to Java 17, fix ToolWindow NPE</li>
|
||||
<li><b>1.0.7</b> Code refactoring, add readme</li>
|
||||
|
|
@ -44,14 +46,11 @@
|
|||
</applicationListeners>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<postStartupActivity implementation="ee.carlrobert.chatgpt.ide.notification.ShowNotificationActivity"/>
|
||||
|
||||
<applicationConfigurable parentId="tools" instance="ee.carlrobert.chatgpt.ide.settings.SettingsConfigurable"
|
||||
id="org.intellij.sdk.settings.AppSettingsConfigurable"
|
||||
displayName="ChatGPT"/>
|
||||
<applicationService serviceImplementation="ee.carlrobert.chatgpt.ide.settings.SettingsState"/>
|
||||
<applicationService serviceImplementation="ee.carlrobert.chatgpt.ide.toolwindow.ToolWindowService"/>
|
||||
<applicationService serviceImplementation="ee.carlrobert.chatgpt.ide.notification.NotificationService"/>
|
||||
<toolWindow id="ChatGPT" icon="Icons.DefaultIcon" anchor="right"
|
||||
factoryClass="ee.carlrobert.chatgpt.ide.toolwindow.ChatGptToolWindowFactory"/>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue