mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
reduce usages of addProjectManagerListener(project)
This commit is contained in:
+10
-14
@@ -20,10 +20,9 @@
|
||||
package com.intellij.util.indexing;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.startup.StartupManagerEx;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.TransactionGuard;
|
||||
import com.intellij.openapi.components.AbstractProjectComponent;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.project.*;
|
||||
@@ -38,22 +37,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class FileBasedIndexProjectHandler extends AbstractProjectComponent implements IndexableFileSet {
|
||||
public class FileBasedIndexProjectHandler implements IndexableFileSet, Disposable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.util.indexing.FileBasedIndexProjectHandler");
|
||||
|
||||
private final FileBasedIndex myIndex;
|
||||
private FileBasedIndexScanRunnableCollector myCollector;
|
||||
|
||||
public FileBasedIndexProjectHandler(FileBasedIndex index,
|
||||
Project project,
|
||||
FileBasedIndexScanRunnableCollector collector,
|
||||
ProjectManager projectManager) {
|
||||
super(project);
|
||||
public FileBasedIndexProjectHandler(@NotNull Project project, FileBasedIndex index, FileBasedIndexScanRunnableCollector collector) {
|
||||
myIndex = index;
|
||||
myCollector = collector;
|
||||
|
||||
if (ApplicationManager.getApplication().isInternal()) {
|
||||
project.getMessageBus().connect().subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {
|
||||
project.getMessageBus().connect(this).subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {
|
||||
@Override
|
||||
public void enteredDumbMode() { }
|
||||
|
||||
@@ -64,7 +59,7 @@ public class FileBasedIndexProjectHandler extends AbstractProjectComponent imple
|
||||
});
|
||||
}
|
||||
|
||||
final StartupManagerEx startupManager = (StartupManagerEx)StartupManager.getInstance(project);
|
||||
StartupManager startupManager = StartupManager.getInstance(project);
|
||||
if (startupManager != null) {
|
||||
startupManager.registerPreStartupActivity(() -> {
|
||||
PushedFilePropertiesUpdater.getInstance(project).initializeProperties();
|
||||
@@ -77,11 +72,12 @@ public class FileBasedIndexProjectHandler extends AbstractProjectComponent imple
|
||||
});
|
||||
|
||||
myIndex.registerIndexableSet(this, project);
|
||||
projectManager.addProjectManagerListener(project, new ProjectManagerListener() {
|
||||
project.getMessageBus().connect(this).subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
|
||||
private boolean removed;
|
||||
|
||||
@Override
|
||||
public void projectClosing(Project project1) {
|
||||
if (!removed) {
|
||||
public void projectClosing(Project eventProject) {
|
||||
if (eventProject == project && !removed) {
|
||||
removed = true;
|
||||
myIndex.removeIndexableSet(FileBasedIndexProjectHandler.this);
|
||||
}
|
||||
@@ -111,7 +107,7 @@ public class FileBasedIndexProjectHandler extends AbstractProjectComponent imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeComponent() {
|
||||
public void dispose() {
|
||||
// done mostly for tests. In real life this is no-op, because the set was removed on project closing
|
||||
myIndex.removeIndexableSet(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user