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 all 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
83 changes: 83 additions & 0 deletions src/browser/context-menu-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
var reload = function(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.webContents.reload();
}
};

var comment = function(item, focusedWindow) {
var selection = document.getSelection();
if (selection.toString().length > 0) {
var textbox = document.getElementById("post_textbox");
textbox.value = "> " + selection;
textbox.focus();
}
};

var changeTemplateForOSx = function(obj){
//OSx uses the 'selector' key whereas Windows/Linux uses 'role'
for (var i=0; i < obj.length; i++) {
if (obj[i].role) {
obj[i].selector = obj[i].role;
delete obj[i].role;
}
}
return obj;
};

var template = [
{
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
},
{
type: 'separator'
},
{
label: 'Comment',
accelerator: 'Shift+CmdOrCtrl+C',
click: comment
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this one on the context menu, and I'm not seeing any functionality out of it. What is it supposed to do?

Copy link
Author

Choose a reason for hiding this comment

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

Hmmm. Here's what I'm seeing. Once you select a post you can select Comment and it will add the > followed by the selected text in the new entry field.
contextmenu

Copy link
Author

Choose a reason for hiding this comment

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

Obvious question but did you pull the latest? I just added this commit late yesterday.

Copy link
Contributor

Choose a reason for hiding this comment

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

I pulled it at 11pm. :-) I'll figure it out. Probably just a user error.
On Jan 29, 2016 7:51 AM, "3-john-4" [email protected] wrote:

In src/browser/context-menu-template.js
#82 (comment)
:

  • },
  • {
  • type: 'separator'
  • },
  • {
  • label: 'Reload',
  • accelerator: 'CmdOrCtrl+R',
  • click: reload
  • },
  • {
  • type: 'separator'
  • },
  • {
  • label: 'Comment',
  • accelerator: 'Shift+CmdOrCtrl+C',
  • click: comment

Obvious question but did you pull the latest? I just added this commit
late yesterday.


Reply to this email directly or view it on GitHub
https://github.com/HackerHappyHour/matterfront/pull/82/files#r51261992.

}
];

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

template = changeTemplateForOSx(template);
}

module.exports = 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