From 61132519e5c8a29b80a18afde3f60f9b38e26173 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sun, 15 Jul 2018 10:32:27 +0200 Subject: [PATCH] Migrate OpenQuicklyWindow.State --- VimR/VimR/States.swift | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/VimR/VimR/States.swift b/VimR/VimR/States.swift index 100e7861..7bb49470 100644 --- a/VimR/VimR/States.swift +++ b/VimR/VimR/States.swift @@ -79,21 +79,40 @@ struct AppState: SerializableState { extension OpenQuicklyWindow { - struct State: SerializableState { + struct State: Codable, SerializableState { static let `default` = State() + static let defaultIgnorePatterns = Set(["*/.git", "*.o", "*.d", "*.dia"].map(FileItemIgnorePattern.init)) + + enum CodingKeys: String, CodingKey { + + case ignorePatterns + } + + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + if let patternsAsString = try container.decodeIfPresent(String.self, forKey: .ignorePatterns) { + self.ignorePatterns = FileItemIgnorePattern.from(string: patternsAsString) + } else { + self.ignorePatterns = State.defaultIgnorePatterns + } + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(FileItemIgnorePattern.toString(self.ignorePatterns), forKey: .ignorePatterns) + } let root = FileItem(URL(fileURLWithPath: "/", isDirectory: true)) var flatFileItems = Observable<[FileItem]>.empty() var cwd = FileUtils.userHomeUrl - var ignorePatterns = Set(["*/.git", "*.o", "*.d", "*.dia"].map(FileItemIgnorePattern.init)) + var ignorePatterns = State.defaultIgnorePatterns var ignoreToken = Token() var open = false init() { - } init?(dict: [String: Any]) {