@@ -43,13 +43,12 @@ public void actionPerformed(final @NotNull AnActionEvent event) {
4343 final ToolWindow toolWindow = toolWindow (project );
4444 toolWindow .activate (() -> {
4545 try {
46+ final VirtualFile selectedFile = selectedFile (project , event );
47+
4648 setProgressText (toolWindow , "plugin.status.in-progress.current" );
4749
4850 final ConfigurationLocation overrideIfExists = getSelectedOverride (toolWindow );
49- final VirtualFile selectedFile = getSelectedValidFile (
50- project ,
51- overrideIfExists );
52- if (selectedFile != null ) {
51+ if (validForScanning (selectedFile , project , overrideIfExists )) {
5352 staticScanner (project ).asyncScanFiles (
5453 singletonList (selectedFile ),
5554 overrideIfExists );
@@ -68,32 +67,30 @@ public void actionPerformed(final @NotNull AnActionEvent event) {
6867 });
6968 }
7069
71- @ Nullable
72- private VirtualFile getSelectedValidFile (
73- final Project project ,
74- final @ Nullable ConfigurationLocation overrideIfExists ) {
75- final VirtualFile selectedFile = getSelectedFile (project );
70+ protected @ Nullable VirtualFile selectedFile (@ NotNull final Project project ,
71+ @ NotNull final AnActionEvent event ) {
72+ return getSelectedFile (project );
73+ }
74+
75+ protected boolean validForScanning (final VirtualFile selectedFile ,
76+ final @ NotNull Project project ,
77+ final @ Nullable ConfigurationLocation overrideIfExists ) {
7678 if (selectedFile == null ) {
77- return null ;
79+ return false ;
7880 }
7981
8082 final PluginConfiguration pluginConfiguration = configurationManager (project ).getCurrent ();
8183 if (!isFileValidAgainstScanScope (project , pluginConfiguration , selectedFile )) {
82- return null ;
84+ return false ;
8385 }
8486
8587 final List <NamedScope > namedScopes = getNamedScopesToCheck (pluginConfiguration , overrideIfExists );
8688 if (!namedScopes .isEmpty () && namedScopes .stream ().map (NamedScope ::getValue ).allMatch (Objects ::isNull )) {
87- return selectedFile ;
89+ return true ;
8890 }
8991
90- final boolean isFileInScope = namedScopes .stream ()
92+ return namedScopes .stream ()
9193 .anyMatch ((NamedScope namedScope ) -> NamedScopeHelper .isFileInScope (psiFileFor (project , selectedFile ), namedScope ));
92- if (isFileInScope ) {
93- return selectedFile ;
94- }
95-
96- return null ;
9794 }
9895
9996 @ NotNull
@@ -171,7 +168,9 @@ public void update(final @NotNull AnActionEvent event) {
171168 final Presentation presentation = event .getPresentation ();
172169
173170 project (event ).ifPresentOrElse (project -> {
174- if (getSelectedFile (project ) != null ) {
171+ final VirtualFile selectedFile = selectedFile (project , event );
172+ final ConfigurationLocation overrideIfExists = getSelectedOverride (toolWindow (project ));
173+ if (selectedFile != null && validForScanning (selectedFile , project , overrideIfExists )) {
175174 presentation .setEnabled (!staticScanner (project ).isScanInProgress ());
176175 } else {
177176 presentation .setEnabled (false );
0 commit comments