From 207afdb84d51cf06039aa35f2d85c681d2d40e06 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sat, 18 Jan 2020 14:03:35 +0100 Subject: [PATCH] Reactor slightly --- VimR/VimR/FileService.swift | 24 ++++++++++++------------ VimR/VimR/OpenQuicklyWindow.swift | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/VimR/VimR/FileService.swift b/VimR/VimR/FileService.swift index 2ea3f5e4..0d7c8ead 100644 --- a/VimR/VimR/FileService.swift +++ b/VimR/VimR/FileService.swift @@ -133,15 +133,6 @@ class FileService { context: NSManagedObjectContext, callback: ([ScoredUrl]) -> () ) { - let saveAndReset = { (context: NSManagedObjectContext) in - do { - try context.save() - } catch { - self.log.error("There was an error saving the context: \(error)") - } - context.reset() - } - var saveCounter = 1 var counter = 1 @@ -154,7 +145,7 @@ class FileService { var batons = initialBatons var stack = [(initialBaton, folder)] while let iterElement = stack.popLast() { - if self.shouldStop({ saveAndReset(context) }) { return } + if self.shouldStop({ self.saveAndReset(context: context) }) { return } autoreleasepool { let baton = iterElement.0 @@ -194,7 +185,7 @@ class FileService { context: context, callback: callback ) - saveAndReset(context) + self.saveAndReset(context: context) saveCounter = 0 @@ -212,11 +203,20 @@ class FileService { self.log.debug("Flushing and scoring last \(saveCounter) Files") self.scoreAllRegisteredFiles(matcherPool: matcherPool, context: context, callback: callback) - saveAndReset(context) + self.saveAndReset(context: context) self.log.debug("Stored \(counter) Files") } + private func saveAndReset(context: NSManagedObjectContext) { + do { + try context.save() + } catch { + self.log.error("There was an error saving the context: \(error)") + } + context.reset() + } + private func shouldStop(_ body: (() -> Void)? = nil) -> Bool { self.stopLock.lock() defer { self.stopLock.unlock() } diff --git a/VimR/VimR/OpenQuicklyWindow.swift b/VimR/VimR/OpenQuicklyWindow.swift index ec7b050d..598e300b 100644 --- a/VimR/VimR/OpenQuicklyWindow.swift +++ b/VimR/VimR/OpenQuicklyWindow.swift @@ -59,6 +59,7 @@ class OpenQuicklyWindow: NSObject, private let progressIndicator = NSProgressIndicator(forAutoLayout: ()) private let cwdControl = NSPathControl(forAutoLayout: ()) private let fileView = NSTableView.standardTableView() + private let vcsIgnoreCheckbox = NSButton(forAutoLayout: ()) private let log = OSLog(subsystem: Defs.loggerSubsystem, category: Defs.LoggerCategory.uiComponents)