From 8ea1caf8b82c0021e5787ad63c6e7d0372935ce9 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 12 Sep 2016 12:47:34 +0300 Subject: [PATCH] ignore rulesChanged event for hidden usage view tabs to fix IDEA-140429 10s hang on changing groupping in show usages --- .../intellij/usages/impl/UsageViewImpl.java | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java index 537f40e33475..7f7f1ca3facf 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java @@ -248,6 +248,16 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra }); } }); + + myTree.addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + if (rulesChanged) { + rulesChanged = false; + rulesChanged(); + } + } + }); } }); } @@ -292,12 +302,12 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra }; } - protected boolean searchHasBeenCancelled() { + boolean searchHasBeenCancelled() { ProgressIndicator progress = associatedProgress; return progress != null && progress.isCanceled(); } - protected void cancelCurrentSearch() { + void cancelCurrentSearch() { ProgressIndicator progress = associatedProgress; if (progress != null) { ProgressWrapper.unwrap(progress).cancel(); @@ -704,8 +714,18 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra return list.toArray(new AnAction[list.size()]); } + private boolean shouldTreeReactNowToRuleChanges() { + return myPresentation.isDetachedMode() || myTree.isShowing(); + } + + private boolean rulesChanged; private void rulesChanged() { ApplicationManager.getApplication().assertIsDispatchThread(); + if (!shouldTreeReactNowToRuleChanges()) { + rulesChanged = true; + return; + } + final List states = new ArrayList<>(); captureUsagesExpandState(new TreePath(myTree.getModel().getRoot()), states); final List allUsages = new ArrayList<>(myUsageNodes.keySet()); @@ -786,7 +806,7 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra TreeUtil.expand(myTree, 2); } - public DefaultMutableTreeNode getModelRoot() { + DefaultMutableTreeNode getModelRoot() { return (DefaultMutableTreeNode)myTree.getModel().getRoot(); } @@ -910,12 +930,7 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra private final TransferToEDTQueue myTransferToEDTQueue; void drainQueuedUsageNodes() { assert !ApplicationManager.getApplication().isDispatchThread() : Thread.currentThread(); - UIUtil.invokeAndWaitIfNeeded(new Runnable() { - @Override - public void run() { - myTransferToEDTQueue.drain(); - } - }); + UIUtil.invokeAndWaitIfNeeded((Runnable)myTransferToEDTQueue::drain); } private final Consumer edtQueue = new Consumer() { @Override @@ -1233,9 +1248,10 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra addButtonToLowerPane(newPerformOperationRunnable(processRunnable, commandName, cannotMakeString, checkReadOnlyStatus), shortDescription); } - public MyPerformOperationRunnable newPerformOperationRunnable(Runnable processRunnable, - String commandName, - String cannotMakeString, boolean checkReadOnlyStatus) { + @NotNull + private MyPerformOperationRunnable newPerformOperationRunnable(Runnable processRunnable, + String commandName, + String cannotMakeString, boolean checkReadOnlyStatus) { return new MyPerformOperationRunnable(cannotMakeString, processRunnable, commandName, checkReadOnlyStatus); } @@ -1443,7 +1459,7 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra return result.toArray(new Navigatable[result.size()]); } - public boolean areTargetsValid() { + boolean areTargetsValid() { return myModel.areTargetsValid(); }