SYNTAX ERROR is not so often now
This commit is contained in:
parent
0b0d07be86
commit
4fdab42521
@ -3,7 +3,7 @@
|
||||
<string name="c_app_name">Calculator++</string>
|
||||
<string name="c_app_icon_name">Calc++</string>
|
||||
<string name="c_app_settings">Settings</string>
|
||||
<string name="c_syntax_error">Syntax error</string>
|
||||
<string name="c_syntax_error">Error</string>
|
||||
<string name="c_result_copied">Result copied to clipboard!</string>
|
||||
<string name="c_settings">Settings</string>
|
||||
<string name="c_help">Help</string>
|
||||
|
@ -153,14 +153,17 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
|
||||
//lock all operations with history
|
||||
if (pendingOperation.getObject() == this) {
|
||||
// actually nothing shall be logged while text operations are done
|
||||
evaluate(expression, operation);
|
||||
evaluate(expression, operation, this);
|
||||
|
||||
historyState.setDisplayState(getCurrentHistoryState().getDisplayState());
|
||||
|
||||
if (pendingOperation.getObject() == this) {
|
||||
// todo serso: of course there is small probability that someone will set pendingOperation after if statement but before .setObject(null)
|
||||
pendingOperation.setObject(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (delayEvaluate) {
|
||||
@ -182,13 +185,21 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
|
||||
evaluate(false, this.editor.getText().toString(), JsclOperation.simplify);
|
||||
}
|
||||
|
||||
private void evaluate(@Nullable final String expression, @NotNull JsclOperation operation) {
|
||||
private void evaluate(@Nullable final String expression,
|
||||
@NotNull JsclOperation operation,
|
||||
@NotNull Runnable currentRunner) {
|
||||
|
||||
if (!StringUtils.isEmpty(expression)) {
|
||||
try {
|
||||
Log.d(CalculatorModel.class.getName(), "Trying to evaluate '" + operation + "': " + expression /*+ StringUtils.fromStackTrace(Thread.currentThread().getStackTrace())*/);
|
||||
final CalculatorEngine.Result result = calculatorEngine.evaluate(operation, expression);
|
||||
if (currentRunner == pendingOperation.getObject()
|
||||
&& expression.equals(this.editor.getText().toString())) {
|
||||
display.setText(result.getResult());
|
||||
display.setJsclOperation(result.getUserOperation());
|
||||
} else {
|
||||
display.setText("");
|
||||
}
|
||||
} catch (EvalError e) {
|
||||
handleEvaluationException(expression, display, operation, e);
|
||||
} catch (ParseException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user