Search in sources :

Example 6 with CalledInAwt

use of org.jetbrains.annotations.CalledInAwt in project intellij-community by JetBrains.

the class DvcsUtil method getSelectedFile.

/**
   * Returns the currently selected file, based on which VcsBranch or StatusBar components will identify the current repository root.
   */
@Nullable
@CalledInAwt
public static VirtualFile getSelectedFile(@NotNull Project project) {
    StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
    final FileEditor fileEditor = StatusBarUtil.getCurrentFileEditor(project, statusBar);
    VirtualFile result = null;
    if (fileEditor != null) {
        if (fileEditor instanceof TextEditor) {
            Document document = ((TextEditor) fileEditor).getEditor().getDocument();
            result = FileDocumentManager.getInstance().getFile(document);
        } else if (fileEditor instanceof ImageFileEditor) {
            result = ((ImageFileEditor) fileEditor).getImageEditor().getFile();
        }
    }
    if (result == null) {
        final FileEditorManager manager = FileEditorManager.getInstance(project);
        if (manager != null) {
            Editor editor = manager.getSelectedTextEditor();
            if (editor != null) {
                result = FileDocumentManager.getInstance().getFile(editor.getDocument());
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ImageFileEditor(org.intellij.images.editor.ImageFileEditor) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ImageFileEditor(org.intellij.images.editor.ImageFileEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Document(com.intellij.openapi.editor.Document) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ImageFileEditor(org.intellij.images.editor.ImageFileEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor) StatusBar(com.intellij.openapi.wm.StatusBar) CalledInAwt(org.jetbrains.annotations.CalledInAwt) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with CalledInAwt

use of org.jetbrains.annotations.CalledInAwt in project intellij-community by JetBrains.

the class SimpleOnesideDiffViewer method onDispose.

@Override
@CalledInAwt
protected void onDispose() {
    for (RangeHighlighter highlighter : myHighlighters) {
        highlighter.dispose();
    }
    myHighlighters.clear();
    super.onDispose();
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Example 8 with CalledInAwt

use of org.jetbrains.annotations.CalledInAwt in project intellij-community by JetBrains.

the class PatchApplier method executePatchGroup.

@CalledInAwt
public static ApplyPatchStatus executePatchGroup(final Collection<PatchApplier> group, final LocalChangeList localChangeList) {
    //?
    if (group.isEmpty())
        return ApplyPatchStatus.SUCCESS;
    final Project project = group.iterator().next().myProject;
    ApplyPatchStatus result = ApplyPatchStatus.SUCCESS;
    for (PatchApplier patchApplier : group) {
        result = ApplyPatchStatus.and(result, patchApplier.nonWriteActionPreCheck());
    }
    final Label beforeLabel = LocalHistory.getInstance().putSystemLabel(project, "Before patch");
    final TriggerAdditionOrDeletion trigger = new TriggerAdditionOrDeletion(project);
    final Ref<ApplyPatchStatus> refStatus = new Ref<>(result);
    try {
        CommandProcessor.getInstance().executeCommand(project, new Runnable() {

            @Override
            public void run() {
                for (PatchApplier applier : group) {
                    refStatus.set(ApplyPatchStatus.and(refStatus.get(), applier.createFiles()));
                    applier.addSkippedItems(trigger);
                }
                trigger.prepare();
                if (refStatus.get() == ApplyPatchStatus.SUCCESS) {
                    // all pre-check results are valuable only if not successful; actual status we can receive after executeWritable
                    refStatus.set(null);
                }
                for (PatchApplier applier : group) {
                    refStatus.set(ApplyPatchStatus.and(refStatus.get(), applier.executeWritable()));
                    if (refStatus.get() == ApplyPatchStatus.ABORT)
                        break;
                }
            }
        }, VcsBundle.message("patch.apply.command"), null);
    } finally {
        VcsFileListenerContextHelper.getInstance(project).clearContext();
        LocalHistory.getInstance().putSystemLabel(project, "After patch");
    }
    result = refStatus.get();
    result = result == null ? ApplyPatchStatus.FAILURE : result;
    trigger.processIt();
    final Set<FilePath> directlyAffected = new HashSet<>();
    final Set<VirtualFile> indirectlyAffected = new HashSet<>();
    for (PatchApplier applier : group) {
        directlyAffected.addAll(applier.getDirectlyAffected());
        indirectlyAffected.addAll(applier.getIndirectlyAffected());
    }
    directlyAffected.addAll(trigger.getAffected());
    final Consumer<Collection<FilePath>> mover = localChangeList == null ? null : createMover(project, localChangeList);
    refreshPassedFilesAndMoveToChangelist(project, directlyAffected, indirectlyAffected, mover);
    if (result == ApplyPatchStatus.FAILURE) {
        suggestRollback(project, group, beforeLabel);
    } else if (result == ApplyPatchStatus.ABORT) {
        rollbackUnderProgress(project, project.getBaseDir(), beforeLabel);
    }
    showApplyStatus(project, result);
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ApplyPatchStatus(com.intellij.openapi.diff.impl.patch.ApplyPatchStatus) Label(com.intellij.history.Label) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Example 9 with CalledInAwt

use of org.jetbrains.annotations.CalledInAwt in project intellij-community by JetBrains.

the class PathsVerifier method nonWriteActionPreCheck.

@CalledInAwt
public List<FilePatch> nonWriteActionPreCheck() {
    List<FilePatch> failedToApply = ContainerUtil.newArrayList();
    myDelayedPrecheckContext = new DelayedPrecheckContext(myProject);
    for (FilePatch patch : myPatches) {
        final CheckPath checker = getChecker(patch);
        if (!checker.canBeApplied(myDelayedPrecheckContext)) {
            revert(checker.getErrorMessage());
            failedToApply.add(patch);
        }
    }
    final Collection<FilePatch> skipped = myDelayedPrecheckContext.doDelayed();
    mySkipped.addAll(skipped);
    myPatches.removeAll(skipped);
    myPatches.removeAll(failedToApply);
    return failedToApply;
}
Also used : ShelvedBinaryFilePatch(com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryFilePatch) BinaryFilePatch(com.intellij.openapi.diff.impl.patch.BinaryFilePatch) ApplyTextFilePatch(com.intellij.openapi.diff.impl.patch.apply.ApplyTextFilePatch) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Example 10 with CalledInAwt

use of org.jetbrains.annotations.CalledInAwt in project intellij-community by JetBrains.

the class PatchApplier method refreshPassedFilesAndMoveToChangelist.

@CalledInAwt
public static void refreshPassedFilesAndMoveToChangelist(@NotNull final Project project, final Collection<FilePath> directlyAffected, final Collection<VirtualFile> indirectlyAffected, final Consumer<Collection<FilePath>> targetChangelistMover) {
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    for (FilePath filePath : directlyAffected) {
        lfs.refreshAndFindFileByIoFile(filePath.getIOFile());
    }
    if (project.isDisposed())
        return;
    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    if (!directlyAffected.isEmpty() && targetChangelistMover != null) {
        changeListManager.invokeAfterUpdate(new Runnable() {

            @Override
            public void run() {
                targetChangelistMover.consume(directlyAffected);
            }
        }, InvokeAfterUpdateMode.SYNCHRONOUS_CANCELLABLE, VcsBundle.message("change.lists.manager.move.changes.to.list"), new Consumer<VcsDirtyScopeManager>() {

            @Override
            public void consume(final VcsDirtyScopeManager vcsDirtyScopeManager) {
                markDirty(vcsDirtyScopeManager, directlyAffected, indirectlyAffected);
            }
        }, null);
    } else {
        markDirty(VcsDirtyScopeManager.getInstance(project), directlyAffected, indirectlyAffected);
    }
}
Also used : LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Aggregations

CalledInAwt (org.jetbrains.annotations.CalledInAwt)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Project (com.intellij.openapi.project.Project)5 NotNull (org.jetbrains.annotations.NotNull)5 FileEditor (com.intellij.openapi.fileEditor.FileEditor)4 Nullable (org.jetbrains.annotations.Nullable)4 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)3 StatusBar (com.intellij.openapi.wm.StatusBar)3 SyncScrollSupport (com.intellij.diff.tools.util.SyncScrollSupport)2 TextDiffViewerUtil (com.intellij.diff.tools.util.base.TextDiffViewerUtil)2 Document (com.intellij.openapi.editor.Document)2 Editor (com.intellij.openapi.editor.Editor)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 EditorNotificationPanel (com.intellij.ui.EditorNotificationPanel)2 List (java.util.List)2 MessageDiffRequest (com.intellij.diff.requests.MessageDiffRequest)1 ThreesideSyncScrollSupport (com.intellij.diff.tools.util.SyncScrollSupport.ThreesideSyncScrollSupport)1 TwosideSyncScrollSupport (com.intellij.diff.tools.util.SyncScrollSupport.TwosideSyncScrollSupport)1