[MM-26017] add menu to all windows (#1327)
* [MM-26017] add menu to all windows * fix suggestions * fix internal images
This commit is contained in:
@@ -17,6 +17,7 @@ import DotsVerticalIcon from 'mdi-react/DotsVerticalIcon';
|
||||
import {ipcRenderer, remote, shell} from 'electron';
|
||||
|
||||
import Utils from '../../utils/util';
|
||||
import contextmenu from '../js/contextMenu';
|
||||
|
||||
import restoreButton from '../../assets/titlebar/chrome-restore.svg';
|
||||
import maximizeButton from '../../assets/titlebar/chrome-maximize.svg';
|
||||
@@ -62,6 +63,14 @@ export default class MainPage extends React.Component {
|
||||
focusFinder: false,
|
||||
finderVisible: false,
|
||||
};
|
||||
contextmenu.setup({
|
||||
useSpellChecker: this.props.useSpellChecker,
|
||||
onSelectSpellCheckerLocale: (locale) => {
|
||||
if (this.props.onSelectSpellCheckerLocale) {
|
||||
this.props.onSelectSpellCheckerLocale(locale);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
parseDeeplinkURL(deeplink, teams = this.props.teams) {
|
||||
|
@@ -128,7 +128,8 @@ export default class MattermostView extends React.Component {
|
||||
webview.focus();
|
||||
}
|
||||
if (!this.state.isContextMenuAdded) {
|
||||
contextMenu.setup(webview, {
|
||||
contextMenu.setup({
|
||||
window: webview,
|
||||
useSpellChecker: this.props.useSpellChecker,
|
||||
onSelectSpellCheckerLocale: (locale) => {
|
||||
if (this.props.onSelectSpellCheckerLocale) {
|
||||
|
@@ -1,16 +1,17 @@
|
||||
// Copyright (c) 2015-2016 Yuya Ochiai
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
import {ipcRenderer} from 'electron';
|
||||
import {ipcRenderer, remote} from 'electron';
|
||||
import electronContextMenu from 'electron-context-menu';
|
||||
|
||||
function getSuggestionsMenus(win, suggestions) {
|
||||
function getSuggestionsMenus(webcontents, suggestions) {
|
||||
if (suggestions.length === 0) {
|
||||
return [{
|
||||
label: 'No Suggestions',
|
||||
enabled: false,
|
||||
}];
|
||||
}
|
||||
const win = webcontents || remote.getCurrentWindow();
|
||||
return suggestions.map((s) => ({
|
||||
label: s,
|
||||
click() {
|
||||
@@ -46,20 +47,33 @@ function getSpellCheckerLocaleMenus(onSelectSpellCheckerLocale) {
|
||||
}
|
||||
|
||||
export default {
|
||||
setup(win, options) {
|
||||
setup(options) {
|
||||
const defaultOptions = {
|
||||
useSpellChecker: false,
|
||||
onSelectSpellCheckerLocale: null,
|
||||
shouldShowMenu: (e, p) => {
|
||||
const isInternalLink = p.linkURL.endsWith('#') && p.linkURL.slice(0, -1) === p.pageURL;
|
||||
let isInternalSrc;
|
||||
try {
|
||||
const srcurl = new URL(p.srcURL);
|
||||
isInternalSrc = srcurl.protocol === 'file:';
|
||||
console.log(`srcrurl protocol: ${srcurl.protocol}`);
|
||||
} catch (err) {
|
||||
console.log(`ups: ${err}`);
|
||||
isInternalSrc = false;
|
||||
}
|
||||
return p.isEditable || (p.mediaType !== 'none' && !isInternalSrc) || (p.linkURL !== '' && !isInternalLink) || p.misspelledWord !== '' || p.selectionText !== '';
|
||||
}
|
||||
};
|
||||
const actualOptions = Object.assign({}, defaultOptions, options);
|
||||
|
||||
electronContextMenu({
|
||||
window: win.webContents ? win : {...win, webContents: win.getWebContents()},
|
||||
prepend(_defaultActions, params) {
|
||||
if (actualOptions.useSpellChecker) {
|
||||
const prependMenuItems = [];
|
||||
if (params.isEditable && params.misspelledWord !== '') {
|
||||
const suggestions = ipcRenderer.sendSync('get-spelling-suggestions', params.misspelledWord);
|
||||
prependMenuItems.push(...getSuggestionsMenus(win, suggestions));
|
||||
prependMenuItems.push(...getSuggestionsMenus(options.window, suggestions));
|
||||
}
|
||||
if (params.isEditable) {
|
||||
prependMenuItems.push(
|
||||
@@ -70,6 +84,7 @@ export default {
|
||||
}
|
||||
return [];
|
||||
},
|
||||
...actualOptions,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@@ -15,7 +15,7 @@ import Config from '../common/config';
|
||||
import SettingsPage from './components/SettingsPage.jsx';
|
||||
import contextMenu from './js/contextMenu';
|
||||
|
||||
contextMenu.setup(remote.getCurrentWindow());
|
||||
contextMenu.setup();
|
||||
|
||||
const config = new Config(remote.app.getPath('userData') + '/config.json', remote.getCurrentWindow().registryConfigData);
|
||||
|
||||
|
Reference in New Issue
Block a user