From ee8c492f7a2e76e559777fd5fb02a153c532d097 Mon Sep 17 00:00:00 2001 From: janssen <118828444+janssen-tiobe@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:41:43 +0200 Subject: [PATCH] #32999: Changed analysis behaviour 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. --- .../plugins/intellij/actions/AnalyzeAction.kt | 16 ++- .../plugins/intellij/actions/AnalyzeFile.kt | 4 + .../intellij/actions/AnalyzeFileOrFolder.kt | 4 + .../intellij/actions/AnalyzeProject.kt | 4 + src/main/resources/icons/filter-outline.png | Bin 346 -> 0 bytes src/main/resources/icons/filter.png | Bin 268 -> 0 bytes .../icons/tics-config-solid_dark.svg | 103 +++++++++++++++ .../resources/icons/tics-file-solid_dark.svg | 121 ++++++++++++++++++ 8 files changed, 248 insertions(+), 4 deletions(-) delete mode 100644 src/main/resources/icons/filter-outline.png delete mode 100644 src/main/resources/icons/filter.png create mode 100644 src/main/resources/icons/tics-config-solid_dark.svg create mode 100644 src/main/resources/icons/tics-file-solid_dark.svg diff --git a/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeAction.kt b/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeAction.kt index 3c5c07e..8c1695f 100644 --- a/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeAction.kt +++ b/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeAction.kt @@ -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 @@ -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 } \ No newline at end of file diff --git a/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeFile.kt b/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeFile.kt index 079709a..9878db2 100644 --- a/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeFile.kt +++ b/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeFile.kt @@ -23,4 +23,8 @@ open class AnalyzeFile : AnalyzeAction() { override fun isFileRequired(): Boolean { return true } + + override fun analyzeFileOpenedInEditor(): Boolean { + return true + } } diff --git a/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeFileOrFolder.kt b/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeFileOrFolder.kt index 2623d2d..45f3ffb 100644 --- a/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeFileOrFolder.kt +++ b/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeFileOrFolder.kt @@ -18,4 +18,8 @@ class AnalyzeFileOrFolder : AnalyzeFile() { super.update(e) } + + override fun analyzeFileOpenedInEditor(): Boolean { + return false + } } \ No newline at end of file diff --git a/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeProject.kt b/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeProject.kt index d084f07..6d978f7 100644 --- a/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeProject.kt +++ b/src/main/kotlin/com/tiobe/plugins/intellij/actions/AnalyzeProject.kt @@ -24,4 +24,8 @@ class AnalyzeProject : AnalyzeAction() { override fun isFileRequired(): Boolean { return false } + + override fun analyzeFileOpenedInEditor(): Boolean { + return false + } } \ No newline at end of file diff --git a/src/main/resources/icons/filter-outline.png b/src/main/resources/icons/filter-outline.png deleted file mode 100644 index 9c686727ba94b985a80e6f2be653b3229df31139..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 346 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ z@c4l+V|{s#GEh*m#5JNMI6tkVJh3R1p}f3YFEcN@I61K(RWH9NefB#WDWIb3o-U3d z7QI_9?e%hY6kvUDUO}r#K_!;y+sc~8EtRZmb#vbY{}g$7#At$pf-l!Wt_DRE#C31%MYyJ% meZVGb6S{JqyYSwSN9^-TwHW5y43Y(Uk-^i|&t;ucLK6VlMusl{ diff --git a/src/main/resources/icons/filter.png b/src/main/resources/icons/filter.png deleted file mode 100644 index 04b56e915f025bc23735e815298cf8267916ccc0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 268 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ z@c4l+V|{s#GEh*m#5JNMI6tkVJh3R1p}f3YFEcN@I61K(RWH9NefB#WDWIZGPZ!4! zi{7^v_wpVx5OICj&v8*PmE{>na)1#_kHbXCjGIk;X3`AC0gkO13MLU=6YWpyh8I08 z?_2*>ZH21JVb#X{hh&b&Po7ciB + + + diff --git a/src/main/resources/icons/tics-file-solid_dark.svg b/src/main/resources/icons/tics-file-solid_dark.svg new file mode 100644 index 0000000..bf44957 --- /dev/null +++ b/src/main/resources/icons/tics-file-solid_dark.svg @@ -0,0 +1,121 @@ + + + +