Beispiel #1
0
        public VocabularyBrowserViewModel(
            IReduxStore <WordTutorApplication> store,
            ILogger logger)
        {
            if (logger is null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _store  = store ?? throw new ArgumentNullException(nameof(store));
            _logger = logger.Action("Browse Vocabulary List");

            var screen = (VocabularyBrowserScreen)_store.State.CurrentScreen;
            var vocab  = _store.State.VocabularySet.Words;

            _selection = screen.Selection;
            _modified  = screen.Modified;
            Words      = new ObservableCollection <VocabularyWord>(
                vocab.OrderBy(w => w.Spelling));

            _screenSubscription = _store.SubscribeToReference(
                app => app.CurrentScreen as VocabularyBrowserScreen,
                RefreshFromScreen);

            _vocabularySubscription = _store.SubscribeToReference(
                app => app.VocabularySet,
                RefreshFromVocabularySet);

            AddWordCommand =
                new RoutedCommandSink(ItemCommands.New, AddWord);

            ModifyWordCommand = new RoutedCommandSink <VocabularyWord>(
                ItemCommands.Open, ModifyWord, CanModifyWord);
        }
        public ModifyVocabularyWordViewModel(
            IReduxStore <WordTutorApplication> store,
            ILogger logger)
        {
            if (logger is null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _store = store ?? throw new ArgumentNullException(nameof(store));

            var screen    = _store.State.CurrentScreen as ModifyVocabularyWordScreen;
            var areAdding = screen?.ExistingWord is null;

            _logger = logger.Action(
                areAdding
                ? "Create Vocabulary Word"
                : "Modify Vocabulary Word");

            _spelling      = screen?.Spelling ?? string.Empty;
            _phrase        = screen?.Phrase ?? string.Empty;
            _pronunciation = screen?.Pronunciation ?? string.Empty;
            _caption       = areAdding ? "Add Word" : "Modify Word";

            _screenSubscription = _store.SubscribeToReference(
                app => app.CurrentScreen as ModifyVocabularyWordScreen,
                RefreshFromScreen);

            SpeakCommand = new RoutedCommandSink <string>(
                VoiceCommands.StartSpeaking, Speak, CanSpeak, this);
            SaveCommand = new RoutedCommandSink(
                ItemCommands.Save, Save, CanSave);
            CloseCommand = new RoutedCommandSink(
                ItemCommands.Close, Close);
        }