public void Do () { Region.SetNeedToEvaluate (true); var parent = Region.Selection.SelectedToken.Parent; Token dividend; Token divisor; if (Region.Selection.SelectedToken is TextToken) { var textToken = Region.Selection.SelectedToken as TextToken; dividend = new TextToken () { Text = GetLeftString (textToken.Text) }; divisor = new TextToken () { Text = GetRightString (textToken.Text) }; } else { dividend = Region.Selection.SelectedToken; divisor = new TextToken (); } var fraction = new FractionToken (); parent.Replace (Region.Selection.SelectedToken, fraction); fraction.Dividend = dividend; fraction.Divisor = divisor; Region.Selection.SelectedToken = divisor; }
public ParenthesesToken () { child = BuildProperty<Token> ("Child"); child.DependencyPropertyValueChanged += HandleValueChanged; showCloseParentheses = BuildProperty<bool> ("ShowCloseParentheses"); Child = new TextToken (); }
public ExponentiationToken () { _base = BuildProperty<Token> ("Base"); _base.DependencyPropertyValueChanged += HandleValueChanged; power = BuildProperty<Token> ("Power"); power.DependencyPropertyValueChanged += HandleValueChanged; Base = new TextToken (); Power = new TextToken (); }
public FractionToken () { dividend = BuildProperty<Token> ("Dividend"); dividend.DependencyPropertyValueChanged += HandleValueChanged; divisor = BuildProperty<Token> ("Divisor"); divisor.DependencyPropertyValueChanged += HandleValueChanged; Dividend = new TextToken (); Divisor = new TextToken (); }
public void Do () { if (Region.Root.Tokens.OfType<AssignmentToken> ().Any () || Region.Root.Tokens.OfType<ResultToken> ().Any ()) return; var token = new AssignmentToken (); var textToken = new TextToken (); Region.Root.Add (token); Region.Root.Add (textToken); Region.Selection.SelectedToken = textToken; }
public void Do () { Region.SetNeedToEvaluate (true); var parent = Region.Selection.SelectedToken.Parent; Token _base; Token power; if (Region.Selection.SelectedToken is TextToken) { var textToken = Region.Selection.SelectedToken as TextToken; _base = new TextToken () { Text = GetLeftString (textToken.Text) }; power = new TextToken () { Text = GetRightString (textToken.Text) }; } else { if (Region.Selection.SelectedToken is FractionToken) { var fraction = Region.Selection.SelectedToken; var parentheses = new ParenthesesToken (); parentheses.ShowCloseParentheses = true; parent.Replace (fraction, parentheses); var container = new HBoxToken (); parentheses.Child = container; container.Add (fraction); _base = parentheses; Region.Selection.SelectedToken = parentheses; } else _base = Region.Selection.SelectedToken; power = new TextToken (); } var exponentiation = new ExponentiationToken (); parent.Replace (Region.Selection.SelectedToken, exponentiation); exponentiation.Base = _base; exponentiation.Power = power; Region.Selection.SelectedToken = power; }
public void Do () { Region.SetNeedToEvaluate (true); var right = new TextToken (); if (Region.Selection.SelectedToken is TextToken) { var textToken = Region.Selection.SelectedToken as TextToken; var parent = GetHBoxToken (textToken); var left = new TextToken () { Text = GetLeftString (textToken.Text) }; right.Text = GetRightString (textToken.Text); var index = parent.Tokens.IndexOf (textToken); parent.Tokens [index] = left; parent.Tokens.Insert (index + 1, Operation); parent.Tokens.Insert (index + 2, right); } else { var parent = GetHBoxToken (Region.Selection.SelectedToken); var index = parent.Tokens.IndexOf (Region.Selection.SelectedToken); if (Region.Selection.Type == SelectionType.Left) { parent.Tokens.Insert (index, Operation); parent.Tokens.Insert (index, right); } else { parent.Tokens.Insert (index + 1, Operation); parent.Tokens.Insert (index + 2, right); } } Region.Selection.SelectedToken = right; }
public MathRegionViewModel (DocumentViewModel document) { Document = document; x = BuildProperty<double> ("X"); y = BuildProperty<double> ("Y"); root = BuildProperty<HBoxToken> ("Root"); selection = BuildProperty<Selection> ("Selection"); insertCharacterCommand = BuildProperty<ICommand> ("InsertCharacterCommand"); insertCharacterCommand.Value = new DelegateCommand<Key> (o => new InsertCharacterAction (o, this).Do ()); plusCommand = BuildProperty<ICommand> ("PlusCommand"); plusCommand.Value = new DelegateCommand<object> (o => new PlusAction (this).Do ()); minusCommand = BuildProperty<ICommand> ("MinusCommand"); minusCommand.Value = new DelegateCommand<object> (o => new MinusAction (this).Do ()); multiplicationCommand = BuildProperty<ICommand> ("MultiplicationCommand"); multiplicationCommand.Value = new DelegateCommand<object> (o => new MultiplicationAction (this).Do ()); divideCommand = BuildProperty<ICommand> ("DivideCommand"); divideCommand.Value = new DelegateCommand<object> (o => new DivideAction (this).Do ()); assignmentCommand = BuildProperty<ICommand> ("AssignmentCommand"); assignmentCommand.Value = new DelegateCommand<object> (o => new AssignmentAction (this).Do ()); resultCommand = BuildProperty<ICommand> ("ResultCommand"); resultCommand.Value = new DelegateCommand<object> (o => new ResultAction (this).Do ()); leftCommand = BuildProperty<ICommand> ("LeftCommand"); leftCommand.Value = new DelegateCommand<object> (o => new LeftAction (this).Do ()); rightCommand = BuildProperty<ICommand> ("RightCommand"); rightCommand.Value = new DelegateCommand<object> (o => new RightAction (this).Do ()); evaluateCommand = BuildProperty<ICommand> ("EvaluateCommand"); evaluateCommand.Value = new DelegateCommand<object> (o => new EvaluateAction (this).Do ()); openBracketCommand = BuildProperty<ICommand> ("OpenBracketCommand"); openBracketCommand.Value = new DelegateCommand<object> (o => new OpenBracketAction (this).Do ()); closeBracketCommand = BuildProperty<ICommand> ("CloseBracketCommand"); closeBracketCommand.Value = new DelegateCommand<object> (o => new CloseBracketAction (this).Do ()); commaCommand = BuildProperty<ICommand> ("CommaCommand"); commaCommand.Value = new DelegateCommand<object> (o => new CommaAction (this).Do ()); exponentiationCommand = BuildProperty<ICommand> ("ExponentiationCommand"); exponentiationCommand.Value = new DelegateCommand<object> (o => new ExponentiationAction (this).Do ()); squareRootCommand = BuildProperty<ICommand> ("SquareRootCommand"); squareRootCommand.Value = new DelegateCommand<object> (o => new SquareRootAction (this).Do ()); absoluteCommand = BuildProperty<ICommand> ("AbsoluteCommand"); absoluteCommand.Value = new DelegateCommand<object> (o => new AbsoluteAction (this).Do ()); needToEvaluate = BuildProperty<bool> ("NeedToEvaluate"); needToEvaluate.DependencyPropertyValueChanged += HandleNeedToEvaluateChanged; Root = new HBoxToken (); Selection = new Selection (); var token = new TextToken (); Root.Add (token); Selection.SelectedToken = token; hasError = BuildProperty<bool> ("HasError"); }