From 3226b149678b8c22cc3910dc2bf4578bd36a1986 Mon Sep 17 00:00:00 2001 From: John L Davis Date: Fri, 22 Jan 2016 16:33:35 -0600 Subject: [PATCH 1/6] Added right click context menu to views --- src/browser/context-menu-template.js | 126 +++++++++++++++++++++++++++ src/browser/context-menu.js | 16 ++++ src/browser/mattermost-observer.js | 1 + 3 files changed, 143 insertions(+) create mode 100644 src/browser/context-menu-template.js create mode 100644 src/browser/context-menu.js diff --git a/src/browser/context-menu-template.js b/src/browser/context-menu-template.js new file mode 100644 index 0000000..a5c7c3c --- /dev/null +++ b/src/browser/context-menu-template.js @@ -0,0 +1,126 @@ +var remote = require('remote'); + +var template = [ + { + label: 'Electron', + submenu: [ + { + label: 'About Electron', + selector: 'orderFrontStandardAboutPanel:' + }, + { + type: 'separator' + }, + { + label: 'Services', + submenu: [] + }, + { + type: 'separator' + }, + { + label: 'Hide Electron', + accelerator: 'Command+H', + selector: 'hide:' + }, + { + label: 'Hide Others', + accelerator: 'Command+Shift+H', + selector: 'hideOtherApplications:' + }, + { + label: 'Show All', + selector: 'unhideAllApplications:' + }, + { + type: 'separator' + }, + { + label: 'Quit', + accelerator: 'Command+Q', + selector: 'terminate:' + }, + ] + }, + { + label: 'Edit', + submenu: [ + { + label: 'Undo', + accelerator: 'Command+Z', + selector: 'undo:' + }, + { + label: 'Redo', + accelerator: 'Shift+Command+Z', + selector: 'redo:' + }, + { + type: 'separator' + }, + { + label: 'Cut', + accelerator: 'Command+X', + selector: 'cut:' + }, + { + label: 'Copy', + accelerator: 'Command+C', + selector: 'copy:' + }, + { + label: 'Paste', + accelerator: 'Command+V', + selector: 'paste:' + }, + { + label: 'Select All', + accelerator: 'Command+A', + selector: 'selectAll:' + } + ] + }, + { + label: 'View', + submenu: [ + { + label: 'Reload', + accelerator: 'Command+R', + click: function() { remote.getCurrentWindow().reload(); } + }, + { + label: 'Toggle DevTools', + accelerator: 'Alt+Command+I', + click: function() { remote.getCurrentWindow().toggleDevTools(); } + }, + ] + }, + { + label: 'Window', + submenu: [ + { + label: 'Minimize', + accelerator: 'Command+M', + selector: 'performMiniaturize:' + }, + { + label: 'Close', + accelerator: 'Command+W', + selector: 'performClose:' + }, + { + type: 'separator' + }, + { + label: 'Bring All to Front', + selector: 'arrangeInFront:' + } + ] + }, + { + label: 'Extra Item Just Because' + + } +]; + +module.exports = template; diff --git a/src/browser/context-menu.js b/src/browser/context-menu.js new file mode 100644 index 0000000..9dd2e70 --- /dev/null +++ b/src/browser/context-menu.js @@ -0,0 +1,16 @@ +var remote = require('remote'); +var Menu = remote.require('menu'); +var template = require("./context-menu-template.js"); + +var menu = {}; + +menu.load = function(){ + console.log("context-menu load() called"); + var contextMenu = Menu.buildFromTemplate(template); + document.addEventListener('contextmenu', function (e) { + e.preventDefault(); + contextMenu.popup(remote.getCurrentWindow()); + }, false); +}; + +module.exports = menu; diff --git a/src/browser/mattermost-observer.js b/src/browser/mattermost-observer.js index 179d5be..c8d3d6d 100644 --- a/src/browser/mattermost-observer.js +++ b/src/browser/mattermost-observer.js @@ -1,4 +1,5 @@ var ipc = require('electron').ipcRenderer; +require("./context-menu.js").load(); document.addEventListener("DOMContentLoaded", function() { // observe the DOM for mutations, specifically the .ps-container From 89287f7dac6f9dff17e9027c254bc0eab71e0199 Mon Sep 17 00:00:00 2001 From: John L Davis Date: Mon, 25 Jan 2016 08:02:29 -0600 Subject: [PATCH 2/6] removed console.log() --- src/browser/context-menu.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/browser/context-menu.js b/src/browser/context-menu.js index 9dd2e70..2618cf5 100644 --- a/src/browser/context-menu.js +++ b/src/browser/context-menu.js @@ -5,7 +5,6 @@ var template = require("./context-menu-template.js"); var menu = {}; menu.load = function(){ - console.log("context-menu load() called"); var contextMenu = Menu.buildFromTemplate(template); document.addEventListener('contextmenu', function (e) { e.preventDefault(); From 74f4455fa126147628580c25410335157745ec44 Mon Sep 17 00:00:00 2001 From: John L Davis Date: Mon, 25 Jan 2016 11:19:44 -0600 Subject: [PATCH 3/6] Allow preload of multiple modules into team webview. Cleaned up context menu items. --- src/browser/context-menu-template.js | 141 ++++++--------------------- src/browser/mattermost-observer.js | 1 - src/browser/preload.js | 2 + src/browser/team-webview.jsx | 2 +- 4 files changed, 34 insertions(+), 112 deletions(-) create mode 100644 src/browser/preload.js diff --git a/src/browser/context-menu-template.js b/src/browser/context-menu-template.js index a5c7c3c..93b9492 100644 --- a/src/browser/context-menu-template.js +++ b/src/browser/context-menu-template.js @@ -2,124 +2,45 @@ var remote = require('remote'); var template = [ { - label: 'Electron', - submenu: [ - { - label: 'About Electron', - selector: 'orderFrontStandardAboutPanel:' - }, - { - type: 'separator' - }, - { - label: 'Services', - submenu: [] - }, - { - type: 'separator' - }, - { - label: 'Hide Electron', - accelerator: 'Command+H', - selector: 'hide:' - }, - { - label: 'Hide Others', - accelerator: 'Command+Shift+H', - selector: 'hideOtherApplications:' - }, - { - label: 'Show All', - selector: 'unhideAllApplications:' - }, - { - type: 'separator' - }, - { - label: 'Quit', - accelerator: 'Command+Q', - selector: 'terminate:' - }, - ] + label: 'Undo', + accelerator: 'Command+Z', + selector: 'undo:' }, { - label: 'Edit', - submenu: [ - { - label: 'Undo', - accelerator: 'Command+Z', - selector: 'undo:' - }, - { - label: 'Redo', - accelerator: 'Shift+Command+Z', - selector: 'redo:' - }, - { - type: 'separator' - }, - { - label: 'Cut', - accelerator: 'Command+X', - selector: 'cut:' - }, - { - label: 'Copy', - accelerator: 'Command+C', - selector: 'copy:' - }, - { - label: 'Paste', - accelerator: 'Command+V', - selector: 'paste:' - }, - { - label: 'Select All', - accelerator: 'Command+A', - selector: 'selectAll:' - } - ] + label: 'Redo', + accelerator: 'Shift+Command+Z', + selector: 'redo:' }, { - label: 'View', - submenu: [ - { - label: 'Reload', - accelerator: 'Command+R', - click: function() { remote.getCurrentWindow().reload(); } - }, - { - label: 'Toggle DevTools', - accelerator: 'Alt+Command+I', - click: function() { remote.getCurrentWindow().toggleDevTools(); } - }, - ] + type: 'separator' }, { - label: 'Window', - submenu: [ - { - label: 'Minimize', - accelerator: 'Command+M', - selector: 'performMiniaturize:' - }, - { - label: 'Close', - accelerator: 'Command+W', - selector: 'performClose:' - }, - { - type: 'separator' - }, - { - label: 'Bring All to Front', - selector: 'arrangeInFront:' - } - ] + label: 'Cut', + accelerator: 'Command+X', + selector: 'cut:' }, { - label: 'Extra Item Just Because' - + label: 'Copy', + accelerator: 'Command+C', + selector: 'copy:' + }, + { + label: 'Paste', + accelerator: 'Command+V', + selector: 'paste:' + }, + { + label: 'Select All', + accelerator: 'Command+A', + selector: 'selectAll:' + }, + { + type: 'separator' + }, + { + label: 'Reload', + accelerator: 'Command+R', + click: function() { remote.getCurrentWindow().reload(); } } ]; diff --git a/src/browser/mattermost-observer.js b/src/browser/mattermost-observer.js index c8d3d6d..179d5be 100644 --- a/src/browser/mattermost-observer.js +++ b/src/browser/mattermost-observer.js @@ -1,5 +1,4 @@ var ipc = require('electron').ipcRenderer; -require("./context-menu.js").load(); document.addEventListener("DOMContentLoaded", function() { // observe the DOM for mutations, specifically the .ps-container diff --git a/src/browser/preload.js b/src/browser/preload.js new file mode 100644 index 0000000..2007771 --- /dev/null +++ b/src/browser/preload.js @@ -0,0 +1,2 @@ +require("./mattermost-observer.js"); +require("./context-menu.js").load(); diff --git a/src/browser/team-webview.jsx b/src/browser/team-webview.jsx index 8cdf5a7..c785b4d 100644 --- a/src/browser/team-webview.jsx +++ b/src/browser/team-webview.jsx @@ -24,7 +24,7 @@ var TeamWebview = React.createClass({ ref="webview" src={this.props.teamUrl} partition="persist:mattermost" - preload="mattermost-observer.js"> + preload="preload.js"> ); From bb2e396138c63c3867524746acf4947fda2b5efd Mon Sep 17 00:00:00 2001 From: John L Davis Date: Wed, 27 Jan 2016 10:30:15 -0600 Subject: [PATCH 4/6] Refactored for OSx and non-OSx menu's --- src/browser/context-menu-template.js | 74 +++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 11 deletions(-) diff --git a/src/browser/context-menu-template.js b/src/browser/context-menu-template.js index 93b9492..ca184ce 100644 --- a/src/browser/context-menu-template.js +++ b/src/browser/context-menu-template.js @@ -1,14 +1,62 @@ -var remote = require('remote'); +var reload = function(item, focusedWindow) { + if (focusedWindow) { + focusedWindow.webContents.reload(); + } +}; + +var windows_linux_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', + 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 template = [ +var osx_template = [ { label: 'Undo', - accelerator: 'Command+Z', + accelerator: 'CmdOrCtrl+Z', selector: 'undo:' }, { label: 'Redo', - accelerator: 'Shift+Command+Z', + accelerator: 'Shift+CmdOrCtrl+Z', selector: 'redo:' }, { @@ -16,22 +64,22 @@ var template = [ }, { label: 'Cut', - accelerator: 'Command+X', + accelerator: 'CmdOrCtrl+X', selector: 'cut:' }, { label: 'Copy', - accelerator: 'Command+C', + accelerator: 'CmdOrCtrl+C', selector: 'copy:' }, { label: 'Paste', - accelerator: 'Command+V', + accelerator: 'CmdOrCtrl+V', selector: 'paste:' }, { label: 'Select All', - accelerator: 'Command+A', + accelerator: 'CmdOrCtrl+A', selector: 'selectAll:' }, { @@ -39,9 +87,13 @@ var template = [ }, { label: 'Reload', - accelerator: 'Command+R', - click: function() { remote.getCurrentWindow().reload(); } + accelerator: 'CmdOrCtrl+R', + click: reload } ]; -module.exports = template; +if (process.platform === 'darwin') { + module.exports = osx_template +} else { + module.exports = windows_linux_template; +} From dcca6ccbc81f407af519baf517b21f93182982e6 Mon Sep 17 00:00:00 2001 From: John L Davis Date: Thu, 28 Jan 2016 14:30:24 -0600 Subject: [PATCH 5/6] Updated context menu to include Comment function --- src/browser/context-menu-template.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/browser/context-menu-template.js b/src/browser/context-menu-template.js index ca184ce..43eb1d4 100644 --- a/src/browser/context-menu-template.js +++ b/src/browser/context-menu-template.js @@ -4,6 +4,15 @@ var reload = function(item, focusedWindow) { } }; +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 windows_linux_template = [ { label: 'Undo', @@ -45,6 +54,14 @@ var windows_linux_template = [ label: 'Reload', accelerator: 'CmdOrCtrl+R', click: reload + }, + { + type: 'separator' + }, + { + label: 'Comment', + accelerator: 'Shift+CmdOrCtrl+C', + click: comment } ]; @@ -89,6 +106,14 @@ var osx_template = [ label: 'Reload', accelerator: 'CmdOrCtrl+R', click: reload + }, + { + type: 'separator' + }, + { + label: 'Comment', + accelerator: 'Shift+CmdOrCtrl+C', + click: comment } ]; From 916eabfd0c9c4caff5bfea7550783de865635e4f Mon Sep 17 00:00:00 2001 From: John L Davis Date: Thu, 28 Jan 2016 16:23:17 -0600 Subject: [PATCH 6/6] change template for Windows/Linux --- src/browser/context-menu-template.js | 71 ++++++---------------------- 1 file changed, 15 insertions(+), 56 deletions(-) diff --git a/src/browser/context-menu-template.js b/src/browser/context-menu-template.js index 43eb1d4..e4dab55 100644 --- a/src/browser/context-menu-template.js +++ b/src/browser/context-menu-template.js @@ -13,7 +13,18 @@ var comment = function(item, focusedWindow) { } }; -var windows_linux_template = [ +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', @@ -65,60 +76,8 @@ var windows_linux_template = [ } ]; -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:' - }, - { - label: 'Paste', - accelerator: 'CmdOrCtrl+V', - selector: 'paste:' - }, - { - label: 'Select All', - accelerator: 'CmdOrCtrl+A', - selector: 'selectAll:' - }, - { - type: 'separator' - }, - { - label: 'Reload', - accelerator: 'CmdOrCtrl+R', - click: reload - }, - { - type: 'separator' - }, - { - label: 'Comment', - accelerator: 'Shift+CmdOrCtrl+C', - click: comment - } -]; - if (process.platform === 'darwin') { - module.exports = osx_template -} else { - module.exports = windows_linux_template; + template = changeTemplateForOSx(template); } + +module.exports = template