IDEA-170174 diff: add "Mirror to Left/Right" action to directory diff

This commit is contained in:
Aleksey Pivovarov
2017-05-10 12:25:07 +03:00
parent e87e4d81f8
commit 3dad68ff00
8 changed files with 92 additions and 9 deletions
@@ -0,0 +1,39 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.diff.impl.dir.actions.popup;
import com.intellij.ide.diff.DirDiffElement;
import com.intellij.ide.diff.DirDiffOperation;
import com.intellij.openapi.diff.impl.dir.DirDiffElementImpl;
import org.jetbrains.annotations.NotNull;
public class MirrorToLeftAction extends SetOperationToBase {
@Override
protected boolean isEnabledFor(DirDiffElement element) {
return true;
}
@NotNull
@Override
protected DirDiffOperation getOperation(DirDiffElementImpl element) {
if (element.isSource()) {
return DirDiffOperation.DELETE;
}
else {
return DirDiffOperation.COPY_FROM;
}
}
}
@@ -0,0 +1,39 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.diff.impl.dir.actions.popup;
import com.intellij.ide.diff.DirDiffElement;
import com.intellij.ide.diff.DirDiffOperation;
import com.intellij.openapi.diff.impl.dir.DirDiffElementImpl;
import org.jetbrains.annotations.NotNull;
public class MirrorToRightAction extends SetOperationToBase {
@Override
protected boolean isEnabledFor(DirDiffElement element) {
return true;
}
@NotNull
@Override
protected DirDiffOperation getOperation(DirDiffElementImpl element) {
if (element.isTarget()) {
return DirDiffOperation.DELETE;
}
else {
return DirDiffOperation.COPY_TO;
}
}
}
@@ -17,6 +17,7 @@ package com.intellij.openapi.diff.impl.dir.actions.popup;
import com.intellij.ide.diff.DirDiffElement;
import com.intellij.ide.diff.DirDiffOperation;
import com.intellij.openapi.diff.impl.dir.DirDiffElementImpl;
import org.jetbrains.annotations.NotNull;
/**
@@ -25,7 +26,7 @@ import org.jetbrains.annotations.NotNull;
public class SetCopyToLeft extends SetOperationToBase {
@NotNull
@Override
protected DirDiffOperation getOperation() {
protected DirDiffOperation getOperation(DirDiffElementImpl element) {
return DirDiffOperation.COPY_FROM;
}
@@ -17,6 +17,7 @@ package com.intellij.openapi.diff.impl.dir.actions.popup;
import com.intellij.ide.diff.DirDiffElement;
import com.intellij.ide.diff.DirDiffOperation;
import com.intellij.openapi.diff.impl.dir.DirDiffElementImpl;
import org.jetbrains.annotations.NotNull;
/**
@@ -25,7 +26,7 @@ import org.jetbrains.annotations.NotNull;
public class SetCopyToRight extends SetOperationToBase {
@NotNull
@Override
protected DirDiffOperation getOperation() {
protected DirDiffOperation getOperation(DirDiffElementImpl element) {
return DirDiffOperation.COPY_TO;
}
@@ -17,6 +17,7 @@ package com.intellij.openapi.diff.impl.dir.actions.popup;
import com.intellij.ide.diff.DirDiffElement;
import com.intellij.ide.diff.DirDiffOperation;
import com.intellij.openapi.diff.impl.dir.DirDiffElementImpl;
import org.jetbrains.annotations.NotNull;
/**
@@ -25,8 +26,8 @@ import org.jetbrains.annotations.NotNull;
public class SetDefault extends SetOperationToBase {
@NotNull
@Override
protected DirDiffOperation getOperation() {
return DirDiffOperation.NONE;
protected DirDiffOperation getOperation(DirDiffElementImpl element) {
return element.getDefaultOperation();
}
@Override
@@ -17,6 +17,7 @@ package com.intellij.openapi.diff.impl.dir.actions.popup;
import com.intellij.ide.diff.DirDiffElement;
import com.intellij.ide.diff.DirDiffOperation;
import com.intellij.openapi.diff.impl.dir.DirDiffElementImpl;
import org.jetbrains.annotations.NotNull;
/**
@@ -25,7 +26,7 @@ import org.jetbrains.annotations.NotNull;
public class SetDelete extends SetOperationToBase {
@NotNull
@Override
protected DirDiffOperation getOperation() {
protected DirDiffOperation getOperation(DirDiffElementImpl element) {
return DirDiffOperation.DELETE;
}
@@ -33,14 +33,12 @@ import javax.swing.*;
public abstract class SetOperationToBase extends DumbAwareAction {
@Override
public void actionPerformed(AnActionEvent e) {
DirDiffOperation operation = getOperation();
boolean setToDefault = operation == DirDiffOperation.NONE;
final DirDiffTableModel model = getModel(e);
final JTable table = getTable(e);
assert model != null && table != null;
for (DirDiffElementImpl element : model.getSelectedElements()) {
if (isEnabledFor(element)) {
element.setOperation(setToDefault ? element.getDefaultOperation() : operation);
element.setOperation(getOperation(element));
} else {
element.setOperation(DirDiffOperation.NONE);
}
@@ -49,7 +47,7 @@ public abstract class SetOperationToBase extends DumbAwareAction {
}
@NotNull
protected abstract DirDiffOperation getOperation();
protected abstract DirDiffOperation getOperation(DirDiffElementImpl element);
@Override
public final void update(AnActionEvent e) {
@@ -801,6 +801,9 @@
<action id="DirDiffMenu.SetDelete" class="com.intellij.openapi.diff.impl.dir.actions.popup.SetDelete" text="Set Delete" icon="AllIcons.Vcs.Remove"/>
<action id="DirDiffMenu.SetNoOperation" class="com.intellij.openapi.diff.impl.dir.actions.popup.SetNoOperation" text="Set Do Nothing"/>
<separator/>
<action id="DirDiffMenu.MirrorToRight" class="com.intellij.openapi.diff.impl.dir.actions.popup.MirrorToRightAction" text="Set Mirror to Right" icon="AllIcons.Vcs.Arrow_right"/>
<action id="DirDiffMenu.MirrorToLeft" class="com.intellij.openapi.diff.impl.dir.actions.popup.MirrorToLeftAction" text="Set Mirror to Left" icon="AllIcons.Vcs.Arrow_left"/>
<separator/>
<action id="DirDiffMenu.SetDefault" class="com.intellij.openapi.diff.impl.dir.actions.popup.SetDefault" text="Set Default"/>
<action id="DirDiffMenu.WarnOnDeletion" class="com.intellij.openapi.diff.impl.dir.actions.popup.WarnOnDeletion" text="Warn When Delete" />
<separator/>