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
Menu 2.0 #1058
Menu 2.0 #1058
Changes from 1 commit
57860c2
d2a4044
0e2a935
799f2c7
1f25420
2cb5750
191f371
7926cfe
17afd7d
bbdaa80
7d19867
ea4f0d8
c3a737a
ee76b6a
f06a617
02dab4c
c0d29cd
736fc5e
5138870
ada5f14
134d4a9
d68cad8
c022eb5
7e30962
f781004
1d5d612
e6c7a1c
93c9a24
880de9e
40f11b9
99b171f
0bf5ddc
c57f709
1d9e0c3
de90bd1
32e1e30
bc45a12
f7fd274
839602c
8ad53f3
21d08ed
76ab847
File filter...
Jump to…
Edit bookmark location mvp
- Loading branch information
| @@ -152,6 +152,17 @@ public final class Bookmark: NSManagedObject, WebsitePresentable, Syncable, CRUD | ||
| updateInternal(customTitle: customTitle, url: url) | ||
| } | ||
|
|
||
| enum SaveLocation { | ||
| case keep | ||
| case new(location: Bookmark?) | ||
| } | ||
|
|
||
| public func updateWithNewLocation(customTitle: String?, url: String?, location: Bookmark?) { | ||
jhreis
Contributor
|
||
| let isTitleEmpty = customTitle?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == true | ||
jhreis
Contributor
|
||
| if customTitle == nil || isTitleEmpty { return } | ||
| updateInternal(customTitle: customTitle, url: url, location: .new(location: location)) | ||
| } | ||
|
|
||
| public class func migrateBookmarkOrders() { | ||
| DataController.perform { context in | ||
| migrateOrder(forFavorites: true, context: context) | ||
| @@ -331,6 +342,7 @@ extension Bookmark { | ||
|
|
||
| private func updateInternal(customTitle: String?, url: String?, newSyncOrder: String? = nil, | ||
| save: Bool = true, sendToSync: Bool = true, | ||
| location: SaveLocation = .keep, | ||
| context: WriteContext = .new) { | ||
|
|
||
| DataController.perform(context: context) { context in | ||
| @@ -353,14 +365,27 @@ extension Bookmark { | ||
| } | ||
| } | ||
|
|
||
| // Checking if syncOrder has changed is imporant here for performance reasons. | ||
| // Currently to do bookmark sorting right, we have to grab all bookmarks in a given directory | ||
| // and update their order which is a costly operation. | ||
| if newSyncOrder != nil && bookmarkToUpdate.syncOrder != newSyncOrder { | ||
| bookmarkToUpdate.syncOrder = newSyncOrder | ||
| Bookmark.setOrderForAllBookmarksOnGivenLevel(parent: bookmarkToUpdate.parentFolder, forFavorites: bookmarkToUpdate.isFavorite, context: context) | ||
| switch location { | ||
| case .keep: | ||
| // Checking if syncOrder has changed is imporant here for performance reasons. | ||
| // Currently to do bookmark sorting right, we have to grab all bookmarks in a given directory | ||
| // and update their order which is a costly operation. | ||
| if newSyncOrder != nil && bookmarkToUpdate.syncOrder != newSyncOrder { | ||
| bookmarkToUpdate.syncOrder = newSyncOrder | ||
| Bookmark.setOrderForAllBookmarksOnGivenLevel(parent: bookmarkToUpdate.parentFolder, forFavorites: bookmarkToUpdate.isFavorite, context: context) | ||
| } | ||
| case .new(let newParent): | ||
| var parentOnCorrectContext: Bookmark? | ||
| if let newParent = newParent { | ||
| parentOnCorrectContext = context.object(with: newParent.objectID) as? Bookmark | ||
| } | ||
| bookmarkToUpdate.parentFolder = parentOnCorrectContext | ||
| bookmarkToUpdate.newSyncOrder(forFavorites: bookmarkToUpdate.isFavorite, context: context) | ||
| Bookmark.setOrderForAllBookmarksOnGivenLevel(parent: bookmarkToUpdate.parentFolder, | ||
| forFavorites: bookmarkToUpdate.isFavorite, | ||
| context: context) | ||
| } | ||
|
|
||
| if !bookmarkToUpdate.isFavorite && sendToSync { | ||
| Sync.shared.sendSyncRecords(action: .update, records: [bookmarkToUpdate], context: context) | ||
| } | ||
Maybe just call
dismissView()?