mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 06:51:17 +07:00
Scratches: cleanup
This commit is contained in:
@@ -29,7 +29,7 @@ import java.util.Map;
|
||||
|
||||
public abstract class ScratchFileService {
|
||||
|
||||
public static RootType SCRATCHES = RootType.newRootType("scratches", "Scratches");
|
||||
public static final RootType SCRATCHES = RootType.newRootType("scratches", "Scratches");
|
||||
|
||||
public static ScratchFileService getInstance(@NotNull Project project) {
|
||||
return ServiceManager.getService(project, ScratchFileService.class);
|
||||
@@ -42,11 +42,11 @@ public abstract class ScratchFileService {
|
||||
@NotNull
|
||||
public abstract String getRootPath(@NotNull RootType rootType);
|
||||
|
||||
public abstract boolean isFileInRoot(@NotNull VirtualFile file, @NotNull RootType rootType);
|
||||
|
||||
@Nullable
|
||||
public abstract VirtualFile createScratchFile(@NotNull Project project, @NotNull Language language, @NotNull String initialContent);
|
||||
|
||||
public abstract boolean isScratchFile(@NotNull VirtualFile file);
|
||||
|
||||
@NotNull
|
||||
public abstract PerFileMappings<Language> getScratchesMapping();
|
||||
|
||||
@@ -56,15 +56,17 @@ public abstract class ScratchFileService {
|
||||
private final String myId;
|
||||
private final String myDisplayName;
|
||||
|
||||
private RootType(String id, String displayName) {
|
||||
private RootType(@NotNull String id, @Nullable String displayName) {
|
||||
myId = id;
|
||||
myDisplayName = displayName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getId() {
|
||||
return myId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getDisplayName() {
|
||||
return myDisplayName;
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ public abstract class ScratchFileServiceImpl extends ScratchFileService {
|
||||
|
||||
@Override
|
||||
public boolean isWritable(@NotNull VirtualFile file) {
|
||||
return file.getFileType() == SCRATCH_FILE_TYPE; // todo ensure project is OK
|
||||
return file.getFileType() == SCRATCH_FILE_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,8 +280,13 @@ public abstract class ScratchFileServiceImpl extends ScratchFileService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isScratchFile(@NotNull VirtualFile file) {
|
||||
return file.getFileType() == SCRATCH_FILE_TYPE;
|
||||
public boolean isFileInRoot(@NotNull VirtualFile file, @NotNull RootType rootType) {
|
||||
return rootType == SCRATCHES ? file.getFileType() == SCRATCH_FILE_TYPE : isFileInRootImpl(file, rootType);
|
||||
}
|
||||
|
||||
private static boolean isFileInRootImpl(@NotNull VirtualFile file, RootType scratches) {
|
||||
String rootPath = ScratchFileService.getInstance().getRootPath(scratches);
|
||||
return file.getPath().startsWith(rootPath);
|
||||
}
|
||||
|
||||
private static class MyFileType extends LanguageFileType implements FileTypeIdentifiableByVirtualFile, InternalFileType {
|
||||
@@ -292,8 +297,7 @@ public abstract class ScratchFileServiceImpl extends ScratchFileService {
|
||||
|
||||
@Override
|
||||
public boolean isMyFileType(@NotNull VirtualFile file) {
|
||||
String rootPath = ScratchFileService.getInstance().getRootPath(SCRATCHES);
|
||||
return file.getPath().startsWith(rootPath);
|
||||
return isFileInRootImpl(file, SCRATCHES);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -106,7 +106,7 @@ class ScratchWidget extends EditorBasedWidget implements CustomStatusBarWidget.M
|
||||
VirtualFile file = getSelectedFile();
|
||||
if (file == null) return;
|
||||
ScratchFileService fileService = ScratchFileService.getInstance();
|
||||
if (fileService.isScratchFile(file)) {
|
||||
if (fileService.isFileInRoot(file, ScratchFileService.SCRATCHES)) {
|
||||
Language lang = fileService.getScratchesMapping().getMapping(file);
|
||||
if (lang == null) {
|
||||
lang = LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)file.getFileType()).getLanguage(), file, project);
|
||||
|
||||
Reference in New Issue
Block a user