mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not leak projects, dispose stuff
This commit is contained in:
@@ -7,6 +7,7 @@ import com.intellij.lang.Language;
|
||||
import com.intellij.lang.LanguageUtil;
|
||||
import com.intellij.lang.PerFileMappings;
|
||||
import com.intellij.lang.PerFileMappingsBase;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
@@ -26,6 +27,7 @@ import com.intellij.openapi.fileTypes.*;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -61,7 +63,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
@State(name = "ScratchFileService", storages = @Storage(value = "scratches.xml", roamingType = RoamingType.DISABLED))
|
||||
public class ScratchFileServiceImpl extends ScratchFileService implements PersistentStateComponent<Element>{
|
||||
public class ScratchFileServiceImpl extends ScratchFileService implements PersistentStateComponent<Element>, Disposable {
|
||||
|
||||
private static final RootType NULL_TYPE = new RootType("", null) {};
|
||||
|
||||
@@ -69,6 +71,7 @@ public class ScratchFileServiceImpl extends ScratchFileService implements Persis
|
||||
private final MyLanguages myScratchMapping = new MyLanguages();
|
||||
|
||||
protected ScratchFileServiceImpl(Application application) {
|
||||
Disposer.register(this, myScratchMapping);
|
||||
myIndex = new LightDirectoryIndex<>(application, NULL_TYPE, index -> {
|
||||
LocalFileSystem fileSystem = LocalFileSystem.getInstance();
|
||||
for (RootType r : RootType.getAllRootIds()) {
|
||||
@@ -155,6 +158,10 @@ public class ScratchFileServiceImpl extends ScratchFileService implements Persis
|
||||
myScratchMapping.loadState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
private static class MyLanguages extends PerFileMappingsBase<Language> {
|
||||
@Override
|
||||
public List<Language> getAvailableValues() {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package com.intellij.lang;
|
||||
|
||||
import com.intellij.injected.editor.VirtualFileWindow;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
@@ -40,7 +41,7 @@ import java.util.*;
|
||||
/**
|
||||
* @author gregsh
|
||||
*/
|
||||
public abstract class PerFileMappingsBase<T> implements PersistentStateComponent<Element>, PerFileMappings<T> {
|
||||
public abstract class PerFileMappingsBase<T> implements PersistentStateComponent<Element>, PerFileMappings<T>, Disposable {
|
||||
|
||||
private final TreeMap<VirtualFile, T> myMappings = new TreeMap<>(
|
||||
(f1, f2) -> Comparing.compare(f1 == null ? null : f1.getUrl(), f2 == null ? null : f2.getUrl()));
|
||||
@@ -49,6 +50,10 @@ public abstract class PerFileMappingsBase<T> implements PersistentStateComponent
|
||||
installDeleteUndo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected FilePropertyPusher<T> getFilePropertyPusher() {
|
||||
return null;
|
||||
@@ -281,8 +286,7 @@ public abstract class PerFileMappingsBase<T> implements PersistentStateComponent
|
||||
private void installDeleteUndo() {
|
||||
Application app = ApplicationManager.getApplication();
|
||||
if (app == null) return;
|
||||
|
||||
app.getMessageBus().connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
|
||||
app.getMessageBus().connect(this).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
|
||||
|
||||
WeakReference<MyUndoableAction> lastAction;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user