Ejemplo n.º 1
0
        private void SyntaxModeCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Language language = (Language)_syntaxModeCombo.SelectedItem;

            if (_foldingManager != null)
            {
                _foldingManager.Clear();
                FoldingManager.Uninstall(_foldingManager);
            }

            string scopeName = _registryOptions.GetScopeByLanguageId(language.Id);

            _textMateInstallation.SetGrammar(null);
            _textEditor.Document = new TextDocument(ResourceLoader.LoadSampleFile(scopeName));
            _textMateInstallation.SetGrammar(scopeName);

            if (language.Id == "xml")
            {
                _foldingManager = FoldingManager.Install(_textEditor.TextArea);

                var strategy = new XmlFoldingStrategy();
                strategy.UpdateFoldings(_foldingManager, _textEditor.Document);
                return;
            }
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            _textEditor                 = this.FindControl <TextEditor>("Editor");
            _textEditor.Background      = Brushes.Transparent;
            _textEditor.ShowLineNumbers = true;
            _textEditor.ContextMenu     = new ContextMenu
            {
                Items = new List <MenuItem>
                {
                    new MenuItem {
                        Header = "Copy", InputGesture = new KeyGesture(Key.C, KeyModifiers.Control)
                    },
                    new MenuItem {
                        Header = "Paste", InputGesture = new KeyGesture(Key.V, KeyModifiers.Control)
                    },
                    new MenuItem {
                        Header = "Cut", InputGesture = new KeyGesture(Key.X, KeyModifiers.Control)
                    }
                }
            };
            _textEditor.TextArea.Background    = this.Background;
            _textEditor.TextArea.TextEntered  += textEditor_TextArea_TextEntered;
            _textEditor.TextArea.TextEntering += textEditor_TextArea_TextEntering;
            _textEditor.Options.ShowBoxForControlCharacters = true;
            _textEditor.TextArea.IndentationStrategy        = new Indentation.CSharp.CSharpIndentationStrategy(_textEditor.Options);
            _textEditor.TextArea.Caret.PositionChanged     += Caret_PositionChanged;
            _textEditor.TextArea.RightClickMovesCaret       = true;

            _addControlButton        = this.FindControl <Button>("addControlBtn");
            _addControlButton.Click += AddControlButton_Click;

            _clearControlButton        = this.FindControl <Button>("clearControlBtn");
            _clearControlButton.Click += ClearControlButton_Click;;

            _changeThemeButton        = this.FindControl <Button>("changeThemeBtn");
            _changeThemeButton.Click += ChangeThemeButton_Click;

            _textEditor.TextArea.TextView.ElementGenerators.Add(_generator);

            _registryOptions = new RegistryOptions(
                (ThemeName)_currentTheme);

            _textMateInstallation = _textEditor.InstallTextMate(_registryOptions);

            Language csharpLanguage = _registryOptions.GetLanguageByExtension(".cs");

            _syntaxModeCombo                   = this.FindControl <ComboBox>("syntaxModeCombo");
            _syntaxModeCombo.Items             = _registryOptions.GetAvailableLanguages();
            _syntaxModeCombo.SelectedItem      = csharpLanguage;
            _syntaxModeCombo.SelectionChanged += SyntaxModeCombo_SelectionChanged;

            string scopeName = _registryOptions.GetScopeByLanguageId(csharpLanguage.Id);

            _textEditor.Document = new TextDocument(
                "// AvaloniaEdit supports displaying control chars: \a or \b or \v" + Environment.NewLine +
                ResourceLoader.LoadSampleFile(scopeName));
            _textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId(csharpLanguage.Id));

            _statusTextBlock = this.Find <TextBlock>("StatusText");

            this.AddHandler(PointerWheelChangedEvent, (o, i) =>
            {
                if (i.KeyModifiers != KeyModifiers.Control)
                {
                    return;
                }
                if (i.Delta.Y > 0)
                {
                    _textEditor.FontSize++;
                }
                else
                {
                    _textEditor.FontSize = _textEditor.FontSize > 1 ? _textEditor.FontSize - 1 : 1;
                }
            }, RoutingStrategies.Bubble, true);
        }