DeskCalc: fix mixup of key codes and labels

We must keep an untranslated version of the text for use with the
expression parser. Only the key label in the user interface should be
translated.

Fixes #15709.
This commit is contained in:
Adrien Destugues 2021-07-25 18:51:35 +02:00
parent 8df6e5c2a6
commit e9946b675c

View File

@ -1222,10 +1222,10 @@ CalcView::_ParseCalcDesc(const char** keypadDescription)
strlcpy(key->label, B_TRANSLATE_NOCOLLECT(p), sizeof(key->label)); strlcpy(key->label, B_TRANSLATE_NOCOLLECT(p), sizeof(key->label));
// set code // set code
if (strcmp(key->label, "=") == 0) if (strcmp(p, "=") == 0)
strlcpy(key->code, "\n", sizeof(key->code)); strlcpy(key->code, "\n", sizeof(key->code));
else else
strlcpy(key->code, key->label, sizeof(key->code)); strlcpy(key->code, p, sizeof(key->code));
// set keymap // set keymap
if (strlen(key->label) == 1) if (strlen(key->label) == 1)
@ -1254,37 +1254,35 @@ CalcView::_PressKey(int key)
assert(key < (fRows * fColumns)); assert(key < (fRows * fColumns));
assert(key >= 0); assert(key >= 0);
if (strcmp(fKeypad[key].label, B_TRANSLATE_COMMENT("BS", if (strcmp(fKeypad[key].code, "BS") == 0) {
"Key label, 'BS' means backspace")) == 0) {
// BS means backspace // BS means backspace
fExpressionTextView->BackSpace(); fExpressionTextView->BackSpace();
} else if (strcmp(fKeypad[key].label, B_TRANSLATE_COMMENT("C", } else if (strcmp(fKeypad[key].code, "C") == 0) {
"Key label, 'C' means clear")) == 0) {
// C means clear // C means clear
fExpressionTextView->Clear(); fExpressionTextView->Clear();
} else if (strcmp(fKeypad[key].label, B_TRANSLATE("acos")) == 0 } else if (strcmp(fKeypad[key].code, "acos") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("asin")) == 0 || strcmp(fKeypad[key].code, "asin") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("atan")) == 0 || strcmp(fKeypad[key].code, "atan") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("cbrt")) == 0 || strcmp(fKeypad[key].code, "cbrt") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("ceil")) == 0 || strcmp(fKeypad[key].code, "ceil") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("cos")) == 0 || strcmp(fKeypad[key].code, "cos") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("cosh")) == 0 || strcmp(fKeypad[key].code, "cosh") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("exp")) == 0 || strcmp(fKeypad[key].code, "exp") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("floor")) == 0 || strcmp(fKeypad[key].code, "floor") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("log")) == 0 || strcmp(fKeypad[key].code, "log") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("ln")) == 0 || strcmp(fKeypad[key].code, "ln") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("sin")) == 0 || strcmp(fKeypad[key].code, "sin") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("sinh")) == 0 || strcmp(fKeypad[key].code, "sinh") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("sqrt")) == 0 || strcmp(fKeypad[key].code, "sqrt") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("tan")) == 0 || strcmp(fKeypad[key].code, "tan") == 0
|| strcmp(fKeypad[key].label, B_TRANSLATE("tanh")) == 0) { || strcmp(fKeypad[key].code, "tanh") == 0) {
int32 labelLen = strlen(fKeypad[key].label); int32 labelLen = strlen(fKeypad[key].code);
int32 startSelection = 0; int32 startSelection = 0;
int32 endSelection = 0; int32 endSelection = 0;
fExpressionTextView->GetSelection(&startSelection, &endSelection); fExpressionTextView->GetSelection(&startSelection, &endSelection);
if (endSelection > startSelection) { if (endSelection > startSelection) {
// There is selected text, put it inbetween the parens // There is selected text, put it inbetween the parens
fExpressionTextView->Insert(startSelection, fKeypad[key].label, fExpressionTextView->Insert(startSelection, fKeypad[key].code,
labelLen); labelLen);
fExpressionTextView->Insert(startSelection + labelLen, "(", 1); fExpressionTextView->Insert(startSelection + labelLen, "(", 1);
fExpressionTextView->Insert(endSelection + labelLen + 1, ")", 1); fExpressionTextView->Insert(endSelection + labelLen + 1, ")", 1);
@ -1295,7 +1293,7 @@ CalcView::_PressKey(int key)
endSelection + labelLen + 2, endSelection + labelLen + 2); endSelection + labelLen + 2, endSelection + labelLen + 2);
} else { } else {
// There is no selected text, insert at the cursor location // There is no selected text, insert at the cursor location
fExpressionTextView->Insert(fKeypad[key].label); fExpressionTextView->Insert(fKeypad[key].code);
fExpressionTextView->Insert("()"); fExpressionTextView->Insert("()");
// Put the cursor inside the parens so you can enter an argument // Put the cursor inside the parens so you can enter an argument
// Need to cast to BTextView because Select() is protected // Need to cast to BTextView because Select() is protected