Showing KotlinBukkitAPI tab in Kotlin Files only if KotlinBukkitAPI is available at the Module
This commit is contained in:
1 parent
a43f27923e
commit
fd2b51cc85
1 file changed
+22
-8
+22
-8
@@ -3,7 +3,9 @@ package br.com.devsrsouza.kotlinbukkitapi.tooling.menu
|
|||||||
import br.com.devsrsouza.kotlinbukkitapi.tooling.bukkript.BukkriptFileType
|
import br.com.devsrsouza.kotlinbukkitapi.tooling.bukkript.BukkriptFileType
|
||||||
import com.intellij.openapi.fileEditor.*
|
import com.intellij.openapi.fileEditor.*
|
||||||
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
|
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
|
||||||
|
import com.intellij.openapi.module.ModuleUtilCore
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.roots.ModuleRootManager
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||||
|
|
||||||
@@ -13,23 +15,35 @@ class MenuPreviewFileEditorProvider : WeighedFileEditorProvider() {
|
|||||||
const val ID = "kotlinbukkitapi-menu-preview"
|
const val ID = "kotlinbukkitapi-menu-preview"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getEditorTypeId(): String =
|
override fun getEditorTypeId(): String = ID
|
||||||
ID
|
|
||||||
|
|
||||||
override fun accept(project: Project, file: VirtualFile): Boolean {
|
override fun accept(project: Project, file: VirtualFile): Boolean {
|
||||||
|
|
||||||
val type = file.fileType
|
val type = file.fileType
|
||||||
|
|
||||||
if(type != KotlinFileType.INSTANCE && type != BukkriptFileType.INSTANCE) return false
|
if(type == BukkriptFileType.INSTANCE) return true
|
||||||
|
|
||||||
return true
|
if(type != KotlinFileType.INSTANCE) return false
|
||||||
// return PsiManager.getInstance(project).findFile(file)?.findDescendantOfType<KtCallExpression> {
|
|
||||||
// findMenuDeclaration(it) != null
|
val module = ModuleUtilCore.findModuleForFile(file, project) ?: return false
|
||||||
// } != null
|
|
||||||
|
val root = ModuleRootManager.getInstance(module)
|
||||||
|
var hasKotlinBukkitAPI = false
|
||||||
|
|
||||||
|
root.orderEntries().withoutSdk().forEachLibrary {
|
||||||
|
if((it.name ?: "").contains("kotlinbukkitapi", true)) {
|
||||||
|
hasKotlinBukkitAPI = true
|
||||||
|
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasKotlinBukkitAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createEditor(project: Project, file: VirtualFile): FileEditor {
|
override fun createEditor(project: Project, file: VirtualFile): FileEditor {
|
||||||
println(file.canonicalPath)
|
|
||||||
val editor: TextEditor = TextEditorProvider.getInstance().createEditor(project, file) as TextEditor
|
val editor: TextEditor = TextEditorProvider.getInstance().createEditor(project, file) as TextEditor
|
||||||
val preview =
|
val preview =
|
||||||
MenuPreviewFileEditor(project, file, editor)
|
MenuPreviewFileEditor(project, file, editor)
|
||||||
|
|||||||
Reference in new issue
Block a user