Example usage for com.intellij.openapi.fileEditor OpenFileDescriptor navigate

List of usage examples for com.intellij.openapi.fileEditor OpenFileDescriptor navigate

Introduction

In this page you can find the example usage for com.intellij.openapi.fileEditor OpenFileDescriptor navigate.

Prototype

@Override
    public void navigate(boolean requestFocus) 

Source Link

Usage

From source file:com.android.tools.idea.actions.PsiClassNavigation.java

License:Apache License

@Override
public void navigate(boolean requestFocus) {
    OpenFileDescriptor fileDescriptor = myOffset >= 0
            ? new OpenFileDescriptor(myPsiFile.getProject(), myPsiFile.getVirtualFile(), myOffset)
            : new OpenFileDescriptor(myPsiFile.getProject(), myPsiFile.getVirtualFile(), myLine, 0);
    fileDescriptor.navigate(requestFocus);
}

From source file:com.android.tools.idea.actions.PsiFileAndLineNavigation.java

License:Apache License

@Override
public void navigate(boolean requestFocus) {
    OpenFileDescriptor fileDescriptor = new OpenFileDescriptor(myPsiFile.getProject(),
            myPsiFile.getVirtualFile(), myLineNumber);
    fileDescriptor.navigate(requestFocus);
}

From source file:com.android.tools.idea.gradle.editor.action.GradleEntityNavigateAction.java

License:Apache License

@Override
protected void doActionPerformed(@NotNull GradleEditorEntity entity, AnActionEvent event) {
    if (entity instanceof GradleEntityDefinitionValueLocationAware) {
        GradleEditorSourceBinding location = ((GradleEntityDefinitionValueLocationAware) entity)
                .getDefinitionValueLocation();
        if (location != null) {
            RangeMarker marker = location.getRangeMarker();
            if (marker.isValid()) {
                OpenFileDescriptor descriptor = new OpenFileDescriptor(location.getProject(),
                        location.getFile(), marker.getStartOffset());
                if (descriptor.canNavigate()) {
                    descriptor.navigate(true);
                }//from   w  w  w .java2s  . c  o m
            }
        }
    }
}

From source file:com.armhold.wicketsource.FileNavigator.java

License:Apache License

private void navigate(Project project, VirtualFile file, int line) {
    OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, file, line, 0);
    if (openFileDescriptor.canNavigate()) {
        log.info("Trying to navigate to " + file.getPath() + ":" + line);
        openFileDescriptor.navigate(true);
        WindowManager.getInstance().suggestParentWindow(project).toFront();
    } else {//from w ww  .j av  a  2  s  . com
        log.info("Cannot navigate");
    }
}

From source file:com.facebook.buck.intellij.ideabuck.ui.BuckToolWindowFactory.java

License:Apache License

private void handleClickOnError(BuckTreeNodeDetailError node) {
    TreeNode parentNode = node.getParent();
    if (parentNode instanceof BuckTreeNodeFileError) {
        BuckTreeNodeFileError buckParentNode = (BuckTreeNodeFileError) parentNode;

        DataContext dataContext = DataManager.getInstance().getDataContext();
        Project project = DataKeys.PROJECT.getData(dataContext);

        String relativePath = buckParentNode.getFilePath().replace(project.getBasePath(), "");

        VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(relativePath);
        OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, virtualFile, node.getLine() - 1,
                node.getColumn() - 1);/*  w  ww .  j a v  a  2s. c  om*/
        openFileDescriptor.navigate(true);
    }
}

From source file:com.facebook.buck.intellij.ideabuck.ui.components.BuckTreeViewPanelImpl.java

License:Apache License

private static void handleClickOnError(BuckErrorItemNode node) {
    TreeNode parentNode = node.getParent();
    if (parentNode instanceof BuckFileErrorNode) {
        BuckFileErrorNode buckParentNode = (BuckFileErrorNode) parentNode;
        DataContext dataContext = DataManager.getInstance().getDataContext();
        Project project = DataKeys.PROJECT.getData(dataContext);

        String relativePath = buckParentNode.getText().replace(project.getBasePath(), "");

        VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(relativePath);
        if (virtualFile != null) {
            OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, virtualFile,
                    node.getLine() - 1, node.getColumn() - 1);
            openFileDescriptor.navigate(true);
        }//from  w ww .j  av a  2  s. c o  m
    }
}

From source file:com.jetbrains.lang.dart.assists.AssistUtils.java

License:Apache License

@Nullable
public static Editor navigate(@NotNull final Project project, @NotNull final VirtualFile file,
        final int offset) {
    final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, offset);
    descriptor.setScrollType(ScrollType.MAKE_VISIBLE);
    descriptor.navigate(true);

    final FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(file);
    return fileEditor instanceof TextEditor ? ((TextEditor) fileEditor).getEditor() : null;
}

From source file:org.intellij.plugins.xsltDebugger.XsltDebuggerSession.java

License:Apache License

@Nullable
public static Editor openLocation(Project project, @NotNull String uri, int lineNumber) {
    try {//from  w w  w  .  j a  va 2  s  .  c om
        final VirtualFile file = VfsUtil.findFileByURL(new URI(uri).toURL());
        final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, lineNumber, 0);
        descriptor.navigate(true);

        return FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
    } catch (MalformedURLException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        return null;
    } catch (URISyntaxException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        return null;
    }
}

From source file:org.jraf.intellijplugin.opencurrentactivity.OpenCurrentActivityAnAction.java

License:Open Source License

private void openActivityFile(final Project project, String activityName) {
    log.info("activityName=" + activityName);

    // Keep only the class name
    int dotIndex = activityName.lastIndexOf('.');
    if (dotIndex != -1) {
        activityName = activityName.substring(dotIndex + 1);
    }/*from ww w  . j av a 2s.  com*/
    final String fileName = activityName + EXT_JAVA;

    // Open the file
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        public void run() {
            ApplicationManager.getApplication().runReadAction(new Runnable() {
                public void run() {
                    PsiFile[] foundFiles = PsiShortNamesCache.getInstance(project).getFilesByName(fileName);
                    if (foundFiles.length == 0) {
                        log.info("No file with name " + fileName + " found");
                        mStatusBar.setInfo("Could not find " + fileName + " in project");
                        return;
                    }
                    if (foundFiles.length > 1)
                        log.warn("Found more than one file with name " + fileName);

                    PsiFile foundFile = foundFiles[0];
                    log.info("Found file " + foundFile.getName());
                    OpenFileDescriptor descriptor = new OpenFileDescriptor(project, foundFile.getVirtualFile());
                    descriptor.navigate(true);
                }
            });
        }
    });
}

From source file:org.perfcake.ide.intellij.NewScenarioAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    VirtualFile file = e.getData(DataKeys.VIRTUAL_FILE);
    Module module = e.getData(DataKeys.MODULE);
    Project project = e.getProject();/*from   w  w  w  .j a v  a  2s .c om*/

    ScenarioDialog dialog = new ScenarioDialog(project, module, file);
    dialog.show();

    if (dialog.getExitCode() == 0) {
        VirtualFile scenarioDir = dialog.getScenarioDir();
        String scenarioName = dialog.getScenarioFileName();
        Path scenarioPath = null;
        try {
            scenarioPath = VirtualFileConverter.convertPath(scenarioDir);
        } catch (PerfCakeResourceException e1) {
            Notification error = IntellijUtils
                    .createNotification("Cannot create scenario", NotificationType.ERROR)
                    .setContent("Cannot convert path. See log file for more details");
            Notifications.Bus.notify(error, project);
            logger.error("Cannot create scenario file in directory: " + scenarioDir, e1);
        }

        scenarioPath = scenarioPath.resolve(scenarioName);
        ScenarioManager manager = null;

        switch (dialog.getType()) {
        case "xml":
            manager = ScenarioManagers.createXmlManager(scenarioPath);
            break;
        case "dsl":
            manager = ScenarioManagers.createDslManager(scenarioPath);
            break;
        default:
            logger.warn("Unknown type of scenario: " + dialog.getType());
            return;
        }

        //create scenario
        ServiceManager serviceManager = project.getComponent(ServiceManager.class);
        ScenarioModel model = (ScenarioModel) serviceManager.getModelFactory()
                .createModel(PerfCakeComponent.SCENARIO);
        try {
            manager.writeScenario(model);
            scenarioDir.refresh(false, false);
            VirtualFile scenarioFile = dialog.getScenarioDir().findChild(scenarioName);
            OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, scenarioFile);
            openFileDescriptor.navigate(true);
        } catch (ModelSerializationException | ModelConversionException e1) {
            Notification error = IntellijUtils
                    .createNotification("Cannot create scenario", NotificationType.ERROR)
                    .setContent(String.format("Caused by: %s. See log for more details", e1.getMessage()));
            Notifications.Bus.notify(error, project);
            logger.error("Cannot create scenario", e1);
            return;
        }

    }

}