private async Task Delete() { // Do nothing if there is currently no input if (!Input.Any()) { return; } // Clear everything if required if (_nextStroke != NextInput.DoNothing) { Input.Clear(); _nextStroke = NextInput.DoNothing; return; } // Else only delete 1 section, the selected one var indexOfSelectedInputSection = Input.IndexOf(_selectedInputSection); Input.RemoveAt(indexOfSelectedInputSection); _selectedInputSection = indexOfSelectedInputSection == 0 ? Input.Any() ? Input.First() : null : Input[indexOfSelectedInputSection - 1]; if (_selectedInputSection != null) { _selectedInputSection.IsSelected = true; } // Prevent UI glitches. await Task.Delay(100); }
/// <summary> /// Checks if input is compatible and address accordingly (Exception, Empty or Fail) /// </summary> /// <returns>False if stack in fail state and needs to end, true otherwise</returns> public bool AssertCurrentBlockInput() { if (CurrentBlockSpec.InputType != null) { try { NextInput = NextInput.ConvertTo(CurrentBlockSpec.InputType); } catch (Exception e) { if (options.IncompatibleInputTypeBehaviour == IncompatibleInputTypeBehaviour.Exception) { throw new OperationStackExecutionException("Invalid input coming from " + PreviousBlockSpec?.Tag ?? "unknwon" + " block and going into " + CurrentBlockSpec.Tag + " block. Exception was " + e.Message); } else if (options.IncompatibleInputTypeBehaviour == IncompatibleInputTypeBehaviour.AssumeEmpty) { NextInput = Emptyable.Empty; } else if (options.IncompatibleInputTypeBehaviour == IncompatibleInputTypeBehaviour.Fail) { IsFail = true; var error = ExceptionErrorBuilder <TOperationEvent> .Build(new OperationStackExecutionException("Invalid input coming from " + PreviousBlockSpec?.Tag ?? "unknwon" + " block and going into " + CurrentBlockSpec.Tag + " block. Exception was " + e.Message)); StackTrace.Add(new BlockTraceResult <TOperationEvent>(CurrentBlockSpec.Tag, error, NextInput)); return(false); } } } return(true); }
private async Task Decimal() { if (_nextStroke != NextInput.DoNothing) { ClearAndAddInputSection(DecimalSeparator); _nextStroke = NextInput.DoNothing; } else { await AddInputSection(DecimalSeparator); } }
private async Task VariableStorage(string symbol) { if (_nextStroke != NextInput.DoNothing) { ClearAndAddInputSection(symbol); _nextStroke = NextInput.DoNothing; } else { await AddInputSection(symbol); } }
private async Task Parenthesis(string parenthesis) { if (_nextStroke != NextInput.DoNothing) { ClearAndAddInputSection(parenthesis); _nextStroke = NextInput.DoNothing; } else { await AddInputSection(parenthesis); } }
private async Task UnaryOperator(string symbol) { if (_nextStroke != NextInput.DoNothing) { ClearAndAddInputSection(symbol); _nextStroke = NextInput.DoNothing; } else { await AddInputSection(symbol); } }
private async Task Number(string number) { if (_nextStroke == NextInput.ClearAtAny || _nextStroke == NextInput.ClearAtNumber) { ClearAndAddInputSection(number); _nextStroke = NextInput.DoNothing; } else { await AddInputSection(number); } }
private async Task BinaryOperator(string symbol) { if (_nextStroke == NextInput.ClearAtAny) { ClearAndAddInputSection(symbol); _nextStroke = NextInput.DoNothing; } else if (_nextStroke == NextInput.ClearAtNumber) { ClearAndAddInputSection(LocalizedStrings.LastResultAbbreviation); await AddInputSection(symbol); _nextStroke = NextInput.DoNothing; } else { await AddInputSection(symbol); } }
/// <summary> /// Constructor with all inputs for this operator /// </summary> /// <param name="qsInput">The input query operators</param> public NAryOp(params Query[] qsInput) { Init(qsInput); nextInput = NextInputRoundRobin; rgStep = new Step[qsInput.Length]; rgSteplist = new StepList[qsInput.Length]; rgFinal = new Final[qsInput.Length]; rgPass = new Pass[qsInput.Length]; rgProp = new Prop[qsInput.Length]; rgKeep = new Keep[qsInput.Length]; rgeof = new bool[qsInput.Length]; for (int i = 0; i < qsInput.Length; i++) { rgStep[i] = StepTrivial; rgSteplist[i] = NAryStepListTrivial; rgFinal[i] = FinalTrivial; rgPass[i] = PassTrivial; rgProp[i] = PropTrivial; rgKeep[i] = KeepTrivial; rgeof[i] = false; } }
private async Task Calculate() { // Do nothing if there is no input if (!Input.Any()) { return; } // Clear input if there was no interaction after an error if (_nextStroke == NextInput.ClearAtAny) { Input.Clear(); _nextStroke = NextInput.DoNothing; return; } // Use previous input if it was a valid one and there was no interaction after calculating var input = _nextStroke == NextInput.ClearAtNumber ? _lastInput : Input.ToArray(); // Calculate and show corresponding result _isCalculating = true; _lastInput = input; var calculationResult = await Logic.Calculator.Instance.CalculateAsync(JoinInputSectionsIntoSingleString(input), _variableStorageValues); if (calculationResult != null) { // Show result if calculation was successful if (calculationResult.Successful) { var result = calculationResult.Result; if (TryFormatResult(result, out var resultText)) { AfterResult = true; ClearAndAddInputSection(resultText); _nextStroke = NextInput.ClearAtNumber; AddOrUpdateVariableStorage(LocalizedStrings.LastResultAbbreviation, result); _ = Settings.Instance.ManageNewResultAsync(resultText); } // Show error message if result could not be formatted else { ClearAndAddInputSection(LocalizedStrings.CalculationError); _nextStroke = NextInput.ClearAtAny; } } // Show error message if calculation was not successful else { ClearAndAddInputSection(calculationResult.ErrorMessage); _nextStroke = NextInput.ClearAtAny; } } // It has no reason to be a null object else { ClearAndAddInputSection(LocalizedStrings.UnexpectedError); _nextStroke = NextInput.ClearAtAny; } _isCalculating = false; }
private void Clear() { // Clear user input Input.Clear(); _nextStroke = NextInput.DoNothing; }