mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-28 02:54:31 +03:00
GH-274 Add ignore patterns to the general pref data
This commit is contained in:
parent
eafa76cba3
commit
3a7a5eed2f
@ -7,9 +7,11 @@ import Cocoa
|
||||
import PureLayout
|
||||
import RxSwift
|
||||
|
||||
struct GeneralPrefData {
|
||||
struct GeneralPrefData: Equatable {
|
||||
let openNewWindowWhenLaunching: Bool
|
||||
let openNewWindowOnReactivation: Bool
|
||||
|
||||
let ignorePatterns: Set<FileItemIgnorePattern>
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -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<FileItemIgnorePattern> {
|
||||
return Set(str
|
||||
.componentsSeparatedByString(",")
|
||||
.map {
|
||||
FileItemIgnorePattern(pattern: $0.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()))
|
||||
})
|
||||
}
|
||||
|
||||
private func ignorePatternString(fromSet set: Set<FileItemIgnorePattern>) -> 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,
|
||||
|
@ -18,4 +18,4 @@ extension String {
|
||||
let idx = self.startIndex.advancedBy(prefix.characters.count)
|
||||
return self[idx..<self.endIndex]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user