diff --git a/platform/platform-resources/src/idea/PlatformActions.xml b/platform/platform-resources/src/idea/PlatformActions.xml index dd30603f1365..7e170bca3e77 100644 --- a/platform/platform-resources/src/idea/PlatformActions.xml +++ b/platform/platform-resources/src/idea/PlatformActions.xml @@ -533,6 +533,12 @@ + + + + + + diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffElement.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffElement.java index 08f327c3ab49..beb08b6a427b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffElement.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffElement.java @@ -192,6 +192,10 @@ public class DirDiffElement { } } + public void setOperation(@NotNull DirDiffOperation operation) { + myOperation = operation; + } + public Icon getIcon() { return mySource != null ? mySource.getIcon() : myTarget.getIcon(); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java index ec9c59ce7633..5ea1bf1a22ae 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java @@ -29,6 +29,7 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.ui.FilterComponent; +import com.intellij.ui.PopupHandler; import com.intellij.ui.TableSpeedSearch; import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.components.JBLabel; @@ -37,6 +38,7 @@ import com.intellij.ui.components.JBLoadingPanelListener; import com.intellij.ui.table.JBTable; import com.intellij.util.diff.FilesTooBigForDiffException; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NonNls; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -54,7 +56,7 @@ import java.util.concurrent.atomic.AtomicBoolean; * @author Konstantin Bulenkov */ @SuppressWarnings({"unchecked"}) -public class DirDiffPanel implements Disposable { +public class DirDiffPanel implements Disposable, DataProvider { public static final String DIVIDER_PROPERTY = "dir.diff.panel.divider.location"; private JPanel myDiffPanel; private JBTable myTable; @@ -77,6 +79,8 @@ public class DirDiffPanel implements Disposable { private JComponent myViewComponent; private DiffElement myCurrentElement; private String oldFilter; + public static final DataKey DIR_DIFF_MODEL = DataKey.create("DIR_DIFF_MODEL"); + public static final DataKey DIR_DIFF_TABLE = DataKey.create("DIR_DIFF_TABLE"); public DirDiffPanel(DirDiffTableModel model, DirDiffWindow wnd) { myModel = model; @@ -130,6 +134,7 @@ public class DirDiffPanel implements Disposable { myTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON3) return; if (myTable.getRowCount() > 0) { final int row = myTable.rowAtPoint(e.getPoint()); final int col = myTable.columnAtPoint(e.getPoint()); @@ -192,12 +197,22 @@ public class DirDiffPanel implements Disposable { } } final DirDiffToolbarActions actions = new DirDiffToolbarActions(myModel, myDiffPanel); - final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("DirDiff", actions, true); + final ActionManager actionManager = ActionManager.getInstance(); + final ActionToolbar toolbar = actionManager.createActionToolbar("DirDiff", actions, true); registerCustomShortcuts(actions, myTable); myToolBarPanel.add(toolbar.getComponent(), BorderLayout.CENTER); final JBLabel label = new JBLabel("Use Space button or mouse click to change operation for the selected elements. Enter to perform.", SwingConstants.CENTER); label.setForeground(UIUtil.getInactiveTextColor()); UIUtil.applyStyle(UIUtil.ComponentStyle.MINI, label); + DataManager.registerDataProvider(myFilesPanel, this); + myTable.addMouseListener(new PopupHandler() { + @Override + public void invokePopup(Component comp, int x, int y) { + final JPopupMenu popupMenu = + actionManager.createActionPopupMenu("DirDiffPanel", (ActionGroup)actionManager.getAction("DirDiffMenu")).getComponent(); + popupMenu.show(comp, x, y); + } + }); myFilesPanel.add(label, BorderLayout.SOUTH); final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), wnd.getDisposable()); loadingPanel.addListener(new JBLoadingPanelListener.Adapter() { @@ -472,4 +487,18 @@ public class DirDiffPanel implements Disposable { public void setupSplitter() { mySplitPanel.setDividerLocation(Integer.valueOf(PropertiesComponent.getInstance().getValue(DIVIDER_PROPERTY, "200"))); } + + @Override + public Object getData(@NonNls String dataId) { + if (PlatformDataKeys.PROJECT.is(dataId)) { + return myModel.getProject(); + } + if (DIR_DIFF_MODEL.is(dataId)) { + return myModel; + } + if (DIR_DIFF_TABLE.is(dataId)) { + return myTable; + } + return null; + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/SetCopyToLeft.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/SetCopyToLeft.java new file mode 100644 index 000000000000..92839c69c867 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/SetCopyToLeft.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2012 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.openapi.diff.impl.dir.DirDiffOperation; +import org.jetbrains.annotations.NotNull; + +/** + * @author Konstantin Bulenkov + */ +public class SetCopyToLeft extends SetOperationToBase { + @NotNull + @Override + protected DirDiffOperation getOperation() { + return DirDiffOperation.COPY_FROM; + } +} diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/SetCopyToRight.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/SetCopyToRight.java new file mode 100644 index 000000000000..80d982d8ec28 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/SetCopyToRight.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2012 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.openapi.diff.impl.dir.DirDiffOperation; +import org.jetbrains.annotations.NotNull; + +/** + * @author Konstantin Bulenkov + */ +public class SetCopyToRight extends SetOperationToBase { + @NotNull + @Override + protected DirDiffOperation getOperation() { + return DirDiffOperation.COPY_TO; + } +} diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/SetDelete.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/SetDelete.java new file mode 100644 index 000000000000..3a8038108a61 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/SetDelete.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2012 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.openapi.diff.impl.dir.DirDiffOperation; +import org.jetbrains.annotations.NotNull; + +/** + * @author Konstantin Bulenkov + */ +public class SetDelete extends SetOperationToBase { + @NotNull + @Override + protected DirDiffOperation getOperation() { + return DirDiffOperation.DELETE; + } +} diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/SetOperationToBase.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/SetOperationToBase.java new file mode 100644 index 000000000000..264757c85ea2 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/SetOperationToBase.java @@ -0,0 +1,66 @@ +/* + * Copyright 2000-2012 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.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.diff.impl.dir.DirDiffElement; +import com.intellij.openapi.diff.impl.dir.DirDiffOperation; +import com.intellij.openapi.diff.impl.dir.DirDiffPanel; +import com.intellij.openapi.diff.impl.dir.DirDiffTableModel; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +/** + * @author Konstantin Bulenkov + */ +public abstract class SetOperationToBase extends AnAction { + @Override + public void actionPerformed(AnActionEvent e) { + DirDiffOperation operation = getOperation(); + final DirDiffTableModel model = getModel(e); + final JTable table = getTable(e); + assert model != null && table != null; + for (DirDiffElement element : model.getSelectedElements()) { + element.setOperation(operation); + } + table.repaint(); + } + + @NotNull + protected abstract DirDiffOperation getOperation(); + + @Override + public void update(AnActionEvent e) { + final DirDiffTableModel model = getModel(e); + final JTable table = getTable(e); + e.getPresentation().setEnabled(table != null + && model != null + && !model.getSelectedElements().isEmpty()); + } + + @Nullable + private static JTable getTable(AnActionEvent e) { + return e.getData(DirDiffPanel.DIR_DIFF_TABLE); + } + + @Nullable + public static DirDiffTableModel getModel(AnActionEvent e) { + return e.getData(DirDiffPanel.DIR_DIFF_MODEL); + } +}