From 4d9b92464888750e20c57740d5dd06fb79cd9f99 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Fri, 17 Jan 2020 22:52:37 +0100 Subject: [PATCH] Refactor slightly --- VimR/VimR/OpenQuicklyWindow.swift | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/VimR/VimR/OpenQuicklyWindow.swift b/VimR/VimR/OpenQuicklyWindow.swift index 7f2e7909..b59d48e1 100644 --- a/VimR/VimR/OpenQuicklyWindow.swift +++ b/VimR/VimR/OpenQuicklyWindow.swift @@ -23,6 +23,8 @@ class OpenQuicklyWindow: NSObject, case close } + @objc dynamic var fileItems = [ScoredUrl]() + required init(source: Observable, emitter: ActionEmitter, state: StateType) { self.emit = emitter.typedEmit() self.windowController = NSWindowController(windowNibName: NSNib.Name("OpenQuicklyWindow")) @@ -85,9 +87,6 @@ class OpenQuicklyWindow: NSObject, private var fileServicesPerRootUrl: [URL: FileService] = [:] private var rootUrls: Set { Set(self.fileServicesPerRootUrl.map { url, _ in url }) } - // FIXME: migrate to State later... - @objc dynamic private(set) var fileViewItems = [ScoredUrl]() - private var count = 0 private let fileViewItemsController = NSArrayController() private let windowController: NSWindowController @@ -110,19 +109,19 @@ class OpenQuicklyWindow: NSObject, fileService.stopScanScore() guard pattern.count >= 2 else { - self.fileViewItems.removeAll() + self.fileItems.removeAll() return } self.scanToken = Token() let localToken = self.scanToken - self.fileViewItems.removeAll() + self.fileItems.removeAll() fileService.scanScore(for: pattern) { scoredUrls in DispatchQueue.main.async { guard localToken == self.scanToken else { return } - self.fileViewItems.append(contentsOf: scoredUrls) - self.countField.stringValue = "\(self.fileViewItems.count) Items" + self.fileItems.append(contentsOf: scoredUrls) + self.countField.stringValue = "\(self.fileItems.count) Items" } } } @@ -168,7 +167,7 @@ class OpenQuicklyWindow: NSObject, c.objectClass = ScoredUrl.self c.sortDescriptors = [NSSortDescriptor(key: "score", ascending: false)] c.automaticallyRearrangesObjects = true - c.bind(.contentArray, to: self, withKeyPath: "fileViewItems") + c.bind(.contentArray, to: self, withKeyPath: "fileItems") fileView.bind(.content, to: c, withKeyPath: "arrangedObjects") fileView.bind(.selectionIndexes, to: c, withKeyPath: "selectionIndexes") @@ -241,7 +240,7 @@ extension OpenQuicklyWindow { )?.reset() let cell = cachedCell ?? ImageAndTextTableCell(withIdentifier: "file-view-row") - let url = self.fileViewItems[row].url + let url = self.fileItems[row].url cell.attributedText = self.rowText(for: url as URL) cell.image = FileUtils.icon(forUrl: url) @@ -284,7 +283,7 @@ extension OpenQuicklyWindow { case NSSelectorFromString("insertNewline:"): // TODO open the url - self.emit(.open(self.fileViewItems[self.fileView.selectedRow].url)) + self.emit(.open(self.fileItems[self.fileView.selectedRow].url)) self.window.performClose(self) return true @@ -331,9 +330,7 @@ extension OpenQuicklyWindow { func windowWillClose(_: Notification) { self.endProgress() - self.count = 0 - - self.fileViewItems.removeAll() + self.fileItems.removeAll() self.searchField.stringValue = "" self.countField.stringValue = "0 items"