IDEA-165545 Reopening multiple projects on IDEA start should open them in a batch

This commit is contained in:
Dmitry Avdeev
2017-02-02 15:54:56 +03:00
parent 629d2bea8d
commit 85885990b7
13 changed files with 56 additions and 19 deletions
@@ -411,7 +411,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
myAutoScrollToSourceHandler.install(newPane.myTree);
IdeFocusManager.getInstance(myProject).requestFocus(newPane.getComponentToFocus(), false);
IdeFocusManager.getInstance(myProject).requestFocusInProject(newPane.getComponentToFocus(), myProject);
newPane.restoreExpandedPaths();
if (selectedPsiElement != null && newSubId != null) {
@@ -17,6 +17,7 @@ package com.intellij.openapi.wm;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.popup.util.PopupUtil;
import com.intellij.openapi.util.ActionCallback;
@@ -161,14 +162,16 @@ public abstract class FocusCommand extends ActiveRunnable implements Expirable {
public static class ByComponent extends FocusCommand {
private Component myToFocus;
@Nullable private final Project myProject;
private Throwable myAllocation;
public ByComponent(@Nullable Component toFocus, @NotNull Throwable allocation) {
this(toFocus, toFocus, allocation);
this(toFocus, toFocus, null, allocation);
}
public ByComponent(@Nullable Component toFocus, @Nullable Component dominationComponent, @NotNull Throwable allocation) {
public ByComponent(@Nullable Component toFocus, @Nullable Component dominationComponent, @Nullable Project project, @NotNull Throwable allocation) {
super(toFocus, dominationComponent);
myProject = project;
myAllocation = allocation;
myToFocus = toFocus;
}
@@ -198,9 +201,12 @@ public abstract class FocusCommand extends ActiveRunnable implements Expirable {
LOG.info(myAllocation);
}
if (ApplicationManager.getApplication().isActive()) {
myToFocus.requestFocus();
if (shouldLogFocuses) {
LOG.info("Force request focus on " + myToFocus.getClass().getName());
IdeFrame frame = IdeFocusManager.getGlobalInstance().getLastFocusedFrame();
if (frame == null || myProject == null || myProject == frame.getProject()) {
myToFocus.requestFocus();
if (shouldLogFocuses) {
LOG.info("Force request focus on " + myToFocus.getClass().getName());
}
}
}
}
@@ -52,6 +52,10 @@ import java.awt.event.KeyEvent;
public abstract class IdeFocusManager implements FocusRequestor {
public ActionCallback requestFocusInProject(@NotNull Component c, @Nullable Project project) {
return requestFocus(c, false);
}
/**
* Finds most suitable component to request focus to. For instance you may pass a JPanel instance,
* this method will traverse into it's children to find focusable component
@@ -990,7 +990,7 @@ public class JBTabsImpl extends JComponent
});
myDeferredFocusRequest = () -> {
queued.set(true);
requestor.requestFocus(new FocusCommand.ByComponent(toFocus, new Exception()), true).notify(result);
requestor.requestFocus(new FocusCommand.ByComponent(toFocus, toFocus, myProject, new Exception()), true).notify(result);
};
return result;
}
@@ -106,6 +106,7 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
private final Map<String, String> myNameCache = Collections.synchronizedMap(new THashMap<String, String>());
private Set<String> myDuplicatesCache = null;
private boolean isDuplicatesCacheUpdating = false;
private boolean myBatchOpening;
protected RecentProjectsManagerBase(@NotNull MessageBus messageBus) {
MessageBusConnection connection = messageBus.connect();
@@ -610,14 +611,24 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
forceNewFrame = false;
}
}
for (String openPath : openPaths) {
if (ProjectKt.isValidProjectPath(openPath)) {
doOpenProject(openPath, null, forceNewFrame);
try {
myBatchOpening = true;
for (String openPath : openPaths) {
if (ProjectKt.isValidProjectPath(openPath)) {
doOpenProject(openPath, null, forceNewFrame);
}
}
}
finally {
myBatchOpening = false;
}
}
}
public boolean isBatchOpening() {
return myBatchOpening;
}
@Override
public List<ProjectGroup> getGroups() {
return Collections.unmodifiableList(myState.groups);
@@ -167,7 +167,7 @@ public class AsyncEditorLoader {
myEditor.getScrollingModel().enableAnimation();
if (FileEditorManager.getInstance(myProject).getSelectedTextEditor() == myEditor) {
IdeFocusManager.getInstance(myProject).requestFocus(myTextEditor.getPreferredFocusedComponent(), true);
IdeFocusManager.getInstance(myProject).requestFocusInProject(myTextEditor.getPreferredFocusedComponent(), myProject);
}
EditorNotifications.getInstance(myProject).updateNotifications(myTextEditor.myFile);
}
@@ -302,7 +302,7 @@ class ProgressDialog implements Disposable {
}
}
myProgressWindow.getFocusManager().requestFocus(myCancelButton, true).doWhenDone(myRepaintRunnable);
myProgressWindow.getFocusManager().requestFocusInProject(myCancelButton, myProgressWindow.myProject).doWhenDone(myRepaintRunnable);
}
});
@@ -26,6 +26,7 @@ import com.intellij.openapi.application.*;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.components.impl.ServiceManagerImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.registry.Registry;
@@ -187,6 +188,10 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
return myLastFocusedFrame;
}
public ActionCallback requestFocusInProject(@NotNull Component c, @Nullable Project project) {
return requestFocus(new FocusCommand.ByComponent(c, c, project, new Exception()), false);
}
@Override
@NotNull
public ActionCallback requestFocus(@NotNull final Component c, final boolean forced) {
@@ -17,6 +17,7 @@ package com.intellij.openapi.wm.impl;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.Expirable;
import com.intellij.openapi.util.ExpirableRunnable;
@@ -50,6 +51,11 @@ public class IdeFocusManagerImpl extends IdeFocusManager {
return getGlobalInstance().requestFocus(command, forced);
}
@Override
public ActionCallback requestFocusInProject(@NotNull Component c, @Nullable Project project) {
return getGlobalInstance().requestFocusInProject(c, project);
}
@Override
public JComponent getFocusTargetFor(@NotNull final JComponent comp) {
return getGlobalInstance().getFocusTargetFor(comp);
@@ -234,7 +234,6 @@ public class IdeFrameImpl extends JFrame implements IdeFrameEx, AccessibleContex
return null;
}
@SuppressWarnings({"deprecation", "SSBasedInspection"})
@Override
public void show() {
super.show();
@@ -1771,7 +1771,7 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements
final ToolWindowImpl toolWindow = (ToolWindowImpl)getToolWindow(id);
final FocusWatcher focusWatcher = myId2FocusWatcher.get(id);
commandList
.add(new RequestFocusInToolWindowCmd(getFocusManager(), toolWindow, focusWatcher, myCommandProcessor, forced));
.add(new RequestFocusInToolWindowCmd(getFocusManager(), toolWindow, focusWatcher, myCommandProcessor, myProject));
}
/**
@@ -18,6 +18,7 @@ package com.intellij.openapi.wm.impl;
import com.intellij.ide.AppLifecycleListener;
import com.intellij.ide.DataManager;
import com.intellij.ide.GeneralSettings;
import com.intellij.ide.RecentProjectsManagerBase;
import com.intellij.ide.impl.DataManagerImpl;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
@@ -562,6 +563,9 @@ public final class WindowManagerImpl extends WindowManagerEx implements NamedCom
myProject2Frame.put(project, frame);
frame.setExtendedState(myFrameExtendedState);
frame.setVisible(true);
if (RecentProjectsManagerBase.getInstanceEx().isBatchOpening()) {
frame.toBack();
}
}
frame.addWindowListener(myActivationListener);
@@ -16,6 +16,7 @@
package com.intellij.openapi.wm.impl.commands;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.Expirable;
import com.intellij.openapi.wm.FocusCommand;
@@ -43,14 +44,14 @@ public final class RequestFocusInToolWindowCmd extends FinalizableCommand {
private final ToolWindowImpl myToolWindow;
private final FocusWatcher myFocusWatcher;
private final boolean myForced;
private final Project myProject;
private final Expirable myTimestamp;
public RequestFocusInToolWindowCmd(IdeFocusManager focusManager, final ToolWindowImpl toolWindow, final FocusWatcher focusWatcher, final Runnable finishCallBack, boolean forced) {
public RequestFocusInToolWindowCmd(IdeFocusManager focusManager, final ToolWindowImpl toolWindow, final FocusWatcher focusWatcher, final Runnable finishCallBack, Project project) {
super(finishCallBack);
myToolWindow = toolWindow;
myFocusWatcher = focusWatcher;
myForced = forced;
myProject = project;
myTimestamp = focusManager.getTimestamp(true);
}
@@ -161,10 +162,11 @@ public final class RequestFocusInToolWindowCmd extends FinalizableCommand {
public ActionCallback run() {
return ActionCallback.DONE;
}
}, myForced).doWhenProcessed(() -> updateToolWindow(c)).notify(result);
}, false).doWhenProcessed(() -> updateToolWindow(c)).notify(result);
}
else {
myManager.getFocusManager().requestFocus(new FocusCommand.ByComponent(c, myToolWindow.getComponent(), new Exception()), myForced)
myManager.getFocusManager().requestFocus(new FocusCommand.ByComponent(c, myToolWindow.getComponent(), myProject, new Exception()),
false)
.doWhenProcessed(() -> updateToolWindow(c)).notify(result);
}
}