mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-15 00:34:08 +09:00
feat: added buttons for import/export application settings (#1837)
This commit is contained in:
@@ -298,6 +298,18 @@ class ApplicationSettings: NSStackView {
|
||||
grid.setContentHuggingPriority(.defaultHigh, for: .horizontal)
|
||||
grid.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
||||
|
||||
let importBtn: NSButton = NSButton()
|
||||
importBtn.title = localizedString("Import")
|
||||
importBtn.bezelStyle = .rounded
|
||||
importBtn.target = self
|
||||
importBtn.action = #selector(self.importSettings)
|
||||
|
||||
let exportBtn: NSButton = NSButton()
|
||||
exportBtn.title = localizedString("Export")
|
||||
exportBtn.bezelStyle = .rounded
|
||||
exportBtn.target = self
|
||||
exportBtn.action = #selector(self.exportSettings)
|
||||
|
||||
let resetBtn: NSButton = NSButton()
|
||||
resetBtn.title = localizedString("Reset")
|
||||
resetBtn.bezelStyle = .rounded
|
||||
@@ -307,8 +319,10 @@ class ApplicationSettings: NSStackView {
|
||||
|
||||
grid.addRow(with: [
|
||||
self.titleView(localizedString("Settings")),
|
||||
resetBtn
|
||||
importBtn
|
||||
])
|
||||
grid.addRow(with: [NSGridCell.emptyContentView, exportBtn])
|
||||
grid.addRow(with: [NSGridCell.emptyContentView, resetBtn])
|
||||
|
||||
view.addArrangedSubview(grid)
|
||||
|
||||
@@ -434,6 +448,30 @@ class ApplicationSettings: NSStackView {
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func importSettings(_ sender: NSObject) {
|
||||
let panel = NSOpenPanel()
|
||||
panel.level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.modalPanelWindow)))
|
||||
panel.begin { (result) in
|
||||
guard result.rawValue == NSApplication.ModalResponse.OK.rawValue else { return }
|
||||
if let url = panel.url {
|
||||
Store.shared.import(from: url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func exportSettings(_ sender: NSObject) {
|
||||
let panel = NSSavePanel()
|
||||
panel.nameFieldStringValue = "Stats.plist"
|
||||
panel.showsTagField = false
|
||||
panel.level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.modalPanelWindow)))
|
||||
panel.begin { (result) in
|
||||
guard result.rawValue == NSApplication.ModalResponse.OK.rawValue else { return }
|
||||
if let url = panel.url {
|
||||
Store.shared.export(to: url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func resetSettings(_ sender: NSObject) {
|
||||
let alert = NSAlert()
|
||||
alert.messageText = localizedString("Reset settings")
|
||||
|
||||
Reference in New Issue
Block a user