Exemplo n.º 1
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.TextArea.IndentationStrategy    = new Indentation.CSharp.CSharpIndentationStrategy();
            _textEditor.TextArea.Caret.PositionChanged += Caret_PositionChanged;
            _textEditor.TextArea.RightClickMovesCaret   = true;

            _addControlBtn        = this.FindControl <Button>("addControlBtn");
            _addControlBtn.Click += _addControlBtn_Click;

            _clearControlBtn        = this.FindControl <Button>("clearControlBtn");
            _clearControlBtn.Click += _clearControlBtn_Click;;

            _changeThemeBtn        = this.FindControl <Button>("changeThemeBtn");
            _changeThemeBtn.Click += _changeThemeBtn_Click;

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

            _textMateInstallation = _textEditor.InstallTextMate(
                (ThemeName)_currentTheme,
                null);

            Language csharpLanguage = _textMateInstallation.RegistryOptions.GetLanguageByExtension(".cs");

            _syntaxModeCombo                   = this.FindControl <ComboBox>("syntaxModeCombo");
            _syntaxModeCombo.Items             = _textMateInstallation.RegistryOptions.GetAvailableLanguages();
            _syntaxModeCombo.SelectedItem      = csharpLanguage;
            _syntaxModeCombo.SelectionChanged += _syntaxModeCombo_SelectionChanged;

            string scopeName = _textMateInstallation.RegistryOptions.GetScopeByLanguageId(csharpLanguage.Id);

            _textEditor.Document = new TextDocument(ResourceLoader.LoadSampleFile(scopeName));
            _textMateInstallation.SetGrammarByLanguageId(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);
        }