mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
[floating toolbar] IDEA-321869: disable dropdowns if all actions inside are disabled & fix update for extract actions
GitOrigin-RevId: 8638764b987a426a59d631c8c75064775f99956c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
813d8b8ea9
commit
cff5aa9459
@@ -20,6 +20,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -36,8 +37,18 @@ public abstract class IntroduceHandlerBase implements RefactoringActionHandler,
|
||||
public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
|
||||
final PsiElement[] elements = ExtractMethodHandler.getElements(file.getProject(), editor, file);
|
||||
if (elements != null && elements.length > 0) return true;
|
||||
return acceptLocalVariable() &&
|
||||
PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PsiLocalVariable.class) != null;
|
||||
return acceptLocalVariable() && findLocalVariable(editor, file) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiLocalVariable findLocalVariable(@NotNull Editor editor, @NotNull PsiFile file) {
|
||||
SelectionModel selection = editor.getSelectionModel();
|
||||
if (selection.hasSelection()) {
|
||||
return PsiTreeUtil.findElementOfClassAtRange(file, selection.getSelectionStart(), selection.getSelectionEnd(), PsiLocalVariable.class);
|
||||
}
|
||||
else {
|
||||
return PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PsiLocalVariable.class);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean acceptLocalVariable() {
|
||||
|
||||
@@ -51,7 +51,7 @@ public abstract class BaseRefactoringAction extends AnAction {
|
||||
@NotNull PsiFile file,
|
||||
@NotNull DataContext context,
|
||||
@NotNull String place) {
|
||||
if (ActionPlaces.isPopupPlace(place)) {
|
||||
if (ActionPlaces.isPopupPlace(place) || place.contains(ActionPlaces.EDITOR_FLOATING_TOOLBAR)) {
|
||||
final RefactoringActionHandler handler = getHandler(context);
|
||||
if (handler == null) return false;
|
||||
if (handler instanceof ContextAwareActionHandler contextAwareActionHandler) {
|
||||
|
||||
@@ -21,4 +21,13 @@ class DropdownActionGroup: DefaultActionGroup(), CustomComponentAction {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun update(e: AnActionEvent) {
|
||||
val activeActions = ActionGroupUtil.getActiveActions(this, e)
|
||||
e.presentation.isEnabled = activeActions.isNotEmpty
|
||||
}
|
||||
|
||||
override fun getActionUpdateThread(): ActionUpdateThread {
|
||||
return ActionUpdateThread.BGT
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user