Add "Open Recent" submenu to default

This commit is contained in:
Zhuo Lu 2017-11-18 17:36:30 -08:00 committed by Cheng Zhao
parent f8adaed763
commit f0bff74995
6 changed files with 85 additions and 1 deletions

View file

@ -200,6 +200,7 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu);
dict.SetMethod("sendActionToFirstResponder",
&Menu::SendActionToFirstResponder);
dict.SetMethod("noteNewRecentDocumentURL", &Menu::NoteNewRecentDocumentURL);
#endif
}

View file

@ -31,6 +31,10 @@ class Menu : public mate::TrackableObject<Menu>,
// Fake sending an action from the application menu.
static void SendActionToFirstResponder(const std::string& action);
// Add an item corresponding to the data located by a URL to the Open Recent
// menu, or replace an existing item with the same URL.
static void NoteNewRecentDocumentURL(const std::string& url);
#endif
AtomMenuModel* model() const { return model_.get(); }

View file

@ -139,6 +139,13 @@ void Menu::SendActionToFirstResponder(const std::string& action) {
[NSApp sendAction:selector to:nil from:[NSApp mainMenu]];
}
// static
void Menu::NoteNewRecentDocumentURL(const std::string& url) {
[[NSDocumentController sharedDocumentController]
noteNewRecentDocumentURL:
[NSURL fileURLWithPath:base::SysUTF8ToNSString(url)]];
}
// static
mate::WrappableBase* Menu::New(mate::Arguments* args) {
return new MenuMac(args->isolate(), args->GetThis());

View file

@ -65,6 +65,31 @@
<reference key="NSOnImage" ref="229763992"/>
<reference key="NSMixedImage" ref="909111550"/>
</object>
<object class="NSMenuItem" id="1025936716">
<reference key="NSMenu" ref="110575045"/>
<string key="NSTitle">Open Recent</string>
<string key="NSKeyEquiv"/>
<int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="229763992"/>
<reference key="NSMixedImage" ref="909111550"/>
<string key="NSAction">submenuAction:</string>
<object class="NSMenu" key="NSSubmenu" id="1065607017">
<string key="NSTitle">Open Recent</string>
<array class="NSMutableArray" key="NSMenuItems">
<object class="NSMenuItem" id="759406840">
<reference key="NSMenu" ref="1065607017"/>
<string key="NSTitle">Clear Menu</string>
<string key="NSKeyEquiv"/>
<int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="229763992"/>
<reference key="NSMixedImage" ref="909111550"/>
</object>
</array>
<string key="NSName">_NSRecentDocumentsMenu</string>
</object>
</object>
</array>
<string key="NSName">_NSAppleMenu</string>
</object>
@ -115,6 +140,7 @@
<reference key="object" ref="903638069"/>
<reference key="parent" ref="0"/>
</object>
<!-- NSMenu Main Menu -->
<object class="IBObjectRecord">
<int key="objectID">29</int>
<reference key="object" ref="649796088"/>
@ -123,6 +149,7 @@
</array>
<reference key="parent" ref="0"/>
</object>
<!-- NSMenuItem Electron -->
<object class="IBObjectRecord">
<int key="objectID">56</int>
<reference key="object" ref="694149608"/>
@ -131,30 +158,60 @@
</array>
<reference key="parent" ref="649796088"/>
</object>
<!-- NSMenu Electron -->
<object class="IBObjectRecord">
<int key="objectID">57</int>
<reference key="object" ref="110575045"/>
<array class="NSMutableArray" key="children">
<reference ref="632727374"/>
<reference ref="1025936716"/>
</array>
<reference key="parent" ref="694149608"/>
</object>
<!-- NSMenuItem Quit -->
<object class="IBObjectRecord">
<int key="objectID">136</int>
<reference key="object" ref="632727374"/>
<reference key="parent" ref="110575045"/>
</object>
<!-- NSMenuItem Open Recent -->
<object class="IBObjectRecord">
<int key="objectID">124</int>
<reference key="object" ref="1025936716"/>
<array class="NSMutableArray" key="children">
<reference ref="1065607017"/>
</array>
<reference key="parent" ref="110575045"/>
</object>
<!-- NSMenu Open Recent -->
<object class="IBObjectRecord">
<int key="objectID">125</int>
<reference key="object" ref="1065607017"/>
<array class="NSMutableArray" key="children">
<reference ref="759406840"/>
</array>
<reference key="parent" ref="1025936716"/>
</object>
<!-- NSMenuItem Clear Menu -->
<object class="IBObjectRecord">
<int key="objectID">126</int>
<reference key="object" ref="759406840"/>
<reference key="parent" ref="1065607017"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="136.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="29.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="371.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="56.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="57.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="136.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="124.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="125.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="126.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>

View file

@ -43,6 +43,13 @@ emulating default macOS menu behaviors. Usually you would just use the
See the [macOS Cocoa Event Handling Guide](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW7)
for more information on macOS' native actions.
#### `Menu.noteNewRecentDocumentURL(url)` _macOS_
* `url` String
Add an item corresponding to the data located by a URL to the Open Recent menu,
or replace an existing item with the same URL.
#### `Menu.buildFromTemplate(template)`
* `template` MenuItemConstructorOptions[]

View file

@ -174,6 +174,14 @@ Menu.buildFromTemplate = function (template) {
return menu
}
Menu.noteNewRecentDocumentURL = function (url) {
if (process.platform === 'darwin') {
bindings.noteNewRecentDocumentURL(url);
} else {
throw new Error('Not supported')
}
}
/* Helper Functions */
// Search between separators to find a radio menu item and return its group id