Stop sending requests if tool window isn't visible

This commit is contained in:
Nikolay Krasko
2013-12-12 18:08:06 +04:00
parent fcf81f42e2
commit bbe85f2533
3 changed files with 19 additions and 5 deletions
@@ -29,7 +29,7 @@ public class KotlinInternalToolWindowFactory implements ToolWindowFactory {
public void createToolWindowContent(Project project, ToolWindow toolWindow) {
ContentManager contentManager = toolWindow.getContentManager();
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
contentManager.addContent(contentFactory.createContent(new ResolveToolWindow(project), "Resolve", false));
contentManager.addContent(contentFactory.createContent(new BytecodeToolWindow(project), "Bytecode", false));
contentManager.addContent(contentFactory.createContent(new ResolveToolWindow(project, toolWindow), "Resolve", 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> {
@Override
protected Location prepareRequestInfo() {
if (!toolWindow.isVisible()) {
return null;
}
Location location = Location.fromEditor(FileEditorManager.getInstance(myProject).getSelectedTextEditor(), myProject);
if (location.getEditor() == null) {
return null;
@@ -169,12 +173,15 @@ public class BytecodeToolWindow extends JPanel implements Disposable {
private final Editor myEditor;
private final Alarm myUpdateAlarm;
private final Project myProject;
private final ToolWindow toolWindow;
private UpdateBytecodeToolWindowTask currentTask = null;
public BytecodeToolWindow(Project project) {
public BytecodeToolWindow(Project project, ToolWindow toolWindow) {
super(new BorderLayout());
myProject = project;
this.toolWindow = toolWindow;
myEditor = EditorFactory.getInstance().createEditor(
EditorFactory.getInstance().createDocument(""), project, JavaFileType.INSTANCE, true);
add(myEditor.getComponent());
@@ -245,7 +252,6 @@ public class BytecodeToolWindow extends JPanel implements Disposable {
byteCodeLine++;
}
if (byteCodeStartLine == -1 || byteCodeEndLine == -1) {
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.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
@@ -76,6 +77,10 @@ public class ResolveToolWindow extends JPanel implements Disposable {
private class UpdateResolveToolWindowTask extends LongRunningReadTask<Location, String> {
@Override
protected Location prepareRequestInfo() {
if (!toolWindow.isVisible()) {
return null;
}
Location location = Location.fromEditor(FileEditorManager.getInstance(myProject).getSelectedTextEditor(), myProject);
if (location.getEditor() == null || location.getJetFile() == null) {
return null;
@@ -154,13 +159,16 @@ public class ResolveToolWindow extends JPanel implements Disposable {
private UpdateResolveToolWindowTask currentTask = null;
private final Project myProject;
private final ToolWindow toolWindow;
public ResolveToolWindow(Project project) {
public ResolveToolWindow(Project project, ToolWindow toolWindow) {
super(new BorderLayout());
myProject = project;
this.toolWindow = toolWindow;
myEditor = EditorFactory.getInstance()
.createEditor(EditorFactory.getInstance().createDocument(""), project, JetFileType.INSTANCE, true);
add(myEditor.getComponent());
myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, this);
myUpdateAlarm.addRequest(new Runnable() {
@Override