Invalid elements are now removed from the CopyPasteManager on project closing

This commit is contained in:
Alexandr Evstigneev
2018-10-04 11:49:48 +03:00
parent ec545d9be3
commit ba78eae0aa
@@ -50,15 +50,18 @@ public class PsiCopyPasteManager {
ApplicationManager.getApplication().getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
@Override
public void projectClosing(@NotNull Project project) {
if (myRecentData != null && myRecentData.getProject() == project) {
if (myRecentData != null && (myRecentData.isValid() || myRecentData.getProject() == project)) {
myRecentData = null;
}
Transferable[] contents = myCopyPasteManager.getAllContents();
for (int i = contents.length - 1; i >= 0; i--) {
Transferable t = contents[i];
if (t instanceof MyTransferable && ((MyTransferable)t).myDataProxy.getProject() == project) {
myCopyPasteManager.removeContent(t);
if (t instanceof MyTransferable) {
MyData myData = ((MyTransferable)t).myDataProxy;
if (!myData.isValid() || myData.getProject() == project) {
myCopyPasteManager.removeContent(t);
}
}
}
}
@@ -183,6 +186,10 @@ public class PsiCopyPasteManager {
return myIsCopied;
}
public boolean isValid() {
return myElements.length > 0 && myElements[0].isValid();
}
@Nullable
public Project getProject() {
if (myElements == null || myElements.length == 0) {