mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-15 21:28:40 -09:00
Add context menu (#2001)
This commit is contained in:
parent
2af575c3c0
commit
62e29effbf
7 changed files with 58 additions and 0 deletions
18
app/ui/contextmenu.js
Normal file
18
app/ui/contextmenu.js
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
const editMenu = require('../menus/menus/edit');
|
||||||
|
const shellMenu = require('../menus/menus/shell');
|
||||||
|
const {getKeymaps: commands} = require('../config');
|
||||||
|
const separator = {type: 'separator'};
|
||||||
|
|
||||||
|
// only display cut/copy when there's a cursor selection
|
||||||
|
const filterCutCopy = (selection, menuItem) => {
|
||||||
|
if (/^cut$|^copy$/.test(menuItem.role) && !selection) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return menuItem;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = (createWindow, selection) => {
|
||||||
|
const _shell = shellMenu(commands, createWindow).submenu;
|
||||||
|
const _edit = editMenu(commands).submenu.filter(filterCutCopy.bind(null, selection));
|
||||||
|
return _edit.concat(separator, _shell);
|
||||||
|
};
|
||||||
|
|
@ -11,6 +11,7 @@ const createRPC = require('../rpc');
|
||||||
const notify = require('../notify');
|
const notify = require('../notify');
|
||||||
const fetchNotifications = require('../notifications');
|
const fetchNotifications = require('../notifications');
|
||||||
const Session = require('../session');
|
const Session = require('../session');
|
||||||
|
const contextMenuTemplate = require('./contextmenu');
|
||||||
const {execCommand} = require('../commands');
|
const {execCommand} = require('../commands');
|
||||||
|
|
||||||
module.exports = class Window {
|
module.exports = class Window {
|
||||||
|
|
@ -153,6 +154,11 @@ module.exports = class Window {
|
||||||
rpc.on('open external', ({url}) => {
|
rpc.on('open external', ({url}) => {
|
||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
});
|
});
|
||||||
|
rpc.on('open context menu', selection => {
|
||||||
|
const {createWindow} = app;
|
||||||
|
const {buildFromTemplate} = Menu;
|
||||||
|
buildFromTemplate(contextMenuTemplate(createWindow, selection)).popup(window);
|
||||||
|
});
|
||||||
rpc.on('open hamburger menu', ({x, y}) => {
|
rpc.on('open hamburger menu', ({x, y}) => {
|
||||||
Menu.getApplicationMenu().popup(Math.ceil(x), Math.ceil(y));
|
Menu.getApplicationMenu().popup(Math.ceil(x), Math.ceil(y));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import {
|
||||||
UI_WINDOW_GEOMETRY_CHANGED,
|
UI_WINDOW_GEOMETRY_CHANGED,
|
||||||
UI_WINDOW_MOVE,
|
UI_WINDOW_MOVE,
|
||||||
UI_OPEN_FILE,
|
UI_OPEN_FILE,
|
||||||
|
UI_CONTEXTMENU_OPEN,
|
||||||
UI_COMMAND_EXEC
|
UI_COMMAND_EXEC
|
||||||
} from '../constants/ui';
|
} from '../constants/ui';
|
||||||
|
|
||||||
|
|
@ -27,6 +28,22 @@ import {setActiveGroup} from './term-groups';
|
||||||
|
|
||||||
const {stat} = window.require('fs');
|
const {stat} = window.require('fs');
|
||||||
|
|
||||||
|
export function openContextMenu(uid, selection) {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
dispatch({
|
||||||
|
type: UI_CONTEXTMENU_OPEN,
|
||||||
|
uid,
|
||||||
|
effect() {
|
||||||
|
const state = getState();
|
||||||
|
const show = !state.ui.quickEdit;
|
||||||
|
if (show) {
|
||||||
|
rpc.emit('open context menu', selection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function increaseFontSize() {
|
export function increaseFontSize() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ class TermGroup_ extends PureComponent {
|
||||||
onTitle: this.bind(this.props.onTitle, null, uid),
|
onTitle: this.bind(this.props.onTitle, null, uid),
|
||||||
onData: this.bind(this.props.onData, null, uid),
|
onData: this.bind(this.props.onData, null, uid),
|
||||||
onURLAbort: this.bind(this.props.onURLAbort, null, uid),
|
onURLAbort: this.bind(this.props.onURLAbort, null, uid),
|
||||||
|
onContextMenu: this.bind(this.props.onContextMenu, null, uid),
|
||||||
borderColor: this.props.borderColor,
|
borderColor: this.props.borderColor,
|
||||||
quickEdit: this.props.quickEdit,
|
quickEdit: this.props.quickEdit,
|
||||||
uid
|
uid
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,14 @@ export default class Terms extends Component {
|
||||||
this.terms[uid] = term;
|
this.terms[uid] = term;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
window.addEventListener('contextmenu', () => {
|
||||||
|
const selection = window.getSelection().toString();
|
||||||
|
const {props: {uid}} = this.getActiveTerm();
|
||||||
|
this.props.onContextMenu(uid, selection);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.props.ref_(null);
|
this.props.ref_(null);
|
||||||
}
|
}
|
||||||
|
|
@ -97,6 +105,7 @@ export default class Terms extends Component {
|
||||||
onTitle: this.props.onTitle,
|
onTitle: this.props.onTitle,
|
||||||
onData: this.props.onData,
|
onData: this.props.onData,
|
||||||
onURLAbort: this.props.onURLAbort,
|
onURLAbort: this.props.onURLAbort,
|
||||||
|
onContextMenu: this.props.onContextMenu,
|
||||||
quickEdit: this.props.quickEdit,
|
quickEdit: this.props.quickEdit,
|
||||||
parentProps: this.props
|
parentProps: this.props
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -17,4 +17,5 @@ export const UI_OPEN_FILE = 'UI_OPEN_FILE';
|
||||||
export const UI_OPEN_HAMBURGER_MENU = 'UI_OPEN_HAMBURGER_MENU';
|
export const UI_OPEN_HAMBURGER_MENU = 'UI_OPEN_HAMBURGER_MENU';
|
||||||
export const UI_WINDOW_MINIMIZE = 'UI_WINDOW_MINIMIZE';
|
export const UI_WINDOW_MINIMIZE = 'UI_WINDOW_MINIMIZE';
|
||||||
export const UI_WINDOW_CLOSE = 'UI_WINDOW_CLOSE';
|
export const UI_WINDOW_CLOSE = 'UI_WINDOW_CLOSE';
|
||||||
|
export const UI_CONTEXTMENU_OPEN = 'UI_CONTEXTMENU_OPEN';
|
||||||
export const UI_COMMAND_EXEC = 'UI_COMMAND_EXEC';
|
export const UI_COMMAND_EXEC = 'UI_COMMAND_EXEC';
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {
|
||||||
setSessionXtermTitle,
|
setSessionXtermTitle,
|
||||||
setActiveSession
|
setActiveSession
|
||||||
} from '../actions/sessions';
|
} from '../actions/sessions';
|
||||||
|
import {openContextMenu} from '../actions/ui';
|
||||||
import getRootGroups from '../selectors';
|
import getRootGroups from '../selectors';
|
||||||
|
|
||||||
const TermsContainer = connect(
|
const TermsContainer = connect(
|
||||||
|
|
@ -60,6 +61,11 @@ const TermsContainer = connect(
|
||||||
|
|
||||||
onActive(uid) {
|
onActive(uid) {
|
||||||
dispatch(setActiveSession(uid));
|
dispatch(setActiveSession(uid));
|
||||||
|
},
|
||||||
|
|
||||||
|
onContextMenu(uid, selection) {
|
||||||
|
dispatch(setActiveSession(uid));
|
||||||
|
dispatch(openContextMenu(uid, selection));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue