summaryrefslogtreecommitdiff
path: root/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java')
-rw-r--r--platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java41
1 files changed, 16 insertions, 25 deletions
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java
index 6e08d90a3b5d..1286b6815fcf 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java
@@ -29,68 +29,60 @@ import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.util.BitSet;
import java.util.List;
public class RollbackLineStatusAction extends DumbAwareAction {
- public RollbackLineStatusAction() {
- super(ActionsBundle.actionText("Vcs.RollbackChangedLines"),
- ActionsBundle.actionDescription("Vcs.RollbackChangedLines"),
- AllIcons.Actions.Reset);
- }
-
@Override
public void update(AnActionEvent e) {
Project project = e.getProject();
- if (project == null) {
- e.getPresentation().setEnabled(false);
- return;
- }
- Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
- if (editor == null) {
- e.getPresentation().setEnabled(false);
+ Editor editor = e.getData(CommonDataKeys.EDITOR);
+ if (project == null || editor == null) {
+ e.getPresentation().setEnabledAndVisible(false);
return;
}
LineStatusTracker tracker = LineStatusTrackerManager.getInstance(project).getLineStatusTracker(editor.getDocument());
if (tracker == null) {
- e.getPresentation().setEnabled(false);
+ e.getPresentation().setEnabledAndVisible(false);
return;
}
- e.getPresentation().setEnabled(true);
+ e.getPresentation().setEnabledAndVisible(true);
}
@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getProject();
- Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
+ Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
LineStatusTracker tracker = LineStatusTrackerManager.getInstance(project).getLineStatusTracker(editor.getDocument());
- if (tracker == null) return;
+ assert tracker != null;
rollback(tracker, editor, null);
}
protected static void rollback(@NotNull LineStatusTracker tracker, @Nullable Editor editor, @Nullable Range range) {
+ assert editor != null || range != null;
+
if (range != null) {
doRollback(tracker, range);
return;
}
- if (editor == null) return;
Document document = editor.getDocument();
int totalLines = getLineCount(document);
- SegmentTree lines = new SegmentTree(totalLines + 1);
+ BitSet lines = new BitSet(totalLines + 1);
List<Caret> carets = editor.getCaretModel().getAllCarets();
for (Caret caret : carets) {
if (caret.hasSelection()) {
int line1 = editor.offsetToLogicalPosition(caret.getSelectionStart()).line;
int line2 = editor.offsetToLogicalPosition(caret.getSelectionEnd()).line;
- lines.mark(line1, line2 + 1);
- if (caret.getSelectionEnd() == document.getTextLength()) lines.mark(totalLines);
+ lines.set(line1, line2 + 1);
+ if (caret.getSelectionEnd() == document.getTextLength()) lines.set(totalLines);
}
else {
- lines.mark(caret.getLogicalPosition().line);
- if (caret.getOffset() == document.getTextLength()) lines.mark(totalLines);
+ lines.set(caret.getLogicalPosition().line);
+ if (caret.getOffset() == document.getTextLength()) lines.set(totalLines);
}
}
@@ -106,7 +98,7 @@ public class RollbackLineStatusAction extends DumbAwareAction {
});
}
- private static void doRollback(@NotNull final LineStatusTracker tracker, @NotNull final SegmentTree lines) {
+ private static void doRollback(@NotNull final LineStatusTracker tracker, @NotNull final BitSet lines) {
execute(tracker, new Runnable() {
@Override
public void run() {
@@ -116,7 +108,6 @@ public class RollbackLineStatusAction extends DumbAwareAction {
}
private static void execute(@NotNull final LineStatusTracker tracker, @NotNull final Runnable task) {
- // TODO: is there possible data races?
CommandProcessor.getInstance().executeCommand(tracker.getProject(), new Runnable() {
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {