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_name">Calculator++</string>
|
||||||
<string name="c_app_icon_name">Calc++</string>
|
<string name="c_app_icon_name">Calc++</string>
|
||||||
<string name="c_app_settings">Settings</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_result_copied">Result copied to clipboard!</string>
|
||||||
<string name="c_settings">Settings</string>
|
<string name="c_settings">Settings</string>
|
||||||
<string name="c_help">Help</string>
|
<string name="c_help">Help</string>
|
||||||
|
@ -153,14 +153,17 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
|
|||||||
//lock all operations with history
|
//lock all operations with history
|
||||||
if (pendingOperation.getObject() == this) {
|
if (pendingOperation.getObject() == this) {
|
||||||
// actually nothing shall be logged while text operations are done
|
// actually nothing shall be logged while text operations are done
|
||||||
evaluate(expression, operation);
|
evaluate(expression, operation, this);
|
||||||
|
|
||||||
historyState.setDisplayState(getCurrentHistoryState().getDisplayState());
|
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);
|
pendingOperation.setObject(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (delayEvaluate) {
|
if (delayEvaluate) {
|
||||||
@ -182,13 +185,21 @@ public enum CalculatorModel implements CursorControl, HistoryControl<CalculatorH
|
|||||||
evaluate(false, this.editor.getText().toString(), JsclOperation.simplify);
|
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)) {
|
if (!StringUtils.isEmpty(expression)) {
|
||||||
try {
|
try {
|
||||||
Log.d(CalculatorModel.class.getName(), "Trying to evaluate '" + operation + "': " + expression /*+ StringUtils.fromStackTrace(Thread.currentThread().getStackTrace())*/);
|
Log.d(CalculatorModel.class.getName(), "Trying to evaluate '" + operation + "': " + expression /*+ StringUtils.fromStackTrace(Thread.currentThread().getStackTrace())*/);
|
||||||
final CalculatorEngine.Result result = calculatorEngine.evaluate(operation, expression);
|
final CalculatorEngine.Result result = calculatorEngine.evaluate(operation, expression);
|
||||||
|
if (currentRunner == pendingOperation.getObject()
|
||||||
|
&& expression.equals(this.editor.getText().toString())) {
|
||||||
display.setText(result.getResult());
|
display.setText(result.getResult());
|
||||||
display.setJsclOperation(result.getUserOperation());
|
display.setJsclOperation(result.getUserOperation());
|
||||||
|
} else {
|
||||||
|
display.setText("");
|
||||||
|
}
|
||||||
} catch (EvalError e) {
|
} catch (EvalError e) {
|
||||||
handleEvaluationException(expression, display, operation, e);
|
handleEvaluationException(expression, display, operation, e);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user