diff --git a/images/src/org/intellij/images/actions/ShowThumbnailsAction.java b/images/src/org/intellij/images/actions/ShowThumbnailsAction.java index 8c8edac7ceaf..53bd8d656977 100644 --- a/images/src/org/intellij/images/actions/ShowThumbnailsAction.java +++ b/images/src/org/intellij/images/actions/ShowThumbnailsAction.java @@ -19,7 +19,6 @@ import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.intellij.images.thumbnail.ThumbnailManager; @@ -44,14 +43,13 @@ public final class ShowThumbnailsAction extends AnAction { } public void update(AnActionEvent e) { - super.update(e); VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE); - final boolean isEnabled = file != null && file.isDirectory(); - if (e.getPlace().equals(ActionPlaces.PROJECT_VIEW_POPUP)) { - e.getPresentation().setVisible(isEnabled); + boolean enabled = file != null && file.isDirectory(); + if (ActionPlaces.isPopupPlace(e.getPlace())) { + e.getPresentation().setEnabledAndVisible(enabled); } else { - e.getPresentation().setEnabled(isEnabled); + e.getPresentation().setEnabled(enabled); } } } diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryGroup.java b/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryGroup.java index 042b3162a60b..93d01d8e7ae2 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryGroup.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryGroup.java @@ -17,17 +17,27 @@ package com.intellij.history.integration.ui.actions; import com.intellij.ide.actions.NonTrivialActionGroup; +import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiElement; public class LocalHistoryGroup extends NonTrivialActionGroup implements DumbAware { - public void update(AnActionEvent event) { - if (event.getData(CommonDataKeys.PROJECT) == null) { - event.getPresentation().setEnabledAndVisible(false); + + public void update(AnActionEvent e) { + Project project = e.getProject(); + VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE); + PsiElement element = e.getData(CommonDataKeys.PSI_ELEMENT); + if (project == null || + ActionPlaces.isPopupPlace(e.getPlace()) && ( + file != null && !file.isInLocalFileSystem() || file == null && element != null)) { + e.getPresentation().setEnabledAndVisible(false); } else { - super.update(event); + super.update(e); } } } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/DeleteAction.java b/platform/platform-impl/src/com/intellij/ide/actions/DeleteAction.java index 4564c0b5b902..4669c1b93132 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/DeleteAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/DeleteAction.java @@ -60,7 +60,7 @@ public class DeleteAction extends AnAction implements DumbAware { public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); - if (ActionPlaces.PROJECT_VIEW_POPUP.equals(e.getPlace()) || ActionPlaces.COMMANDER_POPUP.equals(e.getPlace())) { + if (ActionPlaces.isPopupPlace(e.getPlace())) { presentation.setText(IdeBundle.message("action.delete.ellipsis")); } else { diff --git a/platform/vcs-impl/src/com/intellij/ide/actions/SynchronizeCurrentFileAction.java b/platform/vcs-impl/src/com/intellij/ide/actions/SynchronizeCurrentFileAction.java index 47b38d6dc86b..f470a44990ea 100644 --- a/platform/vcs-impl/src/com/intellij/ide/actions/SynchronizeCurrentFileAction.java +++ b/platform/vcs-impl/src/com/intellij/ide/actions/SynchronizeCurrentFileAction.java @@ -27,7 +27,10 @@ import com.intellij.openapi.vfs.newvfs.NewVirtualFile; import com.intellij.openapi.vfs.newvfs.RefreshQueue; import com.intellij.openapi.wm.StatusBar; import com.intellij.openapi.wm.WindowManager; -import org.jetbrains.annotations.Nullable; +import com.intellij.util.containers.JBIterable; +import org.jetbrains.annotations.NotNull; + +import java.util.List; import static com.intellij.openapi.util.text.StringUtil.escapeMnemonics; import static com.intellij.openapi.util.text.StringUtil.firstLast; @@ -35,26 +38,29 @@ import static com.intellij.openapi.util.text.StringUtil.firstLast; public class SynchronizeCurrentFileAction extends AnAction implements DumbAware { @Override public void update(AnActionEvent e) { - VirtualFile[] files = getFiles(e); - - if (getEventProject(e) == null || files == null || files.length == 0) { + List files = getFiles(e).take(2).toList(); + if (e.getProject() == null || files.isEmpty()) { e.getPresentation().setEnabledAndVisible(false); - return; } - e.getPresentation().setEnabledAndVisible(true); - e.getPresentation().setText(getMessage(files)); + else { + e.getPresentation().setEnabledAndVisible(true); + e.getPresentation().setText(getMessage(files)); + } } - private static String getMessage(VirtualFile[] files) { - return files.length == 1 ? IdeBundle.message("action.synchronize.file", escapeMnemonics(firstLast(files[0].getName(), 20))) - : IdeBundle.message("action.synchronize.selected.files"); + @NotNull + private static String getMessage(@NotNull List files) { + VirtualFile theOnlyOne = files.size() == 1 ? files.get(0) : null; + return theOnlyOne != null ? + IdeBundle.message("action.synchronize.file", escapeMnemonics(firstLast(theOnlyOne.getName(), 20))) : + IdeBundle.message("action.synchronize.selected.files"); } @Override public void actionPerformed(AnActionEvent e) { - final Project project = getEventProject(e); - final VirtualFile[] files = getFiles(e); - if (project == null || files == null || files.length == 0) return; + Project project = getEventProject(e); + List files = getFiles(e).toList(); + if (project == null || files.isEmpty()) return; for (VirtualFile file : files) { if (file.isDirectory()) file.getChildren(); @@ -67,7 +73,7 @@ public class SynchronizeCurrentFileAction extends AnAction implements DumbAware RefreshQueue.getInstance().refresh(true, true, () -> postRefresh(project, files), files); } - private static void postRefresh(Project project, VirtualFile[] files) { + private static void postRefresh(Project project, List files) { VcsDirtyScopeManager dirtyScopeManager = VcsDirtyScopeManager.getInstance(project); for (VirtualFile f : files) { if (f.isDirectory()) { @@ -84,8 +90,9 @@ public class SynchronizeCurrentFileAction extends AnAction implements DumbAware } } - @Nullable - private static VirtualFile[] getFiles(AnActionEvent e) { - return e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); + @NotNull + private static JBIterable getFiles(AnActionEvent e) { + return JBIterable.of(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY)) + .filter(o -> o.isInLocalFileSystem()); } } \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchAction.java index 5f028efc5c96..5de638a575eb 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchAction.java @@ -70,7 +70,7 @@ public class ApplyPatchAction extends DumbAwareAction { @Override public void update(AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); - if (isProjectOrScopeView(e.getPlace())) { + if (ActionPlaces.isPopupPlace(e.getPlace())) { VirtualFile vFile = e.getData(CommonDataKeys.VIRTUAL_FILE); e.getPresentation().setEnabledAndVisible(project != null && isPatchFile(vFile)); } @@ -87,7 +87,7 @@ public class ApplyPatchAction extends DumbAwareAction { VirtualFile vFile = null; final String place = e.getPlace(); - if (isProjectOrScopeView(place) || ActionPlaces.MAIN_MENU.equals(place)) { + if (ActionPlaces.isPopupPlace(e.getPlace()) || ActionPlaces.MAIN_MENU.equals(place)) { vFile = e.getData(CommonDataKeys.VIRTUAL_FILE); } if (isPatchFile(vFile)) { @@ -109,10 +109,6 @@ public class ApplyPatchAction extends DumbAwareAction { } } - private static boolean isProjectOrScopeView(@NotNull String place) { - return place.equals(ActionPlaces.PROJECT_VIEW_POPUP) || place.equals(ActionPlaces.SCOPE_VIEW_POPUP); - } - // used by TeamCity plugin public static void showApplyPatch(@NotNull final Project project, @NotNull final VirtualFile file) { final ApplyPatchDifferentiatedDialog dialog = new ApplyPatchDifferentiatedDialog(