List of usage examples for com.intellij.openapi.fileEditor OpenFileDescriptor OpenFileDescriptor
public OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file)
From source file:org.jetbrains.idea.svn.dialogs.RepositoryBrowserComponent.java
License:Apache License
@Nullable public Object getData(@NonNls String dataId) { if (CommonDataKeys.NAVIGATABLE.is(dataId)) { final Project project = myVCS.getProject(); if (project == null || project.isDefault()) { return null; }/* ww w . ja va 2s .co m*/ final VirtualFile vcsFile = getSelectedVcsFile(); return vcsFile != null ? new OpenFileDescriptor(project, vcsFile) : null; } else if (CommonDataKeys.PROJECT.is(dataId)) { return myVCS.getProject(); } return null; }
From source file:org.jetbrains.jet.plugin.versions.UnsupportedAbiVersionNotificationPanelProvider.java
License:Apache License
private static void navigateToLibraryRoot(Project project, @NotNull VirtualFile root) { new OpenFileDescriptor(project, root).navigate(true); }
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 a v a 2 s .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.mustbe.consulo.csharp.ide.codeInsight.actions.CreateUnresolvedElementFix.java
License:Apache License
@Nullable protected static Editor openEditor(@NotNull PsiElement anchor, int offset) { PsiFile containingFile = anchor.getContainingFile(); if (containingFile == null) { return null; }/*w w w .j a va2s.c om*/ VirtualFile virtualFile = containingFile.getVirtualFile(); if (virtualFile == null) { return null; } Project project = containingFile.getProject(); FileEditorProviderManager editorProviderManager = FileEditorProviderManager.getInstance(); if (editorProviderManager.getProviders(project, virtualFile).length == 0) { Messages.showMessageDialog(project, IdeBundle.message("error.files.of.this.type.cannot.be.opened", ApplicationNamesInfo.getInstance().getProductName()), IdeBundle.message("title.cannot.open.file"), Messages.getErrorIcon()); return null; } OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile); Editor editor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true); if (editor != null) { editor.getCaretModel().moveToOffset(offset); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); return editor; } return null; }
From source file:org.napile.idea.thermit.config.explorer.AntExplorer.java
License:Apache License
@Nullable public Object getData(@NonNls String dataId) { if (PlatformDataKeys.NAVIGATABLE.is(dataId)) { final AntBuildFile buildFile = getCurrentBuildFile(); if (buildFile == null) { return null; }// ww w . ja v a 2 s.c o m final VirtualFile file = buildFile.getVirtualFile(); if (file == null) { return null; } final TreePath treePath = myTree.getLeadSelectionPath(); if (treePath == null) { return null; } final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent(); if (node == null) { return null; } if (node.getUserObject() instanceof AntTargetNodeDescriptor) { final AntTargetNodeDescriptor targetNodeDescriptor = (AntTargetNodeDescriptor) node.getUserObject(); final AntBuildTargetBase buildTarget = targetNodeDescriptor.getTarget(); final OpenFileDescriptor descriptor = buildTarget.getOpenFileDescriptor(); if (descriptor != null) { final VirtualFile descriptorFile = descriptor.getFile(); if (descriptorFile.isValid()) { return descriptor; } } } if (file.isValid()) { return new OpenFileDescriptor(myProject, file); } } else if (PlatformDataKeys.HELP_ID.is(dataId)) { return HelpID.ANT; } else if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) { return myProject != null ? myTreeExpander : null; } else if (PlatformDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) { final TreePath[] paths = myTree.getSelectionPaths(); if (paths == null) { return null; } final ArrayList<VirtualFile> result = new ArrayList<VirtualFile>(); for (final TreePath path : paths) { for (DefaultMutableTreeNode node = (DefaultMutableTreeNode) path .getLastPathComponent(); node != null; node = (DefaultMutableTreeNode) node.getParent()) { final Object userObject = node.getUserObject(); if (!(userObject instanceof AntBuildFileNodeDescriptor)) { continue; } final AntBuildFile buildFile = ((AntBuildFileNodeDescriptor) userObject).getBuildFile(); if (buildFile != null) { final VirtualFile virtualFile = buildFile.getVirtualFile(); if (virtualFile != null && virtualFile.isValid()) { result.add(virtualFile); } } break; } } if (result.size() == 0) { return null; } return VfsUtil.toVirtualFileArray(result); } return super.getData(dataId); }
From source file:org.onehippo.essentials.intellij.xml.intentions.CreateFileIntention.java
License:Apache License
@Override public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException { final String fileName = getFileName(project, editor, element); if (Strings.isNullOrEmpty(fileName)) { return;/*from w w w .j ava 2 s . c o m*/ } final Module module = ModuleUtilCore.findModuleForPsiElement(element); if (module == null) { return; } VirtualFile ourResource = null; final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots(); for (VirtualFile sourceRoot : sourceRoots) { ourResource = sourceRoot; if (sourceRoot.getName().equals("resources")) { ourResource = sourceRoot; break; } } if (ourResource == null) { return; } final String filePath = ourResource.getCanonicalPath() + File.separator + fileName; final Application application = ApplicationManager.getApplication(); application.runWriteAction(new Runnable() { @Override public void run() { try { FileUtil.createIfDoesntExist(new File(filePath)); } finally { application.invokeLater(new Runnable() { @Override public void run() { final VirtualFile file = VirtualFileManager.getInstance() .refreshAndFindFileByUrl("file://" + filePath); if (file != null) { final OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, file); FileEditorManager.getInstance(project).openTextEditor(openFileDescriptor, 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();//w w w . ja v a 2s .co m 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; } } }
From source file:randori.plugin.components.RandoriProjectComponent.java
License:Apache License
/** * Opens a ICompilerProblem in a new editor, or opens the editor and places the caret a the specific problem. * /* w ww .j a v a 2 s.co m*/ * @param problem The ICompilerProblem to focus. */ public void openFileForProblem(ICompilerProblem problem) { VirtualFile virtualFile = VFileUtils.getFile(problem.getSourcePath()); if (virtualFile != null) { OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile); if (descriptor != null) { Editor editor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true); if (editor != null) { LogicalPosition position = new LogicalPosition(problem.getLine(), problem.getColumn()); editor.getCaretModel().moveToLogicalPosition(position); } } } }
From source file:ru.scratch.OpenScratchAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent event) { Project project = projectFor(event); VirtualFile defaultScratch = ScratchComponent.getDefaultScratch(); if (defaultScratch != null) { OpenFileDescriptor fileDescriptor = new OpenFileDescriptor(project, defaultScratch); fileDescriptor.navigate(true);// w w w . j a v a2 s. c o m } else { new AddScratchAction().actionPerformed(event); } }
From source file:ru.scratch.ScratchComponent.java
License:Apache License
public static void openInEditor(Project project, File scratchFile) { VirtualFile virtualFile = Util.getVirtualFile(scratchFile.getAbsolutePath()); if (virtualFile != null) { new OpenFileDescriptor(project, virtualFile).navigate(true); ScratchData.getInstance().setLastOpenedFileName(scratchFile.getName()); }/*from ww w .j a v a2 s . c o m*/ }