Skip to content

Commit

Permalink
#32989: Merged main into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
janssen-tiobe committed Nov 30, 2023
2 parents 0675dac + 4318fb3 commit b8e2f2a
Show file tree
Hide file tree
Showing 4 changed files with 24 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
}
}

0 comments on commit b8e2f2a

Please sign in to comment.