Add a context menu for the initial default app.
This commit is contained in:
parent
3bcb5b11a4
commit
fc9135d335
2 changed files with 30 additions and 9 deletions
|
@ -5,5 +5,13 @@
|
|||
</head>
|
||||
<body>
|
||||
Content
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
var ipc = require('ipc');
|
||||
|
||||
window.addEventListener('contextmenu', function (e) {
|
||||
e.preventDefault();
|
||||
ipc.send('menu');
|
||||
}, false);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,24 +1,17 @@
|
|||
var app = require('app');
|
||||
var delegate = require('atom_delegate');
|
||||
var ipc = require('ipc');
|
||||
var Menu = require('menu');
|
||||
var Window = require('window');
|
||||
|
||||
var mainWindow = null;
|
||||
var menu = null;
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', function() {
|
||||
app.terminate();
|
||||
});
|
||||
|
||||
// Echo every message back.
|
||||
ipc.on('message', function(process_id, routing_id) {
|
||||
ipc.send.apply(ipc, arguments);
|
||||
});
|
||||
|
||||
ipc.on('sync-message', function(event, process_id, routing_id) {
|
||||
event.result = arguments;
|
||||
});
|
||||
|
||||
delegate.browserMainParts.preMainMessageLoopRun = function() {
|
||||
mainWindow = new Window({ width: 800, height: 600 });
|
||||
mainWindow.loadUrl('file://' + __dirname + '/index.html');
|
||||
|
@ -33,4 +26,24 @@ delegate.browserMainParts.preMainMessageLoopRun = function() {
|
|||
console.log('closed');
|
||||
mainWindow = null;
|
||||
});
|
||||
|
||||
menu = new Menu;
|
||||
menu.appendItem(0, 'Open GitHub');
|
||||
|
||||
menu.delegate = {
|
||||
getAcceleratorForCommandId: function(commandId) {
|
||||
if (commandId == 0)
|
||||
return 'Ctrl+g';
|
||||
}
|
||||
}
|
||||
|
||||
menu.on('execute', function(commandId) {
|
||||
if (commandId == 0)
|
||||
mainWindow.loadUrl('https://github.com');
|
||||
});
|
||||
|
||||
ipc.on('message', function(processId, routingId, type) {
|
||||
if (type == 'menu')
|
||||
menu.popup(mainWindow);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue