public void run() { ApplicationManager.getApplication().runWriteAction(cmd); } }
private void autoImport(@NotNull InsertionContext context, @Nullable String organization, @NotNull String packageName, @Nullable String alias) { PsiFile file = context.getFile(); final String importPath = organization == null ? packageName : organization + "/" + packageName; ApplicationManager.getApplication().runWriteAction(() -> { BallerinaFile.addImport(((BallerinaFile) file), importPath, alias); }); }
/** * Invoked after a tree has changed. * * @param event the event object specifying changed nodes */ @Override public void treeNodesChanged(@NotNull TreeModelEvent event) { final String text = getCommandsText(); ApplicationManager.getApplication().runWriteAction(() -> commandsDocument.setText(text)); } };
private void writeInternalErlangSdk(@NotNull SdkModificator sdkModificator, @Nullable Sdk erlangSdk) { SdkAdditionalData sdkAdditionData = new SdkAdditionalData( erlangSdk, elixirSdk ); sdkModificator.setSdkAdditionalData(sdkAdditionData); ApplicationManager.getApplication().runWriteAction(sdkModificator::commitChanges); ((ProjectJdkImpl) elixirSdk).resetVersionString(); }
private void perform(@NotNull PsiFile file, @Nullable String pathToImport) { if (file instanceof GoFile && pathToImport != null) { Project project = file.getProject(); CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> { if (!isAvailable()) return; if (((GoFile)file).getImportedPackagesMap().containsKey(pathToImport)) return; ((GoFile)file).addImport(pathToImport, null); }), "Add import", null); } }
@NotNull private VirtualFile createTestRoot(@NotNull String rootName) throws IOException { return ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<VirtualFile, IOException>() { @NotNull @Override public VirtualFile compute() throws IOException { VirtualFile workingDirectory = myFixture.getTempDirFixture().findOrCreateDir(rootName); workingDirectory.createChildData(this, rootName + ".go"); VirtualFile childDirectory = workingDirectory.createChildDirectory(this, "src"); childDirectory.createChildData(this, "nested" + Character.toUpperCase(rootName.charAt(0)) + rootName.substring(1) + ".go"); return workingDirectory; } }); } }
@Override public void chooseAndSetSdk(@Nullable Module module) { Sdk projectSdk = ProjectSettingsService.getInstance(myProject).chooseAndSetSdk(); if (projectSdk == null && module != null) { ApplicationManager.getApplication().runWriteAction(() -> { if (!module.isDisposed()) { ModuleRootModificationUtil.setSdkInherited(module); } }); } }
private static void deleteFile(@NotNull PsiFile referenceFile) throws IOException { ApplicationManager.getApplication().runWriteAction( new ThrowableComputable<Void, IOException>() { @Override public Void compute() throws IOException { referenceFile.getVirtualFile().delete(this); return null; } } ); }
@NotNull @Override protected GoRunFileRunningState newRunningState(@NotNull ExecutionEnvironment env, @NotNull Module module) { String path = getFilePath(); if (!"go".equals(PathUtil.getFileExtension(path))) { VirtualFile f = LocalFileSystem.getInstance().refreshAndFindFileByPath(path); if (f != null && f.getFileType() == ScratchFileType.INSTANCE) { String suffixWithoutExt = "." + UUID.randomUUID().toString().substring(0, 4); String suffix = suffixWithoutExt + ".go"; String before = f.getName(); String beforeWithoutExt = FileUtil.getNameWithoutExtension(before); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { try { f.rename(this, before + suffix); } catch (IOException ignored) { } } }); setFilePath(path + suffix); setName(getName().replace(beforeWithoutExt, beforeWithoutExt + suffixWithoutExt)); } } return new GoRunFileRunningState(env, module, this); } }
private void performImport(BallerinaFile file, String importPath) { // Important: Need to call runWriteAction since this is called from the swing thread. Runnable addImport = () -> BallerinaFile.addImport(file, importPath, null); CommandProcessor.getInstance().runUndoTransparentAction( () -> ApplicationManager.getApplication().runWriteAction(addImport) ); } }
/** * Sets new content to the editor component. * * @param content new content */ public void setContent(@NotNull final String content) { ApplicationManager.getApplication().runWriteAction( () -> CommandProcessor.getInstance().runUndoTransparentAction( () -> previewDocument.replaceString(0, previewDocument.getTextLength(), content) ) ); } }
@Override public void chooseAndSetSdk(@Nullable Module module) { Sdk projectSdk = ProjectSettingsService.getInstance(myProject).chooseAndSetSdk(); if (projectSdk == null && module != null) { ApplicationManager.getApplication().runWriteAction(() -> { if (!module.isDisposed()) { ModuleRootModificationUtil.setSdkInherited(module); } }); } // Need to prompt a restart action to clear and re initiate language server instance from the new SDK. // Todo - Figure out a way to apply language server changes without restarting. if (isBallerinaSdk(projectSdk)) { ApplicationManager.getApplication().invokeLater(this::showRestartDialog); } }
/** * This processes all "regular" keystrokes entered while in insert/replace mode * * @param editor The editor the character was typed into * @param context The data context * @param key The user entered keystroke * @return true if this was a regular character, false if not */ public boolean processKey(@NotNull final Editor editor, @NotNull final DataContext context, @NotNull final KeyStroke key) { if (logger.isDebugEnabled()) { logger.debug("processKey(" + key + ")"); } if (key.getKeyChar() != KeyEvent.CHAR_UNDEFINED) { final Document doc = editor.getDocument(); CommandProcessor.getInstance().executeCommand(editor.getProject(), () -> ApplicationManager.getApplication().runWriteAction( () -> KeyHandler.getInstance().getOriginalHandler().execute( editor, key.getKeyChar(), context)), "", doc, UndoConfirmationPolicy.DEFAULT, doc); return true; } return false; }
@Override public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext) { if (myOriginalHandler != null) myOriginalHandler.execute(editor, c, dataContext); if (c != 'e') return; Project project = editor.getProject(); if (project == null) return; int offset = editor.getCaretModel().getOffset(); if (offset < 4) return; TextRange from = TextRange.from(offset - 4, 4); String text = editor.getDocument().getText(from); if ("case".equals(text)) { PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); ApplicationManager.getApplication().runWriteAction(() -> { if (project.isDisposed()) return; PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project); if (file == null) return; CodeStyleManager.getInstance(project).adjustLineIndent(file, from); }); } } }
private void removeLibraryIfNeeded() { ApplicationManager.getApplication().assertIsDispatchThread(); ModifiableModelsProvider modelsProvider = ModifiableModelsProvider.SERVICE.getInstance(); ModifiableRootModel model = modelsProvider.getModuleModifiableModel(myModule); LibraryOrderEntry goLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName()); if (goLibraryEntry != null) { ApplicationManager.getApplication().runWriteAction(() -> { Library library = goLibraryEntry.getLibrary(); if (library != null) { LibraryTable table = library.getTable(); if (table != null) { table.removeLibrary(library); model.removeOrderEntry(goLibraryEntry); modelsProvider.commitModuleModifiableModel(model); } } else { modelsProvider.disposeModuleModifiableModel(model); } }); } else { ApplicationManager.getApplication().runWriteAction(() -> modelsProvider.disposeModuleModifiableModel(model)); } }
@Override public void handleInsert(@NotNull InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); CharSequence documentText = context.getDocument().getImmutableCharSequence(); int offset = skipWhiteSpaces(editor.getCaretModel().getOffset(), documentText); if (documentText.charAt(offset) != '{') { Project project = context.getProject(); Template template = TemplateManager.getInstance(project).createTemplate("braces", "go", myOneLine ? "{$END$}" : " {\n$END$\n}"); template.setToReformat(true); TemplateManager.getInstance(project).startTemplate(editor, template); } else { editor.getCaretModel().moveToOffset(offset); ApplicationManager.getApplication().runWriteAction(() -> { EditorActionHandler enterAction = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_START_NEW_LINE); enterAction.execute(editor, editor.getCaretModel().getCurrentCaret(), ((EditorEx)editor).getDataContext()); }); } }
private void attachLibraries(@NotNull Collection<VirtualFile> libraryRoots, Set<VirtualFile> exclusions) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!libraryRoots.isEmpty()) { ApplicationManager.getApplication().runWriteAction(() -> { ModuleRootManager model = ModuleRootManager.getInstance(myModule); LibraryOrderEntry goLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName()); if (goLibraryEntry != null && goLibraryEntry.isValid()) { Library library = goLibraryEntry.getLibrary(); if (library != null && !((LibraryEx)library).isDisposed()) { fillLibrary(library, libraryRoots, exclusions); } } else { LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myModule.getProject()); Library library = libraryTable.createLibrary(getLibraryName()); fillLibrary(library, libraryRoots, exclusions); ModuleRootModificationUtil.addDependency(myModule, library); } }); showNotification(myModule.getProject()); } else { removeLibraryIfNeeded(); } }
private void setUpProjectSdk() { ApplicationManager.getApplication().runWriteAction(() -> { Sdk sdk = getProjectDescriptor().getSdk(); ProjectJdkTable.getInstance().addJdk(sdk); ProjectRootManager.getInstance(myFixture.getProject()).setProjectSdk(sdk); }); }
protected void setUpProjectSdk() { ApplicationManager.getApplication().runWriteAction(() -> { Sdk sdk = getProjectDescriptor().getSdk(); ProjectJdkTable.getInstance().addJdk(sdk); ProjectRootManager.getInstance(myFixture.getProject()).setProjectSdk(sdk); }); }
private void doTest() { PsiFile file = myFixture.configureByFile(getTestName(true) + ".go"); resolveAllReferences(file); myFixture.checkHighlighting(); ApplicationManager.getApplication().runWriteAction( () -> OptimizeImportsAction.actionPerformedImpl(DataManager.getInstance().getDataContext(myFixture.getEditor().getContentComponent()))); myFixture.checkResultByFile(getTestName(true) + "_after.go"); }