feat: added feature to set keyboard shortcut to open/close popup window (#1976)

This commit is contained in:
Serhiy Mytrovtsiy
2025-01-20 17:04:55 +01:00
parent b4c835e97d
commit 58ad6c568b
25 changed files with 346 additions and 39 deletions

View File

@@ -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

View File

@@ -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 {