Skip to content

Commit

Permalink
Event based project view focusing (#263)
Browse files Browse the repository at this point in the history
## Problem
Previously once project import starts, the code will check periodically whether the project is ready in order to zoom into the import directory, causing GUI to be sluggish every second before project is finally loaded.

## Solution
I have found the right event to subscribe, so zooming will only happen after the project is loaded. 

## Other change
Enable test on zooming.
Clarify code on variable meaning.
  • Loading branch information
wisechengyi authored Feb 23, 2017
1 parent 5e7f1fe commit 217c643
Showing 1 changed file with 20 additions and 6 deletions.
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

0 comments on commit 217c643

Please sign in to comment.