From 3569c4d1a22669dc2beb1157b342ab4c00dfda80 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 25 Dec 2017 16:27:27 +0300 Subject: [PATCH] lst: pass Editor to RangeMarkerAction Check, that editor is not disposed yet: EA-114231 - TDDE: TraceableDisposable.throwDisposalError --- .../intellij/diff/merge/TextMergeViewer.java | 4 +- .../vcs/ex/LineStatusMarkerPopupRenderer.java | 50 +++++++++---------- .../openapi/vcs/ex/LineStatusTracker.kt | 12 ++--- .../vcs/ex/PartialLocalLineStatusTracker.kt | 8 +-- 4 files changed, 35 insertions(+), 39 deletions(-) diff --git a/platform/diff-impl/src/com/intellij/diff/merge/TextMergeViewer.java b/platform/diff-impl/src/com/intellij/diff/merge/TextMergeViewer.java index 59b45262d0c7..5dde5c0b55c6 100644 --- a/platform/diff-impl/src/com/intellij/diff/merge/TextMergeViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/merge/TextMergeViewer.java @@ -1320,8 +1320,8 @@ public class TextMergeViewer implements MergeTool.MergeViewer { List actions = new ArrayList<>(); actions.add(new ShowPrevChangeMarkerAction(editor, range)); actions.add(new ShowNextChangeMarkerAction(editor, range)); - actions.add(new ShowLineStatusRangeDiffAction(range)); - actions.add(new CopyLineStatusRangeAction(range)); + actions.add(new ShowLineStatusRangeDiffAction(editor, range)); + actions.add(new CopyLineStatusRangeAction(editor, range)); actions.add(new ToggleByWordDiffAction(editor, range, mousePosition)); return actions; } diff --git a/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusMarkerPopupRenderer.java b/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusMarkerPopupRenderer.java index 42053bd19978..b97c81d07059 100644 --- a/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusMarkerPopupRenderer.java +++ b/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusMarkerPopupRenderer.java @@ -418,98 +418,94 @@ public abstract class LineStatusMarkerPopupRenderer extends LineStatusMarkerRend protected abstract class RangeMarkerAction extends DumbAwareAction { @NotNull private final Range myRange; + @NotNull private final Editor myEditor; - public RangeMarkerAction(@NotNull Range range, @NotNull String actionId) { + public RangeMarkerAction(@NotNull Editor editor, @NotNull Range range, @NotNull String actionId) { myRange = range; + myEditor = editor; ActionUtil.copyFrom(this, actionId); } @Override public void update(AnActionEvent e) { Range newRange = myTracker.findRange(myRange); - e.getPresentation().setEnabled(newRange != null && isEnabled(newRange)); + e.getPresentation().setEnabled(newRange != null && !myEditor.isDisposed() && isEnabled(myEditor, newRange)); } @Override public void actionPerformed(AnActionEvent e) { Range newRange = myTracker.findRange(myRange); - if (newRange != null) actionPerformed(newRange); + if (newRange != null) actionPerformed(myEditor, newRange); } - protected abstract boolean isEnabled(@NotNull Range range); + protected abstract boolean isEnabled(@NotNull Editor editor, @NotNull Range range); - protected abstract void actionPerformed(@NotNull Range range); + protected abstract void actionPerformed(@NotNull Editor editor, @NotNull Range range); } public class ShowNextChangeMarkerAction extends RangeMarkerAction { - @NotNull private final Editor myEditor; - public ShowNextChangeMarkerAction(@NotNull Editor editor, @NotNull Range range) { - super(range, "VcsShowNextChangeMarker"); - myEditor = editor; + super(editor, range, "VcsShowNextChangeMarker"); } @Override - protected boolean isEnabled(@NotNull Range range) { + protected boolean isEnabled(@NotNull Editor editor, @NotNull Range range) { return myTracker.getNextRange(range.getLine1()) != null; } @Override - protected void actionPerformed(@NotNull Range range) { + protected void actionPerformed(@NotNull Editor editor, @NotNull Range range) { Range targetRange = myTracker.getNextRange(range.getLine1()); - if (targetRange != null) LineStatusMarkerPopupRenderer.this.scrollAndShow(myEditor, targetRange); + if (targetRange != null) LineStatusMarkerPopupRenderer.this.scrollAndShow(editor, targetRange); } } public class ShowPrevChangeMarkerAction extends RangeMarkerAction { - @NotNull private final Editor myEditor; - public ShowPrevChangeMarkerAction(@NotNull Editor editor, @NotNull Range range) { - super(range, "VcsShowPrevChangeMarker"); - myEditor = editor; + super(editor, range, "VcsShowPrevChangeMarker"); } @Override - protected boolean isEnabled(@NotNull Range range) { + protected boolean isEnabled(@NotNull Editor editor, @NotNull Range range) { return myTracker.getPrevRange(range.getLine1()) != null; } @Override - protected void actionPerformed(@NotNull Range range) { + protected void actionPerformed(@NotNull Editor editor, @NotNull Range range) { Range targetRange = myTracker.getPrevRange(range.getLine1()); - if (targetRange != null) LineStatusMarkerPopupRenderer.this.scrollAndShow(myEditor, targetRange); + if (targetRange != null) LineStatusMarkerPopupRenderer.this.scrollAndShow(editor, targetRange); } } public class CopyLineStatusRangeAction extends RangeMarkerAction { - public CopyLineStatusRangeAction(@NotNull Range range) { - super(range, IdeActions.ACTION_COPY); + public CopyLineStatusRangeAction(@NotNull Editor editor, @NotNull Range range) { + super(editor, range, IdeActions.ACTION_COPY); } @Override - protected boolean isEnabled(@NotNull Range range) { + protected boolean isEnabled(@NotNull Editor editor, @NotNull Range range) { return Range.DELETED == range.getType() || Range.MODIFIED == range.getType(); } @Override - protected void actionPerformed(@NotNull Range range) { + protected void actionPerformed(@NotNull Editor editor, @NotNull Range range) { final String content = getVcsContent(range) + "\n"; CopyPasteManager.getInstance().setContents(new StringSelection(content)); } } public class ShowLineStatusRangeDiffAction extends RangeMarkerAction { - public ShowLineStatusRangeDiffAction(@NotNull Range range) { - super(range, IdeActions.ACTION_SHOW_DIFF_COMMON); + public ShowLineStatusRangeDiffAction(@NotNull Editor editor, @NotNull Range range) { + super(editor, range, IdeActions.ACTION_SHOW_DIFF_COMMON); } @Override - protected boolean isEnabled(@NotNull Range range) { + protected boolean isEnabled(@NotNull Editor editor, @NotNull Range range) { return true; } @Override - protected void actionPerformed(@NotNull Range range) { + protected void actionPerformed(@NotNull Editor editor, @NotNull Range range) { Range ourRange = expand(range, myTracker.getDocument(), myTracker.getVcsDocument()); DiffContent vcsContent = createDiffContent(myTracker.getVcsDocument(), diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.kt index a1b9e6dbcb6a..dd8f3417d49e 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.kt @@ -114,19 +114,19 @@ abstract class LineStatusTracker constructor(override val project: Pr actions.add(ShowPrevChangeMarkerAction(editor, range)) actions.add(ShowNextChangeMarkerAction(editor, range)) actions.add(RollbackLineStatusRangeAction(editor, range)) - actions.add(ShowLineStatusRangeDiffAction(range)) - actions.add(CopyLineStatusRangeAction(range)) + actions.add(ShowLineStatusRangeDiffAction(editor, range)) + actions.add(CopyLineStatusRangeAction(editor, range)) actions.add(ToggleByWordDiffAction(editor, range, mousePosition)) return actions } override fun getFileType(): FileType = tracker.virtualFile.fileType - private inner class RollbackLineStatusRangeAction(private val editor: Editor, range: Range) - : RangeMarkerAction(range, IdeActions.SELECTED_CHANGES_ROLLBACK) { - override fun isEnabled(range: Range): Boolean = true + private inner class RollbackLineStatusRangeAction(editor: Editor, range: Range) + : RangeMarkerAction(editor, range, IdeActions.SELECTED_CHANGES_ROLLBACK) { + override fun isEnabled(editor: Editor, range: Range): Boolean = true - override fun actionPerformed(range: Range) { + override fun actionPerformed(editor: Editor, range: Range) { RollbackLineStatusAction.rollback(tracker, range, editor) } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/PartialLocalLineStatusTracker.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/PartialLocalLineStatusTracker.kt index fd6153cab8f7..24a885aaebb6 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/PartialLocalLineStatusTracker.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/PartialLocalLineStatusTracker.kt @@ -417,11 +417,11 @@ class PartialLocalLineStatusTracker(project: Project, return actions } - private inner class SetChangeListAction(val editor: Editor, range: Range, val mousePosition: Point?) - : RangeMarkerAction(range, IdeActions.MOVE_TO_ANOTHER_CHANGE_LIST) { - override fun isEnabled(range: Range): Boolean = range is LocalRange + private inner class SetChangeListAction(editor: Editor, range: Range, val mousePosition: Point?) + : RangeMarkerAction(editor, range, IdeActions.MOVE_TO_ANOTHER_CHANGE_LIST) { + override fun isEnabled(editor: Editor, range: Range): Boolean = range is LocalRange - override fun actionPerformed(range: Range) { + override fun actionPerformed(editor: Editor, range: Range) { MoveChangesLineStatusAction.moveToAnotherChangelist(tracker, range as LocalRange) val newRange = tracker.findRange(range)