mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: show popup in the middle of the window
make it more noticeable, as we don't know which part of viewer has user's attention
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package com.intellij.diff.impl;
|
||||
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.codeInsight.hint.HintManagerImpl;
|
||||
import com.intellij.codeInsight.hint.HintUtil;
|
||||
import com.intellij.diff.DiffContext;
|
||||
import com.intellij.diff.DiffManagerEx;
|
||||
import com.intellij.diff.DiffTool;
|
||||
@@ -37,15 +40,20 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.popup.Balloon;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.ui.popup.ListPopup;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.wm.ex.IdeFocusTraversalPolicy;
|
||||
import com.intellij.ui.HintHint;
|
||||
import com.intellij.ui.LightweightHint;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.CalledInAwt;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -624,7 +632,7 @@ public abstract class DiffRequestProcessor implements Disposable {
|
||||
|
||||
if (myIterationState != IterationState.NEXT) {
|
||||
// TODO: provide "change" word in chain UserData - for tests/etc
|
||||
if (iterable != null) iterable.notify("Press again to go to the next file");
|
||||
notifyMessage(e.getData(DiffDataKeys.CURRENT_EDITOR), "Press again to go to the next file", true);
|
||||
myIterationState = IterationState.NEXT;
|
||||
return;
|
||||
}
|
||||
@@ -667,7 +675,7 @@ public abstract class DiffRequestProcessor implements Disposable {
|
||||
if (!isNavigationEnabled() || !hasPrevChange()) return;
|
||||
|
||||
if (myIterationState != IterationState.PREV) {
|
||||
if (iterable != null) iterable.notify("Press again to go to the previous file");
|
||||
notifyMessage(e.getData(DiffDataKeys.CURRENT_EDITOR), "Press again to go to the previous file", false);
|
||||
myIterationState = IterationState.PREV;
|
||||
return;
|
||||
}
|
||||
@@ -676,6 +684,29 @@ public abstract class DiffRequestProcessor implements Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyMessage(@Nullable Editor editor, @NotNull String message, boolean next) {
|
||||
final LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(message));
|
||||
Point point = new Point(myContentPanel.getWidth() / 2, next ? myContentPanel.getHeight() - JBUI.scale(40) : JBUI.scale(40));
|
||||
|
||||
final HintHint hintHint = new HintHint(myContentPanel, point)
|
||||
.setPreferredPosition(next ? Balloon.Position.above : Balloon.Position.below)
|
||||
.setAwtTooltip(true)
|
||||
.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD))
|
||||
.setTextBg(HintUtil.INFORMATION_COLOR)
|
||||
.setShowImmediately(true);
|
||||
|
||||
if (editor == null) {
|
||||
final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
|
||||
hint.show(myContentPanel, point.x, point.y, owner instanceof JComponent ? (JComponent)owner : null, hintHint);
|
||||
}
|
||||
else {
|
||||
Point editorPoint = SwingUtilities.convertPoint(myContentPanel, point, editor.getComponent());
|
||||
HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, editorPoint, HintManager.HIDE_BY_ANY_KEY |
|
||||
HintManager.HIDE_BY_TEXT_CHANGE |
|
||||
HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate requests
|
||||
|
||||
protected class MyNextChangeAction extends NextChangeAction {
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package com.intellij.diff.tools.fragmented;
|
||||
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.codeInsight.hint.HintManagerImpl;
|
||||
import com.intellij.codeInsight.hint.HintUtil;
|
||||
import com.intellij.diff.DiffContext;
|
||||
import com.intellij.diff.actions.BufferedLineIterator;
|
||||
import com.intellij.diff.actions.NavigationContextChecker;
|
||||
@@ -62,7 +59,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.UserDataHolder;
|
||||
import com.intellij.ui.LightweightHint;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.text.MergingCharSequence;
|
||||
@@ -600,14 +596,6 @@ public class OnesideDiffViewer extends TextDiffViewerBase {
|
||||
//
|
||||
|
||||
private class MyPrevNextDifferenceIterable implements PrevNextDifferenceIterable {
|
||||
@Override
|
||||
public void notify(@NotNull String message) {
|
||||
final LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(message));
|
||||
HintManagerImpl.getInstanceImpl().showEditorHint(hint, myEditor, HintManager.UNDER, HintManager.HIDE_BY_ANY_KEY |
|
||||
HintManager.HIDE_BY_TEXT_CHANGE |
|
||||
HintManager.HIDE_BY_SCROLLING, 0, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGoNext() {
|
||||
List<OnesideDiffChange> diffChanges = getDiffChanges();
|
||||
@@ -811,6 +799,9 @@ public class OnesideDiffViewer extends TextDiffViewerBase {
|
||||
if (DiffDataKeys.PREV_NEXT_DIFFERENCE_ITERABLE.is(dataId)) {
|
||||
return myPrevNextDifferenceIterable;
|
||||
}
|
||||
else if (DiffDataKeys.CURRENT_EDITOR.is(dataId)) {
|
||||
return myEditor;
|
||||
}
|
||||
else {
|
||||
return super.getData(dataId);
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package com.intellij.diff.tools.simple;
|
||||
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.codeInsight.hint.HintManagerImpl;
|
||||
import com.intellij.codeInsight.hint.HintUtil;
|
||||
import com.intellij.diff.DiffContext;
|
||||
import com.intellij.diff.actions.BufferedLineIterator;
|
||||
import com.intellij.diff.actions.NavigationContextChecker;
|
||||
@@ -57,7 +54,6 @@ import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.UserDataHolder;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.LightweightHint;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
@@ -488,16 +484,6 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer {
|
||||
//
|
||||
|
||||
private class MyPrevNextDifferenceIterable implements PrevNextDifferenceIterable {
|
||||
@Override
|
||||
public void notify(@NotNull String message) {
|
||||
final LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(message));
|
||||
HintManagerImpl.getInstanceImpl().showEditorHint(hint, getCurrentEditor(), HintManager.UNDER,
|
||||
HintManager.HIDE_BY_ANY_KEY |
|
||||
HintManager.HIDE_BY_TEXT_CHANGE |
|
||||
HintManager.HIDE_BY_SCROLLING,
|
||||
0, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGoNext() {
|
||||
if (myDiffChanges.isEmpty()) return false;
|
||||
|
||||
@@ -403,16 +403,6 @@ public class SimpleThreesideDiffViewer extends ThreesideTextDiffViewer {
|
||||
//
|
||||
|
||||
private class MyPrevNextDifferenceIterable implements PrevNextDifferenceIterable {
|
||||
@Override
|
||||
public void notify(@NotNull String message) {
|
||||
final LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(message));
|
||||
HintManagerImpl.getInstanceImpl().showEditorHint(hint, getCurrentEditor(), HintManager.UNDER,
|
||||
HintManager.HIDE_BY_ANY_KEY |
|
||||
HintManager.HIDE_BY_TEXT_CHANGE |
|
||||
HintManager.HIDE_BY_SCROLLING,
|
||||
0, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGoNext() {
|
||||
if (myDiffChanges.isEmpty()) return false;
|
||||
|
||||
@@ -19,9 +19,12 @@ import com.intellij.diff.DiffContext;
|
||||
import com.intellij.diff.FrameDiffTool;
|
||||
import com.intellij.diff.requests.DiffRequest;
|
||||
import com.intellij.openapi.actionSystem.DataKey;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
|
||||
public interface DiffDataKeys {
|
||||
DataKey<Editor> CURRENT_EDITOR = DataKey.create("diff_current_editor");
|
||||
|
||||
DataKey<DiffRequest> DIFF_REQUEST = DataKey.create("diff_request");
|
||||
DataKey<DiffContext> DIFF_CONTEXT = DataKey.create("diff_context");
|
||||
DataKey<FrameDiffTool.DiffViewer> DIFF_VIEWER = DataKey.create("diff_frame_viewer");
|
||||
|
||||
@@ -15,11 +15,7 @@
|
||||
*/
|
||||
package com.intellij.diff.tools.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PrevNextDifferenceIterable {
|
||||
void notify(@NotNull String message);
|
||||
|
||||
boolean canGoPrev();
|
||||
|
||||
boolean canGoNext();
|
||||
|
||||
+11
@@ -23,6 +23,7 @@ import com.intellij.diff.contents.DocumentContent;
|
||||
import com.intellij.diff.requests.ContentDiffRequest;
|
||||
import com.intellij.diff.requests.DiffRequest;
|
||||
import com.intellij.diff.requests.SimpleDiffRequest;
|
||||
import com.intellij.diff.tools.util.DiffDataKeys;
|
||||
import com.intellij.diff.tools.util.SyncScrollSupport;
|
||||
import com.intellij.diff.tools.util.SyncScrollSupport.ThreesideSyncScrollSupport;
|
||||
import com.intellij.diff.tools.util.base.TextDiffViewerBase;
|
||||
@@ -48,6 +49,7 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.CalledInAwt;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -373,6 +375,15 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase {
|
||||
// Helpers
|
||||
//
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getData(@NonNls String dataId) {
|
||||
if (DiffDataKeys.CURRENT_EDITOR.is(dataId)) {
|
||||
return getCurrentEditor();
|
||||
}
|
||||
return super.getData(dataId);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Graphics2D getDividerGraphics(@NotNull Graphics g, @NotNull Component divider) {
|
||||
int width = divider.getWidth();
|
||||
|
||||
+11
@@ -23,6 +23,7 @@ import com.intellij.diff.contents.DocumentContent;
|
||||
import com.intellij.diff.contents.EmptyContent;
|
||||
import com.intellij.diff.requests.ContentDiffRequest;
|
||||
import com.intellij.diff.requests.DiffRequest;
|
||||
import com.intellij.diff.tools.util.DiffDataKeys;
|
||||
import com.intellij.diff.tools.util.SyncScrollSupport;
|
||||
import com.intellij.diff.tools.util.SyncScrollSupport.TwosideSyncScrollSupport;
|
||||
import com.intellij.diff.tools.util.base.TextDiffViewerBase;
|
||||
@@ -48,6 +49,7 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.CalledInAwt;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -404,6 +406,15 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase {
|
||||
// Helpers
|
||||
//
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getData(@NonNls String dataId) {
|
||||
if (DiffDataKeys.CURRENT_EDITOR.is(dataId)) {
|
||||
return getCurrentEditor();
|
||||
}
|
||||
return super.getData(dataId);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Graphics2D getDividerGraphics(@NotNull Graphics g, @NotNull Component divider) {
|
||||
assert myEditor1 != null && myEditor2 != null;
|
||||
|
||||
Reference in New Issue
Block a user