optionsUI: add 'editor.contextDelete'
This commit is contained in:
parent
0e1124b8bb
commit
ee86ef3037
|
@ -683,6 +683,9 @@
|
||||||
"optionsAdvancedExposeIframesNote": {
|
"optionsAdvancedExposeIframesNote": {
|
||||||
"message": "Enables writing iframe-specific CSS like 'html[stylus-iframe] h1 { display:none }'"
|
"message": "Enables writing iframe-specific CSS like 'html[stylus-iframe] h1 { display:none }'"
|
||||||
},
|
},
|
||||||
|
"optionsAdvancedContextDelete": {
|
||||||
|
"message": "Add 'Delete' in editor context menu"
|
||||||
|
},
|
||||||
"optionsActions": {
|
"optionsActions": {
|
||||||
"message": "Actions"
|
"message": "Actions"
|
||||||
},
|
},
|
||||||
|
|
|
@ -99,16 +99,10 @@ contextMenus = Object.assign({
|
||||||
title: 'openStylesManager',
|
title: 'openStylesManager',
|
||||||
click: browserCommands.openManage,
|
click: browserCommands.openManage,
|
||||||
},
|
},
|
||||||
},
|
}, prefs.get('editor.contextDelete') && {
|
||||||
// detect browsers without Delete by looking at the end of UA string
|
'editor.contextDelete': {
|
||||||
/Vivaldi\/[\d.]+$/.test(navigator.userAgent) ||
|
|
||||||
// Chrome and co.
|
|
||||||
/Safari\/[\d.]+$/.test(navigator.userAgent) &&
|
|
||||||
// skip forks with Flash as those are likely to have the menu e.g. CentBrowser
|
|
||||||
!Array.from(navigator.plugins).some(p => p.name == 'Shockwave Flash')
|
|
||||||
&& {
|
|
||||||
'editDeleteText': {
|
|
||||||
title: 'editDeleteText',
|
title: 'editDeleteText',
|
||||||
|
type: 'normal',
|
||||||
contexts: ['editable'],
|
contexts: ['editable'],
|
||||||
documentUrlPatterns: [URLS.ownOrigin + 'edit*'],
|
documentUrlPatterns: [URLS.ownOrigin + 'edit*'],
|
||||||
click: (info, tab) => {
|
click: (info, tab) => {
|
||||||
|
@ -117,26 +111,37 @@ contextMenus = Object.assign({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const id of Object.keys(contextMenus)) {
|
{
|
||||||
const item = Object.assign({id}, contextMenus[id]);
|
const createContextMenus = (ids = Object.keys(contextMenus)) => {
|
||||||
const prefValue = prefs.readOnlyValues[id];
|
for (const id of ids) {
|
||||||
const isBoolean = typeof prefValue == 'boolean';
|
const item = Object.assign({id}, contextMenus[id]);
|
||||||
item.title = chrome.i18n.getMessage(item.title);
|
const prefValue = prefs.readOnlyValues[id];
|
||||||
if (isBoolean) {
|
item.title = chrome.i18n.getMessage(item.title);
|
||||||
item.type = 'checkbox';
|
if (!item.type && typeof prefValue == 'boolean') {
|
||||||
item.checked = prefValue;
|
item.type = 'checkbox';
|
||||||
}
|
item.checked = prefValue;
|
||||||
if (!item.contexts) {
|
}
|
||||||
item.contexts = ['browser_action'];
|
if (!item.contexts) {
|
||||||
}
|
item.contexts = ['browser_action'];
|
||||||
delete item.click;
|
}
|
||||||
chrome.contextMenus.create(item, ignoreChromeError);
|
delete item.click;
|
||||||
|
chrome.contextMenus.create(item, ignoreChromeError);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
createContextMenus();
|
||||||
|
prefs.subscribe((id, checked) => {
|
||||||
|
if (id == 'editor.contextDelete') {
|
||||||
|
if (checked) {
|
||||||
|
createContextMenus([id]);
|
||||||
|
} else {
|
||||||
|
chrome.contextMenus.remove(id, ignoreChromeError);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
chrome.contextMenus.update(id, {checked}, ignoreChromeError);
|
||||||
|
}
|
||||||
|
}, Object.keys(contextMenus).filter(key => typeof prefs.readOnlyValues[key] == 'boolean'));
|
||||||
}
|
}
|
||||||
|
|
||||||
prefs.subscribe((id, checked) => {
|
|
||||||
chrome.contextMenus.update(id, {checked}, ignoreChromeError);
|
|
||||||
}, Object.keys(contextMenus));
|
|
||||||
|
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
// [re]inject content scripts
|
// [re]inject content scripts
|
||||||
{
|
{
|
||||||
|
|
4
edit.js
4
edit.js
|
@ -1234,8 +1234,8 @@ function initHooks() {
|
||||||
|
|
||||||
|
|
||||||
function toggleContextMenuDelete(event) {
|
function toggleContextMenuDelete(event) {
|
||||||
if (event.button == 2) {
|
if (event.button == 2 && prefs.get('editor.contextDelete')) {
|
||||||
chrome.contextMenus.update('editDeleteText', {
|
chrome.contextMenus.update('editor.contextDelete', {
|
||||||
enabled: Boolean(
|
enabled: Boolean(
|
||||||
this.selectionStart != this.selectionEnd ||
|
this.selectionStart != this.selectionEnd ||
|
||||||
this.somethingSelected && this.somethingSelected()
|
this.somethingSelected && this.somethingSelected()
|
||||||
|
|
|
@ -71,6 +71,13 @@
|
||||||
<span class="onoffswitch-label" for="exposeIframes"></span>
|
<span class="onoffswitch-label" for="exposeIframes"></span>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
|
<label>
|
||||||
|
<span i18n-text="optionsAdvancedContextDelete"></span>
|
||||||
|
<span class="onoffswitch">
|
||||||
|
<input type="checkbox" class="onoffswitch-checkbox" id="editor.contextDelete">
|
||||||
|
<span class="onoffswitch-label" for="editor.contextDelete"></span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
12
prefs.js
12
prefs.js
|
@ -44,6 +44,7 @@ var prefs = new function Prefs() {
|
||||||
'editor.matchHighlight': 'token', // token = token/word under cursor even if nothing is selected
|
'editor.matchHighlight': 'token', // token = token/word under cursor even if nothing is selected
|
||||||
// selection = only when something is selected
|
// selection = only when something is selected
|
||||||
// '' (empty string) = disabled
|
// '' (empty string) = disabled
|
||||||
|
'editor.contextDelete': contextDeleteMissing(), // "Delete" item in context menu
|
||||||
|
|
||||||
'badgeDisabled': '#8B0000', // badge background color when disabled
|
'badgeDisabled': '#8B0000', // badge background color when disabled
|
||||||
'badgeNormal': '#006666', // badge background color
|
'badgeNormal': '#006666', // badge background color
|
||||||
|
@ -301,6 +302,17 @@ var prefs = new function Prefs() {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function contextDeleteMissing() {
|
||||||
|
return (
|
||||||
|
// detect browsers without Delete by looking at the end of UA string
|
||||||
|
/Vivaldi\/[\d.]+$/.test(navigator.userAgent) ||
|
||||||
|
// Chrome and co.
|
||||||
|
/Safari\/[\d.]+$/.test(navigator.userAgent) &&
|
||||||
|
// skip forks with Flash as those are likely to have the menu e.g. CentBrowser
|
||||||
|
!Array.from(navigator.plugins).some(p => p.name == 'Shockwave Flash')
|
||||||
|
);
|
||||||
|
}
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user