Search in sources :

Example 96 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.

the class AndroidResGroupNode method navigate.

@Override
public void navigate(boolean requestFocus) {
    if (myFiles.isEmpty()) {
        return;
    }
    PsiFile fileToOpen = findFileToOpen(myFiles);
    if (fileToOpen == null) {
        return;
    }
    new OpenFileDescriptor(myProject, fileToOpen.getVirtualFile()).navigate(requestFocus);
}
Also used : PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 97 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project android by JetBrains.

the class NlModel method overrideConfigurationScreenSize.

/**
   * Changes the configuration to use a custom device with screen size defined by xDimension and yDimension.
   */
public void overrideConfigurationScreenSize(@AndroidCoordinate int xDimension, @AndroidCoordinate int yDimension) {
    Device original = myConfiguration.getDevice();
    // doesn't copy tag id
    Device.Builder deviceBuilder = new Device.Builder(original);
    if (original != null) {
        deviceBuilder.setTagId(original.getTagId());
    }
    deviceBuilder.setName("Custom");
    deviceBuilder.setId(Configuration.CUSTOM_DEVICE_ID);
    Device device = deviceBuilder.build();
    for (State state : device.getAllStates()) {
        Screen screen = state.getHardware().getScreen();
        screen.setXDimension(xDimension);
        screen.setYDimension(yDimension);
        double dpi = screen.getPixelDensity().getDpiValue();
        double width = xDimension / dpi;
        double height = yDimension / dpi;
        double diagonalLength = Math.sqrt(width * width + height * height);
        screen.setDiagonalLength(diagonalLength);
        screen.setSize(AvdScreenData.getScreenSize(diagonalLength));
        screen.setRatio(AvdScreenData.getScreenRatio(xDimension, yDimension));
        screen.setScreenRound(device.getDefaultHardware().getScreen().getScreenRound());
        screen.setChin(device.getDefaultHardware().getScreen().getChin());
    }
    // If a custom device already exists, remove it before adding the latest one
    List<Device> devices = myConfiguration.getConfigurationManager().getDevices();
    boolean customDeviceReplaced = false;
    for (int i = 0; i < devices.size(); i++) {
        if ("Custom".equals(devices.get(i).getId())) {
            devices.set(i, device);
            customDeviceReplaced = true;
            break;
        }
    }
    if (!customDeviceReplaced) {
        devices.add(device);
    }
    VirtualFile better;
    State newState;
    //Change the orientation of the device depending on the shape of the canvas
    if (xDimension > yDimension) {
        better = ConfigurationMatcher.getBetterMatch(myConfiguration, device, "Landscape", null, null);
        newState = device.getState("Landscape");
    } else {
        better = ConfigurationMatcher.getBetterMatch(myConfiguration, device, "Portrait", null, null);
        newState = device.getState("Portrait");
    }
    if (better != null) {
        VirtualFile old = myConfiguration.getFile();
        assert old != null;
        Project project = mySurface.getProject();
        OpenFileDescriptor descriptor = new OpenFileDescriptor(project, better, -1);
        FileEditorManager manager = FileEditorManager.getInstance(project);
        FileEditor selectedEditor = manager.getSelectedEditor(old);
        manager.openEditor(descriptor, true);
        // Switch to the same type of editor (XML or Layout Editor) in the target file
        if (selectedEditor instanceof NlEditor) {
            manager.setSelectedEditor(better, NlEditorProvider.DESIGNER_ID);
        } else if (selectedEditor != null) {
            manager.setSelectedEditor(better, TextEditorProvider.getInstance().getEditorTypeId());
        }
        AndroidFacet facet = AndroidFacet.getInstance(myConfiguration.getModule());
        assert facet != null;
        Configuration configuration = facet.getConfigurationManager().getConfiguration(better);
        configuration.setEffectiveDevice(device, newState);
    } else {
        myConfiguration.setEffectiveDevice(device, newState);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Configuration(com.android.tools.idea.configurations.Configuration) Device(com.android.sdklib.devices.Device) Screen(com.android.sdklib.devices.Screen) NlEditor(com.android.tools.idea.uibuilder.editor.NlEditor) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) State(com.android.sdklib.devices.State) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 98 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-plugins by JetBrains.

the class AbstractStepDefinitionCreator method closeActiveTemplateBuilders.

protected void closeActiveTemplateBuilders(PsiFile file) {
    final Project project = file.getProject();
    final VirtualFile vFile = ObjectUtils.assertNotNull(file.getVirtualFile());
    final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vFile);
    FileEditorManager.getInstance(project).getAllEditors(vFile);
    FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
    final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    assert editor != null;
    final TemplateManager templateManager = TemplateManager.getInstance(file.getProject());
    final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
    final Template template = templateManager.getActiveTemplate(editor);
    if (templateState != null && template != null) {
        templateState.gotoEnd(false);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) TemplateManager(com.intellij.codeInsight.template.TemplateManager) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Editor(com.intellij.openapi.editor.Editor) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) Template(com.intellij.codeInsight.template.Template)

Example 99 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-plugins by JetBrains.

the class FlexHighlightingTest method testCreateClassFromMetadataAttr.

@JSTestOptions({ JSTestOption.WithFlexFacet })
public void testCreateClassFromMetadataAttr() throws Exception {
    JSTestUtils.disableFileHeadersInTemplates(getProject());
    final String testName = getTestName(false);
    findAndInvokeIntentionAction(doTestFor(true, testName + ".as"), JSBundle.message("javascript.create.class.intention.name", "Baz"), myEditor, myFile);
    assertEmpty(filterUnwantedInfos(doHighlighting(), this));
    final VirtualFile createdFile = VfsUtilCore.findRelativeFile("foo/Baz.as", myFile.getVirtualFile().getParent());
    myEditor = FileEditorManager.getInstance(myProject).openTextEditor(new OpenFileDescriptor(myProject, createdFile), true);
    myFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
    checkResultByFile(getBasePath() + "/" + testName + "_created.as");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 100 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-plugins by JetBrains.

the class SocketInputHandlerImpl method openFileAndFindXmlAttributeOrTag.

private void openFileAndFindXmlAttributeOrTag() throws IOException {
    Project project = readProject();
    VirtualFile file = reader.readFile();
    int parentTextOffset = reader.readInt();
    final String name = reader.readUTF();
    final XmlFile psiFile = virtualFileToXmlFile(project, file);
    final XmlTag rootTag = psiFile.getRootTag();
    assert rootTag != null;
    final XmlTag parentTag = PsiTreeUtil.getParentOfType(rootTag.findElementAt(parentTextOffset - rootTag.getStartOffsetInParent()), XmlTag.class);
    assert parentTag != null;
    XmlAttribute attribute = parentTag.getAttribute(name);
    final int offset;
    if (attribute != null) {
        offset = attribute.getTextOffset();
    } else {
        XmlTag tag = parentTag.findFirstSubTag(name);
        assert tag != null;
        offset = tag.getTextOffset();
    }
    navigateToFile(new OpenFileDescriptor(project, file, offset));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)155 VirtualFile (com.intellij.openapi.vfs.VirtualFile)97 Project (com.intellij.openapi.project.Project)40 Editor (com.intellij.openapi.editor.Editor)30 PsiElement (com.intellij.psi.PsiElement)27 PsiFile (com.intellij.psi.PsiFile)21 Navigatable (com.intellij.pom.Navigatable)19 Nullable (org.jetbrains.annotations.Nullable)18 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)10 Document (com.intellij.openapi.editor.Document)9 FileEditor (com.intellij.openapi.fileEditor.FileEditor)9 TextRange (com.intellij.openapi.util.TextRange)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)9 File (java.io.File)9 Result (com.intellij.openapi.application.Result)8 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)8 NotNull (org.jetbrains.annotations.NotNull)6 TemplateBuilder (com.intellij.codeInsight.template.TemplateBuilder)5 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 XmlTag (com.intellij.psi.xml.XmlTag)5