Add "Open Recent" submenu to default
This commit is contained in:
parent
f8adaed763
commit
f0bff74995
6 changed files with 85 additions and 1 deletions
|
@ -200,6 +200,7 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu);
|
dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu);
|
||||||
dict.SetMethod("sendActionToFirstResponder",
|
dict.SetMethod("sendActionToFirstResponder",
|
||||||
&Menu::SendActionToFirstResponder);
|
&Menu::SendActionToFirstResponder);
|
||||||
|
dict.SetMethod("noteNewRecentDocumentURL", &Menu::NoteNewRecentDocumentURL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,10 @@ class Menu : public mate::TrackableObject<Menu>,
|
||||||
|
|
||||||
// Fake sending an action from the application menu.
|
// Fake sending an action from the application menu.
|
||||||
static void SendActionToFirstResponder(const std::string& action);
|
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
|
#endif
|
||||||
|
|
||||||
AtomMenuModel* model() const { return model_.get(); }
|
AtomMenuModel* model() const { return model_.get(); }
|
||||||
|
|
|
@ -139,6 +139,13 @@ void Menu::SendActionToFirstResponder(const std::string& action) {
|
||||||
[NSApp sendAction:selector to:nil from:[NSApp mainMenu]];
|
[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
|
// static
|
||||||
mate::WrappableBase* Menu::New(mate::Arguments* args) {
|
mate::WrappableBase* Menu::New(mate::Arguments* args) {
|
||||||
return new MenuMac(args->isolate(), args->GetThis());
|
return new MenuMac(args->isolate(), args->GetThis());
|
||||||
|
|
|
@ -65,6 +65,31 @@
|
||||||
<reference key="NSOnImage" ref="229763992"/>
|
<reference key="NSOnImage" ref="229763992"/>
|
||||||
<reference key="NSMixedImage" ref="909111550"/>
|
<reference key="NSMixedImage" ref="909111550"/>
|
||||||
</object>
|
</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>
|
</array>
|
||||||
<string key="NSName">_NSAppleMenu</string>
|
<string key="NSName">_NSAppleMenu</string>
|
||||||
</object>
|
</object>
|
||||||
|
@ -115,6 +140,7 @@
|
||||||
<reference key="object" ref="903638069"/>
|
<reference key="object" ref="903638069"/>
|
||||||
<reference key="parent" ref="0"/>
|
<reference key="parent" ref="0"/>
|
||||||
</object>
|
</object>
|
||||||
|
<!-- NSMenu Main Menu -->
|
||||||
<object class="IBObjectRecord">
|
<object class="IBObjectRecord">
|
||||||
<int key="objectID">29</int>
|
<int key="objectID">29</int>
|
||||||
<reference key="object" ref="649796088"/>
|
<reference key="object" ref="649796088"/>
|
||||||
|
@ -123,6 +149,7 @@
|
||||||
</array>
|
</array>
|
||||||
<reference key="parent" ref="0"/>
|
<reference key="parent" ref="0"/>
|
||||||
</object>
|
</object>
|
||||||
|
<!-- NSMenuItem Electron -->
|
||||||
<object class="IBObjectRecord">
|
<object class="IBObjectRecord">
|
||||||
<int key="objectID">56</int>
|
<int key="objectID">56</int>
|
||||||
<reference key="object" ref="694149608"/>
|
<reference key="object" ref="694149608"/>
|
||||||
|
@ -131,30 +158,60 @@
|
||||||
</array>
|
</array>
|
||||||
<reference key="parent" ref="649796088"/>
|
<reference key="parent" ref="649796088"/>
|
||||||
</object>
|
</object>
|
||||||
|
<!-- NSMenu Electron -->
|
||||||
<object class="IBObjectRecord">
|
<object class="IBObjectRecord">
|
||||||
<int key="objectID">57</int>
|
<int key="objectID">57</int>
|
||||||
<reference key="object" ref="110575045"/>
|
<reference key="object" ref="110575045"/>
|
||||||
<array class="NSMutableArray" key="children">
|
<array class="NSMutableArray" key="children">
|
||||||
<reference ref="632727374"/>
|
<reference ref="632727374"/>
|
||||||
|
<reference ref="1025936716"/>
|
||||||
</array>
|
</array>
|
||||||
<reference key="parent" ref="694149608"/>
|
<reference key="parent" ref="694149608"/>
|
||||||
</object>
|
</object>
|
||||||
|
<!-- NSMenuItem Quit -->
|
||||||
<object class="IBObjectRecord">
|
<object class="IBObjectRecord">
|
||||||
<int key="objectID">136</int>
|
<int key="objectID">136</int>
|
||||||
<reference key="object" ref="632727374"/>
|
<reference key="object" ref="632727374"/>
|
||||||
<reference key="parent" ref="110575045"/>
|
<reference key="parent" ref="110575045"/>
|
||||||
</object>
|
</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>
|
</array>
|
||||||
</object>
|
</object>
|
||||||
<dictionary class="NSMutableDictionary" key="flattenedProperties">
|
<dictionary class="NSMutableDictionary" key="flattenedProperties">
|
||||||
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||||
<string key="-2.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="-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="29.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||||
<string key="371.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="56.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||||
<string key="57.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>
|
||||||
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
|
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
|
||||||
<nil key="activeLocalization"/>
|
<nil key="activeLocalization"/>
|
||||||
|
|
|
@ -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)
|
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.
|
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)`
|
#### `Menu.buildFromTemplate(template)`
|
||||||
|
|
||||||
* `template` MenuItemConstructorOptions[]
|
* `template` MenuItemConstructorOptions[]
|
||||||
|
|
|
@ -174,6 +174,14 @@ Menu.buildFromTemplate = function (template) {
|
||||||
return menu
|
return menu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Menu.noteNewRecentDocumentURL = function (url) {
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
bindings.noteNewRecentDocumentURL(url);
|
||||||
|
} else {
|
||||||
|
throw new Error('Not supported')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
|
|
||||||
// Search between separators to find a radio menu item and return its group id
|
// Search between separators to find a radio menu item and return its group id
|
||||||
|
|
Loading…
Reference in a new issue