mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
dir diff context menu
This commit is contained in:
@@ -533,6 +533,12 @@
|
||||
<group id="EditorContextBarMenu">
|
||||
</group>
|
||||
|
||||
<group id="DirDiffMenu">
|
||||
<action id="DirDiffMenu.SetCopyToRight" class="com.intellij.openapi.diff.impl.dir.actions.popup.SetCopyToRight" text="Set Copy to Right" icon="/vcs/arrow_right.png"/>
|
||||
<action id="DirDiffMenu.SetCopyToLeft" class="com.intellij.openapi.diff.impl.dir.actions.popup.SetCopyToLeft" text="Set Copy to Left" icon="/vcs/arrow_left.png"/>
|
||||
<action id="DirDiffMenu.SetDelete" class="com.intellij.openapi.diff.impl.dir.actions.popup.SetDelete" text="Set Delete" icon="/vcs/remove.png"/>
|
||||
</group>
|
||||
|
||||
<action id="Rerun" class="com.intellij.execution.runners.FakeRerunAction" text="Rerun"/>
|
||||
|
||||
<action id="IncrementWindowWidth" class="com.intellij.ide.actions.WindowAction$IncrementWidth" use-shortcut-of="ResizeToolWindowRight"/>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<DirDiffTableModel> DIR_DIFF_MODEL = DataKey.create("DIR_DIFF_MODEL");
|
||||
public static final DataKey<JTable> 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;
|
||||
}
|
||||
}
|
||||
|
||||
+30
@@ -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;
|
||||
}
|
||||
}
|
||||
+30
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+66
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user