summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2019-11-17 15:38:05 +0100
committerTamás Zolnai <tamas.zolnai@collabora.com>2019-11-24 14:12:30 +0100
commit7041d5c5b035007f09f092d15b40aae4731803a6 (patch)
tree0bdf006cbe204b0be53f64078b86a0dbf7ccbdb4
parent08aa7d9149bea918386a3dc4475e130bfe93917e (diff)
Update conext menu code to handle Spelling Popup
* Use unique IDs for sub menus. * Handle uno command's parameter. * When there is any parameter, we use the menu text. * Avoid to enable FontDialog on other conext menus * Introduce the command ".uno:None" to indicate that the menu item can't be executed. * Whitelisted spelling context menu's uno commands. * Add a black list in unocommands.py to list those uno commands which have no text in xcu file. In this case, we can use the text sent in the menu structure. Change-Id: Ie84fcb7d6c7a2f4cd50c666dbcd8c77cf42731de Reviewed-on: https://gerrit.libreoffice.org/83606 Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com> Tested-by: Tamás Zolnai <tamas.zolnai@collabora.com>
-rw-r--r--loleaflet/src/control/Control.ContextMenu.js30
-rw-r--r--loleaflet/src/unocommands.js8
-rwxr-xr-xscripts/unocommands.py6
3 files changed, 39 insertions, 5 deletions
diff --git a/loleaflet/src/control/Control.ContextMenu.js b/loleaflet/src/control/Control.ContextMenu.js
index bd5e3c400..00f5f959d 100644
--- a/loleaflet/src/control/Control.ContextMenu.js
+++ b/loleaflet/src/control/Control.ContextMenu.js
@@ -36,7 +36,9 @@ L.Control.ContextMenu = L.Control.extend({
'DeleteRows', 'DeleteColumns', 'DeleteTable',
'MergeCells', 'SetOptimalColumnWidth', 'SetOptimalRowHeight',
'UpdateCurIndex','RemoveTableOf',
- 'ReplyComment', 'DeleteComment', 'DeleteAuthor', 'DeleteAllNotes'],
+ 'ReplyComment', 'DeleteComment', 'DeleteAuthor', 'DeleteAllNotes',
+ 'SpellingAndGrammarDialog', 'LanguageStatus', 'FontDialog', 'FontDialogForParagraph',
+ 'SpellCheckIgnore', 'SpellCheckIgnoreAll', 'SpellCheckApplySuggestion'],
spreadsheet: ['MergeCells', 'SplitCell', 'RecalcPivotTable', 'FormatCellDialog',
'ShowNote', 'DeleteNote'],
@@ -116,6 +118,7 @@ L.Control.ContextMenu = L.Control.extend({
var docType = this._map.getDocType();
var contextMenu = {};
var sepIdx = 1, itemName;
+ var subMenuIdx = 1;
var isLastItemText = false;
for (var idx in obj.menu) {
var item = obj.menu[idx];
@@ -133,7 +136,20 @@ L.Control.ContextMenu = L.Control.extend({
// Only show whitelisted items
// Command name (excluding '.uno:') starts from index = 5
var commandName = item.command.substring(5);
- if (this.options.whitelist.general.indexOf(commandName) === -1 &&
+
+ // Command might have paramateres (e.g. .uno:SpellCheckIgnore?Type:string=Grammar)
+ var hasParam = false;
+ if (commandName.indexOf('?')!== -1) {
+ commandName = commandName.substring(0, commandName.indexOf('?'));
+ hasParam = true;
+ }
+
+ // We use a special character dialog in spelling context menu with a parameter
+ if (commandName === 'FontDialog' && !hasParam)
+ continue;
+
+ if (commandName !== 'None' &&
+ this.options.whitelist.general.indexOf(commandName) === -1 &&
!(docType === 'text' && this.options.whitelist.text.indexOf(commandName) !== -1) &&
!(docType === 'spreadsheet' && this.options.whitelist.spreadsheet.indexOf(commandName) !== -1) &&
!(docType === 'presentation' && this.options.whitelist.presentation.indexOf(commandName) !== -1) &&
@@ -146,8 +162,12 @@ L.Control.ContextMenu = L.Control.extend({
item.command = '.uno:HideNote';
}
- // Get the translated text associated with the command
- itemName = _UNO(item.command, docType, true);
+ if (hasParam || commandName === 'None' || commandName === 'FontDialogForParagraph') {
+ itemName = window.removeAccessKey(item.text);
+ } else {
+ // Get the translated text associated with the command
+ itemName = _UNO(item.command, docType, true);
+ }
contextMenu[item.command] = {
// Using 'click' and <a href='#' is vital for copy/paste security context.
@@ -178,7 +198,7 @@ L.Control.ContextMenu = L.Control.extend({
continue;
}
- contextMenu[item.command] = {
+ contextMenu['submenu' + subMenuIdx++] = {
name: _(itemName).replace(/\(~[A-Za-z]\)/, '').replace('~', ''),
items: submenu
};
diff --git a/loleaflet/src/unocommands.js b/loleaflet/src/unocommands.js
index f6fcc3e6c..deb7e70b0 100644
--- a/loleaflet/src/unocommands.js
+++ b/loleaflet/src/unocommands.js
@@ -154,6 +154,7 @@ var unoCommandsArray = {
JumpUpThisLevel:{text:{menu:_('To Previous Paragraph in Level'),},},
JustifyPara:{global:{menu:_('Justified'),},},
LanguageMenu:{global:{menu:_('Language'),},},
+ LanguageStatus:{global:{menu:_('Language Status'),},},
LayoutStatus:{presentation:{menu:_('Layout'),},},
LeftPara:{global:{context:_('Align Left'),menu:_('Left'),},},
MergeCells:{presentation:{menu:_('Merge Cells'),},spreadsheet:{menu:_('Merge Cells'),},text:{menu:_('Merge Cells'),},},
@@ -241,6 +242,9 @@ var unoCommandsArray = {
SpacePara1:{global:{menu:_('Line Spacing: 1'),},},
SpacePara15:{global:{menu:_('Line Spacing: 1.5'),},},
SpacePara2:{global:{menu:_('Line Spacing: 2'),},},
+ SpellCheckApplySuggestion:{global:{menu:_('Apply Suggestion'),},},
+ SpellCheckIgnore:{global:{menu:_('Ignore'),},},
+ SpellCheckIgnoreAll:{global:{menu:_('IgnoreAll'),},},
SpellDialog:{global:{menu:_('~Spelling...'),},},
SpellOnline:{global:{menu:_('~Automatic Spell Checking'),},},
SpellingAndGrammarDialog:{global:{menu:_('~Spelling...'),},},
@@ -311,6 +315,10 @@ window._UNO = function(string, component, isContext) {
}
}
+ return this.removeAccessKey(text);
+}
+
+window.removeAccessKey = function(text) {
// Remove access key markers from translated strings
// 1. access key in parenthesis in case of non-latin scripts
text = text.replace(/\(~[A-Za-z]\)/, '');
diff --git a/scripts/unocommands.py b/scripts/unocommands.py
index e4dc45ef4..59aa19d84 100755
--- a/scripts/unocommands.py
+++ b/scripts/unocommands.py
@@ -86,6 +86,7 @@ def extractMenuCommands(path):
# Extract all the uno commands we are using in the Online context menu
def extractContextCommands(path):
+ commandsToIgnore = ["FontDialogForParagraph"]
commands = []
# extract from the comments whitelist
@@ -114,6 +115,7 @@ def extractContextCommands(path):
if line.find("_UNO(") >= 0:
commands += commandFromMenuLine(line)
+ commands = [command for command in commands if command not in commandsToIgnore]
# may the list unique
return set(commands)
@@ -242,6 +244,10 @@ window._UNO = function(string, component, isContext) {
\t\t}
\t}
+\treturn this.removeAccessKey(text);
+}
+
+window.removeAccessKey = function(text) {
\t// Remove access key markers from translated strings
\t// 1. access key in parenthesis in case of non-latin scripts
\ttext = text.replace(/\(~[A-Za-z]\)/, '');