use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class FocusTracesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
final IdeFocusManager manager = IdeFocusManager.getGlobalInstance();
if (!(manager instanceof FocusManagerImpl))
return;
final FocusManagerImpl focusManager = (FocusManagerImpl) manager;
myActive = !myActive;
if (myActive) {
myFocusTracker = new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent event) {
if (event instanceof FocusEvent && event.getID() == FocusEvent.FOCUS_GAINED) {
focusManager.recordFocusRequest(((FocusEvent) event).getComponent(), false);
}
}
};
Toolkit.getDefaultToolkit().addAWTEventListener(myFocusTracker, AWTEvent.FOCUS_EVENT_MASK);
}
if (!myActive) {
final List<FocusRequestInfo> requests = focusManager.getRequests();
new FocusTracesDialog(project, new ArrayList<>(requests)).show();
Toolkit.getDefaultToolkit().removeAWTEventListener(myFocusTracker);
myFocusTracker = null;
requests.clear();
}
}
use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class DataManagerImpl method getFocusedComponent.
@Nullable
private Component getFocusedComponent() {
if (myWindowManager == null) {
return null;
}
Window activeWindow = myWindowManager.getMostRecentFocusedWindow();
if (activeWindow == null) {
activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
if (activeWindow == null) {
activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
if (activeWindow == null)
return null;
}
}
if (Registry.is("actionSystem.noContextComponentWhileFocusTransfer")) {
IdeFocusManager fm = IdeFocusManager.findInstanceByComponent(activeWindow);
if (fm.isFocusBeingTransferred()) {
return null;
}
}
// whereas we want to be able to type in other frames as well.
if (activeWindow instanceof FloatingDecorator) {
IdeFocusManager ideFocusManager = IdeFocusManager.findInstanceByComponent(activeWindow);
IdeFrame lastFocusedFrame = ideFocusManager.getLastFocusedFrame();
JComponent frameComponent = lastFocusedFrame != null ? lastFocusedFrame.getComponent() : null;
Window lastFocusedWindow = frameComponent != null ? SwingUtilities.getWindowAncestor(frameComponent) : null;
boolean toolWindowIsNotFocused = myWindowManager.getFocusedComponent(activeWindow) == null;
if (toolWindowIsNotFocused && lastFocusedWindow != null) {
activeWindow = lastFocusedWindow;
}
}
// try to find first parent window that has focus
Window window = activeWindow;
Component focusedComponent = null;
while (window != null) {
focusedComponent = myWindowManager.getFocusedComponent(window);
if (focusedComponent != null) {
break;
}
window = window.getOwner();
}
if (focusedComponent == null) {
focusedComponent = activeWindow;
}
return focusedComponent;
}
use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class DirDiffPanel method focusTable.
public void focusTable() {
final Project project = myModel.getProject();
final IdeFocusManager focusManager = project == null || project.isDefault() ? IdeFocusManager.getGlobalInstance() : IdeFocusManager.getInstance(project);
focusManager.requestFocus(myTable, true);
}
use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class ChooseByNameBase method showTextFieldPanel.
protected void showTextFieldPanel() {
final JLayeredPane layeredPane = getLayeredPane();
final Dimension preferredTextFieldPanelSize = myTextFieldPanel.getPreferredSize();
final int x = (layeredPane.getWidth() - preferredTextFieldPanelSize.width) / 2;
final int paneHeight = layeredPane.getHeight();
final int y = paneHeight / 3 - preferredTextFieldPanelSize.height / 2;
VISIBLE_LIST_SIZE_LIMIT = Math.max(10, (paneHeight - (y + preferredTextFieldPanelSize.height)) / (preferredTextFieldPanelSize.height / 2) - 1);
ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(myTextFieldPanel, myTextField);
builder.setLocateWithinScreenBounds(false);
builder.setKeyEventHandler(event -> {
if (myTextPopup == null || !AbstractPopup.isCloseRequest(event) || !myTextPopup.isCancelKeyEnabled()) {
return false;
}
IdeFocusManager focusManager = IdeFocusManager.getInstance(myProject);
if (isDescendingFromTemporarilyFocusableToolWindow(focusManager.getFocusOwner())) {
focusManager.requestFocus(myTextField, true);
return false;
} else {
myTextPopup.cancel(event);
return true;
}
}).setCancelCallback(() -> {
myTextPopup = null;
close(false);
return Boolean.TRUE;
}).setFocusable(true).setRequestFocus(true).setModalContext(false).setCancelOnClickOutside(false);
Point point = new Point(x, y);
SwingUtilities.convertPointToScreen(point, layeredPane);
Rectangle bounds = new Rectangle(point, new Dimension(preferredTextFieldPanelSize.width + 20, preferredTextFieldPanelSize.height));
myTextPopup = builder.createPopup();
myTextPopup.setSize(bounds.getSize());
myTextPopup.setLocation(bounds.getLocation());
MnemonicHelper.init(myTextFieldPanel);
if (myProject != null && !myProject.isDefault()) {
DaemonCodeAnalyzer.getInstance(myProject).disableUpdateByTimer(myTextPopup);
}
Disposer.register(myTextPopup, new Disposable() {
@Override
public void dispose() {
cancelListUpdater();
}
});
myTextPopup.show(layeredPane);
}
use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class FileEditorManagerImpl method notifyPublisher.
@NotNull
@Override
public ActionCallback notifyPublisher(@NotNull final Runnable runnable) {
final IdeFocusManager focusManager = IdeFocusManager.getInstance(myProject);
final ActionCallback done = new ActionCallback();
return myBusyObject.execute(new ActiveRunnable() {
@NotNull
@Override
public ActionCallback run() {
focusManager.doWhenFocusSettlesDown(new ExpirableRunnable.ForProject(myProject) {
@Override
public void run() {
runnable.run();
done.setDone();
}
});
return done;
}
});
}
Aggregations