Howto get Project and Editor in Activity triggered through a Tool Window

已回答

I have a plugin with a Tool Window created using Swing elements. When a button is pressed, I want a text to be inserted in the editor.

In a Tool Plugin Window I have the button

acceptButton.addActionListener(toolWindowAcceptAction)

With the definition of the toolWindowAcceptAction as an instance of the class

class ToolWindwonAcceptAction(
var window: TollWindowFactory? = null,
) : ActionListener {
override fun actionPerformed(e: java.awt.event.ActionEvent?) {
// Insert text in Editor
}
}

When this event is triggered, I want a text to be inserted in the current editor.

However I cant figure out how to get a reference to the current Project and/or Editor. The event is an "ActionEvent" and not an "AnActionEvent" (which would reference the current proect and editor). The suggetion in this post is deprecated (and returns null); https://intellij-support.jetbrains.com/hc/en-us/community/posts/360004480599-How-to-get-current-Editor-instance- 

0

Hi,

Try using com.intellij.openapi.fileEditor.FileEditorManager.

0

Worked like a charm! Thank you!

0

请先登录再写评论。