diff --git a/VimR/GeneralPrefPane.swift b/VimR/GeneralPrefPane.swift index fcf7e97f..21b97ec3 100644 --- a/VimR/GeneralPrefPane.swift +++ b/VimR/GeneralPrefPane.swift @@ -7,9 +7,11 @@ import Cocoa import PureLayout import RxSwift -struct GeneralPrefData { +struct GeneralPrefData: Equatable { let openNewWindowWhenLaunching: Bool let openNewWindowOnReactivation: Bool + + let ignorePatterns: Set } func == (left: GeneralPrefData, right: GeneralPrefData) -> Bool { @@ -17,10 +19,6 @@ func == (left: GeneralPrefData, right: GeneralPrefData) -> Bool { && left.openNewWindowOnReactivation == right.openNewWindowOnReactivation } -func != (left: GeneralPrefData, right: GeneralPrefData) -> Bool { - return !(left == right) -} - class GeneralPrefPane: PrefPane { override var pinToContainer: Bool { @@ -213,12 +211,14 @@ extension GeneralPrefPane { func openUntitledWindowWhenLaunchingAction(sender: NSButton) { self.data = GeneralPrefData(openNewWindowWhenLaunching: self.openWhenLaunchingCheckbox.boolState, - openNewWindowOnReactivation: self.data.openNewWindowOnReactivation) + openNewWindowOnReactivation: self.data.openNewWindowOnReactivation, + ignorePatterns: self.data.ignorePatterns) } func openUntitledWindowOnReactivation(sender: NSButton) { self.data = GeneralPrefData(openNewWindowWhenLaunching: self.data.openNewWindowWhenLaunching, - openNewWindowOnReactivation: self.openOnReactivationCheckbox.boolState) + openNewWindowOnReactivation: self.openOnReactivationCheckbox.boolState, + ignorePatterns: self.data.ignorePatterns) } private func alert(title title: String, info: String) { diff --git a/VimR/PrefStore.swift b/VimR/PrefStore.swift index 530b729f..39d91a34 100644 --- a/VimR/PrefStore.swift +++ b/VimR/PrefStore.swift @@ -10,6 +10,7 @@ private class PrefKeys { static let openNewWindowWhenLaunching = "open-new-window-when-launching" static let openNewWindowOnReactivation = "open-new-window-on-reactivation" + static let openQuicklyIgnorePatterns = "open-quickly-ignore-patterns" static let editorFontName = "editor-font-name" static let editorFontSize = "editor-font-size" @@ -35,7 +36,9 @@ class PrefStore: Store { private let fontManager = NSFontManager.sharedFontManager() var data = PrefData( - general: GeneralPrefData(openNewWindowWhenLaunching: true, openNewWindowOnReactivation: true), + general: GeneralPrefData(openNewWindowWhenLaunching: true, + openNewWindowOnReactivation: true, + ignorePatterns: Set([ "*/.git", "*.o", "*.d", "*.dia" ].map(FileItemIgnorePattern.init))), appearance: AppearancePrefData(editorFont: PrefStore.defaultEditorFont, editorUsesLigatures: false) ) @@ -55,6 +58,18 @@ class PrefStore: Store { self.subject.onCompleted() } + private func ignorePatterns(fromString str: String) -> Set { + return Set(str + .componentsSeparatedByString(",") + .map { + FileItemIgnorePattern(pattern: $0.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())) + }) + } + + private func ignorePatternString(fromSet set: Set) -> String { + return set.reduce("") { "\($0), \($1.pattern)" } + } + private func prefDataFromDict(prefs: [String: AnyObject]) -> PrefData { let editorFontName = prefs[PrefKeys.editorFontName] as? String ?? PrefStore.defaultEditorFont.fontName @@ -67,10 +82,14 @@ class PrefStore: Store { let openNewWindowWhenLaunching = (prefs[PrefKeys.openNewWindowWhenLaunching] as? NSNumber)?.boolValue ?? true let openNewWindowOnReactivation = (prefs[PrefKeys.openNewWindowOnReactivation] as? NSNumber)?.boolValue ?? true + let ignorePatternsList = (prefs[PrefKeys.openQuicklyIgnorePatterns] as? String) ?? "*/.git, *.o, *.d, *.dia" + let ignorePatterns = self.ignorePatterns(fromString: ignorePatternsList) + return PrefData( general: GeneralPrefData( openNewWindowWhenLaunching: openNewWindowWhenLaunching, - openNewWindowOnReactivation: openNewWindowOnReactivation + openNewWindowOnReactivation: openNewWindowOnReactivation, + ignorePatterns: ignorePatterns ), appearance: AppearancePrefData(editorFont: editorFont, editorUsesLigatures: usesLigatures) ) @@ -97,6 +116,7 @@ class PrefStore: Store { // General PrefKeys.openNewWindowWhenLaunching: generalData.openNewWindowWhenLaunching, PrefKeys.openNewWindowOnReactivation: generalData.openNewWindowOnReactivation, + PrefKeys.openQuicklyIgnorePatterns: self.ignorePatternString(fromSet: generalData.ignorePatterns), // Appearance PrefKeys.editorFontName: appearanceData.editorFont.fontName, diff --git a/VimR/SwiftCommons.swift b/VimR/SwiftCommons.swift index 94029a7f..76366c46 100644 --- a/VimR/SwiftCommons.swift +++ b/VimR/SwiftCommons.swift @@ -18,4 +18,4 @@ extension String { let idx = self.startIndex.advancedBy(prefix.characters.count) return self[idx..