Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable reordering when sort by name is enabled #3552

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ final class BookmarkOutlineViewDataSource: NSObject, BookmarksOutlineViewDataSou
private var outlineView: BookmarksOutlineView?

private let contentMode: ContentMode
private var sortMode: BookmarksSortMode
private(set) var expandedNodesIDs = Set<String>()
@Published private(set) var isSearching = false

Expand Down Expand Up @@ -95,18 +96,21 @@ final class BookmarkOutlineViewDataSource: NSObject, BookmarksOutlineViewDataSou
self.dragDropManager = dragDropManager
self.treeController = treeController
self.presentFaviconsFetcherOnboarding = presentFaviconsFetcherOnboarding
self.sortMode = sortMode

super.init()
}

func reloadData(with sortMode: BookmarksSortMode, withRootFolder rootFolder: BookmarkFolder? = nil) {
isSearching = false
dragDestinationFolder = nil
self.sortMode = sortMode
treeController.rebuild(for: sortMode, withRootFolder: rootFolder)
}

func reloadData(forSearchQuery searchQuery: String, sortMode: BookmarksSortMode) {
isSearching = true
self.sortMode = sortMode
treeController.rebuild(forSearchQuery: searchQuery, sortMode: sortMode)
}

Expand Down Expand Up @@ -260,6 +264,8 @@ final class BookmarkOutlineViewDataSource: NSObject, BookmarksOutlineViewDataSou
}

func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation {
if !sortMode.isReorderingEnabled { return .none }

let destinationNode = nodeForItem(item)

if contentMode == .foldersOnly, destinationNode.isRoot {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ extension BookmarkManagementDetailViewController: NSTableViewDelegate, NSTableVi
validateDrop info: NSDraggingInfo,
proposedRow row: Int,
proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation {
if !sortBookmarksViewModel.selectedSortMode.isReorderingEnabled { return .none }
let destination = destination(for: dropOperation, at: row)

guard !isSearching || destination is BookmarkFolder else { return .none }
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/Bookmarks/ViewModel/SortBookmarksViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ enum BookmarksSortMode: Codable {
return self == .nameAscending || self == .nameDescending
}

var isReorderingEnabled: Bool{
return self == .manual
}

func menu(target: AnyObject) -> NSMenu {
switch self {
case .manual:
Expand Down
6 changes: 6 additions & 0 deletions UnitTests/Bookmarks/ViewModels/BookmarksSortModeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,10 @@ class BookmarksSortModeTests: XCTestCase {
XCTAssertEqual(descendingMenu.items[4].title, UserText.bookmarksSortByNameDescending)
XCTAssertEqual(descendingMenu.items[4].state, .on)
}

func testReorderingValueIsCorrect() {
XCTAssertTrue(BookmarksSortMode.manual.isReorderingEnabled)
XCTAssertFalse(BookmarksSortMode.nameAscending.isReorderingEnabled)
XCTAssertFalse(BookmarksSortMode.nameDescending.isReorderingEnabled)
}
}
Loading