mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
focus manager: flushing count is modal-aware
This commit is contained in:
@@ -52,7 +52,6 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
private final ArrayList<FocusCommand> myFocusRequests = new ArrayList<FocusCommand>();
|
||||
|
||||
private final ArrayList<KeyEvent> myToDispatchOnDone = new ArrayList<KeyEvent>();
|
||||
private int myFlushingIdleRequestsEntryCount = 0;
|
||||
|
||||
private WeakReference<FocusCommand> myLastForcedRequest = new WeakReference<FocusCommand>(null);
|
||||
|
||||
@@ -91,6 +90,9 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
|
||||
private DataContext myRunContext;
|
||||
|
||||
private Map<Integer, Integer> myModalityCount2FlushCount = new HashMap<Integer, Integer>();
|
||||
private Integer myCurrentModalityCount;
|
||||
|
||||
public FocusManagerImpl(WindowManager wm) {
|
||||
myApp = ApplicationManager.getApplication();
|
||||
myQueue = IdeEventQueue.getInstance();
|
||||
@@ -114,13 +116,17 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
myLastFocused.put((IdeFrame)parent, new WeakReference<Component>(c));
|
||||
}
|
||||
} else if (e instanceof WindowEvent) {
|
||||
Window wnd = ((WindowEvent)e).getWindow();
|
||||
if (e.getID() == WindowEvent.WINDOW_CLOSED) {
|
||||
Window wnd = ((WindowEvent)e).getWindow();
|
||||
if (wnd instanceof IdeFrame) {
|
||||
myLastFocused.remove((IdeFrame)wnd);
|
||||
myLastFocusedAtDeactivation.remove((IdeFrame)wnd);
|
||||
}
|
||||
}
|
||||
|
||||
if (wnd instanceof Dialog) {
|
||||
myCurrentModalityCount = null;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -379,7 +385,7 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
|
||||
private void flushIdleRequests() {
|
||||
try {
|
||||
myFlushingIdleRequestsEntryCount++;
|
||||
incFlushingRequests(1);
|
||||
|
||||
final KeyEvent[] events = myToDispatchOnDone.toArray(new KeyEvent[myToDispatchOnDone.size()]);
|
||||
if (events.length > 0) {
|
||||
@@ -427,14 +433,14 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
myFlushWasDelayedToFixFocus = true;
|
||||
}
|
||||
|
||||
if (canFlushIdleRequests() && myFlushingIdleRequestsEntryCount <= 1 && (focusOk || !myFlushWasDelayedToFixFocus)) {
|
||||
if (canFlushIdleRequests() && getFlushingIdleRequests() <= 1 && (focusOk || !myFlushWasDelayedToFixFocus)) {
|
||||
myFlushWasDelayedToFixFocus = false;
|
||||
flushNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
myFlushingIdleRequestsEntryCount--;
|
||||
incFlushingRequests(-1);
|
||||
if (!isIdleQueueEmpty()) {
|
||||
restartIdleAlarm();
|
||||
}
|
||||
@@ -514,7 +520,51 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
}
|
||||
|
||||
private boolean isFlushingIdleRequests() {
|
||||
return myFlushingIdleRequestsEntryCount > 0;
|
||||
return getFlushingIdleRequests() > 0;
|
||||
}
|
||||
|
||||
private int getFlushingIdleRequests() {
|
||||
int currentModalityCount = getCurrentModalityCount();
|
||||
if (myModalityCount2FlushCount.containsKey(currentModalityCount)) {
|
||||
return myModalityCount2FlushCount.get(currentModalityCount);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void incFlushingRequests(int delta) {
|
||||
int currentModalityCount = getCurrentModalityCount();
|
||||
if (myModalityCount2FlushCount.containsKey(currentModalityCount)) {
|
||||
Integer requests = myModalityCount2FlushCount.get(currentModalityCount);
|
||||
myModalityCount2FlushCount.put(currentModalityCount, requests + delta);
|
||||
} else {
|
||||
myModalityCount2FlushCount.put(currentModalityCount, Integer.valueOf(delta));
|
||||
}
|
||||
}
|
||||
|
||||
private int getCurrentModalityCount() {
|
||||
if (myCurrentModalityCount == null) {
|
||||
int modalDialogs = 0;
|
||||
Window[] windows = Frame.getWindows();
|
||||
for (Window each : windows) {
|
||||
if (each instanceof Dialog) {
|
||||
Dialog eachDialog = (Dialog)each;
|
||||
if (eachDialog.isModal() && eachDialog.isShowing()) {
|
||||
modalDialogs++;
|
||||
}
|
||||
}
|
||||
}
|
||||
myCurrentModalityCount = modalDialogs;
|
||||
Iterator<Integer> modalityCounts = myModalityCount2FlushCount.keySet().iterator();
|
||||
while (modalityCounts.hasNext()) {
|
||||
Integer eachModalityCount = modalityCounts.next();
|
||||
if (eachModalityCount > myCurrentModalityCount) {
|
||||
modalityCounts.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return myCurrentModalityCount;
|
||||
}
|
||||
|
||||
public void suspendKeyProcessingUntil(@NotNull final ActionCallback done) {
|
||||
|
||||
Reference in New Issue
Block a user