SYNTAX ERROR is not so often now

This commit is contained in:
Sergey Solovyev 2011-10-27 10:50:18 +04:00
parent be94ef5452
commit 8da8c742d2
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_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>

View File

@ -153,11 +153,14 @@ 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());
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); 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);
display.setText(result.getResult()); if (currentRunner == pendingOperation.getObject()
display.setJsclOperation(result.getUserOperation()); && expression.equals(this.editor.getText().toString())) {
display.setText(result.getResult());
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) {