List of usage examples for com.intellij.openapi.fileEditor FileEditorManager getInstance
public static FileEditorManager getInstance(@NotNull Project project)
From source file:FeatureEditorFactory.java
License:Apache License
/** * Creates the tool window's contents/*ww w . j ava2s . c o m*/ * @param project The intellij project that's being worked on. * @param toolWindow The tool window that is being created */ public void createToolWindowContent(Project project, ToolWindow toolWindow) { myToolWindow = toolWindow; ContentFactory contentFactory = ContentFactory.SERVICE.getInstance(); Content content = contentFactory.createContent(myPanel1, "", false); toolWindow.getContentManager().addContent(content); descriptionText.setText(""); enablesText.setText(""); enabledByText.setText(""); // Load the editor object (so we can access it later) editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); this.project = project; // Configure the toolwindow }
From source file:PatternFinder.java
License:Apache License
@Override public void actionPerformed(final AnActionEvent anActionEvent) { //Get all the required data from data keys final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR); final Project project = anActionEvent.getRequiredData(CommonDataKeys.PROJECT); final SelectionModel selectionModel = editor.getSelectionModel(); Runnable runnable = new Runnable() { @Override//from w w w .j a va 2s . c o m public void run() { //Get Basepath for project String basePath = project.getBasePath(); try { //Array list for all found filenames List<String> filenames = new ArrayList<String>(); String currentlySelectedPattern = selectionModel.getSelectedText(); //Clean search for multiple select scenarious {{> atoms-text-paragraph-medium}} currentlySelectedPattern = currentlySelectedPattern.trim(); //TODO Replace with nice Regex ASAP currentlySelectedPattern = currentlySelectedPattern.replace("{{> ", ""); currentlySelectedPattern = currentlySelectedPattern.replace("{{>", ""); currentlySelectedPattern = currentlySelectedPattern.replace(" }}", ""); currentlySelectedPattern = currentlySelectedPattern.replace("}}", ""); currentlySelectedPattern = currentlySelectedPattern.trim(); //Path to patterns getFileNames(currentlySelectedPattern.toLowerCase(), filenames, Paths.get(basePath + "/source/_patterns")); //File found if (filenames.get(0) != null) { VirtualFile fileToOpen = LocalFileSystem.getInstance().findFileByPath(filenames.get(0)); FileEditorManager.getInstance(project).openFile(fileToOpen, true); } } catch (Exception e) { System.out.println("No pattern found"); } } }; runnable.run(); selectionModel.removeSelection(); }
From source file:ServerXMLDocumentManager.java
License:Apache License
/** * This function loads a file into the IntelliJ editor. Can also be used * to reload the contents of the editor. * @param serverXML The server.xml file we want to load into the editor *///from w w w . j a v a 2 s .c o m public void loadFile(File serverXML) { try { this.serverXML = serverXML; vf = LocalFileSystem.getInstance().findFileByIoFile(this.serverXML); FileEditorManager.getInstance(project).openFile(vf, true); vf.setWritable(true); } catch (Exception e) { e.printStackTrace(); } }
From source file:ariba.ideplugin.idea.GotoComponent.java
License:Apache License
/** * Find the file corresponding to an awl tag. The AWL file defining this tag will * open./* w w w . ja v a2s . c o m*/ * If the file does not exist the java file will open. * * @param event occurred */ public void actionPerformed(AnActionEvent event) { LOG.info("User performed GotoComponent!"); Project project = (Project) event.getDataContext().getData(DataConstants.PROJECT); VirtualFile[] selectedFile = FileEditorManager.getInstance(project).getSelectedFiles(); if (selectedFile.length == 0) { showError("No file is currently selected", project); return; } VirtualFile currentFile = selectedFile[0]; // ignore if the file is not awl String currentFileExtension = currentFile.getExtension(); if (!currentFileExtension.equals("awl") && !currentFileExtension.equals("htm")) { return; } Editor editor = (Editor) event.getDataContext().getData(DataConstants.EDITOR); ProjectRootManager rootManager = ProjectRootManager.getInstance(project); Document document = editor.getDocument(); CaretModel caret = editor.getCaretModel(); String componentName = findComponentName(document, caret.getOffset()); if (componentName == null) { showError("cannot figure out component name", project); } else { String javaFileName = componentName + ".java"; String awlFileName = componentName + ".awl"; // find components Vector components = new Vector(); findComponents(rootManager, javaFileName, awlFileName, components); if (components.isEmpty()) { javaFileName = nameWithPrefix(componentName, "") + ".java"; awlFileName = nameWithPrefix(componentName, "") + ".awl"; findComponents(rootManager, javaFileName, awlFileName, components); } if (components.isEmpty()) { javaFileName = nameWithPrefix(componentName, "AW") + ".java"; awlFileName = nameWithPrefix(componentName, "AW") + ".awl"; findComponents(rootManager, javaFileName, awlFileName, components); } if (components.isEmpty()) { javaFileName = nameWithPrefix(componentName, "AWT") + ".java"; awlFileName = nameWithPrefix(componentName, "AWT") + ".awl"; findComponents(rootManager, javaFileName, awlFileName, components); } if (!components.isEmpty()) { openFile(project, components); } else { String errorMessage = "cannot find component " + componentName; showError(errorMessage, project); } } }
From source file:ariba.ideplugin.idea.GotoComponent.java
License:Apache License
private void openFile(Project project, Vector components) { // open the first one by default VirtualFile javaFile = (VirtualFile) components.firstElement(); OpenFileDescriptor fd = new OpenFileDescriptor(project, javaFile); Editor newEditor = FileEditorManager.getInstance(project).openTextEditor(fd, true); if (newEditor == null) { showError("Can't open editor", project); }/*from w ww. java 2 s . c o m*/ }
From source file:ariba.ideplugin.idea.ToggleAction.java
License:Apache License
/** * Switch between an awl page and the corresponding java page. * @param event occurred// w ww . java 2s .co m */ public void actionPerformed(AnActionEvent event) { LOG.info("User performed ToggleAction!"); Project project = (Project) event.getDataContext().getData(DataConstants.PROJECT); if (project != null) { VirtualFile[] selectedFile = FileEditorManager.getInstance(project).getSelectedFiles(); if (selectedFile.length == 0) { error(project, "No file is currently selected"); return; } VirtualFile currEditorFile = selectedFile[0]; if (currEditorFile != null) { String extension = currEditorFile.getExtension(); String pairName; VirtualFile pairFile; if ("awl".equals(extension) || "htm".equals(extension)) { pairName = currEditorFile.getNameWithoutExtension() + ".java"; pairFile = currEditorFile.getParent().findChild(pairName); if (pairFile == null) { pairName = currEditorFile.getNameWithoutExtension() + ".groovy"; pairFile = currEditorFile.getParent().findChild(pairName); } if (pairFile == null) { error(project, "Could not find .java or .groovy file for " + currEditorFile.getName()); return; } } else if ("java".equals(extension) || "groovy".equals(extension)) { pairName = currEditorFile.getNameWithoutExtension() + ".awl"; pairFile = currEditorFile.getParent().findChild(pairName); if (pairFile == null) { pairName = currEditorFile.getNameWithoutExtension() + ".htm"; pairFile = currEditorFile.getParent().findChild(pairName); } if (pairFile == null) { error(project, "Could not find .awl or .htm file for " + currEditorFile.getName()); return; } } else { error(project, "Unexpected file type: " + extension); return; } OpenFileDescriptor fd = new OpenFileDescriptor(project, pairFile); if (fd != null) { FileEditorManager manager = FileEditorManager.getInstance(project); Editor e = manager.openTextEditor(fd, true); if (e == null) { error(project, "Editor is null"); } } else { error(project, "Unable to open file: " + pairName); } } else { error(project, "No file is currently selected"); } } }
From source file:base.PerlLightTestCase.java
License:Apache License
protected void doTestStructureView() { initWithFileSmartWithoutErrors();/*from w ww.ja v a 2 s. c om*/ PsiFile psiFile = getFile(); final VirtualFile virtualFile = psiFile.getVirtualFile(); final FileEditor fileEditor = FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile); final StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(psiFile); assertNotNull(builder); StructureView structureView = builder.createStructureView(fileEditor, getProject()); assertNotNull(structureView); StructureViewModel structureViewModel = structureView.getTreeModel(); StringBuilder sb = new StringBuilder(); serializeTree(structureViewModel.getRoot(), structureViewModel, sb, null, "", new THashSet<>()); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), sb.toString()); }
From source file:base.PerlLightTestCase.java
License:Apache License
protected void doTestTypeHierarchy() { initWithFileSmartWithoutErrors();/* w w w. j a v a2 s .c o m*/ Editor editor = getEditor(); Object psiElement = FileEditorManager.getInstance(getProject()) .getData(CommonDataKeys.PSI_ELEMENT.getName(), editor, editor.getCaretModel().getCurrentCaret()); MapDataContext dataContext = new MapDataContext(); dataContext.put(CommonDataKeys.PROJECT, getProject()); dataContext.put(CommonDataKeys.EDITOR, getEditor()); dataContext.put(CommonDataKeys.PSI_ELEMENT, (PsiElement) psiElement); dataContext.put(CommonDataKeys.PSI_FILE, getFile()); HierarchyProvider hierarchyProvider = BrowseHierarchyActionBase.findProvider(LanguageTypeHierarchy.INSTANCE, (PsiElement) psiElement, getFile(), dataContext); assertNotNull(hierarchyProvider); StringBuilder sb = new StringBuilder(); sb.append("Provider: ").append(hierarchyProvider.getClass().getSimpleName()).append("\n"); PsiElement target = hierarchyProvider.getTarget(dataContext); assertNotNull(target); sb.append("Target: ").append(target).append("\n"); HierarchyBrowser browser = hierarchyProvider.createHierarchyBrowser(target); sb.append("Browser: ").append(browser.getClass().getSimpleName()).append("\n"); assertInstanceOf(browser, TypeHierarchyBrowserBase.class); try { Field myType2TreeMap = HierarchyBrowserBaseEx.class.getDeclaredField("myType2TreeMap"); myType2TreeMap.setAccessible(true); Method createHierarchyTreeStructure = browser.getClass() .getDeclaredMethod("createHierarchyTreeStructure", String.class, PsiElement.class); createHierarchyTreeStructure.setAccessible(true); Method getContentDisplayName = browser.getClass().getDeclaredMethod("getContentDisplayName", String.class, PsiElement.class); getContentDisplayName.setAccessible(true); Method getElementFromDescriptor = browser.getClass().getDeclaredMethod("getElementFromDescriptor", HierarchyNodeDescriptor.class); getElementFromDescriptor.setAccessible(true); Map<String, JTree> subTrees = (Map<String, JTree>) myType2TreeMap.get(browser); List<String> treesNames = new ArrayList<>(subTrees.keySet()); ContainerUtil.sort(treesNames); for (String treeName : treesNames) { sb.append("----------------------------------------------------------------------------------\n") .append("Tree: ").append(getContentDisplayName.invoke(browser, treeName, target)) .append("\n"); HierarchyTreeStructure structure = (HierarchyTreeStructure) createHierarchyTreeStructure .invoke(browser, treeName, target); if (structure == null) { sb.append("none\n"); continue; } serializeTreeStructure(structure, (HierarchyNodeDescriptor) structure.getRootElement(), node -> { try { return (PsiElement) getElementFromDescriptor.invoke(browser, node); } catch (Exception e) { throw new RuntimeException(e); } }, sb, "", new THashSet<>()); } } catch (Exception e) { throw new RuntimeException(e); } UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), sb.toString()); }
From source file:bazaar4idea.BzrCurrentBranchStatusUpdater.java
License:Apache License
public void update(Project project) { hgCurrentBranchStatus.setCurrentBranch(null); Editor textEditor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if (textEditor == null) { return;//ww w . j av a 2 s . c o m } Document document = textEditor.getDocument(); VirtualFile file = FileDocumentManager.getInstance().getFile(document); VirtualFile repo = VcsUtil.getVcsRootFor(project, file); String branch = null; if (repo != null) { // todo uncomment // BzrTagBranchCommand hgTagBranchCommand = new BzrTagBranchCommand(project, repo); // branch = hgTagBranchCommand.getCurrentBranch(); } hgCurrentBranchStatus.setCurrentBranch(branch); }
From source file:ch.mjava.intellij.tapestry.TapestrySwitcher.java
License:Apache License
public void actionPerformed(AnActionEvent e) { List<PsiFile> files = getPartnerFiles(e.getData(LangDataKeys.PSI_FILE)); if (files.isEmpty()) { PluginHelper.showErrorBalloonWith("No partner file found", e.getDataContext()); } else {//from w w w . j a va 2s . c o m FileEditorManager fileEditorManager = FileEditorManager.getInstance(e.getProject()); for (PsiFile file : files) { fileEditorManager.openFile(file.getVirtualFile(), true, true); } } }