generated from JetBrains/intellij-platform-plugin-template
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
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/cc/unitmesh/devti/actions/chat/ChatWithThisAction.kt
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,42 @@ | ||
package cc.unitmesh.devti.actions.chat | ||
|
||
import cc.unitmesh.devti.gui.DevtiFlowToolWindowFactory | ||
import cc.unitmesh.devti.gui.chat.ChatActionType | ||
import cc.unitmesh.devti.gui.chat.ChatCodingComponent | ||
import cc.unitmesh.devti.gui.chat.ChatCodingService | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.actionSystem.CommonDataKeys | ||
import com.intellij.openapi.wm.ToolWindowManager | ||
|
||
class ChatWithThisAction: ChatBaseAction() { | ||
override fun getActionType(): ChatActionType { | ||
return ChatActionType.CHAT | ||
} | ||
|
||
override fun actionPerformed(event: AnActionEvent) { | ||
val project = event.project ?: return | ||
val document = event.getData(CommonDataKeys.EDITOR)?.document | ||
|
||
val caretModel = event.getData(CommonDataKeys.EDITOR)?.caretModel | ||
var prefixText = caretModel?.currentCaret?.selectedText ?: "" | ||
|
||
val toolWindowManager = ToolWindowManager.getInstance(project).getToolWindow(DevtiFlowToolWindowFactory.Util.id) | ||
val contentManager = toolWindowManager?.contentManager | ||
|
||
val chatCodingService = ChatCodingService(getActionType(), project) | ||
val contentPanel = ChatCodingComponent(chatCodingService) | ||
val content = contentManager?.factory?.createContent(contentPanel, "Chat with this", false) | ||
val language = event.getData(CommonDataKeys.PSI_FILE)?.language?.displayName ?: "" | ||
|
||
contentManager?.removeAllContents(true) | ||
contentManager?.addContent(content!!) | ||
|
||
toolWindowManager?.activate { | ||
contentPanel.setContent(""" | ||
|```$language | ||
|$prefixText | ||
|```""".trimMargin()) | ||
} | ||
|
||
} | ||
} |
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