IDEA-198037 new.search.everywhere opens on the wrong screen

This commit is contained in:
Mikhail Sokolov
2018-09-07 19:24:28 +03:00
parent f01b37156f
commit b46f19c55b
@@ -11,15 +11,18 @@ import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.DimensionService;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.ui.SearchTextField;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.ui.JBInsets;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -136,18 +139,26 @@ public class SearchEverywhereManagerImpl implements SearchEverywhereManager {
private void calcPositionAndShow(Project project, JBPopup balloon) {
Point savedLocation = DimensionService.getInstance().getLocation(LOCATION_SETTINGS_KEY, project);
//for first show and short mode popup should be shifted to the top screen half
if (savedLocation == null && mySearchEverywhereUI.getViewType() == SearchEverywhereUI.ViewType.SHORT) {
Window window = project != null
? WindowManager.getInstance().suggestParentWindow(project)
: KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
Component parent = UIUtil.findUltimateParent(window);
if (parent != null) {
Dimension balloonSize = balloon.getContent().getPreferredSize();
RelativePoint showPoint = new RelativePoint(parent, new Point((parent.getSize().width - balloonSize.width) / 2, parent.getHeight() / 4 - balloonSize.height / 2));
balloon.show(showPoint);
return;
}
}
if (project != null) {
balloon.showCenteredInCurrentWindow(project);
} else {
balloon.showInFocusCenter();
}
//for first show and short mode popup should be shifted to the top screen half
if (savedLocation == null && mySearchEverywhereUI.getViewType() == SearchEverywhereUI.ViewType.SHORT) {
Point location = balloon.getLocationOnScreen();
location.y /= 2;
balloon.setLocation(location);
}
}
@Override