From 443204183c9b15d3337b8893b5fdabb8a231231c Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 15 Oct 2019 12:33:17 +0200 Subject: [PATCH] SSR: don't change result scope when changing scopes from context (IDEA-219700) GitOrigin-RevId: 6d5f1a739160d84aafac3c53fd7326e026246753 --- .../plugin/ui/ScopePanel.java | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ScopePanel.java b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ScopePanel.java index dc524c96fa00..6815fa54110d 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ScopePanel.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/ScopePanel.java @@ -52,6 +52,7 @@ public class ScopePanel extends JPanel { @NotNull private SearchScope myScope; private NullableConsumer myConsumer; Scopes.Type myScopeType; + private boolean myUpdating = false; final ActionToolbarImpl myToolbar; final JPanel myScopeDetailsPanel = new JPanel(new CardLayout()); @@ -153,35 +154,40 @@ public class ScopePanel extends JPanel { public void setScopesFromContext() { DataManager.getInstance().getDataContextFromFocusAsync().onSuccess(context -> { - final Module module = LangDataKeys.MODULE.getData(context); - if (module != null) { - myModulesComboBox.setSelectedModule(module); - } - final Editor editor = CommonDataKeys.HOST_EDITOR.getData(context); - if (editor != null) { - final Document document = editor.getDocument(); - final VirtualFile file = FileDocumentManager.getInstance().getFile(document); - if (file != null) { - myDirectoryComboBox.setDirectory(file.getParent()); + myUpdating = true; + try { + final Module module = LangDataKeys.MODULE.getData(context); + if (module != null) { + myModulesComboBox.setSelectedModule(module); } - myScopesComboBox.selectItem(IdeBundle.message("scope.current.file")); - } - else { - final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context); - if (files != null && files.length > 0) { - boolean found = false; - for (VirtualFile file : files) { - if (file.isDirectory()) { - myDirectoryComboBox.setDirectory(file); - found = true; - break; + final Editor editor = CommonDataKeys.HOST_EDITOR.getData(context); + if (editor != null) { + final Document document = editor.getDocument(); + final VirtualFile file = FileDocumentManager.getInstance().getFile(document); + if (file != null) { + myDirectoryComboBox.setDirectory(file.getParent()); + } + myScopesComboBox.selectItem(IdeBundle.message("scope.current.file")); + } + else { + final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context); + if (files != null && files.length > 0) { + boolean found = false; + for (VirtualFile file : files) { + if (file.isDirectory()) { + myDirectoryComboBox.setDirectory(file); + found = true; + break; + } + } + if (!found) { + myScopesComboBox.selectItem("Selected Files"); // this scope name is not available in a properties file + myDirectoryComboBox.setDirectory(files[0].getParent()); } } - if (!found) { - myScopesComboBox.selectItem("Selected Files"); // this scope name is not available in a properties file - myDirectoryComboBox.setDirectory(files[0].getParent()); - } } + } finally { + myUpdating = false; } }); } @@ -196,6 +202,7 @@ public class ScopePanel extends JPanel { } void setScopeFromUI(@NotNull Scopes.Type type, boolean requestFocus) { + if (myUpdating) return; switch (type) { case PROJECT: myScope = GlobalSearchScope.projectScope(myProject);