mirror of https://github.com/zlatinb/muwire
more efficient mass unsharing
parent
d7423e7e08
commit
300404915d
|
@ -540,60 +540,58 @@ class MainFrameModel {
|
||||||
runInsideUIAsync {
|
runInsideUIAsync {
|
||||||
synchronized (allSharedFiles) {
|
synchronized (allSharedFiles) {
|
||||||
allSharedFiles.removeAll(e.unsharedFiles)
|
allSharedFiles.removeAll(e.unsharedFiles)
|
||||||
|
shared.retainAll(allSharedFiles)
|
||||||
}
|
}
|
||||||
loadedFiles = allSharedFiles.size()
|
loadedFiles = allSharedFiles.size()
|
||||||
|
|
||||||
for (SharedFile sharedFile : e.unsharedFiles) {
|
for (SharedFile sharedFile : e.unsharedFiles) {
|
||||||
boolean wasVisible = shared.remove(sharedFile)
|
|
||||||
|
|
||||||
DefaultMutableTreeNode dmtn = fileToNode.remove(sharedFile)
|
DefaultMutableTreeNode dmtn = fileToNode.remove(sharedFile)
|
||||||
if (dmtn != null) {
|
if (dmtn == null)
|
||||||
|
continue
|
||||||
|
|
||||||
if (wasVisible) {
|
Object[] path = dmtn.getUserObjectPath()
|
||||||
Object[] path = dmtn.getUserObjectPath()
|
DefaultMutableTreeNode otherNode = treeRoot
|
||||||
DefaultMutableTreeNode otherNode = treeRoot
|
for (int i = 1; i < path.length; i++) {
|
||||||
for (int i = 1; i < path.length; i++) {
|
Object o = path[i]
|
||||||
Object o = path[i]
|
DefaultMutableTreeNode next = null
|
||||||
DefaultMutableTreeNode next = null
|
for (int j = 0; j < otherNode.childCount; j++) {
|
||||||
for (int j = 0; j < otherNode.childCount; j++) {
|
if (otherNode.getChildAt(j).getUserObject() == o) {
|
||||||
if (otherNode.getChildAt(j).getUserObject() == o) {
|
next = otherNode.getChildAt(j)
|
||||||
next = otherNode.getChildAt(j)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (next == null)
|
|
||||||
throw new IllegalStateException()
|
|
||||||
otherNode = next
|
|
||||||
}
|
|
||||||
while (true) {
|
|
||||||
def parent = otherNode.getParent()
|
|
||||||
otherNode.removeFromParent()
|
|
||||||
if (parent.getChildCount() == 0) {
|
|
||||||
otherNode = parent
|
|
||||||
} else
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<File> unshared = new ArrayList<>()
|
|
||||||
while (true) {
|
|
||||||
def parent = dmtn.getParent()
|
|
||||||
parent.remove(dmtn)
|
|
||||||
if (parent == allFilesTreeRoot)
|
|
||||||
break
|
break
|
||||||
if (parent.getChildCount() == 0) {
|
|
||||||
File file = parent.getUserObject().file
|
|
||||||
if (core.watchedDirectoryManager.isWatched(file))
|
|
||||||
unshared.add(file)
|
|
||||||
dmtn = parent
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (next == null)
|
||||||
|
throw new IllegalStateException()
|
||||||
|
otherNode = next
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
def parent = otherNode.getParent()
|
||||||
|
otherNode.removeFromParent()
|
||||||
|
if (parent.getChildCount() == 0) {
|
||||||
|
otherNode = parent
|
||||||
|
} else
|
||||||
break
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
List<File> unshared = new ArrayList<>()
|
||||||
|
while (true) {
|
||||||
|
def parent = dmtn.getParent()
|
||||||
|
parent.remove(dmtn)
|
||||||
|
if (parent == allFilesTreeRoot)
|
||||||
|
break
|
||||||
|
if (parent.getChildCount() == 0) {
|
||||||
|
File file = parent.getUserObject().file
|
||||||
|
if (core.watchedDirectoryManager.isWatched(file))
|
||||||
|
unshared.add(file)
|
||||||
|
dmtn = parent
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if (!unshared.isEmpty()) {
|
break
|
||||||
File unsharedRoot = unshared.get(unshared.size() - 1)
|
}
|
||||||
core.eventBus.publish(new DirectoryUnsharedEvent(directory: unsharedRoot))
|
if (!unshared.isEmpty()) {
|
||||||
}
|
File unsharedRoot = unshared.get(unshared.size() - 1)
|
||||||
|
core.eventBus.publish(new DirectoryUnsharedEvent(directory: unsharedRoot))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue