From 29e002f8f1721caf3c6c51890b9fc33e3dd43b82 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sat, 12 Jun 2021 09:30:16 +0100 Subject: [PATCH] get rid of manual library refresh, switch to LinkedHashSet for all files, properly clean up intermediate nodes in the filtered tree --- .../com/muwire/gui/MainFrameController.groovy | 1 - .../com/muwire/gui/MainFrameModel.groovy | 20 +++++++++---------- .../com/muwire/gui/RefreshLibraryEvent.groovy | 6 ------ 3 files changed, 10 insertions(+), 17 deletions(-) delete mode 100644 gui/src/main/groovy/com/muwire/gui/RefreshLibraryEvent.groovy diff --git a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy index e48e710e..772c4795 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy @@ -478,7 +478,6 @@ class MainFrameController { core.eventBus.publish(new FileUnsharedEvent(unsharedFile : sf)) } - core.eventBus.publish(new RefreshLibraryEvent()) } @ControllerAction diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index 31d1ea97..1ad67329 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -104,7 +104,7 @@ class MainFrameModel { volatile String filter volatile Filterer filterer boolean treeVisible = true - private final List allSharedFiles = Collections.synchronizedList(new ArrayList<>()) + private final Set allSharedFiles = Collections.synchronizedSet(new LinkedHashSet<>()) def shared TreeModel sharedTree DefaultMutableTreeNode allFilesTreeRoot, treeRoot @@ -299,7 +299,6 @@ class MainFrameModel { core.eventBus.register(UIMessageReadEvent.class, this) core.eventBus.register(MessageSentEvent.class, this) core.eventBus.register(MessageFolderLoadingEvent.class, this) - core.eventBus.register(RefreshLibraryEvent.class, this) core.muOptions.watchedKeywords.each { @@ -563,7 +562,14 @@ class MainFrameModel { throw new IllegalStateException() otherNode = next } - otherNode.removeFromParent() + while(true) { + def parent = otherNode.getParent() + otherNode.removeFromParent() + if (parent.getChildCount() == 0) { + otherNode = parent + } else + break + } } List unshared = new ArrayList<>() @@ -585,16 +591,10 @@ class MainFrameModel { File unsharedRoot = unshared.get( unshared.size() -1 ) core.eventBus.publish(new DirectoryUnsharedEvent(directory : unsharedRoot)) } - } + } } } - void onRefreshLibraryEvent(RefreshLibraryEvent e) { - runInsideUIAsync { - view.refreshSharedFiles() - } - } - void onUploadEvent(UploadEvent e) { runInsideUIAsync { UploaderWrapper wrapper = null diff --git a/gui/src/main/groovy/com/muwire/gui/RefreshLibraryEvent.groovy b/gui/src/main/groovy/com/muwire/gui/RefreshLibraryEvent.groovy deleted file mode 100644 index 39ce48e6..00000000 --- a/gui/src/main/groovy/com/muwire/gui/RefreshLibraryEvent.groovy +++ /dev/null @@ -1,6 +0,0 @@ -package com.muwire.gui - -import com.muwire.core.Event - -class RefreshLibraryEvent extends Event { -}