com.intellij.ide.scratch.ScratchFileService Java Examples
The following examples show how to use
com.intellij.ide.scratch.ScratchFileService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsoleHistoryController.java From consulo with Apache License 2.0 | 6 votes |
private void saveHistory() { try { if (getModel().isEmpty()) return; if (myRootType.isHidden()) { saveHistoryOld(); return; } AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { VirtualFile file = HistoryRootType.getInstance().findFile(null, getHistoryName(myRootType, myId), ScratchFileService.Option.create_if_missing); VfsUtil.saveText(file, StringUtil.join(getModel().getEntries(), myRootType.getEntrySeparator())); } finally { token.finish(); } } catch (Exception ex) { LOG.error(ex); } }
Example #2
Source File: RunIdeConsoleAction.java From consulo with Apache License 2.0 | 6 votes |
protected void runConsole(@Nonnull AnActionEvent e, @Nonnull String language) { Project project = e.getProject(); if (project == null) return; List<String> extensions = IdeScriptEngineManager.getInstance().getFileExtensions(language); try { String pathName = PathUtil.makeFileName(DEFAULT_FILE_NAME, ContainerUtil.getFirstItem(extensions)); VirtualFile virtualFile = IdeConsoleRootType.getInstance().findFile(project, pathName, ScratchFileService.Option.create_if_missing); if (virtualFile != null) { FileEditorManager.getInstance(project).openFile(virtualFile, true); } } catch (IOException ex) { LOG.error(ex); } }
Example #3
Source File: FileUtil.java From jetbrains-plugin-graph-database-support with Apache License 2.0 | 5 votes |
public static VirtualFile getDataSourceFile(Project project, DataSourceApi dataSource) throws IOException { return ScratchFileService.getInstance().findFile( GraphDbEditorsConsoleRootType.getInstance(), NameUtil.createDataSourceFileName(dataSource), ScratchFileService.Option.create_if_missing ); }
Example #4
Source File: FileUtil.java From jetbrains-plugin-graph-database-support with Apache License 2.0 | 5 votes |
public static VirtualFile getScratchFile(Project project, String fileName) throws IOException { return ScratchFileService.getInstance().findFile( ParameterRootType.getInstance(), project.getName() + fileName, ScratchFileService.Option.create_if_missing ); }
Example #5
Source File: AutoTestManager.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull protected AutoTestWatcher createWatcher(Project project) { return new DelayedDocumentWatcher(project, myDelayMillis, this::restartAllAutoTests, file -> { if (ScratchFileService.getInstance().getRootType(file) != null) { return false; } // Vladimir.Krivosheev - I don't know, why AutoTestManager checks it, but old behavior is preserved return FileEditorManager.getInstance(project).isFileOpen(file); }); }
Example #6
Source File: ConsoleHistoryController.java From consulo with Apache License 2.0 | 5 votes |
public boolean loadHistory(String id, VirtualFile consoleFile) { try { VirtualFile file = myRootType.isHidden() ? null : HistoryRootType.getInstance().findFile(null, getHistoryName(myRootType, id), ScratchFileService.Option.existing_only); if (file == null) { if (loadHistoryOld(id)) { if (!myRootType.isHidden()) { // migrate content AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { VfsUtil.saveText(consoleFile, myContent); } finally { token.finish(); } } return true; } return false; } String[] split = VfsUtilCore.loadText(file).split(myRootType.getEntrySeparator()); getModel().resetEntries(Arrays.asList(split)); return true; } catch (Exception ignored) { return false; } }
Example #7
Source File: ConsoleHistoryController.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static VirtualFile getContentFile(@Nonnull final ConsoleRootType rootType, @Nonnull String id, ScratchFileService.Option option) { final String pathName = PathUtil.makeFileName(rootType.getContentPathName(id), rootType.getDefaultFileExtension()); try { return rootType.findFile(null, pathName, option); } catch (final IOException e) { LOG.warn(e); ApplicationManager.getApplication().invokeLater(() -> { String message = String.format("Unable to open '%s/%s'\nReason: %s", rootType.getId(), pathName, e.getLocalizedMessage()); Messages.showErrorDialog(message, "Unable to Open File"); }); return null; } }
Example #8
Source File: BashResolveUtil.java From BashSupport with Apache License 2.0 | 4 votes |
public static boolean isScratchFile(@Nullable VirtualFile file) { return file != null && ScratchFileService.getInstance().getRootType(file) != null; }
Example #9
Source File: BaseIntentionAction.java From consulo with Apache License 2.0 | 4 votes |
/** * @return true, if element belongs to project content root or is located in scratch files */ public static boolean canModify(PsiElement element) { return element.getManager().isInProject(element) || ScratchFileService.isInScratchRoot(PsiUtilCore.getVirtualFile(element)); }
Example #10
Source File: NonPhysicalReferenceSearcher.java From consulo with Apache License 2.0 | 4 votes |
private static boolean isApplicableTo(PsiFile file) { if (file == null) { return false; } return (!file.getViewProvider().isPhysical() && !(file instanceof PsiCodeFragment)) || ScratchFileService.getInstance().getRootType(file.getVirtualFile()) != null; }
Example #11
Source File: MoveFilesOrDirectoriesHandler.java From consulo with Apache License 2.0 | 4 votes |
public static boolean isValidTarget(PsiElement psiElement) { if (!(psiElement instanceof PsiDirectory || psiElement instanceof PsiDirectoryContainer)) return false; return psiElement.getManager().isInProject(psiElement) || ScratchFileService.isInScratchRoot(PsiUtilCore.getVirtualFile(psiElement)); }