mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-97142 IDEA-138653 diff: add action to switch current side, scrolling to the 'related' position
This commit is contained in:
@@ -15,18 +15,23 @@
|
||||
*/
|
||||
package com.intellij.diff.actions.impl;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CustomShortcutSet;
|
||||
import com.intellij.openapi.actionSystem.ShortcutSet;
|
||||
import com.intellij.openapi.actionSystem.EmptyAction;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class FocusOppositePaneAction extends AnAction implements DumbAware {
|
||||
protected final boolean myScrollToPosition;
|
||||
|
||||
public FocusOppositePaneAction() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public FocusOppositePaneAction(boolean scrollToPosition) {
|
||||
myScrollToPosition = scrollToPosition;
|
||||
setEnabledInModalContext(true);
|
||||
}
|
||||
|
||||
@@ -35,8 +40,8 @@ public class FocusOppositePaneAction extends AnAction implements DumbAware {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void setupAction(@NotNull JComponent component, @NotNull Disposable disposable) {
|
||||
ShortcutSet shortcutSet = CustomShortcutSet.fromString("control TAB"); // TODO: allow to change shortcut
|
||||
registerCustomShortcutSet(shortcutSet, component, disposable);
|
||||
public void setupAction(@NotNull JComponent component) {
|
||||
String action = myScrollToPosition ? "Diff.FocusOppositePaneAndScroll" : "Diff.FocusOppositePane";
|
||||
EmptyAction.setupAction(this, action, component);
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase {
|
||||
|
||||
myStatusPanel = new MyStatusPanel();
|
||||
|
||||
new MyFocusOppositePaneAction().setupAction(myPanel, this);
|
||||
new MyFocusOppositePaneAction().setupAction(myPanel);
|
||||
|
||||
|
||||
installEditorListeners();
|
||||
|
||||
@@ -819,12 +819,12 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer {
|
||||
return getTextSettings().isEnableSyncScroll();
|
||||
}
|
||||
|
||||
public int transfer(@NotNull Side side, int line) {
|
||||
public int transfer(@NotNull Side baseSide, int line) {
|
||||
if (myDiffChanges.isEmpty()) {
|
||||
return line;
|
||||
}
|
||||
|
||||
return super.transfer(side, line);
|
||||
return super.transfer(baseSide, line);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,8 +29,8 @@ public abstract class BaseSyncScrollable implements SyncScrollSupport.SyncScroll
|
||||
*/
|
||||
protected abstract void processHelper(@NotNull ScrollHelper helper);
|
||||
|
||||
public int transfer(@NotNull Side side, int line) {
|
||||
ScrollHelper helper = new ScrollHelper(side, line);
|
||||
public int transfer(@NotNull Side baseSide, int line) {
|
||||
ScrollHelper helper = new ScrollHelper(baseSide, line);
|
||||
processHelper(helper);
|
||||
|
||||
int master1 = helper.getMaster1();
|
||||
|
||||
@@ -35,7 +35,7 @@ public class SyncScrollSupport {
|
||||
boolean isSyncScrollEnabled();
|
||||
|
||||
@CalledInAwt
|
||||
int transfer(@NotNull Side side, int line);
|
||||
int transfer(@NotNull Side baseSide, int line);
|
||||
}
|
||||
|
||||
public static class TwosideSyncScrollSupport {
|
||||
@@ -73,6 +73,15 @@ public class SyncScrollSupport {
|
||||
myDuringSyncScroll = false;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SyncScrollable getScrollable() {
|
||||
return myScrollable;
|
||||
}
|
||||
|
||||
public boolean isDuringSyncScroll() {
|
||||
return myDuringSyncScroll;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ThreesideSyncScrollSupport {
|
||||
|
||||
+21
-1
@@ -109,7 +109,8 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase {
|
||||
myPanel = new TwosideTextDiffPanel(this, myContentPanel, this, context);
|
||||
|
||||
|
||||
new MyFocusOppositePaneAction().setupAction(myPanel, this);
|
||||
new MyFocusOppositePaneAction(true).setupAction(myPanel);
|
||||
new MyFocusOppositePaneAction(false).setupAction(myPanel);
|
||||
|
||||
myEditorSettingsAction = new MySetEditorSettingsAction();
|
||||
myEditorSettingsAction.applyDefaults();
|
||||
@@ -315,6 +316,14 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase {
|
||||
// Abstract
|
||||
//
|
||||
|
||||
@CalledInAwt
|
||||
@NotNull
|
||||
protected LogicalPosition transferPosition(@NotNull Side baseSide, @NotNull LogicalPosition position) {
|
||||
if (mySyncScrollListener == null) return position;
|
||||
int line = mySyncScrollListener.getScrollable().transfer(baseSide, position.line);
|
||||
return new LogicalPosition(line, position.column);
|
||||
}
|
||||
|
||||
@CalledInAwt
|
||||
protected void scrollToLine(@NotNull Side side, int line) {
|
||||
Editor editor = side.select(myEditor1, myEditor2);
|
||||
@@ -388,10 +397,21 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase {
|
||||
//
|
||||
|
||||
private class MyFocusOppositePaneAction extends FocusOppositePaneAction {
|
||||
public MyFocusOppositePaneAction(boolean scrollToPosition) {
|
||||
super(scrollToPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
if (myEditor1 == null || myEditor2 == null) return;
|
||||
|
||||
if (myScrollToPosition) {
|
||||
EditorEx currentEditor = myCurrentSide.select(myEditor1, myEditor2);
|
||||
EditorEx targetEditor = myCurrentSide.other().select(myEditor1, myEditor2);
|
||||
LogicalPosition position = transferPosition(myCurrentSide, currentEditor.getCaretModel().getLogicalPosition());
|
||||
targetEditor.getCaretModel().moveToLogicalPosition(position);
|
||||
}
|
||||
|
||||
myCurrentSide = myCurrentSide.other();
|
||||
myPanel.requestFocus();
|
||||
getCurrentEditor().getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
|
||||
|
||||
@@ -1221,7 +1221,10 @@ action.VcsHistory.ShowAllAffected.description=Show all changes made in the chose
|
||||
|
||||
action.AddFrameworkSupport.text=Add Framework Support...
|
||||
|
||||
action.Diff.FocusOppositePane.text=Select opposite pane in diff view
|
||||
action.Diff.FocusOppositePane.text=Select Opposite Diff Pane
|
||||
action.Diff.FocusOppositePane.description=Select opposite pane in diff view
|
||||
action.Diff.FocusOppositePaneAndScroll.text=Select Position In Opposite Diff Pane
|
||||
action.Diff.FocusOppositePaneAndScroll.description=Select the same position in opposite pane in diff view
|
||||
action.Diff.PrevChange.text=Compare Previous File
|
||||
action.Diff.NextChange.text=Compare Next File
|
||||
action.Diff.SelectedChange.text=Choose File To Compare
|
||||
|
||||
@@ -547,6 +547,12 @@
|
||||
<action id="NextDiff">
|
||||
<keyboard-shortcut first-keystroke="F7"/>
|
||||
</action>
|
||||
<action id="Diff.FocusOppositePane">
|
||||
<keyboard-shortcut first-keystroke="control TAB"/>
|
||||
</action>
|
||||
<action id="Diff.FocusOppositePaneAndScroll">
|
||||
<keyboard-shortcut first-keystroke="control shift TAB"/>
|
||||
</action>
|
||||
<action id="Move">
|
||||
<keyboard-shortcut first-keystroke="F6"/>
|
||||
</action>
|
||||
|
||||
@@ -162,7 +162,9 @@
|
||||
<action id="CompareFileWithEditor" class="com.intellij.diff.actions.CompareFileWithEditorAction"/>
|
||||
<action id="CompareClipboardWithSelection" class="com.intellij.diff.actions.CompareClipboardWithSelectionAction"/>
|
||||
|
||||
<action id="Diff.FocusOppositePane" class="com.intellij.openapi.diff.actions.FocusOppositePaneAction" use-shortcut-of="NextSplitter"/>
|
||||
<action id="Diff.FocusOppositePane" class="com.intellij.openapi.diff.actions.FocusOppositePaneAction"/>
|
||||
<action id="Diff.FocusOppositePaneAndScroll" class="com.intellij.openapi.actionSystem.EmptyAction"/>
|
||||
|
||||
<action id="Diff.ShowSettingsPopup" class="com.intellij.openapi.actionSystem.EmptyAction" text="Show Diff Settings Popup..."/>
|
||||
<action id="Diff.ShowInExternalTool" class="com.intellij.openapi.actionSystem.EmptyAction" icon="AllIcons.General.ExternalToolsSmall"
|
||||
text="Show Diff in External Tool"/>
|
||||
|
||||
@@ -132,6 +132,8 @@ public abstract class KeymapsTestCase extends PlatformTestCase {
|
||||
{ "shift control U", "ShelveChanges.UnshelveWithDialog", "EditorToggleCase"},
|
||||
{ "control E", "RecentFiles", "Vcs.ShowMessageHistory"},
|
||||
{ "control alt Z", "Vcs.RollbackChangedLines", "ChangesView.Revert"},
|
||||
{ "control TAB", "Switcher", "Diff.FocusOppositePane"},
|
||||
{ "shift control TAB", "Switcher", "Diff.FocusOppositePaneAndScroll"},
|
||||
});
|
||||
put("Mac OS X 10.5+", new String[][] {
|
||||
{ "F5", "CopyElement", "Console.TableResult.Reload", "UML.ApplyCurrentLayout"},
|
||||
|
||||
Reference in New Issue
Block a user