Ejemplo n.º 1
0
        protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            TextView = e.NameScope.Find <TextView>("textView");

            LogicalChildren.Add(TextView);

            disposables.Add(TextDocumentProperty.Changed.Subscribe(args =>
            {
                if (args.NewValue != null)
                {
                    // Todo unsubscribe these events.
                    TextDocument.Changing += (sender, ee) =>
                    {
                        TextDocument?.UndoStack.PushOptional(new RestoreCaretAndSelectionUndoAction(this));

                        if (BeforeTextChangedCommand != null)
                        {
                            BeforeTextChangedCommand.Execute(null);
                        }
                    };

                    TextDocument.Changed += (sender, ee) =>
                    {
                        InvalidateVisual();

                        LineHeight = TextView.CharSize.Height;

                        if (TextChangedCommand != null && TextChangedCommand.CanExecute(null))
                        {
                            TextChangedCommand.Execute(null);
                        }
                    };
                }
            }));
        }
Ejemplo n.º 2
0
        protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            TextView        = e.NameScope.Find <TextView>("textView");
            TextView.Cursor = new Cursor(StandardCursorType.Ibeam);

            //textView.BackgroundRenderers.Clear();
            //textView.DocumentLineTransformers.Clear();

            //textView.BackgroundRenderers.Add(new SelectedLineBackgroundRenderer());
            //textView.BackgroundRenderers.Add(new ColumnLimitBackgroundRenderer());
            //textView.BackgroundRenderers.Add(new SelectionBackgroundRenderer());
            //textView.DocumentLineTransformers.Add(new SelectedWordTextLineTransformer(this));

            disposables.Add(TextDocumentProperty.Changed.Subscribe(args =>
            {
                if (args.NewValue != null)
                {
                    // Todo unsubscribe these events.
                    TextDocument.Changing += (sender, ee) =>
                    {
                        TextDocument?.UndoStack.StartUndoGroup();
                        TextDocument?.UndoStack.PushOptional(new RestoreCaretAndSelectionUndoAction(this));

                        if (BeforeTextChangedCommand != null)
                        {
                            BeforeTextChangedCommand.Execute(null);
                        }
                    };

                    TextDocument.Changed += (sender, ee) =>
                    {
                        TextDocument?.UndoStack.EndUndoGroup();

                        InvalidateVisual();

                        LineHeight = TextView.CharSize.Height;

                        textChangedDelayTimer.Stop();
                        textChangedDelayTimer.Start();
                    };
                }
            }));
        }
Ejemplo n.º 3
0
        public EditorViewModel(EditorModel model) : base(model)
        {
            disposables      = new CompositeDisposable();
            highlightingData = new ObservableCollection <OffsetSyntaxHighlightingData>();

            BeforeTextChangedCommand = ReactiveCommand.Create();
            disposables.Add(BeforeTextChangedCommand.Subscribe(model.OnBeforeTextChanged));

            TextChangedCommand = ReactiveCommand.Create();
            disposables.Add(TextChangedCommand.Subscribe(model.OnTextChanged));

            SaveCommand = ReactiveCommand.Create();
            disposables.Add(SaveCommand.Subscribe(param => Save()));

            disposables.Add(CloseCommand.Subscribe(_ =>
            {
                Model.ProjectFile.FileModifiedExternally -= ProjectFile_FileModifiedExternally;
                Model.Editor.CaretChangedByPointerClick  -= Editor_CaretChangedByPointerClick;
                Save();
                Model.ShutdownBackgroundWorkers();
                Model.UnRegisterLanguageService();

                intellisenseManager?.Dispose();
                intellisenseManager = null;

                Diagnostics?.Clear();

                ShellViewModel.Instance.InvalidateErrors();

                Model.Dispose();
                Intellisense.Dispose();
                disposables.Dispose();

                Model.TextDocument = null;
            }));

            AddWatchCommand = ReactiveCommand.Create();
            disposables.Add(AddWatchCommand.Subscribe(_ => { IoC.Get <IWatchList>()?.AddWatch(WordAtCaret); }));

            tabCharacter = "    ";

            model.DocumentLoaded += (sender, e) =>
            {
                model.ProjectFile.FileModifiedExternally -= ProjectFile_FileModifiedExternally;
                Model.Editor.CaretChangedByPointerClick  -= Editor_CaretChangedByPointerClick;

                foreach (var bgRenderer in languageServiceBackgroundRenderers)
                {
                    BackgroundRenderers.Remove(bgRenderer);
                }

                languageServiceBackgroundRenderers.Clear();

                foreach (var transformer in languageServiceDocumentLineTransformers)
                {
                    DocumentLineTransformers.Remove(transformer);
                }

                languageServiceDocumentLineTransformers.Clear();

                if (model.LanguageService != null)
                {
                    languageServiceBackgroundRenderers.AddRange(model.LanguageService.GetBackgroundRenderers(model.ProjectFile));

                    foreach (var bgRenderer in languageServiceBackgroundRenderers)
                    {
                        BackgroundRenderers.Add(bgRenderer);
                    }

                    languageServiceDocumentLineTransformers.AddRange(
                        model.LanguageService.GetDocumentLineTransformers(model.ProjectFile));

                    foreach (var textTransformer in languageServiceDocumentLineTransformers)
                    {
                        DocumentLineTransformers.Add(textTransformer);
                    }

                    intellisenseManager = new IntellisenseManager(Model.Editor, Intellisense, Intellisense.CompletionAssistant, model.LanguageService, model.ProjectFile);

                    EventHandler <KeyEventArgs> tunneledKeyUpHandler = (send, ee) =>
                    {
                        if (caretIndex > 0)
                        {
                            intellisenseManager.OnKeyUp(ee, CaretIndex, CaretTextLocation.Line, CaretTextLocation.Column);
                        }
                    };

                    EventHandler <KeyEventArgs> tunneledKeyDownHandler = (send, ee) =>
                    {
                        if (caretIndex > 0)
                        {
                            intellisenseManager.OnKeyDown(ee, CaretIndex, CaretTextLocation.Line, CaretTextLocation.Column);
                        }
                    };

                    EventHandler <TextInputEventArgs> tunneledTextInputHandler = (send, ee) =>
                    {
                        if (caretIndex > 0)
                        {
                            intellisenseManager.OnTextInput(ee, CaretIndex, CaretTextLocation.Line, CaretTextLocation.Column);
                        }
                    };

                    Model.Editor.CaretChangedByPointerClick += Editor_CaretChangedByPointerClick;

                    disposables.Add(Model.Editor.AddHandler(InputElement.KeyDownEvent, tunneledKeyDownHandler, RoutingStrategies.Tunnel));
                    disposables.Add(Model.Editor.AddHandler(InputElement.KeyUpEvent, tunneledKeyUpHandler, RoutingStrategies.Tunnel));
                    disposables.Add(Model.Editor.AddHandler(InputElement.TextInputEvent, tunneledTextInputHandler, RoutingStrategies.Bubble));
                }

                model.CodeAnalysisCompleted += (s, ee) =>
                {
                    Diagnostics = model.CodeAnalysisResults.Diagnostics;

                    HighlightingData =
                        new ObservableCollection <OffsetSyntaxHighlightingData>(model.CodeAnalysisResults.SyntaxHighlightingData);

                    IndexItems         = new ObservableCollection <IndexEntry>(model.CodeAnalysisResults.IndexItems);
                    selectedIndexEntry = IndexItems.FirstOrDefault();
                    this.RaisePropertyChanged(nameof(SelectedIndexEntry));

                    ShellViewModel.Instance.InvalidateErrors();
                };

                model.ProjectFile.FileModifiedExternally += ProjectFile_FileModifiedExternally;

                TextDocument = model.TextDocument;

                Title = Model.ProjectFile.Name;
            };

            model.TextChanged += (sender, e) =>
            {
                if (ShellViewModel.Instance.DocumentTabs.TemporaryDocument == this)
                {
                    Dock = Dock.Left;

                    ShellViewModel.Instance.DocumentTabs.TemporaryDocument = null;
                }

                IsDirty = model.IsDirty;
            };

            intellisense = new IntellisenseViewModel(model, this);

            documentLineTransformers = new ObservableCollection <IDocumentLineTransformer>();

            backgroundRenderers = new ObservableCollection <IBackgroundRenderer>();
            backgroundRenderers.Add(new SelectedLineBackgroundRenderer());

            DebugLineHighlighter = new SelectedDebugLineBackgroundRenderer();
            backgroundRenderers.Add(DebugLineHighlighter);

            backgroundRenderers.Add(new ColumnLimitBackgroundRenderer());
            wordAtCaretHighlighter = new SelectedWordBackgroundRenderer();
            backgroundRenderers.Add(wordAtCaretHighlighter);
            backgroundRenderers.Add(new SelectionBackgroundRenderer());

            margins = new ObservableCollection <TextViewMargin>();

            Dock = Dock.Right;
        }
Ejemplo n.º 4
0
        public EditorViewModel(EditorModel model) : base(model)
        {
            disposables      = new CompositeDisposable();
            highlightingData = new ObservableCollection <OffsetSyntaxHighlightingData>();

            BeforeTextChangedCommand = ReactiveCommand.Create();
            disposables.Add(BeforeTextChangedCommand.Subscribe(model.OnBeforeTextChanged));

            TextChangedCommand = ReactiveCommand.Create();
            disposables.Add(TextChangedCommand.Subscribe(model.OnTextChanged));

            SaveCommand = ReactiveCommand.Create();
            disposables.Add(SaveCommand.Subscribe(param => Save()));

            CloseCommand = ReactiveCommand.Create();

            disposables.Add(CloseCommand.Subscribe(_ =>
            {
                Model.ProjectFile.FileModifiedExternally -= ProjectFile_FileModifiedExternally;
                Save();
                Model.ShutdownBackgroundWorkers();
                Model.UnRegisterLanguageService();

                if (ShellViewModel.Instance.DocumentTabs.TemporaryDocument == this)
                {
                    ShellViewModel.Instance.DocumentTabs.TemporaryDocument = null;
                }

                ShellViewModel.Instance.InvalidateErrors();

                Model.Dispose();
                Intellisense.Dispose();
                disposables.Dispose();

                Model.TextDocument = null;
                ShellViewModel.Instance.DocumentTabs.Documents.Remove(this);
            }));

            AddWatchCommand = ReactiveCommand.Create();
            disposables.Add(AddWatchCommand.Subscribe(_ => { IoC.Get <IWatchList>()?.AddWatch(WordAtCaret); }));

            tabCharacter = "    ";

            model.DocumentLoaded += (sender, e) =>
            {
                model.ProjectFile.FileModifiedExternally -= ProjectFile_FileModifiedExternally;

                foreach (var bgRenderer in languageServiceBackgroundRenderers)
                {
                    BackgroundRenderers.Remove(bgRenderer);
                }

                languageServiceBackgroundRenderers.Clear();

                foreach (var transformer in languageServiceDocumentLineTransformers)
                {
                    DocumentLineTransformers.Remove(transformer);
                }

                languageServiceDocumentLineTransformers.Clear();

                if (model.LanguageService != null)
                {
                    languageServiceBackgroundRenderers.AddRange(model.LanguageService.GetBackgroundRenderers(model.ProjectFile));

                    foreach (var bgRenderer in languageServiceBackgroundRenderers)
                    {
                        BackgroundRenderers.Add(bgRenderer);
                    }

                    languageServiceDocumentLineTransformers.AddRange(
                        model.LanguageService.GetDocumentLineTransformers(model.ProjectFile));

                    foreach (var textTransformer in languageServiceDocumentLineTransformers)
                    {
                        DocumentLineTransformers.Add(textTransformer);
                    }
                }

                model.CodeAnalysisCompleted += (s, ee) =>
                {
                    Diagnostics = model.CodeAnalysisResults.Diagnostics;

                    foreach (var marker in Diagnostics)
                    {
                        if (marker.Length == 0)
                        {
                            var line      = TextDocument.GetLineByOffset(marker.StartOffset);
                            var endoffset = TextUtilities.GetNextCaretPosition(TextDocument, marker.StartOffset,
                                                                               TextUtilities.LogicalDirection.Forward, TextUtilities.CaretPositioningMode.WordBorderOrSymbol);

                            if (endoffset == -1)
                            {
                                marker.Length = line.Length;
                            }
                            else
                            {
                                marker.EndOffset = endoffset;
                            }
                        }
                    }

                    HighlightingData =
                        new ObservableCollection <OffsetSyntaxHighlightingData>(model.CodeAnalysisResults.SyntaxHighlightingData);

                    IndexItems         = new ObservableCollection <IndexEntry>(model.CodeAnalysisResults.IndexItems);
                    selectedIndexEntry = IndexItems.FirstOrDefault();
                    this.RaisePropertyChanged(nameof(SelectedIndexEntry));

                    ShellViewModel.Instance.InvalidateErrors();
                };

                model.ProjectFile.FileModifiedExternally += ProjectFile_FileModifiedExternally;
                TextDocument = model.TextDocument;
                this.RaisePropertyChanged(nameof(Title));
            };

            model.TextChanged += (sender, e) =>
            {
                if (ShellViewModel.Instance.DocumentTabs.TemporaryDocument == this)
                {
                    Dock = Dock.Left;

                    ShellViewModel.Instance.DocumentTabs.TemporaryDocument = null;
                }

                this.RaisePropertyChanged(nameof(Title));
            };

            intellisense = new IntellisenseViewModel(model, this);

            documentLineTransformers = new ObservableCollection <IDocumentLineTransformer>();

            backgroundRenderers = new ObservableCollection <IBackgroundRenderer>();
            backgroundRenderers.Add(new SelectedLineBackgroundRenderer());

            DebugLineHighlighter = new SelectedDebugLineBackgroundRenderer();
            backgroundRenderers.Add(DebugLineHighlighter);

            backgroundRenderers.Add(new ColumnLimitBackgroundRenderer());
            wordAtCaretHighlighter = new SelectedWordBackgroundRenderer();
            backgroundRenderers.Add(wordAtCaretHighlighter);
            backgroundRenderers.Add(new SelectionBackgroundRenderer());

            margins = new ObservableCollection <TextViewMargin>();

            dock = Dock.Right;
        }