mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: mark gutter icons with Alignment.LEFT
This commit is contained in:
@@ -21,14 +21,12 @@ import com.intellij.diff.tools.simple.ThreesideDiffChangeBase;
|
||||
import com.intellij.diff.util.*;
|
||||
import com.intellij.diff.util.DiffUtil.UpdatedLineRange;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.diff.DiffBundle;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.markup.*;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.CalledInAwt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -337,47 +335,10 @@ public class TextMergeChange extends ThreesideDiffChangeBase {
|
||||
boolean ctrlClickVisible,
|
||||
@NotNull final Runnable perform) {
|
||||
final String tooltipText = DiffUtil.createTooltipText(text, ctrlClickVisible ? CTRL_CLICK_TO_RESOLVE : null);
|
||||
return new GutterIconRenderer() {
|
||||
@NotNull
|
||||
return new DiffGutterRenderer(icon, tooltipText) {
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public boolean isNavigateAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnAction getClickAction() {
|
||||
return new DumbAwareAction() {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
perform.run();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return System.identityHashCode(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTooltipText() {
|
||||
return tooltipText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDumbAware() {
|
||||
return true;
|
||||
protected void performAction(AnActionEvent e) {
|
||||
perform.run();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -17,18 +17,13 @@ package com.intellij.diff.tools.fragmented;
|
||||
|
||||
import com.intellij.diff.fragments.DiffFragment;
|
||||
import com.intellij.diff.fragments.LineFragment;
|
||||
import com.intellij.diff.util.DiffDrawUtil;
|
||||
import com.intellij.diff.util.DiffUtil;
|
||||
import com.intellij.diff.util.*;
|
||||
import com.intellij.diff.util.DiffUtil.UpdatedLineRange;
|
||||
import com.intellij.diff.util.Side;
|
||||
import com.intellij.diff.util.TextDiffType;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.markup.*;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -240,62 +235,25 @@ public class UnifiedDiffChange {
|
||||
private GutterIconRenderer createIconRenderer(@NotNull final Side sourceSide,
|
||||
@NotNull final String tooltipText,
|
||||
@NotNull final Icon icon) {
|
||||
return new GutterIconRenderer() {
|
||||
@NotNull
|
||||
return new DiffGutterRenderer(icon, tooltipText) {
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
protected void performAction(AnActionEvent e) {
|
||||
if (myViewer.isStateIsOutOfDate()) return;
|
||||
if (!myViewer.isEditable(sourceSide.other(), true)) return;
|
||||
|
||||
public boolean isNavigateAction() {
|
||||
return true;
|
||||
}
|
||||
final Project project = e.getProject();
|
||||
final Document document = myViewer.getDocument(sourceSide.other());
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnAction getClickAction() {
|
||||
return new DumbAwareAction() {
|
||||
DiffUtil.executeWriteCommand(document, project, "Replace change", new Runnable() {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
if (myViewer.isStateIsOutOfDate()) return;
|
||||
if (!myViewer.isEditable(sourceSide.other(), true)) return;
|
||||
|
||||
final Project project = e.getProject();
|
||||
final Document document = myViewer.getDocument(sourceSide.other());
|
||||
|
||||
DiffUtil.executeWriteCommand(document, project, "Replace change", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myViewer.replaceChange(UnifiedDiffChange.this, sourceSide);
|
||||
myViewer.scheduleRediff();
|
||||
}
|
||||
});
|
||||
// applyChange() will schedule rediff, but we want to try to do it in sync
|
||||
// and we can't do it inside write action
|
||||
myViewer.rediff();
|
||||
public void run() {
|
||||
myViewer.replaceChange(UnifiedDiffChange.this, sourceSide);
|
||||
myViewer.scheduleRediff();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return System.identityHashCode(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTooltipText() {
|
||||
return tooltipText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDumbAware() {
|
||||
return true;
|
||||
});
|
||||
// applyChange() will schedule rediff, but we want to try to do it in sync
|
||||
// and we can't do it inside write action
|
||||
myViewer.rediff();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -17,18 +17,13 @@ package com.intellij.diff.tools.simple;
|
||||
|
||||
import com.intellij.diff.fragments.DiffFragment;
|
||||
import com.intellij.diff.fragments.LineFragment;
|
||||
import com.intellij.diff.util.DiffDrawUtil;
|
||||
import com.intellij.diff.util.DiffUtil;
|
||||
import com.intellij.diff.util.Side;
|
||||
import com.intellij.diff.util.TextDiffType;
|
||||
import com.intellij.diff.util.*;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.markup.*;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -306,55 +301,18 @@ public class SimpleDiffChange {
|
||||
@NotNull final Icon icon,
|
||||
@NotNull final Runnable perform) {
|
||||
if (!DiffUtil.isEditable(myViewer.getEditor(sourceSide.other()))) return null;
|
||||
return new GutterIconRenderer() {
|
||||
@NotNull
|
||||
return new DiffGutterRenderer(icon, tooltipText) {
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public boolean isNavigateAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnAction getClickAction() {
|
||||
return new DumbAwareAction() {
|
||||
protected void performAction(AnActionEvent e) {
|
||||
if (!myIsValid) return;
|
||||
final Project project = e.getProject();
|
||||
final Document document = myViewer.getEditor(sourceSide.other()).getDocument();
|
||||
DiffUtil.executeWriteCommand(document, project, "Replace change", new Runnable() {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
if (!myIsValid) return;
|
||||
final Project project = e.getProject();
|
||||
final Document document = myViewer.getEditor(sourceSide.other()).getDocument();
|
||||
DiffUtil.executeWriteCommand(document, project, "Replace change", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
perform.run();
|
||||
}
|
||||
});
|
||||
public void run() {
|
||||
perform.run();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return System.identityHashCode(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTooltipText() {
|
||||
return tooltipText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDumbAware() {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.diff.util;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.editor.markup.GutterIconRenderer;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public abstract class DiffGutterRenderer extends GutterIconRenderer {
|
||||
@NotNull private final Icon myIcon;
|
||||
@Nullable private final String myTooltip;
|
||||
|
||||
public DiffGutterRenderer(@NotNull Icon icon, @Nullable String tooltip) {
|
||||
myIcon = icon;
|
||||
myTooltip = tooltip;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return myIcon;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTooltipText() {
|
||||
return myTooltip;
|
||||
}
|
||||
|
||||
public boolean isNavigateAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDumbAware() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Alignment getAlignment() {
|
||||
return Alignment.LEFT;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnAction getClickAction() {
|
||||
return new DumbAwareAction() {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
performAction(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return System.identityHashCode(this);
|
||||
}
|
||||
|
||||
protected abstract void performAction(AnActionEvent e);
|
||||
}
|
||||
Reference in New Issue
Block a user