Don't show file root if it's same as the only declaration (KT-21200)
#KT-21200 Fixed
This commit is contained in:
@@ -50,6 +50,8 @@ class KotlinIconProvider : IconProvider(), DumbAware {
|
|||||||
companion object {
|
companion object {
|
||||||
var INSTANCE = KotlinIconProvider()
|
var INSTANCE = KotlinIconProvider()
|
||||||
|
|
||||||
|
fun isSingleClassFile(file: KtFile) = getSingleClass(file) != null
|
||||||
|
|
||||||
fun getSingleClass(file: KtFile): KtClassOrObject? {
|
fun getSingleClass(file: KtFile): KtClassOrObject? {
|
||||||
val mainClass = getMainClass(file)
|
val mainClass = getMainClass(file)
|
||||||
return if (mainClass != null && file.declarations.size == 1) mainClass else null
|
return if (mainClass != null && file.declarations.size == 1) mainClass else null
|
||||||
|
|||||||
+6
@@ -24,6 +24,7 @@ import com.intellij.openapi.editor.Editor;
|
|||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.idea.KotlinIconProvider;
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
import org.jetbrains.kotlin.psi.KtFile;
|
||||||
|
|
||||||
public class KotlinStructureViewFactory implements PsiStructureViewFactory {
|
public class KotlinStructureViewFactory implements PsiStructureViewFactory {
|
||||||
@@ -40,6 +41,11 @@ public class KotlinStructureViewFactory implements PsiStructureViewFactory {
|
|||||||
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
|
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
|
||||||
return new KotlinStructureViewModel(file, editor);
|
return new KotlinStructureViewModel(file, editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRootNodeShown() {
|
||||||
|
return !KotlinIconProvider.Companion.isSingleClassFile(file);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user