예제 #1
0
        public FormulaEditorViewModel()
        {
            KeyPressedCommand       = new RelayCommand <FormulaKeyEventArgs>(KeyPressedAction);
            ShowErrorPressedCommand = new RelayCommand(ShowErrorPressedAction, ShowErrorPressedCommand_CanExecute);
            UndoCommand             = new RelayCommand(UndoAction, UndoCommand_CanExecute);
            RedoCommand             = new RelayCommand(RedoAction, RedoCommand_CanExecute);
            SensorCommand           = new RelayCommand(SensorAction);
            CompleteTokenCommand    = new RelayCommand <int>(CompleteTokenAction);
            SaveCommand             = new RelayCommand(SaveAction);
            CancelCommand           = new RelayCommand(CancelAction);

            Messenger.Default.Register <GenericMessage <Sprite> >(this, ViewModelMessagingToken.CurrentSpriteChangedListener, SelectedSpriteChangedMessageAction);
            Messenger.Default.Register <GenericMessage <Program> >(this, ViewModelMessagingToken.CurrentProgramChangedListener, CurrentProgramChangedMessageAction);

            _editor.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == GetPropertyName(() => _editor.Formula))
                {
                    RaisePropertyChanged(() => Formula);
                }
                if (e.PropertyName == GetPropertyName(() => _editor.Tokens))
                {
                    RaisePropertyChanged(() => Tokens);
                }
                if (e.PropertyName == GetPropertyName(() => _editor.IsTokensEmpty))
                {
                    RaisePropertyChanged(() => IsTokensEmpty);
                }
                if (e.PropertyName == GetPropertyName(() => _editor.CaretIndex))
                {
                    RaisePropertyChanged(() => CaretIndex);
                }
                if (e.PropertyName == GetPropertyName(() => _editor.SelectionStart))
                {
                    RaisePropertyChanged(() => SelectionStart);
                }
                if (e.PropertyName == GetPropertyName(() => _editor.SelectionLength))
                {
                    RaisePropertyChanged(() => SelectionLength);
                }
                if (e.PropertyName == GetPropertyName(() => _editor.CanUndo))
                {
                    RaisePropertyChanged(() => CanUndo);
                    UndoCommand.RaiseCanExecuteChanged();
                }
                if (e.PropertyName == GetPropertyName(() => _editor.CanRedo))
                {
                    RaisePropertyChanged(() => CanRedo);
                    RedoCommand.RaiseCanExecuteChanged();
                }
                if (e.PropertyName == GetPropertyName(() => _editor.CanDelete))
                {
                    RaisePropertyChanged(() => CanDelete);
                }
                if (e.PropertyName == GetPropertyName(() => _editor.HasError))
                {
                    RaisePropertyChanged(() => HasError);
                    ShowErrorPressedCommand.RaiseCanExecuteChanged();
                }
                if (e.PropertyName == GetPropertyName(() => _editor.HasError))
                {
                    RaisePropertyChanged(() => CanEvaluate);
                }
                if (e.PropertyName == GetPropertyName(() => _editor.ParsingError))
                {
                    RaisePropertyChanged(() => ParsingError);
                }
            };

            _keyboardViewModel = ServiceLocator.ViewModelLocator.FormulaKeyboardViewModel;
            //_keyboardViewModel.PropertyChanged += (sender, e) =>
            //{
            //    if (e.PropertyName == GetPropertyName(() => _keyboardViewModel.IsAddLocalVariableButtonVisible)) RaisePropertyChanged(() => IsAddLocalVariableButtonVisible);
            //    if (e.PropertyName == GetPropertyName(() => _keyboardViewModel.IsAddGlobalVariableButtonVisible)) RaisePropertyChanged(() => IsAddGlobalVariableButtonVisible);
            //};
            _sensorsAreActive = false;
        }
        public FormulaEditorViewModel()
        {
            KeyPressedCommand = new RelayCommand<FormulaKeyEventArgs>(KeyPressedAction);
            ShowErrorPressedCommand = new RelayCommand(ShowErrorPressedAction, ShowErrorPressedCommand_CanExecute);
            UndoCommand = new RelayCommand(UndoAction, UndoCommand_CanExecute);
            RedoCommand = new RelayCommand(RedoAction, RedoCommand_CanExecute);
            SensorCommand = new RelayCommand(SensorAction);
            CompleteTokenCommand = new RelayCommand<int>(CompleteTokenAction);
            SaveCommand = new RelayCommand(SaveAction);
            CancelCommand = new RelayCommand(CancelAction);
            
            Messenger.Default.Register<GenericMessage<Sprite>>(this, ViewModelMessagingToken.CurrentSpriteChangedListener, SelectedSpriteChangedMessageAction);
            Messenger.Default.Register<GenericMessage<Program>>(this, ViewModelMessagingToken.CurrentProgramChangedListener, CurrentProgramChangedMessageAction);

            _editor.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == GetPropertyName(() => _editor.Formula)) RaisePropertyChanged(() => Formula);
                if (e.PropertyName == GetPropertyName(() => _editor.Tokens)) RaisePropertyChanged(() => Tokens);
                if (e.PropertyName == GetPropertyName(() => _editor.IsTokensEmpty)) RaisePropertyChanged(() => IsTokensEmpty);
                if (e.PropertyName == GetPropertyName(() => _editor.CaretIndex)) RaisePropertyChanged(() => CaretIndex);
                if (e.PropertyName == GetPropertyName(() => _editor.SelectionStart)) RaisePropertyChanged(() => SelectionStart);
                if (e.PropertyName == GetPropertyName(() => _editor.SelectionLength)) RaisePropertyChanged(() => SelectionLength);
                if (e.PropertyName == GetPropertyName(() => _editor.CanUndo))
                {
                    RaisePropertyChanged(() => CanUndo);
                    UndoCommand.RaiseCanExecuteChanged();
                }
                if (e.PropertyName == GetPropertyName(() => _editor.CanRedo))
                {
                    RaisePropertyChanged(() => CanRedo);
                    RedoCommand.RaiseCanExecuteChanged();
                }
                if (e.PropertyName == GetPropertyName(() => _editor.CanDelete)) RaisePropertyChanged(() => CanDelete);
                if (e.PropertyName == GetPropertyName(() => _editor.HasError))
                {
                    RaisePropertyChanged(() => HasError);
                    ShowErrorPressedCommand.RaiseCanExecuteChanged();
                }
                if (e.PropertyName == GetPropertyName(() => _editor.HasError)) RaisePropertyChanged(() => CanEvaluate);
                if (e.PropertyName == GetPropertyName(() => _editor.ParsingError)) RaisePropertyChanged(() => ParsingError);
            };

            _keyboardViewModel = ServiceLocator.ViewModelLocator.FormulaKeyboardViewModel;
            //_keyboardViewModel.PropertyChanged += (sender, e) =>
            //{
            //    if (e.PropertyName == GetPropertyName(() => _keyboardViewModel.IsAddLocalVariableButtonVisible)) RaisePropertyChanged(() => IsAddLocalVariableButtonVisible);
            //    if (e.PropertyName == GetPropertyName(() => _keyboardViewModel.IsAddGlobalVariableButtonVisible)) RaisePropertyChanged(() => IsAddGlobalVariableButtonVisible);
            //};
            _sensorsAreActive = false;
        }