SYNTAX ERROR is not so often now

This commit is contained in:
serso 2011-10-27 10:50:18 +04:00
parent 2754e11c1c
commit 08ee781b07
2 changed files with 17 additions and 6 deletions

View File

@ -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>

View File

@ -153,11 +153,14 @@ 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());
pendingOperation.setObject(null);
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);
}
}
}
}
@ -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);
display.setText(result.getResult());
display.setJsclOperation(result.getUserOperation());
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) {