mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: added feature to set keyboard shortcut to open/close popup window (#1976)
This commit is contained in:
@@ -78,10 +78,14 @@ open class Module {
|
||||
}
|
||||
public var combinedPosition: Int {
|
||||
get { Store.shared.int(key: "\(self.name)_position", defaultValue: 0) }
|
||||
set { Store.shared.set(key: "\(self.name)_position", value: newValue) }
|
||||
set { Store.shared.set(key: "\(self.name)_position", value: newValue) }
|
||||
}
|
||||
public var userDefaults: UserDefaults? = UserDefaults(suiteName: "\(Bundle.main.object(forInfoDictionaryKey: "TeamId") as! String).eu.exelban.Stats.widgets")
|
||||
|
||||
public var popupKeyboardShortcut: [UInt16] {
|
||||
return self.popupView?.keyboardShortcut ?? []
|
||||
}
|
||||
|
||||
private var moduleType: ModuleType
|
||||
|
||||
private var settingsView: Settings_v? = nil
|
||||
|
||||
@@ -12,18 +12,40 @@
|
||||
import Cocoa
|
||||
|
||||
public protocol Popup_p: NSView {
|
||||
var keyboardShortcut: [UInt16] { get }
|
||||
var sizeCallback: ((NSSize) -> Void)? { get set }
|
||||
|
||||
func settings() -> NSView?
|
||||
|
||||
func appear()
|
||||
func disappear()
|
||||
func setKeyboardShortcut(_ binding: [UInt16])
|
||||
}
|
||||
|
||||
open class PopupWrapper: NSStackView, Popup_p {
|
||||
public var title: String
|
||||
public var keyboardShortcut: [UInt16] = []
|
||||
open var sizeCallback: ((NSSize) -> Void)? = nil
|
||||
|
||||
public init(_ typ: ModuleType, frame: NSRect) {
|
||||
self.title = typ.rawValue
|
||||
self.keyboardShortcut = Store.shared.array(key: "\(typ.rawValue)_popup_keyboardShortcut", defaultValue: []) as? [UInt16] ?? []
|
||||
|
||||
super.init(frame: frame)
|
||||
}
|
||||
|
||||
required public init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
open func settings() -> NSView? { return nil }
|
||||
open func appear() {}
|
||||
open func disappear() {}
|
||||
|
||||
open func setKeyboardShortcut(_ binding: [UInt16]) {
|
||||
self.keyboardShortcut = binding
|
||||
Store.shared.set(key: "\(self.title)_popup_keyboardShortcut", value: binding)
|
||||
}
|
||||
}
|
||||
|
||||
public class PopupWindow: NSWindow, NSWindowDelegate {
|
||||
|
||||
Reference in New Issue
Block a user