From 4030681ca65090e4427378f772de2d728e45c3cd Mon Sep 17 00:00:00 2001 From: David Kocher Date: Wed, 6 Nov 2024 15:59:55 +0100 Subject: [PATCH 1/2] Fix #12897. Make sure to ignore file system events from monitored collection while reordering collection. --- .../main/java/ch/cyberduck/core/Collection.java | 8 ++++++++ .../cocoa/datasource/BookmarkTableDataSource.java | 15 ++++----------- .../cyberduck/ui/controller/BrowserController.cs | 10 +--------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/ch/cyberduck/core/Collection.java b/core/src/main/java/ch/cyberduck/core/Collection.java index 304e46fae96..aa1f6506d1d 100644 --- a/core/src/main/java/ch/cyberduck/core/Collection.java +++ b/core/src/main/java/ch/cyberduck/core/Collection.java @@ -136,6 +136,14 @@ public void replace(int row, E item) { } } + public void move(int from, int to) { + final E item = super.remove(from); + this.add(to, item); + for(CollectionListener listener : listeners) { + listener.collectionItemChanged(item); + } + } + @Override public void clear() { for(Iterator iter = this.iterator(); iter.hasNext(); ) { diff --git a/osx/src/main/java/ch/cyberduck/ui/cocoa/datasource/BookmarkTableDataSource.java b/osx/src/main/java/ch/cyberduck/ui/cocoa/datasource/BookmarkTableDataSource.java index 924b5061c8e..1a6d66b54cd 100644 --- a/osx/src/main/java/ch/cyberduck/ui/cocoa/datasource/BookmarkTableDataSource.java +++ b/osx/src/main/java/ch/cyberduck/ui/cocoa/datasource/BookmarkTableDataSource.java @@ -424,20 +424,13 @@ else if(!pasteboard.isEmpty()) { else { int insert = row.intValue(); for(Host bookmark : pasteboard) { - int previous = source.indexOf(bookmark); - if(previous == insert) { + int sourceIndex = source.indexOf(bookmark); + if(sourceIndex == insert) { // No need to move continue; } - source.remove(previous); - int moved; - if(previous < insert) { - moved = insert - 1; - } - else { - moved = insert; - } - source.add(moved, bookmark); + int destIndex = sourceIndex < insert ? insert - 1 : insert; + source.move(sourceIndex, destIndex); } for(Host bookmark : pasteboard) { int index = source.indexOf(bookmark); diff --git a/windows/src/main/csharp/ch/cyberduck/ui/controller/BrowserController.cs b/windows/src/main/csharp/ch/cyberduck/ui/controller/BrowserController.cs index 4094fafe321..de5d98b3fd3 100644 --- a/windows/src/main/csharp/ch/cyberduck/ui/controller/BrowserController.cs +++ b/windows/src/main/csharp/ch/cyberduck/ui/controller/BrowserController.cs @@ -751,15 +751,7 @@ private void View_HostModelDropped(ModelDropEventArgs dropargs) } foreach (Host promisedDragBookmark in dropargs.SourceModels) { - _bookmarkModel.Source.remove(promisedDragBookmark); - if (destIndex > _bookmarkModel.Source.size()) - { - _bookmarkModel.Source.add(promisedDragBookmark); - } - else - { - _bookmarkModel.Source.add(destIndex, promisedDragBookmark); - } + _bookmarkModel.Source.move(sourceIndex, destIndex); //view.selectRowIndexes(NSIndexSet.indexSetWithIndex(row), false); //view.scrollRowToVisible(row); } From 94cccca8b16c26f8a96d2a4efc77f5e74f28ad1e Mon Sep 17 00:00:00 2001 From: David Kocher Date: Wed, 6 Nov 2024 16:12:28 +0100 Subject: [PATCH 2/2] Override base method. --- core/src/main/java/ch/cyberduck/core/Collection.java | 5 +++-- .../java/ch/cyberduck/core/MonitorFolderHostCollection.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/ch/cyberduck/core/Collection.java b/core/src/main/java/ch/cyberduck/core/Collection.java index aa1f6506d1d..caa800501ad 100644 --- a/core/src/main/java/ch/cyberduck/core/Collection.java +++ b/core/src/main/java/ch/cyberduck/core/Collection.java @@ -129,11 +129,12 @@ public void add(int row, E item) { this.collectionItemAdded(item); } - public void replace(int row, E item) { - this.set(row, item); + public E set(int row, E item) { + final E previous = super.set(row, item); for(CollectionListener listener : listeners) { listener.collectionItemChanged(item); } + return previous; } public void move(int from, int to) { diff --git a/core/src/main/java/ch/cyberduck/core/MonitorFolderHostCollection.java b/core/src/main/java/ch/cyberduck/core/MonitorFolderHostCollection.java index 238bb40b61d..4812aad587d 100644 --- a/core/src/main/java/ch/cyberduck/core/MonitorFolderHostCollection.java +++ b/core/src/main/java/ch/cyberduck/core/MonitorFolderHostCollection.java @@ -68,7 +68,7 @@ public void fileWritten(final Local file) { // Found bookmark with matching UUID if(new HostEditComparator().compare(bookmark, this.get(index)) != 0) { log.debug("Replace bookmark {} at index {}", bookmark, index); - this.replace(index, bookmark); + this.set(index, bookmark); } } }