Skip to content

Commit

Permalink
#32999: Changed analysis behaviour
Browse files Browse the repository at this point in the history
Analysis used to run according to context, which meant that having the explorer in focus meant the selected file would be analyzed instead of the file opened in the editor. The behaviour has now changed to analyzing the file opened in the editor unless triggered by right clicking the file in the explorer.
  • Loading branch information
janssen-tiobe committed Oct 10, 2023
1 parent 79257ad commit ee8c492
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ abstract class AnalyzeAction : AbstractAction() {
}

private fun analyze(context: DataContext, project: Project) {
// try to get the file/folder from context, otherwise check if they can be retrieved from the opened editor
val file: VirtualFile? = PlatformDataKeys.VIRTUAL_FILE.getData(context).let {
it ?: project.let { it1 ->
FileEditorManager.getInstance(it1).selectedEditor?.file
// If analyzeFileOpenedInEditor is true, use the file opened in the editor. Else it will try to
// get the file/folder from context, otherwise check if they can be retrieved from the opened editor.
val file: VirtualFile? = analyzeFileOpenedInEditor().let {
if (it) {
FileEditorManager.getInstance(project).selectedEditor?.file
} else {
PlatformDataKeys.VIRTUAL_FILE.getData(context).let {virtualFile ->
virtualFile ?: FileEditorManager.getInstance(project).selectedEditor?.file
}
}
}

if (isFileRequired() && file == null) {
showErrorMessageDialog(
ErrorMessages.NO_ACTIVE_FILE
Expand Down Expand Up @@ -88,4 +94,6 @@ abstract class AnalyzeAction : AbstractAction() {
protected abstract fun getTicsCommand(file: VirtualFile?, project: Project?): GeneralCommandLine

protected abstract fun isFileRequired(): Boolean

protected abstract fun analyzeFileOpenedInEditor(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ open class AnalyzeFile : AnalyzeAction() {
override fun isFileRequired(): Boolean {
return true
}

override fun analyzeFileOpenedInEditor(): Boolean {
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ class AnalyzeFileOrFolder : AnalyzeFile() {

super.update(e)
}

override fun analyzeFileOpenedInEditor(): Boolean {
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ class AnalyzeProject : AnalyzeAction() {
override fun isFileRequired(): Boolean {
return false
}

override fun analyzeFileOpenedInEditor(): Boolean {
return false
}
}
Binary file removed src/main/resources/icons/filter-outline.png
Binary file not shown.
Binary file removed src/main/resources/icons/filter.png
Binary file not shown.
103 changes: 103 additions & 0 deletions src/main/resources/icons/tics-config-solid_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
121 changes: 121 additions & 0 deletions src/main/resources/icons/tics-file-solid_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ee8c492

Please sign in to comment.