diff --git a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/CopyAction.java b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/CopyAction.java index 2d5a76d2..15618a32 100644 --- a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/CopyAction.java +++ b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/CopyAction.java @@ -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); diff --git a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ChatMessageResponseBody.java b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ChatMessageResponseBody.java index d834f903..a001c8b7 100644 --- a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ChatMessageResponseBody.java +++ b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ChatMessageResponseBody.java @@ -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); diff --git a/src/main/resources/messages/codegpt.properties b/src/main/resources/messages/codegpt.properties index 9e16c10b..12e8e5d8 100644 --- a/src/main/resources/messages/codegpt.properties +++ b/src/main/resources/messages/codegpt.properties @@ -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