How to print an output of a TypedAction to a tool window?
I was able to print a result of a typed action to a dialog box using below code.
import Algorithms.Guideline06_09;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.actionSystem.TypedActionHandler;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
public class MyTypedHandler implements TypedActionHandler {
private TypedActionHandler myOriginalHandler;
String result = "";
public MyTypedHandler(TypedActionHandler originalHandler){
myOriginalHandler = originalHandler;
}
@Override
public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext){
myOriginalHandler.execute(editor, c, dataContext);
final Document document = editor.getDocument();
final Project project = editor.getProject();
try {
Guideline06_09 obj = new Guideline06_09();
String result = obj.runalgorithm(document.getText());
if(!result.isEmpty()){
Messages.showMessageDialog(project, result, "SCA Arosha", Messages.getInformationIcon());
}
}catch (Exception e){
}
Runnable runnable = new Runnable() {
@Override
public void run() {
}
};
WriteCommandAction.runWriteCommandAction(project, runnable);
}
}
Please sign in to leave a comment.
First of all you should register tollwindow like this:
(plugin.xml)
and
public class SomeFactoryClassName implements ToolWindowFactory {
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
Content content = contentFactory.createContent({some component with console view}, "myView", false);
toolWindow.getContentManager().addContent(content);
}
@Override
public void init(ToolWindow window) {
}
}
Thanks!