reduce debugger views flickering - process all events with delay

This commit is contained in:
Egor.Ushakov
2014-08-18 15:39:45 +04:00
parent c03358fa60
commit 1ca73cfc0f
6 changed files with 20 additions and 27 deletions
@@ -20,7 +20,7 @@ import com.intellij.ide.DataManager;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.ui.content.ContentManager;
import com.intellij.util.SingleAlarm;
import com.intellij.util.Alarm;
import com.intellij.xdebugger.XDebugSession;
import com.intellij.xdebugger.impl.ui.XDebugSessionTab;
import org.jetbrains.annotations.NotNull;
@@ -35,29 +35,26 @@ import java.util.EventObject;
public abstract class XDebugView implements Disposable {
public enum SessionEvent {PAUSED, BEFORE_RESUME, RESUMED, STOPPED, FRAME_CHANGED, SETTINGS_CHANGED}
private final SingleAlarm myClearAlarm;
private static final int VIEW_CLEAR_DELAY = 100; //ms
private final Alarm myUpdateAlarm;
private static final int VIEW_UPDATE_DELAY = 100; //ms
public XDebugView() {
myClearAlarm = new SingleAlarm(new Runnable() {
@Override
public void run() {
clear();
}
}, VIEW_CLEAR_DELAY, this);
}
protected final void requestClear() {
myClearAlarm.cancelAndRequest();
}
protected final void cancelClear() {
myClearAlarm.cancel();
myUpdateAlarm = new Alarm(this);
}
protected abstract void clear();
public abstract void processSessionEvent(@NotNull SessionEvent event);
public void onSessionEvent(@NotNull final SessionEvent event) {
myUpdateAlarm.cancelAllRequests();
myUpdateAlarm.addRequest(new Runnable() {
@Override
public void run() {
processSessionEvent(event);
}
}, VIEW_UPDATE_DELAY);
}
protected abstract void processSessionEvent(@NotNull SessionEvent event);
@Nullable
protected static XDebugSession getSession(@NotNull EventObject e) {
@@ -36,7 +36,7 @@ public class XDebugViewSessionListener extends XDebugSessionAdapter {
AppUIUtil.invokeLaterIfProjectAlive(session.getProject(), new Runnable() {
@Override
public void run() {
myDebugView.processSessionEvent(event);
myDebugView.onSessionEvent(event);
}
});
}
@@ -221,13 +221,11 @@ public class XFramesView extends XDebugView {
mySelectedStack = null;
XSuspendContext suspendContext = session == null ? null : session.getSuspendContext();
if (suspendContext == null) {
requestClear();
clear();
return;
}
if (event == SessionEvent.PAUSED) {
// clear immediately
cancelClear();
clear();
}
@@ -57,11 +57,10 @@ public class XVariablesView extends XVariablesViewBase {
tree.markNodesObsolete();
if (stackFrame != null) {
cancelClear();
buildTreeAndRestoreState(stackFrame);
}
else {
requestClear();
clear();
}
}
@@ -275,7 +275,6 @@ public class XWatchesViewImpl extends XDebugView implements DnDNativeTarget, XWa
XDebugSession session = getSession(getMainPanel());
XStackFrame stackFrame = session == null ? null : session.getCurrentStackFrame();
if (stackFrame != null) {
cancelClear();
tree.setSourcePosition(stackFrame.getSourcePosition());
myRootNode.updateWatches(stackFrame.getEvaluator());
if (myTreeState != null) {
@@ -283,7 +282,7 @@ public class XWatchesViewImpl extends XDebugView implements DnDNativeTarget, XWa
}
}
else {
requestClear();
clear();
}
}
@@ -198,7 +198,7 @@ public class XDebugSessionTab extends DebuggerSessionTabBase {
@Override
public void run() {
for (XDebugView view : myViews) {
view.processSessionEvent(XDebugView.SessionEvent.SETTINGS_CHANGED);
view.onSessionEvent(XDebugView.SessionEvent.SETTINGS_CHANGED);
}
}
});