Search in sources :

Example 11 with CalledInAwt

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

the class VcsDiffUtil method showChangesDialog.

@CalledInAwt
public static void showChangesDialog(@NotNull Project project, @NotNull String title, @NotNull List<Change> changes) {
    DialogBuilder dialogBuilder = new DialogBuilder(project);
    dialogBuilder.setTitle(title);
    dialogBuilder.setActionDescriptors(new DialogBuilder.CloseDialogAction());
    final ChangesBrowser changesBrowser = new ChangesBrowser(project, null, changes, null, false, true, null, ChangesBrowser.MyUseCase.COMMITTED_CHANGES, null);
    changesBrowser.setChangesToDisplay(changes);
    dialogBuilder.setCenterPanel(changesBrowser);
    dialogBuilder.setPreferredFocusComponent(changesBrowser.getPreferredFocusedComponent());
    dialogBuilder.setDimensionServiceKey("VcsDiffUtil.ChangesDialog");
    dialogBuilder.showNotModal();
}
Also used : ChangesBrowser(com.intellij.openapi.vcs.changes.ui.ChangesBrowser) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Example 12 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 13 with CalledInAwt

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

the class AnnotateStackTraceAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    myIsLoading = true;
    ProgressManager.getInstance().run(new Task.Backgroundable(myEditor.getProject(), "Getting File History", true) {

        private final Object LOCK = new Object();

        private final MergingUpdateQueue myUpdateQueue = new MergingUpdateQueue("AnnotateStackTraceAction", 200, true, null);

        private MyActiveAnnotationGutter myGutter;

        @Override
        public void onCancel() {
            myEditor.getGutter().closeAllAnnotations();
        }

        @Override
        public void onFinished() {
            myIsLoading = false;
            Disposer.dispose(myUpdateQueue);
        }

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            MultiMap<VirtualFile, Integer> files2lines = new MultiMap<>();
            Map<Integer, LastRevision> revisions = ContainerUtil.newHashMap();
            ApplicationManager.getApplication().runReadAction(() -> {
                for (int line = 0; line < myEditor.getDocument().getLineCount(); line++) {
                    indicator.checkCanceled();
                    VirtualFile file = getHyperlinkVirtualFile(myHyperlinks.findAllHyperlinksOnLine(line));
                    if (file == null)
                        continue;
                    files2lines.putValue(file, line);
                }
            });
            files2lines.entrySet().forEach(entry -> {
                indicator.checkCanceled();
                VirtualFile file = entry.getKey();
                Collection<Integer> lines = entry.getValue();
                LastRevision revision = getLastRevision(file);
                if (revision == null)
                    return;
                synchronized (LOCK) {
                    for (Integer line : lines) {
                        revisions.put(line, revision);
                    }
                }
                myUpdateQueue.queue(new Update("update") {

                    @Override
                    public void run() {
                        updateGutter(indicator, revisions);
                    }
                });
            });
            // myUpdateQueue can be disposed before the last revisions are passed to the gutter
            ApplicationManager.getApplication().invokeLater(() -> updateGutter(indicator, revisions));
        }

        @CalledInAwt
        private void updateGutter(@NotNull ProgressIndicator indicator, @NotNull Map<Integer, LastRevision> revisions) {
            if (indicator.isCanceled())
                return;
            if (myGutter == null) {
                myGutter = new MyActiveAnnotationGutter(getProject(), myHyperlinks, indicator);
                myEditor.getGutter().registerTextAnnotation(myGutter, myGutter);
            }
            Map<Integer, LastRevision> revisionsCopy;
            synchronized (LOCK) {
                revisionsCopy = ContainerUtil.newHashMap(revisions);
            }
            myGutter.updateData(revisionsCopy);
            ((EditorGutterComponentEx) myEditor.getGutter()).revalidateMarkup();
        }

        @Nullable
        private LastRevision getLastRevision(@NotNull VirtualFile file) {
            try {
                AbstractVcs vcs = VcsUtil.getVcsFor(myEditor.getProject(), file);
                if (vcs == null)
                    return null;
                VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
                if (historyProvider == null)
                    return null;
                FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
                if (historyProvider instanceof VcsHistoryProviderEx) {
                    VcsFileRevision revision = ((VcsHistoryProviderEx) historyProvider).getLastRevision(filePath);
                    if (revision == null)
                        return null;
                    return LastRevision.create(revision);
                } else {
                    VcsHistorySession session = historyProvider.createSessionFor(filePath);
                    if (session == null)
                        return null;
                    List<VcsFileRevision> list = session.getRevisionList();
                    if (list == null || list.isEmpty())
                        return null;
                    return LastRevision.create(list.get(0));
                }
            } catch (VcsException ignored) {
                LOG.warn(ignored);
                return null;
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) DateFormatUtil(com.intellij.util.text.DateFormatUtil) java.util(java.util) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileHyperlinkInfo(com.intellij.execution.filters.FileHyperlinkInfo) EditorHyperlinkSupport(com.intellij.execution.impl.EditorHyperlinkSupport) EditorFontType(com.intellij.openapi.editor.colors.EditorFontType) ContainerUtil(com.intellij.util.containers.ContainerUtil) ActiveAnnotationGutter(com.intellij.openapi.vcs.actions.ActiveAnnotationGutter) ShowAllAffectedGenericAction(com.intellij.openapi.vcs.annotate.ShowAllAffectedGenericAction) VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) Task(com.intellij.openapi.progress.Task) ColorKey(com.intellij.openapi.editor.colors.ColorKey) VcsContextFactory(com.intellij.openapi.vcs.actions.VcsContextFactory) AnnotationSource(com.intellij.openapi.vcs.annotate.AnnotationSource) CalledWithReadLock(org.jetbrains.annotations.CalledWithReadLock) Disposer(com.intellij.openapi.util.Disposer) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) EditorGutterComponentEx(com.intellij.openapi.editor.ex.EditorGutterComponentEx) com.intellij.openapi.vcs(com.intellij.openapi.vcs) MultiMap(com.intellij.util.containers.MultiMap) CalledInAwt(org.jetbrains.annotations.CalledInAwt) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) ProgressManager(com.intellij.openapi.progress.ProgressManager) VcsUtil(com.intellij.vcsUtil.VcsUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) AnAction(com.intellij.openapi.actionSystem.AnAction) VcsHistoryProvider(com.intellij.openapi.vcs.history.VcsHistoryProvider) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Editor(com.intellij.openapi.editor.Editor) VcsHistoryProviderEx(com.intellij.vcs.history.VcsHistoryProviderEx) MergingUpdateQueue(com.intellij.util.ui.update.MergingUpdateQueue) java.awt(java.awt) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Update(com.intellij.util.ui.update.Update) List(java.util.List) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) XmlStringUtil(com.intellij.xml.util.XmlStringUtil) NotNull(org.jetbrains.annotations.NotNull) Task(com.intellij.openapi.progress.Task) CalledInAwt(org.jetbrains.annotations.CalledInAwt) VcsHistoryProvider(com.intellij.openapi.vcs.history.VcsHistoryProvider) Update(com.intellij.util.ui.update.Update) MultiMap(com.intellij.util.containers.MultiMap) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsHistoryProviderEx(com.intellij.vcs.history.VcsHistoryProviderEx) VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) List(java.util.List) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) MergingUpdateQueue(com.intellij.util.ui.update.MergingUpdateQueue) MultiMap(com.intellij.util.containers.MultiMap) Nullable(org.jetbrains.annotations.Nullable)

Example 14 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 15 with CalledInAwt

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

the class BackgroundTaskUtil method executeAndTryWait.

@NotNull
@CalledInAwt
public static ProgressIndicator executeAndTryWait(@NotNull Function<ProgressIndicator, /*@NotNull*/
Runnable> backgroundTask, @Nullable Runnable onSlowAction, long waitMillis, boolean forceEDT) {
    ModalityState modality = ModalityState.current();
    if (forceEDT) {
        ProgressIndicator indicator = new EmptyProgressIndicator(modality);
        try {
            Runnable callback = backgroundTask.fun(indicator);
            finish(callback, indicator);
        } catch (ProcessCanceledException ignore) {
        } catch (Throwable t) {
            LOG.error(t);
        }
        return indicator;
    } else {
        Pair<Runnable, ProgressIndicator> pair = computeInBackgroundAndTryWait(backgroundTask, (callback, indicator) -> {
            ApplicationManager.getApplication().invokeLater(() -> {
                finish(callback, indicator);
            }, modality);
        }, modality, waitMillis);
        Runnable callback = pair.first;
        ProgressIndicator indicator = pair.second;
        if (callback != null) {
            finish(callback, indicator);
        } else {
            if (onSlowAction != null)
                onSlowAction.run();
        }
        return indicator;
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModalityState(com.intellij.openapi.application.ModalityState) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) CalledInAwt(org.jetbrains.annotations.CalledInAwt) NotNull(org.jetbrains.annotations.NotNull)

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