Search in sources :

Example 61 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project GsonFormat by zzz40500.

the class PsiClassUtil method getPsiClass.

public static PsiClass getPsiClass(PsiFile psiFile, Project project, String generateClass) throws Throwable {
    PsiClass psiClass = null;
    PsiDirectory psiDirectory = getJavaSrc(psiFile);
    if (psiDirectory == null || psiDirectory.getVirtualFile().getCanonicalPath() == null) {
        return null;
    }
    File file = new File(psiDirectory.getVirtualFile().getCanonicalPath().concat("/").concat(generateClass.trim().replace(".", "/")).concat(".java"));
    String[] strArray = generateClass.replace(" ", "").split("\\.");
    if (TextUtils.isEmpty(generateClass)) {
        return null;
    }
    String className = strArray[strArray.length - 1];
    String packName = generateClass.substring(0, generateClass.length() - className.length());
    if (file.exists()) {
        for (int i = 0; i < strArray.length - 1; i++) {
            psiDirectory = psiDirectory.findSubdirectory(strArray[i]);
            if (psiDirectory == null) {
                return null;
            }
        }
        PsiFile psiFile1 = psiDirectory.findFile(className + ".java");
        if ((psiFile1 instanceof PsiJavaFile) && ((PsiJavaFile) psiFile1).getClasses().length > 0) {
            psiClass = ((PsiJavaFile) psiFile1).getClasses()[0];
        }
        if (psiClass != null) {
            FileEditorManager manager = FileEditorManager.getInstance(project);
            manager.openFile(psiClass.getContainingFile().getVirtualFile(), true, true);
        }
    } else {
        if (!file.getParentFile().exists() && !TextUtils.isEmpty(packName)) {
            psiDirectory = createPackageInSourceRoot(packName, psiDirectory);
        } else {
            for (int i = 0; i < strArray.length - 1; i++) {
                psiDirectory = psiDirectory.findSubdirectory(strArray[i]);
                if (psiDirectory == null) {
                    return null;
                }
            }
        }
        psiClass = JavaDirectoryService.getInstance().createClass(psiDirectory, className);
        FileEditorManager manager = FileEditorManager.getInstance(project);
        manager.openFile(psiClass.getContainingFile().getVirtualFile(), true, true);
    }
    return psiClass;
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) File(java.io.File)

Example 62 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class ResourceBundleManager method closeResourceBundleEditors.

private static void closeResourceBundleEditors(@NotNull ResourceBundle resourceBundle) {
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(resourceBundle.getProject());
    fileEditorManager.closeFile(new ResourceBundleAsVirtualFile(resourceBundle));
    for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
        fileEditorManager.closeFile(propertiesFile.getVirtualFile());
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundleAsVirtualFile(com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)

Example 63 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class JavaFormatterPerformanceTest method testPaymentManager.

public void testPaymentManager() throws Exception {
    final FileEditorManager editorManager = FileEditorManager.getInstance(LightPlatformTestCase.getProject());
    try {
        getSettings().getCommonSettings(JavaLanguage.INSTANCE).KEEP_LINE_BREAKS = false;
        doTest();
    } finally {
        getSettings().getCommonSettings(JavaLanguage.INSTANCE).KEEP_LINE_BREAKS = true;
        editorManager.closeFile(editorManager.getSelectedFiles()[0]);
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager)

Example 64 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class CodeInsightTestCase method tearDown.

@Override
protected void tearDown() throws Exception {
    try {
        if (myProject != null) {
            FileEditorManager editorManager = FileEditorManager.getInstance(myProject);
            for (VirtualFile openFile : editorManager.getOpenFiles()) {
                editorManager.closeFile(openFile);
            }
        }
    } finally {
        myEditor = null;
        super.tearDown();
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager)

Example 65 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class BraceHighlighter method runActivity.

@Override
public void runActivity(@NotNull final Project project) {
    // sorry, upsource
    if (ApplicationManager.getApplication().isHeadlessEnvironment())
        return;
    final EditorEventMulticaster eventMulticaster = EditorFactory.getInstance().getEventMulticaster();
    CaretListener myCaretListener = new CaretAdapter() {

        @Override
        public void caretPositionChanged(CaretEvent e) {
            myAlarm.cancelAllRequests();
            Editor editor = e.getEditor();
            final SelectionModel selectionModel = editor.getSelectionModel();
            // Don't update braces in case of the active selection.
            if (editor.getProject() != project || selectionModel.hasSelection()) {
                return;
            }
            final Document document = editor.getDocument();
            int line = e.getNewPosition().line;
            if (line < 0 || line >= document.getLineCount()) {
                return;
            }
            updateBraces(editor, myAlarm);
        }
    };
    eventMulticaster.addCaretListener(myCaretListener, project);
    final SelectionListener mySelectionListener = new SelectionListener() {

        @Override
        public void selectionChanged(SelectionEvent e) {
            myAlarm.cancelAllRequests();
            Editor editor = e.getEditor();
            if (editor.getProject() != project) {
                return;
            }
            final TextRange oldRange = e.getOldRange();
            final TextRange newRange = e.getNewRange();
            if (oldRange != null && newRange != null && !(oldRange.isEmpty() ^ newRange.isEmpty())) {
                // Don't perform braces update in case of active/absent selection.
                return;
            }
            updateBraces(editor, myAlarm);
        }
    };
    eventMulticaster.addSelectionListener(mySelectionListener, project);
    DocumentListener documentListener = new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            myAlarm.cancelAllRequests();
            Editor[] editors = EditorFactory.getInstance().getEditors(e.getDocument(), project);
            for (Editor editor : editors) {
                updateBraces(editor, myAlarm);
            }
        }
    };
    eventMulticaster.addDocumentListener(documentListener, project);
    final FocusChangeListener myFocusChangeListener = new FocusChangeListener() {

        @Override
        public void focusLost(Editor editor) {
            clearBraces(editor);
        }

        @Override
        public void focusGained(Editor editor) {
            updateBraces(editor, myAlarm);
        }
    };
    ((EditorEventMulticasterEx) eventMulticaster).addFocusChangeListner(myFocusChangeListener, project);
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    fileEditorManager.addFileEditorManagerListener(new FileEditorManagerListener() {

        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent e) {
            myAlarm.cancelAllRequests();
        }
    }, project);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) EditorEventMulticasterEx(com.intellij.openapi.editor.ex.EditorEventMulticasterEx) SelectionModel(com.intellij.openapi.editor.SelectionModel) Editor(com.intellij.openapi.editor.Editor) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) FocusChangeListener(com.intellij.openapi.editor.ex.FocusChangeListener)

Aggregations

FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)67 VirtualFile (com.intellij.openapi.vfs.VirtualFile)36 FileEditor (com.intellij.openapi.fileEditor.FileEditor)29 Editor (com.intellij.openapi.editor.Editor)22 Project (com.intellij.openapi.project.Project)22 TextEditor (com.intellij.openapi.fileEditor.TextEditor)12 Document (com.intellij.openapi.editor.Document)10 PsiFile (com.intellij.psi.PsiFile)10 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)9 Nullable (org.jetbrains.annotations.Nullable)8 TextRange (com.intellij.openapi.util.TextRange)6 NotNull (org.jetbrains.annotations.NotNull)6 FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)5 PsiElement (com.intellij.psi.PsiElement)5 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 GuiTask (org.fest.swing.edt.GuiTask)4 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)3 ResourceBundleAsVirtualFile (com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)3 PsiClass (com.intellij.psi.PsiClass)3