fixed PY-16936 Several tasks 'Updating skeletons' is launched if packages are installed right after adding new remote interpreter

This commit is contained in:
Ekaterina Tuzova
2015-10-11 17:37:56 +03:00
parent a6165d8003
commit dd851d64c5
5 changed files with 18 additions and 16 deletions
@@ -19,9 +19,6 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.UnnamedConfigurable;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkModel;
@@ -276,12 +273,8 @@ public class PyActiveSdkConfigurable implements UnnamedConfigurable {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
ProgressManager.getInstance().run(new Task.Backgroundable(myProject, PyBundle.message("sdk.gen.updating.skels"), false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
PythonSdkUpdater.updateSdk(finalSelectedSdk, myProject);
}
});
assert finalSelectedSdk != null;
PythonSdkType.getInstance().setupSdkPaths(finalSelectedSdk, myProject, null);
}
});
}
@@ -418,7 +418,7 @@ public class PythonSdkDetailsDialog extends DialogWrapper {
}
private void reloadSdk(Sdk currentSdk) {
PythonSdkType.setupSdkPaths(currentSdk, myProject, null, myModificators.get(currentSdk)); // or must it be a RunWriteAction?
PythonSdkType.getInstance().setupSdkPaths(currentSdk, myProject, null, myModificators.get(currentSdk)); // or must it be a RunWriteAction?
}
private class ToggleVirtualEnvFilterButton extends ToggleActionButton implements DumbAware {
@@ -67,7 +67,7 @@ public class GenerateProjectCallback implements NullableConsumer<ProjectSettings
sdk = SdkConfigurationUtil.createAndAddSDK(sdkHome.getPath(), PythonSdkType.getInstance());
if (sdk != null) {
final SdkModificator modificator = sdk.getSdkModificator();
PythonSdkType.setupSdkPaths(sdk, project, null, modificator);
PythonSdkType.getInstance().setupSdkPaths(sdk, project, null, modificator);
modificator.commitChanges();
}
@@ -63,6 +63,7 @@ import com.intellij.util.ArrayUtil;
import com.intellij.util.Consumer;
import com.intellij.util.ExceptionUtil;
import com.intellij.util.NullableConsumer;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
import com.jetbrains.python.PyBundle;
import com.jetbrains.python.PyNames;
@@ -110,6 +111,8 @@ public class PythonSdkType extends SdkType {
private static final Key<WeakReference<Component>> SDK_CREATOR_COMPONENT_KEY = Key.create("#com.jetbrains.python.sdk.creatorComponent");
private Set<String> scheduledToRefresh = ContainerUtil.newConcurrentSet();
public static PythonSdkType getInstance() {
return SdkType.findInstance(PythonSdkType.class);
}
@@ -521,15 +524,17 @@ public class PythonSdkType extends SdkType {
return true; // run setupSdkPaths only once (from PythonSdkDetailsStep). Skip this from showCustomCreateUI
}
public static void setupSdkPaths(@NotNull final Sdk sdk,
public void setupSdkPaths(@NotNull final Sdk sdk,
@Nullable final Project project,
@Nullable final Component ownerComponent,
@NotNull final SdkModificator sdkModificator) {
scheduledToRefresh.add(sdk.getHomePath());
doSetupSdkPaths(project, ownerComponent, PySdkUpdater.fromSdkModificator(sdk, sdkModificator));
}
public static void setupSdkPaths(final Sdk sdk, @Nullable final Project project, @Nullable final Component ownerComponent) {
public void setupSdkPaths(final Sdk sdk, @Nullable final Project project, @Nullable final Component ownerComponent) {
scheduledToRefresh.add(sdk.getHomePath());
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
@@ -551,7 +556,7 @@ public class PythonSdkType extends SdkType {
}, ModalityState.NON_MODAL);
}
private static boolean doSetupSdkPaths(@Nullable final Project project,
private boolean doSetupSdkPaths(@Nullable final Project project,
@Nullable final Component ownerComponent,
@NotNull final PySdkUpdater sdkUpdater) {
if (isRemote(sdkUpdater.getSdk()) && project == null && ownerComponent == null) {
@@ -572,6 +577,10 @@ public class PythonSdkType extends SdkType {
application.invokeLater(new Runnable() {
@Override
public void run() {
if (!scheduledToRefresh.contains(sdkUpdater.getHomePath())) {
return;
}
scheduledToRefresh.remove(sdkUpdater.getHomePath());
progressManager.run(new Task.Backgroundable(project, PyBundle.message("sdk.gen.updating.skels"), false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
@@ -78,7 +78,7 @@ public class PythonSdkUpdater implements StartupActivity {
updateActiveSdks(project, 7000);
}
public void updateActiveSdks(@NotNull final Project project, final int delay) {
public static void updateActiveSdks(@NotNull final Project project, final int delay) {
final Set<Sdk> sdksToUpdate = new HashSet<Sdk>();
for (Module module : ModuleManager.getInstance(project).getModules()) {
final Sdk sdk = PythonSdkType.findPythonSdk(module);
@@ -96,7 +96,7 @@ public class PythonSdkUpdater implements StartupActivity {
}
}
private void updateSdks(final Project project, final int delay, final Set<Sdk> sdksToUpdate) {
private static void updateSdks(final Project project, final int delay, final Set<Sdk> sdksToUpdate) {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
public void run() {
if (delay > 0) {