Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event based project view focusing #263

Merged
merged 4 commits into from
Feb 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.twitter.intellij.pants.service.project;

import com.intellij.ProjectTopics;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.process.ProcessOutputTypes;
Expand All @@ -27,13 +28,17 @@
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleTypeId;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootAdapter;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.util.Consumer;
import com.intellij.util.messages.MessageBusConnection;
import com.twitter.intellij.pants.metrics.PantsExternalMetricsListenerManager;
import com.twitter.intellij.pants.projectview.PantsProjectPaneSelectInTarget;
import com.twitter.intellij.pants.projectview.ProjectFilesViewPane;
Expand Down Expand Up @@ -91,7 +96,18 @@ private void doViewSwitch(@NotNull ExternalSystemTaskId id, @NotNull String proj
if (ModuleManager.getInstance(ideProject).getModules().length > 0) {
return;
}
new ViewSwitchProcessor(ideProject, projectPath).asyncViewSwitch();

MessageBusConnection messageBusConnection = ideProject.getMessageBus().connect();
messageBusConnection.subscribe(
ProjectTopics.PROJECT_ROOTS,
new ModuleRootAdapter() {
@Override
public void rootsChanged(ModuleRootEvent event) {
// Initiate view switch only when project modules have been created.
new ViewSwitchProcessor(ideProject, projectPath).asyncViewSwitch();
}
}
);
}

/**
Expand Down Expand Up @@ -226,10 +242,7 @@ public void asyncViewSwitch() {
/**
* Make sure the project view opened so the view switch will follow.
*/
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}
final ToolWindow projectWindow = ToolWindowManager.getInstance(myProject).getToolWindow("Project");
final ToolWindow projectWindow = ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.PROJECT_VIEW);
if (projectWindow == null) {
return;
}
Expand Down Expand Up @@ -271,7 +284,8 @@ public void run() {
}
}
}
directoryFocusHandle.cancel(false);
final boolean mayInterruptIfRunning = true;
directoryFocusHandle.cancel(mayInterruptIfRunning);
}
});
}
Expand Down