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