mirror of https://github.com/mpv-player/mpv
mac/apphub: move menu bar into AppHub
This commit is contained in:
parent
e2bc1e5f9b
commit
1bc680d32a
|
@ -21,6 +21,7 @@ class AppHub: NSObject {
|
|||
var mpv: OpaquePointer?
|
||||
@objc var input: InputHelper
|
||||
var event: EventHelper?
|
||||
var menu: MenuBar?
|
||||
#if HAVE_MACOS_MEDIA_PLAYER
|
||||
var remote: RemoteCommandCenter?
|
||||
#endif
|
||||
|
@ -33,6 +34,7 @@ class AppHub: NSObject {
|
|||
private override init() {
|
||||
input = InputHelper()
|
||||
super.init()
|
||||
if isApplication { menu = MenuBar(self) }
|
||||
#if HAVE_MACOS_MEDIA_PLAYER
|
||||
remote = RemoteCommandCenter(self)
|
||||
#endif
|
||||
|
|
|
@ -58,7 +58,6 @@ static void terminate_cocoa_application(void)
|
|||
}
|
||||
|
||||
@implementation Application
|
||||
@synthesize menuBar = _menu_bar;
|
||||
@synthesize openCount = _open_count;
|
||||
@synthesize cocoaCB = _cocoa_cb;
|
||||
|
||||
|
@ -183,7 +182,6 @@ static void init_cocoa_application(bool regular)
|
|||
{
|
||||
NSApp = mpv_shared_app();
|
||||
[NSApp setDelegate:NSApp];
|
||||
[NSApp setMenuBar:[[MenuBar alloc] init]];
|
||||
|
||||
// Will be set to Regular from cocoa_common during UI creation so that we
|
||||
// don't create an icon when playing audio only files.
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "osdep/mac/application.h"
|
||||
|
||||
@class CocoaCB;
|
||||
@class MenuBar;
|
||||
struct mpv_event;
|
||||
struct mpv_handle;
|
||||
|
||||
|
@ -27,7 +26,6 @@ struct mpv_handle;
|
|||
|
||||
- (void)initCocoaCb:(struct mpv_handle *)ctx;
|
||||
|
||||
@property(nonatomic, retain) MenuBar *menuBar;
|
||||
@property(nonatomic, assign) size_t openCount;
|
||||
@property(nonatomic, retain) CocoaCB *cocoaCB;
|
||||
@end
|
||||
|
|
|
@ -68,18 +68,20 @@ extension MenuBar {
|
|||
}
|
||||
|
||||
class MenuBar: NSObject {
|
||||
unowned let appHub: AppHub
|
||||
let mainMenu = NSMenu(title: "Main")
|
||||
let servicesMenu = NSMenu(title: "Services")
|
||||
var menuConfigs: [Config] = []
|
||||
var dynamicMenuItems: [Type:[MenuItem]] = [:]
|
||||
let appIcon: NSImage
|
||||
|
||||
@objc override init() {
|
||||
@objc init(_ appHub: AppHub) {
|
||||
self.appHub = appHub
|
||||
UserDefaults.standard.set(false, forKey: "NSFullScreenMenuItemEverywhere")
|
||||
UserDefaults.standard.set(true, forKey: "NSDisabledDictationMenuItem")
|
||||
UserDefaults.standard.set(true, forKey: "NSDisabledCharacterPaletteMenuItem")
|
||||
NSWindow.allowsAutomaticWindowTabbing = false
|
||||
appIcon = AppHub.shared.getIcon()
|
||||
appIcon = appHub.getIcon()
|
||||
|
||||
super.init()
|
||||
|
||||
|
@ -318,7 +320,7 @@ class MenuBar: NSObject {
|
|||
|
||||
@objc func quit(_ menuItem: MenuItem) {
|
||||
guard let menuConfig = menuItem.config else { return }
|
||||
AppHub.shared.input.command(menuConfig.command)
|
||||
appHub.input.command(menuConfig.command)
|
||||
}
|
||||
|
||||
@objc func openFiles() {
|
||||
|
@ -327,7 +329,7 @@ class MenuBar: NSObject {
|
|||
panel.canChooseDirectories = true
|
||||
|
||||
if panel.runModal() == .OK {
|
||||
AppHub.shared.input.open(files: panel.urls.map { $0.path })
|
||||
appHub.input.open(files: panel.urls.map { $0.path })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,7 +337,7 @@ class MenuBar: NSObject {
|
|||
let panel = NSOpenPanel()
|
||||
|
||||
if panel.runModal() == .OK, let url = panel.urls.first {
|
||||
AppHub.shared.input.command("loadlist \"\(url.path)\"")
|
||||
appHub.input.command("loadlist \"\(url.path)\"")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -355,13 +357,13 @@ class MenuBar: NSObject {
|
|||
}
|
||||
|
||||
if alert.runModal() == .alertFirstButtonReturn && input.stringValue.count > 0 {
|
||||
AppHub.shared.input.open(files: [input.stringValue])
|
||||
appHub.input.open(files: [input.stringValue])
|
||||
}
|
||||
}
|
||||
|
||||
@objc func command(_ menuItem: MenuItem) {
|
||||
guard let menuConfig = menuItem.config else { return }
|
||||
AppHub.shared.input.command(menuConfig.command)
|
||||
appHub.input.command(menuConfig.command)
|
||||
}
|
||||
|
||||
@objc func url(_ menuItem: MenuItem) {
|
||||
|
|
|
@ -105,13 +105,11 @@ class Window: NSWindow, NSWindowDelegate {
|
|||
currentScreen = screen
|
||||
unfScreen = screen
|
||||
|
||||
if let app = NSApp as? Application {
|
||||
app.menuBar.register(#selector(setHalfWindowSize), key: .itemHalfSize)
|
||||
app.menuBar.register(#selector(setNormalWindowSize), key: .itemNormalSize)
|
||||
app.menuBar.register(#selector(setDoubleWindowSize), key: .itemDoubleSize)
|
||||
app.menuBar.register(#selector(performMiniaturize(_:)), key: .itemMinimize)
|
||||
app.menuBar.register(#selector(performZoom(_:)), key: .itemZoom)
|
||||
}
|
||||
AppHub.shared.menu?.register(#selector(setHalfWindowSize), key: .itemHalfSize)
|
||||
AppHub.shared.menu?.register(#selector(setNormalWindowSize), key: .itemNormalSize)
|
||||
AppHub.shared.menu?.register(#selector(setDoubleWindowSize), key: .itemDoubleSize)
|
||||
AppHub.shared.menu?.register(#selector(performMiniaturize(_:)), key: .itemMinimize)
|
||||
AppHub.shared.menu?.register(#selector(performZoom(_:)), key: .itemZoom)
|
||||
}
|
||||
|
||||
override func toggleFullScreen(_ sender: Any?) {
|
||||
|
|
Loading…
Reference in New Issue