Skip to content
This repository has been archived by the owner on Mar 7, 2018. It is now read-only.

Right click menus #82

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions src/browser/context-menu-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
var reload = function(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.webContents.reload();
}
};

var windows_linux_template = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, this seems like a lot of duplication just to show keyboard shortcuts. 😦

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these actually identical?

{
label: 'Undo',
accelerator: 'CmdOrCtrl+Z',
role: 'undo:'
},
{
label: 'Redo',
accelerator: 'Shift+CmdOrCtrl+Z',
role: 'redo:'
},
{
type: 'separator'
},
{
label: 'Cut',
accelerator: 'CmdOrCtrl+X',
role: 'cut:'
},
{
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, they both say CmdOrCtrl+C...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is that OSx uses the selector property and non-OSx uses the role property on the menu item.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried role for OSx and the items were grayed out.

role: 'copy:'
},
{
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
role: 'paste:'
},
{
label: 'Select All',
accelerator: 'CmdOrCtrl+A',
role: 'selectAll:'
},
{
type: 'separator'
},
{
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
click: reload
}
];

var osx_template = [
{
label: 'Undo',
accelerator: 'CmdOrCtrl+Z',
selector: 'undo:'
},
{
label: 'Redo',
accelerator: 'Shift+CmdOrCtrl+Z',
selector: 'redo:'
},
{
type: 'separator'
},
{
label: 'Cut',
accelerator: 'CmdOrCtrl+X',
selector: 'cut:'
},
{
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
selector: 'copy:'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it appears that cut/copy/paste all have default actions, so we don't need to code anything?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it appears that cut/copy/paste all have default actions, so we don't need to code anything?

I'm not sure I understand what you're trying to say here. From what I can tell the copy, paste etc. commands write and read to the ClipBoard similar to a focusedWindow.webContents.copy().

},
{
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
selector: 'paste:'
},
{
label: 'Select All',
accelerator: 'CmdOrCtrl+A',
selector: 'selectAll:'
},
{
type: 'separator'
},
{
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
click: reload
}
];

if (process.platform === 'darwin') {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change this condition so it is false you'll see that the use of role instead of selector in the menu items does not work on OSx. At least that's what I saw. I was not able to test for Windows.
Here's a link to the discussion on using role vs selector. http://www.pracucci.com/atom-electron-enable-copy-and-paste.html

module.exports = osx_template
} else {
module.exports = windows_linux_template;
}
15 changes: 15 additions & 0 deletions src/browser/context-menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var remote = require('remote');
var Menu = remote.require('menu');
var template = require("./context-menu-template.js");

var menu = {};

menu.load = function(){
var contextMenu = Menu.buildFromTemplate(template);
document.addEventListener('contextmenu', function (e) {
e.preventDefault();
contextMenu.popup(remote.getCurrentWindow());
}, false);
};

module.exports = menu;
2 changes: 2 additions & 0 deletions src/browser/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require("./mattermost-observer.js");
require("./context-menu.js").load();
2 changes: 1 addition & 1 deletion src/browser/team-webview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var TeamWebview = React.createClass({
ref="webview"
src={this.props.teamUrl}
partition="persist:mattermost"
preload="mattermost-observer.js">
preload="preload.js">
</webview>
</div>
);
Expand Down