예제 #1
0
 public void HandleError(ErrorDescription error)
 {
     HasErrors = true;
     ParserErrors.Add(error);
 }
예제 #2
0
        public MainWindowViewModel()
        {
            CompositeDisposable.Add(new PropertyChangedEventListener(m_Model, (s, ev) =>
            {
                switch (ev.PropertyName)
                {
                case nameof(m_Model.LyricsSource):
                    RaisePropertyChanged(nameof(LyricsSource));
                    break;

                case nameof(m_Model.IsModified):
                    RaisePropertyChanged(nameof(IsModified));
                    break;

                case nameof(m_Model.SavedFileNameWithoutExtension):
                    RaisePropertyChanged(nameof(DocumentName));
                    break;
                }
            }));
            var synchronizationContext = SynchronizationContext.Current;

            Debug.Assert(synchronizationContext != null, "SynchronizationContext.Current is null");
            CompositeDisposable.Add(
                m_Model.AsPropertyChanged(nameof(m_Model.ParserErrors))
                .Throttle(TimeSpan.FromMilliseconds(1000))
                .ObserveOn(synchronizationContext)
                .Subscribe(_ =>
            {
                ParserErrors.Clear();
                foreach (var item in m_Model.ParserErrors)
                {
                    ParserErrors.Add(item);
                }
            })
                );
            CompositeDisposable.Add(new PropertyChangedEventListener(this, async(s, ev) =>
            {
                switch (ev.PropertyName)
                {
                case nameof(CaretLocation):
                    if (LyricsSource != null)
                    {
                        var logicalLineIndex = LyricsSource.LineMap.GetLogicalLineIndexByPhysical(CaretLocation.Line - 1);
                        if (logicalLineIndex >= 0)
                        {
                            await ForcusViewSyllableAsync(logicalLineIndex, 0);
                        }
                    }
                    break;

                case nameof(CurrentSyllable):
                    if (LyricsSource != null)
                    {
                        var physicalLineIndex = LyricsSource.LineMap.GetPhysicalLineIndexByLogical(CurrentSyllable.Line);
                        await FocusEditorCharacterAsync(physicalLineIndex + 1, -1, false);
                    }
                    break;
                }
            }));

            NewCommand = new HotKeyCommand(async() => await NewAsync())
            {
                Gesture = new KeyGesture(Key.N, ModifierKeys.Control)
            };
            OpenCommand = new HotKeyCommand(async() => await OpenAsync())
            {
                Gesture = new KeyGesture(Key.O, ModifierKeys.Control)
            };
            SaveAsCommand = new ViewModelCommand(async() => await SaveAsAsync());
            SaveCommand   = new HotKeyCommand(async() => await SaveAsync())
            {
                Gesture = new KeyGesture(Key.S, ModifierKeys.Control)
            };
            AutoSetRubyInSelectionCommand   = new ViewModelCommand(AutoSetRubyInSelection);
            HighlightFirstCommand           = new ViewModelCommand(async() => await HighlightLyricsAsync(LyricsHighlightRequest.First));
            HighlightNextCommand            = new ViewModelCommand(async() => await HighlightLyricsAsync(LyricsHighlightRequest.Next));
            HighlightPreviousCommand        = new ViewModelCommand(async() => await HighlightLyricsAsync(LyricsHighlightRequest.Previous));
            HighlightNextLineCommand        = new ViewModelCommand(async() => await HighlightLyricsAsync(LyricsHighlightRequest.NextLine));
            HighlightPreviousLineCommand    = new ViewModelCommand(async() => await HighlightLyricsAsync(LyricsHighlightRequest.PreviousLine));
            MoveCaretToSelectedErrorCommand = new ViewModelCommand(async() => await MoveCaretToSelectedErrorAsync());
        }