mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
loading project under one progress (take two): continuous progress
This commit is contained in:
@@ -100,10 +100,6 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
|
||||
if (componentsRegistered != null) {
|
||||
componentsRegistered.run();
|
||||
}
|
||||
|
||||
if (indicator != null) {
|
||||
indicator.setIndeterminate(false);
|
||||
}
|
||||
createComponents(indicator);
|
||||
myComponentsCreated = true;
|
||||
}
|
||||
|
||||
+10
-12
@@ -255,27 +255,25 @@ public class EditorsSplitters extends IdePanePanel implements UISettingsListener
|
||||
}
|
||||
}
|
||||
|
||||
private double myProgressMaximum;
|
||||
private int myCurrentProgress;
|
||||
|
||||
private void initializeProgress() {
|
||||
private static void initializeProgress() {
|
||||
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
if (indicator != null) {
|
||||
indicator.setText(IdeBundle.message("loading.editors"));
|
||||
indicator.setText2("");
|
||||
indicator.setIndeterminate(false);
|
||||
indicator.setFraction(0);
|
||||
|
||||
myProgressMaximum = countFiles(mySplittersElement);
|
||||
myCurrentProgress = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int getEditorsCount() {
|
||||
return mySplittersElement == null ? 0 : countFiles(mySplittersElement);
|
||||
}
|
||||
|
||||
private double myProgressStep;
|
||||
|
||||
public void setProgressStep(double step) { myProgressStep = step; }
|
||||
|
||||
private void updateProgress() {
|
||||
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
if (indicator != null) {
|
||||
myCurrentProgress++;
|
||||
indicator.setFraction(myCurrentProgress / myProgressMaximum);
|
||||
indicator.setFraction(indicator.getFraction() + myProgressStep);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class ProgressDialog implements Disposable {
|
||||
|
||||
if (myProgressBar.isShowing()) {
|
||||
final int perc = (int)(fraction * 100);
|
||||
myProgressBar.setIndeterminate(perc == 0 || myProgressWindow.isIndeterminate());
|
||||
myProgressBar.setIndeterminate(myProgressWindow.isIndeterminate());
|
||||
myProgressBar.setValue(perc);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,11 @@ import com.intellij.openapi.components.impl.stores.StoreUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.impl.EditorsSplitters;
|
||||
import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.impl.ModuleManagerImpl;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressIndicatorProvider;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
@@ -74,6 +79,7 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project
|
||||
private final AtomicBoolean mySavingInProgress = new AtomicBoolean(false);
|
||||
private String myName;
|
||||
private final boolean myLight;
|
||||
private static boolean ourClassesAreLoaded;
|
||||
|
||||
/**
|
||||
* @param filePath System-independent path
|
||||
@@ -276,22 +282,15 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project
|
||||
public void init() {
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
final ProgressIndicator progressIndicator = isDefault() ? null : ProgressIndicatorProvider.getGlobalProgressIndicator();
|
||||
if (progressIndicator != null) {
|
||||
progressIndicator.pushState();
|
||||
}
|
||||
try {
|
||||
init(progressIndicator);
|
||||
}
|
||||
finally {
|
||||
if (progressIndicator != null) {
|
||||
progressIndicator.popState();
|
||||
}
|
||||
}
|
||||
ProgressIndicator progressIndicator = isDefault() ? null : ProgressIndicatorProvider.getGlobalProgressIndicator();
|
||||
init(progressIndicator);
|
||||
|
||||
long time = System.currentTimeMillis() - start;
|
||||
LOG.info(getComponentConfigCount() + " project components initialized in " + time + " ms");
|
||||
|
||||
if (!isDefault()) {
|
||||
distributeProgress();
|
||||
}
|
||||
ApplicationManager.getApplication().getMessageBus().syncPublisher(ProjectLifecycleListener.TOPIC).projectComponentsInitialized(this);
|
||||
|
||||
//noinspection SynchronizeOnThis
|
||||
@@ -301,6 +300,33 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setProgressDuringInit(@NotNull ProgressIndicator indicator) {
|
||||
indicator.setFraction(getPercentageOfComponentsLoaded() / (ourClassesAreLoaded ? 10 : 2));
|
||||
}
|
||||
|
||||
private void distributeProgress() {
|
||||
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
if (indicator == null) return;
|
||||
|
||||
double toDistribute = 1 - indicator.getFraction();
|
||||
ModuleManagerImpl moduleManager = (ModuleManagerImpl)ModuleManager.getInstance(this);
|
||||
int modulesCount = moduleManager.getModulePathsCount();
|
||||
EditorsSplitters splitters = ((FileEditorManagerImpl)FileEditorManager.getInstance(this)).getMainSplitters();
|
||||
int editors = splitters.getEditorsCount();
|
||||
|
||||
double modulesPart = (ourClassesAreLoaded || editors == 0) ? toDistribute : toDistribute * 0.5;
|
||||
if (modulesCount != 0) {
|
||||
|
||||
double step = modulesPart / modulesCount;
|
||||
moduleManager.setProgressStep(step);
|
||||
}
|
||||
|
||||
if (editors != 0) {
|
||||
splitters.setProgressStep(toDistribute - modulesPart / editors);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
if (ApplicationManagerEx.getApplicationEx().isDoNotSave()) {
|
||||
@@ -359,6 +385,7 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project
|
||||
LOG.error(component.toString(), e);
|
||||
}
|
||||
}
|
||||
ourClassesAreLoaded = true;
|
||||
}
|
||||
|
||||
private void projectClosed() {
|
||||
|
||||
@@ -215,7 +215,6 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
|
||||
ProgressIndicator indicator = myProgressManager.getProgressIndicator();
|
||||
if (indicator != null && !project.isDefault()) {
|
||||
indicator.setText(ProjectBundle.message("loading.components.for", project.getName()));
|
||||
indicator.setIndeterminate(true);
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().getMessageBus().syncPublisher(ProjectLifecycleListener.TOPIC).beforeProjectLoaded(project);
|
||||
|
||||
+11
-9
@@ -255,10 +255,9 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project
|
||||
final List<Module> modulesWithUnknownTypes = new ArrayList<Module>();
|
||||
List<ModuleLoadingErrorDescription> errors = new ArrayList<ModuleLoadingErrorDescription>();
|
||||
|
||||
for (int i = 0; i < myModulePaths.size(); i++) {
|
||||
ModulePath modulePath = myModulePaths.get(i);
|
||||
for (ModulePath modulePath : myModulePaths) {
|
||||
if (progressIndicator != null) {
|
||||
progressIndicator.setFraction((double) i / myModulePaths.size());
|
||||
progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
|
||||
}
|
||||
try {
|
||||
final Module module = moduleModel.loadModuleInternal(modulePath.getPath());
|
||||
@@ -274,8 +273,9 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project
|
||||
myFailedModulePaths.remove(modulePath);
|
||||
}
|
||||
catch (IOException e) {
|
||||
errors.add(ModuleLoadingErrorDescription.create(ProjectBundle.message("module.cannot.load.error", modulePath.getPath(), e.getMessage()),
|
||||
modulePath, this));
|
||||
errors
|
||||
.add(ModuleLoadingErrorDescription.create(ProjectBundle.message("module.cannot.load.error", modulePath.getPath(), e.getMessage()),
|
||||
modulePath, this));
|
||||
}
|
||||
catch (ModuleWithNameAlreadyExists moduleWithNameAlreadyExists) {
|
||||
errors.add(ModuleLoadingErrorDescription.create(moduleWithNameAlreadyExists.getMessage(), modulePath, this));
|
||||
@@ -285,12 +285,14 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project
|
||||
onModuleLoadErrors(errors);
|
||||
|
||||
showUnknownModuleTypeNotification(modulesWithUnknownTypes);
|
||||
|
||||
if (progressIndicator != null) {
|
||||
progressIndicator.setIndeterminate(true);
|
||||
}
|
||||
}
|
||||
|
||||
public int getModulePathsCount() { return myModulePaths == null ? 0 : myModulePaths.size(); }
|
||||
|
||||
private double myProgressStep;
|
||||
|
||||
public void setProgressStep(double step) { myProgressStep = step; }
|
||||
|
||||
protected boolean isUnknownModuleType(@NotNull Module module) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user