mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Provide kotlin source types aware create package action
#KTIJ-12018 Fixed GitOrigin-RevId: 7013d9679eea45ec7af678ce8d91e1608239997e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c38631ccd7
commit
50fbbc61fd
+12
-9
@@ -84,7 +84,7 @@ public class CreateDirectoryOrPackageAction extends AnAction implements DumbAwar
|
||||
final CreateGroupHandler validator;
|
||||
final String message, title;
|
||||
|
||||
if (PsiDirectoryFactory.getInstance(project).isPackage(directory)) {
|
||||
if (isPackage(project, Collections.singletonList(directory))) {
|
||||
validator = new CreatePackageHandler(project, directory);
|
||||
message = IdeBundle.message("prompt.enter.new.package.name");
|
||||
title = IdeBundle.message("title.new.package");
|
||||
@@ -146,14 +146,7 @@ public class CreateDirectoryOrPackageAction extends AnAction implements DumbAwar
|
||||
|
||||
presentation.setEnabledAndVisible(true);
|
||||
|
||||
boolean isPackage = false;
|
||||
final PsiDirectoryFactory factory = PsiDirectoryFactory.getInstance(project);
|
||||
for (PsiDirectory directory : directories) {
|
||||
if (factory.isPackage(directory)) {
|
||||
isPackage = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
boolean isPackage = isPackage(project, directories);
|
||||
|
||||
if (isPackage) {
|
||||
presentation.setText(IdeBundle.messagePointer("action.package"));
|
||||
@@ -165,6 +158,16 @@ public class CreateDirectoryOrPackageAction extends AnAction implements DumbAwar
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isPackage(@NotNull Project project, @NotNull List<@NotNull PsiDirectory> directories) {
|
||||
final PsiDirectoryFactory factory = PsiDirectoryFactory.getInstance(project);
|
||||
for (PsiDirectory directory : directories) {
|
||||
if (factory.isPackage(directory)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private JBPopup createLightWeightPopup(@Nullable Project project,
|
||||
@NlsContexts.PopupTitle String title,
|
||||
String initialText,
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.actions
|
||||
|
||||
import com.intellij.ide.actions.CreateDirectoryOrPackageAction
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.ProjectRootManager
|
||||
import com.intellij.psi.PsiDirectory
|
||||
import org.jetbrains.kotlin.idea.base.util.KOTLIN_AWARE_SOURCE_ROOT_TYPES
|
||||
|
||||
class CreateKotlinAwareDirectoryOrPackageAction: CreateDirectoryOrPackageAction() {
|
||||
override fun isPackage(project: Project, directories: List<PsiDirectory>): Boolean {
|
||||
val fileIndex = ProjectRootManager.getInstance(project).getFileIndex()
|
||||
return directories.any {
|
||||
val virtualFile = it.getVirtualFile()
|
||||
fileIndex.isUnderSourceRootOfType(virtualFile, KOTLIN_AWARE_SOURCE_ROOT_TYPES)
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.actions
|
||||
|
||||
import com.intellij.openapi.actionSystem.ex.ActionRuntimeRegistrar
|
||||
import com.intellij.openapi.actionSystem.impl.ActionConfigurationCustomizer
|
||||
|
||||
private const val NEW_DIR: String = "NewDir"
|
||||
|
||||
class KotlinActionsManager: ActionConfigurationCustomizer, ActionConfigurationCustomizer.LightCustomizeStrategy {
|
||||
override suspend fun customize(actionRegistrar: ActionRuntimeRegistrar) {
|
||||
actionRegistrar.replaceAction(NEW_DIR, CreateKotlinAwareDirectoryOrPackageAction())
|
||||
}
|
||||
}
|
||||
@@ -509,6 +509,7 @@
|
||||
|
||||
<!-- Declaration search and Find Usages -->
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<actionConfigurationCustomizer implementation="org.jetbrains.kotlin.idea.actions.KotlinActionsManager"/>
|
||||
<searchEverywhereResultsEqualityProvider implementation="org.jetbrains.kotlin.idea.searcheverywhere.KtSearchEverywhereEqualityProvider"/>
|
||||
<referencesSearch implementation="org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearcher"/>
|
||||
<referencesSearch implementation="org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinAliasedImportedElementSearcher"/>
|
||||
|
||||
Reference in New Issue
Block a user