Skip to content

Commit

Permalink
Sync With AppKit
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoolwinter committed Nov 8, 2024
1 parent 44f1cd1 commit 5eb0973
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ final class CodeEditDocumentController: NSDocumentController {
}
}

override func clearRecentDocuments(_ sender: Any?) {
super.clearRecentDocuments(sender)
UserDefaults.standard.set([Any](), forKey: "recentProjectPaths")
}

override func addDocument(_ document: NSDocument) {
super.addDocument(document)
if let document = document as? CodeFileDocument {
Expand Down
10 changes: 10 additions & 0 deletions CodeEdit/Features/Welcome/Model/RecentProjectsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum RecentProjectsStore {

// Limit list to to 100 items after de-duplication
UserDefaults.standard.setValue(Array(paths.prefix(100)), forKey: defaultsKey)
setDocumentControllerRecents()
donateSearchableItems()
NotificationCenter.default.post(name: Self.didUpdateNotification, object: nil)
}
Expand Down Expand Up @@ -72,6 +73,15 @@ enum RecentProjectsStore {
setPaths([])
}

/// Syncs AppKit's recent documents list with ours, keeping the dock menu and other lists up-to-date.
private static func setDocumentControllerRecents() {
CodeEditDocumentController.shared.clearRecentDocuments(nil)
for path in recentProjectURLs().prefix(10) {
CodeEditDocumentController.shared.noteNewRecentDocumentURL(path)
}
}

Check failure on line 83 in CodeEdit/Features/Welcome/Model/RecentProjectsStore.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Lines should not have trailing whitespace (trailing_whitespace)
/// Donates all recent URLs to Core Search, making them searchable in Spotlight
private static func donateSearchableItems() {
let searchableItems = recentProjectURLs().map { entity in
let attributeSet = CSSearchableItemAttributeSet(contentType: .content)
Expand Down

0 comments on commit 5eb0973

Please sign in to comment.