Skip to content

Commit

Permalink
Merge pull request #107 from SeeSharpSoft/fb_scatches_support
Browse files Browse the repository at this point in the history
[FEATURE] support for ScratchFileType
  • Loading branch information
SeeSharpSoft authored Mar 3, 2019
2 parents e22d1d2 + 22e18f6 commit 3d6d3e4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvHelper.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package net.seesharpsoft.intellij.plugins.csv;

import com.intellij.ide.scratch.ScratchFileType;
import com.intellij.lang.*;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiManager;
import com.intellij.psi.TokenType;
Expand Down Expand Up @@ -37,6 +41,12 @@ public static PsiElement createEmptyCsvField(Project project) {
return node.getPsi();
}

public static boolean isCsvFile(Project project, VirtualFile file) {
final FileType fileType = file.getFileType();
return (fileType instanceof LanguageFileType && ((LanguageFileType) fileType).getLanguage().isKindOf(CsvLanguage.INSTANCE)) ||
(fileType == ScratchFileType.INSTANCE && LanguageUtil.getLanguageForPsi(project, file) == CsvLanguage.INSTANCE);
}

public static IElementType getElementType(PsiElement element) {
return element == null || element.getNode() == null ? null : element.getNode().getElementType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@
import com.intellij.openapi.editor.EditorSettings;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.SingleRootFileViewProvider;
import net.seesharpsoft.intellij.plugins.csv.CsvLanguage;
import net.seesharpsoft.intellij.plugins.csv.CsvHelper;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;

public class CsvFileEditorProvider implements AsyncFileEditorProvider, DumbAware {

public static final String EDITOR_TYPE_ID = "csv-text-editor";

public static boolean isCsvFile(VirtualFile file) {
return file.getFileType() instanceof LanguageFileType && ((LanguageFileType) file.getFileType()).getLanguage().isKindOf(CsvLanguage.INSTANCE);
}

@Override
public String getEditorTypeId() {
return EDITOR_TYPE_ID;
Expand All @@ -40,7 +35,7 @@ public FileEditorPolicy getPolicy() {

@Override
public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
return isCsvFile(file) && !SingleRootFileViewProvider.isTooLargeForContentLoading(file);
return CsvHelper.isCsvFile(project, file) && !SingleRootFileViewProvider.isTooLargeForContentLoading(file);
}

protected void applySettings(EditorSettings editorSettings, CsvEditorSettingsExternalizable csvEditorSettingsExternalizable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.SingleRootFileViewProvider;
import net.seesharpsoft.intellij.plugins.csv.CsvHelper;
import net.seesharpsoft.intellij.plugins.csv.editor.CsvEditorSettingsExternalizable;
import net.seesharpsoft.intellij.plugins.csv.editor.CsvFileEditorProvider;
import net.seesharpsoft.intellij.plugins.csv.editor.table.swing.CsvTableEditorSwing;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -38,7 +38,8 @@ public FileEditorPolicy getPolicy() {

@Override
public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
return CsvEditorSettingsExternalizable.getInstance().getEditorPrio() != CsvEditorSettingsExternalizable.EditorPrio.TEXT_ONLY && CsvFileEditorProvider.isCsvFile(file) &&
return CsvEditorSettingsExternalizable.getInstance().getEditorPrio() != CsvEditorSettingsExternalizable.EditorPrio.TEXT_ONLY &&
CsvHelper.isCsvFile(project, file) &&
!SingleRootFileViewProvider.isTooLargeForIntelligence(file);
}

Expand Down

0 comments on commit 3d6d3e4

Please sign in to comment.