-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreferencesWindowController.swift
50 lines (38 loc) · 1.54 KB
/
PreferencesWindowController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// PreferencesWindowController.swift
// AndroidTool
//
// Created by Morten Just Petersen on 5/1/15.
// Copyright (c) 2015 Morten Just Petersen. All rights reserved.
//
import Cocoa
class PreferencesWindowController: NSWindowController {
@IBAction func screenshotFolderClicked(_ sender: AnyObject) {
selectFolder("Screenshots", message: "Save screenshots in this folder", defaultsPath: "screenshotsFolder")
}
@IBAction func screenRecordingFolderClicked(_ sender: AnyObject) {
selectFolder("Screen recordings", message: "Save recordings in this folder", defaultsPath: "screenRecordingsFolder")
}
override func windowDidLoad() {
super.windowDidLoad()
// all bindings are belong to IB
}
func selectFolder(_ title:String, message:String, defaultsPath:String){
let openPanel = NSOpenPanel();
openPanel.title = title
openPanel.message = message
openPanel.showsResizeIndicator=true;
openPanel.canChooseDirectories = true;
openPanel.canChooseFiles = false;
openPanel.allowsMultipleSelection = false;
openPanel.canCreateDirectories = true;
openPanel.begin { (result) -> Void in
if(result == NSFileHandlingPanelOKButton){
let path = openPanel.url!.path
print("selected folder is \(path), saving to \(defaultsPath)");
let ud = UserDefaults.standard
ud.setValue(path, forKey: defaultsPath)
}
}
}
}