Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Add "save image" to context menu #919

Merged
merged 6 commits into from
Dec 4, 2018
Merged
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
1 change: 1 addition & 0 deletions src/i18n/lang/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"Report issue": "Report issue",
"Reset app data": "Reset app data",
"Reset zoom": "Reset zoom",
"Save_Image": "Save Image",
"Select_a_screen_to_share": "Select a screen to share",
"Select &all": "Select &all",
"Server_Failed_to_Load": "Server Failed to Load",
Expand Down
29 changes: 21 additions & 8 deletions src/public/lib/SpellCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class SpellCheck {
}

setupContextMenuListener() {
window.addEventListener('contextmenu', (event) => {
webContents.on('context-menu', (event, properties) => {
event.preventDefault();

const template = this.createMenuTemplate();
Expand All @@ -338,26 +338,39 @@ class SpellCheck {
template.unshift(this.languagesMenu);
}

if (properties.mediaType === 'image') {
template.unshift({
type: 'separator',
}, {
label: i18n.__('Save_Image'),
click: () => {
webContents.downloadURL(properties.srcURL);
},
});
}

setTimeout(() => {
if (event.target.nodeName === 'A') {
const targetLink = event.target.href;
if (properties.linkURL !== '') {
const targetLink = properties.linkURL;

template.unshift({
label: i18n.__('Open_Link'),
click: () => {
shell.openExternal(targetLink);
},
});
template.unshift({
}, {
label: i18n.__('Copy_Link'),
click: () => {
clipboard.writeText(targetLink);
clipboard.write({
text: properties.linkURL,
bookmark: properties.linkText,
});
},
});
}

if (['TEXTAREA', 'INPUT'].indexOf(event.target.nodeName) > -1) {
const text = window.getSelection().toString().trim();
if (properties.isEditable && properties.selectionText !== '') {
const text = properties.selectionText.toString().trim();
if (text !== '' && !this.isCorrect(text)) {
const options = this.getCorrections(text);
const maxItems = Math.min(options.length, 6);
Expand Down