Stop sending requests if tool window isn't visible
This commit is contained in:
@@ -29,7 +29,7 @@ public class KotlinInternalToolWindowFactory implements ToolWindowFactory {
|
|||||||
public void createToolWindowContent(Project project, ToolWindow toolWindow) {
|
public void createToolWindowContent(Project project, ToolWindow toolWindow) {
|
||||||
ContentManager contentManager = toolWindow.getContentManager();
|
ContentManager contentManager = toolWindow.getContentManager();
|
||||||
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
|
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
|
||||||
contentManager.addContent(contentFactory.createContent(new ResolveToolWindow(project), "Resolve", false));
|
contentManager.addContent(contentFactory.createContent(new ResolveToolWindow(project, toolWindow), "Resolve", false));
|
||||||
contentManager.addContent(contentFactory.createContent(new BytecodeToolWindow(project), "Bytecode", false));
|
contentManager.addContent(contentFactory.createContent(new BytecodeToolWindow(project, toolWindow), "Bytecode", false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ public class BytecodeToolWindow extends JPanel implements Disposable {
|
|||||||
public class UpdateBytecodeToolWindowTask extends LongRunningReadTask<Location, String> {
|
public class UpdateBytecodeToolWindowTask extends LongRunningReadTask<Location, String> {
|
||||||
@Override
|
@Override
|
||||||
protected Location prepareRequestInfo() {
|
protected Location prepareRequestInfo() {
|
||||||
|
if (!toolWindow.isVisible()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Location location = Location.fromEditor(FileEditorManager.getInstance(myProject).getSelectedTextEditor(), myProject);
|
Location location = Location.fromEditor(FileEditorManager.getInstance(myProject).getSelectedTextEditor(), myProject);
|
||||||
if (location.getEditor() == null) {
|
if (location.getEditor() == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -169,12 +173,15 @@ public class BytecodeToolWindow extends JPanel implements Disposable {
|
|||||||
private final Editor myEditor;
|
private final Editor myEditor;
|
||||||
private final Alarm myUpdateAlarm;
|
private final Alarm myUpdateAlarm;
|
||||||
private final Project myProject;
|
private final Project myProject;
|
||||||
|
private final ToolWindow toolWindow;
|
||||||
|
|
||||||
private UpdateBytecodeToolWindowTask currentTask = null;
|
private UpdateBytecodeToolWindowTask currentTask = null;
|
||||||
|
|
||||||
public BytecodeToolWindow(Project project) {
|
public BytecodeToolWindow(Project project, ToolWindow toolWindow) {
|
||||||
super(new BorderLayout());
|
super(new BorderLayout());
|
||||||
myProject = project;
|
myProject = project;
|
||||||
|
this.toolWindow = toolWindow;
|
||||||
|
|
||||||
myEditor = EditorFactory.getInstance().createEditor(
|
myEditor = EditorFactory.getInstance().createEditor(
|
||||||
EditorFactory.getInstance().createDocument(""), project, JavaFileType.INSTANCE, true);
|
EditorFactory.getInstance().createDocument(""), project, JavaFileType.INSTANCE, true);
|
||||||
add(myEditor.getComponent());
|
add(myEditor.getComponent());
|
||||||
@@ -245,7 +252,6 @@ public class BytecodeToolWindow extends JPanel implements Disposable {
|
|||||||
byteCodeLine++;
|
byteCodeLine++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (byteCodeStartLine == -1 || byteCodeEndLine == -1) {
|
if (byteCodeStartLine == -1 || byteCodeEndLine == -1) {
|
||||||
return new Pair<Integer, Integer>(0, 0);
|
return new Pair<Integer, Integer>(0, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.editor.Editor;
|
|||||||
import com.intellij.openapi.editor.EditorFactory;
|
import com.intellij.openapi.editor.EditorFactory;
|
||||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.wm.ToolWindow;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
@@ -76,6 +77,10 @@ public class ResolveToolWindow extends JPanel implements Disposable {
|
|||||||
private class UpdateResolveToolWindowTask extends LongRunningReadTask<Location, String> {
|
private class UpdateResolveToolWindowTask extends LongRunningReadTask<Location, String> {
|
||||||
@Override
|
@Override
|
||||||
protected Location prepareRequestInfo() {
|
protected Location prepareRequestInfo() {
|
||||||
|
if (!toolWindow.isVisible()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Location location = Location.fromEditor(FileEditorManager.getInstance(myProject).getSelectedTextEditor(), myProject);
|
Location location = Location.fromEditor(FileEditorManager.getInstance(myProject).getSelectedTextEditor(), myProject);
|
||||||
if (location.getEditor() == null || location.getJetFile() == null) {
|
if (location.getEditor() == null || location.getJetFile() == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -154,13 +159,16 @@ public class ResolveToolWindow extends JPanel implements Disposable {
|
|||||||
private UpdateResolveToolWindowTask currentTask = null;
|
private UpdateResolveToolWindowTask currentTask = null;
|
||||||
|
|
||||||
private final Project myProject;
|
private final Project myProject;
|
||||||
|
private final ToolWindow toolWindow;
|
||||||
|
|
||||||
public ResolveToolWindow(Project project) {
|
public ResolveToolWindow(Project project, ToolWindow toolWindow) {
|
||||||
super(new BorderLayout());
|
super(new BorderLayout());
|
||||||
myProject = project;
|
myProject = project;
|
||||||
|
this.toolWindow = toolWindow;
|
||||||
myEditor = EditorFactory.getInstance()
|
myEditor = EditorFactory.getInstance()
|
||||||
.createEditor(EditorFactory.getInstance().createDocument(""), project, JetFileType.INSTANCE, true);
|
.createEditor(EditorFactory.getInstance().createDocument(""), project, JetFileType.INSTANCE, true);
|
||||||
add(myEditor.getComponent());
|
add(myEditor.getComponent());
|
||||||
|
|
||||||
myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, this);
|
myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, this);
|
||||||
myUpdateAlarm.addRequest(new Runnable() {
|
myUpdateAlarm.addRequest(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user