@Override public void doRun() { PsiDirectory psiParent = PsiHelper.findPsiDirByPath(project, file.getParentFile().getPath()); if(psiParent==null){ ReportHelper.setState(ExecutionState.FAILED); return; } try { PsiFile psiResultFile = PsiFileFactory.getInstance(project).createFileFromText(file.getName(), PlainTextFileType.INSTANCE, content); // PsiFile psiFile = psiDirectory.createFile(psiDirectory.createFile(file.getName()).getName()); // psiFile.getVirtualFile(). psiParent.add(psiResultFile); } catch (IncorrectOperationException ex){ Logger.log("CreateFileAction " + ex.getMessage()); Logger.printStack(ex); ReportHelper.setState(ExecutionState.FAILED); return; } }
public void testTextFileClearingDoesNotCrash() { configureByText(PlainTextFileType.INSTANCE, "foo bar goo\n"); SmartPsiElementPointer pointer = createPointer(myFile.getFirstChild()); PlatformTestUtil.tryGcSoftlyReachableObjects(); assertEquals(myFile.getFirstChild(), pointer.getElement()); Document document = myFile.getViewProvider().getDocument(); document.deleteString(0, document.getTextLength()); PlatformTestUtil.tryGcSoftlyReachableObjects(); assertEquals(myFile.getFirstChild(), pointer.getElement()); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); PlatformTestUtil.tryGcSoftlyReachableObjects(); assertEquals(myFile.getFirstChild(), pointer.getElement()); }
public void testLargeFileWithManyChangesPerformance() { configureByText(PlainTextFileType.INSTANCE, StringUtil.repeat("foo foo \n", 50000)); final TextRange range = TextRange.from(10, 10); final SmartPsiFileRange pointer = getPointerManager().createSmartPsiFileRangePointer(myFile, range); final Document document = myFile.getViewProvider().getDocument(); assertNotNull(document); PlatformTestUtil.startPerformanceTest("smart pointer range update", 25000, () -> { for (int i = 0; i < 10000; i++) { document.insertString(i * 20 + 100, "x\n"); assertFalse(PsiDocumentManager.getInstance(myProject).isCommitted(document)); assertEquals(range, pointer.getRange()); } }).cpuBound().assertTiming(); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); assertEquals(range, pointer.getRange()); }
public void testConvergingRanges() { configureByText(PlainTextFileType.INSTANCE, "aba"); final Document document = myFile.getViewProvider().getDocument(); assertNotNull(document); SmartPsiFileRange range1 = getPointerManager().createSmartPsiFileRangePointer(myFile, TextRange.create(0, 2)); SmartPsiFileRange range2 = getPointerManager().createSmartPsiFileRangePointer(myFile, TextRange.create(1, 3)); document.deleteString(0, 1); document.deleteString(1, 2); assertEquals(TextRange.create(0, 1), range1.getRange()); assertEquals(TextRange.create(0, 1), range2.getRange()); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); assertEquals(TextRange.create(0, 1), range1.getRange()); assertEquals(TextRange.create(0, 1), range2.getRange()); document.insertString(0, "a"); assertEquals(TextRange.create(1, 2), range1.getRange()); assertEquals(TextRange.create(1, 2), range2.getRange()); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); assertEquals(TextRange.create(1, 2), range1.getRange()); assertEquals(TextRange.create(1, 2), range2.getRange()); }
private void doTest(boolean enabled, String document) { InspectionProfileImpl.INIT_INSPECTIONS = true; try { myFixture.configureByText(PlainTextFileType.INSTANCE, document); myFixture.enableInspections(new SpellCheckingInspection()); EditorCustomization customization = SpellCheckingEditorCustomizationProvider.getInstance().getCustomization(enabled); assertNotNull(customization); customization.customize((EditorEx)myFixture.getEditor()); myFixture.checkHighlighting(); } finally { InspectionProfileImpl.INIT_INSPECTIONS = false; } }
@Nullable @Override public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) { if (file.getFileType() != PlainTextFileType.INSTANCE) return null; final String extension = file.getExtension(); final String fileName = file.getName(); if (extension != null && isIgnored("*." + extension) || isIgnored(fileName)) return null; final PluginsAdvertiser.KnownExtensions knownExtensions = PluginsAdvertiser.loadExtensions(); if (knownExtensions != null) { final EditorNotificationPanel panel = extension != null ? createPanel("*." + extension, knownExtensions) : null; if (panel != null) { return panel; } return createPanel(fileName, knownExtensions); } return null; }
public void testRestoreState() throws Exception { String text = "some<caret> text<caret>\n" + "some <selection><caret>other</selection> <selection>text<caret></selection>\n" + "<selection>ano<caret>ther</selection> line"; PsiFile psiFile = myFixture.configureByText(PlainTextFileType.INSTANCE, text); VirtualFile virtualFile = psiFile.getVirtualFile(); assertNotNull(virtualFile); myManager.openFile(virtualFile, false); myManager.closeAllFiles(); FileEditor[] fileEditors = myManager.openFile(virtualFile, false); assertNotNull(fileEditors); assertEquals(1, fileEditors.length); Editor editor = ((TextEditor)fileEditors[0]).getEditor(); verifyEditorState(editor, text); }
public void testInfoTestAttributes() throws Exception { LanguageExtensionPoint<Annotator> extension = new LanguageExtensionPoint<Annotator>(); extension.language="TEXT"; extension.implementationClass = TestAnnotator.class.getName(); PlatformTestUtil.registerExtension(ExtensionPointName.create(LanguageAnnotators.EP_NAME), extension, getTestRootDisposable()); myFixture.configureByText(PlainTextFileType.INSTANCE, "foo"); EditorColorsScheme scheme = new EditorColorsSchemeImpl(new DefaultColorsScheme()){{initFonts();}}; scheme.setAttributes(HighlighterColors.TEXT, new TextAttributes(Color.black, Color.white, null, null, Font.PLAIN)); ((EditorEx)myFixture.getEditor()).setColorsScheme(scheme); myFixture.doHighlighting(); MarkupModel model = DocumentMarkupModel.forDocument(myFixture.getEditor().getDocument(), getProject(), false); RangeHighlighter[] highlighters = model.getAllHighlighters(); assertEquals(1, highlighters.length); TextAttributes attributes = highlighters[0].getTextAttributes(); assertNotNull(attributes); assertNull(attributes.getBackgroundColor()); assertNull(attributes.getForegroundColor()); }
@Nullable @Override protected VirtualFile getFile(@NotNull AnActionEvent e) { VcsFileRevision revision = getFileRevision(e); if (revision == null) return null; final FileType currentFileType = myAnnotation.getFile().getFileType(); FilePath filePath = (revision instanceof VcsFileRevisionEx ? ((VcsFileRevisionEx)revision).getPath() : VcsUtil.getFilePath(myAnnotation.getFile())); return new VcsVirtualFile(filePath.getPath(), revision, VcsFileSystem.getInstance()) { @NotNull @Override public FileType getFileType() { FileType type = super.getFileType(); if (!type.isBinary()) return type; if (!currentFileType.isBinary()) return currentFileType; return PlainTextFileType.INSTANCE; } }; }
private static void showUsages(@NotNull JPanel panel, @Nullable TextDescriptor exampleUsage) { String text = ""; FileType fileType = PlainTextFileType.INSTANCE; if (exampleUsage != null) { try { text = exampleUsage.getText(); String name = exampleUsage.getFileName(); FileTypeManagerEx fileTypeManager = FileTypeManagerEx.getInstanceEx(); String extension = fileTypeManager.getExtension(name); fileType = fileTypeManager.getFileTypeByExtension(extension); } catch (IOException e) { LOG.error(e); } } ((ActionUsagePanel)panel.getComponent(0)).reset(text, fileType); panel.repaint(); }
private void updateFileTypeForEditorComponent(@NotNull ComboBox inputComboBox) { final Component editorComponent = inputComboBox.getEditor().getEditorComponent(); if (editorComponent instanceof EditorTextField) { boolean isRegexp = myCbRegularExpressions.isSelectedWhenSelectable(); FileType fileType = PlainTextFileType.INSTANCE; if (isRegexp) { Language regexpLanguage = Language.findLanguageByID("RegExp"); if (regexpLanguage != null) { LanguageFileType regexpFileType = regexpLanguage.getAssociatedFileType(); if (regexpFileType != null) { fileType = regexpFileType; } } } String fileName = isRegexp ? "a.regexp" : "a.txt"; final PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(fileName, fileType, ((EditorTextField)editorComponent).getText(), -1, true); ((EditorTextField)editorComponent).setNewDocumentAndFileType(fileType, PsiDocumentManager.getInstance(myProject).getDocument(file)); } }
@NotNull @Override public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) { ArrayList<AbstractTreeNode> nodes = new ArrayList<AbstractTreeNode>(); for (AbstractTreeNode child : children) { if (child instanceof PsiFileNode) { VirtualFile file = ((PsiFileNode) child).getVirtualFile(); if (file != null && !file.isDirectory() && !(file.getFileType() instanceof PlainTextFileType)) { continue; } } nodes.add(child); } return nodes; }
@Nullable private Location buildLocation() { if (mySelectedTaskProvider == null) { return null; } ExternalTaskExecutionInfo task = mySelectedTaskProvider.produce(); if (task == null) { return null; } String projectPath = task.getSettings().getExternalProjectPath(); String name = myExternalSystemId.getReadableName() + projectPath + StringUtil.join(task.getSettings().getTaskNames(), " "); // We create a dummy text file instead of re-using external system file in order to avoid clashing with other configuration producers. // For example gradle files are enhanced groovy scripts but we don't want to run them via regular IJ groovy script runners. // Gradle tooling api should be used for running gradle tasks instead. IJ execution sub-system operates on Location objects // which encapsulate PsiElement and groovy runners are automatically applied if that PsiElement IS-A GroovyFile. PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(name, PlainTextFileType.INSTANCE, "nichts"); return new ExternalSystemTaskLocation(myProject, file, task); }
@javax.annotation.Nullable private static EditorHighlighter createEditorHighlighter(@Nullable Project project, @Nonnull DocumentContent content) { FileType type = content.getContentType(); VirtualFile file = content.getHighlightFile(); Language language = content.getUserData(DiffUserDataKeys.LANGUAGE); EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance(); if (language != null) { SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, file); return highlighterFactory.createEditorHighlighter(syntaxHighlighter, EditorColorsManager.getInstance().getGlobalScheme()); } if (file != null) { if ((type == null || type == PlainTextFileType.INSTANCE) || file.getFileType() == type || file instanceof LightVirtualFile) { return highlighterFactory.createEditorHighlighter(project, file); } } if (type != null) { return highlighterFactory.createEditorHighlighter(project, type); } return null; }
@Nonnull private static DocumentContent createImpl(@Nullable Project project, @Nonnull String text, @Nullable FileType fileType, @javax.annotation.Nullable String fileName, @Nullable VirtualFile highlightFile, @javax.annotation.Nullable Charset charset, @javax.annotation.Nullable Boolean bom, boolean respectLineSeparators, boolean readOnly) { if (UnknownFileType.INSTANCE == fileType) fileType = PlainTextFileType.INSTANCE; // TODO: detect invalid (different across the file) separators ? LineSeparator separator = respectLineSeparators ? StringUtil.detectSeparators(text) : null; String correctedContent = StringUtil.convertLineSeparators(text); Document document = createDocument(project, correctedContent, fileType, fileName, readOnly); DocumentContent content = new DocumentContentImpl(project, document, fileType, highlightFile, separator, charset, bom); if (fileName != null) content.putUserData(DiffUserDataKeysEx.FILE_NAME, fileName); return content; }
private void doTest(@Nonnull final String cs, @Nonnull String before, @Nonnull String expected) { final boolean smarterSelection = Registry.is("editor.smarterSelectionQuoting"); Registry.get("editor.smarterSelectionQuoting").setValue(true); try { myFixture.configureByText(PlainTextFileType.INSTANCE, before); final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction(); performAction(myFixture.getProject(), new Runnable() { @Override public void run() { for (int i = 0, max = cs.length(); i < max; i++) { final char c = cs.charAt(i); typedAction.actionPerformed(myFixture.getEditor(), c, ((EditorEx)myFixture.getEditor()).getDataContext()); } } }); myFixture.checkResult(expected); } finally { Registry.get("editor.smarterSelectionQuoting").setValue(smarterSelection); } }
public void testRuby7852ErrantEditor() { myFixture.configureByText(PlainTextFileType.INSTANCE, "\"aaa\"\nbbb\n\n"); myFixture.getEditor().getCaretModel().moveToOffset(0); myFixture.getEditor().getSelectionModel().setSelection(0, 5); final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction(); performAction(myFixture.getProject(), new Runnable() { @Override public void run() { typedAction.actionPerformed(myFixture.getEditor(), '\'', ((EditorEx)myFixture.getEditor()).getDataContext()); } }); myFixture.getEditor().getSelectionModel().removeSelection(); myFixture.checkResult("'aaa'\nbbb\n\n"); myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getDocument().getLineStartOffset(3)); performAction(myFixture.getProject(), new Runnable() { @Override public void run() { typedAction.actionPerformed(myFixture.getEditor(), 'A', ((EditorEx)myFixture.getEditor()).getDataContext()); typedAction.actionPerformed(myFixture.getEditor(), 'B', ((EditorEx)myFixture.getEditor()).getDataContext()); } }); myFixture.checkResult("'aaa'\nbbb\n\nAB"); }
@Override protected JComponent createCenterPanel() { final Document document = ((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(true); ((DocumentImpl)document).setAcceptSlashR(true); myTextArea = EditorFactory.getInstance().createEditor(document, myProject, PlainTextFileType.INSTANCE, true); final EditorSettings settings = myTextArea.getSettings(); settings.setLineNumbersShown(false); settings.setLineMarkerAreaShown(false); settings.setFoldingOutlineShown(false); settings.setRightMarginShown(false); settings.setAdditionalLinesCount(0); settings.setAdditionalColumnsCount(0); settings.setAdditionalPageAtBottom(false); ((EditorEx)myTextArea).setBackgroundColor(UIUtil.getInactiveTextFieldBackgroundColor()); return myTextArea.getComponent(); }
@RequiredReadAction @Nullable @Override public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile file, @Nonnull FileEditor fileEditor) { if (file.getFileType() != PlainTextFileType.INSTANCE && !(file.getFileType() instanceof AbstractFileType)) return null; final String extension = file.getExtension(); if (extension == null) { return null; } if (myEnabledExtensions.contains(extension) || UnknownFeaturesCollector.getInstance(myProject).isIgnored(createFileFeatureForIgnoring(file))) return null; UnknownExtension fileFeatureForChecking = new UnknownExtension(FileTypeFactory.FILE_TYPE_FACTORY_EP.getName(), file.getName()); List<IdeaPluginDescriptor> allPlugins = PluginsAdvertiserHolder.getLoadedPluginDescriptors(); Set<IdeaPluginDescriptor> byFeature = PluginsAdvertiser.findByFeature(allPlugins, fileFeatureForChecking); if (!byFeature.isEmpty()) { return createPanel(file, byFeature, allPlugins); } return null; }
@Nullable @Override protected VirtualFile getFile(@Nonnull AnActionEvent e) { VcsFileRevision revision = getFileRevision(e); if (revision == null) return null; final FileType currentFileType = myAnnotation.getFile().getFileType(); FilePath filePath = (revision instanceof VcsFileRevisionEx ? ((VcsFileRevisionEx)revision).getPath() : VcsUtil.getFilePath(myAnnotation.getFile())); return new VcsVirtualFile(filePath.getPath(), revision, VcsFileSystem.getInstance()) { @Nonnull @Override public FileType getFileType() { FileType type = super.getFileType(); if (!type.isBinary()) return type; if (!currentFileType.isBinary()) return currentFileType; return PlainTextFileType.INSTANCE; } }; }
@Nonnull private static EditorTextField createEditorField(@Nonnull String text, @Nullable TextRange rangeToSelect) { Document document = EditorFactory.getInstance().createDocument(text); EditorTextField field = new EditorTextField(document, null, PlainTextFileType.INSTANCE, false, false); field.setPreferredSize(new Dimension(200, 350)); field.addSettingsProvider(editor -> { editor.setVerticalScrollbarVisible(true); editor.setHorizontalScrollbarVisible(true); editor.getSettings().setAdditionalLinesCount(2); if (rangeToSelect != null) { editor.getCaretModel().moveToOffset(rangeToSelect.getStartOffset()); editor.getScrollingModel().scrollVertically(document.getTextLength() - 1); editor.getSelectionModel().setSelection(rangeToSelect.getStartOffset(), rangeToSelect.getEndOffset()); } }); return field; }
private static void showUsages(@Nonnull JPanel panel, @Nullable TextDescriptor exampleUsage) { String text = ""; FileType fileType = PlainTextFileType.INSTANCE; if (exampleUsage != null) { try { text = exampleUsage.getText(); String name = exampleUsage.getFileName(); FileTypeManagerEx fileTypeManager = FileTypeManagerEx.getInstanceEx(); String extension = fileTypeManager.getExtension(name); fileType = fileTypeManager.getFileTypeByExtension(extension); } catch (IOException e) { LOG.error(e); } } ((ActionUsagePanel)panel.getComponent(0)).reset(text, fileType); panel.repaint(); }
private void updateFileTypeForEditorComponent(@Nonnull ComboBox inputComboBox) { final Component editorComponent = inputComboBox.getEditor().getEditorComponent(); if (editorComponent instanceof EditorTextField) { boolean isRegexp = myCbRegularExpressions.isSelectedWhenSelectable(); FileType fileType = PlainTextFileType.INSTANCE; if (isRegexp) { Language regexpLanguage = Language.findLanguageByID("RegExp"); if (regexpLanguage != null) { LanguageFileType regexpFileType = regexpLanguage.getAssociatedFileType(); if (regexpFileType != null) { fileType = regexpFileType; } } } String fileName = isRegexp ? "a.regexp" : "a.txt"; final PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(fileName, fileType, ((EditorTextField)editorComponent).getText(), -1, true); ((EditorTextField)editorComponent).setNewDocumentAndFileType(fileType, PsiDocumentManager.getInstance(myProject).getDocument(file)); } }
protected void createNewNameComponent() { String[] suggestedNames = getSuggestedNames(); myOldName = UsageViewUtil.getShortName(myPsiElement); myNameSuggestionsField = new NameSuggestionsField(suggestedNames, myProject, PlainTextFileType.INSTANCE, myEditor) { @Override protected boolean shouldSelectAll() { return myEditor == null || myEditor.getSettings().isPreselectRename(); } }; if (myPsiElement instanceof PsiFile && myEditor == null) { myNameSuggestionsField.selectNameWithoutExtension(); } myNameChangedListener = new NameSuggestionsField.DataChanged() { @Override public void dataChanged() { processNewNameChanged(); } }; myNameSuggestionsField.addDataChangedListener(myNameChangedListener); }
private void createNewNameComponent() { myNameSuggestionsField = new NameSuggestionsField(new String[]{myTag.getName()}, myProject, PlainTextFileType.INSTANCE, myEditor); myNameChangedListener = new NameSuggestionsField.DataChanged() { @Override public void dataChanged() { validateButtons(); } }; myNameSuggestionsField.addDataChangedListener(myNameChangedListener); myNameSuggestionsField.getComponent().registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { completeVariable(myNameSuggestionsField.getEditor()); } }, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); }
public void testReplaceRegexp() throws Throwable { FindManager findManager = FindManager.getInstance(myProject); FindModel findModel = new FindModel(); findModel.setStringToFind("bug(?=here)"); findModel.setStringToReplace("x$0y"); findModel.setWholeWordsOnly(false); findModel.setFromCursor(false); findModel.setGlobal(true); findModel.setMultipleFiles(false); findModel.setProjectScope(true); findModel.setRegularExpressions(true); findModel.setPromptOnReplace(false); findManager.setFindNextModel(null); findManager.getFindInFileModel().copyFrom(findModel); String text = "bughere\n" + "bughere"; configureByText(PlainTextFileType.INSTANCE, text); boolean succ = FindUtil.replace(getProject(), getEditor(), 0, findModel); assertTrue(succ); assertEquals("xbugyhere\n" + "xbugyhere", getEditor().getDocument().getText()); }
public void testReplaceRegexp1() throws Throwable { FindManager findManager = FindManager.getInstance(myProject); FindModel findModel = new FindModel(); findModel.setStringToFind("bug(?=here)"); findModel.setStringToReplace("$0"); findModel.setWholeWordsOnly(false); findModel.setFromCursor(false); findModel.setGlobal(true); findModel.setMultipleFiles(false); findModel.setProjectScope(true); findModel.setRegularExpressions(true); findModel.setPromptOnReplace(false); findManager.setFindNextModel(null); findManager.getFindInFileModel().copyFrom(findModel); String text = "bughere\n" + "bughere"; configureByText(PlainTextFileType.INSTANCE, text); boolean succ = FindUtil.replace(getProject(), getEditor(), 0, findModel); assertTrue(succ); assertEquals(text, getEditor().getDocument().getText()); }
public void testReplaceRegexpWithNewLine() throws Throwable { FindManager findManager = FindManager.getInstance(myProject); FindModel findModel = new FindModel(); findModel.setStringToFind("xxx"); findModel.setStringToReplace("xxx\\n"); findModel.setWholeWordsOnly(false); findModel.setFromCursor(false); findModel.setGlobal(true); findModel.setMultipleFiles(false); findModel.setProjectScope(true); findModel.setRegularExpressions(true); findModel.setPromptOnReplace(false); findManager.setFindNextModel(null); findManager.getFindInFileModel().copyFrom(findModel); String text = "xxx"; configureByText(PlainTextFileType.INSTANCE, text); boolean succ = FindUtil.replace(getProject(), getEditor(), 0, findModel); assertTrue(succ); assertEquals(text+"\n", getEditor().getDocument().getText()); }
public void testWholeWordsInNonIndexedFiles() throws Exception { createFile(myModule, "A.test123", "foo fo foo"); // don't use createFile here because it creates PsiFile and runs file type autodetection // in real life some files might not be autodetected as plain text until the search starts VirtualFile custom = new WriteCommandAction<VirtualFile>(myProject) { @Override protected void run(@NotNull Result<VirtualFile> result) throws Throwable { File dir = createTempDirectory(); File file = new File(dir.getPath(), "A.test1234"); file.createNewFile(); FileUtil.writeToFile(file, "foo fo foo"); addSourceContentToRoots(myModule, VfsUtil.findFileByIoFile(dir, true)); result.setResult(VfsUtil.findFileByIoFile(file, true)); } }.execute().getResultObject(); assertNull(FileDocumentManager.getInstance().getCachedDocument(custom)); assertEquals(PlainTextFileType.INSTANCE, custom.getFileType()); FindModel findModel = new FindModel(); findModel.setWholeWordsOnly(true); findModel.setFromCursor(false); findModel.setGlobal(true); findModel.setMultipleFiles(true); findModel.setProjectScope(true); findModel.setStringToFind("fo"); assertSize(2, findUsages(findModel)); // and we should get the same with text loaded assertNotNull(FileDocumentManager.getInstance().getDocument(custom)); assertEquals(FileTypes.PLAIN_TEXT, custom.getFileType()); assertSize(2, findUsages(findModel)); }
@Override public void apply() throws ConfigurationException { if (myDocstringFormatComboBox.getSelectedItem() != myDocumentationSettings.getFormat()) { DaemonCodeAnalyzer.getInstance(myProject).restart(); } if (analyzeDoctest.isSelected() != myDocumentationSettings.isAnalyzeDoctest()) { final List<VirtualFile> files = Lists.newArrayList(); ProjectRootManager.getInstance(myProject).getFileIndex().iterateContent(new ContentIterator() { @Override public boolean processFile(VirtualFile fileOrDir) { if (!fileOrDir.isDirectory() && PythonFileType.INSTANCE.getDefaultExtension().equals(fileOrDir.getExtension())) { files.add(fileOrDir); } return true; } }); FileContentUtil.reparseFiles(myProject, Lists.newArrayList(files), false); } myModel.apply(); myDocumentationSettings.setFormat((DocStringFormat)myDocstringFormatComboBox.getSelectedItem()); final ReSTService reSTService = ReSTService.getInstance(myModule); reSTService.setWorkdir(myWorkDir.getText()); if (txtIsRst.isSelected() != reSTService.txtIsRst()) { reSTService.setTxtIsRst(txtIsRst.isSelected()); reparseFiles(Collections.singletonList(PlainTextFileType.INSTANCE.getDefaultExtension())); } myDocumentationSettings.setAnalyzeDoctest(analyzeDoctest.isSelected()); PyPackageRequirementsSettings.getInstance(myModule).setRequirementsPath(myRequirementsPathField.getText()); DaemonCodeAnalyzer.getInstance(myProject).restart(); }
@Override public void actionPerformed(AnActionEvent e) { logger.info("Gathering information for create paste"); // Gets the selected text Editor editor = e.getData(CommonDataKeys.EDITOR); // Default plain text FileType fileType = PlainTextFileType.INSTANCE; final Paste paste = new Paste(); // If there are something selected if (editor != null && editor.getSelectionModel().getSelectedText() != null) { logger.info("Using selected text as content"); paste.setContent(editor.getSelectionModel().getSelectedText()); } else { logger.info("No text selected, checking for files selected"); // Gets all the selected files VirtualFile[] selectedFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); // When there is multiple files selected, i do nothing if (selectedFiles != null && selectedFiles.length == 1 && !selectedFiles[0].isDirectory()) { final VirtualFile selectedFile = selectedFiles[0]; logger.info("Getting content from selected file: " + selectedFile); fileType = selectedFile.getFileType(); // Try to get the Highlight based on the file, if not found use the Text paste.setHighLight(UltimatePasteBinUtils.getHighlighFromVirtualFile(selectedFile).orElse(PasteHighLight.TEXT)); // Set the content of the selected file to paste UltimatePasteBinUtils.getFileContent(selectedFile).ifPresent(paste::setContent); } else { logger.info("Multiple files selected, ignoring"); } } CreatePasteForm.createAndShowForm(paste, e.getProject(), fileType); }
@Override @RequiredReadAction protected PsiFile createExpressionCodeFragment(@NotNull Project project, @NotNull String text, @Nullable PsiElement context, boolean isPhysical) { if(context == null) { XDebugSession session = mySession; XSourcePosition currentPosition = session == null ? null : session.getCurrentPosition(); if(currentPosition != null) { VirtualFile file = currentPosition.getFile(); PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if(psiFile != null) { context = psiFile.findElementAt(currentPosition.getOffset()); } } } DotNetDebuggerProvider debuggerProvider = context == null ? null : DotNetDebuggerProviders.findByPsiFile(context.getContainingFile()); if(debuggerProvider == null) { LightVirtualFile virtualFile = new LightVirtualFile("test.txt", PlainTextFileType.INSTANCE, text); return new PsiPlainTextFileImpl(new SingleRootFileViewProvider(PsiManager.getInstance(project), virtualFile, true)); } return debuggerProvider.createExpressionCodeFragment(project, context, text, isPhysical); }
private void doTest(final char c, @Nonnull String before, @Nonnull String expected) { myFixture.configureByText(PlainTextFileType.INSTANCE, before); final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction(); performAction(myFixture.getProject(), new Runnable() { @Override public void run() { typedAction.actionPerformed(myFixture.getEditor(), c, ((EditorEx)myFixture.getEditor()).getDataContext()); } }); myFixture.getEditor().getSelectionModel().removeSelection(); myFixture.checkResult(expected); }
@Override public void navigate(Project project) { Application.get().invokeLater(() -> { Document document = EditorFactory.getInstance().createDocument(StringUtil.convertLineSeparators(myText)); EditorTextField textField = new EditorTextField(document, project, PlainTextFileType.INSTANCE, true, false) { @Override protected EditorEx createEditor() { EditorEx editor = super.createEditor(); editor.getScrollPane().setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); editor.getScrollPane().setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); editor.getSettings().setUseSoftWraps(true); return editor; } }; JFrame frame = WindowManager.getInstance().getFrame(project); if(frame != null) { Dimension size = frame.getSize(); if(size != null) { textField.setPreferredSize(new Dimension(size.width / 2, size.height / 2)); } } JBPopupFactory.getInstance() .createComponentPopupBuilder(textField, textField) .setTitle(myTitle) .setResizable(true) .setMovable(true) .setRequestFocus(true) .createPopup() .showCenteredInCurrentWindow(project); }); }
@Override @Nonnull public FileType getFileType() { PsiElement context = getContext(); if (context != null) { PsiFile containingFile = context.getContainingFile(); if (containingFile != null) return containingFile.getFileType(); } final LanguageFileType fileType = myLanguage.getAssociatedFileType(); return fileType != null ? fileType : PlainTextFileType.INSTANCE; }
public TextViewer(@Nonnull Document document, @Nonnull Project project, boolean embeddedIntoDialogWrapper, boolean useSoftWraps) { super(document, project, PlainTextFileType.INSTANCE, true, false); myEmbeddedIntoDialogWrapper = embeddedIntoDialogWrapper; myUseSoftWraps = useSoftWraps; setFontInheritedFromLAF(false); }
public static FileChooserDescriptor createSelectPatchDescriptor() { return new FileChooserDescriptor(true, false, false, false, false, false) { @Override public boolean isFileSelectable(VirtualFile file) { return file.getFileType() == PatchFileType.INSTANCE || file.getFileType() == PlainTextFileType.INSTANCE; } }; }
public MyEditorComboBox(Project project) { super(PREF_WIDTH); setEditor(new StringComboboxEditor(project, PlainTextFileType.INSTANCE, this) { @Override protected void onEditorCreate(EditorEx editor) { super.onEditorCreate(editor); getDocument().putUserData(CONTINUE_RUN_COMPLETION, true); } }); }
private void initEditor() { if (myEditor == null) { myPreviewEditorPanel.removeAll(); EditorFactory editorFactory = EditorFactory.getInstance(); myDocument = editorFactory.createDocument(""); myEditor = editorFactory.createEditor(myDocument, myProject, ObjectUtil.notNull(myFileType, PlainTextFileType.INSTANCE), true); CopyrightConfigurable.setupEditor(myEditor); myPreviewEditorPanel.add(myEditor.getComponent(), BorderLayout.CENTER); } }