feat: add popup menu for toolwindow chat textpane

This commit is contained in:
Carl-Robert Linnupuu 2024-12-16 12:43:45 +00:00
parent 2b53033b69
commit 0d52dc5ae8
3 changed files with 31 additions and 2 deletions

View file

@ -19,7 +19,7 @@ public class CopyAction extends TrackableAction {
public CopyAction(@NotNull Editor toolwindowEditor) {
super(
CodeGPTBundle.get("toolwindow.chat.editor.action.copy.title"),
CodeGPTBundle.get("shared.copy"),
CodeGPTBundle.get("toolwindow.chat.editor.action.copy.description"),
Actions.Copy,
ActionType.COPY_CODE);

View file

@ -5,8 +5,13 @@ import static ee.carlrobert.codegpt.util.MarkdownUtil.convertMdToHtml;
import static java.lang.String.format;
import static javax.swing.event.HyperlinkEvent.EventType.ACTIVATED;
import com.intellij.icons.AllIcons;
import com.intellij.icons.AllIcons.General;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileEditorManager;
@ -15,6 +20,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.PopupHandler;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.JBUI;
import com.vladsch.flexmark.ast.FencedCodeBlock;
@ -313,9 +319,31 @@ public class ChatMessageResponseBody extends JPanel {
textPane.setCaretPosition(textPane.getDocument().getLength());
}
textPane.setBorder(JBUI.Borders.empty());
installPopupMenu(textPane);
return textPane;
}
private void installPopupMenu(JTextPane textPane) {
PopupHandler.installPopupMenu(textPane, new DefaultActionGroup(
new AnAction(
CodeGPTBundle.get("shared.copy"),
CodeGPTBundle.get("shared.copyToClipboard"),
AllIcons.Actions.Copy) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
textPane.copy();
}
@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabled(textPane.getSelectedText() != null);
}
}
), ActionPlaces.EDITOR_POPUP);
}
private static JPanel createWebpageListPanel(WebpageList webpageList) {
var title = new JPanel(new BorderLayout());
title.setOpaque(false);

View file

@ -171,7 +171,6 @@ dialog.tokenSoftLimitExceeded.description=Warning: The 'git diff' output contain
dialog.continue=Continue
editor.diff.title=CodeGPT Diff
editor.diff.local.content.title=CodeGPT suggested code
toolwindow.chat.editor.action.copy.title=Copy
toolwindow.chat.editor.action.copy.description=Copy generated code
toolwindow.chat.editor.action.copy.success=Code copied!
toolwindow.chat.editor.action.autoApply.title=Auto Apply
@ -234,6 +233,8 @@ shared.apiVersion=API version:
shared.escToCancel=Esc to cancel
shared.cancel=Cancel
shared.confirm=Confirm
shared.copy=Copy
shared.copyToClipboard=Copy to clipboard
shared.configuration=Configuration
shared.port=Port:
shared.discard=Discard