mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix dispose for libraries in project structure + directory-based storage fix: set correct requestor for file deletion
This commit is contained in:
+7
-2
@@ -15,12 +15,14 @@
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
public class LibraryEditor {
|
||||
public class LibraryEditor implements Disposable {
|
||||
private final Library myLibrary;
|
||||
private String myLibraryName = null;
|
||||
private Library.ModifiableModel myModel = null;
|
||||
@@ -36,6 +38,9 @@ public class LibraryEditor {
|
||||
return myLibrary.getName();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
public String[] getUrls(OrderRootType rootType) {
|
||||
if (myModel != null) {
|
||||
return myModel.getUrls(rootType);
|
||||
@@ -83,10 +88,10 @@ public class LibraryEditor {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Library.ModifiableModel getModel() {
|
||||
if (myModel == null) {
|
||||
myModel = myLibrary.getModifiableModel();
|
||||
Disposer.register(this, myModel);
|
||||
}
|
||||
return myModel;
|
||||
}
|
||||
|
||||
+3
@@ -160,6 +160,9 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
for (final LibrariesModifiableModel provider : myContext.myLevel2Providers.values()) {
|
||||
provider.disposeUncommittedLibraries();
|
||||
}
|
||||
}
|
||||
|
||||
protected AnAction createCopyAction() {
|
||||
|
||||
+2
@@ -209,6 +209,8 @@ public abstract class BaseStructureConfigurable extends MasterDetailsComponent i
|
||||
|
||||
myAutoScrollHandler.cancelAllRequests();
|
||||
|
||||
myContext.getDaemonAnalyzer().clear();
|
||||
|
||||
Disposer.dispose(this);
|
||||
}
|
||||
|
||||
|
||||
+26
-7
@@ -22,6 +22,7 @@ import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
@@ -55,9 +56,15 @@ public class LibrariesModifiableModel implements LibraryTable.ModifiableModel {
|
||||
public void removeLibrary(@NotNull Library library) {
|
||||
if (getLibrariesModifiableModel().getLibraryByName(library.getName()) == null) return;
|
||||
|
||||
myRemovedLibraries.add(library);
|
||||
removeLibraryEditor(library);
|
||||
final Library existingLibrary = myTable.getLibraryByName(library.getName());
|
||||
getLibrariesModifiableModel().removeLibrary(library);
|
||||
if (existingLibrary == library) {
|
||||
myRemovedLibraries.add(library);
|
||||
} else {
|
||||
// dispose uncommitted library
|
||||
Disposer.dispose(library);
|
||||
}
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
@@ -88,6 +95,7 @@ public class LibrariesModifiableModel implements LibraryTable.ModifiableModel {
|
||||
public void deferredCommit(){
|
||||
for (LibraryEditor libraryEditor : new ArrayList<LibraryEditor>(myLibrary2EditorMap.values())) {
|
||||
libraryEditor.commit(); // TODO: is seems like commit will recreate the editor, but it should not
|
||||
Disposer.dispose(libraryEditor);
|
||||
}
|
||||
if (!(myLibrary2EditorMap.isEmpty() && myRemovedLibraries.isEmpty())) {
|
||||
getLibrariesModifiableModel().commit();
|
||||
@@ -126,12 +134,7 @@ public class LibrariesModifiableModel implements LibraryTable.ModifiableModel {
|
||||
private void removeLibraryEditor(final Library library) {
|
||||
final LibraryEditor libraryEditor = myLibrary2EditorMap.remove(library);
|
||||
if (libraryEditor != null) {
|
||||
for (Iterator it = myLibrary2EditorMap.keySet().iterator(); it.hasNext();) {
|
||||
final Library lib = (Library)it.next();
|
||||
if (libraryEditor == myLibrary2EditorMap.get(lib)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
Disposer.dispose(libraryEditor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,4 +149,20 @@ public class LibrariesModifiableModel implements LibraryTable.ModifiableModel {
|
||||
|
||||
return myLibrariesModifiableModel;
|
||||
}
|
||||
|
||||
public void disposeUncommittedLibraries() {
|
||||
for (final Library library : new ArrayList<Library>(myLibrary2EditorMap.keySet())) {
|
||||
final Library existingLibrary = myTable.getLibraryByName(library.getName());
|
||||
if (existingLibrary != library) {
|
||||
Disposer.dispose(library);
|
||||
}
|
||||
|
||||
final LibraryEditor libraryEditor = myLibrary2EditorMap.get(library);
|
||||
if (libraryEditor != null) {
|
||||
Disposer.dispose(libraryEditor);
|
||||
}
|
||||
}
|
||||
|
||||
myLibrary2EditorMap.clear();
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -166,9 +166,6 @@ public class ProjectStructureDaemonAnalyzer implements Disposable {
|
||||
public void clearCaches() {
|
||||
LOG.debug("clear caches");
|
||||
myProblemHolders.clear();
|
||||
mySourceElement2Usages.clear();
|
||||
myContainingElement2Usages.clear();
|
||||
myElementWithNotCalculatedUsages.clear();
|
||||
}
|
||||
|
||||
public void clearAllProblems() {
|
||||
@@ -210,6 +207,12 @@ public class ProjectStructureDaemonAnalyzer implements Disposable {
|
||||
});
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
mySourceElement2Usages.clear();
|
||||
myContainingElement2Usages.clear();
|
||||
myElementWithNotCalculatedUsages.clear();
|
||||
}
|
||||
|
||||
private class AnalyzeElementUpdate extends Update {
|
||||
private final ProjectStructureElement myElement;
|
||||
private final boolean myCheck;
|
||||
|
||||
Reference in New Issue
Block a user