Search in sources :

Example 56 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.

the class XBreakpointItem method removed.

@Override
public void removed(Project project) {
    final XBreakpointManagerImpl breakpointManager = getManager();
    new WriteAction() {

        @Override
        protected void run(@NotNull final Result result) {
            breakpointManager.removeBreakpoint(myBreakpoint);
        }
    }.execute();
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) Result(com.intellij.openapi.application.Result)

Example 57 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.

the class EditorUtil method fillVirtualSpaceUntil.

public static void fillVirtualSpaceUntil(@NotNull final Editor editor, int columnNumber, int lineNumber) {
    final int offset = editor.logicalPositionToOffset(new LogicalPosition(lineNumber, columnNumber));
    final String filler = EditorModificationUtil.calcStringToFillVirtualSpace(editor);
    if (!filler.isEmpty()) {
        new WriteAction() {

            @Override
            protected void run(@NotNull Result result) throws Throwable {
                editor.getDocument().insertString(offset, filler);
                editor.getCaretModel().moveToOffset(offset + filler.length());
            }
        }.execute();
    }
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) Result(com.intellij.openapi.application.Result)

Example 58 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.

the class VirtualFileListenerTest method testFireEvent.

@Test
public void testFireEvent() throws IOException {
    VirtualFile dir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(myTempDir.newFolder("vDir"));
    assertNotNull(dir);
    dir.getChildren();
    Ref<Boolean> eventFired = Ref.create(false);
    VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() {

        @Override
        public void fileCreated(@NotNull VirtualFileEvent event) {
            eventFired.set(true);
        }
    }, getTestRootDisposable());
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws IOException {
            dir.createChildData(this, "x.txt");
        }
    }.execute();
    assertTrue(eventFired.get());
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) IOException(java.io.IOException) Result(com.intellij.openapi.application.Result) Test(org.junit.Test)

Example 59 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.

the class VfsUtilTest method testPresentableUrlSurvivesDeletion.

@Test
public void testPresentableUrlSurvivesDeletion() throws IOException {
    VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(myTempDir.newFile("file.txt"));
    assertNotNull(file);
    String url = file.getPresentableUrl();
    assertNotNull(url);
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws IOException {
            file.delete(this);
        }
    }.execute();
    assertEquals(url, file.getPresentableUrl());
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) IOException(java.io.IOException) Result(com.intellij.openapi.application.Result) Test(org.junit.Test)

Example 60 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.

the class RemoteFileInfoImpl method finished.

@Override
public void finished(@Nullable final FileType fileType) {
    final File localIOFile;
    synchronized (myLock) {
        LOG.debug("Downloading finished, size = " + myLocalFile.length() + ", file type=" + (fileType != null ? fileType.getName() : "null"));
        if (fileType != null) {
            String fileName = myLocalFile.getName();
            int dot = fileName.lastIndexOf('.');
            String extension = fileType.getDefaultExtension();
            if (dot == -1 || !extension.regionMatches(true, 0, fileName, dot + 1, extension.length())) {
                File newFile = FileUtil.findSequentNonexistentFile(myLocalFile.getParentFile(), fileName, extension);
                try {
                    FileUtil.rename(myLocalFile, newFile);
                    myLocalFile = newFile;
                } catch (IOException e) {
                    LOG.debug(e);
                }
            }
        }
        localIOFile = myLocalFile;
    }
    VirtualFile localFile = new WriteAction<VirtualFile>() {

        @Override
        protected void run(@NotNull final Result<VirtualFile> result) {
            final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(localIOFile);
            if (file != null) {
                file.refresh(false, false);
            }
            result.setResult(file);
        }
    }.execute().getResultObject();
    LOG.assertTrue(localFile != null, "Virtual local file not found for " + localIOFile.getAbsolutePath());
    LOG.debug("Virtual local file: " + localFile + ", size = " + localFile.getLength());
    synchronized (myLock) {
        myLocalVirtualFile = localFile;
        myPrevLocalFile = null;
        myState = RemoteFileState.DOWNLOADED;
        myErrorMessage = null;
    }
    for (FileDownloadingListener listener : myListeners) {
        listener.fileDownloaded(localFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Aggregations

Result (com.intellij.openapi.application.Result)85 WriteAction (com.intellij.openapi.application.WriteAction)85 NotNull (org.jetbrains.annotations.NotNull)38 VirtualFile (com.intellij.openapi.vfs.VirtualFile)37 File (java.io.File)20 IOException (java.io.IOException)16 Module (com.intellij.openapi.module.Module)10 PsiFile (com.intellij.psi.PsiFile)7 Sdk (com.intellij.openapi.projectRoots.Sdk)5 RunResult (com.intellij.openapi.application.RunResult)4 Document (com.intellij.openapi.editor.Document)4 Project (com.intellij.openapi.project.Project)4 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)4 Library (com.intellij.openapi.roots.libraries.Library)4 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)4 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 FacetManager (com.intellij.facet.FacetManager)2 ProjectFacetManager (com.intellij.facet.ProjectFacetManager)2