[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 {ipcRenderer, remote, shell} from 'electron';
|
||||||
|
|
||||||
import Utils from '../../utils/util';
|
import Utils from '../../utils/util';
|
||||||
|
import contextmenu from '../js/contextMenu';
|
||||||
|
|
||||||
import restoreButton from '../../assets/titlebar/chrome-restore.svg';
|
import restoreButton from '../../assets/titlebar/chrome-restore.svg';
|
||||||
import maximizeButton from '../../assets/titlebar/chrome-maximize.svg';
|
import maximizeButton from '../../assets/titlebar/chrome-maximize.svg';
|
||||||
@@ -62,6 +63,14 @@ export default class MainPage extends React.Component {
|
|||||||
focusFinder: false,
|
focusFinder: false,
|
||||||
finderVisible: 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) {
|
parseDeeplinkURL(deeplink, teams = this.props.teams) {
|
||||||
|
@@ -128,7 +128,8 @@ export default class MattermostView extends React.Component {
|
|||||||
webview.focus();
|
webview.focus();
|
||||||
}
|
}
|
||||||
if (!this.state.isContextMenuAdded) {
|
if (!this.state.isContextMenuAdded) {
|
||||||
contextMenu.setup(webview, {
|
contextMenu.setup({
|
||||||
|
window: webview,
|
||||||
useSpellChecker: this.props.useSpellChecker,
|
useSpellChecker: this.props.useSpellChecker,
|
||||||
onSelectSpellCheckerLocale: (locale) => {
|
onSelectSpellCheckerLocale: (locale) => {
|
||||||
if (this.props.onSelectSpellCheckerLocale) {
|
if (this.props.onSelectSpellCheckerLocale) {
|
||||||
|
@@ -1,16 +1,17 @@
|
|||||||
// Copyright (c) 2015-2016 Yuya Ochiai
|
// Copyright (c) 2015-2016 Yuya Ochiai
|
||||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
import {ipcRenderer} from 'electron';
|
import {ipcRenderer, remote} from 'electron';
|
||||||
import electronContextMenu from 'electron-context-menu';
|
import electronContextMenu from 'electron-context-menu';
|
||||||
|
|
||||||
function getSuggestionsMenus(win, suggestions) {
|
function getSuggestionsMenus(webcontents, suggestions) {
|
||||||
if (suggestions.length === 0) {
|
if (suggestions.length === 0) {
|
||||||
return [{
|
return [{
|
||||||
label: 'No Suggestions',
|
label: 'No Suggestions',
|
||||||
enabled: false,
|
enabled: false,
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
const win = webcontents || remote.getCurrentWindow();
|
||||||
return suggestions.map((s) => ({
|
return suggestions.map((s) => ({
|
||||||
label: s,
|
label: s,
|
||||||
click() {
|
click() {
|
||||||
@@ -46,20 +47,33 @@ function getSpellCheckerLocaleMenus(onSelectSpellCheckerLocale) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setup(win, options) {
|
setup(options) {
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
useSpellChecker: false,
|
useSpellChecker: false,
|
||||||
onSelectSpellCheckerLocale: null,
|
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);
|
const actualOptions = Object.assign({}, defaultOptions, options);
|
||||||
|
|
||||||
electronContextMenu({
|
electronContextMenu({
|
||||||
window: win.webContents ? win : {...win, webContents: win.getWebContents()},
|
|
||||||
prepend(_defaultActions, params) {
|
prepend(_defaultActions, params) {
|
||||||
if (actualOptions.useSpellChecker) {
|
if (actualOptions.useSpellChecker) {
|
||||||
const prependMenuItems = [];
|
const prependMenuItems = [];
|
||||||
if (params.isEditable && params.misspelledWord !== '') {
|
if (params.isEditable && params.misspelledWord !== '') {
|
||||||
const suggestions = ipcRenderer.sendSync('get-spelling-suggestions', 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) {
|
if (params.isEditable) {
|
||||||
prependMenuItems.push(
|
prependMenuItems.push(
|
||||||
@@ -70,6 +84,7 @@ export default {
|
|||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
...actualOptions,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@@ -15,7 +15,7 @@ import Config from '../common/config';
|
|||||||
import SettingsPage from './components/SettingsPage.jsx';
|
import SettingsPage from './components/SettingsPage.jsx';
|
||||||
import contextMenu from './js/contextMenu';
|
import contextMenu from './js/contextMenu';
|
||||||
|
|
||||||
contextMenu.setup(remote.getCurrentWindow());
|
contextMenu.setup();
|
||||||
|
|
||||||
const config = new Config(remote.app.getPath('userData') + '/config.json', remote.getCurrentWindow().registryConfigData);
|
const config = new Config(remote.app.getPath('userData') + '/config.json', remote.getCurrentWindow().registryConfigData);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user