mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-56098 diff: add ability to disable autoscroll
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.diff.ex.DiffPanelEx;
|
||||
import com.intellij.openapi.diff.impl.DiffPanelImpl;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.ui.ToggleActionButton;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class ToggleAutoScrollAction extends ToggleActionButton implements DumbAware {
|
||||
public ToggleAutoScrollAction() {
|
||||
super("Auto Scroll", AllIcons.General.AutoscrollToSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
DiffPanelEx diffPanel = DiffPanelImpl.fromDataContext(e.getDataContext());
|
||||
if (diffPanel != null) {
|
||||
return diffPanel.isAutoScrollEnabled();
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
final DiffPanelImpl diffPanel = DiffPanelImpl.fromDataContext(e.getDataContext());
|
||||
if (diffPanel != null) {
|
||||
diffPanel.setAutoScrollEnabled(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,4 +41,8 @@ public interface DiffPanelEx extends DiffPanel, Disposable {
|
||||
void setComparisonPolicy(ComparisonPolicy comparisonPolicy);
|
||||
|
||||
ComparisonPolicy getComparisonPolicy();
|
||||
|
||||
void setAutoScrollEnabled(boolean enabled);
|
||||
|
||||
boolean isAutoScrollEnabled();
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.diff.*;
|
||||
import com.intellij.openapi.diff.actions.MergeActionGroup;
|
||||
import com.intellij.openapi.diff.actions.ToggleAutoScrollAction;
|
||||
import com.intellij.openapi.diff.ex.DiffPanelEx;
|
||||
import com.intellij.openapi.diff.ex.DiffPanelOptions;
|
||||
import com.intellij.openapi.diff.impl.external.DiffManagerImpl;
|
||||
@@ -111,6 +112,8 @@ public class DiffPanelImpl implements DiffPanelEx, ContentChangeListener, TwoSid
|
||||
ActionManager actionManager = ActionManager.getInstance();
|
||||
toolbar.addAction(actionManager.getAction("DiffPanel.Toolbar"));
|
||||
toolbar.addSeparator();
|
||||
toolbar.addAction(new ToggleAutoScrollAction());
|
||||
toolbar.addSeparator();
|
||||
toolbar.addAction(actionManager.getAction("ContextHelp"));
|
||||
toolbar.addAction(getEditSourceAction());
|
||||
toolbar.addSeparator();
|
||||
@@ -468,6 +471,14 @@ public class DiffPanelImpl implements DiffPanelEx, ContentChangeListener, TwoSid
|
||||
}
|
||||
}
|
||||
|
||||
public void setAutoScrollEnabled(boolean enabled) {
|
||||
myScrollSupport.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public boolean isAutoScrollEnabled() {
|
||||
return myScrollSupport.isEnabled();
|
||||
}
|
||||
|
||||
public void setComparisonPolicy(ComparisonPolicy comparisonPolicy) {
|
||||
setComparisonPolicy(comparisonPolicy, true);
|
||||
}
|
||||
|
||||
+10
-1
@@ -36,6 +36,7 @@ public class SyncScrollSupport implements Disposable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.diff.impl.util.SyncScrollSupport");
|
||||
private boolean myDuringVerticalScroll = false;
|
||||
private final ArrayList<ScrollListener> myScrollers = new ArrayList<ScrollListener>();
|
||||
private boolean myEnabled = true;
|
||||
|
||||
public void install(EditingSides[] sideContainers) {
|
||||
Disposer.dispose(this);
|
||||
@@ -58,6 +59,14 @@ public class SyncScrollSupport implements Disposable {
|
||||
myScrollers.clear();
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
myEnabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return myEnabled;
|
||||
}
|
||||
|
||||
private void install2(Editor[] editors, EditingSides[] sideContainers) {
|
||||
addSlavesScroller(editors[0], new Pair<FragmentSide, EditingSides>(FragmentSide.SIDE1, sideContainers[0]));
|
||||
addSlavesScroller(editors[1], new Pair<FragmentSide, EditingSides>(FragmentSide.SIDE2, sideContainers[0]));
|
||||
@@ -100,7 +109,7 @@ public class SyncScrollSupport implements Disposable {
|
||||
}
|
||||
|
||||
public void visibleAreaChanged(VisibleAreaEvent e) {
|
||||
if (myDuringVerticalScroll) return;
|
||||
if (!myEnabled || myDuringVerticalScroll) return;
|
||||
Rectangle newRectangle = e.getNewRectangle();
|
||||
Rectangle oldRectangle = e.getOldRectangle();
|
||||
if (newRectangle == null || oldRectangle == null) return;
|
||||
|
||||
Reference in New Issue
Block a user