mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
mark as plain text: scratches and visibility in action search (IDEA-168513)
This commit is contained in:
+7
-5
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.openapi.file.exclude;
|
||||
|
||||
import com.intellij.ide.scratch.ScratchUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
@@ -75,6 +76,7 @@ public class EnforcedPlainTextFileTypeManager implements ProjectManagerListener
|
||||
|
||||
public static boolean isApplicableFor(@NotNull VirtualFile file) {
|
||||
if (!(file instanceof VirtualFileWithId) || file.isDirectory()) return false;
|
||||
if (ScratchUtil.isScratch(file)) return false;
|
||||
FileType originalType = FileTypeManager.getInstance().getFileTypeByFileName(file.getName());
|
||||
return !originalType.isBinary() && originalType != FileTypes.PLAIN_TEXT && originalType != StdFileTypes.JAVA;
|
||||
}
|
||||
@@ -89,13 +91,13 @@ public class EnforcedPlainTextFileTypeManager implements ProjectManagerListener
|
||||
|
||||
private void setPlainTextStatus(@NotNull final Project project, final boolean isAdded, @NotNull final VirtualFile... files) {
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
ProjectPlainTextFileTypeManager projectPlainTextFileTypeManager = ProjectPlainTextFileTypeManager.getInstance(project);
|
||||
ProjectPlainTextFileTypeManager projectManager = ProjectPlainTextFileTypeManager.getInstance(project);
|
||||
for (VirtualFile file : files) {
|
||||
if (projectPlainTextFileTypeManager.hasProjectContaining(file)) {
|
||||
ensureProjectFileSetAdded(project, projectPlainTextFileTypeManager);
|
||||
if (projectManager.isInContent(file)) {
|
||||
ensureProjectFileSetAdded(project, projectManager);
|
||||
if (isAdded ?
|
||||
projectPlainTextFileTypeManager.addFile(file) :
|
||||
projectPlainTextFileTypeManager.removeFile(file)) {
|
||||
projectManager.addFile(file) :
|
||||
projectManager.removeFile(file)) {
|
||||
FileBasedIndex.getInstance().requestReindex(file);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public class ProjectPlainTextFileTypeManager extends PersistentFileSetManager {
|
||||
myIndex = projectFileIndex;
|
||||
}
|
||||
|
||||
boolean hasProjectContaining(@NotNull VirtualFile file) {
|
||||
boolean isInContent(@NotNull VirtualFile file) {
|
||||
return myIndex.isInContent(file);
|
||||
}
|
||||
|
||||
|
||||
+26
-43
@@ -16,16 +16,18 @@
|
||||
package com.intellij.openapi.file.exclude.ui;
|
||||
|
||||
import com.intellij.idea.ActionsBundle;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.JBIterable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Rustam Vishnyakov
|
||||
@@ -33,52 +35,33 @@ import java.util.Collection;
|
||||
public class MarkAsOriginalTypeAction extends DumbAwareAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
DataContext dataContext = e.getDataContext();
|
||||
final VirtualFile[] selectedFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
|
||||
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||
if (selectedFiles == null || selectedFiles.length == 0) return;
|
||||
Collection<VirtualFile> filesToUnmark = new ArrayList<>();
|
||||
for (VirtualFile file : selectedFiles) {
|
||||
if (file != null && !file.isDirectory()) {
|
||||
filesToUnmark.add(file);
|
||||
}
|
||||
}
|
||||
Project project = e.getProject();
|
||||
EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance();
|
||||
assert typeManager != null;
|
||||
if (project != null) {
|
||||
typeManager.resetOriginalFileType(project, filesToUnmark.toArray(new VirtualFile[filesToUnmark.size()]));
|
||||
}
|
||||
if (project == null || typeManager == null) return;
|
||||
JBIterable<VirtualFile> selectedFiles =
|
||||
JBIterable.of(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY))
|
||||
.filter(file -> !file.isDirectory() && typeManager.isMarkedAsPlainText(file));
|
||||
typeManager.resetOriginalFileType(project, VfsUtilCore.toVirtualFileArray(selectedFiles.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
DataContext dataContext = e.getDataContext();
|
||||
final VirtualFile[] selectedFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
|
||||
final Presentation presentation = e.getPresentation();
|
||||
final EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance();
|
||||
presentation.setVisible(false);
|
||||
if (typeManager == null || selectedFiles == null || selectedFiles.length == 0) {
|
||||
return;
|
||||
EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance();
|
||||
JBIterable<VirtualFile> selectedFiles =
|
||||
JBIterable.of(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY))
|
||||
.filter(file -> !file.isDirectory() && typeManager.isMarkedAsPlainText(file));
|
||||
FileTypeManager fileTypeManager = FileTypeManager.getInstance();
|
||||
boolean enabled = e.getProject() != null && !selectedFiles.isEmpty();
|
||||
Set<FileType> fileTypes = selectedFiles.map(file -> fileTypeManager.getFileTypeByFileName(file.getName())).toSet();
|
||||
|
||||
if (fileTypes.size() == 1) {
|
||||
FileType original = fileTypes.iterator().next();
|
||||
String originalName = original.getName();
|
||||
String text = ActionsBundle.actionText("MarkAsOriginalTypeAction").replace("Original File Type", originalName);
|
||||
e.getPresentation().setText(text);
|
||||
e.getPresentation().setIcon(original.getIcon());
|
||||
}
|
||||
FileType originalType = null;
|
||||
for (VirtualFile file : selectedFiles) {
|
||||
if (typeManager.isMarkedAsPlainText(file)) {
|
||||
FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(file.getName());
|
||||
if (originalType == null) {
|
||||
originalType = fileType;
|
||||
}
|
||||
else if (fileType != originalType) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (originalType == null) return;
|
||||
presentation.setVisible(true);
|
||||
presentation.setText(ActionsBundle.actionText("MarkAsOriginalTypeAction") + " " + originalType.getName());
|
||||
presentation.setIcon(originalType.getIcon());
|
||||
e.getPresentation().setEnabledAndVisible(enabled);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
-36
@@ -15,15 +15,15 @@
|
||||
*/
|
||||
package com.intellij.openapi.file.exclude.ui;
|
||||
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeFactory;
|
||||
import com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import com.intellij.util.containers.JBIterable;
|
||||
|
||||
/**
|
||||
* @author Rustam Vishnyakov
|
||||
@@ -31,43 +31,24 @@ import java.util.Collection;
|
||||
public class MarkAsPlainTextAction extends DumbAwareAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
DataContext dataContext = e.getDataContext();
|
||||
final VirtualFile[] selectedFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
|
||||
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||
if (selectedFiles == null || selectedFiles.length == 0) return;
|
||||
Project project = e.getProject();
|
||||
EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance();
|
||||
assert typeManager != null;
|
||||
Collection<VirtualFile> filesToMark = new ArrayList<>();
|
||||
for (VirtualFile file : selectedFiles) {
|
||||
if (file != null &&
|
||||
!file.isDirectory() &&
|
||||
EnforcedPlainTextFileTypeManager.isApplicableFor(file) &&
|
||||
!typeManager.isMarkedAsPlainText(file)) {
|
||||
filesToMark.add(file);
|
||||
}
|
||||
}
|
||||
if (project != null) {
|
||||
typeManager.markAsPlainText(project, filesToMark.toArray(new VirtualFile[filesToMark.size()]));
|
||||
}
|
||||
if (project == null || typeManager == null) return;
|
||||
JBIterable<VirtualFile> selectedFiles =
|
||||
JBIterable.of(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY))
|
||||
.filter(file -> EnforcedPlainTextFileTypeManager.isApplicableFor(file) && !typeManager.isMarkedAsPlainText(file));
|
||||
typeManager.markAsPlainText(project, VfsUtilCore.toVirtualFileArray(selectedFiles.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
DataContext dataContext = e.getDataContext();
|
||||
final VirtualFile[] selectedFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
|
||||
final Presentation presentation = e.getPresentation();
|
||||
final EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance();
|
||||
presentation.setVisible(false);
|
||||
if (typeManager == null || selectedFiles == null || selectedFiles.length == 0) {
|
||||
return;
|
||||
}
|
||||
for (VirtualFile file : selectedFiles) {
|
||||
if (!EnforcedPlainTextFileTypeManager.isApplicableFor(file) || typeManager.isMarkedAsPlainText(file)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
presentation.setVisible(true);
|
||||
presentation.setIcon(EnforcedPlainTextFileTypeFactory.ENFORCED_PLAIN_TEXT_ICON);
|
||||
EnforcedPlainTextFileTypeManager typeManager = EnforcedPlainTextFileTypeManager.getInstance();
|
||||
JBIterable<VirtualFile> selectedFiles =
|
||||
typeManager == null ? JBIterable.empty() : JBIterable.of(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY))
|
||||
.filter(file -> EnforcedPlainTextFileTypeManager.isApplicableFor(file) && !typeManager.isMarkedAsPlainText(file));
|
||||
boolean enabled = e.getProject() != null && !selectedFiles.isEmpty();
|
||||
e.getPresentation().setEnabledAndVisible(enabled);
|
||||
e.getPresentation().setIcon(EnforcedPlainTextFileTypeFactory.ENFORCED_PLAIN_TEXT_ICON);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1502,7 +1502,7 @@ action.EditorGutterToggleGlobalIndentLines.text=Show Indent Guides
|
||||
action.ExcludeFromProject.text=Exclude From Project...
|
||||
group.MarkFileAs.text=Mark File as
|
||||
action.MarkAsPlainTextAction.text=Mark as Plain Text
|
||||
action.MarkAsOriginalTypeAction.text=Mark as
|
||||
action.MarkAsOriginalTypeAction.text=Mark as Original File Type
|
||||
|
||||
action.Console.Open.text=Open Console
|
||||
action.Console.Open.description=Open console for selected entity
|
||||
|
||||
Reference in New Issue
Block a user