Search in sources :

Example 1 with NlPreviewManager

use of com.android.tools.idea.uibuilder.editor.NlPreviewManager in project android by JetBrains.

the class GenerateLayoutTestSkeletonAction method getSurface.

@Nullable
private static DesignSurface getSurface(@NotNull Project project) {
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    FileEditor[] editors = fileEditorManager.getSelectedEditors();
    for (FileEditor fileEditor : editors) {
        if (fileEditor instanceof NlEditor) {
            return ((NlEditor) fileEditor).getComponent().getSurface();
        }
    }
    Editor editor = fileEditorManager.getSelectedTextEditor();
    if (editor == null) {
        return null;
    }
    NlPreviewManager previewManager = NlPreviewManager.getInstance(project);
    if (previewManager.isWindowVisible()) {
        return previewManager.getPreviewForm().getSurface();
    }
    PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
    if (file == null) {
        return null;
    }
    for (FileEditor fileEditor : fileEditorManager.getEditors(file.getVirtualFile())) {
        if (fileEditor instanceof NlEditor) {
            return ((NlEditor) fileEditor).getComponent().getSurface();
        }
    }
    return null;
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NlPreviewManager(com.android.tools.idea.uibuilder.editor.NlPreviewManager) NlEditor(com.android.tools.idea.uibuilder.editor.NlEditor) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NlEditor(com.android.tools.idea.uibuilder.editor.NlEditor) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

NlEditor (com.android.tools.idea.uibuilder.editor.NlEditor)1 NlPreviewManager (com.android.tools.idea.uibuilder.editor.NlPreviewManager)1 Editor (com.intellij.openapi.editor.Editor)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 PsiFile (com.intellij.psi.PsiFile)1 Nullable (org.jetbrains.annotations.Nullable)1