mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-88319 Tip of the Day should have focus after Idea startup
This commit is contained in:
@@ -162,7 +162,7 @@ public abstract class DialogWrapper {
|
||||
@Nullable
|
||||
private DoNotAskOption myDoNotAsk;
|
||||
|
||||
private JComponent myPreferredFocusedComponent;
|
||||
protected JComponent myPreferredFocusedComponent;
|
||||
private Computable<Point> myInitialLocationCallback;
|
||||
|
||||
protected final Disposable myDisposable = new Disposable() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.openapi.wm;
|
||||
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.popup.util.PopupUtil;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.util.ActiveRunnable;
|
||||
@@ -141,6 +142,10 @@ public abstract class FocusCommand extends ActiveRunnable implements Expirable {
|
||||
return myAllocation;
|
||||
}
|
||||
|
||||
public boolean canFocusChangeFrom(@Nullable Component component) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final Object[] objects = getEqualityObjects();
|
||||
@@ -213,5 +218,11 @@ public abstract class FocusCommand extends ActiveRunnable implements Expirable {
|
||||
public Component getComponent() {
|
||||
return myToFocus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFocusChangeFrom(@Nullable Component component) {
|
||||
DialogWrapper dialog = DialogWrapper.findInstance(component);
|
||||
return (dialog == null) || (dialog == DialogWrapper.findInstance(myToFocus));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.internal.statistic.UsageTrigger;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.impl.DialogWrapperPeerImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -72,6 +73,7 @@ public class TipDialog extends DialogWrapper{
|
||||
public NextTipAction(){
|
||||
super(IdeBundle.message("action.next.tip"));
|
||||
putValue(DialogWrapper.DEFAULT_ACTION,Boolean.TRUE);
|
||||
putValue(DialogWrapper.FOCUSED_ACTION,Boolean.TRUE); // myPreferredFocusedComponent
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e){
|
||||
@@ -79,4 +81,10 @@ public class TipDialog extends DialogWrapper{
|
||||
UsageTrigger.trigger("tips.of.the.day.next");
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return myPreferredFocusedComponent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -745,6 +745,16 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer implements FocusTra
|
||||
|
||||
@Override
|
||||
public void windowOpened(WindowEvent e) {
|
||||
if (!isModal()) {
|
||||
DialogWrapper wrapper = getDialogWrapper();
|
||||
if (wrapper != null) {
|
||||
JComponent component = wrapper.getPreferredFocusedComponent();
|
||||
if (component != null) {
|
||||
// request focus for non-modal dialog (i.e. TipDialog)
|
||||
IdeFocusManager.findInstance().requestFocus(component, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!SystemInfo.isMacOSLion) return;
|
||||
Window window = e.getWindow();
|
||||
if (window instanceof Dialog) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -203,6 +203,9 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
public ActionCallback requestFocus(@NotNull final FocusCommand command, final boolean forced) {
|
||||
assertDispatchThread();
|
||||
|
||||
if (!forced && !command.canFocusChangeFrom(getFocusOwner())) {
|
||||
return ActionCallback.REJECTED;
|
||||
}
|
||||
if (isInternalMode) {
|
||||
recordCommand(command, new Throwable(), forced);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user