Add app.dock.setMenu API
This commit is contained in:
parent
ba4f502b1e
commit
0e94977d42
8 changed files with 52 additions and 13 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "atom/browser/api/atom_api_menu.h"
|
||||||
#include "atom/browser/atom_browser_context.h"
|
#include "atom/browser/atom_browser_context.h"
|
||||||
#include "atom/browser/browser.h"
|
#include "atom/browser/browser.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
|
@ -191,12 +192,15 @@ int DockBounce(const std::string& type) {
|
||||||
request_id = Browser::Get()->DockBounce(Browser::BOUNCE_INFORMATIONAL);
|
request_id = Browser::Get()->DockBounce(Browser::BOUNCE_INFORMATIONAL);
|
||||||
return request_id;
|
return request_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DockSetMenu(atom::api::Menu* menu) {
|
||||||
|
Browser::Get()->DockSetMenu(menu->model());
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||||
v8::Handle<v8::Context> context, void* priv) {
|
v8::Handle<v8::Context> context, void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
Browser* browser = Browser::Get();
|
|
||||||
CommandLine* command_line = CommandLine::ForCurrentProcess();
|
CommandLine* command_line = CommandLine::ForCurrentProcess();
|
||||||
|
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
|
@ -206,20 +210,17 @@ void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||||
base::Bind(&CommandLine::AppendArg,
|
base::Bind(&CommandLine::AppendArg,
|
||||||
base::Unretained(command_line)));
|
base::Unretained(command_line)));
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
|
auto browser = base::Unretained(Browser::Get());
|
||||||
dict.SetMethod("dockBounce", &DockBounce);
|
dict.SetMethod("dockBounce", &DockBounce);
|
||||||
dict.SetMethod("dockCancelBounce",
|
dict.SetMethod("dockCancelBounce",
|
||||||
base::Bind(&Browser::DockCancelBounce,
|
base::Bind(&Browser::DockCancelBounce, browser));
|
||||||
base::Unretained(browser)));
|
|
||||||
dict.SetMethod("dockSetBadgeText",
|
dict.SetMethod("dockSetBadgeText",
|
||||||
base::Bind(&Browser::DockSetBadgeText,
|
base::Bind(&Browser::DockSetBadgeText, browser));
|
||||||
base::Unretained(browser)));
|
|
||||||
dict.SetMethod("dockGetBadgeText",
|
dict.SetMethod("dockGetBadgeText",
|
||||||
base::Bind(&Browser::DockGetBadgeText,
|
base::Bind(&Browser::DockGetBadgeText, browser));
|
||||||
base::Unretained(browser)));
|
dict.SetMethod("dockHide", base::Bind(&Browser::DockHide, browser));
|
||||||
dict.SetMethod("dockHide",
|
dict.SetMethod("dockShow", base::Bind(&Browser::DockShow, browser));
|
||||||
base::Bind(&Browser::DockHide, base::Unretained(browser)));
|
dict.SetMethod("dockSetMenu", &DockSetMenu);
|
||||||
dict.SetMethod("dockShow",
|
|
||||||
base::Bind(&Browser::DockShow, base::Unretained(browser)));
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ if process.platform is 'darwin'
|
||||||
getBadge: bindings.dockGetBadgeText
|
getBadge: bindings.dockGetBadgeText
|
||||||
hide: bindings.dockHide
|
hide: bindings.dockHide
|
||||||
show: bindings.dockShow
|
show: bindings.dockShow
|
||||||
|
setMenu: bindings.dockSetMenu
|
||||||
|
|
||||||
# Be compatible with old API.
|
# Be compatible with old API.
|
||||||
app.once 'ready', -> app.emit 'finish-launching'
|
app.once 'ready', -> app.emit 'finish-launching'
|
||||||
|
|
|
@ -20,7 +20,7 @@ void AtomBrowserMainParts::PreMainMessageLoopStart() {
|
||||||
// Force the NSApplication subclass to be used.
|
// Force the NSApplication subclass to be used.
|
||||||
NSApplication* application = [AtomApplication sharedApplication];
|
NSApplication* application = [AtomApplication sharedApplication];
|
||||||
|
|
||||||
AtomApplicationDelegate* delegate = [AtomApplicationDelegate alloc];
|
AtomApplicationDelegate* delegate = [[AtomApplicationDelegate alloc] init];
|
||||||
[NSApp setDelegate:(id<NSFileManagerDelegate>)delegate];
|
[NSApp setDelegate:(id<NSFileManagerDelegate>)delegate];
|
||||||
|
|
||||||
base::FilePath frameworkPath = brightray::MainApplicationBundlePath()
|
base::FilePath frameworkPath = brightray::MainApplicationBundlePath()
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
#include "atom/browser/browser_observer.h"
|
#include "atom/browser/browser_observer.h"
|
||||||
#include "atom/browser/window_list_observer.h"
|
#include "atom/browser/window_list_observer.h"
|
||||||
|
|
||||||
|
namespace ui {
|
||||||
|
class MenuModel;
|
||||||
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
// This class is used for control application-wide operations.
|
// This class is used for control application-wide operations.
|
||||||
|
@ -60,6 +64,9 @@ class Browser : public WindowListObserver {
|
||||||
// Hide/Show dock.
|
// Hide/Show dock.
|
||||||
void DockHide();
|
void DockHide();
|
||||||
void DockShow();
|
void DockShow();
|
||||||
|
|
||||||
|
// Set docks' menu.
|
||||||
|
void DockSetMenu(ui::MenuModel* model);
|
||||||
#endif // defined(OS_MACOSX)
|
#endif // defined(OS_MACOSX)
|
||||||
|
|
||||||
// Tell the application to open a file.
|
// Tell the application to open a file.
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "atom/browser/browser.h"
|
#include "atom/browser/browser.h"
|
||||||
|
|
||||||
#import "atom/browser/mac/atom_application.h"
|
#import "atom/browser/mac/atom_application.h"
|
||||||
|
#import "atom/browser/mac/atom_application_delegate.h"
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
#include "atom/browser/window_list.h"
|
#include "atom/browser/window_list.h"
|
||||||
#import "base/mac/bundle_locations.h"
|
#import "base/mac/bundle_locations.h"
|
||||||
|
@ -60,4 +61,9 @@ void Browser::DockShow() {
|
||||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Browser::DockSetMenu(ui::MenuModel* model) {
|
||||||
|
AtomApplicationDelegate* delegate = [NSApp delegate];
|
||||||
|
[delegate setApplicationDockMenu:model];
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -4,7 +4,16 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#import "atom/browser/ui/cocoa/atom_menu_controller.h"
|
||||||
|
|
||||||
@interface AtomApplicationDelegate : NSObject<NSApplicationDelegate> {
|
@interface AtomApplicationDelegate : NSObject<NSApplicationDelegate> {
|
||||||
|
@private
|
||||||
|
base::scoped_nsobject<AtomMenuController> menu_controller_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id)init;
|
||||||
|
|
||||||
|
// Sets the menu that will be returned in "applicationDockMenu:".
|
||||||
|
- (void)setApplicationDockMenu:(ui::MenuModel*)model;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -10,6 +10,16 @@
|
||||||
|
|
||||||
@implementation AtomApplicationDelegate
|
@implementation AtomApplicationDelegate
|
||||||
|
|
||||||
|
- (id)init {
|
||||||
|
self = [super init];
|
||||||
|
menu_controller_.reset([[AtomMenuController alloc] init]);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setApplicationDockMenu:(ui::MenuModel*)model {
|
||||||
|
[menu_controller_ populateWithModel:model];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)applicationWillFinishLaunching:(NSNotification*)notify {
|
- (void)applicationWillFinishLaunching:(NSNotification*)notify {
|
||||||
atom::Browser::Get()->WillFinishLaunching();
|
atom::Browser::Get()->WillFinishLaunching();
|
||||||
}
|
}
|
||||||
|
@ -18,6 +28,10 @@
|
||||||
atom::Browser::Get()->DidFinishLaunching();
|
atom::Browser::Get()->DidFinishLaunching();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSMenu*)applicationDockMenu:(NSApplication*)sender {
|
||||||
|
return [menu_controller_ menu];
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)application:(NSApplication*)sender
|
- (BOOL)application:(NSApplication*)sender
|
||||||
openFile:(NSString*)filename {
|
openFile:(NSString*)filename {
|
||||||
std::string filename_str(base::SysNSStringToUTF8(filename));
|
std::string filename_str(base::SysNSStringToUTF8(filename));
|
||||||
|
|
|
@ -70,7 +70,8 @@ int EventFlagsFromNSEvent(NSEvent* event) {
|
||||||
@synthesize model = model_;
|
@synthesize model = model_;
|
||||||
|
|
||||||
- (id)init {
|
- (id)init {
|
||||||
self = [super init];
|
if ((self = [super init]))
|
||||||
|
[self menu];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue