simplify context menu + shorten titles
This commit is contained in:
parent
d2a99b5be1
commit
bd9d51308a
|
@ -1352,8 +1352,8 @@
|
||||||
"message": "Reading styles..."
|
"message": "Reading styles..."
|
||||||
},
|
},
|
||||||
"reload": {
|
"reload": {
|
||||||
"message": "Reload Stylus extension",
|
"message": "Reload",
|
||||||
"description": "Context menu reload"
|
"description": "Context menu to reload the extension when installed in developer mode"
|
||||||
},
|
},
|
||||||
"replace": {
|
"replace": {
|
||||||
"message": "Replace",
|
"message": "Replace",
|
||||||
|
|
|
@ -1,34 +1,34 @@
|
||||||
/* global browserCommands */// background.js
|
/* global browserCommands */// background.js
|
||||||
/* global msg */
|
/* global msg */
|
||||||
/* global prefs */
|
/* global prefs */
|
||||||
/* global CHROME FIREFOX URLS ignoreChromeError */// toolbox.js
|
/* global CHROME URLS ignoreChromeError */// toolbox.js
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(() => {
|
chrome.management.getSelf(ext => {
|
||||||
const contextMenus = {
|
const contextMenus = Object.assign({
|
||||||
'show-badge': {
|
'show-badge': {
|
||||||
title: 'menuShowBadge',
|
title: 'menuShowBadge',
|
||||||
click: info => prefs.set(info.menuItemId, info.checked),
|
click: togglePref,
|
||||||
},
|
},
|
||||||
'disableAll': {
|
'disableAll': {
|
||||||
title: 'disableAllStyles',
|
title: 'disableAllStyles',
|
||||||
click: browserCommands.styleDisableAll,
|
click: browserCommands.styleDisableAll,
|
||||||
},
|
},
|
||||||
'open-manager': {
|
'open-manager': {
|
||||||
title: 'openStylesManager',
|
title: 'optionsOpenManager',
|
||||||
click: browserCommands.openManage,
|
click: browserCommands.openManage,
|
||||||
},
|
},
|
||||||
'open-options': {
|
'open-options': {
|
||||||
title: 'openOptions',
|
title: 'openOptions',
|
||||||
click: browserCommands.openOptions,
|
click: browserCommands.openOptions,
|
||||||
},
|
},
|
||||||
|
}, ext.installType === 'development' && {
|
||||||
'reload': {
|
'reload': {
|
||||||
presentIf: async () => (await browser.management.getSelf()).installType === 'development',
|
|
||||||
title: 'reload',
|
title: 'reload',
|
||||||
click: browserCommands.reload,
|
click: browserCommands.reload,
|
||||||
},
|
},
|
||||||
|
}, CHROME && {
|
||||||
'editor.contextDelete': {
|
'editor.contextDelete': {
|
||||||
presentIf: () => !FIREFOX && prefs.get('editor.contextDelete'),
|
|
||||||
title: 'editDeleteText',
|
title: 'editDeleteText',
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
contexts: ['editable'],
|
contexts: ['editable'],
|
||||||
|
@ -38,39 +38,24 @@
|
||||||
.catch(msg.ignoreError);
|
.catch(msg.ignoreError);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
||||||
// "Delete" item in context menu for browsers that don't have it
|
|
||||||
if (CHROME) {
|
|
||||||
prefs.__defaults['editor.contextDelete'] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const keys = Object.keys(contextMenus);
|
|
||||||
prefs.subscribe(keys.filter(id => typeof prefs.defaults[id] === 'boolean'),
|
|
||||||
CHROME >= 62 && CHROME <= 64 ? toggleCheckmarkBugged : toggleCheckmark);
|
|
||||||
prefs.subscribe(keys.filter(id => contextMenus[id].presentIf && prefs.knownKeys.includes(id)),
|
|
||||||
togglePresence);
|
|
||||||
|
|
||||||
createContextMenus(keys);
|
|
||||||
|
|
||||||
|
createContextMenus(Object.keys(contextMenus));
|
||||||
chrome.contextMenus.onClicked.addListener((info, tab) =>
|
chrome.contextMenus.onClicked.addListener((info, tab) =>
|
||||||
contextMenus[info.menuItemId].click(info, tab));
|
contextMenus[info.menuItemId].click(info, tab));
|
||||||
|
|
||||||
async function createContextMenus(ids) {
|
function createContextMenus(ids) {
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
let item = contextMenus[id];
|
const item = Object.assign({id, contexts: ['browser_action']}, contextMenus[id]);
|
||||||
if (item.presentIf && !await item.presentIf()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
item = Object.assign({id}, item);
|
|
||||||
delete item.presentIf;
|
|
||||||
item.title = chrome.i18n.getMessage(item.title);
|
item.title = chrome.i18n.getMessage(item.title);
|
||||||
if (!item.type && typeof prefs.defaults[id] === 'boolean') {
|
if (typeof prefs.defaults[id] === 'boolean') {
|
||||||
|
if (item.type) {
|
||||||
|
prefs.subscribe(id, togglePresence);
|
||||||
|
} else {
|
||||||
item.type = 'checkbox';
|
item.type = 'checkbox';
|
||||||
item.checked = prefs.get(id);
|
item.checked = prefs.get(id);
|
||||||
|
prefs.subscribe(id, CHROME >= 62 && CHROME <= 64 ? toggleCheckmarkBugged : toggleCheckmark);
|
||||||
}
|
}
|
||||||
if (!item.contexts) {
|
|
||||||
item.contexts = ['browser_action'];
|
|
||||||
}
|
}
|
||||||
delete item.click;
|
delete item.click;
|
||||||
chrome.contextMenus.create(item, ignoreChromeError);
|
chrome.contextMenus.create(item, ignoreChromeError);
|
||||||
|
@ -87,6 +72,11 @@
|
||||||
createContextMenus([id]);
|
createContextMenus([id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param {chrome.contextMenus.OnClickData} info */
|
||||||
|
function togglePref(info) {
|
||||||
|
prefs.set(info.menuItemId, info.checked);
|
||||||
|
}
|
||||||
|
|
||||||
function togglePresence(id, checked) {
|
function togglePresence(id, checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
createContextMenus([id]);
|
createContextMenus([id]);
|
||||||
|
@ -94,4 +84,4 @@
|
||||||
chrome.contextMenus.remove(id, ignoreChromeError);
|
chrome.contextMenus.remove(id, ignoreChromeError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})();
|
});
|
||||||
|
|
|
@ -96,7 +96,7 @@
|
||||||
'editor.autoCloseBrackets': true, // auto-add a closing pair when typing an opening one of ()[]{}''""
|
'editor.autoCloseBrackets': true, // auto-add a closing pair when typing an opening one of ()[]{}''""
|
||||||
'editor.autocompleteOnTyping': false, // show autocomplete dropdown on typing a word token
|
'editor.autocompleteOnTyping': false, // show autocomplete dropdown on typing a word token
|
||||||
// "Delete" item in context menu for browsers that don't have it
|
// "Delete" item in context menu for browsers that don't have it
|
||||||
'editor.contextDelete': null,
|
'editor.contextDelete': false,
|
||||||
'editor.selectByTokens': true,
|
'editor.selectByTokens': true,
|
||||||
|
|
||||||
'editor.appliesToLineWidget': true, // show applies-to line widget on the editor
|
'editor.appliesToLineWidget': true, // show applies-to line widget on the editor
|
||||||
|
|
Loading…
Reference in New Issue
Block a user