use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class DiffPanelImpl method setDiffRequest.
public void setDiffRequest(DiffRequest data) {
myDiffRequest = data;
if (data.getHints().contains(DiffTool.HINT_DO_NOT_IGNORE_WHITESPACES)) {
setComparisonPolicy(ComparisonPolicy.DEFAULT, false);
}
myDataProvider.putData(myDiffRequest.getGenericData());
DiffContent content1 = data.getContents()[0];
DiffContent content2 = data.getContents()[1];
setContents(content1, content2);
setTitles(data);
setWindowTitle(myOwnerWindow, data.getWindowTitle());
myPanel.setToolbarActions(createToolbar());
data.customizeToolbar(myPanel.resetToolbar());
myPanel.registerToolbarActions();
initEditorSettings(getEditor1());
initEditorSettings(getEditor2());
final JComponent oldBottomComponent = myPanel.getBottomComponent();
if (oldBottomComponent instanceof Disposable) {
Disposer.dispose((Disposable) oldBottomComponent);
}
final JComponent newBottomComponent = data.getBottomComponent();
myPanel.setBottomComponent(newBottomComponent);
if (myIsRequestFocus) {
IdeFocusManager fm = IdeFocusManager.getInstance(myProject);
boolean isEditor1Focused = getEditor1() != null && fm.getFocusedDescendantFor(getEditor1().getComponent()) != null;
boolean isEditor2Focused = myData.getContent2() != null && getEditor2() != null && fm.getFocusedDescendantFor(getEditor2().getComponent()) != null;
if (isEditor1Focused || isEditor2Focused) {
Editor e = isEditor2Focused ? getEditor2() : getEditor1();
if (e != null) {
fm.requestFocus(e.getContentComponent(), true);
}
}
myPanel.requestScrollEditors();
}
}
use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class JBTable method editCellAt.
@Override
public boolean editCellAt(final int row, final int column, final EventObject e) {
if (cellEditor != null && !cellEditor.stopCellEditing()) {
return false;
}
if (row < 0 || row >= getRowCount() || column < 0 || column >= getColumnCount()) {
return false;
}
if (!isCellEditable(row, column)) {
return false;
}
if (e instanceof KeyEvent) {
// do not start editing in autoStartsEdit mode on Ctrl-Z and other non-typed events
if (!UIUtil.isReallyTypedEvent((KeyEvent) e) || ((KeyEvent) e).getKeyChar() == KeyEvent.CHAR_UNDEFINED)
return false;
SpeedSearchSupply supply = SpeedSearchSupply.getSupply(this);
if (supply != null && supply.isPopupActive()) {
return false;
}
}
final TableCellEditor editor = getCellEditor(row, column);
if (editor != null && editor.isCellEditable(e)) {
editorComp = prepareEditor(editor, row, column);
//((JComponent)editorComp).setBorder(null);
if (editorComp == null) {
removeEditor();
return false;
}
editorComp.setBounds(getCellRect(row, column, false));
add(editorComp);
editorComp.validate();
if (surrendersFocusOnKeyStroke()) {
// this replaces focus request in JTable.processKeyBinding
final IdeFocusManager focusManager = IdeFocusManager.findInstanceByComponent(this);
focusManager.setTypeaheadEnabled(false);
focusManager.requestFocus(editorComp, true).doWhenProcessed(() -> focusManager.setTypeaheadEnabled(true));
}
setCellEditor(editor);
setEditingRow(row);
setEditingColumn(column);
editor.addCellEditorListener(this);
return true;
}
return false;
}
use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class ToolbarUpdater method updateActions.
private void updateActions(boolean now, final boolean transparentOnly, final boolean forced) {
final Runnable updateRunnable = new MyUpdateRunnable(this, transparentOnly, forced);
final Application app = ApplicationManager.getApplication();
if (now || app.isUnitTestMode()) {
updateRunnable.run();
} else {
final IdeFocusManager fm = IdeFocusManager.getInstance(null);
if (!app.isHeadlessEnvironment()) {
if (app.isDispatchThread() && myComponent.isShowing()) {
fm.doWhenFocusSettlesDown(updateRunnable);
} else {
UiNotifyConnector.doWhenFirstShown(myComponent, () -> fm.doWhenFocusSettlesDown(updateRunnable));
}
}
}
}
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 IdeEventQueue method storeLastFocusedComponent.
private static void storeLastFocusedComponent(@NotNull WindowEvent we) {
final Window eventWindow = we.getWindow();
if (we.getID() == WindowEvent.WINDOW_DEACTIVATED || we.getID() == WindowEvent.WINDOW_LOST_FOCUS) {
Component frame = UIUtil.findUltimateParent(eventWindow);
Component focusOwnerInDeactivatedWindow = eventWindow.getMostRecentFocusOwner();
IdeFrame[] allProjectFrames = WindowManager.getInstance().getAllProjectFrames();
if (focusOwnerInDeactivatedWindow != null) {
for (IdeFrame ideFrame : allProjectFrames) {
JFrame aFrame = WindowManager.getInstance().getFrame(ideFrame.getProject());
if (aFrame.equals(frame)) {
IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance();
if (focusManager instanceof FocusManagerImpl) {
((FocusManagerImpl) focusManager).setLastFocusedAtDeactivation(ideFrame, focusOwnerInDeactivatedWindow);
}
}
}
}
}
}
Aggregations