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

Localize add-on & add features for menu display #17

Merged
merged 35 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9ea02aa
feat: localize options page
rugk Nov 28, 2020
e09ba85
refactor: minor changes recommend by eslint
rugk Nov 28, 2020
c101989
i18n: put menu strings into en.json
rugk Dec 2, 2020
cb6c3ee
refactor: one line per item
rugk Dec 2, 2020
b8307af
refactor: font character
rugk Dec 2, 2020
3aeec08
refactor: make it use the localisation, actually
rugk Feb 28, 2021
e88963e
chore: unify style
rugk Feb 28, 2021
bc236ce
refactor: use prefix to differenciate casing and fonts
rugk Feb 28, 2021
b10ecc5
refactor: use prefix when creating IDs
rugk Feb 28, 2021
a8fedf1
refactor: simplify creation of menu
rugk Feb 28, 2021
5cc97d8
refactor: extract own context menu module
rugk Feb 28, 2021
bb05270
style: rename some stuff
rugk Feb 28, 2021
3953056
refactor: move modules not needed anywhere else to single place
rugk Feb 28, 2021
e574f0c
refactor: rename and remove duplicate code
rugk Feb 28, 2021
4f547bc
translation: add German translations for context menu entries
rugk Feb 28, 2021
dc87791
translation: remove duplicate entry
rugk Feb 28, 2021
d280858
fix(options): fix options loading
rugk Feb 28, 2021
f544202
fix: do not add suberflous separators
rugk Feb 28, 2021
bc68386
feat: allow showing the plain tzext of a transformation
rugk Feb 28, 2021
a2cb769
style: fix order of translation file keys
rugk Feb 28, 2021
f582a72
translations: fix German translation examples and add guides
rugk Feb 28, 2021
6be555e
wrong way getting selection based on permission error
rugk Feb 28, 2021
8f1bbd7
Revert "wrong way getting selection based on permission error"
rugk Feb 28, 2021
3a22aab
feat(): add live preview feature
rugk Feb 28, 2021
8f59b28
feat: do not show menu if no text is selected
rugk Feb 28, 2021
6466b50
feat: add performance limit
rugk Feb 28, 2021
cb5485a
Merge branch 'main' into localisationTry2
rugk Feb 28, 2021
1aa2da2
style: fix style/EsLint errors
rugk Mar 2, 2021
aacb819
Hide incompatible setting with Chrome/ium
rugk Mar 2, 2021
675b4e0
style: eslint fix file
rugk Mar 9, 2021
aed6c40
fix(ContextMenu): refactor context menu definition
rugk Mar 9, 2021
34b79d1
fix: show option in Thunderbird, not only Firefox
rugk Mar 9, 2021
6e04f89
doc: adjust function descriptions
rugk Mar 9, 2021
a48a61c
fix: add seperator
rugk Mar 11, 2021
56a2818
chore: re-add bad icon removal done for testing
rugk Mar 11, 2021
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
44 changes: 29 additions & 15 deletions src/background/modules/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,36 @@ async function handleMenuShown(info) {
* @returns {void}
*/
function buildMenu(unicodeFontSettings, exampleText = null, refreshMenu = false) {
let addedEntries = false;
for (const transformationId of menuStructure) {
if (unicodeFontSettings.changeFont) {
addMenuItems(menuStructure[TRANSFORMATION_TYPE.FONT], unicodeFontSettings, exampleText, refreshMenu);
}
if (unicodeFontSettings.changeFont &&
unicodeFontSettings.changeCase &&
!refreshMenu) {
menus.create({
id: "seperator-case-font",
type: "separator",
contexts: ["editable"]
});
}
if (unicodeFontSettings.changeCase) {
addMenuItems(menuStructure[TRANSFORMATION_TYPE.CASING], unicodeFontSettings, exampleText, refreshMenu);
}
}

/**
* Add Unicode menu items.
*
* @param {string[]} menuItems
* @param {Object} [unicodeFontSettings]
* @param {string?} [exampleText=null]
* @param {bool?} [refreshMenu=false]
* @returns {void}
*/
function addMenuItems(menuItems, unicodeFontSettings = lastCachedUnicodeFontSettings, exampleText = null, refreshMenu = false) {
for (const transformationId of menuItems) {
if (transformationId === SEPARATOR_ID) {
if (!addedEntries || refreshMenu) {
if (refreshMenu) {
continue;
}

Expand All @@ -99,16 +125,6 @@ function buildMenu(unicodeFontSettings, exampleText = null, refreshMenu = false)
continue;
}

const transformationType = UnicodeTransformationHandler.getTransformationType(transformationId);
if (transformationType === TRANSFORMATION_TYPE.CASING &&
!unicodeFontSettings.changeCase) {
continue;
}
if (transformationType === TRANSFORMATION_TYPE.FONT &&
!unicodeFontSettings.changeFont) {
continue;
}

const translatedMenuText = browser.i18n.getMessage(transformationId);
let textToBeTransformed = translatedMenuText;
if (unicodeFontSettings.livePreview && exampleText) {
Expand All @@ -132,9 +148,7 @@ function buildMenu(unicodeFontSettings, exampleText = null, refreshMenu = false)
"title": menuText,
"contexts": ["editable"],
});

}
addedEntries = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/modules/AutomaticSettings
66 changes: 34 additions & 32 deletions src/common/modules/data/Fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,41 @@ export const FONT_ID_PREFIX = "menuFont";
*
* @public
* @const
* @type {Object.<string>}
* @type {Object.<Symbol, string[]>}
*/
export const menuStructure = Object.freeze([
`${FONT_ID_PREFIX}Superscript`,
`${FONT_ID_PREFIX}SmallCaps`,
`${FONT_ID_PREFIX}AllSmallCaps`,
`${FONT_ID_PREFIX}Unicase`,
SEPARATOR_ID,
`${FONT_ID_PREFIX}SerifBold`,
`${FONT_ID_PREFIX}SerifItalic`,
`${FONT_ID_PREFIX}SerifBoldItalic`,
`${FONT_ID_PREFIX}SansSerif`,
`${FONT_ID_PREFIX}SansSerifBold`,
`${FONT_ID_PREFIX}SansSerifItalic`,
`${FONT_ID_PREFIX}SansSerifBoldItalic`,
`${FONT_ID_PREFIX}Script`,
`${FONT_ID_PREFIX}ScriptBold`,
`${FONT_ID_PREFIX}ScriptFraktur`,
`${FONT_ID_PREFIX}FrakturBold`,
`${FONT_ID_PREFIX}Monospace`,
`${FONT_ID_PREFIX}DoubleStruck`,
SEPARATOR_ID,
`${FONT_ID_PREFIX}Circled`,
`${FONT_ID_PREFIX}CircledBlack`,
`${FONT_ID_PREFIX}Squared`,
`${FONT_ID_PREFIX}SquaredBlack`,
`${FONT_ID_PREFIX}Fullwidth`,
SEPARATOR_ID,
`${CASE_ID_PREFIX}Lowercase`,
`${CASE_ID_PREFIX}Uppercase`,
`${CASE_ID_PREFIX}CapitalizeEachWord`,
`${CASE_ID_PREFIX}ToggleCase`
]);
export const menuStructure = Object.freeze({
[TRANSFORMATION_TYPE.FONT]: [
`${FONT_ID_PREFIX}Superscript`,
`${FONT_ID_PREFIX}SmallCaps`,
`${FONT_ID_PREFIX}AllSmallCaps`,
`${FONT_ID_PREFIX}Unicase`,
SEPARATOR_ID,
`${FONT_ID_PREFIX}SerifBold`,
`${FONT_ID_PREFIX}SerifItalic`,
`${FONT_ID_PREFIX}SerifBoldItalic`,
`${FONT_ID_PREFIX}SansSerif`,
`${FONT_ID_PREFIX}SansSerifBold`,
`${FONT_ID_PREFIX}SansSerifItalic`,
`${FONT_ID_PREFIX}SansSerifBoldItalic`,
`${FONT_ID_PREFIX}Script`,
`${FONT_ID_PREFIX}ScriptBold`,
`${FONT_ID_PREFIX}ScriptFraktur`,
`${FONT_ID_PREFIX}FrakturBold`,
`${FONT_ID_PREFIX}Monospace`,
`${FONT_ID_PREFIX}DoubleStruck`,
`${FONT_ID_PREFIX}Circled`,
rugk marked this conversation as resolved.
Show resolved Hide resolved
`${FONT_ID_PREFIX}CircledBlack`,
`${FONT_ID_PREFIX}Squared`,
`${FONT_ID_PREFIX}SquaredBlack`,
`${FONT_ID_PREFIX}Fullwidth`,
],
[TRANSFORMATION_TYPE.CASING]: [
`${CASE_ID_PREFIX}Lowercase`,
`${CASE_ID_PREFIX}Uppercase`,
`${CASE_ID_PREFIX}CapitalizeEachWord`,
`${CASE_ID_PREFIX}ToggleCase`
]
});

/**
* Unicode fonts
Expand Down