Skip to content

Commit

Permalink
Disable reordering when sort by name is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaemepereira committed Nov 14, 2024
1 parent ce3975e commit ff64721
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
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)
}
}

0 comments on commit ff64721

Please sign in to comment.